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

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

Issue 1652493002: Use request initiator to check for cross origin requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 597
598 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) { 598 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) {
599 ServiceWorkerMetrics::RecordFallbackedRequestMode(request_mode_); 599 ServiceWorkerMetrics::RecordFallbackedRequestMode(request_mode_);
600 // When the request_mode is |CORS| or |CORS-with-forced-preflight| and the 600 // When the request_mode is |CORS| or |CORS-with-forced-preflight| and the
601 // origin of the request URL is different from the security origin of the 601 // origin of the request URL is different from the security origin of the
602 // document, we can't simply fallback to the network in the browser process. 602 // document, we can't simply fallback to the network in the browser process.
603 // It is because the CORS preflight logic is implemented in the renderer. So 603 // It is because the CORS preflight logic is implemented in the renderer. So
604 // we returns a fall_back_required response to the renderer. 604 // we returns a fall_back_required response to the renderer.
605 if ((request_mode_ == FETCH_REQUEST_MODE_CORS || 605 if ((request_mode_ == FETCH_REQUEST_MODE_CORS ||
606 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) && 606 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) &&
607 delegate_->GetRequestingOrigin() != request()->url().GetOrigin()) { 607 !request()->initiator().IsSameOriginWith(
608 url::Origin(request()->url()))) {
608 fall_back_required_ = true; 609 fall_back_required_ = true;
609 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS); 610 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS);
610 CreateResponseHeader( 611 CreateResponseHeader(
611 400, "Service Worker Fallback Required", ServiceWorkerHeaderMap()); 612 400, "Service Worker Fallback Required", ServiceWorkerHeaderMap());
612 CommitResponseHeader(); 613 CommitResponseHeader();
613 return; 614 return;
614 } 615 }
615 // Change the response type and restart the request to fallback to 616 // Change the response type and restart the request to fallback to
616 // the network. 617 // the network.
617 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE); 618 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 base::TimeTicks() /* service_worker_ready_time */); 829 base::TimeTicks() /* service_worker_ready_time */);
829 return; 830 return;
830 } 831 }
831 delegate_->OnStartCompleted(true /* was_fetched_via_service_worker */, 832 delegate_->OnStartCompleted(true /* was_fetched_via_service_worker */,
832 fall_back_required_, response_url_, 833 fall_back_required_, response_url_,
833 service_worker_response_type_, worker_start_time_, 834 service_worker_response_type_, worker_start_time_,
834 worker_ready_time_); 835 worker_ready_time_);
835 } 836 }
836 837
837 } // namespace content 838 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698