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