| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 base::Bind(&KeyboardOverlayHandler::OpenLearnMorePage, | 367 base::Bind(&KeyboardOverlayHandler::OpenLearnMorePage, |
| 368 base::Unretained(this))); | 368 base::Unretained(this))); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void KeyboardOverlayHandler::GetInputMethodId(const base::ListValue* args) { | 371 void KeyboardOverlayHandler::GetInputMethodId(const base::ListValue* args) { |
| 372 chromeos::input_method::InputMethodManager* manager = | 372 chromeos::input_method::InputMethodManager* manager = |
| 373 chromeos::input_method::InputMethodManager::Get(); | 373 chromeos::input_method::InputMethodManager::Get(); |
| 374 const chromeos::input_method::InputMethodDescriptor& descriptor = | 374 const chromeos::input_method::InputMethodDescriptor& descriptor = |
| 375 manager->GetActiveIMEState()->GetCurrentInputMethod(); | 375 manager->GetActiveIMEState()->GetCurrentInputMethod(); |
| 376 base::StringValue param(descriptor.id()); | 376 base::StringValue param(descriptor.id()); |
| 377 web_ui()->CallJavascriptFunction("initKeyboardOverlayId", param); | 377 web_ui()->CallJavascriptFunctionUnsafe("initKeyboardOverlayId", param); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void KeyboardOverlayHandler::GetLabelMap(const base::ListValue* args) { | 380 void KeyboardOverlayHandler::GetLabelMap(const base::ListValue* args) { |
| 381 DCHECK(profile_); | 381 DCHECK(profile_); |
| 382 PrefService* pref_service = profile_->GetPrefs(); | 382 PrefService* pref_service = profile_->GetPrefs(); |
| 383 typedef std::map<ModifierKey, ModifierKey> ModifierMap; | 383 typedef std::map<ModifierKey, ModifierKey> ModifierMap; |
| 384 ModifierMap modifier_map; | 384 ModifierMap modifier_map; |
| 385 modifier_map[chromeos::input_method::kSearchKey] = static_cast<ModifierKey>( | 385 modifier_map[chromeos::input_method::kSearchKey] = static_cast<ModifierKey>( |
| 386 pref_service->GetInteger(prefs::kLanguageRemapSearchKeyTo)); | 386 pref_service->GetInteger(prefs::kLanguageRemapSearchKeyTo)); |
| 387 modifier_map[chromeos::input_method::kControlKey] = static_cast<ModifierKey>( | 387 modifier_map[chromeos::input_method::kControlKey] = static_cast<ModifierKey>( |
| 388 pref_service->GetInteger(prefs::kLanguageRemapControlKeyTo)); | 388 pref_service->GetInteger(prefs::kLanguageRemapControlKeyTo)); |
| 389 modifier_map[chromeos::input_method::kAltKey] = static_cast<ModifierKey>( | 389 modifier_map[chromeos::input_method::kAltKey] = static_cast<ModifierKey>( |
| 390 pref_service->GetInteger(prefs::kLanguageRemapAltKeyTo)); | 390 pref_service->GetInteger(prefs::kLanguageRemapAltKeyTo)); |
| 391 // TODO(mazda): Support prefs::kLanguageRemapCapsLockKeyTo once Caps Lock is | 391 // TODO(mazda): Support prefs::kLanguageRemapCapsLockKeyTo once Caps Lock is |
| 392 // added to the overlay UI. | 392 // added to the overlay UI. |
| 393 | 393 |
| 394 base::DictionaryValue dict; | 394 base::DictionaryValue dict; |
| 395 for (ModifierMap::const_iterator i = modifier_map.begin(); | 395 for (ModifierMap::const_iterator i = modifier_map.begin(); |
| 396 i != modifier_map.end(); ++i) { | 396 i != modifier_map.end(); ++i) { |
| 397 dict.SetString(ModifierKeyToLabel(i->first), ModifierKeyToLabel(i->second)); | 397 dict.SetString(ModifierKeyToLabel(i->first), ModifierKeyToLabel(i->second)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 web_ui()->CallJavascriptFunction("initIdentifierMap", dict); | 400 web_ui()->CallJavascriptFunctionUnsafe("initIdentifierMap", dict); |
| 401 } | 401 } |
| 402 | 402 |
| 403 void KeyboardOverlayHandler::OpenLearnMorePage(const base::ListValue* args) { | 403 void KeyboardOverlayHandler::OpenLearnMorePage(const base::ListValue* args) { |
| 404 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab( | 404 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab( |
| 405 web_ui()->GetWebContents(), | 405 web_ui()->GetWebContents(), |
| 406 content::OpenURLParams(GURL(kLearnMoreURL), | 406 content::OpenURLParams(GURL(kLearnMoreURL), |
| 407 content::Referrer(), | 407 content::Referrer(), |
| 408 NEW_FOREGROUND_TAB, | 408 NEW_FOREGROUND_TAB, |
| 409 ui::PAGE_TRANSITION_LINK, | 409 ui::PAGE_TRANSITION_LINK, |
| 410 false)); | 410 false)); |
| 411 } | 411 } |
| 412 | 412 |
| 413 //////////////////////////////////////////////////////////////////////////////// | 413 //////////////////////////////////////////////////////////////////////////////// |
| 414 // | 414 // |
| 415 // KeyboardOverlayUI | 415 // KeyboardOverlayUI |
| 416 // | 416 // |
| 417 //////////////////////////////////////////////////////////////////////////////// | 417 //////////////////////////////////////////////////////////////////////////////// |
| 418 | 418 |
| 419 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI* web_ui) | 419 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI* web_ui) |
| 420 : WebDialogUI(web_ui) { | 420 : WebDialogUI(web_ui) { |
| 421 Profile* profile = Profile::FromWebUI(web_ui); | 421 Profile* profile = Profile::FromWebUI(web_ui); |
| 422 KeyboardOverlayHandler* handler = new KeyboardOverlayHandler(profile); | 422 KeyboardOverlayHandler* handler = new KeyboardOverlayHandler(profile); |
| 423 web_ui->AddMessageHandler(handler); | 423 web_ui->AddMessageHandler(handler); |
| 424 | 424 |
| 425 // Set up the chrome://keyboardoverlay/ source. | 425 // Set up the chrome://keyboardoverlay/ source. |
| 426 content::WebUIDataSource::Add(profile, | 426 content::WebUIDataSource::Add(profile, |
| 427 CreateKeyboardOverlayUIHTMLSource(profile)); | 427 CreateKeyboardOverlayUIHTMLSource(profile)); |
| 428 } | 428 } |
| OLD | NEW |