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

Side by Side Diff: content/browser/service_worker/service_worker_request_handler.cc

Issue 1257553002: [Proof-of-concept] PlzNavigate and Service Worker Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass navigation_provider_id 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_request_handler.h" 5 #include "content/browser/service_worker/service_worker_request_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h"
10 #include "content/browser/loader/navigation_url_loader_impl_core.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
11 #include "content/browser/service_worker/service_worker_provider_host.h" 13 #include "content/browser/service_worker/service_worker_provider_host.h"
12 #include "content/browser/service_worker/service_worker_registration.h" 14 #include "content/browser/service_worker/service_worker_registration.h"
13 #include "content/browser/service_worker/service_worker_url_request_job.h" 15 #include "content/browser/service_worker/service_worker_url_request_job.h"
14 #include "content/browser/service_worker/service_worker_utils.h" 16 #include "content/browser/service_worker/service_worker_utils.h"
15 #include "content/common/resource_request_body.h" 17 #include "content/common/resource_request_body.h"
16 #include "content/common/service_worker/service_worker_types.h" 18 #include "content/common/service_worker/service_worker_types.h"
17 #include "content/public/browser/resource_context.h" 19 #include "content/public/browser/resource_context.h"
20 #include "content/public/common/content_switches.h"
18 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
19 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_interceptor.h" 23 #include "net/url_request/url_request_interceptor.h"
21 #include "storage/browser/blob/blob_storage_context.h" 24 #include "storage/browser/blob/blob_storage_context.h"
22 25
23 namespace content { 26 namespace content {
24 27
25 namespace { 28 namespace {
26 29
27 int kUserDataKey; // Key value is not important. 30 int kUserDataKey; // Key value is not important.
(...skipping 15 matching lines...) Expand all
43 request, network_delegate, resource_context_); 46 request, network_delegate, resource_context_);
44 } 47 }
45 48
46 private: 49 private:
47 ResourceContext* resource_context_; 50 ResourceContext* resource_context_;
48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); 51 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
49 }; 52 };
50 53
51 } // namespace 54 } // namespace
52 55
53 void ServiceWorkerRequestHandler::InitializeHandler( 56 void ServiceWorkerRequestHandler::InitializeHandler(
michaeln 2015/07/30 01:35:08 InitializeHandler could be an alternative place to
Fabrice (no longer in Chrome) 2015/08/06 15:39:15 We should avoid duplicating code. I think the prop
54 net::URLRequest* request, 57 net::URLRequest* request,
55 ServiceWorkerContextWrapper* context_wrapper, 58 ServiceWorkerContextWrapper* context_wrapper,
56 storage::BlobStorageContext* blob_storage_context, 59 storage::BlobStorageContext* blob_storage_context,
57 int process_id, 60 int process_id,
58 int provider_id, 61 int provider_id,
59 bool skip_service_worker, 62 bool skip_service_worker,
60 FetchRequestMode request_mode, 63 FetchRequestMode request_mode,
61 FetchCredentialsMode credentials_mode, 64 FetchCredentialsMode credentials_mode,
62 ResourceType resource_type, 65 ResourceType resource_type,
63 RequestContextType request_context_type, 66 RequestContextType request_context_type,
(...skipping 30 matching lines...) Expand all
94 request_context_type, 97 request_context_type,
95 frame_type, 98 frame_type,
96 blob_storage_context->AsWeakPtr(), 99 blob_storage_context->AsWeakPtr(),
97 body)); 100 body));
98 if (!handler) 101 if (!handler)
99 return; 102 return;
100 103
101 request->SetUserData(&kUserDataKey, handler.release()); 104 request->SetUserData(&kUserDataKey, handler.release());
102 } 105 }
103 106
107 void ServiceWorkerRequestHandler::InitializeNavigationHandler(
108 net::URLRequest* request,
109 ServiceWorkerContextWrapper* context_wrapper,
110 storage::BlobStorageContext* blob_storage_context,
111 bool skip_service_worker,
112 bool is_main_frame,
113 scoped_refptr<ResourceRequestBody> body,
114 NavigationURLLoaderImplCore* loader) {
115 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kEnableBrowserSideNavigation));
117 if (!request->url().SchemeIsHTTPOrHTTPS())
118 return;
119 if (!context_wrapper || !context_wrapper->context())
120 return;
121 scoped_ptr<ServiceWorkerProviderHost> provider_host(
122 context_wrapper->context()->CreateNavigationProviderHost());
123 loader->SetServiceWorkerProviderHost(provider_host.Pass());
124 if (skip_service_worker) {
125 // TODO(horo): Does it work correctly?.
126 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url()));
127 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies());
128 provider_host->AddAllMatchingRegistrations();
129 return;
130 }
131 scoped_ptr<ServiceWorkerRequestHandler> handler(
132 loader->service_worker_provider_host()->CreateRequestHandler(
133 FETCH_REQUEST_MODE_NO_CORS, FETCH_CREDENTIALS_MODE_SAME_ORIGIN,
134 is_main_frame ? RESOURCE_TYPE_MAIN_FRAME : RESOURCE_TYPE_SUB_FRAME,
135 REQUEST_CONTEXT_TYPE_LOCATION, // TODO(horo): pass in
136 // FrameHostMsg_BeginNavigation
137 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, // TODO(horo): pass in
138 // FrameHostMsg_BeginNavigation
139 blob_storage_context->AsWeakPtr(), body));
140 if (!handler)
141 return;
142 request->SetUserData(&kUserDataKey, handler.release());
143 }
144
104 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( 145 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler(
105 net::URLRequest* request) { 146 net::URLRequest* request) {
106 return static_cast<ServiceWorkerRequestHandler*>( 147 return static_cast<ServiceWorkerRequestHandler*>(
107 request->GetUserData(&kUserDataKey)); 148 request->GetUserData(&kUserDataKey));
108 } 149 }
109 150
110 scoped_ptr<net::URLRequestInterceptor> 151 scoped_ptr<net::URLRequestInterceptor>
111 ServiceWorkerRequestHandler::CreateInterceptor( 152 ServiceWorkerRequestHandler::CreateInterceptor(
112 ResourceContext* resource_context) { 153 ResourceContext* resource_context) {
113 return scoped_ptr<net::URLRequestInterceptor>( 154 return scoped_ptr<net::URLRequestInterceptor>(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ResourceType resource_type) 207 ResourceType resource_type)
167 : context_(context), 208 : context_(context),
168 provider_host_(provider_host), 209 provider_host_(provider_host),
169 blob_storage_context_(blob_storage_context), 210 blob_storage_context_(blob_storage_context),
170 resource_type_(resource_type), 211 resource_type_(resource_type),
171 old_process_id_(0), 212 old_process_id_(0),
172 old_provider_id_(kInvalidServiceWorkerProviderId) { 213 old_provider_id_(kInvalidServiceWorkerProviderId) {
173 } 214 }
174 215
175 } // namespace content 216 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698