Skip to content

Commit

Permalink
implement nornagon suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
loc committed Dec 12, 2019
1 parent e54baff commit 52b18a3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/browser/api/web-contents.js
Expand Up @@ -287,14 +287,7 @@ WebContents.prototype.loadFile = function (filePath, options = {}) {
}

WebContents.prototype.setWindowOpenOverride = function (handler) {
this.windowOpenOverrideHandler = handler
}

WebContents.prototype._callWindowOpenOverride = function (event, url, frameName) {
if (this.windowOpenOverrideHandler) {
const response = this.windowOpenOverrideHandler({ url, frameName })
if (response === false) event.preventDefault()
}
this._windowOpenOverrideHandler = handler
}

const addReplyToEvent = (event) => {
Expand Down Expand Up @@ -325,7 +318,7 @@ WebContents.prototype._init = function () {
// The navigation controller.
NavigationController.call(this, this)

this.windowOpenOverrideHandler = null
this._windowOpenOverrideHandler = null

// Every remote callback from renderer process would add a listener to the
// render-view-deleted event, so ignore the listeners warning.
Expand Down Expand Up @@ -406,7 +399,10 @@ WebContents.prototype._init = function () {
})

this.on('-will-add-new-contents', (event, url, frameName) => {
this._callWindowOpenOverride(event, url, frameName)
if (this._windowOpenOverrideHandler) {
const response = this._windowOpenOverrideHandler({ url, frameName })
if (response === false) event.preventDefault()
}
})

// Create a new browser window for the native implementation of
Expand Down

0 comments on commit 52b18a3

Please sign in to comment.