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 ExtensionDictionaryEventRouter
;
16 class ExtensionInputMethodEventRouter
;
19 namespace extensions
{
21 // Implements the inputMethodPrivate.getInputMethodConfig method.
22 class GetInputMethodConfigFunction
: public UIThreadExtensionFunction
{
24 GetInputMethodConfigFunction() {}
27 ~GetInputMethodConfigFunction() override
{}
29 ResponseAction
Run() override
;
32 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethodConfig",
33 INPUTMETHODPRIVATE_GETINPUTMETHODCONFIG
)
34 DISALLOW_COPY_AND_ASSIGN(GetInputMethodConfigFunction
);
37 // Implements the inputMethodPrivate.getCurrentInputMethod method.
38 class GetCurrentInputMethodFunction
: public UIThreadExtensionFunction
{
40 GetCurrentInputMethodFunction() {}
43 ~GetCurrentInputMethodFunction() override
{}
45 ResponseAction
Run() override
;
48 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getCurrentInputMethod",
49 INPUTMETHODPRIVATE_GETCURRENTINPUTMETHOD
)
50 DISALLOW_COPY_AND_ASSIGN(GetCurrentInputMethodFunction
);
53 // Implements the inputMethodPrivate.setCurrentInputMethod method.
54 class SetCurrentInputMethodFunction
: public UIThreadExtensionFunction
{
56 SetCurrentInputMethodFunction() {}
59 ~SetCurrentInputMethodFunction() override
{}
61 ResponseAction
Run() override
;
64 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setCurrentInputMethod",
65 INPUTMETHODPRIVATE_SETCURRENTINPUTMETHOD
)
66 DISALLOW_COPY_AND_ASSIGN(SetCurrentInputMethodFunction
);
69 // Implements the inputMethodPrivate.getInputMethods method.
70 class GetInputMethodsFunction
: public UIThreadExtensionFunction
{
72 GetInputMethodsFunction() {}
75 ~GetInputMethodsFunction() override
{}
77 ResponseAction
Run() override
;
80 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getInputMethods",
81 INPUTMETHODPRIVATE_GETINPUTMETHODS
)
82 DISALLOW_COPY_AND_ASSIGN(GetInputMethodsFunction
);
85 // Implements the inputMethodPrivate.fetchAllDictionaryWords method.
86 class FetchAllDictionaryWordsFunction
: public UIThreadExtensionFunction
{
88 FetchAllDictionaryWordsFunction() {}
91 ~FetchAllDictionaryWordsFunction() override
{}
93 ResponseAction
Run() override
;
96 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.fetchAllDictionaryWords",
97 INPUTMETHODPRIVATE_FETCHALLDICTIONARYWORDS
)
98 DISALLOW_COPY_AND_ASSIGN(FetchAllDictionaryWordsFunction
);
101 // Implements the inputMethodPrivate.addWordToDictionary method.
102 class AddWordToDictionaryFunction
: public UIThreadExtensionFunction
{
104 AddWordToDictionaryFunction() {}
107 ~AddWordToDictionaryFunction() override
{}
109 ResponseAction
Run() override
;
112 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.addWordToDictionary",
113 INPUTMETHODPRIVATE_ADDWORDTODICTIONARY
)
114 DISALLOW_COPY_AND_ASSIGN(AddWordToDictionaryFunction
);
117 // Implements the inputMethodPrivate.getEncryptSyncEnabled method.
118 class GetEncryptSyncEnabledFunction
: public UIThreadExtensionFunction
{
120 GetEncryptSyncEnabledFunction() {}
123 ~GetEncryptSyncEnabledFunction() override
{}
125 ResponseAction
Run() override
;
128 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.getEncryptSyncEnabled",
129 INPUTMETHODPRIVATE_GETENCRYPTSYNCENABLED
)
130 DISALLOW_COPY_AND_ASSIGN(GetEncryptSyncEnabledFunction
);
133 class InputMethodAPI
: public BrowserContextKeyedAPI
,
134 public extensions::EventRouter::Observer
{
136 static const char kOnDictionaryChanged
[];
137 static const char kOnDictionaryLoaded
[];
138 static const char kOnInputMethodChanged
[];
140 explicit InputMethodAPI(content::BrowserContext
* context
);
141 ~InputMethodAPI() override
;
143 // Returns input method name for the given XKB (X keyboard extensions in X
144 // Window System) id.
145 static std::string
GetInputMethodForXkb(const std::string
& xkb_id
);
147 // BrowserContextKeyedAPI implementation.
148 static BrowserContextKeyedAPIFactory
<InputMethodAPI
>* GetFactoryInstance();
150 // BrowserContextKeyedAPI implementation.
151 void Shutdown() override
;
153 // EventRouter::Observer implementation.
154 void OnListenerAdded(const extensions::EventListenerInfo
& details
) override
;
157 friend class BrowserContextKeyedAPIFactory
<InputMethodAPI
>;
159 // BrowserContextKeyedAPI implementation.
160 static const char* service_name() {
161 return "InputMethodAPI";
163 static const bool kServiceIsNULLWhileTesting
= true;
165 content::BrowserContext
* const context_
;
167 // Created lazily upon OnListenerAdded.
168 scoped_ptr
<chromeos::ExtensionInputMethodEventRouter
>
169 input_method_event_router_
;
170 scoped_ptr
<chromeos::ExtensionDictionaryEventRouter
>
171 dictionary_event_router_
;
173 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI
);
176 } // namespace extensions
178 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_