OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
7 | 7 |
8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
9 (function() { | 9 (function() { |
10 native function GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
11 native function StartRequest(); | 11 native function StartRequest(); |
12 native function GetChromeHidden(); | 12 native function GetChromeHidden(); |
13 native function GetNextRequestId(); | 13 native function GetNextRequestId(); |
14 native function Print(); | 14 native function Print(); |
15 | 15 |
16 native function GetCurrentPageActions(extensionId); | 16 native function GetCurrentPageActions(extensionId); |
17 native function GetExtensionViews(); | 17 native function GetExtensionViews(); |
18 native function GetNextContextMenuId(); | 18 native function GetNextContextMenuId(); |
19 native function GetNextTtsEventId(); | 19 native function GetNextTtsEventId(); |
20 native function OpenChannelToTab(); | 20 native function OpenChannelToTab(); |
21 native function GetRenderViewId(); | 21 native function GetRenderViewId(); |
22 native function SetIconCommon(); | 22 native function SetIconCommon(); |
23 native function GetUniqueSubEventName(eventName); | 23 native function GetUniqueSubEventName(eventName); |
24 native function GetLocalFileSystem(name, path); | 24 native function GetLocalFileSystem(name, path); |
25 native function DecodeJPEG(jpegImage); | 25 native function DecodeJPEG(jpegImage); |
26 native function CreateBlob(filePath); | 26 native function CreateBlob(filePath); |
| 27 native function SendResponseAck(requestId); |
27 | 28 |
28 var chromeHidden = GetChromeHidden(); | 29 var chromeHidden = GetChromeHidden(); |
29 | 30 |
30 if (!chrome) | 31 if (!chrome) |
31 chrome = {}; | 32 chrome = {}; |
32 | 33 |
33 function forEach(dict, f) { | 34 function forEach(dict, f) { |
34 for (key in dict) { | 35 for (key in dict) { |
35 if (dict.hasOwnProperty(key)) | 36 if (dict.hasOwnProperty(key)) |
36 f(key, dict[key]); | 37 f(key, dict[key]); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 172 } |
172 // JSON.stringify doesn't support a root object which is undefined. | 173 // JSON.stringify doesn't support a root object which is undefined. |
173 if (request.args === undefined) | 174 if (request.args === undefined) |
174 request.args = null; | 175 request.args = null; |
175 | 176 |
176 var sargs = opt_args.noStringify ? | 177 var sargs = opt_args.noStringify ? |
177 request.args : chromeHidden.JSON.stringify(request.args); | 178 request.args : chromeHidden.JSON.stringify(request.args); |
178 var nativeFunction = opt_args.nativeFunction || StartRequest; | 179 var nativeFunction = opt_args.nativeFunction || StartRequest; |
179 | 180 |
180 var requestId = GetNextRequestId(); | 181 var requestId = GetNextRequestId(); |
| 182 request.id = requestId; |
181 requests[requestId] = request; | 183 requests[requestId] = request; |
182 var hasCallback = | 184 var hasCallback = |
183 (request.callback || opt_args.customCallback) ? true : false; | 185 (request.callback || opt_args.customCallback) ? true : false; |
184 return nativeFunction(functionName, sargs, requestId, hasCallback, | 186 return nativeFunction(functionName, sargs, requestId, hasCallback, |
185 opt_args.forIOThread); | 187 opt_args.forIOThread); |
186 } | 188 } |
187 | 189 |
188 // --- Setup additional api's not currently handled in common/extensions/api | 190 // --- Setup additional api's not currently handled in common/extensions/api |
189 | 191 |
190 // WebRequestEvent object. This is used for special webRequest events with | 192 // WebRequestEvent object. This is used for special webRequest events with |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 }; | 761 }; |
760 | 762 |
761 apiFunctions["experimental.savePage.saveAsMHTML"].customCallback = | 763 apiFunctions["experimental.savePage.saveAsMHTML"].customCallback = |
762 function(name, request, response) { | 764 function(name, request, response) { |
763 var params = chromeHidden.JSON.parse(response); | 765 var params = chromeHidden.JSON.parse(response); |
764 var path = params.mhtmlFilePath; | 766 var path = params.mhtmlFilePath; |
765 var size = params.mhtmlFileLength; | 767 var size = params.mhtmlFileLength; |
766 | 768 |
767 if (request.callback) | 769 if (request.callback) |
768 request.callback(CreateBlob(path, size)); | 770 request.callback(CreateBlob(path, size)); |
| 771 request.callback = null; |
769 | 772 |
770 request.callback = null; | 773 // Notify the browser. Now that the blob is referenced from JavaScript, |
| 774 // the browser can drop its reference to it. |
| 775 SendResponseAck(request.id); |
771 }; | 776 }; |
772 | 777 |
773 apiFunctions["fileBrowserPrivate.requestLocalFileSystem"].customCallback = | 778 apiFunctions["fileBrowserPrivate.requestLocalFileSystem"].customCallback = |
774 function(name, request, response) { | 779 function(name, request, response) { |
775 var resp = response ? [chromeHidden.JSON.parse(response)] : []; | 780 var resp = response ? [chromeHidden.JSON.parse(response)] : []; |
776 var fs = null; | 781 var fs = null; |
777 if (!resp[0].error) | 782 if (!resp[0].error) |
778 fs = GetLocalFileSystem(resp[0].name, resp[0].path); | 783 fs = GetLocalFileSystem(resp[0].name, resp[0].path); |
779 if (request.callback) | 784 if (request.callback) |
780 request.callback(fs); | 785 request.callback(fs); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 | 1054 |
1050 if (!chrome.tts) | 1055 if (!chrome.tts) |
1051 chrome.tts = {}; | 1056 chrome.tts = {}; |
1052 | 1057 |
1053 if (!chrome.ttsEngine) | 1058 if (!chrome.ttsEngine) |
1054 chrome.ttsEngine = {}; | 1059 chrome.ttsEngine = {}; |
1055 | 1060 |
1056 if (!chrome.experimental.downloads) | 1061 if (!chrome.experimental.downloads) |
1057 chrome.experimental.downloads = {}; | 1062 chrome.experimental.downloads = {}; |
1058 })(); | 1063 })(); |
OLD | NEW |