NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / keyboard_overlay_ui.cc
blob918d4981021b70816e62e5a49d16a562d57cffcf
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/shell.h"
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/ime/input_method_manager.h"
21 #include "chromeos/ime/xkeyboard.h"
22 #include "content/public/browser/page_navigator.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_delegate.h"
25 #include "content/public/browser/web_ui.h"
26 #include "content/public/browser/web_ui_data_source.h"
27 #include "content/public/browser/web_ui_message_handler.h"
28 #include "grit/browser_resources.h"
29 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h"
31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h"
34 using chromeos::input_method::ModifierKey;
35 using content::WebUIMessageHandler;
36 using ui::WebDialogUI;
38 namespace {
40 const char kLearnMoreURL[] =
41 #if defined(OFFICIAL_BUILD)
42 "chrome-extension://honijodknafkokifofgiaalefdiedpko/"
43 "main.html?answer=188743";
44 #else
45 "http://support.google.com/chromeos/bin/answer.py?answer=183101";
46 #endif
48 struct ModifierToLabel {
49 const ModifierKey modifier;
50 const char* label;
51 } kModifierToLabels[] = {
52 {chromeos::input_method::kSearchKey, "search"},
53 {chromeos::input_method::kControlKey, "ctrl"},
54 {chromeos::input_method::kAltKey, "alt"},
55 {chromeos::input_method::kVoidKey, "disabled"},
56 {chromeos::input_method::kCapsLockKey, "caps lock"},
57 {chromeos::input_method::kEscapeKey, "esc"},
60 struct I18nContentToMessage {
61 const char* i18n_content;
62 int message;
63 } kI18nContentToMessage[] = {
64 { "keyboardOverlayLearnMore", IDS_KEYBOARD_OVERLAY_LEARN_MORE },
65 { "keyboardOverlayTitle", IDS_KEYBOARD_OVERLAY_TITLE },
66 { "keyboardOverlayInstructions", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS },
67 { "keyboardOverlayInstructionsHide", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_HIDE },
68 { "keyboardOverlayActivateLastLauncherItem",
69 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_LAUNCHER_ITEM },
70 { "keyboardOverlayActivateLastTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_TAB },
71 { "keyboardOverlayActivateLauncherItem1",
72 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_1 },
73 { "keyboardOverlayActivateLauncherItem2",
74 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_2 },
75 { "keyboardOverlayActivateLauncherItem3",
76 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_3 },
77 { "keyboardOverlayActivateLauncherItem4",
78 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_4 },
79 { "keyboardOverlayActivateLauncherItem5",
80 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_5 },
81 { "keyboardOverlayActivateLauncherItem6",
82 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_6 },
83 { "keyboardOverlayActivateLauncherItem7",
84 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_7 },
85 { "keyboardOverlayActivateLauncherItem8",
86 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_8 },
87 { "keyboardOverlayActivateNextTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_NEXT_TAB },
88 { "keyboardOverlayActivatePreviousTab",
89 IDS_KEYBOARD_OVERLAY_ACTIVATE_PREVIOUS_TAB },
90 { "keyboardOverlayActivateTab1", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_1 },
91 { "keyboardOverlayActivateTab2", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_2 },
92 { "keyboardOverlayActivateTab3", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_3 },
93 { "keyboardOverlayActivateTab4", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_4 },
94 { "keyboardOverlayActivateTab5", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_5 },
95 { "keyboardOverlayActivateTab6", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_6 },
96 { "keyboardOverlayActivateTab7", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_7 },
97 { "keyboardOverlayActivateTab8", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_8 },
98 { "keyboardOverlayAddWwwAndComAndOpenAddress",
99 IDS_KEYBOARD_OVERLAY_ADD_WWW_AND_COM_AND_OPEN_ADDRESS },
100 { "keyboardOverlayBookmarkAllTabs", IDS_KEYBOARD_OVERLAY_BOOKMARK_ALL_TABS },
101 { "keyboardOverlayBookmarkCurrentPage",
102 IDS_KEYBOARD_OVERLAY_BOOKMARK_CURRENT_PAGE },
103 { "keyboardOverlayBookmarkManager", IDS_KEYBOARD_OVERLAY_BOOKMARK_MANAGER },
104 { "keyboardOverlayCenterWindow", IDS_KEYBOARD_OVERLAY_CENTER_WINDOW },
105 { "keyboardOverlayClearBrowsingDataDialog",
106 IDS_KEYBOARD_OVERLAY_CLEAR_BROWSING_DATA_DIALOG },
107 { "keyboardOverlayCloseTab", IDS_KEYBOARD_OVERLAY_CLOSE_TAB },
108 { "keyboardOverlayCloseWindow", IDS_KEYBOARD_OVERLAY_CLOSE_WINDOW },
109 { "keyboardOverlayCopy", IDS_KEYBOARD_OVERLAY_COPY },
110 { "keyboardOverlayCut", IDS_KEYBOARD_OVERLAY_CUT },
111 { "keyboardOverlayCycleThroughInputMethods",
112 IDS_KEYBOARD_OVERLAY_CYCLE_THROUGH_INPUT_METHODS },
113 { "keyboardOverlayDecreaseKeyBrightness",
114 IDS_KEYBOARD_OVERLAY_DECREASE_KEY_BRIGHTNESS },
115 { "keyboardOverlayDelete", IDS_KEYBOARD_OVERLAY_DELETE },
116 { "keyboardOverlayDeleteWord", IDS_KEYBOARD_OVERLAY_DELETE_WORD },
117 { "keyboardOverlayDeveloperTools", IDS_KEYBOARD_OVERLAY_DEVELOPER_TOOLS },
118 { "keyboardOverlayDockWindowLeft", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_LEFT },
119 { "keyboardOverlayDockWindowRight", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_RIGHT },
120 { "keyboardOverlayDomInspector", IDS_KEYBOARD_OVERLAY_DOM_INSPECTOR },
121 { "keyboardOverlayDownloads", IDS_KEYBOARD_OVERLAY_DOWNLOADS },
122 { "keyboardOverlayEnd", IDS_KEYBOARD_OVERLAY_END },
123 { "keyboardOverlayF1", IDS_KEYBOARD_OVERLAY_F1 },
124 { "keyboardOverlayF10", IDS_KEYBOARD_OVERLAY_F10 },
125 { "keyboardOverlayF11", IDS_KEYBOARD_OVERLAY_F11 },
126 { "keyboardOverlayF12", IDS_KEYBOARD_OVERLAY_F12 },
127 { "keyboardOverlayF2", IDS_KEYBOARD_OVERLAY_F2 },
128 { "keyboardOverlayF3", IDS_KEYBOARD_OVERLAY_F3 },
129 { "keyboardOverlayF4", IDS_KEYBOARD_OVERLAY_F4 },
130 { "keyboardOverlayF5", IDS_KEYBOARD_OVERLAY_F5 },
131 { "keyboardOverlayF6", IDS_KEYBOARD_OVERLAY_F6 },
132 { "keyboardOverlayF7", IDS_KEYBOARD_OVERLAY_F7 },
133 { "keyboardOverlayF8", IDS_KEYBOARD_OVERLAY_F8 },
134 { "keyboardOverlayF9", IDS_KEYBOARD_OVERLAY_F9 },
135 { "keyboardOverlayFindPreviousText",
136 IDS_KEYBOARD_OVERLAY_FIND_PREVIOUS_TEXT },
137 { "keyboardOverlayFindText", IDS_KEYBOARD_OVERLAY_FIND_TEXT },
138 { "keyboardOverlayFindTextAgain", IDS_KEYBOARD_OVERLAY_FIND_TEXT_AGAIN },
139 { "keyboardOverlayFocusAddressBar", IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR },
140 { "keyboardOverlayFocusAddressBarInSearchMode",
141 IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR_IN_SEARCH_MODE },
142 { "keyboardOverlayFocusBookmarks", IDS_KEYBOARD_OVERLAY_FOCUS_BOOKMARKS },
143 { "keyboardOverlayFocusLauncher", IDS_KEYBOARD_OVERLAY_FOCUS_LAUNCHER },
144 { "keyboardOverlayFocusNextPane", IDS_KEYBOARD_OVERLAY_FOCUS_NEXT_PANE },
145 { "keyboardOverlayFocusPreviousPane",
146 IDS_KEYBOARD_OVERLAY_FOCUS_PREVIOUS_PANE },
147 { "keyboardOverlayFocusToolbar", IDS_KEYBOARD_OVERLAY_FOCUS_TOOLBAR },
148 { "keyboardOverlayGoBack", IDS_KEYBOARD_OVERLAY_GO_BACK },
149 { "keyboardOverlayGoForward", IDS_KEYBOARD_OVERLAY_GO_FORWARD },
150 { "keyboardOverlayHelp", IDS_KEYBOARD_OVERLAY_HELP },
151 { "keyboardOverlayHistory", IDS_KEYBOARD_OVERLAY_HISTORY },
152 { "keyboardOverlayHome", IDS_KEYBOARD_OVERLAY_HOME },
153 { "keyboardOverlayIncreaseKeyBrightness",
154 IDS_KEYBOARD_OVERLAY_INCREASE_KEY_BRIGHTNESS },
155 { "keyboardOverlayInputUnicodeCharacters",
156 IDS_KEYBOARD_OVERLAY_INPUT_UNICODE_CHARACTERS },
157 { "keyboardOverlayInsert", IDS_KEYBOARD_OVERLAY_INSERT },
158 { "keyboardOverlayJavascriptConsole",
159 IDS_KEYBOARD_OVERLAY_JAVASCRIPT_CONSOLE },
160 { "keyboardOverlayLockScreen", IDS_KEYBOARD_OVERLAY_LOCK_SCREEN },
161 { "keyboardOverlayLockScreenOrPowerOff",
162 IDS_KEYBOARD_OVERLAY_LOCK_SCREEN_OR_POWER_OFF },
163 { "keyboardOverlayMagnifierDecreaseZoom",
164 IDS_KEYBOARD_OVERLAY_MAGNIFIER_DECREASE_ZOOM },
165 { "keyboardOverlayMagnifierIncreaseZoom",
166 IDS_KEYBOARD_OVERLAY_MAGNIFIER_INCREASE_ZOOM },
167 { "keyboardOverlayMaximizeWindow", IDS_KEYBOARD_OVERLAY_MAXIMIZE_WINDOW },
168 { "keyboardOverlayMinimizeWindow", IDS_KEYBOARD_OVERLAY_MINIMIZE_WINDOW },
169 { "keyboardOverlayMirrorMonitors", IDS_KEYBOARD_OVERLAY_MIRROR_MONITORS },
170 { "keyboardOverlayNewIncognitoWindow",
171 IDS_KEYBOARD_OVERLAY_NEW_INCOGNITO_WINDOW },
172 { "keyboardOverlayNewTab", IDS_KEYBOARD_OVERLAY_NEW_TAB },
173 { "keyboardOverlayNewTerminal", IDS_KEYBOARD_OVERLAY_NEW_TERMINAL },
174 { "keyboardOverlayNewWindow", IDS_KEYBOARD_OVERLAY_NEW_WINDOW },
175 { "keyboardOverlayNextWindow", IDS_KEYBOARD_OVERLAY_NEXT_WINDOW },
176 { "keyboardOverlayNextWord", IDS_KEYBOARD_OVERLAY_NEXT_WORD },
177 { "keyboardOverlayOpen", IDS_KEYBOARD_OVERLAY_OPEN },
178 { "keyboardOverlayOpenAddressInNewTab",
179 IDS_KEYBOARD_OVERLAY_OPEN_ADDRESS_IN_NEW_TAB },
180 { "keyboardOverlayOpenFileManager", IDS_KEYBOARD_OVERLAY_OPEN_FILE_MANAGER },
181 { "keyboardOverlayOpenGoogleCloudPrint",
182 IDS_KEYBOARD_OVERLAY_OPEN_GOOGLE_CLOUD_PRINT },
183 { "keyboardOverlayPageDown", IDS_KEYBOARD_OVERLAY_PAGE_DOWN },
184 { "keyboardOverlayPageUp", IDS_KEYBOARD_OVERLAY_PAGE_UP },
185 { "keyboardOverlayPaste", IDS_KEYBOARD_OVERLAY_PASTE },
186 { "keyboardOverlayPasteAsPlainText",
187 IDS_KEYBOARD_OVERLAY_PASTE_AS_PLAIN_TEXT },
188 { "keyboardOverlayPreviousWindow", IDS_KEYBOARD_OVERLAY_PREVIOUS_WINDOW },
189 { "keyboardOverlayPreviousWord", IDS_KEYBOARD_OVERLAY_PREVIOUS_WORD },
190 { "keyboardOverlayPrint", IDS_KEYBOARD_OVERLAY_PRINT },
191 { "keyboardOverlayReloadCurrentPage",
192 IDS_KEYBOARD_OVERLAY_RELOAD_CURRENT_PAGE },
193 { "keyboardOverlayReloadIgnoringCache",
194 IDS_KEYBOARD_OVERLAY_RELOAD_IGNORING_CACHE },
195 { "keyboardOverlayReopenLastClosedTab",
196 IDS_KEYBOARD_OVERLAY_REOPEN_LAST_CLOSED_TAB },
197 { "keyboardOverlayReportIssue", IDS_KEYBOARD_OVERLAY_REPORT_ISSUE },
198 { "keyboardOverlayResetScreenZoom", IDS_KEYBOARD_OVERLAY_RESET_SCREEN_ZOOM },
199 { "keyboardOverlayResetZoom", IDS_KEYBOARD_OVERLAY_RESET_ZOOM },
200 { "keyboardOverlayRotateScreen", IDS_KEYBOARD_OVERLAY_ROTATE_SCREEN },
201 { "keyboardOverlaySave", IDS_KEYBOARD_OVERLAY_SAVE },
202 { "keyboardOverlayScreenshotRegion",
203 IDS_KEYBOARD_OVERLAY_SCREENSHOT_REGION },
204 { "keyboardOverlayScrollUpOnePage",
205 IDS_KEYBOARD_OVERLAY_SCROLL_UP_ONE_PAGE },
206 { "keyboardOverlaySelectAll", IDS_KEYBOARD_OVERLAY_SELECT_ALL },
207 { "keyboardOverlaySelectPreviousInputMethod",
208 IDS_KEYBOARD_OVERLAY_SELECT_PREVIOUS_INPUT_METHOD },
209 { "keyboardOverlaySelectWordAtATime",
210 IDS_KEYBOARD_OVERLAY_SELECT_WORD_AT_A_TIME },
211 { "keyboardOverlayShowMessageCenter",
212 IDS_KEYBOARD_OVERLAY_SHOW_MESSAGE_CENTER },
213 { "keyboardOverlayShowStatusMenu", IDS_KEYBOARD_OVERLAY_SHOW_STATUS_MENU },
214 { "keyboardOverlayShowWrenchMenu", IDS_KEYBOARD_OVERLAY_SHOW_WRENCH_MENU },
215 { "keyboardOverlaySignOut", IDS_KEYBOARD_OVERLAY_SIGN_OUT },
216 { "keyboardOverlaySwapPrimaryMonitor",
217 IDS_KEYBOARD_OVERLAY_SWAP_PRIMARY_MONITOR },
218 { "keyboardOverlayTakeScreenshot", IDS_KEYBOARD_OVERLAY_TAKE_SCREENSHOT },
219 { "keyboardOverlayTaskManager", IDS_KEYBOARD_OVERLAY_TASK_MANAGER },
220 { "keyboardOverlayToggleBookmarkBar",
221 IDS_KEYBOARD_OVERLAY_TOGGLE_BOOKMARK_BAR },
222 { "keyboardOverlayToggleCapsLock", IDS_KEYBOARD_OVERLAY_TOGGLE_CAPS_LOCK },
223 { "keyboardOverlayToggleChromevoxSpokenFeedback",
224 IDS_KEYBOARD_OVERLAY_TOGGLE_CHROMEVOX_SPOKEN_FEEDBACK },
225 { "keyboardOverlayToggleProjectionTouchHud",
226 IDS_KEYBOARD_OVERLAY_TOGGLE_PROJECTION_TOUCH_HUD },
227 { "keyboardOverlayToggleSpeechInput",
228 IDS_KEYBOARD_OVERLAY_TOGGLE_SPEECH_INPUT },
229 { "keyboardOverlayUndo", IDS_KEYBOARD_OVERLAY_UNDO },
230 { "keyboardOverlayViewKeyboardOverlay",
231 IDS_KEYBOARD_OVERLAY_VIEW_KEYBOARD_OVERLAY },
232 { "keyboardOverlayViewSource", IDS_KEYBOARD_OVERLAY_VIEW_SOURCE },
233 { "keyboardOverlayWordMove", IDS_KEYBOARD_OVERLAY_WORD_MOVE },
234 { "keyboardOverlayZoomIn", IDS_KEYBOARD_OVERLAY_ZOOM_IN },
235 { "keyboardOverlayZoomOut", IDS_KEYBOARD_OVERLAY_ZOOM_OUT },
236 { "keyboardOverlayZoomScreenIn", IDS_KEYBOARD_OVERLAY_ZOOM_SCREEN_IN },
237 { "keyboardOverlayZoomScreenOut", IDS_KEYBOARD_OVERLAY_ZOOM_SCREEN_OUT },
240 std::string ModifierKeyToLabel(ModifierKey modifier) {
241 for (size_t i = 0; i < arraysize(kModifierToLabels); ++i) {
242 if (modifier == kModifierToLabels[i].modifier) {
243 return kModifierToLabels[i].label;
246 return "";
249 content::WebUIDataSource* CreateKeyboardOverlayUIHTMLSource() {
250 content::WebUIDataSource* source =
251 content::WebUIDataSource::Create(chrome::kChromeUIKeyboardOverlayHost);
253 for (size_t i = 0; i < arraysize(kI18nContentToMessage); ++i) {
254 source->AddLocalizedString(kI18nContentToMessage[i].i18n_content,
255 kI18nContentToMessage[i].message);
258 source->AddString("keyboardOverlayLearnMoreURL",
259 base::UTF8ToUTF16(kLearnMoreURL));
260 source->AddBoolean("keyboardOverlayHasChromeOSDiamondKey",
261 CommandLine::ForCurrentProcess()->HasSwitch(
262 chromeos::switches::kHasChromeOSDiamondKey));
263 ash::Shell* shell = ash::Shell::GetInstance();
264 ash::internal::DisplayManager* display_manager = shell->display_manager();
265 source->AddBoolean("keyboardOverlayIsDisplayUIScalingEnabled",
266 display_manager->IsDisplayUIScalingEnabled());
267 source->SetJsonPath("strings.js");
268 source->SetUseJsonJSFormatV2();
269 source->AddResourcePath("keyboard_overlay.js", IDR_KEYBOARD_OVERLAY_JS);
270 source->SetDefaultResource(IDR_KEYBOARD_OVERLAY_HTML);
271 return source;
274 } // namespace
276 // The handler for Javascript messages related to the "keyboardoverlay" view.
277 class KeyboardOverlayHandler
278 : public WebUIMessageHandler,
279 public base::SupportsWeakPtr<KeyboardOverlayHandler> {
280 public:
281 explicit KeyboardOverlayHandler(Profile* profile);
282 virtual ~KeyboardOverlayHandler();
284 // WebUIMessageHandler implementation.
285 virtual void RegisterMessages() OVERRIDE;
287 private:
288 // Called when the page requires the input method ID corresponding to the
289 // current input method or keyboard layout during initialization.
290 void GetInputMethodId(const base::ListValue* args);
292 // Called when the page requres the information of modifier key remapping
293 // during the initialization.
294 void GetLabelMap(const base::ListValue* args);
296 // Called when the learn more link is clicked.
297 void OpenLearnMorePage(const base::ListValue* args);
299 Profile* profile_;
301 DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayHandler);
304 ////////////////////////////////////////////////////////////////////////////////
306 // KeyboardOverlayHandler
308 ////////////////////////////////////////////////////////////////////////////////
309 KeyboardOverlayHandler::KeyboardOverlayHandler(Profile* profile)
310 : profile_(profile) {
313 KeyboardOverlayHandler::~KeyboardOverlayHandler() {
316 void KeyboardOverlayHandler::RegisterMessages() {
317 web_ui()->RegisterMessageCallback("getInputMethodId",
318 base::Bind(&KeyboardOverlayHandler::GetInputMethodId,
319 base::Unretained(this)));
320 web_ui()->RegisterMessageCallback("getLabelMap",
321 base::Bind(&KeyboardOverlayHandler::GetLabelMap,
322 base::Unretained(this)));
323 web_ui()->RegisterMessageCallback("openLearnMorePage",
324 base::Bind(&KeyboardOverlayHandler::OpenLearnMorePage,
325 base::Unretained(this)));
328 void KeyboardOverlayHandler::GetInputMethodId(const base::ListValue* args) {
329 chromeos::input_method::InputMethodManager* manager =
330 chromeos::input_method::InputMethodManager::Get();
331 const chromeos::input_method::InputMethodDescriptor& descriptor =
332 manager->GetCurrentInputMethod();
333 base::StringValue param(descriptor.id());
334 web_ui()->CallJavascriptFunction("initKeyboardOverlayId", param);
337 void KeyboardOverlayHandler::GetLabelMap(const base::ListValue* args) {
338 DCHECK(profile_);
339 PrefService* pref_service = profile_->GetPrefs();
340 typedef std::map<ModifierKey, ModifierKey> ModifierMap;
341 ModifierMap modifier_map;
342 modifier_map[chromeos::input_method::kSearchKey] = static_cast<ModifierKey>(
343 pref_service->GetInteger(prefs::kLanguageRemapSearchKeyTo));
344 modifier_map[chromeos::input_method::kControlKey] = static_cast<ModifierKey>(
345 pref_service->GetInteger(prefs::kLanguageRemapControlKeyTo));
346 modifier_map[chromeos::input_method::kAltKey] = static_cast<ModifierKey>(
347 pref_service->GetInteger(prefs::kLanguageRemapAltKeyTo));
348 // TODO(mazda): Support prefs::kLanguageRemapCapsLockKeyTo once Caps Lock is
349 // added to the overlay UI.
351 base::DictionaryValue dict;
352 for (ModifierMap::const_iterator i = modifier_map.begin();
353 i != modifier_map.end(); ++i) {
354 dict.SetString(ModifierKeyToLabel(i->first), ModifierKeyToLabel(i->second));
357 web_ui()->CallJavascriptFunction("initIdentifierMap", dict);
360 void KeyboardOverlayHandler::OpenLearnMorePage(const base::ListValue* args) {
361 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab(
362 web_ui()->GetWebContents(),
363 content::OpenURLParams(GURL(kLearnMoreURL),
364 content::Referrer(),
365 NEW_FOREGROUND_TAB,
366 content::PAGE_TRANSITION_LINK,
367 false));
370 ////////////////////////////////////////////////////////////////////////////////
372 // KeyboardOverlayUI
374 ////////////////////////////////////////////////////////////////////////////////
376 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI* web_ui)
377 : WebDialogUI(web_ui) {
378 Profile* profile = Profile::FromWebUI(web_ui);
379 KeyboardOverlayHandler* handler = new KeyboardOverlayHandler(profile);
380 web_ui->AddMessageHandler(handler);
382 // Set up the chrome://keyboardoverlay/ source.
383 content::WebUIDataSource::Add(profile, CreateKeyboardOverlayUIHTMLSource());