Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 400523005: Checks whether background is defined in IME extension manifest. And also move KeyEventDone logic fr… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: modified per comments. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/input_method/mock_input_method_engine.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/input_ime/input_ime_api.cc
diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.cc b/chrome/browser/extensions/api/input_ime/input_ime_api.cc
index 6d848aea22aa145ff601fc59b3619ea677c60d29..b35997b4cc6de409e4fbbcce37f2634897ca521a 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api.cc
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api.cc
@@ -7,12 +7,15 @@
#include "base/strings/string_number_conversions.h"
#include "base/values.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/common/extensions/api/input_ime.h"
#include "chrome/common/extensions/api/input_ime/input_components_handler.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_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)
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
@@ -80,13 +83,32 @@ static void DispatchEventToExtension(Profile* profile,
->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 chromeos {
class ImeObserver : public InputMethodEngineInterface::Observer {
public:
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() {}
@@ -163,13 +185,10 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
// 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.
- if (!HasKeyEventListener()) {
+ if (!ShouldForwardKeyEvent()) {
// Continue processing the key event so that the physical keyboard can
// still work.
- base::Callback<void(bool consumed)>* callback =
- reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data);
- callback->Run(false);
- delete callback;
+ CallbackKeyEventHandle(key_data, false);
return;
}
@@ -281,14 +300,20 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
}
private:
- bool HasKeyEventListener() const {
- return extensions::EventRouter::Get(profile_)
+ // Returns true if the extension is ready to accept key event, otherwise
+ // 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_,
input_ime::OnKeyEvent::kEventName);
}
Profile* profile_;
std::string extension_id_;
+ bool has_background_;
DISALLOW_COPY_AND_ASSIGN(ImeObserver);
};
@@ -415,13 +440,7 @@ void InputImeEventRouter::OnKeyEventHandled(
chromeos::input_method::KeyEventHandle* key_data = request->second.second;
request_map_.erase(request);
- InputMethodEngineInterface* engine = GetEngine(extension_id, engine_id);
- if (!engine) {
- LOG(ERROR) << "Engine does not exist: " << engine_id;
- return;
- }
-
- engine->KeyEventDone(key_data, handled);
+ CallbackKeyEventHandle(key_data, handled);
}
std::string InputImeEventRouter::AddRequest(
« no previous file with comments | « chrome/browser/chromeos/input_method/mock_input_method_engine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698