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

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: 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 headers.SetHeaderIfMissing("Accept", "*/*");
davidben 2015/02/03 02:23:20 This is the in the old code too, but Blink's defau
clamy 2015/02/03 16:17:09 Yeah we were missing a TODO to match what blink is
67
68 // Fill POST data from the browser in the request body.
69 scoped_refptr<ResourceRequestBody> request_body;
70 if (entry.GetHasPostData()) {
71 request_body = new ResourceRequestBody();
72 request_body->AppendBytes(
73 reinterpret_cast<const char *>(
74 entry.GetBrowserInitiatedPostData()->front()),
75 entry.GetBrowserInitiatedPostData()->size());
76 }
77
25 FrameMsg_UILoadMetricsReportType::Value report_type = 78 FrameMsg_UILoadMetricsReportType::Value report_type =
26 FrameMsg_UILoadMetricsReportType::NO_REPORT; 79 FrameMsg_UILoadMetricsReportType::NO_REPORT;
27 base::TimeTicks ui_timestamp = base::TimeTicks(); 80 base::TimeTicks ui_timestamp = base::TimeTicks();
28 #if defined(OS_ANDROID) 81 #if defined(OS_ANDROID)
29 if (!entry.intent_received_timestamp().is_null()) 82 if (!entry.intent_received_timestamp().is_null())
30 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; 83 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT;
31 ui_timestamp = entry.intent_received_timestamp(); 84 ui_timestamp = entry.intent_received_timestamp();
32 #endif 85 #endif
33 86
34 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( 87 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
35 frame_tree_node, 88 frame_tree_node,
36 CommonNavigationParams(entry.GetURL(), entry.GetReferrer(), 89 CommonNavigationParams(entry.GetURL(), entry.GetReferrer(),
37 entry.GetTransitionType(), navigation_type, 90 entry.GetTransitionType(), navigation_type,
38 !entry.IsViewSourceMode(),ui_timestamp, 91 !entry.IsViewSourceMode(),ui_timestamp,
39 report_type), 92 report_type),
93 BeginNavigationParams(method, headers.ToString(),
94 LoadFlagFromNavigationType(navigation_type),
95 false),
40 CommitNavigationParams(entry.GetPageState(), 96 CommitNavigationParams(entry.GetPageState(),
41 entry.GetIsOverridingUserAgent(), 97 entry.GetIsOverridingUserAgent(),
42 navigation_start), 98 navigation_start),
43 &entry)); 99 request_body, true, &entry));
100 return navigation_request.Pass();
101 }
102
103 // static
104 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
105 FrameTreeNode* frame_tree_node,
106 const CommonNavigationParams& common_params,
107 const BeginNavigationParams& begin_params,
108 scoped_refptr<ResourceRequestBody> body) {
109 // TODO(clamy): Check if some PageState should be provided here.
110 // TODO(clamy): See how we should handle override of the user agent when the
111 // navigation may start in a renderer and commit in another one.
112 // TODO(clamy): See if the navigation start time should be measured in the
113 // renderer and sent to the browser instead of being measured here.
114 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
115 frame_tree_node, common_params, begin_params,
116 CommitNavigationParams(PageState(), false, base::TimeTicks::Now()),
117 body, false, nullptr));
44 return navigation_request.Pass(); 118 return navigation_request.Pass();
45 } 119 }
46 120
47 NavigationRequest::NavigationRequest( 121 NavigationRequest::NavigationRequest(
48 FrameTreeNode* frame_tree_node, 122 FrameTreeNode* frame_tree_node,
49 const CommonNavigationParams& common_params, 123 const CommonNavigationParams& common_params,
124 const BeginNavigationParams& begin_params,
50 const CommitNavigationParams& commit_params, 125 const CommitNavigationParams& commit_params,
126 scoped_refptr<ResourceRequestBody> body,
127 bool browser_initiated,
51 const NavigationEntryImpl* entry) 128 const NavigationEntryImpl* entry)
52 : frame_tree_node_(frame_tree_node), 129 : frame_tree_node_(frame_tree_node),
53 common_params_(common_params), 130 common_params_(common_params),
131 begin_params_(begin_params),
54 commit_params_(commit_params), 132 commit_params_(commit_params),
133 browser_initiated_(browser_initiated),
55 state_(NOT_STARTED), 134 state_(NOT_STARTED),
56 restore_type_(NavigationEntryImpl::RESTORE_NONE), 135 restore_type_(NavigationEntryImpl::RESTORE_NONE),
57 is_view_source_(false), 136 is_view_source_(false),
58 bindings_(NavigationEntryImpl::kInvalidBindings) { 137 bindings_(NavigationEntryImpl::kInvalidBindings) {
59 if (entry) { 138 if (entry) {
60 source_site_instance_ = entry->source_site_instance(); 139 source_site_instance_ = entry->source_site_instance();
61 dest_site_instance_ = entry->site_instance(); 140 dest_site_instance_ = entry->site_instance();
62 restore_type_ = entry->restore_type(); 141 restore_type_ = entry->restore_type();
63 is_view_source_ = entry->IsViewSourceMode(); 142 is_view_source_ = entry->IsViewSourceMode();
64 bindings_ = entry->bindings(); 143 bindings_ = entry->bindings();
65 } 144 }
145
146 const GURL& first_party_for_cookies =
147 frame_tree_node->IsMainFrame()
148 ? common_params.url
149 : frame_tree_node->frame_tree()->root()->current_url();
150 bool parent_is_main_frame = !frame_tree_node->parent() ?
151 false : frame_tree_node->parent()->IsMainFrame();
152 info_.reset(new NavigationRequestInfo(
153 begin_params, first_party_for_cookies,
154 frame_tree_node->IsMainFrame(), parent_is_main_frame, body));
66 } 155 }
67 156
68 NavigationRequest::~NavigationRequest() { 157 NavigationRequest::~NavigationRequest() {
69 } 158 }
70 159
71 void NavigationRequest::BeginNavigation( 160 void NavigationRequest::BeginNavigation() {
72 scoped_ptr<NavigationRequestInfo> info,
73 scoped_refptr<ResourceRequestBody> request_body) {
74 DCHECK(!loader_); 161 DCHECK(!loader_);
75 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 162 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
76 state_ = STARTED; 163 state_ = STARTED;
77 loader_ = NavigationURLLoader::Create( 164 loader_ = NavigationURLLoader::Create(
78 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 165 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
79 frame_tree_node_->frame_tree_node_id(), common_params_, info.Pass(), 166 frame_tree_node_->frame_tree_node_id(), common_params_, info_.Pass(),
80 request_body.get(), this); 167 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 14 matching lines...) Expand all
105 } 192 }
106 193
107 void NavigationRequest::OnRequestFailed(int net_error) { 194 void NavigationRequest::OnRequestFailed(int net_error) {
108 DCHECK(state_ == STARTED); 195 DCHECK(state_ == STARTED);
109 state_ = FAILED; 196 state_ = FAILED;
110 // TODO(davidben): Network failures should display a network error page. 197 // TODO(davidben): Network failures should display a network error page.
111 NOTIMPLEMENTED(); 198 NOTIMPLEMENTED();
112 } 199 }
113 200
114 } // namespace content 201 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698