diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d4dd40b81470..e87219d3710e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -90,6 +90,22 @@ struct Converter { } }; +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + WindowOpenDisposition val) { + std::string disposition = "other"; + switch (val) { + case CURRENT_TAB: disposition = "default"; break; + case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break; + case NEW_BACKGROUND_TAB: disposition = "background-tab"; break; + case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break; + default: break; + } + return mate::ConvertToV8(isolate, disposition); + } +}; + } // namespace mate @@ -187,10 +203,7 @@ bool WebContents::ShouldCreateWebContents( const GURL& target_url, const std::string& partition_id, content::SessionStorageNamespace* session_storage_namespace) { - Emit("-new-window", - target_url, - frame_name, - static_cast(NEW_FOREGROUND_TAB)); + Emit("new-window", target_url, frame_name, NEW_FOREGROUND_TAB); return false; } @@ -202,7 +215,7 @@ content::WebContents* WebContents::OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) { if (params.disposition != CURRENT_TAB) { - Emit("-new-window", params.url, "", static_cast(params.disposition)); + Emit("new-window", params.url, "", params.disposition); return nullptr; } diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 0ad9a329e6cc..f19a353afa8c 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -58,7 +58,7 @@ void Window::WillCreatePopupWindow(const base::string16& frame_name, const GURL& target_url, const std::string& partition_id, WindowOpenDisposition disposition) { - Emit("-new-window", target_url, frame_name, static_cast(disposition)); + Emit("-new-window", target_url, frame_name); } void Window::WillNavigate(bool* prevent_default, const GURL& url) { diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 38e6caaaa6e8..64aaf2bd415c 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -30,17 +30,6 @@ wrapWebContents = (webContents) -> do (name, method) -> webContents[name] = -> method.apply controller, arguments - # Translate |disposition| to string for 'new-window' event. - webContents.on '-new-window', (args..., disposition) -> - disposition = - switch disposition - when 2 then 'default' - when 4 then 'foreground-tab' - when 5 then 'background-tab' - when 6, 7 then 'new-window' - else 'other' - @emit 'new-window', args..., disposition - # Tell the rpc server that a render view has been deleted and we need to # release all objects owned by it. webContents.on 'render-view-deleted', (event, processId, routingId) -> diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index 14b0cafe8f53..aef8b0def24d 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -41,7 +41,7 @@ createGuest = (embedder, url, frameName, options) -> # Routed window.open messages. ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) -> [url, frameName, options] = args - event.sender.emit '-new-window', event, url, frameName, 7 + event.sender.emit 'new-window', event, url, frameName, 'new-window' if event.sender.isGuest() or event.defaultPrevented event.returnValue = null else