Omit extra transfer of new-window event

This commit is contained in:
Cheng Zhao 2015-06-23 16:34:22 +08:00
parent 2d65c3bcd0
commit 015ef3e014
4 changed files with 20 additions and 18 deletions

View file

@ -90,6 +90,22 @@ struct Converter<PrintSettings> {
} }
}; };
template<>
struct Converter<WindowOpenDisposition> {
static v8::Local<v8::Value> 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 } // namespace mate
@ -187,10 +203,7 @@ bool WebContents::ShouldCreateWebContents(
const GURL& target_url, const GURL& target_url,
const std::string& partition_id, const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace) {
Emit("-new-window", Emit("new-window", target_url, frame_name, NEW_FOREGROUND_TAB);
target_url,
frame_name,
static_cast<int>(NEW_FOREGROUND_TAB));
return false; return false;
} }
@ -202,7 +215,7 @@ content::WebContents* WebContents::OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
const content::OpenURLParams& params) { const content::OpenURLParams& params) {
if (params.disposition != CURRENT_TAB) { if (params.disposition != CURRENT_TAB) {
Emit("-new-window", params.url, "", static_cast<int>(params.disposition)); Emit("new-window", params.url, "", params.disposition);
return nullptr; return nullptr;
} }

View file

@ -58,7 +58,7 @@ void Window::WillCreatePopupWindow(const base::string16& frame_name,
const GURL& target_url, const GURL& target_url,
const std::string& partition_id, const std::string& partition_id,
WindowOpenDisposition disposition) { WindowOpenDisposition disposition) {
Emit("-new-window", target_url, frame_name, static_cast<int>(disposition)); Emit("-new-window", target_url, frame_name);
} }
void Window::WillNavigate(bool* prevent_default, const GURL& url) { void Window::WillNavigate(bool* prevent_default, const GURL& url) {

View file

@ -30,17 +30,6 @@ wrapWebContents = (webContents) ->
do (name, method) -> do (name, method) ->
webContents[name] = -> method.apply controller, arguments 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 # Tell the rpc server that a render view has been deleted and we need to
# release all objects owned by it. # release all objects owned by it.
webContents.on 'render-view-deleted', (event, processId, routingId) -> webContents.on 'render-view-deleted', (event, processId, routingId) ->

View file

@ -41,7 +41,7 @@ createGuest = (embedder, url, frameName, options) ->
# Routed window.open messages. # Routed window.open messages.
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) -> ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
[url, frameName, options] = 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 if event.sender.isGuest() or event.defaultPrevented
event.returnValue = null event.returnValue = null
else else