Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: content/browser/service_worker/service_worker_fetch_dispatcher.cc

Issue 2473263003: Set "Service-Worker-Navigation-Preload" header (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_worker_fetch_dispatcher.h" 5 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "content/browser/loader/resource_dispatcher_host_impl.h" 14 #include "content/browser/loader/resource_dispatcher_host_impl.h"
15 #include "content/browser/loader/resource_message_filter.h" 15 #include "content/browser/loader/resource_message_filter.h"
16 #include "content/browser/loader/resource_request_info_impl.h" 16 #include "content/browser/loader/resource_request_info_impl.h"
17 #include "content/browser/loader/url_loader_factory_impl.h" 17 #include "content/browser/loader/url_loader_factory_impl.h"
18 #include "content/browser/service_worker/embedded_worker_status.h" 18 #include "content/browser/service_worker/embedded_worker_status.h"
19 #include "content/browser/service_worker/service_worker_version.h" 19 #include "content/browser/service_worker/service_worker_version.h"
20 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" 20 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h"
21 #include "content/common/service_worker/service_worker_messages.h" 21 #include "content/common/service_worker/service_worker_messages.h"
22 #include "content/common/service_worker/service_worker_status_code.h" 22 #include "content/common/service_worker/service_worker_status_code.h"
23 #include "content/common/service_worker/service_worker_types.h" 23 #include "content/common/service_worker/service_worker_types.h"
24 #include "content/common/service_worker/service_worker_utils.h" 24 #include "content/common/service_worker/service_worker_utils.h"
25 #include "content/common/url_loader.mojom.h" 25 #include "content/common/url_loader.mojom.h"
26 #include "content/common/url_loader_factory.mojom.h" 26 #include "content/common/url_loader_factory.mojom.h"
27 #include "content/public/common/browser_side_navigation_policy.h" 27 #include "content/public/common/browser_side_navigation_policy.h"
28 #include "content/public/common/content_features.h" 28 #include "content/public/common/content_features.h"
29 #include "net/http/http_util.h"
29 #include "net/log/net_log.h" 30 #include "net/log/net_log.h"
30 #include "net/log/net_log_capture_mode.h" 31 #include "net/log/net_log_capture_mode.h"
31 #include "net/log/net_log_event_type.h" 32 #include "net/log/net_log_event_type.h"
32 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
33 34
34 namespace content { 35 namespace content {
35 36
36 namespace { 37 namespace {
37 38
38 using EventType = ServiceWorkerMetrics::EventType; 39 using EventType = ServiceWorkerMetrics::EventType;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 request.load_flags = original_request->load_flags(); 326 request.load_flags = original_request->load_flags();
326 // Set to SUB_RESOURCE because we shouldn't trigger NavigationResourceThrottle 327 // Set to SUB_RESOURCE because we shouldn't trigger NavigationResourceThrottle
327 // for the service worker navigation preload request. 328 // for the service worker navigation preload request.
328 request.resource_type = RESOURCE_TYPE_SUB_RESOURCE; 329 request.resource_type = RESOURCE_TYPE_SUB_RESOURCE;
329 request.priority = original_request->priority(); 330 request.priority = original_request->priority();
330 request.skip_service_worker = SkipServiceWorker::ALL; 331 request.skip_service_worker = SkipServiceWorker::ALL;
331 request.do_not_prompt_for_login = true; 332 request.do_not_prompt_for_login = true;
332 request.render_frame_id = original_info->GetRenderFrameID(); 333 request.render_frame_id = original_info->GetRenderFrameID();
333 request.is_main_frame = original_info->IsMainFrame(); 334 request.is_main_frame = original_info->IsMainFrame();
334 request.parent_is_main_frame = original_info->ParentIsMainFrame(); 335 request.parent_is_main_frame = original_info->ParentIsMainFrame();
336
337 DCHECK(net::HttpUtil::IsValidHeaderValue(
338 version_->navigation_preload_state().header));
339 request.headers = "Service-Worker-Navigation-Preload: " +
340 version_->navigation_preload_state().header;
341
335 const int request_id = ResourceDispatcherHostImpl::Get()->MakeRequestID(); 342 const int request_id = ResourceDispatcherHostImpl::Get()->MakeRequestID();
336 DCHECK_LT(request_id, -1); 343 DCHECK_LT(request_id, -1);
337 // TODO(horo): Add "Service-Worker-Navigation-Preload" header.
338 // See: https://github.com/w3c/ServiceWorker/issues/920#issuecomment-251150270
339 factory->CreateLoaderAndStart(GetProxy(&preload_handle_->url_loader), 344 factory->CreateLoaderAndStart(GetProxy(&preload_handle_->url_loader),
340 original_info->GetRouteID(), request_id, 345 original_info->GetRouteID(), request_id,
341 request, std::move(url_loader_client)); 346 request, std::move(url_loader_client));
342 } 347 }
343 348
344 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() 349 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType()
345 const { 350 const {
346 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) 351 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH)
347 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; 352 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH;
348 return ResourceTypeToEventType(resource_type_); 353 return ResourceTypeToEventType(resource_type_);
349 } 354 }
350 355
351 } // namespace content 356 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698