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/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 199 } |
200 | 200 |
201 // Sends a notification to the browser that an event either has or no longer has | 201 // Sends a notification to the browser that an event either has or no longer has |
202 // listeners associated with it. Note that we only do this for the first added/ | 202 // listeners associated with it. Note that we only do this for the first added/ |
203 // last removed listener, rather than for each subsequent listener; the browser | 203 // last removed listener, rather than for each subsequent listener; the browser |
204 // only cares if an event has >0 associated listeners. | 204 // only cares if an event has >0 associated listeners. |
205 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy | 205 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy |
206 // background pages. | 206 // background pages. |
207 void SendEventListenersIPC(binding::EventListenersChanged changed, | 207 void SendEventListenersIPC(binding::EventListenersChanged changed, |
208 ScriptContext* context, | 208 ScriptContext* context, |
209 const std::string& event_name) { | 209 const std::string& event_name, |
210 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 210 const base::DictionaryValue* filter) { |
211 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddListener( | 211 // TODO(devlin): Fix this. We need to account for lazy listeners, but it |
212 context->GetExtensionID(), context->url(), event_name)); | 212 // also depends on if the listener is removed due to the context being torn |
| 213 // down or the extension unregistering. |
| 214 bool lazy = false; |
| 215 std::string extension_id = context->GetExtensionID(); |
| 216 |
| 217 if (filter) { |
| 218 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
| 219 content::RenderThread::Get()->Send( |
| 220 new ExtensionHostMsg_AddFilteredListener(extension_id, event_name, |
| 221 *filter, lazy)); |
| 222 } else { |
| 223 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
| 224 content::RenderThread::Get()->Send( |
| 225 new ExtensionHostMsg_RemoveFilteredListener(extension_id, event_name, |
| 226 *filter, lazy)); |
| 227 } |
213 } else { | 228 } else { |
214 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 229 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
215 content::RenderThread::Get()->Send(new ExtensionHostMsg_RemoveListener( | 230 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddListener( |
216 context->GetExtensionID(), context->url(), event_name)); | 231 context->GetExtensionID(), context->url(), event_name)); |
| 232 } else { |
| 233 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
| 234 content::RenderThread::Get()->Send(new ExtensionHostMsg_RemoveListener( |
| 235 context->GetExtensionID(), context->url(), event_name)); |
| 236 } |
217 } | 237 } |
218 } | 238 } |
219 | 239 |
220 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 240 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
221 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 241 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
222 | 242 |
223 } // namespace | 243 } // namespace |
224 | 244 |
225 // Note that we can't use Blink public APIs in the constructor becase Blink | 245 // Note that we can't use Blink public APIs in the constructor becase Blink |
226 // is not initialized at the point we create Dispatcher. | 246 // is not initialized at the point we create Dispatcher. |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 // The "guestViewDeny" module must always be loaded last. It registers | 1439 // The "guestViewDeny" module must always be loaded last. It registers |
1420 // error-providing custom elements for the GuestView types that are not | 1440 // error-providing custom elements for the GuestView types that are not |
1421 // available, and thus all of those types must have been checked and loaded | 1441 // available, and thus all of those types must have been checked and loaded |
1422 // (or not loaded) beforehand. | 1442 // (or not loaded) beforehand. |
1423 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1443 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1424 module_system->Require("guestViewDeny"); | 1444 module_system->Require("guestViewDeny"); |
1425 } | 1445 } |
1426 } | 1446 } |
1427 | 1447 |
1428 } // namespace extensions | 1448 } // namespace extensions |
OLD | NEW |