OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Custom binding for the pageCapture API. | 5 // Custom binding for the pageCapture API. |
6 | 6 |
7 var binding = require('binding').Binding.create('pageCapture'); | 7 var binding = require('binding').Binding.create('pageCapture'); |
8 | 8 |
9 var pageCaptureNatives = requireNative('page_capture'); | 9 var pageCaptureNatives = requireNative('page_capture'); |
10 var CreateBlob = pageCaptureNatives.CreateBlob; | 10 var CreateBlob = pageCaptureNatives.CreateBlob; |
11 var SendResponseAck = pageCaptureNatives.SendResponseAck; | 11 var SendResponseAck = pageCaptureNatives.SendResponseAck; |
12 | 12 |
13 binding.registerCustomHook(function(bindingsAPI) { | 13 binding.registerCustomHook(function(bindingsAPI) { |
14 var apiFunctions = bindingsAPI.apiFunctions; | 14 var apiFunctions = bindingsAPI.apiFunctions; |
15 | 15 |
16 apiFunctions.setCustomCallback('saveAsMHTML', | 16 apiFunctions.setCustomCallback('saveAsMHTML', |
17 function(name, request, response) { | 17 function(name, request, response) { |
18 var path = response.mhtmlFilePath; | 18 var callback = request.callback; |
19 var size = response.mhtmlFileLength; | 19 request.callback = null; |
20 if (response) { | |
Devlin
2014/07/10 20:53:28
nit: inline?
if (response)
response = CreateBlo
robwu
2014/07/10 21:15:56
Done.
| |
21 var path = response.mhtmlFilePath; | |
22 var size = response.mhtmlFileLength; | |
23 response = CreateBlob(path, size); | |
24 } | |
20 | 25 |
21 if (request.callback) | 26 try { |
22 request.callback(CreateBlob(path, size)); | 27 callback(response); |
23 request.callback = null; | 28 } finally { |
Devlin
2014/07/10 20:53:28
We usually put a catch here and log the error so t
robwu
2014/07/10 21:15:56
Done.
| |
24 | 29 // Notify the browser. Now that the blob is referenced from JavaScript, |
25 // Notify the browser. Now that the blob is referenced from JavaScript, | 30 // the browser can drop its reference to it. |
26 // the browser can drop its reference to it. | 31 SendResponseAck(request.id); |
27 SendResponseAck(request.id); | 32 } |
28 }); | 33 }); |
29 }); | 34 }); |
30 | 35 |
31 exports.binding = binding.generate(); | 36 exports.binding = binding.generate(); |
OLD | NEW |