Implement BrowserPluginGuestDelegate::CreateNewGuestWindow for nativeWindowOpen

This commit is contained in:
Kevin Sawicki 2017-05-23 13:26:19 -07:00
parent a16cd0bd03
commit 7baf472c0f
4 changed files with 34 additions and 1 deletions

View file

@ -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<content::WebContentsImpl*>(guest_contents);
guest_contents_impl->GetView()->CreateViewForWidget(
guest_contents->GetRenderViewHost()->GetWidget(), false);
return guest_contents;
}
} // namespace atom

View file

@ -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,

View file

@ -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) => {

View file

@ -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) {