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/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/scoped_observer.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 #include "extensions/browser/browser_context_keyed_api_factory.h" | 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
20 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
21 #include "extensions/browser/extension_function.h" | 20 #include "extensions/browser/extension_function.h" |
| 21 #include "extensions/browser/extension_registry_observer.h" |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 | 23 |
24 class Profile; | 24 class Profile; |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 class InputMethodEngineInterface; | 27 class InputMethodEngineInterface; |
28 class ImeObserver; | 28 class ImeObserver; |
29 } // namespace chromeos | 29 } // namespace chromeos |
30 | 30 |
31 namespace extensions { | 31 namespace extensions { |
| 32 class ExtensionRegistry; |
32 struct InputComponentInfo; | 33 struct InputComponentInfo; |
33 | 34 |
34 class InputImeEventRouter { | 35 class InputImeEventRouter { |
35 public: | 36 public: |
36 static InputImeEventRouter* GetInstance(); | 37 static InputImeEventRouter* GetInstance(); |
37 | 38 |
38 bool RegisterIme(const std::string& extension_id, | 39 bool RegisterIme(const std::string& extension_id, |
39 const extensions::InputComponentInfo& component); | 40 const extensions::InputComponentInfo& component); |
40 void UnregisterAllImes(const std::string& extension_id); | 41 void UnregisterAllImes(const std::string& extension_id); |
41 chromeos::InputMethodEngineInterface* GetEngine( | 42 chromeos::InputMethodEngineInterface* GetEngine( |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 INPUT_IME_HIDEINPUTVIEW) | 213 INPUT_IME_HIDEINPUTVIEW) |
213 | 214 |
214 protected: | 215 protected: |
215 virtual ~InputImeHideInputViewFunction() {} | 216 virtual ~InputImeHideInputViewFunction() {} |
216 | 217 |
217 // ExtensionFunction: | 218 // ExtensionFunction: |
218 virtual bool RunImpl() OVERRIDE; | 219 virtual bool RunImpl() OVERRIDE; |
219 }; | 220 }; |
220 | 221 |
221 class InputImeAPI : public BrowserContextKeyedAPI, | 222 class InputImeAPI : public BrowserContextKeyedAPI, |
222 public content::NotificationObserver, | 223 public ExtensionRegistryObserver, |
223 public EventRouter::Observer { | 224 public EventRouter::Observer { |
224 public: | 225 public: |
225 explicit InputImeAPI(content::BrowserContext* context); | 226 explicit InputImeAPI(content::BrowserContext* context); |
226 virtual ~InputImeAPI(); | 227 virtual ~InputImeAPI(); |
227 | 228 |
228 // BrowserContextKeyedAPI implementation. | 229 // BrowserContextKeyedAPI implementation. |
229 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance(); | 230 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance(); |
230 | 231 |
231 // content::NotificationObserver implementation. | 232 // ExtensionRegistryObserver implementation. |
232 virtual void Observe(int type, | 233 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
233 const content::NotificationSource& source, | 234 const Extension* extension) OVERRIDE; |
234 const content::NotificationDetails& details) OVERRIDE; | 235 virtual void OnExtensionUnloaded( |
| 236 content::BrowserContext* browser_context, |
| 237 const Extension* extension, |
| 238 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
235 | 239 |
236 // EventRouter::Observer implementation. | 240 // EventRouter::Observer implementation. |
237 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 241 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
238 | 242 |
239 private: | 243 private: |
240 friend class BrowserContextKeyedAPIFactory<InputImeAPI>; | 244 friend class BrowserContextKeyedAPIFactory<InputImeAPI>; |
241 InputImeEventRouter* input_ime_event_router(); | 245 InputImeEventRouter* input_ime_event_router(); |
242 | 246 |
243 // BrowserContextKeyedAPI implementation. | 247 // BrowserContextKeyedAPI implementation. |
244 static const char* service_name() { | 248 static const char* service_name() { |
245 return "InputImeAPI"; | 249 return "InputImeAPI"; |
246 } | 250 } |
247 static const bool kServiceIsNULLWhileTesting = true; | 251 static const bool kServiceIsNULLWhileTesting = true; |
248 | 252 |
249 Profile* const profile_; | 253 content::BrowserContext* const browser_context_; |
250 content::NotificationRegistrar registrar_; | 254 |
| 255 // Listen to extension load, unloaded notifications. |
| 256 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 257 extension_registry_observer_; |
251 }; | 258 }; |
252 | 259 |
253 } // namespace extensions | 260 } // namespace extensions |
254 | 261 |
255 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ | 262 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_ |
OLD | NEW |