Commit fbe8587f authored by Mohamed Abdelhalim's avatar Mohamed Abdelhalim Committed by Commit Bot

Navigation: Remove NavigationHandleImpl usages 4.

This is the 4th CL of multiple CLs to remove the usages of
NavigationHandleImpl completely and replace it with NavigationRequest.

This CL includes removing usages of functions of NavigationHandleImpl
from NavigationSimulatorImpl, and replacing them with functions of
NavigationRequest.

Bug: 995268
Change-Id: I4a538610cd78b7e6e8c207900318a35310d3fc4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807113
Commit-Queue: Mohamed Abdelhalim <zetamoo@chromium.org>
Reviewed-by: default avatarLowell Manners <lowell@chromium.org>
Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697581}
parent cef3357d
......@@ -368,38 +368,37 @@ void NavigationSimulatorImpl::InitializeFromStartedRequest(
NavigationRequest* request) {
CHECK(request);
request_ = request;
NavigationHandleImpl* handle = request_->navigation_handle();
CHECK(handle);
CHECK(request->navigation_handle());
CHECK_LE(NavigationRequest::STARTED, request_->state());
CHECK_EQ(web_contents_, handle->GetWebContents());
CHECK_EQ(web_contents_, request_->GetDelegate());
CHECK(render_frame_host_);
CHECK_EQ(frame_tree_node_, request_->frame_tree_node());
state_ = STARTED;
original_url_ = request->commit_params().original_url;
navigation_url_ = handle->GetURL();
navigation_url_ = request_->GetURL();
// |remote_endpoint_| cannot be inferred from the request.
// |initial_method_| cannot be set after the request has started.
browser_initiated_ = request_->browser_initiated();
// |same_document_| should always be false here.
referrer_ = request_->common_params().referrer.Clone();
transition_ = handle->GetPageTransition();
transition_ = request_->GetPageTransition();
// |reload_type_| cannot be set after the request has started.
// |session_history_offset_| cannot be set after the request has started.
has_user_gesture_ = handle->HasUserGesture();
has_user_gesture_ = request_->HasUserGesture();
// |contents_mime_type_| cannot be inferred from the request.
// Add a throttle to count NavigationThrottle calls count. Bump
// num_did_start_navigation to account for the fact that the navigation handle
// has already been created.
num_did_start_navigation_called_++;
RegisterTestThrottle(handle);
RegisterTestThrottle(request);
PrepareCompleteCallbackOnRequest();
}
void NavigationSimulatorImpl::RegisterTestThrottle(NavigationHandle* handle) {
handle->RegisterThrottleForTesting(
void NavigationSimulatorImpl::RegisterTestThrottle(NavigationRequest* request) {
request->RegisterThrottleForTesting(
std::make_unique<NavigationThrottleCallbackRunner>(
handle,
request->navigation_handle(),
base::BindOnce(&NavigationSimulatorImpl::OnWillStartRequest,
weak_factory_.GetWeakPtr()),
base::BindRepeating(&NavigationSimulatorImpl::OnWillRedirectRequest,
......@@ -568,13 +567,12 @@ void NavigationSimulatorImpl::ReadyToCommitComplete(bool ran_throttles) {
CHECK_EQ(1, num_ready_to_commit_called_);
}
NavigationHandleImpl* handle = request_->navigation_handle();
request_id_ = handle->GetGlobalRequestID();
request_id_ = request_->GetGlobalRequestID();
// Update the RenderFrameHost now that we know which RenderFrameHost will
// commit the navigation.
render_frame_host_ =
static_cast<TestRenderFrameHost*>(handle->GetRenderFrameHost());
static_cast<TestRenderFrameHost*>(request_->GetRenderFrameHost());
state_ = READY_TO_COMMIT;
}
......@@ -724,8 +722,8 @@ void NavigationSimulatorImpl::FailComplete(int error_code) {
CHECK_EQ(0, num_did_finish_navigation_called_);
// Update the RenderFrameHost now that we know which RenderFrameHost will
// commit the error page.
render_frame_host_ = static_cast<TestRenderFrameHost*>(
request_->navigation_handle()->GetRenderFrameHost());
render_frame_host_ =
static_cast<TestRenderFrameHost*>(request_->GetRenderFrameHost());
}
}
......@@ -988,17 +986,16 @@ void NavigationSimulatorImpl::DidStartNavigation(
if (request_)
return;
NavigationHandleImpl* handle =
static_cast<NavigationHandleImpl*>(navigation_handle);
NavigationRequest* request = NavigationRequest::From(navigation_handle);
if (handle->frame_tree_node() != frame_tree_node_)
if (request->frame_tree_node() != frame_tree_node_)
return;
request_ = handle->navigation_request();
request_ = request;
num_did_start_navigation_called_++;
// Add a throttle to count NavigationThrottle calls count.
RegisterTestThrottle(handle);
RegisterTestThrottle(request);
PrepareCompleteCallbackOnRequest();
}
......@@ -1016,9 +1013,7 @@ void NavigationSimulatorImpl::ReadyToCommitNavigation(
void NavigationSimulatorImpl::DidFinishNavigation(
NavigationHandle* navigation_handle) {
NavigationRequest* request =
static_cast<NavigationHandleImpl*>(navigation_handle)
->navigation_request();
NavigationRequest* request = NavigationRequest::From(navigation_handle);
if (request == request_) {
num_did_finish_navigation_called_++;
request_ = nullptr;
......@@ -1089,7 +1084,7 @@ bool NavigationSimulatorImpl::SimulateBrowserInitiatedStart() {
web_contents_->GetMainFrame()
->same_document_navigation_request()
->navigation_handle() == request_->navigation_handle()) {
CHECK(request_->navigation_handle()->IsSameDocument());
CHECK(request_->IsSameDocument());
same_document_ = true;
return true;
}
......
......@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/optional.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/browser/frame_host/navigation_request.h"
#include "content/common/content_security_policy/csp_disposition_enum.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_throttle.h"
......@@ -171,9 +172,9 @@ class NavigationSimulatorImpl : public NavigationSimulator,
WebContentsImpl* web_contents,
TestRenderFrameHost* render_frame_host);
// Adds a test navigation throttle to |handle| which sanity checks various
// Adds a test navigation throttle to |request| which sanity checks various
// callbacks have been properly called.
void RegisterTestThrottle(NavigationHandle* handle);
void RegisterTestThrottle(NavigationRequest* request);
// Initializes a NavigationSimulator from an existing NavigationRequest. This
// should only be needed if a navigation was started without a valid
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment