OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /* | 5 /* |
6 * Checks for an extension error that occurred during the asynchronous call. | 6 * Checks for an extension error that occurred during the asynchronous call. |
7 * If an error occurs, will invoke the error callback and throw an exception. | 7 * If an error occurs, will invoke the error callback and throw an exception. |
8 * | 8 * |
9 * @param {function(!Error)} errCallback The callback to invoke for error | 9 * @param {function(!Error)} errCallback The callback to invoke for error |
10 * reporting. | 10 * reporting. |
11 */ | 11 */ |
12 function checkForExtensionError(errCallback) { | 12 function checkForExtensionError(errCallback) { |
13 if (typeof(chrome.extension.lastError) != 'undefined') { | 13 if (typeof(chrome.extension.lastError) != 'undefined') { |
14 var error = new Error(chrome.extension.lastError.message); | 14 var error = new Error(chrome.extension.lastError.message); |
15 errCallback(error); | 15 errCallback(error); |
16 throw error; | 16 throw error; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 /** | 20 /** |
21 * Captures a screenshot of the visible tab. | 21 * Captures a screenshot of the visible tab. |
22 * | 22 * |
23 * @param {function(string)} callback The callback to invoke with the base64 | 23 * @param {function(string)} callback The callback to invoke with the base64 |
24 * encoded PNG. | 24 * encoded PNG. |
25 * @param {function(!Error)} errCallback The callback to invoke for error | 25 * @param {function(!Error)} errCallback The callback to invoke for error |
26 * reporting. | 26 * reporting. |
27 */ | 27 */ |
28 function captureScreenshot(callback, errCallback) { | 28 function captureScreenshot(callback, errCallback) { |
29 chrome.tabs.captureVisibleTab({format:'png'}, function(dataUrl) { | 29 chrome.tabs.captureVisibleTab({format:'png'}, function(dataUrl) { |
| 30 if (chrome.extension.lastError && |
| 31 chrome.extension.lastError.message.indexOf('permission') != -1) { |
| 32 var error = new Error(chrome.extension.lastError.message); |
| 33 error.code = 103; // kForbidden |
| 34 errCallback(error); |
| 35 return; |
| 36 } |
30 checkForExtensionError(errCallback); | 37 checkForExtensionError(errCallback); |
31 var base64 = ';base64,'; | 38 var base64 = ';base64,'; |
32 callback(dataUrl.substr(dataUrl.indexOf(base64) + base64.length)) | 39 callback(dataUrl.substr(dataUrl.indexOf(base64) + base64.length)) |
33 }); | 40 }); |
34 } | 41 } |
35 | 42 |
36 /** | 43 /** |
37 * Gets info about the current window. | 44 * Gets info about the current window. |
38 * | 45 * |
39 * @param {function(*)} callback The callback to invoke with the window info. | 46 * @param {function(*)} callback The callback to invoke with the window info. |
(...skipping 17 matching lines...) Expand all Loading... |
57 */ | 64 */ |
58 function updateWindow(updateInfo, callback, errCallback) { | 65 function updateWindow(updateInfo, callback, errCallback) { |
59 chrome.windows.getCurrent({}, function(window) { | 66 chrome.windows.getCurrent({}, function(window) { |
60 checkForExtensionError(errCallback); | 67 checkForExtensionError(errCallback); |
61 chrome.windows.update(window.id, updateInfo, function(window) { | 68 chrome.windows.update(window.id, updateInfo, function(window) { |
62 checkForExtensionError(errCallback); | 69 checkForExtensionError(errCallback); |
63 callback(); | 70 callback(); |
64 }); | 71 }); |
65 }); | 72 }); |
66 } | 73 } |
OLD | NEW |