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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } else { | 230 } else { |
231 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 231 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
232 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( | 232 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( |
233 extension_id, event_name, *filter, lazy)); | 233 extension_id, event_name, *filter, lazy)); |
234 } | 234 } |
235 } else { | 235 } else { |
236 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 236 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
237 render_thread->Send(new ExtensionHostMsg_AddListener( | 237 render_thread->Send(new ExtensionHostMsg_AddListener( |
238 extension_id, context->url(), event_name, worker_thread_id)); | 238 extension_id, context->url(), event_name, worker_thread_id)); |
239 if (lazy) { | 239 if (lazy) { |
240 render_thread->Send(new ExtensionHostMsg_AddLazyListener( | 240 render_thread->Send( |
241 extension_id, event_name, worker_thread_id)); | 241 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); |
242 } | 242 } |
243 } else { | 243 } else { |
244 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 244 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
245 render_thread->Send(new ExtensionHostMsg_RemoveListener( | 245 render_thread->Send(new ExtensionHostMsg_RemoveListener( |
246 extension_id, context->url(), event_name, worker_thread_id)); | 246 extension_id, context->url(), event_name, worker_thread_id)); |
247 if (lazy && was_manual) { | 247 if (lazy && was_manual) { |
248 render_thread->Send(new ExtensionHostMsg_RemoveLazyListener( | 248 render_thread->Send( |
249 extension_id, event_name, worker_thread_id)); | 249 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); |
250 } | 250 } |
251 } | 251 } |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 255 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
256 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 256 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
257 | 257 |
258 } // namespace | 258 } // namespace |
259 | 259 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 "Extensions.DidCreateScriptContext_LockScreenExtension", elapsed); | 427 "Extensions.DidCreateScriptContext_LockScreenExtension", elapsed); |
428 break; | 428 break; |
429 } | 429 } |
430 | 430 |
431 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 431 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
432 } | 432 } |
433 | 433 |
434 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( | 434 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
435 v8::Local<v8::Context> v8_context, | 435 v8::Local<v8::Context> v8_context, |
436 int64_t service_worker_version_id, | 436 int64_t service_worker_version_id, |
437 const GURL& url) { | 437 const GURL& service_worker_scope, |
| 438 const GURL& script_url) { |
438 const base::TimeTicks start_time = base::TimeTicks::Now(); | 439 const base::TimeTicks start_time = base::TimeTicks::Now(); |
439 | 440 |
440 if (!url.SchemeIs(kExtensionScheme)) { | 441 if (!script_url.SchemeIs(kExtensionScheme)) { |
441 // Early-out if this isn't a chrome-extension:// scheme, because looking up | 442 // Early-out if this isn't a chrome-extension:// scheme, because looking up |
442 // the extension registry is unnecessary if it's not. Checking this will | 443 // the extension registry is unnecessary if it's not. Checking this will |
443 // also skip over hosted apps, which is the desired behavior - hosted app | 444 // also skip over hosted apps, which is the desired behavior - hosted app |
444 // service workers are not our concern. | 445 // service workers are not our concern. |
445 return; | 446 return; |
446 } | 447 } |
447 | 448 |
448 const Extension* extension = | 449 const Extension* extension = |
449 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(url); | 450 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(script_url); |
450 | 451 |
451 if (!extension) { | 452 if (!extension) { |
452 // TODO(kalman): This is no good. Instead we need to either: | 453 // TODO(kalman): This is no good. Instead we need to either: |
453 // | 454 // |
454 // - Hold onto the v8::Context and create the ScriptContext and install | 455 // - Hold onto the v8::Context and create the ScriptContext and install |
455 // our bindings when this extension is loaded. | 456 // our bindings when this extension is loaded. |
456 // - Deal with there being an extension ID (url.host()) but no | 457 // - Deal with there being an extension ID (script_url.host()) but no |
457 // extension associated with it, then document that getBackgroundClient | 458 // extension associated with it, then document that getBackgroundClient |
458 // may fail if the extension hasn't loaded yet. | 459 // may fail if the extension hasn't loaded yet. |
459 // | 460 // |
460 // The former is safer, but is unfriendly to caching (e.g. session restore). | 461 // The former is safer, but is unfriendly to caching (e.g. session restore). |
461 // It seems to contradict the service worker idiom. | 462 // It seems to contradict the service worker idiom. |
462 // | 463 // |
463 // The latter is friendly to caching, but running extension code without an | 464 // The latter is friendly to caching, but running extension code without an |
464 // installed extension makes me nervous, and means that we won't be able to | 465 // installed extension makes me nervous, and means that we won't be able to |
465 // expose arbitrary (i.e. capability-checked) extension APIs to service | 466 // expose arbitrary (i.e. capability-checked) extension APIs to service |
466 // workers. We will probably need to relax some assertions - we just need | 467 // workers. We will probably need to relax some assertions - we just need |
467 // to find them. | 468 // to find them. |
468 // | 469 // |
469 // Perhaps this could be solved with our own event on the service worker | 470 // Perhaps this could be solved with our own event on the service worker |
470 // saying that an extension is ready, and documenting that extension APIs | 471 // saying that an extension is ready, and documenting that extension APIs |
471 // won't work before that event has fired? | 472 // won't work before that event has fired? |
472 return; | 473 return; |
473 } | 474 } |
474 | 475 |
475 ScriptContext* context = new ScriptContext( | 476 ScriptContext* context = new ScriptContext( |
476 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 477 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
477 extension, Feature::SERVICE_WORKER_CONTEXT); | 478 extension, Feature::SERVICE_WORKER_CONTEXT); |
478 context->set_url(url); | 479 context->set_url(script_url); |
| 480 context->set_service_worker_scope(service_worker_scope); |
479 | 481 |
480 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { | 482 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
481 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, | 483 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, |
482 context, &source_map_); | 484 context, &source_map_); |
483 | 485 |
484 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 486 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
485 // safe. | 487 // safe. |
486 context->set_module_system( | 488 context->set_module_system( |
487 base::MakeUnique<ModuleSystem>(context, &source_map_)); | 489 base::MakeUnique<ModuleSystem>(context, &source_map_)); |
488 | 490 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 bindings_system_->WillReleaseScriptContext(context); | 560 bindings_system_->WillReleaseScriptContext(context); |
559 | 561 |
560 script_context_set_->Remove(context); | 562 script_context_set_->Remove(context); |
561 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); | 563 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); |
562 } | 564 } |
563 | 565 |
564 // static | 566 // static |
565 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( | 567 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( |
566 v8::Local<v8::Context> v8_context, | 568 v8::Local<v8::Context> v8_context, |
567 int64_t service_worker_version_id, | 569 int64_t service_worker_version_id, |
568 const GURL& url) { | 570 const GURL& service_worker_scope, |
569 if (url.SchemeIs(kExtensionScheme)) { | 571 const GURL& script_url) { |
| 572 if (script_url.SchemeIs(kExtensionScheme)) { |
570 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. | 573 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. |
571 g_worker_script_context_set.Get().Remove(v8_context, url); | 574 g_worker_script_context_set.Get().Remove(v8_context, script_url); |
572 // TODO(devlin): We're not calling | 575 // TODO(devlin): We're not calling |
573 // ExtensionBindingsSystem::WillReleaseScriptContext() here. This should be | 576 // ExtensionBindingsSystem::WillReleaseScriptContext() here. This should be |
574 // fine, since the entire bindings system is being destroyed when we | 577 // fine, since the entire bindings system is being destroyed when we |
575 // remove the worker data, but we might want to notify the system anyway. | 578 // remove the worker data, but we might want to notify the system anyway. |
576 } | 579 } |
577 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) | 580 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) |
578 WorkerThreadDispatcher::Get()->RemoveWorkerData(service_worker_version_id); | 581 WorkerThreadDispatcher::Get()->RemoveWorkerData(service_worker_version_id); |
579 } | 582 } |
580 | 583 |
581 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 584 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 // The "guestViewDeny" module must always be loaded last. It registers | 1492 // The "guestViewDeny" module must always be loaded last. It registers |
1490 // error-providing custom elements for the GuestView types that are not | 1493 // error-providing custom elements for the GuestView types that are not |
1491 // available, and thus all of those types must have been checked and loaded | 1494 // available, and thus all of those types must have been checked and loaded |
1492 // (or not loaded) beforehand. | 1495 // (or not loaded) beforehand. |
1493 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1496 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1494 module_system->Require("guestViewDeny"); | 1497 module_system->Require("guestViewDeny"); |
1495 } | 1498 } |
1496 } | 1499 } |
1497 | 1500 |
1498 } // namespace extensions | 1501 } // namespace extensions |
OLD | NEW |