Replace OpenURL usage in window.open() with LoadURLWithParams.
The current window.open() implementation on the browser side is using
OpenURL to navigate when the opener is suppressed (e.g. 'noopener') and
URL is specified. This results in the navigation being sent up to the
embedder and come back to content. Since the default parameters being
constructed should not cause the embedder to make any changes to the
navigation, it should be safe to skip the extra code and directly
navigate the new window.
This CL adds LoadURLParams storage to WebContentsImpl and implements
all navigations of window.open() that are started browser process side
to use NavigationController::LoadURLWithParams. It effectively
short-circuits the unnecessary trip to the embedder.
Bug: 882053
Change-Id: I09120397f3a6e7856e76ba0448d0bdff807f7628
Reviewed-on: https://chromium-review.googlesource.com/c/1286194
Commit-Queue: Nasko Oskov <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Cr-Commit-Position: refs/heads/master@{#601148}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 759c8f4a..9b4cad6 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2780,19 +2780,21 @@
}
if (!was_blocked) {
- OpenURLParams open_params(params.target_url, params.referrer,
- WindowOpenDisposition::CURRENT_TAB,
- ui::PAGE_TRANSITION_LINK,
- true /* is_renderer_initiated */);
- open_params.user_gesture = params.mimic_user_gesture;
+ std::unique_ptr<NavigationController::LoadURLParams> load_params =
+ std::make_unique<NavigationController::LoadURLParams>(
+ params.target_url);
+ load_params->referrer = params.referrer;
+ load_params->transition_type = ui::PAGE_TRANSITION_LINK;
+ load_params->is_renderer_initiated = true;
+ load_params->has_user_gesture = params.mimic_user_gesture;
if (delegate_ && !is_guest &&
!delegate_->ShouldResumeRequestsForCreatedWindow()) {
- // We are in asynchronous add new contents path, delay opening url
- new_contents_impl->delayed_open_url_params_.reset(
- new OpenURLParams(open_params));
+ // We are in asynchronous add new contents path, delay navigation.
+ DCHECK(!new_contents_impl->delayed_open_url_params_);
+ new_contents_impl->delayed_load_url_params_ = std::move(load_params);
} else {
- new_contents_impl->OpenURL(open_params);
+ new_contents_impl->controller_.LoadURLWithParams(*load_params.get());
}
}
}
@@ -3318,6 +3320,11 @@
// time, navigations, including the initial one, that goes through OpenURL
// should be delayed until embedder is ready to resume loading.
delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
+
+ // If there was a navigation deferred when creating the window through
+ // CreateNewWindow, drop it in favor of this navigation.
+ delayed_load_url_params_.reset();
+
return nullptr;
}
@@ -4069,6 +4076,13 @@
}
void WebContentsImpl::ResumeLoadingCreatedWebContents() {
+ if (delayed_load_url_params_.get()) {
+ DCHECK(!delayed_open_url_params_);
+ controller_.LoadURLWithParams(*delayed_load_url_params_.get());
+ delayed_load_url_params_.reset(nullptr);
+ return;
+ }
+
if (delayed_open_url_params_.get()) {
OpenURL(*delayed_open_url_params_.get());
delayed_open_url_params_.reset(nullptr);