Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "web/ServiceWorkerGlobalScopeProxy.h" | 31 #include "web/ServiceWorkerGlobalScopeProxy.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/SourceLocation.h" | 33 #include "bindings/core/v8/SourceLocation.h" |
| 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
| 37 #include "core/dom/ExecutionContextTask.h" | 37 #include "core/dom/ExecutionContextTask.h" |
| 38 #include "core/dom/MessagePort.h" | 38 #include "core/dom/MessagePort.h" |
| 39 #include "core/inspector/ConsoleMessage.h" | 39 #include "core/inspector/ConsoleMessage.h" |
| 40 #include "core/origin_trials/OriginTrials.h" | 40 #include "core/origin_trials/OriginTrials.h" |
| 41 #include "core/workers/ParentFrameTaskRunners.h" | |
| 42 #include "core/workers/WorkerGlobalScope.h" | 41 #include "core/workers/WorkerGlobalScope.h" |
| 43 #include "core/workers/WorkerThread.h" | 42 #include "core/workers/WorkerThread.h" |
| 44 #include "modules/background_sync/SyncEvent.h" | 43 #include "modules/background_sync/SyncEvent.h" |
| 45 #include "modules/fetch/Headers.h" | 44 #include "modules/fetch/Headers.h" |
| 46 #include "modules/notifications/Notification.h" | 45 #include "modules/notifications/Notification.h" |
| 47 #include "modules/notifications/NotificationEvent.h" | 46 #include "modules/notifications/NotificationEvent.h" |
| 48 #include "modules/notifications/NotificationEventInit.h" | 47 #include "modules/notifications/NotificationEventInit.h" |
| 49 #include "modules/push_messaging/PushEvent.h" | 48 #include "modules/push_messaging/PushEvent.h" |
| 50 #include "modules/push_messaging/PushMessageData.h" | 49 #include "modules/push_messaging/PushMessageData.h" |
| 51 #include "modules/serviceworkers/ExtendableEvent.h" | 50 #include "modules/serviceworkers/ExtendableEvent.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 80 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); | 79 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); |
| 81 } | 80 } |
| 82 | 81 |
| 83 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() { | 82 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() { |
| 84 // Verify that the proxy has been detached. | 83 // Verify that the proxy has been detached. |
| 85 DCHECK(!m_embeddedWorker); | 84 DCHECK(!m_embeddedWorker); |
| 86 } | 85 } |
| 87 | 86 |
| 88 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) { | 87 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) { |
| 89 visitor->trace(m_document); | 88 visitor->trace(m_document); |
| 90 visitor->trace(m_parentFrameTaskRunners); | |
| 91 visitor->trace(m_pendingPreloadFetchEvents); | 89 visitor->trace(m_pendingPreloadFetchEvents); |
| 92 } | 90 } |
| 93 | 91 |
| 94 void ServiceWorkerGlobalScopeProxy::setRegistration( | 92 void ServiceWorkerGlobalScopeProxy::setRegistration( |
| 95 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { | 93 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { |
| 96 workerGlobalScope()->setRegistration(std::move(handle)); | 94 workerGlobalScope()->setRegistration(std::move(handle)); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) { | 97 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) { |
| 100 WaitUntilObserver* observer = WaitUntilObserver::create( | 98 WaitUntilObserver* observer = WaitUntilObserver::create( |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 | 350 |
| 353 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector( | 351 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector( |
| 354 const String& message) { | 352 const String& message) { |
| 355 DCHECK(m_embeddedWorker); | 353 DCHECK(m_embeddedWorker); |
| 356 document().postInspectorTask( | 354 document().postInspectorTask( |
| 357 BLINK_FROM_HERE, | 355 BLINK_FROM_HERE, |
| 358 createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, | 356 createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, |
| 359 crossThreadUnretained(m_embeddedWorker), message)); | 357 crossThreadUnretained(m_embeddedWorker), message)); |
| 360 } | 358 } |
| 361 | 359 |
| 362 ParentFrameTaskRunners* | |
| 363 ServiceWorkerGlobalScopeProxy::getParentFrameTaskRunners() { | |
| 364 return m_parentFrameTaskRunners.get(); | |
| 365 } | |
| 366 | |
| 367 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope( | 360 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope( |
| 368 WorkerOrWorkletGlobalScope* workerGlobalScope) { | 361 WorkerOrWorkletGlobalScope* workerGlobalScope) { |
| 369 DCHECK(!m_workerGlobalScope); | 362 DCHECK(!m_workerGlobalScope); |
| 370 m_workerGlobalScope = | 363 m_workerGlobalScope = |
| 371 static_cast<ServiceWorkerGlobalScope*>(workerGlobalScope); | 364 static_cast<ServiceWorkerGlobalScope*>(workerGlobalScope); |
| 372 client().workerContextStarted(this); | 365 client().workerContextStarted(this); |
| 373 } | 366 } |
| 374 | 367 |
| 375 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() { | 368 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() { |
| 376 ScriptState::Scope scope( | 369 ScriptState::Scope scope( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 client().workerContextDestroyed(); | 409 client().workerContextDestroyed(); |
| 417 } | 410 } |
| 418 | 411 |
| 419 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy( | 412 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy( |
| 420 WebEmbeddedWorkerImpl& embeddedWorker, | 413 WebEmbeddedWorkerImpl& embeddedWorker, |
| 421 Document& document, | 414 Document& document, |
| 422 WebServiceWorkerContextClient& client) | 415 WebServiceWorkerContextClient& client) |
| 423 : m_embeddedWorker(&embeddedWorker), | 416 : m_embeddedWorker(&embeddedWorker), |
| 424 m_document(&document), | 417 m_document(&document), |
| 425 m_client(&client), | 418 m_client(&client), |
| 426 m_workerGlobalScope(nullptr) { | 419 m_workerGlobalScope(nullptr) {} |
| 427 // ServiceWorker can sometimes run tasks that are initiated by/associated with | |
| 428 // a document's frame but these documents can be from a different process. So | |
| 429 // we intentionally populate the task runners with null document in order to | |
| 430 // use the thread's default task runner. Note that |m_document| should not be | |
| 431 // used as it's a dummy document for loading that doesn't represent the frame | |
| 432 // of any associated document. | |
| 433 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); | |
|
nhiroki
2016/11/29 07:08:27
Just note: We might need to take back this removal
| |
| 434 } | |
| 435 | 420 |
| 436 void ServiceWorkerGlobalScopeProxy::detach() { | 421 void ServiceWorkerGlobalScopeProxy::detach() { |
| 437 m_embeddedWorker = nullptr; | 422 m_embeddedWorker = nullptr; |
| 438 m_document = nullptr; | 423 m_document = nullptr; |
| 439 m_client = nullptr; | 424 m_client = nullptr; |
| 440 m_workerGlobalScope = nullptr; | 425 m_workerGlobalScope = nullptr; |
| 441 } | 426 } |
| 442 | 427 |
| 443 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const { | 428 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const { |
| 444 DCHECK(m_client); | 429 DCHECK(m_client); |
| 445 return *m_client; | 430 return *m_client; |
| 446 } | 431 } |
| 447 | 432 |
| 448 Document& ServiceWorkerGlobalScopeProxy::document() const { | 433 Document& ServiceWorkerGlobalScopeProxy::document() const { |
| 449 DCHECK(m_document); | 434 DCHECK(m_document); |
| 450 return *m_document; | 435 return *m_document; |
| 451 } | 436 } |
| 452 | 437 |
| 453 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() | 438 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() |
| 454 const { | 439 const { |
| 455 DCHECK(m_workerGlobalScope); | 440 DCHECK(m_workerGlobalScope); |
| 456 return m_workerGlobalScope; | 441 return m_workerGlobalScope; |
| 457 } | 442 } |
| 458 | 443 |
| 459 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |