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 ~GetInputMethodConfigFunction() override
{}
28 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 ~GetCurrentInputMethodFunction() override
{}
44 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 ~SetCurrentInputMethodFunction() override
{}
60 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 ~GetInputMethodsFunction() override
{}
76 ResponseAction
Run() override
;
79 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
80 INPUTMETHODPRIVATE_GETINPUTMETHODS
)
81 DISALLOW_COPY_AND_ASSIGN(GetInputMethodsFunction
);
84 // Implements the inputMethodPrivate.fetchAllDictionaryWords method.
85 class FetchAllDictionaryWordsFunction
: public UIThreadExtensionFunction
{
87 FetchAllDictionaryWordsFunction() {}
90 ~FetchAllDictionaryWordsFunction() override
{}
92 ResponseAction
Run() override
;
95 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.fetchAllDictionaryWords",
96 INPUTMETHODPRIVATE_FETCHALLDICTIONARYWORDS
)
97 DISALLOW_COPY_AND_ASSIGN(FetchAllDictionaryWordsFunction
);
100 // Implements the inputMethodPrivate.addWordToDictionary method.
101 class AddWordToDictionaryFunction
: public UIThreadExtensionFunction
{
103 AddWordToDictionaryFunction() {}
106 ~AddWordToDictionaryFunction() override
{}
108 ResponseAction
Run() override
;
111 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.addWordToDictionary",
112 INPUTMETHODPRIVATE_ADDWORDTODICTIONARY
)
113 DISALLOW_COPY_AND_ASSIGN(AddWordToDictionaryFunction
);
116 class InputMethodAPI
: public BrowserContextKeyedAPI
,
117 public extensions::EventRouter::Observer
{
119 static const char kOnInputMethodChanged
[];
121 explicit InputMethodAPI(content::BrowserContext
* context
);
122 ~InputMethodAPI() override
;
124 // Returns input method name for the given XKB (X keyboard extensions in X
125 // Window System) id.
126 static std::string
GetInputMethodForXkb(const std::string
& xkb_id
);
128 // BrowserContextKeyedAPI implementation.
129 static BrowserContextKeyedAPIFactory
<InputMethodAPI
>* GetFactoryInstance();
131 // BrowserContextKeyedAPI implementation.
132 void Shutdown() override
;
134 // EventRouter::Observer implementation.
135 void OnListenerAdded(const extensions::EventListenerInfo
& details
) override
;
138 friend class BrowserContextKeyedAPIFactory
<InputMethodAPI
>;
140 // BrowserContextKeyedAPI implementation.
141 static const char* service_name() {
142 return "InputMethodAPI";
144 static const bool kServiceIsNULLWhileTesting
= true;
146 content::BrowserContext
* const context_
;
148 // Created lazily upon OnListenerAdded.
149 scoped_ptr
<chromeos::ExtensionInputMethodEventRouter
>
150 input_method_event_router_
;
152 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI
);
155 } // namespace extensions
157 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_