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/loader/MixedContentChecker.h" | 9 #include "core/loader/MixedContentChecker.h" |
| 10 #include "core/probe/CoreProbes.h" |
10 #include "core/timing/WorkerGlobalScopePerformance.h" | 11 #include "core/timing/WorkerGlobalScopePerformance.h" |
11 #include "core/workers/WorkerClients.h" | 12 #include "core/workers/WorkerClients.h" |
12 #include "core/workers/WorkerGlobalScope.h" | 13 #include "core/workers/WorkerGlobalScope.h" |
| 14 #include "platform/RuntimeEnabledFeatures.h" |
13 #include "platform/Supplementable.h" | 15 #include "platform/Supplementable.h" |
14 #include "platform/WebTaskRunner.h" | 16 #include "platform/WebTaskRunner.h" |
15 #include "platform/exported/WrappedResourceRequest.h" | 17 #include "platform/exported/WrappedResourceRequest.h" |
16 #include "platform/loader/fetch/ResourceFetcher.h" | 18 #include "platform/loader/fetch/ResourceFetcher.h" |
17 #include "platform/scheduler/child/web_scheduler.h" | 19 #include "platform/scheduler/child/web_scheduler.h" |
| 20 #include "platform/weborigin/SecurityPolicy.h" |
18 #include "public/platform/Platform.h" | 21 #include "public/platform/Platform.h" |
19 #include "public/platform/WebMixedContent.h" | 22 #include "public/platform/WebMixedContent.h" |
20 #include "public/platform/WebMixedContentContextType.h" | 23 #include "public/platform/WebMixedContentContextType.h" |
21 #include "public/platform/WebThread.h" | 24 #include "public/platform/WebThread.h" |
22 #include "public/platform/WebURLRequest.h" | 25 #include "public/platform/WebURLRequest.h" |
23 #include "public/platform/WebWorkerFetchContext.h" | 26 #include "public/platform/WebWorkerFetchContext.h" |
24 | 27 |
25 namespace blink { | 28 namespace blink { |
26 | 29 |
27 namespace { | 30 namespace { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return nullptr; | 118 return nullptr; |
116 } | 119 } |
117 | 120 |
118 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { | 121 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { |
119 // TODO(horo): Implement this. | 122 // TODO(horo): Implement this. |
120 return nullptr; | 123 return nullptr; |
121 } | 124 } |
122 | 125 |
123 bool WorkerFetchContext::ShouldBlockRequestByInspector( | 126 bool WorkerFetchContext::ShouldBlockRequestByInspector( |
124 const ResourceRequest& resource_request) const { | 127 const ResourceRequest& resource_request) const { |
125 // TODO(horo): Implement this. | 128 bool should_block_request = false; |
126 return false; | 129 probe::shouldBlockRequest(worker_global_scope_, resource_request, |
| 130 &should_block_request); |
| 131 return should_block_request; |
127 } | 132 } |
128 | 133 |
129 void WorkerFetchContext::DispatchDidBlockRequest( | 134 void WorkerFetchContext::DispatchDidBlockRequest( |
130 const ResourceRequest& resource_request, | 135 const ResourceRequest& resource_request, |
131 const FetchInitiatorInfo& fetch_initiator_info, | 136 const FetchInitiatorInfo& fetch_initiator_info, |
132 ResourceRequestBlockedReason blocked_reason) const { | 137 ResourceRequestBlockedReason blocked_reason) const { |
133 // TODO(horo): Implement this. | 138 probe::didBlockRequest(worker_global_scope_, resource_request, nullptr, |
| 139 fetch_initiator_info, blocked_reason); |
134 } | 140 } |
135 | 141 |
136 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { | 142 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { |
137 // TODO(horo): Implement this. | 143 // TODO(horo): Implement this. |
138 } | 144 } |
139 | 145 |
140 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { | 146 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { |
141 // TODO(horo): Implement this. | 147 // TODO(horo): Implement this. |
142 return false; | 148 return false; |
143 } | 149 } |
(...skipping 23 matching lines...) Expand all Loading... |
167 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { | 173 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { |
168 return web_context_->CreateURLLoader(); | 174 return web_context_->CreateURLLoader(); |
169 } | 175 } |
170 | 176 |
171 bool WorkerFetchContext::IsControlledByServiceWorker() const { | 177 bool WorkerFetchContext::IsControlledByServiceWorker() const { |
172 return web_context_->IsControlledByServiceWorker(); | 178 return web_context_->IsControlledByServiceWorker(); |
173 } | 179 } |
174 | 180 |
175 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | 181 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, |
176 RedirectType) { | 182 RedirectType) { |
| 183 String user_agent = worker_global_scope_->UserAgent(); |
| 184 probe::applyUserAgentOverride(worker_global_scope_, &user_agent); |
| 185 DCHECK(!user_agent.IsNull()); |
| 186 request.SetHTTPUserAgent(AtomicString(user_agent)); |
| 187 |
177 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); | 188 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo); |
178 WrappedResourceRequest webreq(request); | 189 WrappedResourceRequest webreq(request); |
179 web_context_->WillSendRequest(webreq); | 190 web_context_->WillSendRequest(webreq); |
180 } | 191 } |
181 | 192 |
182 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { | 193 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { |
183 return loading_task_runner_; | 194 return loading_task_runner_; |
184 } | 195 } |
185 | 196 |
| 197 int64_t WorkerFetchContext::ServiceWorkerID() const { |
| 198 // TODO(horo): ServiceWorkerID() is used only for memory cache which is |
| 199 // disabled in worker thread. So we should remove this method. |
| 200 return web_context_->ServiceWorkerID(); |
| 201 } |
| 202 |
186 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, | 203 void WorkerFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request, |
187 FetchResourceType type) { | 204 FetchResourceType type) { |
188 BaseFetchContext::AddAdditionalRequestHeaders(request, type); | 205 BaseFetchContext::AddAdditionalRequestHeaders(request, type); |
189 | 206 |
190 // The remaining modifications are only necessary for HTTP and HTTPS. | 207 // The remaining modifications are only necessary for HTTP and HTTPS. |
191 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) | 208 if (!request.Url().IsEmpty() && !request.Url().ProtocolIsInHTTPFamily()) |
192 return; | 209 return; |
193 | 210 |
194 if (web_context_->IsDataSaverEnabled()) | 211 if (web_context_->IsDataSaverEnabled()) |
195 request.SetHTTPHeaderField("Save-Data", "on"); | 212 request.SetHTTPHeaderField("Save-Data", "on"); |
196 } | 213 } |
197 | 214 |
| 215 void WorkerFetchContext::DispatchWillSendRequest( |
| 216 unsigned long identifier, |
| 217 ResourceRequest& request, |
| 218 const ResourceResponse& redirect_response, |
| 219 const FetchInitiatorInfo& initiator_info) { |
| 220 probe::willSendRequest(worker_global_scope_, identifier, nullptr, request, |
| 221 redirect_response, initiator_info); |
| 222 } |
| 223 |
198 void WorkerFetchContext::DispatchDidReceiveResponse( | 224 void WorkerFetchContext::DispatchDidReceiveResponse( |
199 unsigned long identifier, | 225 unsigned long identifier, |
200 const ResourceResponse& response, | 226 const ResourceResponse& response, |
201 WebURLRequest::FrameType frame_type, | 227 WebURLRequest::FrameType frame_type, |
202 WebURLRequest::RequestContext request_context, | 228 WebURLRequest::RequestContext request_context, |
203 Resource* resource, | 229 Resource* resource, |
204 ResourceResponseType) { | 230 ResourceResponseType) { |
205 if (response.HasMajorCertificateErrors()) { | 231 if (response.HasMajorCertificateErrors()) { |
206 WebMixedContentContextType context_type = | 232 WebMixedContentContextType context_type = |
207 WebMixedContent::ContextTypeFromRequestContext( | 233 WebMixedContent::ContextTypeFromRequestContext( |
208 request_context, false /* strictMixedContentCheckingForPlugin */); | 234 request_context, false /* strictMixedContentCheckingForPlugin */); |
209 if (context_type == WebMixedContentContextType::kBlockable) { | 235 if (context_type == WebMixedContentContextType::kBlockable) { |
210 web_context_->DidRunContentWithCertificateErrors(response.Url()); | 236 web_context_->DidRunContentWithCertificateErrors(response.Url()); |
211 } else { | 237 } else { |
212 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); | 238 web_context_->DidDisplayContentWithCertificateErrors(response.Url()); |
213 } | 239 } |
214 } | 240 } |
| 241 probe::didReceiveResourceResponse(worker_global_scope_, identifier, nullptr, |
| 242 response, resource); |
| 243 } |
| 244 |
| 245 void WorkerFetchContext::DispatchDidReceiveData(unsigned long identifier, |
| 246 const char* data, |
| 247 int data_length) { |
| 248 probe::didReceiveData(worker_global_scope_, identifier, nullptr, data, |
| 249 data_length); |
| 250 } |
| 251 |
| 252 void WorkerFetchContext::DispatchDidReceiveEncodedData( |
| 253 unsigned long identifier, |
| 254 int encoded_data_length) { |
| 255 probe::didReceiveEncodedDataLength(worker_global_scope_, identifier, |
| 256 encoded_data_length); |
| 257 } |
| 258 |
| 259 void WorkerFetchContext::DispatchDidFinishLoading(unsigned long identifier, |
| 260 double finish_time, |
| 261 int64_t encoded_data_length, |
| 262 int64_t decoded_body_length) { |
| 263 probe::didFinishLoading(worker_global_scope_, identifier, nullptr, |
| 264 finish_time, encoded_data_length, |
| 265 decoded_body_length); |
| 266 } |
| 267 |
| 268 void WorkerFetchContext::DispatchDidFail(unsigned long identifier, |
| 269 const ResourceError& error, |
| 270 int64_t encoded_data_length, |
| 271 bool is_internal_request) { |
| 272 probe::didFailLoading(worker_global_scope_, identifier, error); |
215 } | 273 } |
216 | 274 |
217 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { | 275 void WorkerFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { |
218 WorkerGlobalScopePerformance::performance(*worker_global_scope_) | 276 WorkerGlobalScopePerformance::performance(*worker_global_scope_) |
219 ->AddResourceTiming(info); | 277 ->AddResourceTiming(info); |
220 } | 278 } |
221 | 279 |
222 void WorkerFetchContext::PopulateResourceRequest( | 280 void WorkerFetchContext::PopulateResourceRequest( |
223 const KURL& url, | 281 const KURL& url, |
224 Resource::Type type, | 282 Resource::Type type, |
225 const ClientHintsPreferences& hints_preferences, | 283 const ClientHintsPreferences& hints_preferences, |
226 const FetchParameters::ResourceWidth& resource_width, | 284 const FetchParameters::ResourceWidth& resource_width, |
227 const ResourceLoaderOptions& options, | 285 const ResourceLoaderOptions& options, |
228 SecurityViolationReportingPolicy reporting_policy, | 286 SecurityViolationReportingPolicy reporting_policy, |
229 ResourceRequest& out_request) { | 287 ResourceRequest& out_request) { |
230 SetFirstPartyCookieAndRequestorOrigin(out_request); | 288 SetFirstPartyCookieAndRequestorOrigin(out_request); |
231 } | 289 } |
232 | 290 |
233 void WorkerFetchContext::SetFirstPartyCookieAndRequestorOrigin( | 291 void WorkerFetchContext::SetFirstPartyCookieAndRequestorOrigin( |
234 ResourceRequest& out_request) { | 292 ResourceRequest& out_request) { |
235 if (out_request.FirstPartyForCookies().IsNull()) | 293 if (out_request.FirstPartyForCookies().IsNull()) |
236 out_request.SetFirstPartyForCookies(FirstPartyForCookies()); | 294 out_request.SetFirstPartyForCookies(FirstPartyForCookies()); |
237 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to | 295 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to |
238 // initialize itself with a `nullptr` initiator so that this can be a simple | 296 // initialize itself with a `nullptr` initiator so that this can be a simple |
239 // `isNull()` check. https://crbug.com/625969 | 297 // `isNull()` check. https://crbug.com/625969 |
240 if (out_request.RequestorOrigin()->IsUnique()) | 298 if (out_request.RequestorOrigin()->IsUnique()) |
241 out_request.SetRequestorOrigin(GetSecurityOrigin()); | 299 out_request.SetRequestorOrigin(GetSecurityOrigin()); |
| 300 // TODO: Sandboxed flag? |
242 } | 301 } |
243 | 302 |
244 DEFINE_TRACE(WorkerFetchContext) { | 303 DEFINE_TRACE(WorkerFetchContext) { |
245 visitor->Trace(worker_global_scope_); | 304 visitor->Trace(worker_global_scope_); |
246 visitor->Trace(resource_fetcher_); | 305 visitor->Trace(resource_fetcher_); |
247 BaseFetchContext::Trace(visitor); | 306 BaseFetchContext::Trace(visitor); |
248 } | 307 } |
249 | 308 |
250 void ProvideWorkerFetchContextToWorker( | 309 void ProvideWorkerFetchContextToWorker( |
251 WorkerClients* clients, | 310 WorkerClients* clients, |
252 std::unique_ptr<WebWorkerFetchContext> web_context) { | 311 std::unique_ptr<WebWorkerFetchContext> web_context) { |
253 DCHECK(clients); | 312 DCHECK(clients); |
254 WorkerFetchContextHolder::ProvideTo( | 313 WorkerFetchContextHolder::ProvideTo( |
255 *clients, WorkerFetchContextHolder::SupplementName(), | 314 *clients, WorkerFetchContextHolder::SupplementName(), |
256 new WorkerFetchContextHolder(std::move(web_context))); | 315 new WorkerFetchContextHolder(std::move(web_context))); |
257 } | 316 } |
258 | 317 |
259 } // namespace blink | 318 } // namespace blink |
OLD | NEW |