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 #ifndef CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.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/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "extensions/browser/browser_context_keyed_api_factory.h" | 19 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 20 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
| 21 #include "extensions/browser/extension_function.h" | 21 #include "extensions/browser/extension_function.h" |
| 22 #include "extensions/browser/extension_registry_observer.h" | 22 #include "extensions/browser/extension_registry_observer.h" |
| 23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 24 #include "ui/base/ime/ime_engine_handler_interface.h" | 24 #include "ui/base/ime/ime_engine_handler_interface.h" |
| 25 #include "ui/base/ime/ime_engine_observer.h" | 25 #include "ui/base/ime/ime_engine_observer.h" |
| 26 #include "ui/base/ime/text_input_flags.h" | 26 #include "ui/base/ime/text_input_flags.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.h" | 29 #include "chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.h" |
| 30 #elif defined(OS_LINUX) || defined(OS_WIN) | |
| 31 #include "chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.h" | |
| 30 #endif // defined(OS_CHROMEOS) | 32 #endif // defined(OS_CHROMEOS) |
| 31 | 33 |
| 32 class Profile; | 34 class Profile; |
| 33 | 35 |
| 34 namespace ui { | 36 namespace ui { |
| 35 class IMEEngineHandlerInterface; | 37 class IMEEngineHandlerInterface; |
| 36 class IMEEngineObserver; | 38 class IMEEngineObserver; |
| 37 | 39 |
| 38 class ImeObserver : public IMEEngineObserver { | 40 class ImeObserver : public IMEEngineObserver { |
| 39 public: | 41 public: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 82 |
| 81 std::string extension_id_; | 83 std::string extension_id_; |
| 82 Profile* profile_; | 84 Profile* profile_; |
| 83 | 85 |
| 84 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 86 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 } // namespace ui | 89 } // namespace ui |
| 88 | 90 |
| 89 namespace extensions { | 91 namespace extensions { |
| 90 class ExtensionRegistry; | 92 class InputImeKeyEventHandledFunction : public AsyncExtensionFunction { |
|
Devlin
2016/01/05 18:39:06
Why was this moved?
Azure Wei
2016/01/06 06:53:47
Oh, I just thought it's more easy to read to move
| |
| 91 struct InputComponentInfo; | 93 public: |
| 94 DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled", | |
| 95 INPUT_IME_KEYEVENTHANDLED) | |
| 92 | 96 |
| 93 class InputImeEventRouter { | 97 protected: |
| 94 public: | 98 ~InputImeKeyEventHandledFunction() override {} |
| 95 explicit InputImeEventRouter(Profile* profile); | |
| 96 ~InputImeEventRouter(); | |
| 97 | 99 |
| 98 bool RegisterImeExtension( | 100 // ExtensionFunction: |
| 99 const std::string& extension_id, | 101 bool RunAsync() override; |
| 100 const std::vector<extensions::InputComponentInfo>& input_components); | 102 }; |
| 101 void UnregisterAllImes(const std::string& extension_id); | |
| 102 | 103 |
| 103 ui::IMEEngineHandlerInterface* GetEngine(const std::string& extension_id, | 104 class InputImeEventRouter; |
| 104 const std::string& component_id); | |
| 105 ui::IMEEngineHandlerInterface* GetActiveEngine( | |
| 106 const std::string& extension_id); | |
| 107 | |
| 108 // Called when a key event was handled. | |
| 109 void OnKeyEventHandled(const std::string& extension_id, | |
| 110 const std::string& request_id, | |
| 111 bool handled); | |
| 112 | |
| 113 std::string AddRequest( | |
| 114 const std::string& component_id, | |
| 115 ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data); | |
| 116 | |
| 117 private: | |
| 118 typedef std::map< | |
| 119 std::string, | |
| 120 std::pair<std::string, | |
| 121 ui::IMEEngineHandlerInterface::KeyEventDoneCallback>> | |
| 122 RequestMap; | |
| 123 | |
| 124 // The engine map from extension_id to an engine. | |
| 125 std::map<std::string, ui::IMEEngineHandlerInterface*> engine_map_; | |
| 126 | |
| 127 unsigned int next_request_id_; | |
| 128 RequestMap request_map_; | |
| 129 Profile* profile_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouter); | |
| 132 }; | |
| 133 | 105 |
| 134 class InputImeEventRouterFactory { | 106 class InputImeEventRouterFactory { |
| 135 public: | 107 public: |
| 136 static InputImeEventRouterFactory* GetInstance(); | 108 static InputImeEventRouterFactory* GetInstance(); |
| 137 InputImeEventRouter* GetRouter(Profile* profile); | 109 InputImeEventRouter* GetRouter(Profile* profile); |
| 138 | 110 |
| 139 private: | 111 private: |
| 140 friend struct base::DefaultSingletonTraits<InputImeEventRouterFactory>; | 112 friend struct base::DefaultSingletonTraits<InputImeEventRouterFactory>; |
| 141 InputImeEventRouterFactory(); | 113 InputImeEventRouterFactory(); |
| 142 ~InputImeEventRouterFactory(); | 114 ~InputImeEventRouterFactory(); |
| 143 | 115 |
| 144 std::map<Profile*, InputImeEventRouter*, ProfileCompare> router_map_; | 116 std::map<Profile*, InputImeEventRouter*, ProfileCompare> router_map_; |
| 145 | 117 |
| 146 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouterFactory); | 118 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouterFactory); |
| 147 }; | 119 }; |
| 148 | 120 |
| 149 class InputImeKeyEventHandledFunction : public AsyncExtensionFunction { | |
| 150 public: | |
| 151 DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled", | |
| 152 INPUT_IME_KEYEVENTHANDLED) | |
| 153 | |
| 154 protected: | |
| 155 ~InputImeKeyEventHandledFunction() override {} | |
| 156 | |
| 157 // ExtensionFunction: | |
| 158 bool RunAsync() override; | |
| 159 }; | |
| 160 | |
| 161 class InputImeAPI : public BrowserContextKeyedAPI, | 121 class InputImeAPI : public BrowserContextKeyedAPI, |
| 162 public ExtensionRegistryObserver, | 122 public ExtensionRegistryObserver, |
| 163 public EventRouter::Observer { | 123 public EventRouter::Observer { |
| 164 public: | 124 public: |
| 165 explicit InputImeAPI(content::BrowserContext* context); | 125 explicit InputImeAPI(content::BrowserContext* context); |
| 166 ~InputImeAPI() override; | 126 ~InputImeAPI() override; |
| 167 | 127 |
| 168 // BrowserContextKeyedAPI implementation. | 128 // BrowserContextKeyedAPI implementation. |
| 169 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance(); | 129 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance(); |
| 170 | 130 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 193 // Listen to extension load, unloaded notifications. | 153 // Listen to extension load, unloaded notifications. |
| 194 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 154 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 195 extension_registry_observer_; | 155 extension_registry_observer_; |
| 196 }; | 156 }; |
| 197 | 157 |
| 198 InputImeEventRouter* GetInputImeEventRouter(Profile* profile); | 158 InputImeEventRouter* GetInputImeEventRouter(Profile* profile); |
| 199 | 159 |
| 200 } // namespace extensions | 160 } // namespace extensions |
| 201 | 161 |
| 202 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ | 162 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ |
| OLD | NEW |