| OLD | NEW |
| 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 Loading... |
| 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 the event is privileged, only send to extension processes. Otherwise, |
| 281 // it's OK to send to normal renderers (e.g., for content scripts). |
| 282 if (ExtensionAPI::GetInstance()->IsPrivileged(event->event_name) && |
| 283 !process_map->Contains(extension->id(), listener->process->id())) { |
| 278 continue; | 284 continue; |
| 285 } |
| 279 | 286 |
| 280 // Is this event from a different profile than the renderer (ie, an | 287 // Is this event from a different profile than the renderer (ie, an |
| 281 // incognito tab event sent to a normal process, or vice versa). | 288 // incognito tab event sent to a normal process, or vice versa). |
| 282 bool cross_incognito = event->restrict_to_profile && | 289 bool cross_incognito = event->restrict_to_profile && |
| 283 listener_profile != event->restrict_to_profile; | 290 listener_profile != event->restrict_to_profile; |
| 284 // Send the event with different arguments to extensions that can't | 291 // Send the event with different arguments to extensions that can't |
| 285 // cross incognito, if necessary. | 292 // cross incognito, if necessary. |
| 286 if (cross_incognito && !service->CanCrossIncognito(extension)) { | 293 if (cross_incognito && !service->CanCrossIncognito(extension)) { |
| 287 if (!event->cross_incognito_args.empty()) { | 294 if (!event->cross_incognito_args.empty()) { |
| 288 DispatchEvent(listener->process, listener->extension_id, | 295 DispatchEvent(listener->process, listener->extension_id, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); | 389 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); |
| 383 DispatchPendingEvents(eh->extension_id()); | 390 DispatchPendingEvents(eh->extension_id()); |
| 384 break; | 391 break; |
| 385 } | 392 } |
| 386 // TODO(tessamac): if background page crashed/failed clear queue. | 393 // TODO(tessamac): if background page crashed/failed clear queue. |
| 387 default: | 394 default: |
| 388 NOTREACHED(); | 395 NOTREACHED(); |
| 389 return; | 396 return; |
| 390 } | 397 } |
| 391 } | 398 } |
| OLD | NEW |