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/workers/WorkerClients.h" | 9 #include "core/workers/WorkerClients.h" |
10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
11 #include "platform/Supplementable.h" | 11 #include "platform/Supplementable.h" |
12 #include "platform/WebTaskRunner.h" | 12 #include "platform/WebTaskRunner.h" |
13 #include "platform/exported/WrappedResourceRequest.h" | 13 #include "platform/exported/WrappedResourceRequest.h" |
14 #include "platform/loader/fetch/ResourceFetcher.h" | 14 #include "platform/loader/fetch/ResourceFetcher.h" |
15 #include "platform/scheduler/child/web_scheduler.h" | 15 #include "platform/scheduler/child/web_scheduler.h" |
16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
17 #include "public/platform/WebThread.h" | 17 #include "public/platform/WebThread.h" |
18 #include "public/platform/WebURLRequest.h" | 18 #include "public/platform/WebURLRequest.h" |
19 #include "public/platform/WebWorkerFetchContext.h" | 19 #include "public/platform/WebWorkerFetchContext.h" |
| 20 #include "public/web/WebDataSaverFlag.h" |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the | 26 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the |
26 // main thread to the worker thread by attaching to the WorkerClients as a | 27 // main thread to the worker thread by attaching to the WorkerClients as a |
27 // Supplement. | 28 // Supplement. |
28 class WorkerFetchContextHolder final | 29 class WorkerFetchContextHolder final |
29 : public GarbageCollectedFinalized<WorkerFetchContextHolder>, | 30 : public GarbageCollectedFinalized<WorkerFetchContextHolder>, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 175 } |
175 | 176 |
176 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, | 177 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, |
177 FetchResourceType type) { | 178 FetchResourceType type) { |
178 BaseFetchContext::AddAdditionalRequestHeaders(request, type); | 179 BaseFetchContext::AddAdditionalRequestHeaders(request, type); |
179 | 180 |
180 // The remaining modifications are only necessary for HTTP and HTTPS. | 181 // The remaining modifications are only necessary for HTTP and HTTPS. |
181 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) | 182 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) |
182 return; | 183 return; |
183 | 184 |
184 if (web_context_->IsDataSaverEnabled()) | 185 if (web_context_->DataSaverFlag() == WebDataSaverFlag::kEnabled) |
185 request.SetHTTPHeaderField("Save-Data", "on"); | 186 request.SetHTTPHeaderField("Save-Data", "on"); |
186 } | 187 } |
187 | 188 |
188 DEFINE_TRACE(WorkerFetchContext) { | 189 DEFINE_TRACE(WorkerFetchContext) { |
189 visitor->Trace(worker_global_scope_); | 190 visitor->Trace(worker_global_scope_); |
190 visitor->Trace(resource_fetcher_); | 191 visitor->Trace(resource_fetcher_); |
191 BaseFetchContext::Trace(visitor); | 192 BaseFetchContext::Trace(visitor); |
192 } | 193 } |
193 | 194 |
194 void ProvideWorkerFetchContextToWorker( | 195 void ProvideWorkerFetchContextToWorker( |
195 WorkerClients* clients, | 196 WorkerClients* clients, |
196 std::unique_ptr<WebWorkerFetchContext> web_context) { | 197 std::unique_ptr<WebWorkerFetchContext> web_context) { |
197 DCHECK(clients); | 198 DCHECK(clients); |
198 WorkerFetchContextHolder::ProvideTo( | 199 WorkerFetchContextHolder::ProvideTo( |
199 *clients, WorkerFetchContextHolder::SupplementName(), | 200 *clients, WorkerFetchContextHolder::SupplementName(), |
200 new WorkerFetchContextHolder(std::move(web_context))); | 201 new WorkerFetchContextHolder(std::move(web_context))); |
201 } | 202 } |
202 | 203 |
203 } // namespace blink | 204 } // namespace blink |
OLD | NEW |