| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/loader/WorkerFetchContext.h" | 5 #include "core/loader/WorkerFetchContext.h" |
| 6 | 6 |
| 7 #include "core/frame/Deprecation.h" | 7 #include "core/frame/Deprecation.h" |
| 8 #include "core/frame/UseCounter.h" | 8 #include "core/frame/UseCounter.h" |
| 9 #include "core/timing/WorkerGlobalScopePerformance.h" | 9 #include "core/timing/WorkerGlobalScopePerformance.h" |
| 10 #include "core/workers/WorkerClients.h" | 10 #include "core/workers/WorkerClients.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 loading_task_runner_->ToSingleThreadTaskRunner()); | 86 loading_task_runner_->ToSingleThreadTaskRunner()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 ResourceFetcher* WorkerFetchContext::GetResourceFetcher() { | 89 ResourceFetcher* WorkerFetchContext::GetResourceFetcher() { |
| 90 if (resource_fetcher_) | 90 if (resource_fetcher_) |
| 91 return resource_fetcher_; | 91 return resource_fetcher_; |
| 92 resource_fetcher_ = ResourceFetcher::Create(this); | 92 resource_fetcher_ = ResourceFetcher::Create(this); |
| 93 return resource_fetcher_; | 93 return resource_fetcher_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 KURL WorkerFetchContext::FirstPartyForCookies() const { |
| 97 return web_context_->FirstPartyForCookies(); |
| 98 } |
| 99 |
| 96 ContentSettingsClient* WorkerFetchContext::GetContentSettingsClient() const { | 100 ContentSettingsClient* WorkerFetchContext::GetContentSettingsClient() const { |
| 97 // TODO(horo): Implement this. | 101 // TODO(horo): Implement this. |
| 98 return nullptr; | 102 return nullptr; |
| 99 } | 103 } |
| 100 | 104 |
| 101 Settings* WorkerFetchContext::GetSettings() const { | 105 Settings* WorkerFetchContext::GetSettings() const { |
| 102 // TODO(horo): Implement this. | 106 // TODO(horo): Implement this. |
| 103 return nullptr; | 107 return nullptr; |
| 104 } | 108 } |
| 105 | 109 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 188 |
| 185 if (web_context_->IsDataSaverEnabled()) | 189 if (web_context_->IsDataSaverEnabled()) |
| 186 request.SetHTTPHeaderField("Save-Data", "on"); | 190 request.SetHTTPHeaderField("Save-Data", "on"); |
| 187 } | 191 } |
| 188 | 192 |
| 189 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { | 193 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { |
| 190 WorkerGlobalScopePerformance::performance(*worker_global_scope_) | 194 WorkerGlobalScopePerformance::performance(*worker_global_scope_) |
| 191 ->AddResourceTiming(info); | 195 ->AddResourceTiming(info); |
| 192 } | 196 } |
| 193 | 197 |
| 198 void WorkerFetchContext::PopulateResourceRequest( |
| 199 const KURL& url, |
| 200 Resource::Type type, |
| 201 const ClientHintsPreferences& hints_preferences, |
| 202 const FetchParameters::ResourceWidth& resource_width, |
| 203 const ResourceLoaderOptions& options, |
| 204 SecurityViolationReportingPolicy reporting_policy, |
| 205 ResourceRequest& out_request) { |
| 206 SetFirstPartyCookieAndRequestorOrigin(out_request); |
| 207 } |
| 208 |
| 209 void WorkerFetchContext::SetFirstPartyCookieAndRequestorOrigin( |
| 210 ResourceRequest& out_request) { |
| 211 if (out_request.FirstPartyForCookies().IsNull()) |
| 212 out_request.SetFirstPartyForCookies(FirstPartyForCookies()); |
| 213 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to |
| 214 // initialize itself with a `nullptr` initiator so that this can be a simple |
| 215 // `isNull()` check. https://crbug.com/625969 |
| 216 if (out_request.RequestorOrigin()->IsUnique()) |
| 217 out_request.SetRequestorOrigin(GetSecurityOrigin()); |
| 218 } |
| 219 |
| 194 DEFINE_TRACE(WorkerFetchContext) { | 220 DEFINE_TRACE(WorkerFetchContext) { |
| 195 visitor->Trace(worker_global_scope_); | 221 visitor->Trace(worker_global_scope_); |
| 196 visitor->Trace(resource_fetcher_); | 222 visitor->Trace(resource_fetcher_); |
| 197 BaseFetchContext::Trace(visitor); | 223 BaseFetchContext::Trace(visitor); |
| 198 } | 224 } |
| 199 | 225 |
| 200 void ProvideWorkerFetchContextToWorker( | 226 void ProvideWorkerFetchContextToWorker( |
| 201 WorkerClients* clients, | 227 WorkerClients* clients, |
| 202 std::unique_ptr<WebWorkerFetchContext> web_context) { | 228 std::unique_ptr<WebWorkerFetchContext> web_context) { |
| 203 DCHECK(clients); | 229 DCHECK(clients); |
| 204 WorkerFetchContextHolder::ProvideTo( | 230 WorkerFetchContextHolder::ProvideTo( |
| 205 *clients, WorkerFetchContextHolder::SupplementName(), | 231 *clients, WorkerFetchContextHolder::SupplementName(), |
| 206 new WorkerFetchContextHolder(std::move(web_context))); | 232 new WorkerFetchContextHolder(std::move(web_context))); |
| 207 } | 233 } |
| 208 | 234 |
| 209 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |