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/json/json_writer.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "chrome/browser/extensions/extension_devtools_manager.h" | 9 #include "chrome/browser/extensions/extension_devtools_manager.h" |
9 #include "chrome/browser/extensions/extension_processes_api.h" | 10 #include "chrome/browser/extensions/extension_processes_api.h" |
10 #include "chrome/browser/extensions/extension_processes_api_constants.h" | 11 #include "chrome/browser/extensions/extension_processes_api_constants.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_tabs_module.h" | 13 #include "chrome/browser/extensions/extension_tabs_module.h" |
13 #include "chrome/browser/extensions/extension_webrequest_api.h" | 14 #include "chrome/browser/extensions/extension_webrequest_api.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
17 #include "content/browser/child_process_security_policy.h" | 18 #include "content/browser/child_process_security_policy.h" |
18 #include "content/browser/renderer_host/render_process_host.h" | 19 #include "content/browser/renderer_host/render_process_host.h" |
19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 21 #include "chrome/browser/extensions/extension_event_names.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 const char kDispatchEvent[] = "Event.dispatchJSON"; | 25 const char kDispatchEvent[] = "Event.dispatchJSON"; |
24 | 26 |
25 static void NotifyEventListenerRemovedOnIOThread( | 27 static void NotifyEventListenerRemovedOnIOThread( |
26 ProfileId profile_id, | 28 ProfileId profile_id, |
27 const std::string& extension_id, | 29 const std::string& extension_id, |
28 const std::string& sub_event_name) { | 30 const std::string& sub_event_name) { |
29 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 31 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 NotificationService::AllSources()); | 73 NotificationService::AllSources()); |
72 } | 74 } |
73 | 75 |
74 ExtensionEventRouter::~ExtensionEventRouter() { | 76 ExtensionEventRouter::~ExtensionEventRouter() { |
75 } | 77 } |
76 | 78 |
77 void ExtensionEventRouter::AddEventListener( | 79 void ExtensionEventRouter::AddEventListener( |
78 const std::string& event_name, | 80 const std::string& event_name, |
79 RenderProcessHost* process, | 81 RenderProcessHost* process, |
80 const std::string& extension_id) { | 82 const std::string& extension_id) { |
| 83 DVLOG(1) << __PRETTY_FUNCTION__ << " " << event_name << " " << process << " "
<< extension_id; |
81 EventListener listener(process, extension_id); | 84 EventListener listener(process, extension_id); |
82 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name; | 85 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name; |
83 listeners_[event_name].insert(listener); | 86 listeners_[event_name].insert(listener); |
84 | 87 |
85 if (extension_devtools_manager_.get()) | 88 if (extension_devtools_manager_.get()) |
86 extension_devtools_manager_->AddEventListener(event_name, process->id()); | 89 extension_devtools_manager_->AddEventListener(event_name, process->id()); |
87 | 90 |
88 // We lazily tell the TaskManager to start updating when listeners to the | 91 // We lazily tell the TaskManager to start updating when listeners to the |
89 // processes.onUpdated event arrive. | 92 // processes.onUpdated event arrive. |
90 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) | 93 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 cross_incognito_args, event_url); | 171 cross_incognito_args, event_url); |
169 } | 172 } |
170 | 173 |
171 void ExtensionEventRouter::DispatchEventImpl( | 174 void ExtensionEventRouter::DispatchEventImpl( |
172 const std::string& extension_id, | 175 const std::string& extension_id, |
173 const std::string& event_name, | 176 const std::string& event_name, |
174 const std::string& event_args, | 177 const std::string& event_args, |
175 Profile* restrict_to_profile, | 178 Profile* restrict_to_profile, |
176 const std::string& cross_incognito_args, | 179 const std::string& cross_incognito_args, |
177 const GURL& event_url) { | 180 const GURL& event_url) { |
| 181 DVLOG(1) << __PRETTY_FUNCTION__ << " " << event_name << " " << event_args << "
" << event_url << " " << extension_id; |
178 if (!profile_) | 182 if (!profile_) |
179 return; | 183 return; |
180 | 184 |
181 // We don't expect to get events from a completely different profile. | 185 // We don't expect to get events from a completely different profile. |
182 DCHECK(!restrict_to_profile || profile_->IsSameProfile(restrict_to_profile)); | 186 DCHECK(!restrict_to_profile || profile_->IsSameProfile(restrict_to_profile)); |
183 | 187 |
184 ListenerMap::iterator it = listeners_.find(event_name); | 188 ListenerMap::iterator it = listeners_.find(event_name); |
185 if (it == listeners_.end()) | 189 if (it == listeners_.end()) |
186 return; | 190 return; |
187 | 191 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 246 } |
243 } | 247 } |
244 } | 248 } |
245 break; | 249 break; |
246 } | 250 } |
247 default: | 251 default: |
248 NOTREACHED(); | 252 NOTREACHED(); |
249 return; | 253 return; |
250 } | 254 } |
251 } | 255 } |
OLD | NEW |