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

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

Issue 2034663002: ServiceWorker: Keep the worker alive until FetchEvent.waitUntil settles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add an inline comment Created 4 years, 6 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 String origin; 124 String origin;
125 if (!sourceOrigin.isUnique()) 125 if (!sourceOrigin.isUnique())
126 origin = sourceOrigin.toString(); 126 origin = sourceOrigin.toString();
127 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio nContext(), wrapUnique(handle.release())); 127 ServiceWorker* source = ServiceWorker::from(m_workerGlobalScope->getExecutio nContext(), wrapUnique(handle.release()));
128 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Message, eventID); 128 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Message, eventID);
129 129
130 Event* event = ExtendableMessageEvent::create(value, origin, ports, source, observer); 130 Event* event = ExtendableMessageEvent::create(value, origin, ports, source, observer);
131 workerGlobalScope()->dispatchExtendableEvent(event, observer); 131 workerGlobalScope()->dispatchExtendableEvent(event, observer);
132 } 132 }
133 133
134 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer viceWorkerRequest& webRequest) 134 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int responseID, int event FinishID, const WebServiceWorkerRequest& webRequest)
135 { 135 {
136 RespondWithObserver* observer = RespondWithObserver::create(workerGlobalScop e(), eventID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRe quest.requestContext()); 136 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGloba lScope(), WaitUntilObserver::Fetch, eventFinishID);
137 RespondWithObserver* respondWithObserver = RespondWithObserver::create(worke rGlobalScope(), responseID, webRequest.url(), webRequest.mode(), webRequest.fram eType(), webRequest.requestContext(), waitUntilObserver);
137 Request* request = Request::create(workerGlobalScope()->scriptController()-> getScriptState(), webRequest); 138 Request* request = Request::create(workerGlobalScope()->scriptController()-> getScriptState(), webRequest);
138 request->getHeaders()->setGuard(Headers::ImmutableGuard); 139 request->getHeaders()->setGuard(Headers::ImmutableGuard);
139 FetchEventInit eventInit; 140 FetchEventInit eventInit;
140 eventInit.setCancelable(true); 141 eventInit.setCancelable(true);
141 eventInit.setRequest(request); 142 eventInit.setRequest(request);
142 eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webReq uest.clientId()); 143 eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webReq uest.clientId());
143 eventInit.setIsReload(webRequest.isReload()); 144 eventInit.setIsReload(webRequest.isReload());
144 FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptContr oller()->getScriptState(), EventTypeNames::fetch, eventInit, observer); 145 FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptContr oller()->getScriptState(), EventTypeNames::fetch, eventInit, respondWithObserver , waitUntilObserver);
146 waitUntilObserver->willDispatchEvent();
147 // TODO(shimazu): Track if a runtime error occured; respondWith shouldn't
148 // 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.
145 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc hEvent); 149 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc hEvent);
146 observer->didDispatchEvent(dispatchResult); 150 respondWithObserver->didDispatchEvent(dispatchResult);
151 // false is okay because waitUntil for fetch event doesn't care about the
152 // 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.
153 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
147 } 154 }
148 155
149 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int eventID, const WebServiceWorkerRequest& webRequest) 156 void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(int responseID, in t eventFinishID, const WebServiceWorkerRequest& webRequest)
150 { 157 {
151 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(webRequest.referrerUr l()); 158 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(webRequest.referrerUr l());
152 ForeignFetchRespondWithObserver* observer = ForeignFetchRespondWithObserver: :create(workerGlobalScope(), eventID, webRequest.url(), webRequest.mode(), webRe quest.frameType(), webRequest.requestContext(), origin); 159 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGloba lScope(), WaitUntilObserver::Fetch, eventFinishID);
160 ForeignFetchRespondWithObserver* respondWithObserver = ForeignFetchRespondWi thObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest .mode(), webRequest.frameType(), webRequest.requestContext(), origin, waitUntilO bserver);
153 Request* request = Request::create(workerGlobalScope()->scriptController()-> getScriptState(), webRequest); 161 Request* request = Request::create(workerGlobalScope()->scriptController()-> getScriptState(), webRequest);
154 request->getHeaders()->setGuard(Headers::ImmutableGuard); 162 request->getHeaders()->setGuard(Headers::ImmutableGuard);
155 ForeignFetchEventInit eventInit; 163 ForeignFetchEventInit eventInit;
156 eventInit.setCancelable(true); 164 eventInit.setCancelable(true);
157 eventInit.setRequest(request); 165 eventInit.setRequest(request);
158 eventInit.setOrigin(origin->toString()); 166 eventInit.setOrigin(origin->toString());
159 ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope( )->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit , observer); 167 ForeignFetchEvent* fetchEvent = ForeignFetchEvent::create(workerGlobalScope( )->scriptController()->getScriptState(), EventTypeNames::foreignfetch, eventInit , respondWithObserver, waitUntilObserver);
168 waitUntilObserver->willDispatchEvent();
169 // TODO(shimazu): Track if a runtime error occured; respondWith shouldn't
170 // work when the script throws some error, etc.
160 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc hEvent); 171 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc hEvent);
161 observer->didDispatchEvent(dispatchResult); 172 respondWithObserver->didDispatchEvent(dispatchResult);
173 // false is okay because waitUntil for foreign fetch event doesn't care
174 // about the promise rejection.
175 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
162 } 176 }
163 177
164 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) 178 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID)
165 { 179 {
166 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Install, eventID); 180 WaitUntilObserver* observer = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Install, eventID);
167 Event* event; 181 Event* event;
168 if (RuntimeEnabledFeatures::foreignFetchEnabled()) 182 if (RuntimeEnabledFeatures::foreignFetchEnabled())
169 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni t(), observer); 183 event = InstallEvent::create(EventTypeNames::install, ExtendableEventIni t(), observer);
170 else 184 else
171 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent Init(), observer); 185 event = ExtendableEvent::create(EventTypeNames::install, ExtendableEvent Init(), observer);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return *m_document; 312 return *m_document;
299 } 313 }
300 314
301 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con st 315 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() con st
302 { 316 {
303 DCHECK(m_workerGlobalScope); 317 DCHECK(m_workerGlobalScope);
304 return m_workerGlobalScope; 318 return m_workerGlobalScope;
305 } 319 }
306 320
307 } // namespace blink 321 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698