Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: chrome/renderer/resources/extensions/page_capture_custom_bindings.js

Issue 384653002: Improve robustness of pageCapture.saveAsMHTML custom binding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address rdevlin's review comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/page_capture/page_capture_api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ }
});
});
« no previous file with comments | « chrome/browser/extensions/api/page_capture/page_capture_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698