| 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 "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" | 16 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" |
| 17 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 17 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 18 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 18 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 19 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 19 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 20 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 20 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 21 #include "chrome/browser/spellchecker/spellcheck_service.h" | 21 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 23 #include "chrome/common/extensions/api/input_method_private.h" | 23 #include "chrome/common/extensions/api/input_method_private.h" |
| 24 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 25 #include "components/browser_sync/browser/profile_sync_service.h" | 25 #include "components/browser_sync/browser/profile_sync_service.h" |
| 26 #include "extensions/browser/extension_function_registry.h" | 26 #include "extensions/browser/extension_function_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 28 #include "ui/base/ime/chromeos/extension_ime_util.h" | 28 #include "ui/base/ime/chromeos/extension_ime_util.h" |
| 29 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 29 #include "ui/base/ime/chromeos/input_method_descriptor.h" | 30 #include "ui/base/ime/chromeos/input_method_descriptor.h" |
| 30 #include "ui/base/ime/chromeos/input_method_manager.h" | 31 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 31 #include "ui/keyboard/keyboard_util.h" | 32 #include "ui/keyboard/keyboard_util.h" |
| 32 | 33 |
| 33 namespace AddWordToDictionary = | 34 namespace AddWordToDictionary = |
| 34 extensions::api::input_method_private::AddWordToDictionary; | 35 extensions::api::input_method_private::AddWordToDictionary; |
| 35 namespace SetCurrentInputMethod = | 36 namespace SetCurrentInputMethod = |
| 36 extensions::api::input_method_private::SetCurrentInputMethod; | 37 extensions::api::input_method_private::SetCurrentInputMethod; |
| 38 namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout; |
| 37 namespace OnChanged = extensions::api::input_method_private::OnChanged; | 39 namespace OnChanged = extensions::api::input_method_private::OnChanged; |
| 38 namespace OnDictionaryChanged = | 40 namespace OnDictionaryChanged = |
| 39 extensions::api::input_method_private::OnDictionaryChanged; | 41 extensions::api::input_method_private::OnDictionaryChanged; |
| 40 namespace OnDictionaryLoaded = | 42 namespace OnDictionaryLoaded = |
| 41 extensions::api::input_method_private::OnDictionaryLoaded; | 43 extensions::api::input_method_private::OnDictionaryLoaded; |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 // Prefix, which is used by XKB. | 47 // Prefix, which is used by XKB. |
| 46 const char kXkbPrefix[] = "xkb:"; | 48 const char kXkbPrefix[] = "xkb:"; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ProfileSyncServiceFactory::GetForProfile( | 190 ProfileSyncServiceFactory::GetForProfile( |
| 189 Profile::FromBrowserContext(browser_context())); | 191 Profile::FromBrowserContext(browser_context())); |
| 190 if (!profile_sync_service) | 192 if (!profile_sync_service) |
| 191 return RespondNow(Error("Sync service is not ready for current profile.")); | 193 return RespondNow(Error("Sync service is not ready for current profile.")); |
| 192 scoped_ptr<base::Value> ret(new base::FundamentalValue( | 194 scoped_ptr<base::Value> ret(new base::FundamentalValue( |
| 193 profile_sync_service->IsEncryptEverythingEnabled())); | 195 profile_sync_service->IsEncryptEverythingEnabled())); |
| 194 return RespondNow(OneArgument(std::move(ret))); | 196 return RespondNow(OneArgument(std::move(ret))); |
| 195 #endif | 197 #endif |
| 196 } | 198 } |
| 197 | 199 |
| 200 ExtensionFunction::ResponseAction |
| 201 InputMethodPrivateSetXkbLayoutFunction::Run() { |
| 202 #if !defined(OS_CHROMEOS) |
| 203 EXTENSION_FUNCTION_VALIDATE(false); |
| 204 #else |
| 205 scoped_ptr<SetXkbLayout::Params> params(SetXkbLayout::Params::Create(*args_)); |
| 206 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 207 chromeos::input_method::InputMethodManager* manager = |
| 208 chromeos::input_method::InputMethodManager::Get(); |
| 209 chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); |
| 210 keyboard->SetCurrentKeyboardLayoutByName(params->xkb_name); |
| 211 return RespondNow(NoArguments()); |
| 212 #endif |
| 213 } |
| 214 |
| 198 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) | 215 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) |
| 199 : context_(context) { | 216 : context_(context) { |
| 200 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); | 217 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); |
| 201 EventRouter::Get(context_) | 218 EventRouter::Get(context_) |
| 202 ->RegisterObserver(this, OnDictionaryChanged::kEventName); | 219 ->RegisterObserver(this, OnDictionaryChanged::kEventName); |
| 203 EventRouter::Get(context_) | 220 EventRouter::Get(context_) |
| 204 ->RegisterObserver(this, OnDictionaryLoaded::kEventName); | 221 ->RegisterObserver(this, OnDictionaryLoaded::kEventName); |
| 205 ExtensionFunctionRegistry* registry = | 222 ExtensionFunctionRegistry* registry = |
| 206 ExtensionFunctionRegistry::GetInstance(); | 223 ExtensionFunctionRegistry::GetInstance(); |
| 207 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>(); | 224 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 268 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
| 252 g_factory = LAZY_INSTANCE_INITIALIZER; | 269 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 253 | 270 |
| 254 // static | 271 // static |
| 255 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 272 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
| 256 InputMethodAPI::GetFactoryInstance() { | 273 InputMethodAPI::GetFactoryInstance() { |
| 257 return g_factory.Pointer(); | 274 return g_factory.Pointer(); |
| 258 } | 275 } |
| 259 | 276 |
| 260 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |