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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 1294243004: PlzNavigate: Make ServiceWorker work with PlzNavigate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed a spot. Created 5 years, 2 months 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/frame_host/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include "base/command_line.h"
7 #include "content/browser/frame_host/frame_tree.h" 8 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/frame_host/frame_tree_node.h" 9 #include "content/browser/frame_host/frame_tree_node.h"
9 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
10 #include "content/browser/frame_host/navigation_handle_impl.h" 11 #include "content/browser/frame_host/navigation_handle_impl.h"
11 #include "content/browser/frame_host/navigation_request_info.h" 12 #include "content/browser/frame_host/navigation_request_info.h"
12 #include "content/browser/frame_host/navigator.h" 13 #include "content/browser/frame_host/navigator.h"
13 #include "content/browser/loader/navigation_url_loader.h" 14 #include "content/browser/loader/navigation_url_loader.h"
15 #include "content/browser/service_worker/service_worker_provider_host.h"
14 #include "content/browser/site_instance_impl.h" 16 #include "content/browser/site_instance_impl.h"
15 #include "content/common/resource_request_body.h" 17 #include "content/common/resource_request_body.h"
16 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_throttle.h" 19 #include "content/public/browser/navigation_throttle.h"
18 #include "content/public/browser/stream_handle.h" 20 #include "content/public/browser/stream_handle.h"
19 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
22 #include "content/public/common/content_switches.h"
20 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
21 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
22 #include "net/url_request/redirect_info.h" 25 #include "net/url_request/redirect_info.h"
26 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
23 27
24 namespace content { 28 namespace content {
25 29
26 namespace { 30 namespace {
27 31
28 // Returns the net load flags to use based on the navigation type. 32 // Returns the net load flags to use based on the navigation type.
29 // TODO(clamy): unify the code with what is happening on the renderer side. 33 // TODO(clamy): unify the code with what is happening on the renderer side.
30 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { 34 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) {
31 int load_flags = net::LOAD_NORMAL; 35 int load_flags = net::LOAD_NORMAL;
32 switch (navigation_type) { 36 switch (navigation_type) {
(...skipping 10 matching lines...) Expand all
43 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 47 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
44 load_flags |= net::LOAD_ONLY_FROM_CACHE; 48 load_flags |= net::LOAD_ONLY_FROM_CACHE;
45 break; 49 break;
46 case FrameMsg_Navigate_Type::NORMAL: 50 case FrameMsg_Navigate_Type::NORMAL:
47 default: 51 default:
48 break; 52 break;
49 } 53 }
50 return load_flags; 54 return load_flags;
51 } 55 }
52 56
57
58 // PlzNavigate
clamy 2015/10/02 10:34:44 No need for PlzNavigate prefix, this is a PlzNavig
Fabrice (no longer in Chrome) 2015/10/02 16:37:34 Done.
59 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps
60 // going down.
61 int g_next_navigation_provider_id = -2;
62
63 // PlzNavigate
64 // Returns the next ServiceWorkerProviderHost ID for navigations.
65 // Returns kInvalidServiceWorkerProviderId if sandbox_flags indicates a
66 // sandboxed frame.
67 // Returns kInvalidServiceWorkerProviderId for current navigation.
68 int GetNextNavigationProviderId(blink::WebSandboxFlags sandbox_flags) {
69 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
clamy 2015/10/02 10:34:44 This is a PlzNavigate only class, so no need to ha
Fabrice (no longer in Chrome) 2015/10/02 16:37:34 Done.
70 switches::kEnableBrowserSideNavigation)) {
71 bool sandboxed_frame = (sandbox_flags & blink::WebSandboxFlags::Origin) ==
72 blink::WebSandboxFlags::Origin;
73 if (sandboxed_frame)
74 return kInvalidServiceWorkerProviderId;
75 return g_next_navigation_provider_id--;
76 }
77 return kInvalidServiceWorkerProviderId;
78 }
79
53 } // namespace 80 } // namespace
54 81
55 // static 82 // static
56 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( 83 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
57 FrameTreeNode* frame_tree_node, 84 FrameTreeNode* frame_tree_node,
58 const GURL& dest_url, 85 const GURL& dest_url,
59 const Referrer& dest_referrer, 86 const Referrer& dest_referrer,
60 const FrameNavigationEntry& frame_entry, 87 const FrameNavigationEntry& frame_entry,
61 const NavigationEntryImpl& entry, 88 const NavigationEntryImpl& entry,
62 FrameMsg_Navigate_Type::Value navigation_type, 89 FrameMsg_Navigate_Type::Value navigation_type,
(...skipping 14 matching lines...) Expand all
77 // Fill POST data from the browser in the request body. 104 // Fill POST data from the browser in the request body.
78 scoped_refptr<ResourceRequestBody> request_body; 105 scoped_refptr<ResourceRequestBody> request_body;
79 if (entry.GetHasPostData()) { 106 if (entry.GetHasPostData()) {
80 request_body = new ResourceRequestBody(); 107 request_body = new ResourceRequestBody();
81 request_body->AppendBytes( 108 request_body->AppendBytes(
82 reinterpret_cast<const char *>( 109 reinterpret_cast<const char *>(
83 entry.GetBrowserInitiatedPostData()->front()), 110 entry.GetBrowserInitiatedPostData()->front()),
84 entry.GetBrowserInitiatedPostData()->size()); 111 entry.GetBrowserInitiatedPostData()->size());
85 } 112 }
86 113
114 blink::WebSandboxFlags sandbox_flags =
115 frame_tree_node->current_replication_state().sandbox_flags;
87 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( 116 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
88 frame_tree_node, 117 frame_tree_node,
89 entry.ConstructCommonNavigationParams(dest_url, dest_referrer, 118 entry.ConstructCommonNavigationParams(
90 frame_entry, navigation_type), 119 dest_url, dest_referrer, frame_entry, navigation_type),
91 BeginNavigationParams(method, headers.ToString(), 120 BeginNavigationParams(method,
92 LoadFlagFromNavigationType(navigation_type), false), 121 headers.ToString(),
122 LoadFlagFromNavigationType(navigation_type),
123 false, // has_user_gestures
124 false, // skip_service_worker
125 REQUEST_CONTEXT_TYPE_HYPERLINK),
93 entry.ConstructRequestNavigationParams( 126 entry.ConstructRequestNavigationParams(
94 frame_entry, navigation_start, is_same_document_history_load, 127 frame_entry, navigation_start, is_same_document_history_load,
95 frame_tree_node->has_committed_real_load(), 128 frame_tree_node->has_committed_real_load(),
96 controller->GetPendingEntryIndex() == -1, 129 controller->GetPendingEntryIndex() == -1,
97 controller->GetIndexOfEntry(&entry), 130 controller->GetIndexOfEntry(&entry),
98 controller->GetLastCommittedEntryIndex(), 131 controller->GetLastCommittedEntryIndex(),
99 controller->GetEntryCount()), 132 controller->GetEntryCount(),
133 GetNextNavigationProviderId(sandbox_flags)),
100 request_body, true, &frame_entry, &entry)); 134 request_body, true, &frame_entry, &entry));
101 return navigation_request.Pass(); 135 return navigation_request.Pass();
102 } 136 }
103 137
104 // static 138 // static
105 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 139 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
106 FrameTreeNode* frame_tree_node, 140 FrameTreeNode* frame_tree_node,
107 const CommonNavigationParams& common_params, 141 const CommonNavigationParams& common_params,
108 const BeginNavigationParams& begin_params, 142 const BeginNavigationParams& begin_params,
109 scoped_refptr<ResourceRequestBody> body, 143 scoped_refptr<ResourceRequestBody> body,
110 int current_history_list_offset, 144 int current_history_list_offset,
111 int current_history_list_length) { 145 int current_history_list_length) {
146 blink::WebSandboxFlags sandbox_flags =
147 frame_tree_node->current_replication_state().sandbox_flags;
148
112 // TODO(clamy): Check if some PageState should be provided here. 149 // TODO(clamy): Check if some PageState should be provided here.
113 // TODO(clamy): See how we should handle override of the user agent when the 150 // TODO(clamy): See how we should handle override of the user agent when the
114 // navigation may start in a renderer and commit in another one. 151 // navigation may start in a renderer and commit in another one.
115 // TODO(clamy): See if the navigation start time should be measured in the 152 // TODO(clamy): See if the navigation start time should be measured in the
116 // renderer and sent to the browser instead of being measured here. 153 // renderer and sent to the browser instead of being measured here.
117 // TODO(clamy): The pending history list offset should be properly set. 154 // TODO(clamy): The pending history list offset should be properly set.
118 // TODO(clamy): Set has_committed_real_load. 155 // TODO(clamy): Set has_committed_real_load.
119 RequestNavigationParams request_params; 156 RequestNavigationParams request_params(
120 request_params.current_history_list_offset = current_history_list_offset; 157 false, // is_overriding_user_agent
121 request_params.current_history_list_length = current_history_list_length; 158 base::TimeTicks::Now(), // browser_navigation_start
159 std::vector<GURL>(), // redirects
160 false, // can_load_local_resources
161 base::Time::Now(), // request_time
162 PageState(), // page_state
163 -1, // page_id
164 0, // nav_entry_id
165 false, // is_same_document_history_load
166 false, // has_committed_real_load
167 false, // intended_as_new_entry
168 -1, // pending_history_list_offset
169 current_history_list_offset,
170 current_history_list_length,
171 false, // should_clear_history_list
172 GetNextNavigationProviderId(sandbox_flags));
122 scoped_ptr<NavigationRequest> navigation_request( 173 scoped_ptr<NavigationRequest> navigation_request(
123 new NavigationRequest(frame_tree_node, common_params, begin_params, 174 new NavigationRequest(frame_tree_node, common_params, begin_params,
124 request_params, body, false, nullptr, nullptr)); 175 request_params, body, false, nullptr, nullptr));
125 return navigation_request.Pass(); 176 return navigation_request.Pass();
126 } 177 }
127 178
128 NavigationRequest::NavigationRequest( 179 NavigationRequest::NavigationRequest(
129 FrameTreeNode* frame_tree_node, 180 FrameTreeNode* frame_tree_node,
130 const CommonNavigationParams& common_params, 181 const CommonNavigationParams& common_params,
131 const BeginNavigationParams& begin_params, 182 const BeginNavigationParams& begin_params,
(...skipping 29 matching lines...) Expand all
161 212
162 const GURL& first_party_for_cookies = 213 const GURL& first_party_for_cookies =
163 frame_tree_node->IsMainFrame() 214 frame_tree_node->IsMainFrame()
164 ? common_params.url 215 ? common_params.url
165 : frame_tree_node->frame_tree()->root()->current_url(); 216 : frame_tree_node->frame_tree()->root()->current_url();
166 bool parent_is_main_frame = !frame_tree_node->parent() ? 217 bool parent_is_main_frame = !frame_tree_node->parent() ?
167 false : frame_tree_node->parent()->IsMainFrame(); 218 false : frame_tree_node->parent()->IsMainFrame();
168 info_.reset(new NavigationRequestInfo( 219 info_.reset(new NavigationRequestInfo(
169 common_params, begin_params, first_party_for_cookies, 220 common_params, begin_params, first_party_for_cookies,
170 frame_tree_node->IsMainFrame(), parent_is_main_frame, 221 frame_tree_node->IsMainFrame(), parent_is_main_frame,
171 frame_tree_node->frame_tree_node_id(), body)); 222 frame_tree_node->frame_tree_node_id(),
223 request_params.service_worker_provider_id, body));
172 } 224 }
173 225
174 NavigationRequest::~NavigationRequest() { 226 NavigationRequest::~NavigationRequest() {
175 } 227 }
176 228
177 bool NavigationRequest::BeginNavigation() { 229 bool NavigationRequest::BeginNavigation() {
178 DCHECK(!loader_); 230 DCHECK(!loader_);
179 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 231 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
180 state_ = STARTED; 232 state_ = STARTED;
181 233
(...skipping 24 matching lines...) Expand all
206 frame_tree_node_->navigator()->CommitNavigation( 258 frame_tree_node_->navigator()->CommitNavigation(
207 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); 259 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>());
208 return false; 260 return false;
209 261
210 // TODO(davidben): Fire (and add as necessary) observer methods such as 262 // TODO(davidben): Fire (and add as necessary) observer methods such as
211 // DidStartProvisionalLoadForFrame for the navigation. 263 // DidStartProvisionalLoadForFrame for the navigation.
212 } 264 }
213 265
214 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { 266 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) {
215 navigation_handle_ = NavigationHandleImpl::Create( 267 navigation_handle_ = NavigationHandleImpl::Create(
216 common_params_.url, frame_tree_node_->IsMainFrame(), delegate); 268 common_params_.url, frame_tree_node_->IsMainFrame(), delegate,
269 request_params_.service_worker_provider_id);
217 } 270 }
218 271
219 void NavigationRequest::TransferNavigationHandleOwnership( 272 void NavigationRequest::TransferNavigationHandleOwnership(
220 RenderFrameHostImpl* render_frame_host) { 273 RenderFrameHostImpl* render_frame_host) {
221 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); 274 render_frame_host->SetNavigationHandle(navigation_handle_.Pass());
222 render_frame_host->navigation_handle()->ReadyToCommitNavigation( 275 render_frame_host->navigation_handle()->ReadyToCommitNavigation(
223 render_frame_host); 276 render_frame_host);
224 } 277 }
225 278
226 void NavigationRequest::OnRequestRedirected( 279 void NavigationRequest::OnRequestRedirected(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 frame_tree_node_->navigator()->FailedNavigation( 319 frame_tree_node_->navigator()->FailedNavigation(
267 frame_tree_node_, has_stale_copy_in_cache, net_error); 320 frame_tree_node_, has_stale_copy_in_cache, net_error);
268 } 321 }
269 322
270 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 323 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
271 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 324 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
272 common_params_.url); 325 common_params_.url);
273 } 326 }
274 327
275 } // namespace content 328 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698