1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_
#include <map>
#include <string>
#include <vector>
#include "base/memory/singleton.h"
#include "base/scoped_observer.h"
#include "base/values.h"
#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
class Profile;
namespace chromeos {
class InputMethodEngineInterface;
class ImeObserver;
} // namespace chromeos
namespace extensions {
class ExtensionRegistry;
struct InputComponentInfo;
class InputImeEventRouter {
public:
static InputImeEventRouter* GetInstance();
bool RegisterImeExtension(
Profile* profile,
const std::string& extension_id,
const std::vector<extensions::InputComponentInfo>& input_components);
void UnregisterAllImes(const std::string& extension_id);
chromeos::InputMethodEngineInterface* GetEngine(
const std::string& extension_id,
const std::string& component_id);
chromeos::InputMethodEngineInterface* GetActiveEngine(
const std::string& extension_id);
// Called when a key event was handled.
void OnKeyEventHandled(const std::string& extension_id,
const std::string& request_id,
bool handled);
std::string AddRequest(const std::string& component_id,
chromeos::input_method::KeyEventHandle* key_data);
private:
friend struct DefaultSingletonTraits<InputImeEventRouter>;
typedef std::map<std::string, std::pair<std::string,
chromeos::input_method::KeyEventHandle*> > RequestMap;
InputImeEventRouter();
~InputImeEventRouter();
// The engine map from extension_id to an engine.
std::map<std::string, chromeos::InputMethodEngineInterface*> engine_map_;
unsigned int next_request_id_;
RequestMap request_map_;
DISALLOW_COPY_AND_ASSIGN(InputImeEventRouter);
};
class InputImeSetCompositionFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.setComposition",
INPUT_IME_SETCOMPOSITION)
protected:
virtual ~InputImeSetCompositionFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeClearCompositionFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.clearComposition",
INPUT_IME_CLEARCOMPOSITION)
protected:
virtual ~InputImeClearCompositionFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeCommitTextFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.commitText", INPUT_IME_COMMITTEXT)
protected:
virtual ~InputImeCommitTextFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeSetCandidateWindowPropertiesFunction
: public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.setCandidateWindowProperties",
INPUT_IME_SETCANDIDATEWINDOWPROPERTIES)
protected:
virtual ~InputImeSetCandidateWindowPropertiesFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeSetCandidatesFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.setCandidates", INPUT_IME_SETCANDIDATES)
protected:
virtual ~InputImeSetCandidatesFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeSetCursorPositionFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.setCursorPosition",
INPUT_IME_SETCURSORPOSITION)
protected:
virtual ~InputImeSetCursorPositionFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeSetMenuItemsFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.setMenuItems", INPUT_IME_SETMENUITEMS)
protected:
virtual ~InputImeSetMenuItemsFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeUpdateMenuItemsFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.updateMenuItems",
INPUT_IME_UPDATEMENUITEMS)
protected:
virtual ~InputImeUpdateMenuItemsFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeDeleteSurroundingTextFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.deleteSurroundingText",
INPUT_IME_DELETESURROUNDINGTEXT)
protected:
virtual ~InputImeDeleteSurroundingTextFunction() {}
// ExtensionFunction:
virtual bool RunSync() override;
};
class InputImeKeyEventHandledFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled",
INPUT_IME_KEYEVENTHANDLED)
protected:
virtual ~InputImeKeyEventHandledFunction() {}
// ExtensionFunction:
virtual bool RunAsync() override;
};
class InputImeSendKeyEventsFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.sendKeyEvents",
INPUT_IME_SENDKEYEVENTS)
protected:
virtual ~InputImeSendKeyEventsFunction() {}
// ExtensionFunction:
virtual bool RunAsync() override;
};
class InputImeHideInputViewFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.hideInputView",
INPUT_IME_HIDEINPUTVIEW)
protected:
virtual ~InputImeHideInputViewFunction() {}
// ExtensionFunction:
virtual bool RunAsync() override;
};
class InputImeAPI : public BrowserContextKeyedAPI,
public ExtensionRegistryObserver,
public EventRouter::Observer {
public:
explicit InputImeAPI(content::BrowserContext* context);
virtual ~InputImeAPI();
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance();
// ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) override;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) override;
// EventRouter::Observer implementation.
virtual void OnListenerAdded(const EventListenerInfo& details) override;
private:
friend class BrowserContextKeyedAPIFactory<InputImeAPI>;
InputImeEventRouter* input_ime_event_router();
// BrowserContextKeyedAPI implementation.
static const char* service_name() {
return "InputImeAPI";
}
static const bool kServiceIsNULLWhileTesting = true;
content::BrowserContext* const browser_context_;
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_INPUT_IME_INPUT_IME_API_H_
|