]> khamidou — GitHub mirrors - electron.git/commitdiff
Make it safe to use sendSync
authorCheng Zhao <zcbenz@gmail.com>
Tue, 8 Dec 2015 02:07:47 +0000 (10:07 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 8 Dec 2015 02:07:47 +0000 (10:07 +0800)
atom/renderer/api/lib/ipc-renderer.coffee
atom/renderer/api/lib/remote.coffee
chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc

index 29004d212b5600577b03becbdcf9a3a9734b695e..92be75aa20ba8fe81551ef9044c2450dc3f2c82a 100644 (file)
@@ -1,9 +1,17 @@
+{EventEmitter} = require 'events'
+
 binding = process.atomBinding 'ipc'
 v8Util  = process.atomBinding 'v8_util'
 
 # Created by init.coffee.
 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...) ->
   binding.send 'ipc-message', [args...]
 
index 357b88406930903a6525d992b549e6405b715f1c..48cdd937fb079aca1114736002ae271897a75dec 100644 (file)
@@ -119,11 +119,7 @@ metaToPlainObject = (meta) ->
 
 # Browser calls a callback in renderer.
 ipcRenderer.on 'ATOM_RENDERER_CALLBACK', (event, id, args) ->
-  # Delay the callback to next tick in case the browser is still in the middle
-  # of sending this message while the callback sends a sync message to browser,
-  # which can fail sometimes.
-  setImmediate ->
-    callbacksRegistry.apply id, metaToValue(args)
+  callbacksRegistry.apply id, metaToValue(args)
 
 # A callback in browser is released.
 ipcRenderer.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) ->
index 5b34ff30904374a3a043d245cd40c3d0cf8ff925..0b21de46995bb5ad0de9c63b6de5fa96cf056bcf 100644 (file)
@@ -135,6 +135,8 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
     printed_page_params.page_size = page_size_in_dpi[i];
     printed_page_params.content_area = content_area_in_dpi[i];
     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;
 }