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 #include <utility> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
13 #include "content/browser/service_worker/service_worker_response_info.h" | 15 #include "content/browser/service_worker/service_worker_response_info.h" |
14 #include "content/browser/service_worker/service_worker_url_request_job.h" | 16 #include "content/browser/service_worker/service_worker_url_request_job.h" |
15 #include "content/common/resource_request_body_impl.h" | 17 #include "content/common/resource_request_body_impl.h" |
16 #include "content/common/service_worker/service_worker_types.h" | 18 #include "content/common/service_worker/service_worker_types.h" |
17 #include "content/common/service_worker/service_worker_utils.h" | 19 #include "content/common/service_worker/service_worker_utils.h" |
18 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
19 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
20 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 provider_host->running_hosted_version()->remaining_timeout()); | 119 provider_host->running_hosted_version()->remaining_timeout()); |
118 } | 120 } |
119 | 121 |
120 if (!context_wrapper->OriginHasForeignFetchRegistrations( | 122 if (!context_wrapper->OriginHasForeignFetchRegistrations( |
121 request->url().GetOrigin())) { | 123 request->url().GetOrigin())) { |
122 return; | 124 return; |
123 } | 125 } |
124 | 126 |
125 // Any more precise checks to see if the request should be intercepted are | 127 // Any more precise checks to see if the request should be intercepted are |
126 // asynchronous, so just create our handler in all cases. | 128 // asynchronous, so just create our handler in all cases. |
127 std::unique_ptr<ForeignFetchRequestHandler> handler( | 129 std::unique_ptr<ForeignFetchRequestHandler> handler = |
128 new ForeignFetchRequestHandler( | 130 base::WrapUnique(new ForeignFetchRequestHandler( |
129 context_wrapper, blob_storage_context->AsWeakPtr(), request_mode, | 131 context_wrapper, blob_storage_context->AsWeakPtr(), request_mode, |
130 credentials_mode, redirect_mode, resource_type, request_context_type, | 132 credentials_mode, redirect_mode, resource_type, request_context_type, |
131 frame_type, body, timeout)); | 133 frame_type, body, timeout)); |
132 request->SetUserData(&kUserDataKey, handler.release()); | 134 request->SetUserData(&kUserDataKey, std::move(handler)); |
133 } | 135 } |
134 | 136 |
135 ForeignFetchRequestHandler* ForeignFetchRequestHandler::GetHandler( | 137 ForeignFetchRequestHandler* ForeignFetchRequestHandler::GetHandler( |
136 net::URLRequest* request) { | 138 net::URLRequest* request) { |
137 return static_cast<ForeignFetchRequestHandler*>( | 139 return static_cast<ForeignFetchRequestHandler*>( |
138 request->GetUserData(&kUserDataKey)); | 140 request->GetUserData(&kUserDataKey)); |
139 } | 141 } |
140 | 142 |
141 std::unique_ptr<net::URLRequestInterceptor> | 143 std::unique_ptr<net::URLRequestInterceptor> |
142 ForeignFetchRequestHandler::CreateInterceptor( | 144 ForeignFetchRequestHandler::CreateInterceptor( |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // The worker entry in the database was written by old version Chrome (< M56) | 305 // The worker entry in the database was written by old version Chrome (< M56) |
304 // and the main script was not loaded yet. In this case, we can't check the | 306 // and the main script was not loaded yet. In this case, we can't check the |
305 // origin trial token. | 307 // origin trial token. |
306 if (!active_version->origin_trial_tokens()) | 308 if (!active_version->origin_trial_tokens()) |
307 return true; | 309 return true; |
308 const auto& token_map = *active_version->origin_trial_tokens(); | 310 const auto& token_map = *active_version->origin_trial_tokens(); |
309 return base::ContainsKey(token_map, "ForeignFetch"); | 311 return base::ContainsKey(token_map, "ForeignFetch"); |
310 } | 312 } |
311 | 313 |
312 } // namespace content | 314 } // namespace content |
OLD | NEW |