| 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 <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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 if (skip_service_worker == SkipServiceWorker::ALL) | 86 if (skip_service_worker == SkipServiceWorker::ALL) |
| 87 return; | 87 return; |
| 88 | 88 |
| 89 if (!initiated_in_secure_context) | 89 if (!initiated_in_secure_context) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) | 92 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 if (request->initiator().IsSameOriginWith(url::Origin(request->url()))) | 95 if (!request->initiator().has_value() || |
| 96 request->initiator()->IsSameOriginWith(url::Origin(request->url()))) { |
| 96 return; | 97 return; |
| 98 } |
| 97 | 99 |
| 98 if (!context_wrapper->OriginHasForeignFetchRegistrations( | 100 if (!context_wrapper->OriginHasForeignFetchRegistrations( |
| 99 request->url().GetOrigin())) { | 101 request->url().GetOrigin())) { |
| 100 return; | 102 return; |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Any more precise checks to see if the request should be intercepted are | 105 // Any more precise checks to see if the request should be intercepted are |
| 104 // asynchronous, so just create our handler in all cases. | 106 // asynchronous, so just create our handler in all cases. |
| 105 std::unique_ptr<ForeignFetchRequestHandler> handler( | 107 std::unique_ptr<ForeignFetchRequestHandler> handler( |
| 106 new ForeignFetchRequestHandler( | 108 new ForeignFetchRequestHandler( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 213 |
| 212 const GURL& request_url = job->request()->url(); | 214 const GURL& request_url = job->request()->url(); |
| 213 bool scope_matches = false; | 215 bool scope_matches = false; |
| 214 for (const GURL& scope : active_version->foreign_fetch_scopes()) { | 216 for (const GURL& scope : active_version->foreign_fetch_scopes()) { |
| 215 if (ServiceWorkerUtils::ScopeMatches(scope, request_url)) { | 217 if (ServiceWorkerUtils::ScopeMatches(scope, request_url)) { |
| 216 scope_matches = true; | 218 scope_matches = true; |
| 217 break; | 219 break; |
| 218 } | 220 } |
| 219 } | 221 } |
| 220 | 222 |
| 221 const url::Origin& request_origin = job->request()->initiator(); | 223 const url::Origin& request_origin = job->request()->initiator().value(); |
| 222 bool origin_matches = active_version->foreign_fetch_origins().empty(); | 224 bool origin_matches = active_version->foreign_fetch_origins().empty(); |
| 223 for (const url::Origin& origin : active_version->foreign_fetch_origins()) { | 225 for (const url::Origin& origin : active_version->foreign_fetch_origins()) { |
| 224 if (request_origin.IsSameOriginWith(origin)) | 226 if (request_origin.IsSameOriginWith(origin)) |
| 225 origin_matches = true; | 227 origin_matches = true; |
| 226 } | 228 } |
| 227 | 229 |
| 228 if (!scope_matches || !origin_matches) { | 230 if (!scope_matches || !origin_matches) { |
| 229 job->FallbackToNetwork(); | 231 job->FallbackToNetwork(); |
| 230 return; | 232 return; |
| 231 } | 233 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return target_worker_.get(); | 266 return target_worker_.get(); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void ForeignFetchRequestHandler::ClearJob() { | 269 void ForeignFetchRequestHandler::ClearJob() { |
| 268 job_.reset(); | 270 job_.reset(); |
| 269 target_worker_ = nullptr; | 271 target_worker_ = nullptr; |
| 270 resource_context_ = nullptr; | 272 resource_context_ = nullptr; |
| 271 } | 273 } |
| 272 | 274 |
| 273 } // namespace content | 275 } // namespace content |
| OLD | NEW |