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 experimental.inputMethod.get method.
21 class GetInputMethodFunction : public SyncExtensionFunction {
23 GetInputMethodFunction();
26 virtual ~GetInputMethodFunction();
28 virtual bool RunSync() OVERRIDE;
31 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.get", INPUTMETHODPRIVATE_GET)
34 // Notify the initialization is done to input method engine.
35 // TODO(nona): remove this function.
36 class StartImeFunction : public SyncExtensionFunction {
41 virtual ~StartImeFunction();
43 virtual bool RunSync() OVERRIDE;
46 DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.startIme",
47 INPUTMETHODPRIVATE_STARTIME)
50 class InputMethodAPI : public BrowserContextKeyedAPI,
51 public extensions::EventRouter::Observer {
53 static const char kOnInputMethodChanged[];
55 explicit InputMethodAPI(content::BrowserContext* context);
56 virtual ~InputMethodAPI();
58 // Returns input method name for the given XKB (X keyboard extensions in X
60 static std::string GetInputMethodForXkb(const std::string& xkb_id);
62 // BrowserContextKeyedAPI implementation.
63 static BrowserContextKeyedAPIFactory<InputMethodAPI>* GetFactoryInstance();
65 // BrowserContextKeyedAPI implementation.
66 virtual void Shutdown() OVERRIDE;
68 // EventRouter::Observer implementation.
69 virtual void OnListenerAdded(const extensions::EventListenerInfo& details)
73 friend class BrowserContextKeyedAPIFactory<InputMethodAPI>;
75 // BrowserContextKeyedAPI implementation.
76 static const char* service_name() {
77 return "InputMethodAPI";
79 static const bool kServiceIsNULLWhileTesting = true;
81 content::BrowserContext* const context_;
83 // Created lazily upon OnListenerAdded.
84 scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
85 input_method_event_router_;
87 DISALLOW_COPY_AND_ASSIGN(InputMethodAPI);
90 } // namespace extensions
92 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_API_H_