Remove some NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED from c/b/extensions Part2
[chromium-blink-merge.git] / chrome / browser / extensions / api / input_ime / input_ime_api.h
blob176596819b2586ca2e736e37616b79a76aa2870d
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/memory/singleton.h"
13 #include "base/scoped_observer.h"
14 #include "base/values.h"
15 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "components/keyed_service/core/keyed_service.h"
18 #include "extensions/browser/browser_context_keyed_api_factory.h"
19 #include "extensions/browser/event_router.h"
20 #include "extensions/browser/extension_function.h"
21 #include "extensions/browser/extension_registry_observer.h"
22 #include "extensions/common/extension.h"
24 class Profile;
26 namespace chromeos {
27 class InputMethodEngineInterface;
28 class ImeObserver;
29 } // namespace chromeos
31 namespace extensions {
32 class ExtensionRegistry;
33 struct InputComponentInfo;
35 class InputImeEventRouter {
36 public:
37 static InputImeEventRouter* GetInstance();
39 bool RegisterIme(const std::string& extension_id,
40 const extensions::InputComponentInfo& component);
41 void UnregisterAllImes(const std::string& extension_id);
42 chromeos::InputMethodEngineInterface* GetEngine(
43 const std::string& extension_id,
44 const std::string& engine_id);
45 chromeos::InputMethodEngineInterface* GetActiveEngine(
46 const std::string& extension_id);
49 // Called when a key event was handled.
50 void OnKeyEventHandled(const std::string& extension_id,
51 const std::string& request_id,
52 bool handled);
54 std::string AddRequest(const std::string& engine_id,
55 chromeos::input_method::KeyEventHandle* key_data);
57 private:
58 friend struct DefaultSingletonTraits<InputImeEventRouter>;
59 typedef std::map<std::string, std::pair<std::string,
60 chromeos::input_method::KeyEventHandle*> > RequestMap;
62 InputImeEventRouter();
63 ~InputImeEventRouter();
65 // The engine map for event routing.
66 // { Profile : { extension_id : { engine_id : Engine } } }.
67 // TODO(shuchen): reuse the engine map in InputMethodManagerImpl.
68 typedef std::map<std::string, chromeos::InputMethodEngineInterface*>
69 EngineMap;
70 typedef std::map<std::string, EngineMap> ExtensionMap;
71 typedef std::map<Profile*, ExtensionMap, ProfileCompare>
72 ProfileEngineMap;
73 ProfileEngineMap profile_engine_map_;
75 unsigned int next_request_id_;
76 RequestMap request_map_;
78 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouter);
81 class InputImeSetCompositionFunction : public SyncExtensionFunction {
82 public:
83 DECLARE_EXTENSION_FUNCTION("input.ime.setComposition",
84 INPUT_IME_SETCOMPOSITION)
86 protected:
87 virtual ~InputImeSetCompositionFunction() {}
89 // ExtensionFunction:
90 virtual bool RunImpl() OVERRIDE;
93 class InputImeClearCompositionFunction : public SyncExtensionFunction {
94 public:
95 DECLARE_EXTENSION_FUNCTION("input.ime.clearComposition",
96 INPUT_IME_CLEARCOMPOSITION)
98 protected:
99 virtual ~InputImeClearCompositionFunction() {}
101 // ExtensionFunction:
102 virtual bool RunImpl() OVERRIDE;
105 class InputImeCommitTextFunction : public SyncExtensionFunction {
106 public:
107 DECLARE_EXTENSION_FUNCTION("input.ime.commitText", INPUT_IME_COMMITTEXT)
109 protected:
110 virtual ~InputImeCommitTextFunction() {}
112 // ExtensionFunction:
113 virtual bool RunImpl() OVERRIDE;
116 class InputImeSetCandidateWindowPropertiesFunction
117 : public SyncExtensionFunction {
118 public:
119 DECLARE_EXTENSION_FUNCTION("input.ime.setCandidateWindowProperties",
120 INPUT_IME_SETCANDIDATEWINDOWPROPERTIES)
122 protected:
123 virtual ~InputImeSetCandidateWindowPropertiesFunction() {}
125 // ExtensionFunction:
126 virtual bool RunImpl() OVERRIDE;
129 class InputImeSetCandidatesFunction : public SyncExtensionFunction {
130 public:
131 DECLARE_EXTENSION_FUNCTION("input.ime.setCandidates", INPUT_IME_SETCANDIDATES)
133 protected:
134 virtual ~InputImeSetCandidatesFunction() {}
136 // ExtensionFunction:
137 virtual bool RunImpl() OVERRIDE;
140 class InputImeSetCursorPositionFunction : public SyncExtensionFunction {
141 public:
142 DECLARE_EXTENSION_FUNCTION("input.ime.setCursorPosition",
143 INPUT_IME_SETCURSORPOSITION)
145 protected:
146 virtual ~InputImeSetCursorPositionFunction() {}
148 // ExtensionFunction:
149 virtual bool RunImpl() OVERRIDE;
152 class InputImeSetMenuItemsFunction : public SyncExtensionFunction {
153 public:
154 DECLARE_EXTENSION_FUNCTION("input.ime.setMenuItems", INPUT_IME_SETMENUITEMS)
156 protected:
157 virtual ~InputImeSetMenuItemsFunction() {}
159 // ExtensionFunction:
160 virtual bool RunImpl() OVERRIDE;
163 class InputImeUpdateMenuItemsFunction : public SyncExtensionFunction {
164 public:
165 DECLARE_EXTENSION_FUNCTION("input.ime.updateMenuItems",
166 INPUT_IME_UPDATEMENUITEMS)
168 protected:
169 virtual ~InputImeUpdateMenuItemsFunction() {}
171 // ExtensionFunction:
172 virtual bool RunImpl() OVERRIDE;
175 class InputImeDeleteSurroundingTextFunction : public SyncExtensionFunction {
176 public:
177 DECLARE_EXTENSION_FUNCTION("input.ime.deleteSurroundingText",
178 INPUT_IME_DELETESURROUNDINGTEXT)
179 protected:
180 virtual ~InputImeDeleteSurroundingTextFunction() {}
182 // ExtensionFunction:
183 virtual bool RunImpl() OVERRIDE;
186 class InputImeKeyEventHandledFunction : public AsyncExtensionFunction {
187 public:
188 DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled",
189 INPUT_IME_KEYEVENTHANDLED)
191 protected:
192 virtual ~InputImeKeyEventHandledFunction() {}
194 // ExtensionFunction:
195 virtual bool RunImpl() OVERRIDE;
198 class InputImeSendKeyEventsFunction : public AsyncExtensionFunction {
199 public:
200 DECLARE_EXTENSION_FUNCTION("input.ime.sendKeyEvents",
201 INPUT_IME_SENDKEYEVENTS)
203 protected:
204 virtual ~InputImeSendKeyEventsFunction() {}
206 // ExtensionFunction:
207 virtual bool RunImpl() OVERRIDE;
210 class InputImeHideInputViewFunction : public AsyncExtensionFunction {
211 public:
212 DECLARE_EXTENSION_FUNCTION("input.ime.hideInputView",
213 INPUT_IME_HIDEINPUTVIEW)
215 protected:
216 virtual ~InputImeHideInputViewFunction() {}
218 // ExtensionFunction:
219 virtual bool RunImpl() OVERRIDE;
222 class InputImeAPI : public BrowserContextKeyedAPI,
223 public ExtensionRegistryObserver,
224 public EventRouter::Observer {
225 public:
226 explicit InputImeAPI(content::BrowserContext* context);
227 virtual ~InputImeAPI();
229 // BrowserContextKeyedAPI implementation.
230 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance();
232 // ExtensionRegistryObserver implementation.
233 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
234 const Extension* extension) OVERRIDE;
235 virtual void OnExtensionUnloaded(
236 content::BrowserContext* browser_context,
237 const Extension* extension,
238 UnloadedExtensionInfo::Reason reason) OVERRIDE;
240 // EventRouter::Observer implementation.
241 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
243 private:
244 friend class BrowserContextKeyedAPIFactory<InputImeAPI>;
245 InputImeEventRouter* input_ime_event_router();
247 // BrowserContextKeyedAPI implementation.
248 static const char* service_name() {
249 return "InputImeAPI";
251 static const bool kServiceIsNULLWhileTesting = true;
253 content::BrowserContext* const browser_context_;
255 // Listen to extension load, unloaded notifications.
256 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
257 extension_registry_observer_;
260 } // namespace extensions
262 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_