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

Side by Side 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 5 years, 12 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_messages_apitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/messaging/message_service.h" 5 #include "chrome/browser/extensions/api/messaging/message_service.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/tab_contents/tab_util.h" 24 #include "chrome/browser/tab_contents/tab_util.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/render_widget_host.h" 29 #include "content/public/browser/render_widget_host.h"
30 #include "content/public/browser/render_widget_host_view.h" 30 #include "content/public/browser/render_widget_host_view.h"
31 #include "content/public/browser/site_instance.h" 31 #include "content/public/browser/site_instance.h"
32 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
33 #include "extensions/browser/event_router.h"
33 #include "extensions/browser/extension_host.h" 34 #include "extensions/browser/extension_host.h"
34 #include "extensions/browser/extension_registry.h" 35 #include "extensions/browser/extension_registry.h"
35 #include "extensions/browser/extension_system.h" 36 #include "extensions/browser/extension_system.h"
36 #include "extensions/browser/extensions_browser_client.h" 37 #include "extensions/browser/extensions_browser_client.h"
37 #include "extensions/browser/lazy_background_task_queue.h" 38 #include "extensions/browser/lazy_background_task_queue.h"
38 #include "extensions/browser/pref_names.h" 39 #include "extensions/browser/pref_names.h"
39 #include "extensions/browser/process_manager.h" 40 #include "extensions/browser/process_manager.h"
40 #include "extensions/common/extension.h" 41 #include "extensions/common/extension.h"
41 #include "extensions/common/manifest_constants.h" 42 #include "extensions/common/manifest_constants.h"
42 #include "extensions/common/manifest_handlers/background_info.h" 43 #include "extensions/common/manifest_handlers/background_info.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Give the user a chance to accept an incognito connection from the web if 337 // Give the user a chance to accept an incognito connection from the web if
337 // they haven't already, with the conditions: 338 // they haven't already, with the conditions:
338 // - Only for spanning-mode incognito. We don't want the complication of 339 // - Only for spanning-mode incognito. We don't want the complication of
339 // spinning up an additional process here which might need to do some 340 // spinning up an additional process here which might need to do some
340 // setup that we're not expecting. 341 // setup that we're not expecting.
341 // - Only for extensions that can't normally be enabled in incognito, since 342 // - Only for extensions that can't normally be enabled in incognito, since
342 // that surface (e.g. chrome://extensions) should be the only one for 343 // that surface (e.g. chrome://extensions) should be the only one for
343 // enabling in incognito. In practice this means platform apps only. 344 // enabling in incognito. In practice this means platform apps only.
344 if (!is_web_connection || IncognitoInfo::IsSplitMode(target_extension) || 345 if (!is_web_connection || IncognitoInfo::IsSplitMode(target_extension) ||
345 target_extension->can_be_incognito_enabled()) { 346 target_extension->can_be_incognito_enabled()) {
346 DispatchOnDisconnect(source, receiver_port_id, 347 OnOpenChannelAllowed(params.Pass(), false);
347 kReceivingEndDoesntExistError);
348 return; 348 return;
349 } 349 }
350 350
351 // If the target extension isn't even listening for connect/message events,
352 // there is no need to go any further and the connection should be
353 // rejected without showing a prompt. See http://crbug.com/442497
354 EventRouter* event_router = EventRouter::Get(context);
355 const char* const events[] = {"runtime.onConnectExternal",
356 "runtime.onMessageExternal",
357 "extension.onRequestExternal",
358 nullptr};
359 bool has_event_listener = false;
360 for (const char* const* event = events; *event; event++) {
361 has_event_listener |=
362 event_router->ExtensionHasEventListener(target_extension_id, *event);
363 }
364 if (!has_event_listener) {
365 OnOpenChannelAllowed(params.Pass(), false);
366 return;
367 }
368
351 // This check may show a dialog. 369 // This check may show a dialog.
352 IncognitoConnectability::Get(context) 370 IncognitoConnectability::Get(context)
353 ->Query(target_extension, source_contents, source_url, 371 ->Query(target_extension, source_contents, source_url,
354 base::Bind(&MessageService::OnOpenChannelAllowed, 372 base::Bind(&MessageService::OnOpenChannelAllowed,
355 weak_factory_.GetWeakPtr(), base::Passed(&params))); 373 weak_factory_.GetWeakPtr(), base::Passed(&params)));
356 return; 374 return;
357 } 375 }
358 376
359 OnOpenChannelAllowed(params.Pass(), true); 377 OnOpenChannelAllowed(params.Pass(), true);
360 } 378 }
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 int channel_id) { 885 int channel_id) {
868 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); 886 MessageChannelMap::iterator channel_iter = channels_.find(channel_id);
869 if (channel_iter != channels_.end()) { 887 if (channel_iter != channels_.end()) {
870 for (const PendingMessage& message : queue) { 888 for (const PendingMessage& message : queue) {
871 DispatchMessage(message.first, channel_iter->second, message.second); 889 DispatchMessage(message.first, channel_iter->second, message.second);
872 } 890 }
873 } 891 }
874 } 892 }
875 893
876 } // namespace extensions 894 } // namespace extensions
OLDNEW
« 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