Commit 955667fa authored by shuchen@chromium.org's avatar shuchen@chromium.org

Checks whether background is defined in IME extension manifest. And also move...

Checks whether background is defined in IME extension manifest. And also move KeyEventDone logic from InputMethodEngine to input_ime_api.cc.

BUG=394682, 394420
TEST=Verified on linux_chromeos and Pixel device.

Review URL: https://codereview.chromium.org/400523005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283755 0039d316-1c4b-4281-b951-d872f2087c98
parent 42c47a98
...@@ -470,14 +470,6 @@ bool InputMethodEngine::IsActive() const { ...@@ -470,14 +470,6 @@ bool InputMethodEngine::IsActive() const {
return active_; return active_;
} }
void InputMethodEngine::KeyEventDone(input_method::KeyEventHandle* key_data,
bool handled) {
KeyEventDoneCallback* callback =
reinterpret_cast<KeyEventDoneCallback*>(key_data);
callback->Run(handled);
delete callback;
}
bool InputMethodEngine::DeleteSurroundingText(int context_id, bool InputMethodEngine::DeleteSurroundingText(int context_id,
int offset, int offset,
size_t number_of_chars, size_t number_of_chars,
......
...@@ -77,8 +77,6 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -77,8 +77,6 @@ class InputMethodEngine : public InputMethodEngineInterface {
virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE; virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE; virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
virtual bool IsActive() const OVERRIDE; virtual bool IsActive() const OVERRIDE;
virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
bool handled) OVERRIDE;
virtual bool DeleteSurroundingText(int context_id, virtual bool DeleteSurroundingText(int context_id,
int offset, int offset,
size_t number_of_chars, size_t number_of_chars,
......
...@@ -231,10 +231,6 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface { ...@@ -231,10 +231,6 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface {
// Returns true if this IME is active, false if not. // Returns true if this IME is active, false if not.
virtual bool IsActive() const = 0; virtual bool IsActive() const = 0;
// Inform the engine that a key event has been processed.
virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
bool handled) = 0;
// Deletes |number_of_chars| unicode characters as the basis of |offset| from // Deletes |number_of_chars| unicode characters as the basis of |offset| from
// the surrounding text. The |offset| is relative position based on current // the surrounding text. The |offset| is relative position based on current
// caret. // caret.
......
...@@ -90,10 +90,6 @@ bool MockInputMethodEngine::IsActive() const { ...@@ -90,10 +90,6 @@ bool MockInputMethodEngine::IsActive() const {
return true; return true;
} }
void MockInputMethodEngine::KeyEventDone(input_method::KeyEventHandle* key_data,
bool handled) {
}
bool MockInputMethodEngine::DeleteSurroundingText(int context_id, bool MockInputMethodEngine::DeleteSurroundingText(int context_id,
int offset, int offset,
size_t number_of_chars, size_t number_of_chars,
......
...@@ -66,8 +66,6 @@ class MockInputMethodEngine : public InputMethodEngineInterface { ...@@ -66,8 +66,6 @@ class MockInputMethodEngine : public InputMethodEngineInterface {
virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE; virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE; virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
virtual bool IsActive() const OVERRIDE; virtual bool IsActive() const OVERRIDE;
virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
bool handled) OVERRIDE;
virtual bool DeleteSurroundingText(int context_id, virtual bool DeleteSurroundingText(int context_id,
int offset, int offset,
size_t number_of_chars, size_t number_of_chars,
......
...@@ -7,12 +7,15 @@ ...@@ -7,12 +7,15 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/api/input_ime.h" #include "chrome/common/extensions/api/input_ime.h"
#include "chrome/common/extensions/api/input_ime/input_components_handler.h" #include "chrome/common/extensions/api/input_ime/input_components_handler.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_registry.h" #include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/manifest_handlers/background_info.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "chrome/browser/chromeos/input_method/input_method_engine.h" #include "chrome/browser/chromeos/input_method/input_method_engine.h"
...@@ -80,13 +83,32 @@ static void DispatchEventToExtension(Profile* profile, ...@@ -80,13 +83,32 @@ static void DispatchEventToExtension(Profile* profile,
->DispatchEventToExtension(extension_id, event.Pass()); ->DispatchEventToExtension(extension_id, event.Pass());
} }
void CallbackKeyEventHandle(chromeos::input_method::KeyEventHandle* key_data,
bool handled) {
base::Callback<void(bool consumed)>* callback =
reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data);
callback->Run(handled);
delete callback;
}
} // namespace } // namespace
namespace chromeos { namespace chromeos {
class ImeObserver : public InputMethodEngineInterface::Observer { class ImeObserver : public InputMethodEngineInterface::Observer {
public: public:
ImeObserver(Profile* profile, const std::string& extension_id) ImeObserver(Profile* profile, const std::string& extension_id)
: profile_(profile), extension_id_(extension_id) {} : profile_(profile), extension_id_(extension_id), has_background_(false) {
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile_);
ExtensionService* extension_service = extension_system->extension_service();
const extensions::Extension* extension =
extension_service->GetExtensionById(extension_id, false);
DCHECK(extension);
extensions::BackgroundInfo* info = static_cast<extensions::BackgroundInfo*>(
extension->GetManifestData("background"));
if (info)
has_background_ = info->has_background_page();
}
virtual ~ImeObserver() {} virtual ~ImeObserver() {}
...@@ -163,13 +185,10 @@ class ImeObserver : public InputMethodEngineInterface::Observer { ...@@ -163,13 +185,10 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
// If there is no listener for the event, no need to dispatch the event to // If there is no listener for the event, no need to dispatch the event to
// extension. Instead, releases the key event for default system behavior. // extension. Instead, releases the key event for default system behavior.
if (!HasKeyEventListener()) { if (!ShouldForwardKeyEvent()) {
// Continue processing the key event so that the physical keyboard can // Continue processing the key event so that the physical keyboard can
// still work. // still work.
base::Callback<void(bool consumed)>* callback = CallbackKeyEventHandle(key_data, false);
reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data);
callback->Run(false);
delete callback;
return; return;
} }
...@@ -281,14 +300,20 @@ class ImeObserver : public InputMethodEngineInterface::Observer { ...@@ -281,14 +300,20 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
} }
private: private:
bool HasKeyEventListener() const { // Returns true if the extension is ready to accept key event, otherwise
return extensions::EventRouter::Get(profile_) // returns false.
bool ShouldForwardKeyEvent() const {
// Need to check the background page first since the
// ExtensionHasEventListner returns true if the extension does not have a
// background page. See crbug.com/394682.
return has_background_ && extensions::EventRouter::Get(profile_)
->ExtensionHasEventListener(extension_id_, ->ExtensionHasEventListener(extension_id_,
input_ime::OnKeyEvent::kEventName); input_ime::OnKeyEvent::kEventName);
} }
Profile* profile_; Profile* profile_;
std::string extension_id_; std::string extension_id_;
bool has_background_;
DISALLOW_COPY_AND_ASSIGN(ImeObserver); DISALLOW_COPY_AND_ASSIGN(ImeObserver);
}; };
...@@ -415,13 +440,7 @@ void InputImeEventRouter::OnKeyEventHandled( ...@@ -415,13 +440,7 @@ void InputImeEventRouter::OnKeyEventHandled(
chromeos::input_method::KeyEventHandle* key_data = request->second.second; chromeos::input_method::KeyEventHandle* key_data = request->second.second;
request_map_.erase(request); request_map_.erase(request);
InputMethodEngineInterface* engine = GetEngine(extension_id, engine_id); CallbackKeyEventHandle(key_data, handled);
if (!engine) {
LOG(ERROR) << "Engine does not exist: " << engine_id;
return;
}
engine->KeyEventDone(key_data, handled);
} }
std::string InputImeEventRouter::AddRequest( std::string InputImeEventRouter::AddRequest(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment