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"
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 "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "chromeos/chromeos_switches.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 "ui/base/ime/chromeos/ime_keyboard.h"
30 #include "ui/base/ime/chromeos/input_method_manager.h"
32 using chromeos::input_method::ModifierKey
;
33 using content::WebUIMessageHandler
;
34 using ui::WebDialogUI
;
38 const char kLearnMoreURL
[] =
39 #if defined(OFFICIAL_BUILD)
40 "chrome-extension://honijodknafkokifofgiaalefdiedpko/"
41 "main.html?answer=188743";
43 "https://support.google.com/chromebook/answer/183101";
46 struct ModifierToLabel
{
47 const ModifierKey modifier
;
49 } kModifierToLabels
[] = {
50 {chromeos::input_method::kSearchKey
, "search"},
51 {chromeos::input_method::kControlKey
, "ctrl"},
52 {chromeos::input_method::kAltKey
, "alt"},
53 {chromeos::input_method::kVoidKey
, "disabled"},
54 {chromeos::input_method::kCapsLockKey
, "caps lock"},
55 {chromeos::input_method::kEscapeKey
, "esc"},
58 struct I18nContentToMessage
{
59 const char* i18n_content
;
61 } kI18nContentToMessage
[] = {
62 { "keyboardOverlayLearnMore", IDS_KEYBOARD_OVERLAY_LEARN_MORE
},
63 { "keyboardOverlayTitle", IDS_KEYBOARD_OVERLAY_TITLE
},
64 { "keyboardOverlayEscKeyLabel", IDS_KEYBOARD_OVERLAY_ESC_KEY_LABEL
},
65 { "keyboardOverlayBackKeyLabel", IDS_KEYBOARD_OVERLAY_BACK_KEY_LABEL
},
66 { "keyboardOverlayForwardKeyLabel", IDS_KEYBOARD_OVERLAY_FORWARD_KEY_LABEL
},
67 { "keyboardOverlayReloadKeyLabel", IDS_KEYBOARD_OVERLAY_RELOAD_KEY_LABEL
},
68 { "keyboardOverlayFullScreenKeyLabel",
69 IDS_KEYBOARD_OVERLAY_FULL_SCREEN_KEY_LABEL
},
70 { "keyboardOverlaySwitchWinKeyLabel",
71 IDS_KEYBOARD_OVERLAY_SWITCH_WIN_KEY_LABEL
},
72 { "keyboardOverlayBrightDownKeyLabel",
73 IDS_KEYBOARD_OVERLAY_BRIGHT_DOWN_KEY_LABEL
},
74 { "keyboardOverlayBrightUpKeyLabel",
75 IDS_KEYBOARD_OVERLAY_BRIGHT_UP_KEY_LABEL
},
76 { "keyboardOverlayMuteKeyLabel", IDS_KEYBOARD_OVERLAY_MUTE_KEY_LABEL
},
77 { "keyboardOverlayVolDownKeyLabel", IDS_KEYBOARD_OVERLAY_VOL_DOWN_KEY_LABEL
},
78 { "keyboardOverlayVolUpKeyLabel", IDS_KEYBOARD_OVERLAY_VOL_UP_KEY_LABEL
},
79 { "keyboardOverlayPowerKeyLabel", IDS_KEYBOARD_OVERLAY_POWER_KEY_LABEL
},
80 { "keyboardOverlayBackspaceKeyLabel",
81 IDS_KEYBOARD_OVERLAY_BACKSPACE_KEY_LABEL
},
82 { "keyboardOverlayTabKeyLabel", IDS_KEYBOARD_OVERLAY_TAB_KEY_LABEL
},
83 { "keyboardOverlaySearchKeyLabel", IDS_KEYBOARD_OVERLAY_SEARCH_KEY_LABEL
},
84 { "keyboardOverlayEnterKeyLabel", IDS_KEYBOARD_OVERLAY_ENTER_KEY_LABEL
},
85 { "keyboardOverlayShiftKeyLabel", IDS_KEYBOARD_OVERLAY_SHIFT_KEY_LABEL
},
86 { "keyboardOverlayCtrlKeyLabel", IDS_KEYBOARD_OVERLAY_CTRL_KEY_LABEL
},
87 { "keyboardOverlayAltKeyLabel", IDS_KEYBOARD_OVERLAY_ALT_KEY_LABEL
},
88 { "keyboardOverlayLeftKeyLabel", IDS_KEYBOARD_OVERLAY_LEFT_KEY_LABEL
},
89 { "keyboardOverlayRightKeyLabel", IDS_KEYBOARD_OVERLAY_RIGHT_KEY_LABEL
},
90 { "keyboardOverlayUpKeyLabel", IDS_KEYBOARD_OVERLAY_UP_KEY_LABEL
},
91 { "keyboardOverlayDownKeyLabel", IDS_KEYBOARD_OVERLAY_DOWN_KEY_LABEL
},
92 { "keyboardOverlayInstructions", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS
},
93 { "keyboardOverlayInstructionsHide", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_HIDE
},
94 { "keyboardOverlayActivateLastShelfItem",
95 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_SHELF_ITEM
},
96 { "keyboardOverlayActivateLastTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_TAB
},
97 { "keyboardOverlayActivateShelfItem1",
98 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_1
},
99 { "keyboardOverlayActivateShelfItem2",
100 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_2
},
101 { "keyboardOverlayActivateShelfItem3",
102 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_3
},
103 { "keyboardOverlayActivateShelfItem4",
104 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_4
},
105 { "keyboardOverlayActivateShelfItem5",
106 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_5
},
107 { "keyboardOverlayActivateShelfItem6",
108 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_6
},
109 { "keyboardOverlayActivateShelfItem7",
110 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_7
},
111 { "keyboardOverlayActivateShelfItem8",
112 IDS_KEYBOARD_OVERLAY_ACTIVATE_SHELF_ITEM_8
},
113 { "keyboardOverlayActivateNextTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_NEXT_TAB
},
114 { "keyboardOverlayActivatePreviousTab",
115 IDS_KEYBOARD_OVERLAY_ACTIVATE_PREVIOUS_TAB
},
116 { "keyboardOverlayActivateTab1", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_1
},
117 { "keyboardOverlayActivateTab2", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_2
},
118 { "keyboardOverlayActivateTab3", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_3
},
119 { "keyboardOverlayActivateTab4", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_4
},
120 { "keyboardOverlayActivateTab5", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_5
},
121 { "keyboardOverlayActivateTab6", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_6
},
122 { "keyboardOverlayActivateTab7", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_7
},
123 { "keyboardOverlayActivateTab8", IDS_KEYBOARD_OVERLAY_ACTIVATE_TAB_8
},
124 { "keyboardOverlayAddWwwAndComAndOpenAddress",
125 IDS_KEYBOARD_OVERLAY_ADD_WWW_AND_COM_AND_OPEN_ADDRESS
},
126 { "keyboardOverlayBookmarkAllTabs", IDS_KEYBOARD_OVERLAY_BOOKMARK_ALL_TABS
},
127 { "keyboardOverlayBookmarkCurrentPage",
128 IDS_KEYBOARD_OVERLAY_BOOKMARK_CURRENT_PAGE
},
129 { "keyboardOverlayBookmarkManager", IDS_KEYBOARD_OVERLAY_BOOKMARK_MANAGER
},
130 { "keyboardOverlayCenterWindow", IDS_KEYBOARD_OVERLAY_CENTER_WINDOW
},
131 { "keyboardOverlayClearBrowsingDataDialog",
132 IDS_KEYBOARD_OVERLAY_CLEAR_BROWSING_DATA_DIALOG
},
133 { "keyboardOverlayCloseTab", IDS_KEYBOARD_OVERLAY_CLOSE_TAB
},
134 { "keyboardOverlayCloseWindow", IDS_KEYBOARD_OVERLAY_CLOSE_WINDOW
},
135 { "keyboardOverlayCopy", IDS_KEYBOARD_OVERLAY_COPY
},
136 { "keyboardOverlayCut", IDS_KEYBOARD_OVERLAY_CUT
},
137 { "keyboardOverlayCycleThroughInputMethods",
138 IDS_KEYBOARD_OVERLAY_CYCLE_THROUGH_INPUT_METHODS
},
139 { "keyboardOverlayDecreaseKeyBrightness",
140 IDS_KEYBOARD_OVERLAY_DECREASE_KEY_BRIGHTNESS
},
141 { "keyboardOverlayDelete", IDS_KEYBOARD_OVERLAY_DELETE
},
142 { "keyboardOverlayDeleteWord", IDS_KEYBOARD_OVERLAY_DELETE_WORD
},
143 { "keyboardOverlayDeveloperTools", IDS_KEYBOARD_OVERLAY_DEVELOPER_TOOLS
},
144 { "keyboardOverlayDockWindowLeft", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_LEFT
},
145 { "keyboardOverlayDockWindowRight", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_RIGHT
},
146 { "keyboardOverlayDomInspector", IDS_KEYBOARD_OVERLAY_DOM_INSPECTOR
},
147 { "keyboardOverlayDownloads", IDS_KEYBOARD_OVERLAY_DOWNLOADS
},
148 { "keyboardOverlayEnd", IDS_KEYBOARD_OVERLAY_END
},
149 { "keyboardOverlayF1", IDS_KEYBOARD_OVERLAY_F1
},
150 { "keyboardOverlayF10", IDS_KEYBOARD_OVERLAY_F10
},
151 { "keyboardOverlayF11", IDS_KEYBOARD_OVERLAY_F11
},
152 { "keyboardOverlayF12", IDS_KEYBOARD_OVERLAY_F12
},
153 { "keyboardOverlayF2", IDS_KEYBOARD_OVERLAY_F2
},
154 { "keyboardOverlayF3", IDS_KEYBOARD_OVERLAY_F3
},
155 { "keyboardOverlayF4", IDS_KEYBOARD_OVERLAY_F4
},
156 { "keyboardOverlayF5", IDS_KEYBOARD_OVERLAY_F5
},
157 { "keyboardOverlayF6", IDS_KEYBOARD_OVERLAY_F6
},
158 { "keyboardOverlayF7", IDS_KEYBOARD_OVERLAY_F7
},
159 { "keyboardOverlayF8", IDS_KEYBOARD_OVERLAY_F8
},
160 { "keyboardOverlayF9", IDS_KEYBOARD_OVERLAY_F9
},
161 { "keyboardOverlayFindPreviousText",
162 IDS_KEYBOARD_OVERLAY_FIND_PREVIOUS_TEXT
},
163 { "keyboardOverlayFindText", IDS_KEYBOARD_OVERLAY_FIND_TEXT
},
164 { "keyboardOverlayFindTextAgain", IDS_KEYBOARD_OVERLAY_FIND_TEXT_AGAIN
},
165 { "keyboardOverlayFocusAddressBar", IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR
},
166 { "keyboardOverlayFocusAddressBarInSearchMode",
167 IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR_IN_SEARCH_MODE
},
168 { "keyboardOverlayFocusBookmarks", IDS_KEYBOARD_OVERLAY_FOCUS_BOOKMARKS
},
169 { "keyboardOverlayFocusShelf", IDS_KEYBOARD_OVERLAY_FOCUS_SHELF
},
170 { "keyboardOverlayFocusNextPane", IDS_KEYBOARD_OVERLAY_FOCUS_NEXT_PANE
},
171 { "keyboardOverlayFocusPreviousPane",
172 IDS_KEYBOARD_OVERLAY_FOCUS_PREVIOUS_PANE
},
173 { "keyboardOverlayFocusToolbar", IDS_KEYBOARD_OVERLAY_FOCUS_TOOLBAR
},
174 { "keyboardOverlayGoBack", IDS_KEYBOARD_OVERLAY_GO_BACK
},
175 { "keyboardOverlayGoForward", IDS_KEYBOARD_OVERLAY_GO_FORWARD
},
176 { "keyboardOverlayHelp", IDS_KEYBOARD_OVERLAY_HELP
},
177 { "keyboardOverlayHistory", IDS_KEYBOARD_OVERLAY_HISTORY
},
178 { "keyboardOverlayHome", IDS_KEYBOARD_OVERLAY_HOME
},
179 { "keyboardOverlayIncreaseKeyBrightness",
180 IDS_KEYBOARD_OVERLAY_INCREASE_KEY_BRIGHTNESS
},
181 { "keyboardOverlayInputUnicodeCharacters",
182 IDS_KEYBOARD_OVERLAY_INPUT_UNICODE_CHARACTERS
},
183 { "keyboardOverlayInsert", IDS_KEYBOARD_OVERLAY_INSERT
},
184 { "keyboardOverlayJavascriptConsole",
185 IDS_KEYBOARD_OVERLAY_JAVASCRIPT_CONSOLE
},
186 { "keyboardOverlayLockScreen", IDS_KEYBOARD_OVERLAY_LOCK_SCREEN
},
187 { "keyboardOverlayLockScreenOrPowerOff",
188 IDS_KEYBOARD_OVERLAY_LOCK_SCREEN_OR_POWER_OFF
},
189 { "keyboardOverlayMagnifierDecreaseZoom",
190 IDS_KEYBOARD_OVERLAY_MAGNIFIER_DECREASE_ZOOM
},
191 { "keyboardOverlayMagnifierIncreaseZoom",
192 IDS_KEYBOARD_OVERLAY_MAGNIFIER_INCREASE_ZOOM
},
193 { "keyboardOverlayMaximizeWindow", IDS_KEYBOARD_OVERLAY_MAXIMIZE_WINDOW
},
194 { "keyboardOverlayMinimizeWindow", IDS_KEYBOARD_OVERLAY_MINIMIZE_WINDOW
},
195 { "keyboardOverlayMirrorMonitors", IDS_KEYBOARD_OVERLAY_MIRROR_MONITORS
},
196 { "keyboardOverlayNewIncognitoWindow",
197 IDS_KEYBOARD_OVERLAY_NEW_INCOGNITO_WINDOW
},
198 { "keyboardOverlayNewTab", IDS_KEYBOARD_OVERLAY_NEW_TAB
},
199 { "keyboardOverlayNewTerminal", IDS_KEYBOARD_OVERLAY_NEW_TERMINAL
},
200 { "keyboardOverlayNewWindow", IDS_KEYBOARD_OVERLAY_NEW_WINDOW
},
201 { "keyboardOverlayNextUser", IDS_KEYBOARD_OVERLAY_NEXT_USER
},
202 { "keyboardOverlayNextWindow", IDS_KEYBOARD_OVERLAY_NEXT_WINDOW
},
203 { "keyboardOverlayNextWord", IDS_KEYBOARD_OVERLAY_NEXT_WORD
},
204 { "keyboardOverlayOpen", IDS_KEYBOARD_OVERLAY_OPEN
},
205 { "keyboardOverlayOpenAddressInNewTab",
206 IDS_KEYBOARD_OVERLAY_OPEN_ADDRESS_IN_NEW_TAB
},
207 { "keyboardOverlayOpenFileManager", IDS_KEYBOARD_OVERLAY_OPEN_FILE_MANAGER
},
208 { "keyboardOverlayOpenGoogleCloudPrint",
209 IDS_KEYBOARD_OVERLAY_OPEN_GOOGLE_CLOUD_PRINT
},
210 { "keyboardOverlayPageDown", IDS_KEYBOARD_OVERLAY_PAGE_DOWN
},
211 { "keyboardOverlayPageUp", IDS_KEYBOARD_OVERLAY_PAGE_UP
},
212 { "keyboardOverlayPaste", IDS_KEYBOARD_OVERLAY_PASTE
},
213 { "keyboardOverlayPasteAsPlainText",
214 IDS_KEYBOARD_OVERLAY_PASTE_AS_PLAIN_TEXT
},
215 { "keyboardOverlayPreviousUser", IDS_KEYBOARD_OVERLAY_PREVIOUS_USER
},
216 { "keyboardOverlayPreviousWindow", IDS_KEYBOARD_OVERLAY_PREVIOUS_WINDOW
},
217 { "keyboardOverlayPreviousWord", IDS_KEYBOARD_OVERLAY_PREVIOUS_WORD
},
218 { "keyboardOverlayPrint", IDS_KEYBOARD_OVERLAY_PRINT
},
219 { "keyboardOverlayReloadCurrentPage",
220 IDS_KEYBOARD_OVERLAY_RELOAD_CURRENT_PAGE
},
221 { "keyboardOverlayReloadIgnoringCache",
222 IDS_KEYBOARD_OVERLAY_RELOAD_IGNORING_CACHE
},
223 { "keyboardOverlayReopenLastClosedTab",
224 IDS_KEYBOARD_OVERLAY_REOPEN_LAST_CLOSED_TAB
},
225 { "keyboardOverlayReportIssue", IDS_KEYBOARD_OVERLAY_REPORT_ISSUE
},
226 { "keyboardOverlayResetScreenZoom", IDS_KEYBOARD_OVERLAY_RESET_SCREEN_ZOOM
},
227 { "keyboardOverlayResetZoom", IDS_KEYBOARD_OVERLAY_RESET_ZOOM
},
228 { "keyboardOverlayRotateScreen", IDS_KEYBOARD_OVERLAY_ROTATE_SCREEN
},
229 { "keyboardOverlaySave", IDS_KEYBOARD_OVERLAY_SAVE
},
230 { "keyboardOverlayScreenshotRegion",
231 IDS_KEYBOARD_OVERLAY_SCREENSHOT_REGION
},
232 { "keyboardOverlayScrollUpOnePage",
233 IDS_KEYBOARD_OVERLAY_SCROLL_UP_ONE_PAGE
},
234 { "keyboardOverlaySelectAll", IDS_KEYBOARD_OVERLAY_SELECT_ALL
},
235 { "keyboardOverlaySelectPreviousInputMethod",
236 IDS_KEYBOARD_OVERLAY_SELECT_PREVIOUS_INPUT_METHOD
},
237 { "keyboardOverlaySelectWordAtATime",
238 IDS_KEYBOARD_OVERLAY_SELECT_WORD_AT_A_TIME
},
239 { "keyboardOverlayShowMessageCenter",
240 IDS_KEYBOARD_OVERLAY_SHOW_MESSAGE_CENTER
},
241 { "keyboardOverlayShowStatusMenu", IDS_KEYBOARD_OVERLAY_SHOW_STATUS_MENU
},
242 { "keyboardOverlayShowWrenchMenu", IDS_KEYBOARD_OVERLAY_SHOW_WRENCH_MENU
},
243 { "keyboardOverlaySignOut", IDS_KEYBOARD_OVERLAY_SIGN_OUT
},
244 { "keyboardOverlaySwapPrimaryMonitor",
245 IDS_KEYBOARD_OVERLAY_SWAP_PRIMARY_MONITOR
},
246 { "keyboardOverlayTakeScreenshot", IDS_KEYBOARD_OVERLAY_TAKE_SCREENSHOT
},
247 { "keyboardOverlayTaskManager", IDS_KEYBOARD_OVERLAY_TASK_MANAGER
},
248 { "keyboardOverlayToggleBookmarkBar",
249 IDS_KEYBOARD_OVERLAY_TOGGLE_BOOKMARK_BAR
},
250 { "keyboardOverlayToggleCapsLock", IDS_KEYBOARD_OVERLAY_TOGGLE_CAPS_LOCK
},
251 { "keyboardOverlayDisableCapsLock", IDS_KEYBOARD_OVERLAY_DISABLE_CAPS_LOCK
},
252 { "keyboardOverlayToggleChromevoxSpokenFeedback",
253 IDS_KEYBOARD_OVERLAY_TOGGLE_CHROMEVOX_SPOKEN_FEEDBACK
},
254 { "keyboardOverlayToggleProjectionTouchHud",
255 IDS_KEYBOARD_OVERLAY_TOGGLE_PROJECTION_TOUCH_HUD
},
256 { "keyboardOverlayToggleSpeechInput",
257 IDS_KEYBOARD_OVERLAY_TOGGLE_SPEECH_INPUT
},
258 { "keyboardOverlayUndo", IDS_KEYBOARD_OVERLAY_UNDO
},
259 { "keyboardOverlayViewKeyboardOverlay",
260 IDS_KEYBOARD_OVERLAY_VIEW_KEYBOARD_OVERLAY
},
261 { "keyboardOverlayViewSource", IDS_KEYBOARD_OVERLAY_VIEW_SOURCE
},
262 { "keyboardOverlayWordMove", IDS_KEYBOARD_OVERLAY_WORD_MOVE
},
263 { "keyboardOverlayZoomIn", IDS_KEYBOARD_OVERLAY_ZOOM_IN
},
264 { "keyboardOverlayZoomOut", IDS_KEYBOARD_OVERLAY_ZOOM_OUT
},
265 { "keyboardOverlayZoomScreenIn", IDS_KEYBOARD_OVERLAY_ZOOM_SCREEN_IN
},
266 { "keyboardOverlayZoomScreenOut", IDS_KEYBOARD_OVERLAY_ZOOM_SCREEN_OUT
},
269 std::string
ModifierKeyToLabel(ModifierKey modifier
) {
270 for (size_t i
= 0; i
< arraysize(kModifierToLabels
); ++i
) {
271 if (modifier
== kModifierToLabels
[i
].modifier
) {
272 return kModifierToLabels
[i
].label
;
278 content::WebUIDataSource
* CreateKeyboardOverlayUIHTMLSource() {
279 content::WebUIDataSource
* source
=
280 content::WebUIDataSource::Create(chrome::kChromeUIKeyboardOverlayHost
);
282 for (size_t i
= 0; i
< arraysize(kI18nContentToMessage
); ++i
) {
283 source
->AddLocalizedString(kI18nContentToMessage
[i
].i18n_content
,
284 kI18nContentToMessage
[i
].message
);
287 source
->AddString("keyboardOverlayLearnMoreURL",
288 base::UTF8ToUTF16(kLearnMoreURL
));
289 source
->AddBoolean("keyboardOverlayHasChromeOSDiamondKey",
290 base::CommandLine::ForCurrentProcess()->HasSwitch(
291 chromeos::switches::kHasChromeOSDiamondKey
));
292 ash::Shell
* shell
= ash::Shell::GetInstance();
293 ash::DisplayManager
* display_manager
= shell
->display_manager();
294 source
->AddBoolean("keyboardOverlayIsDisplayUIScalingEnabled",
295 display_manager
->IsDisplayUIScalingEnabled());
296 source
->SetJsonPath("strings.js");
297 source
->AddResourcePath("keyboard_overlay.js", IDR_KEYBOARD_OVERLAY_JS
);
298 source
->SetDefaultResource(IDR_KEYBOARD_OVERLAY_HTML
);
304 // The handler for Javascript messages related to the "keyboardoverlay" view.
305 class KeyboardOverlayHandler
306 : public WebUIMessageHandler
,
307 public base::SupportsWeakPtr
<KeyboardOverlayHandler
> {
309 explicit KeyboardOverlayHandler(Profile
* profile
);
310 ~KeyboardOverlayHandler() override
;
312 // WebUIMessageHandler implementation.
313 void RegisterMessages() override
;
316 // Called when the page requires the input method ID corresponding to the
317 // current input method or keyboard layout during initialization.
318 void GetInputMethodId(const base::ListValue
* args
);
320 // Called when the page requres the information of modifier key remapping
321 // during the initialization.
322 void GetLabelMap(const base::ListValue
* args
);
324 // Called when the learn more link is clicked.
325 void OpenLearnMorePage(const base::ListValue
* args
);
329 DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayHandler
);
332 ////////////////////////////////////////////////////////////////////////////////
334 // KeyboardOverlayHandler
336 ////////////////////////////////////////////////////////////////////////////////
337 KeyboardOverlayHandler::KeyboardOverlayHandler(Profile
* profile
)
338 : profile_(profile
) {
341 KeyboardOverlayHandler::~KeyboardOverlayHandler() {
344 void KeyboardOverlayHandler::RegisterMessages() {
345 web_ui()->RegisterMessageCallback("getInputMethodId",
346 base::Bind(&KeyboardOverlayHandler::GetInputMethodId
,
347 base::Unretained(this)));
348 web_ui()->RegisterMessageCallback("getLabelMap",
349 base::Bind(&KeyboardOverlayHandler::GetLabelMap
,
350 base::Unretained(this)));
351 web_ui()->RegisterMessageCallback("openLearnMorePage",
352 base::Bind(&KeyboardOverlayHandler::OpenLearnMorePage
,
353 base::Unretained(this)));
356 void KeyboardOverlayHandler::GetInputMethodId(const base::ListValue
* args
) {
357 chromeos::input_method::InputMethodManager
* manager
=
358 chromeos::input_method::InputMethodManager::Get();
359 const chromeos::input_method::InputMethodDescriptor
& descriptor
=
360 manager
->GetActiveIMEState()->GetCurrentInputMethod();
361 base::StringValue
param(descriptor
.id());
362 web_ui()->CallJavascriptFunction("initKeyboardOverlayId", param
);
365 void KeyboardOverlayHandler::GetLabelMap(const base::ListValue
* args
) {
367 PrefService
* pref_service
= profile_
->GetPrefs();
368 typedef std::map
<ModifierKey
, ModifierKey
> ModifierMap
;
369 ModifierMap modifier_map
;
370 modifier_map
[chromeos::input_method::kSearchKey
] = static_cast<ModifierKey
>(
371 pref_service
->GetInteger(prefs::kLanguageRemapSearchKeyTo
));
372 modifier_map
[chromeos::input_method::kControlKey
] = static_cast<ModifierKey
>(
373 pref_service
->GetInteger(prefs::kLanguageRemapControlKeyTo
));
374 modifier_map
[chromeos::input_method::kAltKey
] = static_cast<ModifierKey
>(
375 pref_service
->GetInteger(prefs::kLanguageRemapAltKeyTo
));
376 // TODO(mazda): Support prefs::kLanguageRemapCapsLockKeyTo once Caps Lock is
377 // added to the overlay UI.
379 base::DictionaryValue dict
;
380 for (ModifierMap::const_iterator i
= modifier_map
.begin();
381 i
!= modifier_map
.end(); ++i
) {
382 dict
.SetString(ModifierKeyToLabel(i
->first
), ModifierKeyToLabel(i
->second
));
385 web_ui()->CallJavascriptFunction("initIdentifierMap", dict
);
388 void KeyboardOverlayHandler::OpenLearnMorePage(const base::ListValue
* args
) {
389 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab(
390 web_ui()->GetWebContents(),
391 content::OpenURLParams(GURL(kLearnMoreURL
),
394 ui::PAGE_TRANSITION_LINK
,
398 ////////////////////////////////////////////////////////////////////////////////
402 ////////////////////////////////////////////////////////////////////////////////
404 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI
* web_ui
)
405 : WebDialogUI(web_ui
) {
406 Profile
* profile
= Profile::FromWebUI(web_ui
);
407 KeyboardOverlayHandler
* handler
= new KeyboardOverlayHandler(profile
);
408 web_ui
->AddMessageHandler(handler
);
410 // Set up the chrome://keyboardoverlay/ source.
411 content::WebUIDataSource::Add(profile
, CreateKeyboardOverlayUIHTMLSource());