| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 11 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 11 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 12 #include "chromeos/ime/extension_ime_util.h" | 12 #include "chromeos/ime/extension_ime_util.h" |
| 13 #include "chromeos/ime/input_method_descriptor.h" | 13 #include "chromeos/ime/input_method_descriptor.h" |
| 14 #include "chromeos/ime/input_method_manager.h" | 14 #include "chromeos/ime/input_method_manager.h" |
| 15 #include "extensions/browser/extension_function_registry.h" | 15 #include "extensions/browser/extension_function_registry.h" |
| 16 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/common/value_builder.h" | 17 #include "extensions/common/value_builder.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Prefix, which is used by XKB. | 21 // Prefix, which is used by XKB. |
| 22 const char kXkbPrefix[] = "xkb:"; | 22 const char kXkbPrefix[] = "xkb:"; |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 ExtensionFunction::ResponseAction GetInputMethodConfigFunction::Run() { |
| 29 #if !defined(OS_CHROMEOS) |
| 30 EXTENSION_FUNCTION_VALIDATE(false); |
| 31 #else |
| 32 bool isExperimental = chromeos::input_method::InputMethodManager:: |
| 33 IsExperimentalImeFeaturesEnabled(); |
| 34 base::DictionaryValue* output = new base::DictionaryValue(); |
| 35 output->SetBoolean("isExperimentalEnabled", isExperimental); |
| 36 return RespondNow(OneArgument(output)); |
| 37 #endif |
| 38 } |
| 39 |
| 28 ExtensionFunction::ResponseAction GetCurrentInputMethodFunction::Run() { | 40 ExtensionFunction::ResponseAction GetCurrentInputMethodFunction::Run() { |
| 29 #if !defined(OS_CHROMEOS) | 41 #if !defined(OS_CHROMEOS) |
| 30 EXTENSION_FUNCTION_VALIDATE(false); | 42 EXTENSION_FUNCTION_VALIDATE(false); |
| 31 #else | 43 #else |
| 32 chromeos::input_method::InputMethodManager* manager = | 44 chromeos::input_method::InputMethodManager* manager = |
| 33 chromeos::input_method::InputMethodManager::Get(); | 45 chromeos::input_method::InputMethodManager::Get(); |
| 34 return RespondNow(OneArgument(new base::StringValue( | 46 return RespondNow(OneArgument(new base::StringValue( |
| 35 manager->GetActiveIMEState()->GetCurrentInputMethod().id()))); | 47 manager->GetActiveIMEState()->GetCurrentInputMethod().id()))); |
| 36 #endif | 48 #endif |
| 37 } | 49 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 96 |
| 85 // static | 97 // static |
| 86 const char InputMethodAPI::kOnInputMethodChanged[] = | 98 const char InputMethodAPI::kOnInputMethodChanged[] = |
| 87 "inputMethodPrivate.onChanged"; | 99 "inputMethodPrivate.onChanged"; |
| 88 | 100 |
| 89 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) | 101 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) |
| 90 : context_(context) { | 102 : context_(context) { |
| 91 EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged); | 103 EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged); |
| 92 ExtensionFunctionRegistry* registry = | 104 ExtensionFunctionRegistry* registry = |
| 93 ExtensionFunctionRegistry::GetInstance(); | 105 ExtensionFunctionRegistry::GetInstance(); |
| 106 registry->RegisterFunction<GetInputMethodConfigFunction>(); |
| 94 registry->RegisterFunction<GetCurrentInputMethodFunction>(); | 107 registry->RegisterFunction<GetCurrentInputMethodFunction>(); |
| 95 registry->RegisterFunction<SetCurrentInputMethodFunction>(); | 108 registry->RegisterFunction<SetCurrentInputMethodFunction>(); |
| 96 registry->RegisterFunction<GetInputMethodsFunction>(); | 109 registry->RegisterFunction<GetInputMethodsFunction>(); |
| 97 } | 110 } |
| 98 | 111 |
| 99 InputMethodAPI::~InputMethodAPI() { | 112 InputMethodAPI::~InputMethodAPI() { |
| 100 } | 113 } |
| 101 | 114 |
| 102 // static | 115 // static |
| 103 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 116 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 125 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 138 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
| 126 g_factory = LAZY_INSTANCE_INITIALIZER; | 139 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 127 | 140 |
| 128 // static | 141 // static |
| 129 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 142 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
| 130 InputMethodAPI::GetFactoryInstance() { | 143 InputMethodAPI::GetFactoryInstance() { |
| 131 return g_factory.Pointer(); | 144 return g_factory.Pointer(); |
| 132 } | 145 } |
| 133 | 146 |
| 134 } // namespace extensions | 147 } // namespace extensions |
| OLD | NEW |