Chromium Code Reviews| 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/chromeos/extensions/input_method_api.h" | 5 #include "chrome/browser/chromeos/extensions/input_method_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" | 17 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" |
| 18 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" | 18 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" |
| 19 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 19 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 21 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 21 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 23 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 24 #include "chrome/browser/spellchecker/spellcheck_service.h" | 24 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 26 #include "chrome/browser/ui/browser.h" | |
| 27 #include "chrome/browser/ui/browser_finder.h" | |
| 26 #include "chrome/common/chrome_features.h" | 28 #include "chrome/common/chrome_features.h" |
| 27 #include "chrome/common/extensions/api/input_method_private.h" | 29 #include "chrome/common/extensions/api/input_method_private.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "chromeos/chromeos_switches.h" | 31 #include "chromeos/chromeos_switches.h" |
| 30 #include "components/browser_sync/browser/profile_sync_service.h" | 32 #include "components/browser_sync/browser/profile_sync_service.h" |
| 31 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
| 32 #include "extensions/browser/extension_function_registry.h" | 34 #include "extensions/browser/extension_function_registry.h" |
| 33 #include "extensions/browser/extension_system.h" | 35 #include "extensions/browser/extension_system.h" |
| 34 #include "ui/base/ime/chromeos/extension_ime_util.h" | 36 #include "ui/base/ime/chromeos/extension_ime_util.h" |
| 35 #include "ui/base/ime/chromeos/ime_keyboard.h" | 37 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 36 #include "ui/base/ime/chromeos/input_method_descriptor.h" | 38 #include "ui/base/ime/chromeos/input_method_descriptor.h" |
| 37 #include "ui/base/ime/chromeos/input_method_manager.h" | 39 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 38 #include "ui/keyboard/keyboard_controller.h" | 40 #include "ui/keyboard/keyboard_controller.h" |
| 39 #include "ui/keyboard/keyboard_util.h" | 41 #include "ui/keyboard/keyboard_util.h" |
| 40 | 42 |
| 41 namespace AddWordToDictionary = | 43 namespace AddWordToDictionary = |
| 42 extensions::api::input_method_private::AddWordToDictionary; | 44 extensions::api::input_method_private::AddWordToDictionary; |
| 43 namespace SetCurrentInputMethod = | 45 namespace SetCurrentInputMethod = |
| 44 extensions::api::input_method_private::SetCurrentInputMethod; | 46 extensions::api::input_method_private::SetCurrentInputMethod; |
| 45 namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout; | 47 namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout; |
| 48 namespace OpenOptionsPage = | |
| 49 extensions::api::input_method_private::OpenOptionsPage; | |
| 46 namespace OnChanged = extensions::api::input_method_private::OnChanged; | 50 namespace OnChanged = extensions::api::input_method_private::OnChanged; |
| 47 namespace OnDictionaryChanged = | 51 namespace OnDictionaryChanged = |
| 48 extensions::api::input_method_private::OnDictionaryChanged; | 52 extensions::api::input_method_private::OnDictionaryChanged; |
| 49 namespace OnDictionaryLoaded = | 53 namespace OnDictionaryLoaded = |
| 50 extensions::api::input_method_private::OnDictionaryLoaded; | 54 extensions::api::input_method_private::OnDictionaryLoaded; |
| 51 namespace OnImeMenuActivationChanged = | 55 namespace OnImeMenuActivationChanged = |
| 52 extensions::api::input_method_private::OnImeMenuActivationChanged; | 56 extensions::api::input_method_private::OnImeMenuActivationChanged; |
| 53 namespace OnImeMenuListChanged = | 57 namespace OnImeMenuListChanged = |
| 54 extensions::api::input_method_private::OnImeMenuListChanged; | 58 extensions::api::input_method_private::OnImeMenuListChanged; |
| 55 namespace OnImeMenuItemsChanged = | 59 namespace OnImeMenuItemsChanged = |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 if (!keyboard_controller) { | 260 if (!keyboard_controller) { |
| 257 keyboard::SetAccessibilityKeyboardEnabled(false); | 261 keyboard::SetAccessibilityKeyboardEnabled(false); |
| 258 return RespondNow(Error(kErrorFailToShowInputView)); | 262 return RespondNow(Error(kErrorFailToShowInputView)); |
| 259 } | 263 } |
| 260 keyboard_controller->ShowKeyboard(false); | 264 keyboard_controller->ShowKeyboard(false); |
| 261 keyboard::SetAccessibilityKeyboardEnabled(false); | 265 keyboard::SetAccessibilityKeyboardEnabled(false); |
| 262 return RespondNow(NoArguments()); | 266 return RespondNow(NoArguments()); |
| 263 #endif | 267 #endif |
| 264 } | 268 } |
| 265 | 269 |
| 270 ExtensionFunction::ResponseAction | |
| 271 InputMethodPrivateOpenOptionsPageFunction::Run() { | |
| 272 #if !defined(OS_CHROMEOS) | |
| 273 EXTENSION_FUNCTION_VALIDATE(false); | |
| 274 #else | |
| 275 std::unique_ptr<OpenOptionsPage::Params> params( | |
| 276 OpenOptionsPage::Params::Create(*args_)); | |
| 277 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 278 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = | |
| 279 chromeos::input_method::InputMethodManager::Get()->GetActiveIMEState(); | |
| 280 const chromeos::input_method::InputMethodDescriptor* ime = | |
| 281 ime_state->GetInputMethodFromId(params->input_method_id); | |
| 282 if (!ime) | |
| 283 return RespondNow(NoArguments()); | |
|
Shu Chen
2016/04/20 06:38:33
This should be an error:
return RespondNow(Error
michaelpg
2016/04/20 08:09:08
Done.
| |
| 284 | |
| 285 content::WebContents* web_contents = GetSenderWebContents(); | |
| 286 if (web_contents) { | |
| 287 const GURL& options_page_url = ime->options_page_url(); | |
| 288 if (!options_page_url.is_empty()) { | |
| 289 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 290 content::OpenURLParams url_params(options_page_url, content::Referrer(), | |
| 291 SINGLETON_TAB, ui::PAGE_TRANSITION_LINK, | |
| 292 false); | |
| 293 browser->OpenURL(url_params); | |
| 294 } | |
| 295 } | |
| 296 return RespondNow(NoArguments()); | |
| 297 #endif | |
| 298 } | |
| 299 | |
| 266 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) | 300 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) |
| 267 : context_(context) { | 301 : context_(context) { |
| 268 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); | 302 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); |
| 269 EventRouter::Get(context_) | 303 EventRouter::Get(context_) |
| 270 ->RegisterObserver(this, OnDictionaryChanged::kEventName); | 304 ->RegisterObserver(this, OnDictionaryChanged::kEventName); |
| 271 EventRouter::Get(context_) | 305 EventRouter::Get(context_) |
| 272 ->RegisterObserver(this, OnDictionaryLoaded::kEventName); | 306 ->RegisterObserver(this, OnDictionaryLoaded::kEventName); |
| 273 EventRouter::Get(context_) | 307 EventRouter::Get(context_) |
| 274 ->RegisterObserver(this, OnImeMenuActivationChanged::kEventName); | 308 ->RegisterObserver(this, OnImeMenuActivationChanged::kEventName); |
| 275 EventRouter::Get(context_) | 309 EventRouter::Get(context_) |
| 276 ->RegisterObserver(this, OnImeMenuListChanged::kEventName); | 310 ->RegisterObserver(this, OnImeMenuListChanged::kEventName); |
| 277 EventRouter::Get(context_) | 311 EventRouter::Get(context_) |
| 278 ->RegisterObserver(this, OnImeMenuItemsChanged::kEventName); | 312 ->RegisterObserver(this, OnImeMenuItemsChanged::kEventName); |
| 279 ExtensionFunctionRegistry* registry = | 313 ExtensionFunctionRegistry* registry = |
| 280 ExtensionFunctionRegistry::GetInstance(); | 314 ExtensionFunctionRegistry::GetInstance(); |
| 281 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>(); | 315 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>(); |
| 282 registry->RegisterFunction<InputMethodPrivateGetCurrentInputMethodFunction>(); | 316 registry->RegisterFunction<InputMethodPrivateGetCurrentInputMethodFunction>(); |
| 283 registry->RegisterFunction<InputMethodPrivateSetCurrentInputMethodFunction>(); | 317 registry->RegisterFunction<InputMethodPrivateSetCurrentInputMethodFunction>(); |
| 284 registry->RegisterFunction<InputMethodPrivateGetInputMethodsFunction>(); | 318 registry->RegisterFunction<InputMethodPrivateGetInputMethodsFunction>(); |
| 285 registry | 319 registry |
| 286 ->RegisterFunction<InputMethodPrivateFetchAllDictionaryWordsFunction>(); | 320 ->RegisterFunction<InputMethodPrivateFetchAllDictionaryWordsFunction>(); |
| 287 registry->RegisterFunction<InputMethodPrivateAddWordToDictionaryFunction>(); | 321 registry->RegisterFunction<InputMethodPrivateAddWordToDictionaryFunction>(); |
| 288 registry->RegisterFunction<InputMethodPrivateGetEncryptSyncEnabledFunction>(); | 322 registry->RegisterFunction<InputMethodPrivateGetEncryptSyncEnabledFunction>(); |
| 289 registry->RegisterFunction< | 323 registry->RegisterFunction< |
| 290 InputMethodPrivateNotifyImeMenuItemActivatedFunction>(); | 324 InputMethodPrivateNotifyImeMenuItemActivatedFunction>(); |
| 325 registry->RegisterFunction<InputMethodPrivateOpenOptionsPageFunction>(); | |
| 291 } | 326 } |
| 292 | 327 |
| 293 InputMethodAPI::~InputMethodAPI() { | 328 InputMethodAPI::~InputMethodAPI() { |
| 294 } | 329 } |
| 295 | 330 |
| 296 // static | 331 // static |
| 297 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 332 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
| 298 std::string xkb_prefix = | 333 std::string xkb_prefix = |
| 299 chromeos::extension_ime_util::GetInputMethodIDByEngineID(kXkbPrefix); | 334 chromeos::extension_ime_util::GetInputMethodIDByEngineID(kXkbPrefix); |
| 300 size_t prefix_length = xkb_prefix.length(); | 335 size_t prefix_length = xkb_prefix.length(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 368 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
| 334 g_factory = LAZY_INSTANCE_INITIALIZER; | 369 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 335 | 370 |
| 336 // static | 371 // static |
| 337 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 372 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
| 338 InputMethodAPI::GetFactoryInstance() { | 373 InputMethodAPI::GetFactoryInstance() { |
| 339 return g_factory.Pointer(); | 374 return g_factory.Pointer(); |
| 340 } | 375 } |
| 341 | 376 |
| 342 } // namespace extensions | 377 } // namespace extensions |
| OLD | NEW |