Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
index c0e32cee57284480dc9383c33efd166ab64c10c8..2275ea32268c7cee1888183c385ce7b2e1714739 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
@@ -81,6 +81,27 @@ WebContents* GetWebContents(int render_process_id, int render_frame_id) { |
return WebContents::FromRenderFrameHost(rfh); |
} |
+std::string GetNavigationPreloadDisabledErrorMessage( |
+ ServiceWorkerVersion::NavigationPreloadSupportStatus support_status) { |
+ switch (support_status) { |
+ case ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED: |
+ NOTREACHED(); |
+ break; |
+ case ServiceWorkerVersion::NavigationPreloadSupportStatus:: |
+ NOT_SUPPORTED_FIELD_TRIAL_STOPPED: |
+ return "The Navigation Preload Origin Trial has ended."; |
+ case ServiceWorkerVersion::NavigationPreloadSupportStatus:: |
+ NOT_SUPPORTED_DISABLED_BY_COMMAND_LINE: |
+ return "Navigation Preload is disabled by command line flag."; |
+ case ServiceWorkerVersion::NavigationPreloadSupportStatus:: |
+ NOT_SUPPORTED_NO_VALID_ORIGIN_TRIAL_TOKEN: |
+ return "The service worker script does not have a valid Navigation " |
+ "Preload Origin Trial token."; |
+ } |
+ NOTREACHED(); |
+ return ""; |
+} |
+ |
} // namespace |
ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
@@ -717,6 +738,17 @@ void ServiceWorkerDispatcherHost::OnEnableNavigationPreload( |
return; |
} |
+ ServiceWorkerVersion::NavigationPreloadSupportStatus support_status = |
+ registration->active_version()->GetNavigationPreloadSupportStatus(); |
+ if (support_status != |
+ ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) { |
+ Send(new ServiceWorkerMsg_EnableNavigationPreloadError( |
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort, |
+ std::string(kEnableNavigationPreloadErrorPrefix) + |
+ GetNavigationPreloadDisabledErrorMessage(support_status))); |
+ return; |
+ } |
+ |
std::vector<GURL> urls = {provider_host->document_url(), |
registration->pattern()}; |
if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { |
@@ -859,6 +891,16 @@ void ServiceWorkerDispatcherHost::OnSetNavigationPreloadHeader( |
return; |
} |
+ ServiceWorkerVersion::NavigationPreloadSupportStatus support_status = |
+ registration->active_version()->GetNavigationPreloadSupportStatus(); |
+ if (support_status != |
+ ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) { |
+ Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( |
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort, |
+ std::string(kSetNavigationPreloadHeaderErrorPrefix) + |
+ GetNavigationPreloadDisabledErrorMessage(support_status))); |
+ return; |
+ } |
std::vector<GURL> urls = {provider_host->document_url(), |
registration->pattern()}; |
if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { |