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

Side by Side Diff: chrome/browser/extensions/extension_event_router.cc

Issue 8585005: Enable content scripts to receive extension API events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_event_router.h" 5 #include "chrome/browser/extensions/extension_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_devtools_manager.h" 10 #include "chrome/browser/extensions/extension_devtools_manager.h"
11 #include "chrome/browser/extensions/extension_host.h" 11 #include "chrome/browser/extensions/extension_host.h"
12 #include "chrome/browser/extensions/extension_process_manager.h" 12 #include "chrome/browser/extensions/extension_process_manager.h"
13 #include "chrome/browser/extensions/extension_processes_api.h" 13 #include "chrome/browser/extensions/extension_processes_api.h"
14 #include "chrome/browser/extensions/extension_processes_api_constants.h" 14 #include "chrome/browser/extensions/extension_processes_api_constants.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_tabs_module.h" 16 #include "chrome/browser/extensions/extension_tabs_module.h"
17 #include "chrome/browser/extensions/extension_webrequest_api.h" 17 #include "chrome/browser/extensions/extension_webrequest_api.h"
18 #include "chrome/browser/extensions/process_map.h" 18 #include "chrome/browser/extensions/process_map.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_messages.h" 22 #include "chrome/common/extensions/extension_messages.h"
23 #include "chrome/common/extensions/api/extension_api.h"
23 #include "content/browser/child_process_security_policy.h" 24 #include "content/browser/child_process_security_policy.h"
24 #include "content/browser/renderer_host/render_process_host.h" 25 #include "content/browser/renderer_host/render_process_host.h"
25 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
26 27
27 using content::BrowserThread; 28 using content::BrowserThread;
29 using extensions::ExtensionAPI;
28 30
29 namespace { 31 namespace {
30 32
31 const char kDispatchEvent[] = "Event.dispatchJSON"; 33 const char kDispatchEvent[] = "Event.dispatchJSON";
32 34
33 void NotifyEventListenerRemovedOnIOThread( 35 void NotifyEventListenerRemovedOnIOThread(
34 void* profile, 36 void* profile,
35 const std::string& extension_id, 37 const std::string& extension_id,
36 const std::string& sub_event_name) { 38 const std::string& sub_event_name) {
37 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( 39 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 269
268 // The extension could have been removed, but we do not unregister it until 270 // The extension could have been removed, but we do not unregister it until
269 // the extension process is unloaded. 271 // the extension process is unloaded.
270 if (!extension) 272 if (!extension)
271 continue; 273 continue;
272 274
273 Profile* listener_profile = Profile::FromBrowserContext( 275 Profile* listener_profile = Profile::FromBrowserContext(
274 listener->process->browser_context()); 276 listener->process->browser_context());
275 extensions::ProcessMap* process_map = 277 extensions::ProcessMap* process_map =
276 listener_profile->GetExtensionService()->process_map(); 278 listener_profile->GetExtensionService()->process_map();
277 if (!process_map->Contains(extension->id(), listener->process->id())) 279
280 if (ExtensionAPI::GetInstance()->IsPrivileged(event->event_name) &&
Yoyo Zhou 2011/11/16 23:51:13 Add a comment here to indicate what this check is
Aaron Boodman 2011/11/17 07:17:52 Done.
281 !process_map->Contains(extension->id(), listener->process->id())) {
278 continue; 282 continue;
283 }
279 284
280 // Is this event from a different profile than the renderer (ie, an 285 // Is this event from a different profile than the renderer (ie, an
281 // incognito tab event sent to a normal process, or vice versa). 286 // incognito tab event sent to a normal process, or vice versa).
282 bool cross_incognito = event->restrict_to_profile && 287 bool cross_incognito = event->restrict_to_profile &&
283 listener_profile != event->restrict_to_profile; 288 listener_profile != event->restrict_to_profile;
284 // Send the event with different arguments to extensions that can't 289 // Send the event with different arguments to extensions that can't
285 // cross incognito, if necessary. 290 // cross incognito, if necessary.
286 if (cross_incognito && !service->CanCrossIncognito(extension)) { 291 if (cross_incognito && !service->CanCrossIncognito(extension)) {
287 if (!event->cross_incognito_args.empty()) { 292 if (!event->cross_incognito_args.empty()) {
288 DispatchEvent(listener->process, listener->extension_id, 293 DispatchEvent(listener->process, listener->extension_id,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); 387 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr();
383 DispatchPendingEvents(eh->extension_id()); 388 DispatchPendingEvents(eh->extension_id());
384 break; 389 break;
385 } 390 }
386 // TODO(tessamac): if background page crashed/failed clear queue. 391 // TODO(tessamac): if background page crashed/failed clear queue.
387 default: 392 default:
388 NOTREACHED(); 393 NOTREACHED();
389 return; 394 return;
390 } 395 }
391 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698