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

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

Issue 2941883003: [ServiceWorker] Fetch event should return integrity value (Closed)
Patch Set: Address yhirano's comment #78 Created 3 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/foreign_fetch_request_handler.h" 5 #include "content/browser/service_worker/foreign_fetch_request_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 void ForeignFetchRequestHandler::InitializeHandler( 69 void ForeignFetchRequestHandler::InitializeHandler(
70 net::URLRequest* request, 70 net::URLRequest* request,
71 ServiceWorkerContextWrapper* context_wrapper, 71 ServiceWorkerContextWrapper* context_wrapper,
72 storage::BlobStorageContext* blob_storage_context, 72 storage::BlobStorageContext* blob_storage_context,
73 int process_id, 73 int process_id,
74 int provider_id, 74 int provider_id,
75 ServiceWorkerMode service_worker_mode, 75 ServiceWorkerMode service_worker_mode,
76 FetchRequestMode request_mode, 76 FetchRequestMode request_mode,
77 FetchCredentialsMode credentials_mode, 77 FetchCredentialsMode credentials_mode,
78 FetchRedirectMode redirect_mode, 78 FetchRedirectMode redirect_mode,
79 const std::string& integrity,
79 ResourceType resource_type, 80 ResourceType resource_type,
80 RequestContextType request_context_type, 81 RequestContextType request_context_type,
81 RequestContextFrameType frame_type, 82 RequestContextFrameType frame_type,
82 scoped_refptr<ResourceRequestBody> body, 83 scoped_refptr<ResourceRequestBody> body,
83 bool initiated_in_secure_context) { 84 bool initiated_in_secure_context) {
84 if (!IsForeignFetchEnabled()) 85 if (!IsForeignFetchEnabled())
85 return; 86 return;
86 87
87 if (!context_wrapper || !context_wrapper->context() || 88 if (!context_wrapper || !context_wrapper->context() ||
88 provider_id == kInvalidServiceWorkerProviderId) { 89 provider_id == kInvalidServiceWorkerProviderId) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (!context_wrapper->OriginHasForeignFetchRegistrations( 123 if (!context_wrapper->OriginHasForeignFetchRegistrations(
123 request->url().GetOrigin())) { 124 request->url().GetOrigin())) {
124 return; 125 return;
125 } 126 }
126 127
127 // Any more precise checks to see if the request should be intercepted are 128 // Any more precise checks to see if the request should be intercepted are
128 // asynchronous, so just create our handler in all cases. 129 // asynchronous, so just create our handler in all cases.
129 std::unique_ptr<ForeignFetchRequestHandler> handler = 130 std::unique_ptr<ForeignFetchRequestHandler> handler =
130 base::WrapUnique(new ForeignFetchRequestHandler( 131 base::WrapUnique(new ForeignFetchRequestHandler(
131 context_wrapper, blob_storage_context->AsWeakPtr(), request_mode, 132 context_wrapper, blob_storage_context->AsWeakPtr(), request_mode,
132 credentials_mode, redirect_mode, resource_type, request_context_type, 133 credentials_mode, redirect_mode, integrity, resource_type,
133 frame_type, body, timeout)); 134 request_context_type, frame_type, body, timeout));
134 request->SetUserData(&kUserDataKey, std::move(handler)); 135 request->SetUserData(&kUserDataKey, std::move(handler));
135 } 136 }
136 137
137 ForeignFetchRequestHandler* ForeignFetchRequestHandler::GetHandler( 138 ForeignFetchRequestHandler* ForeignFetchRequestHandler::GetHandler(
138 net::URLRequest* request) { 139 net::URLRequest* request) {
139 return static_cast<ForeignFetchRequestHandler*>( 140 return static_cast<ForeignFetchRequestHandler*>(
140 request->GetUserData(&kUserDataKey)); 141 request->GetUserData(&kUserDataKey));
141 } 142 }
142 143
143 std::unique_ptr<net::URLRequestInterceptor> 144 std::unique_ptr<net::URLRequestInterceptor>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // other foreign fetch service workers. 176 // other foreign fetch service workers.
176 return nullptr; 177 return nullptr;
177 } 178 }
178 179
179 // It's for original request (A) or redirect case (B-a or B-b). 180 // It's for original request (A) or redirect case (B-a or B-b).
180 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); 181 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker());
181 182
182 ServiceWorkerURLRequestJob* job = new ServiceWorkerURLRequestJob( 183 ServiceWorkerURLRequestJob* job = new ServiceWorkerURLRequestJob(
183 request, network_delegate, std::string(), blob_storage_context_, 184 request, network_delegate, std::string(), blob_storage_context_,
184 resource_context, request_mode_, credentials_mode_, redirect_mode_, 185 resource_context, request_mode_, credentials_mode_, redirect_mode_,
185 resource_type_, request_context_type_, frame_type_, body_, 186 integrity_, resource_type_, request_context_type_, frame_type_, body_,
186 ServiceWorkerFetchType::FOREIGN_FETCH, timeout_, this); 187 ServiceWorkerFetchType::FOREIGN_FETCH, timeout_, this);
187 job_ = job->GetWeakPtr(); 188 job_ = job->GetWeakPtr();
188 resource_context_ = resource_context; 189 resource_context_ = resource_context;
189 190
190 context_->FindReadyRegistrationForDocument( 191 context_->FindReadyRegistrationForDocument(
191 request->url(), 192 request->url(),
192 base::Bind(&ForeignFetchRequestHandler::DidFindRegistration, 193 base::Bind(&ForeignFetchRequestHandler::DidFindRegistration,
193 weak_factory_.GetWeakPtr(), job_)); 194 weak_factory_.GetWeakPtr(), job_));
194 195
195 return job_.get(); 196 return job_.get();
196 } 197 }
197 198
198 ForeignFetchRequestHandler::ForeignFetchRequestHandler( 199 ForeignFetchRequestHandler::ForeignFetchRequestHandler(
199 ServiceWorkerContextWrapper* context, 200 ServiceWorkerContextWrapper* context,
200 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 201 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
201 FetchRequestMode request_mode, 202 FetchRequestMode request_mode,
202 FetchCredentialsMode credentials_mode, 203 FetchCredentialsMode credentials_mode,
203 FetchRedirectMode redirect_mode, 204 FetchRedirectMode redirect_mode,
205 const std::string& integrity,
204 ResourceType resource_type, 206 ResourceType resource_type,
205 RequestContextType request_context_type, 207 RequestContextType request_context_type,
206 RequestContextFrameType frame_type, 208 RequestContextFrameType frame_type,
207 scoped_refptr<ResourceRequestBody> body, 209 scoped_refptr<ResourceRequestBody> body,
208 const base::Optional<base::TimeDelta>& timeout) 210 const base::Optional<base::TimeDelta>& timeout)
209 : context_(context), 211 : context_(context),
210 blob_storage_context_(blob_storage_context), 212 blob_storage_context_(blob_storage_context),
211 resource_type_(resource_type), 213 resource_type_(resource_type),
212 request_mode_(request_mode), 214 request_mode_(request_mode),
213 credentials_mode_(credentials_mode), 215 credentials_mode_(credentials_mode),
214 redirect_mode_(redirect_mode), 216 redirect_mode_(redirect_mode),
217 integrity_(integrity),
215 request_context_type_(request_context_type), 218 request_context_type_(request_context_type),
216 frame_type_(frame_type), 219 frame_type_(frame_type),
217 body_(body), 220 body_(body),
218 timeout_(timeout), 221 timeout_(timeout),
219 weak_factory_(this) {} 222 weak_factory_(this) {}
220 223
221 void ForeignFetchRequestHandler::DidFindRegistration( 224 void ForeignFetchRequestHandler::DidFindRegistration(
222 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, 225 const base::WeakPtr<ServiceWorkerURLRequestJob>& job,
223 ServiceWorkerStatusCode status, 226 ServiceWorkerStatusCode status,
224 scoped_refptr<ServiceWorkerRegistration> registration) { 227 scoped_refptr<ServiceWorkerRegistration> registration) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // The worker entry in the database was written by old version Chrome (< M56) 308 // The worker entry in the database was written by old version Chrome (< M56)
306 // and the main script was not loaded yet. In this case, we can't check the 309 // and the main script was not loaded yet. In this case, we can't check the
307 // origin trial token. 310 // origin trial token.
308 if (!active_version->origin_trial_tokens()) 311 if (!active_version->origin_trial_tokens())
309 return true; 312 return true;
310 const auto& token_map = *active_version->origin_trial_tokens(); 313 const auto& token_map = *active_version->origin_trial_tokens();
311 return base::ContainsKey(token_map, "ForeignFetch"); 314 return base::ContainsKey(token_map, "ForeignFetch");
312 } 315 }
313 316
314 } // namespace content 317 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698