Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / input_ime / input_ime_api.h
blob30fb3be0d6738894033aaa3e166c5e1ffedcae7a
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 explicit InputImeEventRouter(Profile* profile);
38 ~InputImeEventRouter();
40 bool RegisterImeExtension(
41 const std::string& extension_id,
42 const std::vector<extensions::InputComponentInfo>& input_components);
43 void UnregisterAllImes(const std::string& extension_id);
45 chromeos::InputMethodEngineInterface* GetEngine(
46 const std::string& extension_id,
47 const std::string& component_id);
48 chromeos::InputMethodEngineInterface* GetActiveEngine(
49 const std::string& extension_id);
52 // Called when a key event was handled.
53 void OnKeyEventHandled(const std::string& extension_id,
54 const std::string& request_id,
55 bool handled);
57 std::string AddRequest(const std::string& component_id,
58 chromeos::input_method::KeyEventHandle* key_data);
60 private:
61 typedef std::map<std::string, std::pair<std::string,
62 chromeos::input_method::KeyEventHandle*> > RequestMap;
64 // The engine map from extension_id to an engine.
65 std::map<std::string, chromeos::InputMethodEngineInterface*> engine_map_;
67 unsigned int next_request_id_;
68 RequestMap request_map_;
69 Profile* profile_;
71 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouter);
74 class InputImeEventRouterFactory {
75 public:
76 static InputImeEventRouterFactory* GetInstance();
77 InputImeEventRouter* GetRouter(Profile* profile);
79 private:
80 friend struct DefaultSingletonTraits<InputImeEventRouterFactory>;
81 InputImeEventRouterFactory();
82 ~InputImeEventRouterFactory();
84 std::map<Profile*, InputImeEventRouter*, ProfileCompare> router_map_;
86 DISALLOW_COPY_AND_ASSIGN(InputImeEventRouterFactory);
89 class InputImeSetCompositionFunction : public SyncExtensionFunction {
90 public:
91 DECLARE_EXTENSION_FUNCTION("input.ime.setComposition",
92 INPUT_IME_SETCOMPOSITION)
94 protected:
95 ~InputImeSetCompositionFunction() override {}
97 // ExtensionFunction:
98 bool RunSync() override;
101 class InputImeClearCompositionFunction : public SyncExtensionFunction {
102 public:
103 DECLARE_EXTENSION_FUNCTION("input.ime.clearComposition",
104 INPUT_IME_CLEARCOMPOSITION)
106 protected:
107 ~InputImeClearCompositionFunction() override {}
109 // ExtensionFunction:
110 bool RunSync() override;
113 class InputImeCommitTextFunction : public SyncExtensionFunction {
114 public:
115 DECLARE_EXTENSION_FUNCTION("input.ime.commitText", INPUT_IME_COMMITTEXT)
117 protected:
118 ~InputImeCommitTextFunction() override {}
120 // ExtensionFunction:
121 bool RunSync() override;
124 class InputImeSetCandidateWindowPropertiesFunction
125 : public SyncExtensionFunction {
126 public:
127 DECLARE_EXTENSION_FUNCTION("input.ime.setCandidateWindowProperties",
128 INPUT_IME_SETCANDIDATEWINDOWPROPERTIES)
130 protected:
131 ~InputImeSetCandidateWindowPropertiesFunction() override {}
133 // ExtensionFunction:
134 bool RunSync() override;
137 class InputImeSetCandidatesFunction : public SyncExtensionFunction {
138 public:
139 DECLARE_EXTENSION_FUNCTION("input.ime.setCandidates", INPUT_IME_SETCANDIDATES)
141 protected:
142 ~InputImeSetCandidatesFunction() override {}
144 // ExtensionFunction:
145 bool RunSync() override;
148 class InputImeSetCursorPositionFunction : public SyncExtensionFunction {
149 public:
150 DECLARE_EXTENSION_FUNCTION("input.ime.setCursorPosition",
151 INPUT_IME_SETCURSORPOSITION)
153 protected:
154 ~InputImeSetCursorPositionFunction() override {}
156 // ExtensionFunction:
157 bool RunSync() override;
160 class InputImeSetMenuItemsFunction : public SyncExtensionFunction {
161 public:
162 DECLARE_EXTENSION_FUNCTION("input.ime.setMenuItems", INPUT_IME_SETMENUITEMS)
164 protected:
165 ~InputImeSetMenuItemsFunction() override {}
167 // ExtensionFunction:
168 bool RunSync() override;
171 class InputImeUpdateMenuItemsFunction : public SyncExtensionFunction {
172 public:
173 DECLARE_EXTENSION_FUNCTION("input.ime.updateMenuItems",
174 INPUT_IME_UPDATEMENUITEMS)
176 protected:
177 ~InputImeUpdateMenuItemsFunction() override {}
179 // ExtensionFunction:
180 bool RunSync() override;
183 class InputImeDeleteSurroundingTextFunction : public SyncExtensionFunction {
184 public:
185 DECLARE_EXTENSION_FUNCTION("input.ime.deleteSurroundingText",
186 INPUT_IME_DELETESURROUNDINGTEXT)
187 protected:
188 ~InputImeDeleteSurroundingTextFunction() override {}
190 // ExtensionFunction:
191 bool RunSync() override;
194 class InputImeKeyEventHandledFunction : public AsyncExtensionFunction {
195 public:
196 DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled",
197 INPUT_IME_KEYEVENTHANDLED)
199 protected:
200 ~InputImeKeyEventHandledFunction() override {}
202 // ExtensionFunction:
203 bool RunAsync() override;
206 class InputImeSendKeyEventsFunction : public AsyncExtensionFunction {
207 public:
208 DECLARE_EXTENSION_FUNCTION("input.ime.sendKeyEvents",
209 INPUT_IME_SENDKEYEVENTS)
211 protected:
212 ~InputImeSendKeyEventsFunction() override {}
214 // ExtensionFunction:
215 bool RunAsync() override;
218 class InputImeHideInputViewFunction : public AsyncExtensionFunction {
219 public:
220 DECLARE_EXTENSION_FUNCTION("input.ime.hideInputView",
221 INPUT_IME_HIDEINPUTVIEW)
223 protected:
224 ~InputImeHideInputViewFunction() override {}
226 // ExtensionFunction:
227 bool RunAsync() override;
230 class InputImeAPI : public BrowserContextKeyedAPI,
231 public ExtensionRegistryObserver,
232 public EventRouter::Observer {
233 public:
234 explicit InputImeAPI(content::BrowserContext* context);
235 ~InputImeAPI() override;
237 // BrowserContextKeyedAPI implementation.
238 static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance();
240 // ExtensionRegistryObserver implementation.
241 void OnExtensionLoaded(content::BrowserContext* browser_context,
242 const Extension* extension) override;
243 void OnExtensionUnloaded(content::BrowserContext* browser_context,
244 const Extension* extension,
245 UnloadedExtensionInfo::Reason reason) override;
247 // EventRouter::Observer implementation.
248 void OnListenerAdded(const EventListenerInfo& details) override;
250 private:
251 friend class BrowserContextKeyedAPIFactory<InputImeAPI>;
252 InputImeEventRouter* input_ime_event_router();
254 // BrowserContextKeyedAPI implementation.
255 static const char* service_name() {
256 return "InputImeAPI";
258 static const bool kServiceIsNULLWhileTesting = true;
260 content::BrowserContext* const browser_context_;
262 // Listen to extension load, unloaded notifications.
263 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
264 extension_registry_observer_;
267 } // namespace extensions
269 #endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_