Chromium Code Reviews| Index: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp |
| diff --git a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp |
| index 80b9d7dcc0ce61389deb132df7367a8bbff3d2db..5ce983d7a75994761a43289077211c6188347e26 100644 |
| --- a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp |
| +++ b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp |
| @@ -131,9 +131,10 @@ void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(int eventID, |
| workerGlobalScope()->dispatchExtendableEvent(event, observer); |
| } |
| -void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebServiceWorkerRequest& webRequest) |
| +void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int responseID, int eventFinishID, const WebServiceWorkerRequest& webRequest) |
| { |
| - RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScope(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRequest.requestContext()); |
| + WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Fetch, eventFinishID); |
| + RespondWithObserver* respondWithObserver = RespondWithObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRequest.requestContext(), waitUntilObserver); |
| Request* request = Request::create(workerGlobalScope()->scriptController()->getScriptState(), webRequest); |
| request->getHeaders()->setGuard(Headers::ImmutableGuard); |
| FetchEventInit eventInit; |
| @@ -141,24 +142,37 @@ void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer |
| eventInit.setRequest(request); |
| eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webRequest.clientId()); |
| eventInit.setIsReload(webRequest.isReload()); |
| - FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptController()->getScriptState(), EventTypeNames::fetch, eventInit, observer); |
| + FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptController()->getScriptState(), EventTypeNames::fetch, eventInit, respondWithObserver, waitUntilObserver); |
| + waitUntilObserver->willDispatchEvent(); |
| + // TODO(shimazu): Track if a runtime error occured; respondWith shouldn't |
| + // work when the script throws some error, etc. |
|
falken
2016/06/22 01:27:32
I think we can just remove this TODO based on the
shimazu
2016/06/22 05:41:27
Done.
|
| DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetchEvent); |
| - observer->didDispatchEvent(dispatchResult); |
| + respondWithObserver->didDispatchEvent(dispatchResult); |
| + // false is okay because waitUntil for fetch event doesn't care about the |
| + // promise rejection. |
|
falken
2016/06/22 01:27:32
about promise rejection or an uncaught runtime scr
shimazu
2016/06/22 05:41:27
Done.
|
| + waitUntilObserver->didDispatchEvent(false /* errorOccurred */); |
| } |
| -void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int eventID, const WebServiceWorkerRequest& webRequest) |
| +void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int responseID, int eventFinishID, const WebServiceWorkerRequest& webRequest) |
| { |
| RefPtr<SecurityOrigin> origin = SecurityOrigin::create(webRequest.referrerUrl()); |
| - ForeignFetchRespondWithObserver* observer = ForeignFetchRespondWithObserver::create(workerGlobalScope(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRequest.requestContext(), origin); |
| + WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Fetch, eventFinishID); |
| + ForeignFetchRespondWithObserver* respondWithObserver = ForeignFetchRespondWithObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRequest.requestContext(), origin, waitUntilObserver); |
| Request* request = Request::create(workerGlobalScope()->scriptController()->getScriptState(), webRequest); |
| request->getHeaders()->setGuard(Headers::ImmutableGuard); |
| ForeignFetchEventInit eventInit; |
| eventInit.setCancelable(true); |
| eventInit.setRequest(request); |
| eventInit.setOrigin(origin->toString()); |
| - ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope()->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit, observer); |
| + ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope()->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit, respondWithObserver, waitUntilObserver); |
| + waitUntilObserver->willDispatchEvent(); |
| + // TODO(shimazu): Track if a runtime error occured; respondWith shouldn't |
| + // work when the script throws some error, etc. |
| DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetchEvent); |
| - observer->didDispatchEvent(dispatchResult); |
| + respondWithObserver->didDispatchEvent(dispatchResult); |
| + // false is okay because waitUntil for foreign fetch event doesn't care |
| + // about the promise rejection. |
| + waitUntilObserver->didDispatchEvent(false /* errorOccurred */); |
| } |
| void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) |