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

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

Issue 872473003: PlzNavigate: Remove the RequestNavigation IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits + fix compilation error Created 5 years, 10 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 "content/browser/frame_host/frame_tree.h"
7 #include "content/browser/frame_host/frame_tree_node.h" 8 #include "content/browser/frame_host/frame_tree_node.h"
8 #include "content/browser/frame_host/navigation_request_info.h" 9 #include "content/browser/frame_host/navigation_request_info.h"
9 #include "content/browser/frame_host/navigator.h" 10 #include "content/browser/frame_host/navigator.h"
10 #include "content/browser/loader/navigation_url_loader.h" 11 #include "content/browser/loader/navigation_url_loader.h"
11 #include "content/browser/site_instance_impl.h" 12 #include "content/browser/site_instance_impl.h"
12 #include "content/common/resource_request_body.h" 13 #include "content/common/resource_request_body.h"
13 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/stream_handle.h" 15 #include "content/public/browser/stream_handle.h"
16 #include "content/public/common/content_client.h"
17 #include "net/base/load_flags.h"
18 #include "net/http/http_request_headers.h"
15 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
16 20
17 namespace content { 21 namespace content {
18 22
23 namespace {
24
25 // Returns the net load flags to use based on the navigation type.
26 // TODO(clamy): unify the code with what is happening on the renderer side.
27 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) {
28 int load_flags = net::LOAD_NORMAL;
29 switch (navigation_type) {
30 case FrameMsg_Navigate_Type::RELOAD:
31 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
32 load_flags |= net::LOAD_VALIDATE_CACHE;
33 break;
34 case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE:
35 load_flags |= net::LOAD_BYPASS_CACHE;
36 break;
37 case FrameMsg_Navigate_Type::RESTORE:
38 load_flags |= net::LOAD_PREFERRING_CACHE;
39 break;
40 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
41 load_flags |= net::LOAD_ONLY_FROM_CACHE;
42 break;
43 case FrameMsg_Navigate_Type::NORMAL:
44 default:
45 break;
46 }
47 return load_flags;
48 }
49
50 } // namespace
51
19 // static 52 // static
20 scoped_ptr<NavigationRequest> NavigationRequest::Create( 53 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
21 FrameTreeNode* frame_tree_node, 54 FrameTreeNode* frame_tree_node,
22 const NavigationEntryImpl& entry, 55 const NavigationEntryImpl& entry,
23 FrameMsg_Navigate_Type::Value navigation_type, 56 FrameMsg_Navigate_Type::Value navigation_type,
24 base::TimeTicks navigation_start) { 57 base::TimeTicks navigation_start) {
58 std::string method = entry.GetHasPostData() ? "POST" : "GET";
59
60 // Copy existing headers and add necessary headers that may not be present
61 // in the RequestNavigationParams.
62 net::HttpRequestHeaders headers;
63 headers.AddHeadersFromString(entry.extra_headers());
64 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
65 GetContentClient()->GetUserAgent());
66 // TODO(clamy): match what blink is doing with accept headers.
67 headers.SetHeaderIfMissing("Accept", "*/*");
68
69 // Fill POST data from the browser in the request body.
70 scoped_refptr<ResourceRequestBody> request_body;
71 if (entry.GetHasPostData()) {
72 request_body = new ResourceRequestBody();
73 request_body->AppendBytes(
74 reinterpret_cast<const char *>(
75 entry.GetBrowserInitiatedPostData()->front()),
76 entry.GetBrowserInitiatedPostData()->size());
77 }
78
25 FrameMsg_UILoadMetricsReportType::Value report_type = 79 FrameMsg_UILoadMetricsReportType::Value report_type =
26 FrameMsg_UILoadMetricsReportType::NO_REPORT; 80 FrameMsg_UILoadMetricsReportType::NO_REPORT;
27 base::TimeTicks ui_timestamp = base::TimeTicks(); 81 base::TimeTicks ui_timestamp = base::TimeTicks();
28 #if defined(OS_ANDROID) 82 #if defined(OS_ANDROID)
29 if (!entry.intent_received_timestamp().is_null()) 83 if (!entry.intent_received_timestamp().is_null())
30 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; 84 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT;
31 ui_timestamp = entry.intent_received_timestamp(); 85 ui_timestamp = entry.intent_received_timestamp();
32 #endif 86 #endif
33 87
34 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( 88 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
35 frame_tree_node, 89 frame_tree_node,
36 CommonNavigationParams(entry.GetURL(), entry.GetReferrer(), 90 CommonNavigationParams(entry.GetURL(), entry.GetReferrer(),
37 entry.GetTransitionType(), navigation_type, 91 entry.GetTransitionType(), navigation_type,
38 !entry.IsViewSourceMode(),ui_timestamp, 92 !entry.IsViewSourceMode(),ui_timestamp,
39 report_type), 93 report_type),
94 BeginNavigationParams(method, headers.ToString(),
95 LoadFlagFromNavigationType(navigation_type),
96 false),
40 CommitNavigationParams(entry.GetPageState(), 97 CommitNavigationParams(entry.GetPageState(),
41 entry.GetIsOverridingUserAgent(), 98 entry.GetIsOverridingUserAgent(),
42 navigation_start), 99 navigation_start),
43 &entry)); 100 request_body, true, &entry));
101 return navigation_request.Pass();
102 }
103
104 // static
105 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
106 FrameTreeNode* frame_tree_node,
107 const CommonNavigationParams& common_params,
108 const BeginNavigationParams& begin_params,
109 scoped_refptr<ResourceRequestBody> body) {
110 // TODO(clamy): Check if some PageState should be provided here.
111 // TODO(clamy): See how we should handle override of the user agent when the
112 // navigation may start in a renderer and commit in another one.
113 // TODO(clamy): See if the navigation start time should be measured in the
114 // renderer and sent to the browser instead of being measured here.
115 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
116 frame_tree_node, common_params, begin_params,
117 CommitNavigationParams(PageState(), false, base::TimeTicks::Now()),
118 body, false, nullptr));
44 return navigation_request.Pass(); 119 return navigation_request.Pass();
45 } 120 }
46 121
47 NavigationRequest::NavigationRequest( 122 NavigationRequest::NavigationRequest(
48 FrameTreeNode* frame_tree_node, 123 FrameTreeNode* frame_tree_node,
49 const CommonNavigationParams& common_params, 124 const CommonNavigationParams& common_params,
125 const BeginNavigationParams& begin_params,
50 const CommitNavigationParams& commit_params, 126 const CommitNavigationParams& commit_params,
127 scoped_refptr<ResourceRequestBody> body,
128 bool browser_initiated,
51 const NavigationEntryImpl* entry) 129 const NavigationEntryImpl* entry)
52 : frame_tree_node_(frame_tree_node), 130 : frame_tree_node_(frame_tree_node),
53 common_params_(common_params), 131 common_params_(common_params),
132 begin_params_(begin_params),
54 commit_params_(commit_params), 133 commit_params_(commit_params),
134 browser_initiated_(browser_initiated),
55 state_(NOT_STARTED), 135 state_(NOT_STARTED),
56 restore_type_(NavigationEntryImpl::RESTORE_NONE), 136 restore_type_(NavigationEntryImpl::RESTORE_NONE),
57 is_view_source_(false), 137 is_view_source_(false),
58 bindings_(NavigationEntryImpl::kInvalidBindings) { 138 bindings_(NavigationEntryImpl::kInvalidBindings) {
59 if (entry) { 139 if (entry) {
60 source_site_instance_ = entry->source_site_instance(); 140 source_site_instance_ = entry->source_site_instance();
61 dest_site_instance_ = entry->site_instance(); 141 dest_site_instance_ = entry->site_instance();
62 restore_type_ = entry->restore_type(); 142 restore_type_ = entry->restore_type();
63 is_view_source_ = entry->IsViewSourceMode(); 143 is_view_source_ = entry->IsViewSourceMode();
64 bindings_ = entry->bindings(); 144 bindings_ = entry->bindings();
65 } 145 }
146
147 const GURL& first_party_for_cookies =
148 frame_tree_node->IsMainFrame()
149 ? common_params.url
150 : frame_tree_node->frame_tree()->root()->current_url();
151 bool parent_is_main_frame = !frame_tree_node->parent() ?
152 false : frame_tree_node->parent()->IsMainFrame();
153 info_.reset(new NavigationRequestInfo(
154 common_params, begin_params, first_party_for_cookies,
155 frame_tree_node->IsMainFrame(), parent_is_main_frame, body));
66 } 156 }
67 157
68 NavigationRequest::~NavigationRequest() { 158 NavigationRequest::~NavigationRequest() {
69 } 159 }
70 160
71 void NavigationRequest::BeginNavigation( 161 void NavigationRequest::BeginNavigation() {
72 scoped_ptr<NavigationRequestInfo> info,
73 scoped_refptr<ResourceRequestBody> request_body) {
74 DCHECK(!loader_); 162 DCHECK(!loader_);
75 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 163 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
76 state_ = STARTED; 164 state_ = STARTED;
77 loader_ = NavigationURLLoader::Create( 165 loader_ = NavigationURLLoader::Create(
78 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 166 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
79 frame_tree_node_->frame_tree_node_id(), common_params_, info.Pass(), 167 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this);
80 request_body.get(), this);
81 168
82 // TODO(davidben): Fire (and add as necessary) observer methods such as 169 // TODO(davidben): Fire (and add as necessary) observer methods such as
83 // DidStartProvisionalLoadForFrame for the navigation. 170 // DidStartProvisionalLoadForFrame for the navigation.
84 } 171 }
85 172
86 void NavigationRequest::OnRequestRedirected( 173 void NavigationRequest::OnRequestRedirected(
87 const net::RedirectInfo& redirect_info, 174 const net::RedirectInfo& redirect_info,
88 const scoped_refptr<ResourceResponse>& response) { 175 const scoped_refptr<ResourceResponse>& response) {
89 // TODO(davidben): Track other changes from redirects. These are important 176 // TODO(davidben): Track other changes from redirects. These are important
90 // for, e.g., reloads. 177 // for, e.g., reloads.
(...skipping 19 matching lines...) Expand all
110 // TODO(davidben): Network failures should display a network error page. 197 // TODO(davidben): Network failures should display a network error page.
111 NOTIMPLEMENTED() << " where net_error=" << net_error; 198 NOTIMPLEMENTED() << " where net_error=" << net_error;
112 } 199 }
113 200
114 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 201 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
115 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 202 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
116 common_params_.url); 203 common_params_.url);
117 } 204 }
118 205
119 } // namespace content 206 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigation_request_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698