Reland: Split the WebContentsDelegate::ShouldCreateWebContents API.
Orignal CL in:
https://chromium-review.googlesource.com/c/chromium/src/+/1824321
Prior CL blew up because:
https://bugs.chromium.org/p/chromium/issues/detail?id=1011283
Original Description:
Currently ShouldCreateWebContents() does 3 separate things
(1) Tells WebContentsImpl::CreateNewWindow() to suppress default
popup creation logic.
(2) Signals to the embedder that a window creation has been attempted
(3) Allows the embedder to signal back, via use of the global routing_id
maps, that a new WebContents has been created and needs partial
initialization inside the content layer.
This is super complex, especially since only one delegate uses (3).
The new API creates 2 functions:
bool IsWebContentsCreationOverridden()
WebContents* CreateCustomWebContents()
Breaking up the API makes it cleaner. If the WebContents initialization
logic can get changed to absorb the single odd use case in (3) then
CreateCustomWebContents() could be changed to have a void return type
making the API even simpler.
Bug: 545684
Change-Id: I894ae320b55fa410d6469ff07350f4a953952f6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846477
Auto-Submit: Albert J. Wong <[email protected]>
Commit-Queue: John Abd-El-Malek <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Cr-Commit-Position: refs/heads/master@{#703624}
diff --git a/chrome/browser/android/document/document_web_contents_delegate.cc b/chrome/browser/android/document/document_web_contents_delegate.cc
index 3b75d30..915de7aa 100644
--- a/chrome/browser/android/document/document_web_contents_delegate.cc
+++ b/chrome/browser/android/document/document_web_contents_delegate.cc
@@ -41,21 +41,14 @@
NOTREACHED();
}
-bool DocumentWebContentsDelegate::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool DocumentWebContentsDelegate::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
NOTREACHED();
- return false;
+ return true;
}
static jlong JNI_DocumentWebContentsDelegate_Initialize(
diff --git a/chrome/browser/android/document/document_web_contents_delegate.h b/chrome/browser/android/document/document_web_contents_delegate.h
index 2c3e345..e9b3d4ab9 100644
--- a/chrome/browser/android/document/document_web_contents_delegate.h
+++ b/chrome/browser/android/document/document_web_contents_delegate.h
@@ -36,19 +36,12 @@
bool user_gesture,
bool* was_blocked) override;
void CloseContents(content::WebContents* source) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override;
+ const GURL& target_url) override;
};
#endif // CHROME_BROWSER_ANDROID_DOCUMENT_DOCUMENT_WEB_CONTENTS_DELEGATE_H_
diff --git a/chrome/browser/background/background_contents.cc b/chrome/browser/background/background_contents.cc
index 76359b0..a4d5fcd8 100644
--- a/chrome/browser/background/background_contents.cc
+++ b/chrome/browser/background/background_contents.cc
@@ -32,9 +32,7 @@
BackgroundContents::BackgroundContents(
scoped_refptr<SiteInstance> site_instance,
content::RenderFrameHost* opener,
- int32_t routing_id,
- int32_t main_frame_routing_id,
- int32_t main_frame_widget_routing_id,
+ bool is_new_browsing_instance,
Delegate* delegate,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace)
@@ -49,11 +47,12 @@
opener ? opener->GetProcess()->GetID() : MSG_ROUTING_NONE;
create_params.opener_render_frame_id =
opener ? opener->GetRoutingID() : MSG_ROUTING_NONE;
- create_params.routing_id = routing_id;
- create_params.main_frame_routing_id = main_frame_routing_id;
- create_params.main_frame_widget_routing_id = main_frame_widget_routing_id;
- create_params.renderer_initiated_creation = routing_id != MSG_ROUTING_NONE;
create_params.is_never_visible = true;
+
+ // This isn't semantically sensible, but it is what the old code implicitly
+ // did.
+ create_params.renderer_initiated_creation = !is_new_browsing_instance;
+
if (session_storage_namespace) {
content::SessionStorageNamespaceMap session_storage_namespace_map;
session_storage_namespace_map.insert(
diff --git a/chrome/browser/background/background_contents.h b/chrome/browser/background/background_contents.h
index 552f9a25..c661e6e 100644
--- a/chrome/browser/background/background_contents.h
+++ b/chrome/browser/background/background_contents.h
@@ -62,9 +62,7 @@
BackgroundContents(
scoped_refptr<content::SiteInstance> site_instance,
content::RenderFrameHost* opener,
- int32_t routing_id,
- int32_t main_frame_routing_id,
- int32_t main_frame_widget_routing_id,
+ bool is_new_browsing_instance,
Delegate* delegate,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace);
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc
index eb11a0b..0689f2f 100644
--- a/chrome/browser/background/background_contents_service.cc
+++ b/chrome/browser/background/background_contents_service.cc
@@ -578,9 +578,8 @@
DVLOG(1) << "Loading background content url: " << url;
BackgroundContents* contents = CreateBackgroundContents(
- SiteInstance::CreateForURL(profile_, url), nullptr, MSG_ROUTING_NONE,
- MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name, application_id,
- std::string(), nullptr);
+ SiteInstance::CreateForURL(profile_, url), nullptr, true, frame_name,
+ application_id, std::string(), nullptr);
contents->CreateRenderViewSoon(url);
}
@@ -588,16 +587,13 @@
BackgroundContents* BackgroundContentsService::CreateBackgroundContents(
scoped_refptr<SiteInstance> site,
content::RenderFrameHost* opener,
- int32_t routing_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
+ bool is_new_browsing_instance,
const std::string& frame_name,
const std::string& application_id,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
auto contents = std::make_unique<BackgroundContents>(
- std::move(site), opener, routing_id, main_frame_route_id,
- main_frame_widget_route_id, this, partition_id,
+ std::move(site), opener, is_new_browsing_instance, this, partition_id,
session_storage_namespace);
BackgroundContents* contents_ptr = contents.get();
AddBackgroundContents(std::move(contents), application_id, frame_name);
diff --git a/chrome/browser/background/background_contents_service.h b/chrome/browser/background/background_contents_service.h
index bde2fc61..5fcfe86 100644
--- a/chrome/browser/background/background_contents_service.h
+++ b/chrome/browser/background/background_contents_service.h
@@ -117,15 +117,13 @@
const std::string& GetParentApplicationId(BackgroundContents* contents) const;
// Creates a new BackgroundContents using the passed |site| and
- // the |route_id| and begins tracking the object internally so it can be
- // shutdown if the parent application is uninstalled.
+ // begins tracking the object internally so it can be shutdown if the parent
+ // application is uninstalled.
// Observers will receive a OnBackgroundContentsOpened call.
BackgroundContents* CreateBackgroundContents(
scoped_refptr<content::SiteInstance> site,
content::RenderFrameHost* opener,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
+ bool is_new_browsing_instance,
const std::string& frame_name,
const std::string& application_id,
const std::string& partition_id,
diff --git a/chrome/browser/chromeos/first_run/drive_first_run_controller.cc b/chrome/browser/chromeos/first_run/drive_first_run_controller.cc
index 5162378..cb30bba 100644
--- a/chrome/browser/chromeos/first_run/drive_first_run_controller.cc
+++ b/chrome/browser/chromeos/first_run/drive_first_run_controller.cc
@@ -120,14 +120,16 @@
const base::string16& error_description) override;
// content::WebContentsDelegate overrides:
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
+ bool IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) override;
+ content::WebContents* CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
@@ -230,54 +232,54 @@
}
}
-bool DriveWebContentsManager::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool DriveWebContentsManager::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
if (window_container_type == content::mojom::WindowContainerType::NORMAL)
- return true;
+ return false;
// Check that the target URL is for the Drive app.
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile_)
->enabled_extensions().GetAppByURL(target_url);
- if (!extension || extension->id() != app_id_)
- return true;
+ return extension && extension->id() == app_id_;
+}
+
+content::WebContents* DriveWebContentsManager::CreateCustomWebContents(
+ content::RenderFrameHost* opener,
+ content::SiteInstance* source_site_instance,
+ bool is_new_browsing_instance,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url,
+ const std::string& partition_id,
+ content::SessionStorageNamespace* session_storage_namespace) {
// The background contents creation is normally done in Browser, but
// because we're using a detached WebContents, we need to do it ourselves.
BackgroundContentsService* background_contents_service =
BackgroundContentsServiceFactory::GetForProfile(profile_);
- // Prevent redirection if background contents already exists.
- if (background_contents_service->GetAppBackgroundContents(app_id_)) {
- return false;
+ // Only redirect if background contents does not yet exists.
+ if (!background_contents_service->GetAppBackgroundContents(app_id_)) {
+ // drive_first_run/app/manifest.json sets allow_js_access to false and
+ // therefore we are creating a new SiteInstance (and thus a new renderer
+ // process) here, so we must use MSG_ROUTING_NONE and we cannot pass the
+ // opener (similarly to how allow_js_access:false is handled in
+ // Browser::MaybeCreateBackgroundContents).
+ BackgroundContents* contents =
+ background_contents_service->CreateBackgroundContents(
+ content::SiteInstance::Create(profile_), nullptr, true, frame_name,
+ app_id_, partition_id, session_storage_namespace);
+ contents->web_contents()->GetController().LoadURL(
+ target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK,
+ std::string());
}
- // drive_first_run/app/manifest.json sets allow_js_access to false and
- // therefore we are creating a new SiteInstance (and thus a new renderer
- // process) here, so we must use MSG_ROUTING_NONE and we cannot pass the
- // opener (similarily to how allow_js_access:false is handled in
- // Browser::MaybeCreateBackgroundContents).
- BackgroundContents* contents =
- background_contents_service->CreateBackgroundContents(
- content::SiteInstance::Create(profile_), nullptr, MSG_ROUTING_NONE,
- MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name, app_id_, partition_id,
- session_storage_namespace);
- contents->web_contents()->GetController().LoadURL(
- target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
-
- // Return false as we already created the WebContents here.
- return false;
+ return nullptr;
}
void DriveWebContentsManager::OnBackgroundContentsOpened(
diff --git a/chrome/browser/chromeos/login/ui/login_web_dialog.cc b/chrome/browser/chromeos/login/ui/login_web_dialog.cc
index 406554f9..86bdbd0 100644
--- a/chrome/browser/chromeos/login/ui/login_web_dialog.cc
+++ b/chrome/browser/chromeos/login/ui/login_web_dialog.cc
@@ -164,8 +164,8 @@
return (source && !chrome::FindBrowserWithWebContents(source));
}
-bool LoginWebDialog::HandleShouldCreateWebContents() {
- return false;
+bool LoginWebDialog::HandleShouldOverrideWebContentsCreation() {
+ return true;
}
std::vector<ui::Accelerator> LoginWebDialog::GetAccelerators() {
diff --git a/chrome/browser/chromeos/login/ui/login_web_dialog.h b/chrome/browser/chromeos/login/ui/login_web_dialog.h
index 571ba7c..245cb63 100644
--- a/chrome/browser/chromeos/login/ui/login_web_dialog.h
+++ b/chrome/browser/chromeos/login/ui/login_web_dialog.h
@@ -81,7 +81,7 @@
bool HandleOpenURLFromTab(content::WebContents* source,
const content::OpenURLParams& params,
content::WebContents** out_new_contents) override;
- bool HandleShouldCreateWebContents() override;
+ bool HandleShouldOverrideWebContentsCreation() override;
std::vector<ui::Accelerator> GetAccelerators() override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
diff --git a/chrome/browser/media/offscreen_tab.cc b/chrome/browser/media/offscreen_tab.cc
index dd0e28e9..ea8024c 100644
--- a/chrome/browser/media/offscreen_tab.cc
+++ b/chrome/browser/media/offscreen_tab.cc
@@ -280,24 +280,16 @@
return false;
}
-bool OffscreenTab::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool OffscreenTab::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
- DCHECK_EQ(offscreen_tab_web_contents_.get(), web_contents);
+ const GURL& target_url) {
// Disallow creating separate WebContentses. The WebContents implementation
// uses this to spawn new windows/tabs, which is also not allowed for
// offscreen tabs.
- return false;
+ return true;
}
bool OffscreenTab::EmbedsFullscreenWidget() {
diff --git a/chrome/browser/media/offscreen_tab.h b/chrome/browser/media/offscreen_tab.h
index 77991a3..e3d8a35 100644
--- a/chrome/browser/media/offscreen_tab.h
+++ b/chrome/browser/media/offscreen_tab.h
@@ -101,19 +101,12 @@
bool CanDragEnter(content::WebContents* source,
const content::DropData& data,
blink::WebDragOperationsMask operations_allowed) final;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) final;
+ const GURL& target_url) final;
bool EmbedsFullscreenWidget() final;
void EnterFullscreenModeForTab(
content::WebContents* contents,
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index bf5a1e4..8a90ffb 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -112,24 +112,17 @@
std::move(callback).Run(false);
}
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- SessionStorageNamespace* session_storage_namespace) override {
+ const GURL& target_url) override {
// Since we don't want to permit child windows that would have a
// window.opener property, terminate prerendering.
prerender_contents_->Destroy(FINAL_STATUS_CREATE_NEW_WINDOW);
// Cancel the popup.
- return false;
+ return true;
}
bool OnGoToEntryOffset(int offset) override {
diff --git a/chrome/browser/ui/ash/keyboard/chrome_keyboard_web_contents.cc b/chrome/browser/ui/ash/keyboard/chrome_keyboard_web_contents.cc
index cd826d9d..4af64d7 100644
--- a/chrome/browser/ui/ash/keyboard/chrome_keyboard_web_contents.cc
+++ b/chrome/browser/ui/ash/keyboard/chrome_keyboard_web_contents.cc
@@ -59,20 +59,13 @@
return false;
}
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override {
- return false;
+ const GURL& target_url) override {
+ return true;
}
void SetContentsBounds(content::WebContents* source,
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index a86a546..3cdada94 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -1608,30 +1608,34 @@
std::make_unique<RepostFormWarningController>(source), source);
}
-bool Browser::ShouldCreateWebContents(
- content::WebContents* web_contents,
+bool Browser::IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) {
+ return window_container_type ==
+ content::mojom::WindowContainerType::BACKGROUND &&
+ ShouldCreateBackgroundContents(source_site_instance, opener_url,
+ frame_name);
+}
+
+WebContents* Browser::CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
- if ((window_container_type !=
- content::mojom::WindowContainerType::BACKGROUND) ||
- !ShouldCreateBackgroundContents(source_site_instance, opener_url,
- frame_name))
- return true;
-
- CreateBackgroundContents(source_site_instance, opener, opener_url, route_id,
- main_frame_route_id, main_frame_widget_route_id,
- frame_name, target_url, partition_id,
- session_storage_namespace);
- return false;
+ BackgroundContents* background_contents = CreateBackgroundContents(
+ source_site_instance, opener, opener_url, is_new_browsing_instance,
+ frame_name, target_url, partition_id, session_storage_namespace);
+ if (background_contents) {
+ return background_contents->web_contents();
+ }
+ return nullptr;
}
void Browser::WebContentsCreated(WebContents* source_contents,
@@ -2853,9 +2857,7 @@
content::SiteInstance* source_site_instance,
content::RenderFrameHost* opener,
const GURL& opener_url,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
+ bool is_new_browsing_instance,
const std::string& frame_name,
const GURL& target_url,
const std::string& partition_id,
@@ -2883,9 +2885,8 @@
// Passed all the checks, so this should be created as a BackgroundContents.
if (allow_js_access) {
return service->CreateBackgroundContents(
- source_site_instance, opener, route_id, main_frame_route_id,
- main_frame_widget_route_id, frame_name, extension->id(), partition_id,
- session_storage_namespace);
+ source_site_instance, opener, is_new_browsing_instance, frame_name,
+ extension->id(), partition_id, session_storage_namespace);
}
// If script access is not allowed, create the the background contents in a
@@ -2894,8 +2895,8 @@
// process.
BackgroundContents* contents = service->CreateBackgroundContents(
content::SiteInstance::Create(source_site_instance->GetBrowserContext()),
- nullptr, MSG_ROUTING_NONE, MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name,
- extension->id(), partition_id, session_storage_namespace);
+ nullptr, is_new_browsing_instance, frame_name, extension->id(),
+ partition_id, session_storage_namespace);
// When a separate process is used, the original renderer cannot access the
// new window later, thus we need to navigate the window now.
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 3f131a82..9c57ba6e 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -707,14 +707,16 @@
bool* proceed_to_fire_unload) override;
bool ShouldFocusLocationBarByDefault(content::WebContents* source) override;
void ShowRepostFormWarningDialog(content::WebContents* source) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
+ bool IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) override;
+ content::WebContents* CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
@@ -1002,9 +1004,7 @@
content::SiteInstance* source_site_instance,
content::RenderFrameHost* opener,
const GURL& opener_url,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
+ bool is_new_browsing_instance,
const std::string& frame_name,
const GURL& target_url,
const std::string& partition_id,
diff --git a/chrome/browser/ui/media_router/presentation_receiver_window_controller.cc b/chrome/browser/ui/media_router/presentation_receiver_window_controller.cc
index 1a5ce1d..03ae005 100644
--- a/chrome/browser/ui/media_router/presentation_receiver_window_controller.cc
+++ b/chrome/browser/ui/media_router/presentation_receiver_window_controller.cc
@@ -195,22 +195,14 @@
std::move(callback).Run(false);
}
-bool PresentationReceiverWindowController::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool PresentationReceiverWindowController::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
- DCHECK_EQ(web_contents_.get(), web_contents);
+ const GURL& target_url) {
// Disallow creating separate WebContentses. The WebContents implementation
// uses this to spawn new windows/tabs, which is also not allowed for
// local presentations.
- return false;
+ return true;
}
diff --git a/chrome/browser/ui/media_router/presentation_receiver_window_controller.h b/chrome/browser/ui/media_router/presentation_receiver_window_controller.h
index 039725f..611c041 100644
--- a/chrome/browser/ui/media_router/presentation_receiver_window_controller.h
+++ b/chrome/browser/ui/media_router/presentation_receiver_window_controller.h
@@ -93,19 +93,12 @@
void CanDownload(const GURL& url,
const std::string& request_method,
base::OnceCallback<void(bool)> callback) final;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) final;
+ const GURL& target_url) override;
// The profile used for the presentation.
std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration>
diff --git a/components/embedder_support/android/delegate/web_contents_delegate_android.cc b/components/embedder_support/android/delegate/web_contents_delegate_android.cc
index 3ba63a18..5316b981 100644
--- a/components/embedder_support/android/delegate/web_contents_delegate_android.cc
+++ b/components/embedder_support/android/delegate/web_contents_delegate_android.cc
@@ -189,27 +189,20 @@
Java_WebContentsDelegateAndroid_rendererResponsive(env, obj);
}
-bool WebContentsDelegateAndroid::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool WebContentsDelegateAndroid::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env);
if (obj.is_null())
- return true;
+ return false;
ScopedJavaLocalRef<jstring> java_url =
ConvertUTF8ToJavaString(env, target_url.spec());
- return Java_WebContentsDelegateAndroid_shouldCreateWebContents(env, obj,
- java_url);
+ return !Java_WebContentsDelegateAndroid_shouldCreateWebContents(env, obj,
+ java_url);
}
void WebContentsDelegateAndroid::WebContentsCreated(
diff --git a/components/embedder_support/android/delegate/web_contents_delegate_android.h b/components/embedder_support/android/delegate/web_contents_delegate_android.h
index 62ccbc2..3127006a 100644
--- a/components/embedder_support/android/delegate/web_contents_delegate_android.h
+++ b/components/embedder_support/android/delegate/web_contents_delegate_android.h
@@ -76,19 +76,12 @@
const std::string& frame_name,
const GURL& target_url,
content::WebContents* new_contents) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override;
+ const GURL& target_url) override;
void CloseContents(content::WebContents* source) override;
void SetContentsBounds(content::WebContents* source,
const gfx::Rect& bounds) override;
diff --git a/components/offline_pages/content/background_loader/background_loader_contents.cc b/components/offline_pages/content/background_loader/background_loader_contents.cc
index b0b86f1..030e61f 100644
--- a/components/offline_pages/content/background_loader/background_loader_contents.cc
+++ b/components/offline_pages/content/background_loader/background_loader_contents.cc
@@ -76,21 +76,14 @@
}
}
-bool BackgroundLoaderContents::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool BackgroundLoaderContents::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
// Background pages should not create other webcontents/tabs.
- return false;
+ return true;
}
void BackgroundLoaderContents::AddNewContents(
diff --git a/components/offline_pages/content/background_loader/background_loader_contents.h b/components/offline_pages/content/background_loader/background_loader_contents.h
index 77638f0..cac688e 100644
--- a/components/offline_pages/content/background_loader/background_loader_contents.h
+++ b/components/offline_pages/content/background_loader/background_loader_contents.h
@@ -56,19 +56,12 @@
const std::string& request_method,
base::OnceCallback<void(bool)> callback) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override;
+ const GURL& target_url) override;
void AddNewContents(content::WebContents* source,
std::unique_ptr<content::WebContents> new_contents,
diff --git a/components/offline_pages/content/background_loader/background_loader_contents_unittest.cc b/components/offline_pages/content/background_loader/background_loader_contents_unittest.cc
index 7e22d0e..0a0aec9 100644
--- a/components/offline_pages/content/background_loader/background_loader_contents_unittest.cc
+++ b/components/offline_pages/content/background_loader/background_loader_contents_unittest.cc
@@ -134,14 +134,11 @@
}
TEST_F(BackgroundLoaderContentsTest, ShouldNotCreateWebContents) {
- ASSERT_FALSE(contents()->ShouldCreateWebContents(
- nullptr /* contents */, nullptr /* opener */,
- nullptr /* source_site_instance */, 0 /* route_id */,
- 0 /* main_frame_route_id */, 0 /* main_frame_widget_route_id */,
+ ASSERT_TRUE(contents()->IsWebContentsCreationOverridden(
+ nullptr /* source_site_instance */,
content::mojom::WindowContainerType::NORMAL /* window_container_type */,
GURL() /* opener_url */, "foo" /* frame_name */,
- GURL::EmptyGURL() /* target_url */, "bar" /* partition_id */,
- nullptr /* session_storage_namespace */));
+ GURL::EmptyGURL() /* target_url */));
}
TEST_F(BackgroundLoaderContentsTest, ShouldNotAddNewContents) {
diff --git a/content/browser/content_service_delegate_impl.cc b/content/browser/content_service_delegate_impl.cc
index f792a5e..37692e762 100644
--- a/content/browser/content_service_delegate_impl.cc
+++ b/content/browser/content_service_delegate_impl.cc
@@ -104,25 +104,18 @@
}
// WebContentsDelegate:
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override {
+ const GURL& target_url) override {
// This method is invoked when attempting to open links in a new tab, e.g.:
// <a href="https://www.google.com/" target="_blank">Link</a>
client_->DidSuppressNavigation(target_url,
WindowOpenDisposition::NEW_FOREGROUND_TAB,
/*from_user_gesture=*/true);
- return false;
+ return true;
}
WebContents* OpenURLFromTab(WebContents* source,
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
index 680edc97..9e0df57 100644
--- a/content/browser/frame_host/render_frame_host_impl.cc
+++ b/content/browser/frame_host/render_frame_host_impl.cc
@@ -4203,8 +4203,9 @@
cloned_namespace.get());
if (is_new_browsing_instance || !new_window) {
- // Opener suppressed or Javascript access disabled. Never tell the renderer
- // about the new window.
+ // Opener suppressed, Javascript access disabled, or delegate did not
+ // provide a handle to any windows it created. In these cases, never tell
+ // the renderer about the new window.
std::move(callback).Run(mojom::CreateNewWindowStatus::kIgnore, nullptr);
return;
}
@@ -4223,8 +4224,8 @@
if (main_frame->waiting_for_init_) {
// Need to check |waiting_for_init_| as some paths inside CreateNewWindow
- // call above (namely, if WebContentsDelegate::ShouldCreateWebContents
- // returns false) will resume requests by calling RenderFrameHostImpl::Init.
+ // call above (eg if WebContentsDelegate::IsWebContentsCreationOverridden()
+ // returns true) will resume requests by calling RenderFrameHostImpl::Init.
main_frame->frame_->BlockRequests();
}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 3d447fd..91c9a1c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2824,39 +2824,14 @@
static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
- // TODO(crbug.com/545684): Move these closer to usage after cleaning up the
- // ShouldCreateWebContents() interface to not need the raw ID numbers.
- int render_view_route_id = MSG_ROUTING_NONE;
- int main_frame_route_id = MSG_ROUTING_NONE;
- int main_frame_widget_route_id = MSG_ROUTING_NONE;
- if (!is_new_browsing_instance) {
- render_view_route_id = opener->GetProcess()->GetNextRoutingID();
- main_frame_route_id = opener->GetProcess()->GetNextRoutingID();
- main_frame_widget_route_id = opener->GetProcess()->GetNextRoutingID();
- }
-
- if (delegate_ &&
- !delegate_->ShouldCreateWebContents(
- this, opener, source_site_instance, render_view_route_id,
- main_frame_route_id, main_frame_widget_route_id,
- params.window_container_type, opener->GetLastCommittedURL(),
- params.frame_name, params.target_url, partition_id,
- session_storage_namespace)) {
- // Note: even though we're not creating a WebContents here, it could have
- // been created by the embedder so ensure that the RenderFrameHost is
- // properly initialized.
- // It's safe to only target the frame because the render process will not
- // have a chance to create more frames at this point.
- RenderFrameHostImpl* rfh =
- RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
- if (rfh) {
- // TODO(crbug.com/545684): It's super surprising that
- // ShouldCreateWebContents() is actually a way to allow
- // BackgroundWebContents to intercede and provide a completely different
- // webcontents. Fix that API.
- return rfh->delegate();
- }
- return nullptr;
+ if (delegate_ && delegate_->IsWebContentsCreationOverridden(
+ source_site_instance, params.window_container_type,
+ opener->GetLastCommittedURL(), params.frame_name,
+ params.target_url)) {
+ return static_cast<WebContentsImpl*>(delegate_->CreateCustomWebContents(
+ opener, source_site_instance, is_new_browsing_instance,
+ opener->GetLastCommittedURL(), params.frame_name, params.target_url,
+ partition_id, session_storage_namespace));
}
bool renderer_started_hidden =
@@ -2878,9 +2853,22 @@
// the opener's process will not given the routing IDs for the new
// objects.
create_params.renderer_initiated_creation = !is_new_browsing_instance;
- create_params.routing_id = render_view_route_id;
- create_params.main_frame_routing_id = main_frame_route_id;
- create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
+
+ // If |is_new_browsing_instance| is true, defer routing_id allocation
+ // to the WebContentsImpl::Create() call. This is required because with
+ // a new browsing instance, WebContentsImpl::Create() may elect a different
+ // SiteInstance from |site_instance| (which happens if |site_instance| is
+ // nullptr for example).
+ //
+ // TODO(ajwong): This routing id allocation should be pushed down further
+ // into WebContentsImpl::Create().
+ if (!is_new_browsing_instance) {
+ create_params.routing_id = opener->GetProcess()->GetNextRoutingID();
+ create_params.main_frame_routing_id =
+ opener->GetProcess()->GetNextRoutingID();
+ create_params.main_frame_widget_routing_id =
+ opener->GetProcess()->GetNextRoutingID();
+ }
std::unique_ptr<WebContentsImpl> new_contents;
if (!is_guest) {
@@ -2924,8 +2912,9 @@
// TODO(ajwong): This should be keyed off the RenderFrame routing id or the
// FrameTreeNode id instead of the routing id of the Widget for the main
// frame. https://crbug.com/545684
- DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id);
- GlobalRoutingID id(render_process_id, main_frame_widget_route_id);
+ DCHECK_NE(MSG_ROUTING_NONE, create_params.main_frame_routing_id);
+ GlobalRoutingID id(render_process_id,
+ create_params.main_frame_widget_routing_id);
pending_contents_[id] = std::move(new_contents);
AddDestructionObserver(new_contents_impl);
}
diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc
index d868e5cc..1f046dd 100644
--- a/content/public/browser/web_contents_delegate.cc
+++ b/content/public/browser/web_contents_delegate.cc
@@ -119,20 +119,25 @@
return true;
}
-bool WebContentsDelegate::ShouldCreateWebContents(
- WebContents* web_contents,
+bool WebContentsDelegate::IsWebContentsCreationOverridden(
+ SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) {
+ return false;
+}
+
+WebContents* WebContentsDelegate::CreateCustomWebContents(
RenderFrameHost* opener,
SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
const std::string& partition_id,
SessionStorageNamespace* session_storage_namespace) {
- return true;
+ return nullptr;
}
JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager(
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
index b0f8fe9..dd9fcc8 100644
--- a/content/public/browser/web_contents_delegate.h
+++ b/content/public/browser/web_contents_delegate.h
@@ -57,7 +57,6 @@
class FileSelectListener;
class JavaScriptDialogManager;
class RenderFrameHost;
-class RenderProcessHost;
class RenderWidgetHost;
class SessionStorageNamespace;
class SiteInstance;
@@ -298,35 +297,30 @@
virtual bool OnGoToEntryOffset(int offset);
// Allows delegate to control whether a new WebContents can be created by
- // |web_contents|.
+ // the WebContents itself.
//
- // The route ID parameters passed to this method are associated with the
- // |source_site_instance|'s RenderProcessHost. They may also be
- // MSG_ROUTING_NONE. If they are valid, they correspond to a trio of
- // RenderView, RenderFrame, and RenderWidget objects that have been created in
- // the renderer, but not yet assigned a WebContents, RenderViewHost,
- // RenderFrameHost, or RenderWidgetHost.
+ // If an delegate returns true, it can optionally also override
+ // CreateCustomWebContents() below to provide their own WebContents.
+ virtual bool IsWebContentsCreationOverridden(
+ SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url);
+
+ // Allow delegate to creates a custom WebContents when
+ // WebContents::CreateNewWindow() is called. This function is only called
+ // when IsWebContentsCreationOverridden() returns true.
//
- // The return value is interpreted as follows:
- //
- // Return true: |web_contents| should create a WebContents.
- // Return false: |web_contents| should not create a WebContents. The
- // provisionally-created RenderView (if it exists) in the renderer
- // process will be destroyed, UNLESS the delegate, during this method,
- // itself creates a WebContents using |source_site_instance|,
- // |route_id|, |main_frame_route_id|, and |main_frame_widget_route_id|
- // as creation parameters. If this happens, the delegate assumes
- // ownership of the corresponding RenderView, etc. |web_contents| will
- // detect that this has happened by looking for the existence of a
- // RenderViewHost in |source_site_instance| with |route_id|.
- virtual bool ShouldCreateWebContents(
- WebContents* web_contents,
+ // In general, a delegate should return a pointer to a created WebContents
+ // so that the opener can be given a references to it as appropriate.
+ // Returning nullptr also makes sense if the delegate wishes to suppress
+ // all window creation, or if the delegate wants to ensure the opener
+ // cannot get a reference effectively creating a new browsing instance.
+ virtual WebContents* CreateCustomWebContents(
RenderFrameHost* opener,
SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
diff --git a/extensions/browser/guest_view/extension_options/extension_options_guest.cc b/extensions/browser/guest_view/extension_options/extension_options_guest.cc
index 0890def7..bfe998a 100644
--- a/extensions/browser/guest_view/extension_options/extension_options_guest.cc
+++ b/extensions/browser/guest_view/extension_options/extension_options_guest.cc
@@ -207,24 +207,29 @@
return extension_options_guest_delegate_->HandleContextMenu(params);
}
-bool ExtensionOptionsGuest::ShouldCreateWebContents(
- content::WebContents* web_contents,
+bool ExtensionOptionsGuest::IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) {
+ // This method handles opening links from within the guest. Since this guest
+ // view is used for displaying embedded extension options, we want any
+ // external links to be opened in a new tab, not in a new guest view so we
+ // override creation.
+ return true;
+}
+
+WebContents* ExtensionOptionsGuest::CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_renderer_initiated,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
- // This method handles opening links from within the guest. Since this guest
- // view is used for displaying embedded extension options, we want any
- // external links to be opened in a new tab, not in a new guest view.
- // Therefore we just open the URL in a new tab, and since we aren't handling
- // the new web contents, we return false.
+ // To get links out of the guest view, we just open the URL in a new tab.
// TODO(ericzeng): Open the tab in the background if the click was a
// ctrl-click or middle mouse button click
if (extension_options_guest_delegate_) {
@@ -233,7 +238,11 @@
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_LINK, false));
}
- return false;
+
+ // Returning nullptr here ensures that the guest-view can never get a
+ // reference to the new WebContents. It effectively forces a new browsing
+ // instance for all popups from an extensions guest.
+ return nullptr;
}
void ExtensionOptionsGuest::DidFinishNavigation(
diff --git a/extensions/browser/guest_view/extension_options/extension_options_guest.h b/extensions/browser/guest_view/extension_options/extension_options_guest.h
index bdeb2d5..3378cb2 100644
--- a/extensions/browser/guest_view/extension_options/extension_options_guest.h
+++ b/extensions/browser/guest_view/extension_options/extension_options_guest.h
@@ -50,14 +50,16 @@
void CloseContents(content::WebContents* source) final;
bool HandleContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) final;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
+ bool IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) final;
+ content::WebContents* CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
index 78cfe84..af060f3 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
@@ -391,14 +391,19 @@
return is_guest_fullscreen_;
}
-bool MimeHandlerViewGuest::ShouldCreateWebContents(
- content::WebContents* web_contents,
+bool MimeHandlerViewGuest::IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) {
+ return true;
+}
+
+content::WebContents* MimeHandlerViewGuest::CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_renderer_initiated,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
@@ -414,7 +419,7 @@
auto* delegate = embedder_web_contents()->GetDelegate();
if (delegate)
delegate->OpenURLFromTab(embedder_web_contents(), open_params);
- return false;
+ return nullptr;
}
bool MimeHandlerViewGuest::SetFullscreenState(bool is_fullscreen) {
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
index a608b0f3..14c969b9 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
@@ -147,14 +147,16 @@
void ExitFullscreenModeForTab(content::WebContents*) override;
bool IsFullscreenForTabOrPending(
const content::WebContents* web_contents) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
+ bool IsWebContentsCreationOverridden(
+ content::SiteInstance* source_site_instance,
+ content::mojom::WindowContainerType window_container_type,
+ const GURL& opener_url,
+ const std::string& frame_name,
+ const GURL& target_url) override;
+ content::WebContents* CreateCustomWebContents(
content::RenderFrameHost* opener,
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
- content::mojom::WindowContainerType window_container_type,
+ bool is_new_browsing_instance,
const GURL& opener_url,
const std::string& frame_name,
const GURL& target_url,
diff --git a/fuchsia/engine/browser/frame_impl.cc b/fuchsia/engine/browser/frame_impl.cc
index 0e17d7a..b1f3ae5 100644
--- a/fuchsia/engine/browser/frame_impl.cc
+++ b/fuchsia/engine/browser/frame_impl.cc
@@ -300,27 +300,18 @@
}
}
-bool FrameImpl::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool FrameImpl::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
// Specify a generous upper bound for unacknowledged popup windows, so that we
// can catch bad client behavior while not interfering with normal operation.
constexpr size_t kMaxPendingWebContentsCount = 10;
- DCHECK_EQ(web_contents, web_contents_.get());
-
if (!popup_listener_)
- return false;
+ return true;
if (pending_popups_.size() >= kMaxPendingWebContentsCount) {
// The content is producing popups faster than the embedder can process
@@ -328,10 +319,10 @@
LOG(WARNING) << "Too many pending popups, ignoring request.";
// Don't produce a WebContents for this popup.
- return false;
+ return true;
}
- return true;
+ return false;
}
void FrameImpl::AddNewContents(
diff --git a/fuchsia/engine/browser/frame_impl.h b/fuchsia/engine/browser/frame_impl.h
index 45c3abd..6e7f8c6 100644
--- a/fuchsia/engine/browser/frame_impl.h
+++ b/fuchsia/engine/browser/frame_impl.h
@@ -141,19 +141,12 @@
const base::string16& message,
int32_t line_no,
const base::string16& source_id) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override;
+ const GURL& target_url) override;
void WebContentsCreated(content::WebContents* source_contents,
int opener_render_process_id,
int opener_render_frame_id,
diff --git a/headless/lib/browser/headless_web_contents_impl.cc b/headless/lib/browser/headless_web_contents_impl.cc
index c0ff8fa6..86f4d81 100644
--- a/headless/lib/browser/headless_web_contents_impl.cc
+++ b/headless/lib/browser/headless_web_contents_impl.cc
@@ -177,22 +177,15 @@
return target;
}
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override {
- return !headless_web_contents_->browser_context()
- ->options()
- ->block_new_web_contents();
+ const GURL& target_url) override {
+ return headless_web_contents_->browser_context()
+ ->options()
+ ->block_new_web_contents();
}
private:
diff --git a/ui/views/controls/webview/web_dialog_view.cc b/ui/views/controls/webview/web_dialog_view.cc
index 2952e8d..2e2baf0 100644
--- a/ui/views/controls/webview/web_dialog_view.cc
+++ b/ui/views/controls/webview/web_dialog_view.cc
@@ -391,22 +391,15 @@
*proceed_to_fire_unload = proceed;
}
-bool WebDialogView::ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+bool WebDialogView::IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) {
+ const GURL& target_url) {
if (delegate_)
- return delegate_->HandleShouldCreateWebContents();
- return true;
+ return delegate_->HandleShouldOverrideWebContentsCreation();
+ return false;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/views/controls/webview/web_dialog_view.h b/ui/views/controls/webview/web_dialog_view.h
index 7e6755c7..8c7f6521 100644
--- a/ui/views/controls/webview/web_dialog_view.h
+++ b/ui/views/controls/webview/web_dialog_view.h
@@ -145,19 +145,12 @@
void BeforeUnloadFired(content::WebContents* tab,
bool proceed,
bool* proceed_to_fire_unload) override;
- bool ShouldCreateWebContents(
- content::WebContents* web_contents,
- content::RenderFrameHost* opener,
+ bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
- int32_t route_id,
- int32_t main_frame_route_id,
- int32_t main_frame_widget_route_id,
content::mojom::WindowContainerType window_container_type,
const GURL& opener_url,
const std::string& frame_name,
- const GURL& target_url,
- const std::string& partition_id,
- content::SessionStorageNamespace* session_storage_namespace) override;
+ const GURL& target_url) override;
private:
FRIEND_TEST_ALL_PREFIXES(WebDialogBrowserTest, WebContentRendered);
diff --git a/ui/web_dialogs/web_dialog_delegate.cc b/ui/web_dialogs/web_dialog_delegate.cc
index 60add58..0d0e20d60 100644
--- a/ui/web_dialogs/web_dialog_delegate.cc
+++ b/ui/web_dialogs/web_dialog_delegate.cc
@@ -54,8 +54,8 @@
return false;
}
-bool WebDialogDelegate::HandleShouldCreateWebContents() {
- return true;
+bool WebDialogDelegate::HandleShouldOverrideWebContentsCreation() {
+ return false;
}
std::vector<Accelerator> WebDialogDelegate::GetAccelerators() {
diff --git a/ui/web_dialogs/web_dialog_delegate.h b/ui/web_dialogs/web_dialog_delegate.h
index 7e2587e..ba3e5d5 100644
--- a/ui/web_dialogs/web_dialog_delegate.h
+++ b/ui/web_dialogs/web_dialog_delegate.h
@@ -142,8 +142,8 @@
content::WebContents** out_new_contents);
// A callback to control whether a WebContents will be created. Returns
- // false to disallow the creation. Return true to use the default handler.
- virtual bool HandleShouldCreateWebContents();
+ // true to disallow the creation. Return false to use the default handler.
+ virtual bool HandleShouldOverrideWebContentsCreation();
// Stores the dialog bounds.
virtual void StoreDialogSize(const gfx::Size& dialog_size) {}