Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / input_method_api.h
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
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_
7
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"
13
14 namespace chromeos {
15 class ExtensionInputMethodEventRouter;
16 }
17
18 namespace extensions {
19
20 // Implements the inputMethodPrivate.getInputMethodConfig  method.
21 class GetInputMethodConfigFunction : public UIThreadExtensionFunction {
22  public:
23   GetInputMethodConfigFunction() {}
24
25  protected:
26   virtual ~GetInputMethodConfigFunction() {}
27
28   virtual ResponseAction Run() override;
29
30  private:
31   DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethodConfig",
32                              INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG)
33   DISALLOW_COPY_AND_ASSIGN(GetInputMethodConfigFunction);
34 };
35
36 // Implements the inputMethodPrivate.getCurrentInputMethod method.
37 class GetCurrentInputMethodFunction : public UIThreadExtensionFunction {
38  public:
39   GetCurrentInputMethodFunction() {}
40
41  protected:
42   virtual ~GetCurrentInputMethodFunction() {}
43
44   virtual ResponseAction Run() override;
45
46  private:
47   DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod",
48                              INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD)
49   DISALLOW_COPY_AND_ASSIGN(GetCurrentInputMethodFunction);
50 };
51
52 // Implements the inputMethodPrivate.setCurrentInputMethod method.
53 class SetCurrentInputMethodFunction : public UIThreadExtensionFunction {
54  public:
55   SetCurrentInputMethodFunction() {}
56
57  protected:
58   virtual ~SetCurrentInputMethodFunction() {}
59
60   virtual ResponseAction Run() override;
61
62  private:
63   DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod",
64                              INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD)
65   DISALLOW_COPY_AND_ASSIGN(SetCurrentInputMethodFunction);
66 };
67
68 // Implements the inputMethodPrivate.getInputMethods method.
69 class GetInputMethodsFunction : public UIThreadExtensionFunction {
70  public:
71   GetInputMethodsFunction() {}
72
73  protected:
74   virtual ~GetInputMethodsFunction() {}
75
76   virtual ResponseAction Run() override;
77
78  private:
79   DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
80                              INPUTMETHODPRIVATE_GETINPUTMETHODS)
81   DISALLOW_COPY_AND_ASSIGN(GetInputMethodsFunction);
82 };
83
84 class InputMethodAPI : public BrowserContextKeyedAPI,
85                        public extensions::EventRouter::Observer {
86  public:
87   static const char kOnInputMethodChanged[];
88
89   explicit InputMethodAPI(content::BrowserContext* context);
90   virtual ~InputMethodAPI();
91
92   // Returns input method name for the given XKB (X keyboard extensions in X
93   // Window System) id.
94   static std::string GetInputMethodForXkb(const std::string& xkb_id);
95
96   // BrowserContextKeyedAPI implementation.
97   static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance();
98
99   // BrowserContextKeyedAPI implementation.
100   virtual void Shutdown() override;
101
102   // EventRouter::Observer implementation.
103   virtual void OnListenerAdded(const extensions::EventListenerInfo& details)
104       override;
105
106  private:
107   friend class BrowserContextKeyedAPIFactory<InputMethodAPI>;
108
109   // BrowserContextKeyedAPI implementation.
110   static const char* service_name() {
111     return "InputMethodAPI";
112   }
113   static const bool kServiceIsNULLWhileTesting = true;
114
115   content::BrowserContext* const context_;
116
117   // Created lazily upon OnListenerAdded.
118   scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
119       input_method_event_router_;
120
121   DISALLOW_COPY_AND_ASSIGN(InputMethodAPI);
122 };
123
124 }  // namespace extensions
125
126 #endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_