OLD | NEW |
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 "base/macros.h" | 7 #include "base/macros.h" |
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/browser/service_worker/service_worker_url_request_job.h" | 9 #include "content/browser/service_worker/service_worker_url_request_job.h" |
10 #include "content/common/resource_request_body.h" | 10 #include "content/common/resource_request_body.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 const GURL& request_url = job->request()->url(); | 174 const GURL& request_url = job->request()->url(); |
175 bool scope_matches = false; | 175 bool scope_matches = false; |
176 for (const GURL& scope : active_version->foreign_fetch_scopes()) { | 176 for (const GURL& scope : active_version->foreign_fetch_scopes()) { |
177 if (ServiceWorkerUtils::ScopeMatches(scope, request_url)) { | 177 if (ServiceWorkerUtils::ScopeMatches(scope, request_url)) { |
178 scope_matches = true; | 178 scope_matches = true; |
179 break; | 179 break; |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 if (!scope_matches) { | 183 const url::Origin& request_origin = job->request()->initiator(); |
| 184 bool origin_matches = active_version->foreign_fetch_origins().empty(); |
| 185 for (const url::Origin& origin : active_version->foreign_fetch_origins()) { |
| 186 if (request_origin.IsSameOriginWith(origin)) |
| 187 origin_matches = true; |
| 188 } |
| 189 |
| 190 if (!scope_matches || !origin_matches) { |
184 job->FallbackToNetwork(); | 191 job->FallbackToNetwork(); |
185 return; | 192 return; |
186 } | 193 } |
187 | 194 |
188 target_worker_ = active_version; | 195 target_worker_ = active_version; |
189 job->ForwardToServiceWorker(); | 196 job->ForwardToServiceWorker(); |
190 } | 197 } |
191 | 198 |
192 void ForeignFetchRequestHandler::OnPrepareToRestart( | 199 void ForeignFetchRequestHandler::OnPrepareToRestart( |
193 base::TimeTicks service_worker_start_time, | 200 base::TimeTicks service_worker_start_time, |
(...skipping 20 matching lines...) Expand all Loading... |
214 } | 221 } |
215 return target_worker_.get(); | 222 return target_worker_.get(); |
216 } | 223 } |
217 | 224 |
218 void ForeignFetchRequestHandler::ClearJob() { | 225 void ForeignFetchRequestHandler::ClearJob() { |
219 job_.reset(); | 226 job_.reset(); |
220 target_worker_ = nullptr; | 227 target_worker_ = nullptr; |
221 } | 228 } |
222 | 229 |
223 } // namespace content | 230 } // namespace content |
OLD | NEW |