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(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 delete chrome.extension.lastError; | 90 delete chrome.extension.lastError; |
91 } else { | 91 } else { |
92 if (!error) { | 92 if (!error) { |
93 error = "Unknown error."; | 93 error = "Unknown error."; |
94 } | 94 } |
95 console.error("Error during " + name + ": " + error); | 95 console.error("Error during " + name + ": " + error); |
96 chrome.extension.lastError = { | 96 chrome.extension.lastError = { |
97 "message": error | 97 "message": error |
98 }; | 98 }; |
99 } | 99 } |
100 | |
101 if (request.customCallback) { | 100 if (request.customCallback) { |
102 request.customCallback(name, request, response); | 101 request.customCallback(name, request, response); |
103 } | 102 } |
104 | 103 |
105 if (request.callback) { | 104 if (request.callback) { |
106 // Callbacks currently only support one callback argument. | 105 // Callbacks currently only support one callback argument. |
107 var callbackArgs = response ? [chromeHidden.JSON.parse(response)] : []; | 106 var callbackArgs = response ? [chromeHidden.JSON.parse(response)] : []; |
108 | 107 |
109 // Validate callback in debug only -- and only when the | 108 // Validate callback in debug only -- and only when the |
110 // caller has provided a callback. Implementations of api | 109 // caller has provided a callback. Implementations of api |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 try { | 652 try { |
654 if (responseCallback) | 653 if (responseCallback) |
655 responseCallback(response); | 654 responseCallback(response); |
656 } finally { | 655 } finally { |
657 port.disconnect(); | 656 port.disconnect(); |
658 port = null; | 657 port = null; |
659 } | 658 } |
660 }); | 659 }); |
661 }; | 660 }; |
662 | 661 |
| 662 apiFunctions["fileSystem.resolveLocalFileSystemURL"].customCallback = |
| 663 function(name, request, response) { |
| 664 var method_callback = request.callback; |
| 665 var successCallback = function(entry) { |
| 666 method_callback(entry); |
| 667 }; |
| 668 var errorCallback = function(err) { |
| 669 chrome.extension.lastError = { |
| 670 "message": "File error " + err.code |
| 671 }; |
| 672 method_callback(null); |
| 673 }; |
| 674 var fs = null; |
| 675 var resp = response ? [chromeHidden.JSON.parse(response)] : null; |
| 676 if (!resp || !resp.length || !resp[0]) { |
| 677 errorCallback({"code": -255}); |
| 678 return; |
| 679 } else if (resp[0].error) { |
| 680 errorCallback({"code": resp[0].error}); |
| 681 return; |
| 682 } |
| 683 // Get local file system instance. |
| 684 fs = GetLocalFileSystem(resp[0].name, resp[0].path); |
| 685 if (resp[0].fileUrl.substr(0, resp[0].path.length) != resp[0].path) { |
| 686 errorCallback({"code": FileError.NOT_FOUND_ERR}); |
| 687 return; |
| 688 } |
| 689 var file_path = resp[0].fileUrl.substr(resp[0].path.length); |
| 690 // Try to get directory. |
| 691 fs.root.getDirectory(file_path, {create: false}, |
| 692 successCallback, function(err) { |
| 693 // Not a directory? Maybe it's a file then. |
| 694 fs.root.getFile(file_path, {create: false}, successCallback, |
| 695 errorCallback); |
| 696 }); |
| 697 request.callback = null; |
| 698 }; |
| 699 |
663 apiFunctions["fileBrowserPrivate.requestLocalFileSystem"].customCallback = | 700 apiFunctions["fileBrowserPrivate.requestLocalFileSystem"].customCallback = |
664 function(name, request, response) { | 701 function(name, request, response) { |
665 var resp = response ? [chromeHidden.JSON.parse(response)] : []; | 702 var resp = response ? [chromeHidden.JSON.parse(response)] : []; |
666 var fs = null; | 703 var fs = null; |
667 if (!resp[0].error) | 704 if (!resp[0].error) |
668 fs = GetLocalFileSystem(resp[0].name, resp[0].path); | 705 fs = GetLocalFileSystem(resp[0].name, resp[0].path); |
669 if (request.callback) | 706 if (request.callback) |
670 request.callback(fs); | 707 request.callback(fs); |
671 request.callback = null; | 708 request.callback = null; |
672 }; | 709 }; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 935 |
899 if (!chrome.experimental) | 936 if (!chrome.experimental) |
900 chrome.experimental = {}; | 937 chrome.experimental = {}; |
901 | 938 |
902 if (!chrome.experimental.accessibility) | 939 if (!chrome.experimental.accessibility) |
903 chrome.experimental.accessibility = {}; | 940 chrome.experimental.accessibility = {}; |
904 | 941 |
905 if (!chrome.experimental.tts) | 942 if (!chrome.experimental.tts) |
906 chrome.experimental.tts = {}; | 943 chrome.experimental.tts = {}; |
907 })(); | 944 })(); |
OLD | NEW |