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

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

Issue 2255713003: Effectively disable foreign fetch when third party cookies are disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: null out resource_context_ Created 4 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
« no previous file with comments | « content/browser/service_worker/foreign_fetch_request_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/browser/service_worker/service_worker_response_info.h" 12 #include "content/browser/service_worker/service_worker_response_info.h"
13 #include "content/browser/service_worker/service_worker_url_request_job.h" 13 #include "content/browser/service_worker/service_worker_url_request_job.h"
14 #include "content/common/resource_request_body_impl.h" 14 #include "content/common/resource_request_body_impl.h"
15 #include "content/common/service_worker/service_worker_utils.h" 15 #include "content/common/service_worker/service_worker_utils.h"
16 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/browser/resource_request_info.h"
16 #include "content/public/common/content_client.h" 18 #include "content/public/common/content_client.h"
17 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
18 #include "content/public/common/origin_trial_policy.h" 20 #include "content/public/common/origin_trial_policy.h"
19 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_interceptor.h" 22 #include "net/url_request/url_request_interceptor.h"
21 #include "storage/browser/blob/blob_storage_context.h" 23 #include "storage/browser/blob/blob_storage_context.h"
22 24
23 namespace content { 25 namespace content {
24 26
25 namespace { 27 namespace {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 154
153 // It's for original request (A) or redirect case (B-a or B-b). 155 // It's for original request (A) or redirect case (B-a or B-b).
154 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); 156 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker());
155 157
156 ServiceWorkerURLRequestJob* job = new ServiceWorkerURLRequestJob( 158 ServiceWorkerURLRequestJob* job = new ServiceWorkerURLRequestJob(
157 request, network_delegate, std::string(), blob_storage_context_, 159 request, network_delegate, std::string(), blob_storage_context_,
158 resource_context, request_mode_, credentials_mode_, redirect_mode_, 160 resource_context, request_mode_, credentials_mode_, redirect_mode_,
159 resource_type_, request_context_type_, frame_type_, body_, 161 resource_type_, request_context_type_, frame_type_, body_,
160 ServiceWorkerFetchType::FOREIGN_FETCH, this); 162 ServiceWorkerFetchType::FOREIGN_FETCH, this);
161 job_ = job->GetWeakPtr(); 163 job_ = job->GetWeakPtr();
164 resource_context_ = resource_context;
162 165
163 context_->FindReadyRegistrationForDocument( 166 context_->FindReadyRegistrationForDocument(
164 request->url(), 167 request->url(),
165 base::Bind(&ForeignFetchRequestHandler::DidFindRegistration, 168 base::Bind(&ForeignFetchRequestHandler::DidFindRegistration,
166 weak_factory_.GetWeakPtr(), job_)); 169 weak_factory_.GetWeakPtr(), job_));
167 170
168 return job_.get(); 171 return job_.get();
169 } 172 }
170 173
171 ForeignFetchRequestHandler::ForeignFetchRequestHandler( 174 ForeignFetchRequestHandler::ForeignFetchRequestHandler(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 for (const url::Origin& origin : active_version->foreign_fetch_origins()) { 223 for (const url::Origin& origin : active_version->foreign_fetch_origins()) {
221 if (request_origin.IsSameOriginWith(origin)) 224 if (request_origin.IsSameOriginWith(origin))
222 origin_matches = true; 225 origin_matches = true;
223 } 226 }
224 227
225 if (!scope_matches || !origin_matches) { 228 if (!scope_matches || !origin_matches) {
226 job->FallbackToNetwork(); 229 job->FallbackToNetwork();
227 return; 230 return;
228 } 231 }
229 232
233 int render_process_id;
234 int render_frame_id;
235 if (!ResourceRequestInfo::GetRenderFrameForRequest(
236 job->request(), &render_process_id, &render_frame_id)) {
237 render_process_id = -1;
238 render_frame_id = -1;
239 }
240 if (!GetContentClient()->browser()->AllowServiceWorker(
241 registration->pattern(), job->request()->first_party_for_cookies(),
242 resource_context_, render_process_id, render_frame_id)) {
243 job->FallbackToNetwork();
244 return;
245 }
246
230 target_worker_ = active_version; 247 target_worker_ = active_version;
231 job->ForwardToServiceWorker(); 248 job->ForwardToServiceWorker();
232 } 249 }
233 250
234 void ForeignFetchRequestHandler::OnPrepareToRestart() { 251 void ForeignFetchRequestHandler::OnPrepareToRestart() {
235 use_network_ = true; 252 use_network_ = true;
236 ClearJob(); 253 ClearJob();
237 } 254 }
238 255
239 ServiceWorkerVersion* ForeignFetchRequestHandler::GetServiceWorkerVersion( 256 ServiceWorkerVersion* ForeignFetchRequestHandler::GetServiceWorkerVersion(
240 ServiceWorkerMetrics::URLRequestJobResult* result) { 257 ServiceWorkerMetrics::URLRequestJobResult* result) {
241 // TODO(mek): Figure out what should happen if the active worker changes or 258 // TODO(mek): Figure out what should happen if the active worker changes or
242 // gets uninstalled before this point is reached. 259 // gets uninstalled before this point is reached.
243 if (!target_worker_) { 260 if (!target_worker_) {
244 *result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION; 261 *result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION;
245 return nullptr; 262 return nullptr;
246 } 263 }
247 return target_worker_.get(); 264 return target_worker_.get();
248 } 265 }
249 266
250 void ForeignFetchRequestHandler::ClearJob() { 267 void ForeignFetchRequestHandler::ClearJob() {
251 job_.reset(); 268 job_.reset();
252 target_worker_ = nullptr; 269 target_worker_ = nullptr;
270 resource_context_ = nullptr;
253 } 271 }
254 272
255 } // namespace content 273 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/foreign_fetch_request_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698