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

Unified Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 800853006: Reject connection attempts without prompt if target app doesn't handle the event anyway. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link to bug in comment Created 6 years 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 | « no previous file | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/messaging/message_service.cc
diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc
index 3678b0029234a1119b660681387980c30b5679da..49d407f530991546644c78902c42666058083222 100644
--- a/chrome/browser/extensions/api/messaging/message_service.cc
+++ b/chrome/browser/extensions/api/messaging/message_service.cc
@@ -30,6 +30,7 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
+#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
@@ -343,8 +344,25 @@ void MessageService::OpenChannelToExtension(
// enabling in incognito. In practice this means platform apps only.
if (!is_web_connection || IncognitoInfo::IsSplitMode(target_extension) ||
target_extension->can_be_incognito_enabled()) {
- DispatchOnDisconnect(source, receiver_port_id,
- kReceivingEndDoesntExistError);
+ OnOpenChannelAllowed(params.Pass(), false);
+ return;
+ }
+
+ // If the target extension isn't even listening for connect/message events,
+ // there is no need to go any further and the connection should be
+ // rejected without showing a prompt. See http://crbug.com/442497
+ EventRouter* event_router = EventRouter::Get(context);
+ const char* const events[] = {"runtime.onConnectExternal",
+ "runtime.onMessageExternal",
+ "extension.onRequestExternal",
+ nullptr};
+ bool has_event_listener = false;
+ for (const char* const* event = events; *event; event++) {
+ has_event_listener |=
+ event_router->ExtensionHasEventListener(target_extension_id, *event);
+ }
+ if (!has_event_listener) {
+ OnOpenChannelAllowed(params.Pass(), false);
return;
}
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698