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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/navigation_request.cc
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
index 34647b93f93e788ec9e81f797a86526d1bdf3da4..2a9f6277c47f25b5da834357e38b31a04110d12e 100644
--- a/content/browser/frame_host/navigation_request.cc
+++ b/content/browser/frame_host/navigation_request.cc
@@ -4,6 +4,7 @@
#include "content/browser/frame_host/navigation_request.h"
+#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/navigation_request_info.h"
#include "content/browser/frame_host/navigator.h"
@@ -12,16 +13,68 @@
#include "content/common/resource_request_body.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/stream_handle.h"
+#include "content/public/common/content_client.h"
+#include "net/base/load_flags.h"
+#include "net/http/http_request_headers.h"
#include "net/url_request/redirect_info.h"
namespace content {
+namespace {
+
+// Returns the net load flags to use based on the navigation type.
+// TODO(clamy): unify the code with what is happening on the renderer side.
+int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) {
+ int load_flags = net::LOAD_NORMAL;
+ switch (navigation_type) {
+ case FrameMsg_Navigate_Type::RELOAD:
+ case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL:
+ load_flags |= net::LOAD_VALIDATE_CACHE;
+ break;
+ case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE:
+ load_flags |= net::LOAD_BYPASS_CACHE;
+ break;
+ case FrameMsg_Navigate_Type::RESTORE:
+ load_flags |= net::LOAD_PREFERRING_CACHE;
+ break;
+ case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
+ load_flags |= net::LOAD_ONLY_FROM_CACHE;
+ break;
+ case FrameMsg_Navigate_Type::NORMAL:
+ default:
+ break;
+ }
+ return load_flags;
+}
+
+} // namespace
+
// static
-scoped_ptr<NavigationRequest> NavigationRequest::Create(
+scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
FrameTreeNode* frame_tree_node,
const NavigationEntryImpl& entry,
FrameMsg_Navigate_Type::Value navigation_type,
base::TimeTicks navigation_start) {
+ std::string method = entry.GetHasPostData() ? "POST" : "GET";
+
+ // Copy existing headers and add necessary headers that may not be present
+ // in the RequestNavigationParams.
+ net::HttpRequestHeaders headers;
+ headers.AddHeadersFromString(entry.extra_headers());
+ headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
+ GetContentClient()->GetUserAgent());
+ 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
+
+ // Fill POST data from the browser in the request body.
+ scoped_refptr<ResourceRequestBody> request_body;
+ if (entry.GetHasPostData()) {
+ request_body = new ResourceRequestBody();
+ request_body->AppendBytes(
+ reinterpret_cast<const char *>(
+ entry.GetBrowserInitiatedPostData()->front()),
+ entry.GetBrowserInitiatedPostData()->size());
+ }
+
FrameMsg_UILoadMetricsReportType::Value report_type =
FrameMsg_UILoadMetricsReportType::NO_REPORT;
base::TimeTicks ui_timestamp = base::TimeTicks();
@@ -37,21 +90,47 @@ scoped_ptr<NavigationRequest> NavigationRequest::Create(
entry.GetTransitionType(), navigation_type,
!entry.IsViewSourceMode(),ui_timestamp,
report_type),
+ BeginNavigationParams(method, headers.ToString(),
+ LoadFlagFromNavigationType(navigation_type),
+ false),
CommitNavigationParams(entry.GetPageState(),
entry.GetIsOverridingUserAgent(),
navigation_start),
- &entry));
+ request_body, true, &entry));
+ return navigation_request.Pass();
+}
+
+// static
+scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
+ FrameTreeNode* frame_tree_node,
+ const CommonNavigationParams& common_params,
+ const BeginNavigationParams& begin_params,
+ scoped_refptr<ResourceRequestBody> body) {
+ // TODO(clamy): Check if some PageState should be provided here.
+ // TODO(clamy): See how we should handle override of the user agent when the
+ // navigation may start in a renderer and commit in another one.
+ // TODO(clamy): See if the navigation start time should be measured in the
+ // renderer and sent to the browser instead of being measured here.
+ scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
+ frame_tree_node, common_params, begin_params,
+ CommitNavigationParams(PageState(), false, base::TimeTicks::Now()),
+ body, false, nullptr));
return navigation_request.Pass();
}
NavigationRequest::NavigationRequest(
FrameTreeNode* frame_tree_node,
const CommonNavigationParams& common_params,
+ const BeginNavigationParams& begin_params,
const CommitNavigationParams& commit_params,
+ scoped_refptr<ResourceRequestBody> body,
+ bool browser_initiated,
const NavigationEntryImpl* entry)
: frame_tree_node_(frame_tree_node),
common_params_(common_params),
+ begin_params_(begin_params),
commit_params_(commit_params),
+ browser_initiated_(browser_initiated),
state_(NOT_STARTED),
restore_type_(NavigationEntryImpl::RESTORE_NONE),
is_view_source_(false),
@@ -63,21 +142,29 @@ NavigationRequest::NavigationRequest(
is_view_source_ = entry->IsViewSourceMode();
bindings_ = entry->bindings();
}
+
+ const GURL& first_party_for_cookies =
+ frame_tree_node->IsMainFrame()
+ ? common_params.url
+ : frame_tree_node->frame_tree()->root()->current_url();
+ bool parent_is_main_frame = !frame_tree_node->parent() ?
+ false : frame_tree_node->parent()->IsMainFrame();
+ info_.reset(new NavigationRequestInfo(
+ begin_params, first_party_for_cookies,
+ frame_tree_node->IsMainFrame(), parent_is_main_frame, body));
}
NavigationRequest::~NavigationRequest() {
}
-void NavigationRequest::BeginNavigation(
- scoped_ptr<NavigationRequestInfo> info,
- scoped_refptr<ResourceRequestBody> request_body) {
+void NavigationRequest::BeginNavigation() {
DCHECK(!loader_);
DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
state_ = STARTED;
loader_ = NavigationURLLoader::Create(
frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
- frame_tree_node_->frame_tree_node_id(), common_params_, info.Pass(),
- request_body.get(), this);
+ frame_tree_node_->frame_tree_node_id(), common_params_, info_.Pass(),
+ this);
// TODO(davidben): Fire (and add as necessary) observer methods such as
// DidStartProvisionalLoadForFrame for the navigation.

Powered by Google App Engine
This is Rietveld 408576698