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/extensions/api/input_ime/input_ime_api.h" |
10 #include "chrome/browser/extensions/event_names.h" | 11 #include "chrome/browser/extensions/event_names.h" |
11 #include "chrome/browser/extensions/extension_function_registry.h" | 12 #include "chrome/browser/extensions/extension_function_registry.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chromeos/ime/input_method_manager.h" | 15 #include "chromeos/ime/input_method_manager.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Prefix, which is used by XKB. | 19 // Prefix, which is used by XKB. |
19 const char kXkbPrefix[] = "xkb:"; | 20 const char kXkbPrefix[] = "xkb:"; |
(...skipping 15 matching lines...) Expand all Loading... |
35 #else | 36 #else |
36 chromeos::input_method::InputMethodManager* manager = | 37 chromeos::input_method::InputMethodManager* manager = |
37 chromeos::input_method::InputMethodManager::Get(); | 38 chromeos::input_method::InputMethodManager::Get(); |
38 const std::string input_method = InputMethodAPI::GetInputMethodForXkb( | 39 const std::string input_method = InputMethodAPI::GetInputMethodForXkb( |
39 manager->GetCurrentInputMethod().id()); | 40 manager->GetCurrentInputMethod().id()); |
40 SetResult(Value::CreateStringValue(input_method)); | 41 SetResult(Value::CreateStringValue(input_method)); |
41 return true; | 42 return true; |
42 #endif | 43 #endif |
43 } | 44 } |
44 | 45 |
| 46 StartImeFunction::StartImeFunction() { |
| 47 } |
| 48 |
| 49 StartImeFunction::~StartImeFunction() { |
| 50 } |
| 51 |
| 52 bool StartImeFunction::RunImpl() { |
| 53 #if !defined(OS_CHROMEOS) |
| 54 NOTREACHED(); |
| 55 return false; |
| 56 #else |
| 57 chromeos::InputMethodEngine* engine = |
| 58 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 59 if (engine) |
| 60 engine->StartIme(); |
| 61 return true; |
| 62 #endif |
| 63 } |
| 64 |
45 InputMethodAPI::InputMethodAPI(Profile* profile) | 65 InputMethodAPI::InputMethodAPI(Profile* profile) |
46 : profile_(profile) { | 66 : profile_(profile) { |
47 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 67 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
48 this, event_names::kOnInputMethodChanged); | 68 this, event_names::kOnInputMethodChanged); |
49 ExtensionFunctionRegistry* registry = | 69 ExtensionFunctionRegistry* registry = |
50 ExtensionFunctionRegistry::GetInstance(); | 70 ExtensionFunctionRegistry::GetInstance(); |
51 registry->RegisterFunction<GetInputMethodFunction>(); | 71 registry->RegisterFunction<GetInputMethodFunction>(); |
| 72 registry->RegisterFunction<StartImeFunction>(); |
52 } | 73 } |
53 | 74 |
54 InputMethodAPI::~InputMethodAPI() { | 75 InputMethodAPI::~InputMethodAPI() { |
55 } | 76 } |
56 | 77 |
57 // static | 78 // static |
58 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 79 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
59 size_t prefix_length = std::string(kXkbPrefix).length(); | 80 size_t prefix_length = std::string(kXkbPrefix).length(); |
60 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 81 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); |
61 return xkb_id.substr(prefix_length); | 82 return xkb_id.substr(prefix_length); |
(...skipping 15 matching lines...) Expand all Loading... |
77 | 98 |
78 static base::LazyInstance<ProfileKeyedAPIFactory<InputMethodAPI> > | 99 static base::LazyInstance<ProfileKeyedAPIFactory<InputMethodAPI> > |
79 g_factory = LAZY_INSTANCE_INITIALIZER; | 100 g_factory = LAZY_INSTANCE_INITIALIZER; |
80 | 101 |
81 // static | 102 // static |
82 ProfileKeyedAPIFactory<InputMethodAPI>* InputMethodAPI::GetFactoryInstance() { | 103 ProfileKeyedAPIFactory<InputMethodAPI>* InputMethodAPI::GetFactoryInstance() { |
83 return &g_factory.Get(); | 104 return &g_factory.Get(); |
84 } | 105 } |
85 | 106 |
86 } // namespace extensions | 107 } // namespace extensions |
OLD | NEW |