diff --git chrome/browser/extensions/api/tab_capture/offscreen_tab.cc chrome/browser/extensions/api/tab_capture/offscreen_tab.cc index f50fdf9..9e59835 100644 --- chrome/browser/extensions/api/tab_capture/offscreen_tab.cc +++ chrome/browser/extensions/api/tab_capture/offscreen_tab.cc @@ -214,7 +214,9 @@ bool OffscreenTab::ShouldCreateWebContents( const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) { + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) { DCHECK_EQ(offscreen_tab_web_contents_.get(), contents); // Disallow creating separate WebContentses. The WebContents implementation // uses this to spawn new windows/tabs, which is also not allowed for diff --git chrome/browser/extensions/api/tab_capture/offscreen_tab.h chrome/browser/extensions/api/tab_capture/offscreen_tab.h index e639319..5f75a9a 100644 --- chrome/browser/extensions/api/tab_capture/offscreen_tab.h +++ chrome/browser/extensions/api/tab_capture/offscreen_tab.h @@ -148,7 +148,9 @@ class OffscreenTab : protected content::WebContentsDelegate, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) final; + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) final; bool EmbedsFullscreenWidget() const final; void EnterFullscreenModeForTab(content::WebContents* contents, const GURL& origin) final; diff --git chrome/browser/prerender/prerender_contents.cc chrome/browser/prerender/prerender_contents.cc index c3e60e0..93365f5c 100644 --- chrome/browser/prerender/prerender_contents.cc +++ chrome/browser/prerender/prerender_contents.cc @@ -139,7 +139,9 @@ class PrerenderContents::WebContentsDelegateImpl const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - SessionStorageNamespace* session_storage_namespace) override { + SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) 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); diff --git chrome/browser/ui/browser.cc chrome/browser/ui/browser.cc index bbb37ff..484eda3 100644 --- chrome/browser/ui/browser.cc +++ chrome/browser/ui/browser.cc @@ -1589,7 +1589,9 @@ bool Browser::ShouldCreateWebContents( const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) { + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) { if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { // If a BackgroundContents is created, suppress the normal WebContents. return !MaybeCreateBackgroundContents( diff --git chrome/browser/ui/browser.h chrome/browser/ui/browser.h index 6cdff54..0efcaa2 100644 --- chrome/browser/ui/browser.h +++ chrome/browser/ui/browser.h @@ -619,7 +619,9 @@ class Browser : public TabStripModelObserver, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) override; + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) override; void WebContentsCreated(content::WebContents* source_contents, int opener_render_process_id, int opener_render_frame_id, diff --git content/browser/web_contents/web_contents_impl.cc content/browser/web_contents/web_contents_impl.cc index 8850f6a..1a3719e 100644 --- content/browser/web_contents/web_contents_impl.cc +++ content/browser/web_contents/web_contents_impl.cc @@ -1572,6 +1572,12 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { std::string unique_name; frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); + if (params.view && params.delegate_view) { + view_.reset(params.view); + render_view_host_delegate_view_ = params.delegate_view; + } + + if (!view_) { WebContentsViewDelegate* delegate = GetContentClient()->browser()->GetWebContentsViewDelegate(this); @@ -1602,6 +1608,7 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { std::move(view_), &render_view_host_delegate_view_)); } + } CHECK(render_view_host_delegate_view_); CHECK(view_.get()); @@ -2063,11 +2070,14 @@ void WebContentsImpl::CreateNewWindow( static_cast(session_storage_namespace); CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); + content::WebContentsView* view = NULL; + content::RenderViewHostDelegateView* delegate_view = NULL; + if (delegate_ && !delegate_->ShouldCreateWebContents( this, route_id, main_frame_route_id, main_frame_widget_route_id, params.window_container_type, params.frame_name, params.target_url, - partition_id, session_storage_namespace)) { + partition_id, session_storage_namespace, &view, &delegate_view)) { if (route_id != MSG_ROUTING_NONE && !RenderViewHost::FromID(render_process_id, route_id)) { // If the embedder didn't create a WebContents for this route, we need to @@ -2096,6 +2106,8 @@ void WebContentsImpl::CreateNewWindow( create_params.opener_render_process_id = render_process_id; create_params.opener_render_frame_id = params.opener_render_frame_id; create_params.opener_suppressed = params.opener_suppressed; + create_params.view = view; + create_params.delegate_view = delegate_view; if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) create_params.initially_hidden = true; create_params.renderer_initiated_creation = diff --git content/public/browser/web_contents.cc content/public/browser/web_contents.cc index fa0afb5..d677b31 100644 --- content/public/browser/web_contents.cc +++ content/public/browser/web_contents.cc @@ -29,7 +29,9 @@ WebContents::CreateParams::CreateParams(BrowserContext* context, guest_delegate(nullptr), context(nullptr), renderer_initiated_creation(false), - initialize_renderer(false) { + initialize_renderer(false), + view(nullptr), + delegate_view(nullptr) { } WebContents::CreateParams::CreateParams(const CreateParams& other) = default; diff --git content/public/browser/web_contents.h content/public/browser/web_contents.h index af944f7..cde1d7b 100644 --- content/public/browser/web_contents.h +++ content/public/browser/web_contents.h @@ -59,9 +59,11 @@ class PageState; class RenderFrameHost; class RenderProcessHost; class RenderViewHost; +class RenderViewHostDelegateView; class RenderWidgetHost; class RenderWidgetHostView; class WebContentsDelegate; +class WebContentsView; struct CustomContextMenuContext; struct DropData; struct Manifest; @@ -162,6 +164,10 @@ class WebContents : public PageNavigator, // Note that the pre-created renderer process may not be used if the first // navigation requires a dedicated or privileged process, such as a WebUI. bool initialize_renderer; + + // Optionally specify the view and delegate view. + content::WebContentsView* view; + content::RenderViewHostDelegateView* delegate_view; }; // Creates a new WebContents. diff --git content/public/browser/web_contents_delegate.cc content/public/browser/web_contents_delegate.cc index b86ec61..2d1ddb2 100644 --- content/public/browser/web_contents_delegate.cc +++ content/public/browser/web_contents_delegate.cc @@ -144,7 +144,9 @@ bool WebContentsDelegate::ShouldCreateWebContents( const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - SessionStorageNamespace* session_storage_namespace) { + SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) { return true; } diff --git content/public/browser/web_contents_delegate.h content/public/browser/web_contents_delegate.h index 2beb83c..b02f4f1 100644 --- content/public/browser/web_contents_delegate.h +++ content/public/browser/web_contents_delegate.h @@ -42,9 +42,11 @@ class ColorChooser; class JavaScriptDialogManager; class PageState; class RenderFrameHost; +class RenderViewHostDelegateView; class SessionStorageNamespace; class WebContents; class WebContentsImpl; +class WebContentsView; struct ColorSuggestion; struct ContextMenuParams; struct DropData; @@ -303,7 +305,9 @@ class CONTENT_EXPORT WebContentsDelegate { const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - SessionStorageNamespace* session_storage_namespace); + SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view); // Notifies the delegate about the creation of a new WebContents. This // typically happens when popups are created. diff --git extensions/browser/guest_view/extension_options/extension_options_guest.cc extensions/browser/guest_view/extension_options/extension_options_guest.cc index c02aace..67b9bd8 100644 --- extensions/browser/guest_view/extension_options/extension_options_guest.cc +++ extensions/browser/guest_view/extension_options/extension_options_guest.cc @@ -201,7 +201,9 @@ bool ExtensionOptionsGuest::ShouldCreateWebContents( const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) { + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) { // 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. diff --git extensions/browser/guest_view/extension_options/extension_options_guest.h extensions/browser/guest_view/extension_options/extension_options_guest.h index e0309f7..f6a3878 100644 --- extensions/browser/guest_view/extension_options/extension_options_guest.h +++ extensions/browser/guest_view/extension_options/extension_options_guest.h @@ -56,7 +56,9 @@ class ExtensionOptionsGuest const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) final; + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) final; // content::WebContentsObserver implementation. void DidNavigateMainFrame(const content::LoadCommittedDetails& details, diff --git ui/keyboard/content/keyboard_ui_content.cc ui/keyboard/content/keyboard_ui_content.cc index d08fd23..3ec515c 100644 --- ui/keyboard/content/keyboard_ui_content.cc +++ ui/keyboard/content/keyboard_ui_content.cc @@ -64,7 +64,9 @@ class KeyboardContentsDelegate : public content::WebContentsDelegate, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) override { + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) override { return false; } diff --git ui/views/controls/webview/web_dialog_view.cc ui/views/controls/webview/web_dialog_view.cc index d8afe6e..59259b7 100644 --- ui/views/controls/webview/web_dialog_view.cc +++ ui/views/controls/webview/web_dialog_view.cc @@ -341,7 +341,9 @@ bool WebDialogView::ShouldCreateWebContents( const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) { + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) { if (delegate_) return delegate_->HandleShouldCreateWebContents(); return true; diff --git ui/views/controls/webview/web_dialog_view.h ui/views/controls/webview/web_dialog_view.h index 65be6d54..7802d6d 100644 --- ui/views/controls/webview/web_dialog_view.h +++ ui/views/controls/webview/web_dialog_view.h @@ -123,7 +123,9 @@ class WEBVIEW_EXPORT WebDialogView : public views::ClientView, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, - content::SessionStorageNamespace* session_storage_namespace) override; + content::SessionStorageNamespace* session_storage_namespace, + content::WebContentsView** view, + content::RenderViewHostDelegateView** delegate_view) override; private: FRIEND_TEST_ALL_PREFIXES(WebDialogBrowserTest, WebContentRendered);