| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_message_filter.h" | 5 #include "extensions/browser/extension_message_filter.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "content/public/browser/render_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
| 9 #include "content/public/browser/resource_dispatcher_host.h" | 9 #include "content/public/browser/resource_dispatcher_host.h" |
| 10 #include "extensions/browser/blob_holder.h" | 10 #include "extensions/browser/blob_holder.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 OnExtensionResumeRequests); | 88 OnExtensionResumeRequests); |
| 89 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestForIOThread, | 89 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestForIOThread, |
| 90 OnExtensionRequestForIOThread) | 90 OnExtensionRequestForIOThread) |
| 91 IPC_MESSAGE_UNHANDLED(handled = false) | 91 IPC_MESSAGE_UNHANDLED(handled = false) |
| 92 IPC_END_MESSAGE_MAP() | 92 IPC_END_MESSAGE_MAP() |
| 93 return handled; | 93 return handled; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ExtensionMessageFilter::OnExtensionAddListener( | 96 void ExtensionMessageFilter::OnExtensionAddListener( |
| 97 const std::string& extension_id, | 97 const std::string& extension_id, |
| 98 const GURL& listener_url, |
| 98 const std::string& event_name) { | 99 const std::string& event_name) { |
| 99 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_); | 100 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_); |
| 100 if (!process) | 101 if (!process) |
| 101 return; | 102 return; |
| 102 EventRouter* router = EventRouter::Get(browser_context_); | 103 EventRouter* router = EventRouter::Get(browser_context_); |
| 103 if (!router) | 104 if (!router) |
| 104 return; | 105 return; |
| 105 router->AddEventListener(event_name, process, extension_id); | 106 // A valid |extension_id| is mutually exclusive to a valid |listener_url|. |
| 107 if (!extension_id.empty() && !listener_url.is_valid()) |
| 108 router->AddEventListener(event_name, process, extension_id); |
| 109 if (extension_id.empty() && listener_url.is_valid()) |
| 110 router->AddEventListenerForURL(event_name, process, listener_url); |
| 106 } | 111 } |
| 107 | 112 |
| 108 void ExtensionMessageFilter::OnExtensionRemoveListener( | 113 void ExtensionMessageFilter::OnExtensionRemoveListener( |
| 109 const std::string& extension_id, | 114 const std::string& extension_id, |
| 115 const GURL& listener_url, |
| 110 const std::string& event_name) { | 116 const std::string& event_name) { |
| 111 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_); | 117 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_); |
| 112 if (!process) | 118 if (!process) |
| 113 return; | 119 return; |
| 114 EventRouter* router = EventRouter::Get(browser_context_); | 120 EventRouter* router = EventRouter::Get(browser_context_); |
| 115 if (!router) | 121 if (!router) |
| 116 return; | 122 return; |
| 117 router->RemoveEventListener(event_name, process, extension_id); | 123 // A valid |extension_id| is mutually exclusive to a valid |listener_url|. |
| 124 if (!extension_id.empty() && !listener_url.is_valid()) |
| 125 router->RemoveEventListener(event_name, process, extension_id); |
| 126 if (extension_id.empty() && listener_url.is_valid()) |
| 127 router->RemoveEventListenerForURL(event_name, process, listener_url); |
| 118 } | 128 } |
| 119 | 129 |
| 120 void ExtensionMessageFilter::OnExtensionAddLazyListener( | 130 void ExtensionMessageFilter::OnExtensionAddLazyListener( |
| 121 const std::string& extension_id, const std::string& event_name) { | 131 const std::string& extension_id, const std::string& event_name) { |
| 122 EventRouter* router = EventRouter::Get(browser_context_); | 132 EventRouter* router = EventRouter::Get(browser_context_); |
| 123 if (!router) | 133 if (!router) |
| 124 return; | 134 return; |
| 125 router->AddLazyEventListener(event_name, extension_id); | 135 router->AddLazyEventListener(event_name, extension_id); |
| 126 } | 136 } |
| 127 | 137 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 ExtensionFunctionDispatcher::DispatchOnIOThread( | 214 ExtensionFunctionDispatcher::DispatchOnIOThread( |
| 205 extension_info_map_.get(), | 215 extension_info_map_.get(), |
| 206 browser_context_, | 216 browser_context_, |
| 207 render_process_id_, | 217 render_process_id_, |
| 208 weak_ptr_factory_.GetWeakPtr(), | 218 weak_ptr_factory_.GetWeakPtr(), |
| 209 routing_id, | 219 routing_id, |
| 210 params); | 220 params); |
| 211 } | 221 } |
| 212 | 222 |
| 213 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |