do setOwnerWindow

This commit is contained in:
Jeremy Rose
2022-09-15 13:11:36 -07:00
parent ade06e0915
commit 82551ba2cf
4 changed files with 12 additions and 2 deletions

View File

@@ -84,7 +84,7 @@ BrowserWindow.fromWebContents = (webContents: WebContents) => {
};
BrowserWindow.fromBrowserView = (browserView: BrowserView) => {
return browserView.ownerWindow;
return BrowserWindow.fromWebContents(browserView.webContents);
};
BrowserWindow.prototype.setTouchBar = function (touchBar) {
@@ -162,8 +162,10 @@ BrowserWindow.prototype.setBackgroundThrottling = function (allowed: boolean) {
};
BrowserWindow.prototype.addBrowserView = function (browserView: BrowserView) {
if (browserView.ownerWindow) { browserView.ownerWindow.removeBrowserView(browserView); }
this.contentView.addChildView(browserView.webContentsView);
browserView.ownerWindow = this;
browserView.webContents._setOwnerWindow(this);
this._browserViews.push(browserView);
};
@@ -193,7 +195,6 @@ BrowserWindow.prototype.getBrowserViews = function () {
};
BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
this.removeBrowserView(browserView);
this.addBrowserView(browserView);
};

View File

@@ -1998,6 +1998,10 @@ void WebContents::SetOwnerWindow(NativeWindow* owner_window) {
SetOwnerWindow(GetWebContents(), owner_window);
}
void WebContents::SetOwnerBaseWindow(BaseWindow* owner_window) {
SetOwnerWindow(GetWebContents(), owner_window->window());
}
void WebContents::SetOwnerWindow(content::WebContents* web_contents,
NativeWindow* owner_window) {
if (owner_window) {
@@ -4033,6 +4037,7 @@ v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
.SetProperty("debugger", &WebContents::Debugger)
.SetProperty("mainFrame", &WebContents::MainFrame)
.SetMethod("_setOwnerWindow", &WebContents::SetOwnerBaseWindow)
.Build();
}

View File

@@ -94,6 +94,8 @@ class OffScreenWebContentsView;
namespace api {
class BaseWindow;
// Wrapper around the content::WebContents.
class WebContents : public ExclusiveAccessContext,
public gin::Wrappable<WebContents>,
@@ -375,6 +377,7 @@ class WebContents : public ExclusiveAccessContext,
void SetOwnerWindow(NativeWindow* owner_window);
void SetOwnerWindow(content::WebContents* web_contents,
NativeWindow* owner_window);
void SetOwnerBaseWindow(BaseWindow* owner_window);
// Returns the WebContents managed by this delegate.
content::WebContents* GetWebContents() const;

View File

@@ -88,6 +88,7 @@ declare namespace Electron {
detachFromOuterFrame(): void;
setEmbedder(embedder: Electron.WebContents): void;
viewInstanceId: number;
_setOwnerWindow(w: BaseWindow): void;
}
interface WebFrameMain {