From 3e05350d6b9ede5bde005f85e430d8345f8567d3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Feb 2017 12:52:43 -0800 Subject: [PATCH 1/3] Check that window is non-null before accessing constructor prop --- lib/browser/api/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 14e87d3d74f5..28f51ca6be67 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -147,7 +147,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { let asyncPopup = false // menu.popup(x, y, positioningItem) - if (typeof window !== 'object' || window.constructor !== BrowserWindow) { + if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) { // Shift. positioningItem = y y = x From c951e253c6c025e8d104f30e37b0d5994bf19deb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Feb 2017 12:53:29 -0800 Subject: [PATCH 2/3] Default to focused window whenever param is null/undefined --- lib/browser/api/menu.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 28f51ca6be67..9615962ac66b 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -152,7 +152,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { positioningItem = y y = x x = window - window = BrowserWindow.getFocusedWindow() + window = null } // menu.popup(window, {}) @@ -164,6 +164,9 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { asyncPopup = options.async } + // Default to showing in focused window. + if (window == null) window = BrowserWindow.getFocusedWindow() + // Default to showing under mouse location. if (typeof x !== 'number') x = -1 if (typeof y !== 'number') y = -1 From 739f3ed10207ea62eaaabb86d2ece9e32b4a9e9f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Feb 2017 12:59:26 -0800 Subject: [PATCH 3/3] Popup pepper menu in owner browser window --- lib/browser/api/web-contents.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index c43a28823915..6c03800bcdec 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -253,7 +253,7 @@ WebContents.prototype._init = function () { this.on('pepper-context-menu', function (event, params) { // Access Menu via electron.Menu to prevent circular require const menu = electron.Menu.buildFromTemplate(params.menu) - menu.popup(params.x, params.y) + menu.popup(event.sender.getOwnerBrowserWindow(), params.x, params.y) }) // The devtools requests the webContents to reload.