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.getCurrentInputMethod method.
21 class GetCurrentInputMethodFunction : public UIThreadExtensionFunction {
23 GetCurrentInputMethodFunction() {}
26 virtual ~GetCurrentInputMethodFunction() {}
28 virtual ResponseAction Run() OVERRIDE;
31 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod",
32 INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD)
35 // Implements the inputMethodPrivate.setCurrentInputMethod method.
36 class SetCurrentInputMethodFunction : public UIThreadExtensionFunction {
38 SetCurrentInputMethodFunction() {}
41 virtual ~SetCurrentInputMethodFunction() {}
43 virtual ResponseAction Run() OVERRIDE;
46 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod",
47 INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD)
50 // Implements the inputMethodPrivate.getInputMethods method.
51 class GetInputMethodsFunction : public UIThreadExtensionFunction {
53 GetInputMethodsFunction() {}
56 virtual ~GetInputMethodsFunction() {}
58 virtual ResponseAction Run() OVERRIDE;
61 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
62 INPUTMETHODPRIVATE_GETINPUTMETHODS)
65 class InputMethodAPI : public BrowserContextKeyedAPI,
66 public extensions::EventRouter::Observer {
68 static const char kOnInputMethodChanged[];
70 explicit InputMethodAPI(content::BrowserContext* context);
71 virtual ~InputMethodAPI();
73 // Returns input method name for the given XKB (X keyboard extensions in X
75 static std::string GetInputMethodForXkb(const std::string& xkb_id);
77 // BrowserContextKeyedAPI implementation.
78 static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance();
80 // BrowserContextKeyedAPI implementation.
81 virtual void Shutdown() OVERRIDE;
83 // EventRouter::Observer implementation.
84 virtual void OnListenerAdded(const extensions::EventListenerInfo& details)
88 friend class BrowserContextKeyedAPIFactory<InputMethodAPI>;
90 // BrowserContextKeyedAPI implementation.
91 static const char* service_name() {
92 return "InputMethodAPI";
94 static const bool kServiceIsNULLWhileTesting = true;
96 content::BrowserContext* const context_;
98 // Created lazily upon OnListenerAdded.
99 scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
100 input_method_event_router_;
102 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI);
105 } // namespace extensions
107 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_