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

Unified Diff: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp

Issue 2416843002: Implement FetchEvent.navigationPreload (Closed)
Patch Set: stop using nullable promise Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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 867168b7d5ceedaa4be5aa3fd3ec823b5b38112d..b3d1850adf7115988cb12ace8c85a4223eb20caa 100644
--- a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
+++ b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
@@ -60,6 +60,7 @@
#include "public/platform/modules/notifications/WebNotificationData.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
+#include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
#include "public/web/WebSerializedScriptValue.h"
#include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
#include "web/WebEmbeddedWorkerImpl.h"
@@ -85,6 +86,7 @@ ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() {
DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) {
visitor->trace(m_document);
+ visitor->trace(m_pendingPreloadFetchEvents);
}
void ServiceWorkerGlobalScopeProxy::setRegistration(
@@ -151,7 +153,8 @@ void ServiceWorkerGlobalScopeProxy::dispatchExtendableMessageEvent(
void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(
int fetchEventID,
- const WebServiceWorkerRequest& webRequest) {
+ const WebServiceWorkerRequest& webRequest,
+ bool navigationPreloadSent) {
ScriptState::Scope scope(
workerGlobalScope()->scriptController()->getScriptState());
WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(
@@ -168,9 +171,16 @@ void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(
eventInit.setClientId(
webRequest.isMainResourceLoad() ? WebString() : webRequest.clientId());
eventInit.setIsReload(webRequest.isReload());
+ ScriptState* scriptState =
+ workerGlobalScope()->scriptController()->getScriptState();
FetchEvent* fetchEvent = FetchEvent::create(
- workerGlobalScope()->scriptController()->getScriptState(),
- EventTypeNames::fetch, eventInit, respondWithObserver, waitUntilObserver);
+ scriptState, EventTypeNames::fetch, eventInit, respondWithObserver,
+ waitUntilObserver, navigationPreloadSent);
+ if (navigationPreloadSent) {
+ // Keep |fetchEvent| until onNavigationPreloadResponse() or
+ // onNavigationPreloadError() will be called.
+ m_pendingPreloadFetchEvents.add(fetchEventID, fetchEvent);
+ }
waitUntilObserver->willDispatchEvent();
respondWithObserver->willDispatchEvent();
DispatchEventResult dispatchResult =
@@ -181,6 +191,24 @@ void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(
waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
}
+void ServiceWorkerGlobalScopeProxy::onNavigationPreloadResponse(
+ int fetchEventID,
+ std::unique_ptr<WebServiceWorkerResponse> response,
+ std::unique_ptr<WebDataConsumerHandle> dataConsumeHandle) {
+ FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
+ DCHECK(fetchEvent);
+ fetchEvent->onNavigationPreloadResponse(std::move(response),
+ std::move(dataConsumeHandle));
+}
+
+void ServiceWorkerGlobalScopeProxy::onNavigationPreloadError(
+ int fetchEventID,
+ std::unique_ptr<WebServiceWorkerError> error) {
+ FetchEvent* fetchEvent = m_pendingPreloadFetchEvents.take(fetchEventID);
+ DCHECK(fetchEvent);
+ fetchEvent->onNavigationPreloadError(std::move(error));
+}
+
void ServiceWorkerGlobalScopeProxy::dispatchForeignFetchEvent(
int fetchEventID,
const WebServiceWorkerRequest& webRequest) {

Powered by Google App Engine
This is Rietveld 408576698