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

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: Review comments 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 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps
58 // going down.
59 int g_next_navigation_provider_id = -2;
60
61 // Returns the next ServiceWorkerProviderHost ID for navigations.
62 // Returns kInvalidServiceWorkerProviderId if sandbox_flags indicates a
nasko 2015/10/02 22:09:45 nit: Reflow this comment as a single sentence: Ret
Fabrice (no longer in Chrome) 2015/10/06 17:21:37 Done.
63 // sandboxed frame.
64 int GetNextNavigationProviderId(blink::WebSandboxFlags sandbox_flags) {
65 bool sandboxed_frame = (sandbox_flags & blink::WebSandboxFlags::Origin) ==
66 blink::WebSandboxFlags::Origin;
67 if (sandboxed_frame)
nasko 2015/10/02 22:09:45 Why use a full boolean variable instead of checkin
Fabrice (no longer in Chrome) 2015/10/06 17:21:37 Thought it was a bit clearer but I changed it.
68 return kInvalidServiceWorkerProviderId;
69 return g_next_navigation_provider_id--;
70 }
71
53 } // namespace 72 } // namespace
54 73
55 // static 74 // static
56 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( 75 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
57 FrameTreeNode* frame_tree_node, 76 FrameTreeNode* frame_tree_node,
58 const GURL& dest_url, 77 const GURL& dest_url,
59 const Referrer& dest_referrer, 78 const Referrer& dest_referrer,
60 const FrameNavigationEntry& frame_entry, 79 const FrameNavigationEntry& frame_entry,
61 const NavigationEntryImpl& entry, 80 const NavigationEntryImpl& entry,
62 FrameMsg_Navigate_Type::Value navigation_type, 81 FrameMsg_Navigate_Type::Value navigation_type,
(...skipping 19 matching lines...) Expand all
82 reinterpret_cast<const char *>( 101 reinterpret_cast<const char *>(
83 entry.GetBrowserInitiatedPostData()->front()), 102 entry.GetBrowserInitiatedPostData()->front()),
84 entry.GetBrowserInitiatedPostData()->size()); 103 entry.GetBrowserInitiatedPostData()->size());
85 } 104 }
86 105
87 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( 106 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
88 frame_tree_node, 107 frame_tree_node,
89 entry.ConstructCommonNavigationParams(dest_url, dest_referrer, 108 entry.ConstructCommonNavigationParams(dest_url, dest_referrer,
90 frame_entry, navigation_type), 109 frame_entry, navigation_type),
91 BeginNavigationParams(method, headers.ToString(), 110 BeginNavigationParams(method, headers.ToString(),
92 LoadFlagFromNavigationType(navigation_type), false), 111 LoadFlagFromNavigationType(navigation_type),
112 false, // has_user_gestures
113 false, // skip_service_worker
114 REQUEST_CONTEXT_TYPE_HYPERLINK),
93 entry.ConstructRequestNavigationParams( 115 entry.ConstructRequestNavigationParams(
94 frame_entry, navigation_start, is_same_document_history_load, 116 frame_entry, navigation_start, is_same_document_history_load,
95 frame_tree_node->has_committed_real_load(), 117 frame_tree_node->has_committed_real_load(),
96 controller->GetPendingEntryIndex() == -1, 118 controller->GetPendingEntryIndex() == -1,
97 controller->GetIndexOfEntry(&entry), 119 controller->GetIndexOfEntry(&entry),
98 controller->GetLastCommittedEntryIndex(), 120 controller->GetLastCommittedEntryIndex(),
99 controller->GetEntryCount()), 121 controller->GetEntryCount()),
100 request_body, true, &frame_entry, &entry)); 122 request_body, true, &frame_entry, &entry));
101 return navigation_request.Pass(); 123 return navigation_request.Pass();
102 } 124 }
103 125
104 // static 126 // static
105 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 127 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
106 FrameTreeNode* frame_tree_node, 128 FrameTreeNode* frame_tree_node,
107 const CommonNavigationParams& common_params, 129 const CommonNavigationParams& common_params,
108 const BeginNavigationParams& begin_params, 130 const BeginNavigationParams& begin_params,
109 scoped_refptr<ResourceRequestBody> body, 131 scoped_refptr<ResourceRequestBody> body,
110 int current_history_list_offset, 132 int current_history_list_offset,
111 int current_history_list_length) { 133 int current_history_list_length) {
112 // TODO(clamy): Check if some PageState should be provided here. 134 // 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 135 // 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. 136 // 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 137 // 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. 138 // renderer and sent to the browser instead of being measured here.
117 // TODO(clamy): The pending history list offset should be properly set. 139 // TODO(clamy): The pending history list offset should be properly set.
118 // TODO(clamy): Set has_committed_real_load. 140 // TODO(clamy): Set has_committed_real_load.
119 RequestNavigationParams request_params; 141 RequestNavigationParams request_params(
120 request_params.current_history_list_offset = current_history_list_offset; 142 false, // is_overriding_user_agent
121 request_params.current_history_list_length = current_history_list_length; 143 base::TimeTicks::Now(), // browser_navigation_start
144 std::vector<GURL>(), // redirects
145 false, // can_load_local_resources
146 base::Time::Now(), // request_time
147 PageState(), // page_state
148 -1, // page_id
149 0, // nav_entry_id
150 false, // is_same_document_history_load
151 false, // has_committed_real_load
152 false, // intended_as_new_entry
153 -1, // pending_history_list_offset
154 current_history_list_offset, current_history_list_length,
155 false); // should_clear_history_list
nasko 2015/10/02 22:09:45 nit: align this comment vertically with the rest a
Fabrice (no longer in Chrome) 2015/10/06 17:21:38 Done in the other patch.
122 scoped_ptr<NavigationRequest> navigation_request( 156 scoped_ptr<NavigationRequest> navigation_request(
123 new NavigationRequest(frame_tree_node, common_params, begin_params, 157 new NavigationRequest(frame_tree_node, common_params, begin_params,
124 request_params, body, false, nullptr, nullptr)); 158 request_params, body, false, nullptr, nullptr));
125 return navigation_request.Pass(); 159 return navigation_request.Pass();
126 } 160 }
127 161
128 NavigationRequest::NavigationRequest( 162 NavigationRequest::NavigationRequest(
129 FrameTreeNode* frame_tree_node, 163 FrameTreeNode* frame_tree_node,
130 const CommonNavigationParams& common_params, 164 const CommonNavigationParams& common_params,
131 const BeginNavigationParams& begin_params, 165 const BeginNavigationParams& begin_params,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 Referrer::SanitizeForRequest(common_params_.url, 221 Referrer::SanitizeForRequest(common_params_.url,
188 common_params_.referrer), 222 common_params_.referrer),
189 begin_params_.has_user_gesture, common_params_.transition, false); 223 begin_params_.has_user_gesture, common_params_.transition, false);
190 224
191 // Abort the request if needed. This will destroy the NavigationRequest. 225 // Abort the request if needed. This will destroy the NavigationRequest.
192 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { 226 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
193 frame_tree_node_->ResetNavigationRequest(false); 227 frame_tree_node_->ResetNavigationRequest(false);
194 return false; 228 return false;
195 } 229 }
196 230
231 // Initialize the service_worker_provider_id here.
232 blink::WebSandboxFlags sandbox_flags =
233 frame_tree_node_->current_replication_state().sandbox_flags;
234 int service_worker_provider_id = GetNextNavigationProviderId(sandbox_flags);
235
236 info_->service_worker_provider_id = service_worker_provider_id;
237 request_params_.service_worker_provider_id = service_worker_provider_id;
238 navigation_handle_->set_service_worker_provider_id(
239 service_worker_provider_id);
240
197 loader_ = NavigationURLLoader::Create( 241 loader_ = NavigationURLLoader::Create(
198 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 242 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
199 info_.Pass(), this); 243 info_.Pass(), this);
200 return true; 244 return true;
201 } 245 }
202 246
203 // There is no need to make a network request for this navigation, so commit 247 // There is no need to make a network request for this navigation, so commit
204 // it immediately. 248 // it immediately.
205 state_ = RESPONSE_STARTED; 249 state_ = RESPONSE_STARTED;
206 frame_tree_node_->navigator()->CommitNavigation( 250 frame_tree_node_->navigator()->CommitNavigation(
207 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); 251 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>());
208 return false; 252 return false;
209 253
210 // TODO(davidben): Fire (and add as necessary) observer methods such as 254 // TODO(davidben): Fire (and add as necessary) observer methods such as
211 // DidStartProvisionalLoadForFrame for the navigation. 255 // DidStartProvisionalLoadForFrame for the navigation.
212 } 256 }
213 257
214 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { 258 void NavigationRequest::CreateNavigationHandle() {
215 navigation_handle_ = NavigationHandleImpl::Create( 259 navigation_handle_ = NavigationHandleImpl::Create(
216 common_params_.url, frame_tree_node_->IsMainFrame(), delegate); 260 common_params_.url, frame_tree_node_->IsMainFrame(), frame_tree_node_);
217 } 261 }
218 262
219 void NavigationRequest::TransferNavigationHandleOwnership( 263 void NavigationRequest::TransferNavigationHandleOwnership(
220 RenderFrameHostImpl* render_frame_host) { 264 RenderFrameHostImpl* render_frame_host) {
221 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); 265 render_frame_host->SetNavigationHandle(navigation_handle_.Pass());
222 render_frame_host->navigation_handle()->ReadyToCommitNavigation( 266 render_frame_host->navigation_handle()->ReadyToCommitNavigation(
223 render_frame_host); 267 render_frame_host);
224 } 268 }
225 269
226 void NavigationRequest::OnRequestRedirected( 270 void NavigationRequest::OnRequestRedirected(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 frame_tree_node_->navigator()->FailedNavigation( 310 frame_tree_node_->navigator()->FailedNavigation(
267 frame_tree_node_, has_stale_copy_in_cache, net_error); 311 frame_tree_node_, has_stale_copy_in_cache, net_error);
268 } 312 }
269 313
270 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 314 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
271 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 315 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
272 common_params_.url); 316 common_params_.url);
273 } 317 }
274 318
275 } // namespace content 319 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698