diff --git a/atom/browser/web_view_guest_delegate.cc b/atom/browser/web_view_guest_delegate.cc index 21b917ac61af..84fbf2cfd00a 100644 --- a/atom/browser/web_view_guest_delegate.cc +++ b/atom/browser/web_view_guest_delegate.cc @@ -6,6 +6,7 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/common/native_mate_converters/gurl_converter.h" +#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/guest_host.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/render_frame_host.h" @@ -188,4 +189,19 @@ content::SiteInstance* WebViewGuestDelegate::GetOwnerSiteInstance() { return embedder_web_contents_->GetSiteInstance(); } +content::WebContents* WebViewGuestDelegate::CreateNewGuestWindow( + const content::WebContents::CreateParams& create_params) { + content::WebContents::CreateParams guest_params(create_params); + guest_params.initial_size = + embedder_web_contents_->GetContainerBounds().size(); + guest_params.context = embedder_web_contents_->GetNativeView(); + auto guest_contents = content::WebContents::Create(guest_params); + auto guest_contents_impl = + static_cast(guest_contents); + guest_contents_impl->GetView()->CreateViewForWidget( + guest_contents->GetRenderViewHost()->GetWidget(), false); + + return guest_contents; +} + } // namespace atom diff --git a/atom/browser/web_view_guest_delegate.h b/atom/browser/web_view_guest_delegate.h index 329b7ec3178f..0d97d8095068 100644 --- a/atom/browser/web_view_guest_delegate.h +++ b/atom/browser/web_view_guest_delegate.h @@ -64,6 +64,8 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, bool CanBeEmbeddedInsideCrossProcessFrames() override; content::RenderWidgetHost* GetOwnerRenderWidgetHost() override; content::SiteInstance* GetOwnerSiteInstance() override; + content::WebContents* CreateNewGuestWindow( + const content::WebContents::CreateParams& create_params) override; // WebContentsZoomController::Observer: void OnZoomLevelChanged(content::WebContents* web_contents, diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 49a134f39415..c6931c854a06 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -36,8 +36,9 @@ BrowserWindow.prototype._init = function () { frameName) => { v8Util.setHiddenValue(webContents, 'url-framename', {url, frameName}) }) + // Create a new browser window for the native implementation of - // "window.open"(sandbox mode only) + // "window.open", used in sandbox and nativeWindowOpen mode this.webContents.on('-add-new-contents', (event, webContents, disposition, userGesture, left, top, width, height) => { diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 0bfe77d1e5e4..bf1de28e1ae4 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -116,6 +116,20 @@ const createGuest = function (embedder, params) { guest.allowPopups = params.allowpopups }) + guest.on('-add-new-contents', (...args) => { + const embedder = getEmbedder(guestInstanceId) + if (embedder != null) { + embedder.emit('-add-new-contents', ...args) + } + }) + + guest.on('-web-contents-created', (...args) => { + const embedder = getEmbedder(guestInstanceId) + if (embedder != null) { + embedder.emit('-web-contents-created', ...args) + } + }) + const sendToEmbedder = (channel, ...args) => { const embedder = getEmbedder(guestInstanceId) if (embedder != null) {