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

Unified Diff: content/browser/service_worker/service_worker_request_handler.cc

Issue 1294243004: PlzNavigate: Make ServiceWorker work with PlzNavigate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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: content/browser/service_worker/service_worker_request_handler.cc
diff --git a/content/browser/service_worker/service_worker_request_handler.cc b/content/browser/service_worker/service_worker_request_handler.cc
index 6d7d04b2e0a1b99a9101916faee3f4dd1612a9fb..a2e5da91d973731010d7b368019e45b4a9561b4f 100644
--- a/content/browser/service_worker/service_worker_request_handler.cc
+++ b/content/browser/service_worker/service_worker_request_handler.cc
@@ -6,6 +6,8 @@
#include <string>
+#include "base/command_line.h"
+#include "content/browser/loader/navigation_url_loader_impl_core.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_provider_host.h"
@@ -15,6 +17,7 @@
#include "content/common/service_worker/service_worker_types.h"
#include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/resource_context.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/origin_util.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
@@ -64,8 +67,8 @@ void ServiceWorkerRequestHandler::InitializeHandler(
ResourceType resource_type,
RequestContextType request_context_type,
RequestContextFrameType frame_type,
- scoped_refptr<ResourceRequestBody> body) {
- // Create the handler even for insecure HTTP since it's used in the
+ scoped_refptr<ResourceRequestBody> body,
+ NavigationURLLoaderImplCore* loader) {
// case of redirect to HTTPS.
carlosk 2015/08/27 14:26:43 Re-add the first line of this comment.
Fabrice (no longer in Chrome) 2015/08/28 15:40:16 Bad auto-merge :( Done.
if (!request->url().SchemeIsHTTPOrHTTPS() &&
!OriginCanAccessServiceWorkers(request->url())) {
@@ -77,13 +80,28 @@ void ServiceWorkerRequestHandler::InitializeHandler(
return;
}
- ServiceWorkerProviderHost* provider_host =
- context_wrapper->context()->GetProviderHost(process_id, provider_id);
+ ServiceWorkerProviderHost* provider_host = nullptr;
+ if (process_id == -1) {
+ // PlzNavigate
+ // Initialize a dummy SWProviderHost for browser-initiated navigations.
+ CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation));
+ DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id));
+ scoped_ptr<ServiceWorkerProviderHost> scoped_provider_host(
+ context_wrapper->context()->CreateBrowserProviderHost(provider_id));
+ provider_host = scoped_provider_host.get();
+ loader->SetServiceWorkerProviderHost(scoped_provider_host.Pass());
+ } else {
+ provider_host =
+ context_wrapper->context()->GetProviderHost(process_id, provider_id);
+ }
+
if (!provider_host || !provider_host->IsContextAlive())
return;
if (skip_service_worker) {
if (ServiceWorkerUtils::IsMainResourceType(resource_type)) {
+ // TODO(horo): Does this work properly for PlzNavigate?
provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url()));
provider_host->SetTopmostFrameUrl(request->first_party_for_cookies());
// A page load with skip_service_worker should be triggered by

Powered by Google App Engine
This is Rietveld 408576698