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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Sends a notification to the browser that an event either has or no longer has | 208 // Sends a notification to the browser that an event either has or no longer has |
209 // listeners associated with it. Note that we only do this for the first added/ | 209 // listeners associated with it. Note that we only do this for the first added/ |
210 // last removed listener, rather than for each subsequent listener; the browser | 210 // last removed listener, rather than for each subsequent listener; the browser |
211 // only cares if an event has >0 associated listeners. | 211 // only cares if an event has >0 associated listeners. |
212 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy | 212 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy |
213 // background pages. | 213 // background pages. |
214 void SendEventListenersIPC(binding::EventListenersChanged changed, | 214 void SendEventListenersIPC(binding::EventListenersChanged changed, |
215 ScriptContext* context, | 215 ScriptContext* context, |
216 const std::string& event_name, | 216 const std::string& event_name, |
217 const base::DictionaryValue* filter, | 217 const base::DictionaryValue* filter, |
218 bool was_manual) { | 218 bool update_lazy_listeners) { |
219 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context); | 219 bool is_lazy = update_lazy_listeners && |
| 220 ExtensionFrameHelper::IsContextForEventPage(context); |
220 // TODO(lazyboy): For service workers, use worker specific IPC::Sender | 221 // TODO(lazyboy): For service workers, use worker specific IPC::Sender |
221 // instead of |render_thread|. | 222 // instead of |render_thread|. |
222 const int worker_thread_id = content::WorkerThread::GetCurrentId(); | 223 const int worker_thread_id = content::WorkerThread::GetCurrentId(); |
223 std::string extension_id = context->GetExtensionID(); | 224 std::string extension_id = context->GetExtensionID(); |
224 content::RenderThread* render_thread = content::RenderThread::Get(); | 225 content::RenderThread* render_thread = content::RenderThread::Get(); |
225 | 226 |
226 if (filter) { | 227 if (filter) { |
227 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 228 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
228 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( | 229 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( |
229 extension_id, event_name, *filter, lazy)); | 230 extension_id, event_name, *filter, is_lazy)); |
230 } else { | 231 } else { |
231 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 232 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
232 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( | 233 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( |
233 extension_id, event_name, *filter, lazy)); | 234 extension_id, event_name, *filter, is_lazy)); |
234 } | 235 } |
235 } else { | 236 } else { |
236 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 237 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
237 render_thread->Send(new ExtensionHostMsg_AddListener( | 238 render_thread->Send(new ExtensionHostMsg_AddListener( |
238 extension_id, context->url(), event_name, worker_thread_id)); | 239 extension_id, context->url(), event_name, worker_thread_id)); |
239 if (lazy) { | 240 if (is_lazy) { |
240 render_thread->Send( | 241 render_thread->Send( |
241 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); | 242 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); |
242 } | 243 } |
243 } else { | 244 } else { |
244 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 245 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
245 render_thread->Send(new ExtensionHostMsg_RemoveListener( | 246 render_thread->Send(new ExtensionHostMsg_RemoveListener( |
246 extension_id, context->url(), event_name, worker_thread_id)); | 247 extension_id, context->url(), event_name, worker_thread_id)); |
247 if (lazy && was_manual) { | 248 if (is_lazy) { |
248 render_thread->Send( | 249 render_thread->Send( |
249 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); | 250 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); |
250 } | 251 } |
251 } | 252 } |
252 } | 253 } |
253 } | 254 } |
254 | 255 |
255 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 256 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
256 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 257 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
257 | 258 |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 // The "guestViewDeny" module must always be loaded last. It registers | 1493 // The "guestViewDeny" module must always be loaded last. It registers |
1493 // error-providing custom elements for the GuestView types that are not | 1494 // error-providing custom elements for the GuestView types that are not |
1494 // available, and thus all of those types must have been checked and loaded | 1495 // available, and thus all of those types must have been checked and loaded |
1495 // (or not loaded) beforehand. | 1496 // (or not loaded) beforehand. |
1496 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1497 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1497 module_system->Require("guestViewDeny"); | 1498 module_system->Require("guestViewDeny"); |
1498 } | 1499 } |
1499 } | 1500 } |
1500 | 1501 |
1501 } // namespace extensions | 1502 } // namespace extensions |
OLD | NEW |