| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/extension_devtools_manager.h" | 8 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 9 #include "chrome/browser/extensions/extension_processes_api.h" | 9 #include "chrome/browser/extensions/extension_processes_api.h" |
| 10 #include "chrome/browser/extensions/extension_processes_api_constants.h" | 10 #include "chrome/browser/extensions/extension_processes_api_constants.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_tabs_module.h" | 12 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 13 #include "chrome/browser/extensions/extension_webrequest_api.h" | 13 #include "chrome/browser/extensions/extension_webrequest_api.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_messages.h" | 16 #include "chrome/common/extensions/extension_messages.h" |
| 17 #include "content/browser/child_process_security_policy.h" | 17 #include "content/browser/child_process_security_policy.h" |
| 18 #include "content/browser/renderer_host/render_process_host.h" | 18 #include "content/browser/renderer_host/render_process_host.h" |
| 19 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kDispatchEvent[] = "Event.dispatchJSON"; | 23 const char kDispatchEvent[] = "Event.dispatchJSON"; |
| 24 | 24 |
| 25 static void NotifyEventListenerRemovedOnIOThread( | 25 static void NotifyEventListenerRemovedOnIOThread( |
| 26 ProfileId profile_id, | 26 void* profile, |
| 27 const std::string& extension_id, | 27 const std::string& extension_id, |
| 28 const std::string& sub_event_name) { | 28 const std::string& sub_event_name) { |
| 29 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 29 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 30 profile_id, extension_id, sub_event_name); | 30 profile, extension_id, sub_event_name); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 struct ExtensionEventRouter::EventListener { | 35 struct ExtensionEventRouter::EventListener { |
| 36 RenderProcessHost* process; | 36 RenderProcessHost* process; |
| 37 std::string extension_id; | 37 std::string extension_id; |
| 38 | 38 |
| 39 explicit EventListener(RenderProcessHost* process, | 39 explicit EventListener(RenderProcessHost* process, |
| 40 const std::string& extension_id) | 40 const std::string& extension_id) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // If a processes.onUpdated event listener is removed (or a process with one | 109 // If a processes.onUpdated event listener is removed (or a process with one |
| 110 // exits), then we let the TaskManager know that it has one fewer listener. | 110 // exits), then we let the TaskManager know that it has one fewer listener. |
| 111 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) | 111 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) |
| 112 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved(); | 112 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved(); |
| 113 | 113 |
| 114 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
| 115 BrowserThread::IO, FROM_HERE, | 115 BrowserThread::IO, FROM_HERE, |
| 116 NewRunnableFunction( | 116 NewRunnableFunction( |
| 117 &NotifyEventListenerRemovedOnIOThread, | 117 &NotifyEventListenerRemovedOnIOThread, |
| 118 profile_->GetRuntimeId(), listener.extension_id, event_name)); | 118 profile_, listener.extension_id, event_name)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool ExtensionEventRouter::HasEventListener(const std::string& event_name) { | 121 bool ExtensionEventRouter::HasEventListener(const std::string& event_name) { |
| 122 return (listeners_.find(event_name) != listeners_.end() && | 122 return (listeners_.find(event_name) != listeners_.end() && |
| 123 !listeners_[event_name].empty()); | 123 !listeners_[event_name].empty()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool ExtensionEventRouter::ExtensionHasEventListener( | 126 bool ExtensionEventRouter::ExtensionHasEventListener( |
| 127 const std::string& extension_id, const std::string& event_name) { | 127 const std::string& extension_id, const std::string& event_name) { |
| 128 ListenerMap::iterator it = listeners_.find(event_name); | 128 ListenerMap::iterator it = listeners_.find(event_name); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 break; | 245 break; |
| 246 } | 246 } |
| 247 default: | 247 default: |
| 248 NOTREACHED(); | 248 NOTREACHED(); |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 } | 251 } |
| OLD | NEW |