Index: chrome/renderer/resources/extensions/page_capture_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/page_capture_custom_bindings.js b/chrome/renderer/resources/extensions/page_capture_custom_bindings.js |
index f9147d787eb0e51922b9aa556efa08b846b8e0cd..a7a140af0a980393147ee0eb8d5bf9dccc09c422 100644 |
--- a/chrome/renderer/resources/extensions/page_capture_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/page_capture_custom_bindings.js |
@@ -6,6 +6,7 @@ |
var binding = require('binding').Binding.create('pageCapture'); |
+var handleUncaughtException = require('uncaught_exception_handler').handle; |
var pageCaptureNatives = requireNative('page_capture'); |
var CreateBlob = pageCaptureNatives.CreateBlob; |
var SendResponseAck = pageCaptureNatives.SendResponseAck; |
@@ -15,16 +16,23 @@ binding.registerCustomHook(function(bindingsAPI) { |
apiFunctions.setCustomCallback('saveAsMHTML', |
function(name, request, response) { |
- var path = response.mhtmlFilePath; |
- var size = response.mhtmlFileLength; |
- |
- if (request.callback) |
- request.callback(CreateBlob(path, size)); |
+ var callback = request.callback; |
request.callback = null; |
- |
- // Notify the browser. Now that the blob is referenced from JavaScript, |
- // the browser can drop its reference to it. |
- SendResponseAck(request.id); |
+ if (response) |
+ response = CreateBlob(response.mhtmlFilePath, response.mhtmlFileLength); |
+ |
+ try { |
+ callback(response); |
+ } catch (e) { |
+ var message = "Error in chrome.pageCapture.saveAsMHTML callback: " + e; |
+ if (request.stack) |
+ message += "\n" + request.stack; |
+ handleUncaughtException(message, e); |
+ } finally { |
+ // Notify the browser. Now that the blob is referenced from JavaScript, |
+ // the browser can drop its reference to it. |
+ SendResponseAck(request.id); |
+ } |
}); |
}); |