Make it safe to use sendSync

This commit is contained in:
Cheng Zhao 2015-12-08 10:07:47 +08:00
parent ac2e500cf7
commit e78a02806e
3 changed files with 11 additions and 5 deletions

View file

@ -1,9 +1,17 @@
{EventEmitter} = require 'events'
binding = process.atomBinding 'ipc' binding = process.atomBinding 'ipc'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
# Created by init.coffee. # Created by init.coffee.
ipcRenderer = v8Util.getHiddenValue global, 'ipc' ipcRenderer = v8Util.getHiddenValue global, 'ipc'
# Delay the callback to next tick in case the browser is still in the middle
# of sending a message while the callback sends a sync message to browser,
# which can fail sometimes.
ipcRenderer.emit = (args...) ->
setTimeout (-> EventEmitter::emit.call ipcRenderer, args...), 0
ipcRenderer.send = (args...) -> ipcRenderer.send = (args...) ->
binding.send 'ipc-message', [args...] binding.send 'ipc-message', [args...]

View file

@ -119,11 +119,7 @@ metaToPlainObject = (meta) ->
# Browser calls a callback in renderer. # Browser calls a callback in renderer.
ipcRenderer.on 'ATOM_RENDERER_CALLBACK', (event, id, args) -> ipcRenderer.on 'ATOM_RENDERER_CALLBACK', (event, id, args) ->
# Delay the callback to next tick in case the browser is still in the middle callbacksRegistry.apply id, metaToValue(args)
# of sending this message while the callback sends a sync message to browser,
# which can fail sometimes.
setImmediate ->
callbacksRegistry.apply id, metaToValue(args)
# A callback in browser is released. # A callback in browser is released.
ipcRenderer.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) -> ipcRenderer.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) ->

View file

@ -135,6 +135,8 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
printed_page_params.page_size = page_size_in_dpi[i]; printed_page_params.page_size = page_size_in_dpi[i];
printed_page_params.content_area = content_area_in_dpi[i]; printed_page_params.content_area = content_area_in_dpi[i];
Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params)); Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params));
// Send the rest of the pages with an invalid metafile handle.
printed_page_params.metafile_data_handle = base::SharedMemoryHandle();
} }
return true; return true;
} }