| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "extensions/browser/browser_context_keyed_api_factory.h" | 10 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 11 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
| 12 #include "extensions/browser/extension_function.h" | 12 #include "extensions/browser/extension_function.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 class ExtensionInputMethodEventRouter; | 15 class ExtensionInputMethodEventRouter; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 // Implements the inputMethodPrivate.getCurrentInputMethod method. | 20 // Implements the inputMethodPrivate.getCurrentInputMethod method. |
| 21 class GetCurrentInputMethodFunction : public UIThreadExtensionFunction { | 21 class GetCurrentInputMethodFunction : public UIThreadExtensionFunction { |
| 22 public: | 22 public: |
| 23 GetCurrentInputMethodFunction() {} | 23 GetCurrentInputMethodFunction() {} |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 virtual ~GetCurrentInputMethodFunction() {} | 26 virtual ~GetCurrentInputMethodFunction() {} |
| 27 | 27 |
| 28 virtual ResponseAction Run() OVERRIDE; | 28 virtual ResponseAction Run() override; |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod", | 31 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod", |
| 32 INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD) | 32 INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD) |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // Implements the inputMethodPrivate.setCurrentInputMethod method. | 35 // Implements the inputMethodPrivate.setCurrentInputMethod method. |
| 36 class SetCurrentInputMethodFunction : public UIThreadExtensionFunction { | 36 class SetCurrentInputMethodFunction : public UIThreadExtensionFunction { |
| 37 public: | 37 public: |
| 38 SetCurrentInputMethodFunction() {} | 38 SetCurrentInputMethodFunction() {} |
| 39 | 39 |
| 40 protected: | 40 protected: |
| 41 virtual ~SetCurrentInputMethodFunction() {} | 41 virtual ~SetCurrentInputMethodFunction() {} |
| 42 | 42 |
| 43 virtual ResponseAction Run() OVERRIDE; | 43 virtual ResponseAction Run() override; |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod", | 46 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod", |
| 47 INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD) | 47 INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD) |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Implements the inputMethodPrivate.getInputMethods method. | 50 // Implements the inputMethodPrivate.getInputMethods method. |
| 51 class GetInputMethodsFunction : public UIThreadExtensionFunction { | 51 class GetInputMethodsFunction : public UIThreadExtensionFunction { |
| 52 public: | 52 public: |
| 53 GetInputMethodsFunction() {} | 53 GetInputMethodsFunction() {} |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 virtual ~GetInputMethodsFunction() {} | 56 virtual ~GetInputMethodsFunction() {} |
| 57 | 57 |
| 58 virtual ResponseAction Run() OVERRIDE; | 58 virtual ResponseAction Run() override; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods", | 61 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods", |
| 62 INPUTMETHODPRIVATE_GETINPUTMETHODS) | 62 INPUTMETHODPRIVATE_GETINPUTMETHODS) |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class InputMethodAPI : public BrowserContextKeyedAPI, | 65 class InputMethodAPI : public BrowserContextKeyedAPI, |
| 66 public extensions::EventRouter::Observer { | 66 public extensions::EventRouter::Observer { |
| 67 public: | 67 public: |
| 68 static const char kOnInputMethodChanged[]; | 68 static const char kOnInputMethodChanged[]; |
| 69 | 69 |
| 70 explicit InputMethodAPI(content::BrowserContext* context); | 70 explicit InputMethodAPI(content::BrowserContext* context); |
| 71 virtual ~InputMethodAPI(); | 71 virtual ~InputMethodAPI(); |
| 72 | 72 |
| 73 // Returns input method name for the given XKB (X keyboard extensions in X | 73 // Returns input method name for the given XKB (X keyboard extensions in X |
| 74 // Window System) id. | 74 // Window System) id. |
| 75 static std::string GetInputMethodForXkb(const std::string& xkb_id); | 75 static std::string GetInputMethodForXkb(const std::string& xkb_id); |
| 76 | 76 |
| 77 // BrowserContextKeyedAPI implementation. | 77 // BrowserContextKeyedAPI implementation. |
| 78 static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance(); | 78 static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance(); |
| 79 | 79 |
| 80 // BrowserContextKeyedAPI implementation. | 80 // BrowserContextKeyedAPI implementation. |
| 81 virtual void Shutdown() OVERRIDE; | 81 virtual void Shutdown() override; |
| 82 | 82 |
| 83 // EventRouter::Observer implementation. | 83 // EventRouter::Observer implementation. |
| 84 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) | 84 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
| 85 OVERRIDE; | 85 override; |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 friend class BrowserContextKeyedAPIFactory<InputMethodAPI>; | 88 friend class BrowserContextKeyedAPIFactory<InputMethodAPI>; |
| 89 | 89 |
| 90 // BrowserContextKeyedAPI implementation. | 90 // BrowserContextKeyedAPI implementation. |
| 91 static const char* service_name() { | 91 static const char* service_name() { |
| 92 return "InputMethodAPI"; | 92 return "InputMethodAPI"; |
| 93 } | 93 } |
| 94 static const bool kServiceIsNULLWhileTesting = true; | 94 static const bool kServiceIsNULLWhileTesting = true; |
| 95 | 95 |
| 96 content::BrowserContext* const context_; | 96 content::BrowserContext* const context_; |
| 97 | 97 |
| 98 // Created lazily upon OnListenerAdded. | 98 // Created lazily upon OnListenerAdded. |
| 99 scoped_ptr<chromeos::ExtensionInputMethodEventRouter> | 99 scoped_ptr<chromeos::ExtensionInputMethodEventRouter> |
| 100 input_method_event_router_; | 100 input_method_event_router_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI); | 102 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 } // namespace extensions | 105 } // namespace extensions |
| 106 | 106 |
| 107 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ | 107 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_ |
| OLD | NEW |