Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp

Issue 2699713003: [WIP] RespondWithObserver
Patch Set: RespondWithObserver Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/ServiceWorkerGlobalScopeProxy.h" 31 #include "web/ServiceWorkerGlobalScopeProxy.h"
32 32
33 #include <memory>
34 #include <utility>
33 #include "bindings/core/v8/SourceLocation.h" 35 #include "bindings/core/v8/SourceLocation.h"
34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 36 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
35 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 38 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 39 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/MessagePort.h" 40 #include "core/dom/MessagePort.h"
39 #include "core/inspector/ConsoleMessage.h" 41 #include "core/inspector/ConsoleMessage.h"
40 #include "core/origin_trials/OriginTrials.h" 42 #include "core/origin_trials/OriginTrials.h"
41 #include "core/workers/ParentFrameTaskRunners.h" 43 #include "core/workers/ParentFrameTaskRunners.h"
42 #include "core/workers/WorkerGlobalScope.h" 44 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerThread.h" 45 #include "core/workers/WorkerThread.h"
44 #include "modules/background_sync/SyncEvent.h" 46 #include "modules/background_sync/SyncEvent.h"
45 #include "modules/fetch/Headers.h" 47 #include "modules/fetch/Headers.h"
46 #include "modules/notifications/Notification.h" 48 #include "modules/notifications/Notification.h"
47 #include "modules/notifications/NotificationEvent.h" 49 #include "modules/notifications/NotificationEvent.h"
48 #include "modules/notifications/NotificationEventInit.h" 50 #include "modules/notifications/NotificationEventInit.h"
49 #include "modules/payments/PaymentAppRequest.h" 51 #include "modules/payments/PaymentAppRequest.h"
50 #include "modules/payments/PaymentAppRequestConversion.h" 52 #include "modules/payments/PaymentAppRequestConversion.h"
51 #include "modules/payments/PaymentRequestEvent.h" 53 #include "modules/payments/PaymentRequestEvent.h"
52 #include "modules/push_messaging/PushEvent.h" 54 #include "modules/push_messaging/PushEvent.h"
53 #include "modules/push_messaging/PushMessageData.h" 55 #include "modules/push_messaging/PushMessageData.h"
54 #include "modules/serviceworkers/ExtendableEvent.h" 56 #include "modules/serviceworkers/ExtendableEvent.h"
55 #include "modules/serviceworkers/ExtendableMessageEvent.h" 57 #include "modules/serviceworkers/ExtendableMessageEvent.h"
56 #include "modules/serviceworkers/FetchEvent.h" 58 #include "modules/serviceworkers/FetchEvent.h"
57 #include "modules/serviceworkers/ForeignFetchEvent.h" 59 #include "modules/serviceworkers/ForeignFetchEvent.h"
58 #include "modules/serviceworkers/InstallEvent.h" 60 #include "modules/serviceworkers/InstallEvent.h"
61 #include "modules/serviceworkers/PaymentRequestRespondWithObserver.h"
59 #include "modules/serviceworkers/ServiceWorkerClient.h" 62 #include "modules/serviceworkers/ServiceWorkerClient.h"
60 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" 63 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
61 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" 64 #include "modules/serviceworkers/ServiceWorkerWindowClient.h"
62 #include "modules/serviceworkers/WaitUntilObserver.h" 65 #include "modules/serviceworkers/WaitUntilObserver.h"
63 #include "platform/RuntimeEnabledFeatures.h" 66 #include "platform/RuntimeEnabledFeatures.h"
64 #include "public/platform/modules/notifications/WebNotificationData.h" 67 #include "public/platform/modules/notifications/WebNotificationData.h"
65 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" 68 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
66 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" 69 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
67 #include "public/web/WebSerializedScriptValue.h" 70 #include "public/web/WebSerializedScriptValue.h"
68 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" 71 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
69 #include "web/WebEmbeddedWorkerImpl.h" 72 #include "web/WebEmbeddedWorkerImpl.h"
70 #include "wtf/Assertions.h" 73 #include "wtf/Assertions.h"
71 #include "wtf/Functional.h" 74 #include "wtf/Functional.h"
72 #include "wtf/PtrUtil.h" 75 #include "wtf/PtrUtil.h"
73 #include <memory>
74 #include <utility>
75 76
76 namespace blink { 77 namespace blink {
77 78
78 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create( 79 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create(
79 WebEmbeddedWorkerImpl& embeddedWorker, 80 WebEmbeddedWorkerImpl& embeddedWorker,
80 Document& document, 81 Document& document,
81 WebServiceWorkerContextClient& client) { 82 WebServiceWorkerContextClient& client) {
82 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); 83 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client);
83 } 84 }
84 85
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 159
159 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent( 160 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(
160 int fetchEventID, 161 int fetchEventID,
161 const WebServiceWorkerRequest& webRequest, 162 const WebServiceWorkerRequest& webRequest,
162 bool navigationPreloadSent) { 163 bool navigationPreloadSent) {
163 ScriptState::Scope scope( 164 ScriptState::Scope scope(
164 workerGlobalScope()->scriptController()->getScriptState()); 165 workerGlobalScope()->scriptController()->getScriptState());
165 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create( 166 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(
166 workerGlobalScope(), WaitUntilObserver::Fetch, fetchEventID); 167 workerGlobalScope(), WaitUntilObserver::Fetch, fetchEventID);
167 RespondWithObserver* respondWithObserver = RespondWithObserver::create( 168 RespondWithObserver* respondWithObserver = FetchRespondWithObserver::create(
168 workerGlobalScope(), fetchEventID, webRequest.url(), webRequest.mode(), 169 workerGlobalScope(), fetchEventID, webRequest.url(), webRequest.mode(),
169 webRequest.redirectMode(), webRequest.frameType(), 170 webRequest.redirectMode(), webRequest.frameType(),
170 webRequest.requestContext(), waitUntilObserver); 171 webRequest.requestContext(), waitUntilObserver);
171 Request* request = Request::create( 172 Request* request = Request::create(
172 workerGlobalScope()->scriptController()->getScriptState(), webRequest); 173 workerGlobalScope()->scriptController()->getScriptState(), webRequest);
173 request->getHeaders()->setGuard(Headers::ImmutableGuard); 174 request->getHeaders()->setGuard(Headers::ImmutableGuard);
174 FetchEventInit eventInit; 175 FetchEventInit eventInit;
175 eventInit.setCancelable(true); 176 eventInit.setCancelable(true);
176 eventInit.setRequest(request); 177 eventInit.setRequest(request);
177 eventInit.setClientId( 178 eventInit.setClientId(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 WaitUntilObserver* observer = WaitUntilObserver::create( 334 WaitUntilObserver* observer = WaitUntilObserver::create(
334 workerGlobalScope(), WaitUntilObserver::Sync, eventID); 335 workerGlobalScope(), WaitUntilObserver::Sync, eventID);
335 Event* event = SyncEvent::create(EventTypeNames::sync, tag, 336 Event* event = SyncEvent::create(EventTypeNames::sync, tag,
336 lastChance == IsLastChance, observer); 337 lastChance == IsLastChance, observer);
337 workerGlobalScope()->dispatchExtendableEvent(event, observer); 338 workerGlobalScope()->dispatchExtendableEvent(event, observer);
338 } 339 }
339 340
340 void ServiceWorkerGlobalScopeProxy::dispatchPaymentRequestEvent( 341 void ServiceWorkerGlobalScopeProxy::dispatchPaymentRequestEvent(
341 int eventID, 342 int eventID,
342 const WebPaymentAppRequest& webAppRequest) { 343 const WebPaymentAppRequest& webAppRequest) {
343 WaitUntilObserver* observer = WaitUntilObserver::create( 344 ScriptState::Scope scope(
345 workerGlobalScope()->scriptController()->getScriptState());
346 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(
344 workerGlobalScope(), WaitUntilObserver::PaymentRequest, eventID); 347 workerGlobalScope(), WaitUntilObserver::PaymentRequest, eventID);
348 RespondWithObserver* respondWithObserver =
349 PaymentRequestRespondWithObserver::create(workerGlobalScope(), eventID,
350 waitUntilObserver);
351
345 Event* event = PaymentRequestEvent::create( 352 Event* event = PaymentRequestEvent::create(
346 EventTypeNames::paymentrequest, 353 EventTypeNames::paymentrequest,
347 PaymentAppRequestConversion::toPaymentAppRequest( 354 PaymentAppRequestConversion::toPaymentAppRequest(
348 workerGlobalScope()->scriptController()->getScriptState(), 355 workerGlobalScope()->scriptController()->getScriptState(),
349 webAppRequest), 356 webAppRequest),
350 observer); 357 respondWithObserver, waitUntilObserver);
351 workerGlobalScope()->dispatchExtendableEvent(event, observer); 358
359 waitUntilObserver->willDispatchEvent();
360 respondWithObserver->willDispatchEvent();
361 DispatchEventResult dispatchResult =
362 workerGlobalScope()->dispatchEvent(event);
363 respondWithObserver->didDispatchEvent(dispatchResult);
364 // false is okay because waitUntil for payment request event doesn't care
365 // about the promise rejection or an uncaught runtime script error.
366 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
352 } 367 }
353 368
354 bool ServiceWorkerGlobalScopeProxy::hasFetchEventHandler() { 369 bool ServiceWorkerGlobalScopeProxy::hasFetchEventHandler() {
355 DCHECK(m_workerGlobalScope); 370 DCHECK(m_workerGlobalScope);
356 return m_workerGlobalScope->hasEventListeners(EventTypeNames::fetch); 371 return m_workerGlobalScope->hasEventListeners(EventTypeNames::fetch);
357 } 372 }
358 373
359 void ServiceWorkerGlobalScopeProxy::countFeature(UseCounter::Feature) { 374 void ServiceWorkerGlobalScopeProxy::countFeature(UseCounter::Feature) {
360 // TODO(nhiroki): Support UseCounter for ServiceWorker. Send an IPC message to 375 // TODO(nhiroki): Support UseCounter for ServiceWorker. Send an IPC message to
361 // the browser process and ask each controlled document to record API use in 376 // the browser process and ask each controlled document to record API use in
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return *m_document; 498 return *m_document;
484 } 499 }
485 500
486 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() 501 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope()
487 const { 502 const {
488 DCHECK(m_workerGlobalScope); 503 DCHECK(m_workerGlobalScope);
489 return m_workerGlobalScope; 504 return m_workerGlobalScope;
490 } 505 }
491 506
492 } // namespace blink 507 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698