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

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

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 "content/browser/child_process_security_policy.h" 23 #include "content/browser/child_process_security_policy.h"
24 #include "content/browser/renderer_host/render_process_host.h"
25 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_process_host.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace { 29 namespace {
30 30
31 const char kDispatchEvent[] = "Event.dispatchJSON"; 31 const char kDispatchEvent[] = "Event.dispatchJSON";
32 32
33 void NotifyEventListenerRemovedOnIOThread( 33 void NotifyEventListenerRemovedOnIOThread(
34 void* profile, 34 void* profile,
35 const std::string& extension_id, 35 const std::string& extension_id,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 void ExtensionEventRouter::AddEventListener( 108 void ExtensionEventRouter::AddEventListener(
109 const std::string& event_name, 109 const std::string& event_name,
110 RenderProcessHost* process, 110 RenderProcessHost* process,
111 const std::string& extension_id) { 111 const std::string& extension_id) {
112 EventListener listener(process, extension_id); 112 EventListener listener(process, extension_id);
113 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name; 113 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name;
114 listeners_[event_name].insert(listener); 114 listeners_[event_name].insert(listener);
115 115
116 if (extension_devtools_manager_.get()) 116 if (extension_devtools_manager_.get())
117 extension_devtools_manager_->AddEventListener(event_name, process->id()); 117 extension_devtools_manager_->AddEventListener(event_name,
118 process->GetID());
118 119
119 // We lazily tell the TaskManager to start updating when listeners to the 120 // We lazily tell the TaskManager to start updating when listeners to the
120 // processes.onUpdated event arrive. 121 // processes.onUpdated event arrive.
121 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 122 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0)
122 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded(); 123 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded();
123 } 124 }
124 125
125 void ExtensionEventRouter::RemoveEventListener( 126 void ExtensionEventRouter::RemoveEventListener(
126 const std::string& event_name, 127 const std::string& event_name,
127 RenderProcessHost* process, 128 RenderProcessHost* process,
128 const std::string& extension_id) { 129 const std::string& extension_id) {
129 EventListener listener(process, extension_id); 130 EventListener listener(process, extension_id);
130 DCHECK_EQ(listeners_[event_name].count(listener), 1u) << 131 DCHECK_EQ(listeners_[event_name].count(listener), 1u) <<
131 " PID=" << process->id() << " extension=" << extension_id << 132 " PID=" << process->GetID() << " extension=" << extension_id <<
132 " event=" << event_name; 133 " event=" << event_name;
133 listeners_[event_name].erase(listener); 134 listeners_[event_name].erase(listener);
134 // Note: extension_id may point to data in the now-deleted listeners_ object. 135 // Note: extension_id may point to data in the now-deleted listeners_ object.
135 // Do not use. 136 // Do not use.
136 137
137 if (extension_devtools_manager_.get()) 138 if (extension_devtools_manager_.get())
138 extension_devtools_manager_->RemoveEventListener(event_name, process->id()); 139 extension_devtools_manager_->RemoveEventListener(event_name,
140 process->GetID());
139 141
140 // If a processes.onUpdated event listener is removed (or a process with one 142 // If a processes.onUpdated event listener is removed (or a process with one
141 // exits), then we let the TaskManager know that it has one fewer listener. 143 // exits), then we let the TaskManager know that it has one fewer listener.
142 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 144 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0)
143 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved(); 145 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved();
144 146
145 BrowserThread::PostTask( 147 BrowserThread::PostTask(
146 BrowserThread::IO, FROM_HERE, 148 BrowserThread::IO, FROM_HERE,
147 base::Bind( 149 base::Bind(
148 &NotifyEventListenerRemovedOnIOThread, 150 &NotifyEventListenerRemovedOnIOThread,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 266
265 const Extension* extension = service->GetExtensionById( 267 const Extension* extension = service->GetExtensionById(
266 listener->extension_id, false); 268 listener->extension_id, false);
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->GetBrowserContext());
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 if (!process_map->Contains(extension->id(), listener->process->GetID()))
278 continue; 280 continue;
279 281
280 // Is this event from a different profile than the renderer (ie, an 282 // Is this event from a different profile than the renderer (ie, an
281 // incognito tab event sent to a normal process, or vice versa). 283 // incognito tab event sent to a normal process, or vice versa).
282 bool cross_incognito = event->restrict_to_profile && 284 bool cross_incognito = event->restrict_to_profile &&
283 listener_profile != event->restrict_to_profile; 285 listener_profile != event->restrict_to_profile;
284 // Send the event with different arguments to extensions that can't 286 // Send the event with different arguments to extensions that can't
285 // cross incognito, if necessary. 287 // cross incognito, if necessary.
286 if (cross_incognito && !service->CanCrossIncognito(extension)) { 288 if (cross_incognito && !service->CanCrossIncognito(extension)) {
287 if (!event->cross_incognito_args.empty()) { 289 if (!event->cross_incognito_args.empty()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr(); 384 ExtensionHost* eh = content::Details<ExtensionHost>(details).ptr();
383 DispatchPendingEvents(eh->extension_id()); 385 DispatchPendingEvents(eh->extension_id());
384 break; 386 break;
385 } 387 }
386 // TODO(tessamac): if background page crashed/failed clear queue. 388 // TODO(tessamac): if background page crashed/failed clear queue.
387 default: 389 default:
388 NOTREACHED(); 390 NOTREACHED();
389 return; 391 return;
390 } 392 }
391 } 393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698