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.
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.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"
15 class ExtensionInputMethodEventRouter;
18 namespace extensions {
20 // Implements the inputMethodPrivate.getInputMethodConfig method.
21 class GetInputMethodConfigFunction : public UIThreadExtensionFunction {
23 GetInputMethodConfigFunction() {}
26 virtual ~GetInputMethodConfigFunction() {}
28 virtual ResponseAction Run() override;
31 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethodConfig",
32 INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG)
33 DISALLOW_COPY_AND_ASSIGN(GetInputMethodConfigFunction);
36 // Implements the inputMethodPrivate.getCurrentInputMethod method.
37 class GetCurrentInputMethodFunction : public UIThreadExtensionFunction {
39 GetCurrentInputMethodFunction() {}
42 virtual ~GetCurrentInputMethodFunction() {}
44 virtual ResponseAction Run() override;
47 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod",
48 INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD)
49 DISALLOW_COPY_AND_ASSIGN(GetCurrentInputMethodFunction);
52 // Implements the inputMethodPrivate.setCurrentInputMethod method.
53 class SetCurrentInputMethodFunction : public UIThreadExtensionFunction {
55 SetCurrentInputMethodFunction() {}
58 virtual ~SetCurrentInputMethodFunction() {}
60 virtual ResponseAction Run() override;
63 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod",
64 INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD)
65 DISALLOW_COPY_AND_ASSIGN(SetCurrentInputMethodFunction);
68 // Implements the inputMethodPrivate.getInputMethods method.
69 class GetInputMethodsFunction : public UIThreadExtensionFunction {
71 GetInputMethodsFunction() {}
74 virtual ~GetInputMethodsFunction() {}
76 virtual ResponseAction Run() override;
79 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
80 INPUTMETHODPRIVATE_GETINPUTMETHODS)
81 DISALLOW_COPY_AND_ASSIGN(GetInputMethodsFunction);
84 class InputMethodAPI : public BrowserContextKeyedAPI,
85 public extensions::EventRouter::Observer {
87 static const char kOnInputMethodChanged[];
89 explicit InputMethodAPI(content::BrowserContext* context);
90 virtual ~InputMethodAPI();
92 // Returns input method name for the given XKB (X keyboard extensions in X
94 static std::string GetInputMethodForXkb(const std::string& xkb_id);
96 // BrowserContextKeyedAPI implementation.
97 static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance();
99 // BrowserContextKeyedAPI implementation.
100 virtual void Shutdown() override;
102 // EventRouter::Observer implementation.
103 virtual void OnListenerAdded(const extensions::EventListenerInfo& details)
107 friend class BrowserContextKeyedAPIFactory<InputMethodAPI>;
109 // BrowserContextKeyedAPI implementation.
110 static const char* service_name() {
111 return "InputMethodAPI";
113 static const bool kServiceIsNULLWhileTesting = true;
115 content::BrowserContext* const context_;
117 // Created lazily upon OnListenerAdded.
118 scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
119 input_method_event_router_;
121 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI);
124 } // namespace extensions
126 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_