diff --git a/atom/browser/api/atom_api_menu_views.cc b/atom/browser/api/atom_api_menu_views.cc index 62a785519fc9..0a3b16183030 100644 --- a/atom/browser/api/atom_api_menu_views.cc +++ b/atom/browser/api/atom_api_menu_views.cc @@ -60,9 +60,10 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) { } void MenuViews::ClosePopupAt(int32_t window_id) { - if (menu_runners_[window_id]) + if (menu_runners_[window_id]) { menu_runners_[window_id]->Cancel(); - menu_runners_.erase(window_id); + menu_runners_.erase(window_id); + } } // static diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 320741106cdb..dbf53c860039 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -653,9 +653,10 @@ void WebContents::RendererResponsive(content::WebContents* source) { bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) { if (params.custom_context.is_pepper_menu) { - Emit("pepper-context-menu", std::make_pair(params, web_contents()), - base::Bind(&content::WebContents::NotifyContextMenuClosed, - base::Unretained(web_contents()), params.custom_context)); + Emit("pepper-context-menu", + std::make_pair(params, web_contents()), + base::Bind(&content::WebContents::NotifyContextMenuClosed, + base::Unretained(web_contents()), params.custom_context)); } else { Emit("context-menu", std::make_pair(params, web_contents())); } diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index 8d73bbe26211..2d84e9f564af 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -278,13 +278,10 @@ WebContents.prototype._init = function () { // Handle context menu action request from pepper plugin. this.on('pepper-context-menu', function (event, params, callback) { - // Access Menu via electron.Menu to prevent circular require + // Access Menu via electron.Menu to prevent circular require. const menu = electron.Menu.buildFromTemplate(params.menu) + menu.once('closed', callback) menu.popup(event.sender.getOwnerBrowserWindow(), params.x, params.y) - - menu.on('closed', () => { - callback() - }) }) // The devtools requests the webContents to reload.