/chrome/browser/chromeos/extensions/input_method_api.h

http://github.com/chromium/chromium · C Header · 347 lines · 238 code · 83 blank · 26 comment · 0 complexity · 8635b64be3af851c6d17b85f457d53f5 MD5 · raw file

  1. // Copyright (c) 2011 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.
  4. #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
  5. #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
  6. #include <memory>
  7. #include "base/compiler_specific.h"
  8. #include "base/macros.h"
  9. #include "chrome/common/extensions/api/input_method_private.h"
  10. #include "extensions/browser/browser_context_keyed_api_factory.h"
  11. #include "extensions/browser/event_router.h"
  12. #include "extensions/browser/extension_function.h"
  13. namespace chromeos {
  14. class ExtensionDictionaryEventRouter;
  15. class ExtensionInputMethodEventRouter;
  16. class ExtensionImeMenuEventRouter;
  17. }
  18. namespace extensions {
  19. // Implements the inputMethodPrivate.getInputMethodConfig method.
  20. class InputMethodPrivateGetInputMethodConfigFunction
  21. : public ExtensionFunction {
  22. public:
  23. InputMethodPrivateGetInputMethodConfigFunction() {}
  24. protected:
  25. ~InputMethodPrivateGetInputMethodConfigFunction() override {}
  26. ResponseAction Run() override;
  27. private:
  28. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethodConfig",
  29. INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG)
  30. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetInputMethodConfigFunction);
  31. };
  32. // Implements the inputMethodPrivate.getCurrentInputMethod method.
  33. class InputMethodPrivateGetCurrentInputMethodFunction
  34. : public ExtensionFunction {
  35. public:
  36. InputMethodPrivateGetCurrentInputMethodFunction() {}
  37. protected:
  38. ~InputMethodPrivateGetCurrentInputMethodFunction() override {}
  39. ResponseAction Run() override;
  40. private:
  41. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod",
  42. INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD)
  43. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetCurrentInputMethodFunction);
  44. };
  45. // Implements the inputMethodPrivate.setCurrentInputMethod method.
  46. class InputMethodPrivateSetCurrentInputMethodFunction
  47. : public ExtensionFunction {
  48. public:
  49. InputMethodPrivateSetCurrentInputMethodFunction() {}
  50. protected:
  51. ~InputMethodPrivateSetCurrentInputMethodFunction() override {}
  52. ResponseAction Run() override;
  53. private:
  54. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod",
  55. INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD)
  56. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateSetCurrentInputMethodFunction);
  57. };
  58. // Implements the inputMethodPrivate.getInputMethods method.
  59. class InputMethodPrivateGetInputMethodsFunction : public ExtensionFunction {
  60. public:
  61. InputMethodPrivateGetInputMethodsFunction() {}
  62. protected:
  63. ~InputMethodPrivateGetInputMethodsFunction() override {}
  64. ResponseAction Run() override;
  65. private:
  66. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
  67. INPUTMETHODPRIVATE_GETINPUTMETHODS)
  68. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetInputMethodsFunction);
  69. };
  70. // Implements the inputMethodPrivate.fetchAllDictionaryWords method.
  71. class InputMethodPrivateFetchAllDictionaryWordsFunction
  72. : public ExtensionFunction {
  73. public:
  74. InputMethodPrivateFetchAllDictionaryWordsFunction() {}
  75. protected:
  76. ~InputMethodPrivateFetchAllDictionaryWordsFunction() override {}
  77. ResponseAction Run() override;
  78. private:
  79. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.fetchAllDictionaryWords",
  80. INPUTMETHODPRIVATE_FETCHALLDICTIONARYWORDS)
  81. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateFetchAllDictionaryWordsFunction);
  82. };
  83. // Implements the inputMethodPrivate.addWordToDictionary method.
  84. class InputMethodPrivateAddWordToDictionaryFunction : public ExtensionFunction {
  85. public:
  86. InputMethodPrivateAddWordToDictionaryFunction() {}
  87. protected:
  88. ~InputMethodPrivateAddWordToDictionaryFunction() override {}
  89. ResponseAction Run() override;
  90. private:
  91. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.addWordToDictionary",
  92. INPUTMETHODPRIVATE_ADDWORDTODICTIONARY)
  93. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateAddWordToDictionaryFunction);
  94. };
  95. // Implements the inputMethodPrivate.getEncryptSyncEnabled method.
  96. class InputMethodPrivateGetEncryptSyncEnabledFunction
  97. : public ExtensionFunction {
  98. public:
  99. InputMethodPrivateGetEncryptSyncEnabledFunction() {}
  100. protected:
  101. ~InputMethodPrivateGetEncryptSyncEnabledFunction() override {}
  102. ResponseAction Run() override;
  103. private:
  104. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getEncryptSyncEnabled",
  105. INPUTMETHODPRIVATE_GETENCRYPTSYNCENABLED)
  106. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetEncryptSyncEnabledFunction);
  107. };
  108. // Implements the inputMethodPrivate.setXkbLayout method.
  109. class InputMethodPrivateSetXkbLayoutFunction : public ExtensionFunction {
  110. public:
  111. InputMethodPrivateSetXkbLayoutFunction() {}
  112. protected:
  113. ~InputMethodPrivateSetXkbLayoutFunction() override {}
  114. ResponseAction Run() override;
  115. private:
  116. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setXkbLayout",
  117. INPUTMETHODPRIVATE_SETXKBLAYOUT)
  118. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateSetXkbLayoutFunction);
  119. };
  120. // Implements the inputMethodPrivate.showInputView method.
  121. class InputMethodPrivateShowInputViewFunction : public ExtensionFunction {
  122. public:
  123. InputMethodPrivateShowInputViewFunction() {}
  124. protected:
  125. ~InputMethodPrivateShowInputViewFunction() override {}
  126. ResponseAction Run() override;
  127. private:
  128. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.showInputView",
  129. INPUTMETHODPRIVATE_SHOWINPUTVIEW)
  130. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateShowInputViewFunction);
  131. };
  132. // Implements the inputMethodPrivate.hideInputView method.
  133. class InputMethodPrivateHideInputViewFunction : public ExtensionFunction {
  134. public:
  135. InputMethodPrivateHideInputViewFunction() = default;
  136. InputMethodPrivateHideInputViewFunction(
  137. const InputMethodPrivateHideInputViewFunction&) = delete;
  138. InputMethodPrivateHideInputViewFunction& operator=(
  139. const InputMethodPrivateHideInputViewFunction&) = delete;
  140. protected:
  141. ~InputMethodPrivateHideInputViewFunction() override {}
  142. ResponseAction Run() override;
  143. private:
  144. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.hideInputView",
  145. INPUTMETHODPRIVATE_HIDEINPUTVIEW)
  146. };
  147. // Implements the inputMethodPrivate.openOptionsPage method.
  148. class InputMethodPrivateOpenOptionsPageFunction : public ExtensionFunction {
  149. public:
  150. InputMethodPrivateOpenOptionsPageFunction() {}
  151. protected:
  152. ~InputMethodPrivateOpenOptionsPageFunction() override {}
  153. ResponseAction Run() override;
  154. private:
  155. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.openOptionsPage",
  156. INPUTMETHODPRIVATE_OPENOPTIONSPAGE)
  157. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateOpenOptionsPageFunction);
  158. };
  159. class InputMethodPrivateGetSurroundingTextFunction : public ExtensionFunction {
  160. public:
  161. InputMethodPrivateGetSurroundingTextFunction() {}
  162. protected:
  163. ~InputMethodPrivateGetSurroundingTextFunction() override {}
  164. ResponseAction Run() override;
  165. private:
  166. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getSurroundingText",
  167. INPUTMETHODPRIVATE_GETSURROUNDINGTEXT)
  168. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetSurroundingTextFunction);
  169. };
  170. class InputMethodPrivateGetSettingsFunction : public ExtensionFunction {
  171. public:
  172. InputMethodPrivateGetSettingsFunction() = default;
  173. protected:
  174. ~InputMethodPrivateGetSettingsFunction() override = default;
  175. // ExtensionFunction:
  176. ResponseAction Run() override;
  177. private:
  178. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getSettings",
  179. INPUTMETHODPRIVATE_GETSETTINGS)
  180. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetSettingsFunction);
  181. };
  182. class InputMethodPrivateSetSettingsFunction : public ExtensionFunction {
  183. public:
  184. InputMethodPrivateSetSettingsFunction() = default;
  185. protected:
  186. ~InputMethodPrivateSetSettingsFunction() override = default;
  187. // ExtensionFunction:
  188. ResponseAction Run() override;
  189. private:
  190. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setSettings",
  191. INPUTMETHODPRIVATE_SETSETTINGS)
  192. DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateSetSettingsFunction);
  193. };
  194. class InputMethodPrivateSetCompositionRangeFunction : public ExtensionFunction {
  195. public:
  196. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCompositionRange",
  197. INPUTMETHODPRIVATE_SETCOMPOSITIONRANGE)
  198. protected:
  199. ~InputMethodPrivateSetCompositionRangeFunction() override {}
  200. // ExtensionFunction:
  201. ResponseAction Run() override;
  202. };
  203. class InputMethodPrivateSetSelectionRangeFunction : public ExtensionFunction {
  204. public:
  205. InputMethodPrivateSetSelectionRangeFunction(
  206. const InputMethodPrivateSetSelectionRangeFunction&) = delete;
  207. InputMethodPrivateSetSelectionRangeFunction& operator=(
  208. const InputMethodPrivateSetSelectionRangeFunction&) = delete;
  209. InputMethodPrivateSetSelectionRangeFunction() = default;
  210. protected:
  211. ~InputMethodPrivateSetSelectionRangeFunction() override = default;
  212. // ExtensionFunction:
  213. ResponseAction Run() override;
  214. private:
  215. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setSelectionRange",
  216. INPUTMETHODPRIVATE_SETSELECTIONRANGE)
  217. };
  218. class InputMethodPrivateResetFunction : public ExtensionFunction {
  219. public:
  220. InputMethodPrivateResetFunction() = default;
  221. InputMethodPrivateResetFunction(const InputMethodPrivateResetFunction&) =
  222. delete;
  223. InputMethodPrivateResetFunction& operator=(
  224. const InputMethodPrivateResetFunction&) = delete;
  225. protected:
  226. ~InputMethodPrivateResetFunction() override = default;
  227. // ExtensionFunction:
  228. ResponseAction Run() override;
  229. private:
  230. DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.reset",
  231. INPUTMETHODPRIVATE_RESET)
  232. };
  233. class InputMethodAPI : public BrowserContextKeyedAPI,
  234. public extensions::EventRouter::Observer {
  235. public:
  236. explicit InputMethodAPI(content::BrowserContext* context);
  237. ~InputMethodAPI() override;
  238. // Returns input method name for the given XKB (X keyboard extensions in X
  239. // Window System) id.
  240. static std::string GetInputMethodForXkb(const std::string& xkb_id);
  241. // BrowserContextKeyedAPI implementation.
  242. static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance();
  243. // BrowserContextKeyedAPI implementation.
  244. void Shutdown() override;
  245. // EventRouter::Observer implementation.
  246. void OnListenerAdded(const extensions::EventListenerInfo& details) override;
  247. private:
  248. friend class BrowserContextKeyedAPIFactory<InputMethodAPI>;
  249. // BrowserContextKeyedAPI implementation.
  250. static const char* service_name() {
  251. return "InputMethodAPI";
  252. }
  253. static const bool kServiceIsNULLWhileTesting = true;
  254. content::BrowserContext* const context_;
  255. // Created lazily upon OnListenerAdded.
  256. std::unique_ptr<chromeos::ExtensionInputMethodEventRouter>
  257. input_method_event_router_;
  258. std::unique_ptr<chromeos::ExtensionDictionaryEventRouter>
  259. dictionary_event_router_;
  260. std::unique_ptr<chromeos::ExtensionImeMenuEventRouter> ime_menu_event_router_;
  261. DISALLOW_COPY_AND_ASSIGN(InputMethodAPI);
  262. };
  263. } // namespace extensions
  264. #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_