OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview Code to execute before Closure's base.js. | 6 * @fileoverview Code to execute before Closure's base.js. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 18 matching lines...) Expand all Loading... |
29 /** | 29 /** |
30 * Custom function for importing ChromeVox scripts. | 30 * Custom function for importing ChromeVox scripts. |
31 * @param {string} src The JS file to import. | 31 * @param {string} src The JS file to import. |
32 * @return {boolean} Whether the script was imported. | 32 * @return {boolean} Whether the script was imported. |
33 */ | 33 */ |
34 window.CLOSURE_IMPORT_SCRIPT = function(src) { | 34 window.CLOSURE_IMPORT_SCRIPT = function(src) { |
35 // Only run our version of the import script | 35 // Only run our version of the import script |
36 // when trying to inject ChromeVox scripts. | 36 // when trying to inject ChromeVox scripts. |
37 // TODO(lazyboy): Use URL instead. | 37 // TODO(lazyboy): Use URL instead. |
38 if (src.startsWith('chrome-extension://')) { | 38 if (src.startsWith('chrome-extension://')) { |
39 if (!goog.inHtmlDocument_() || | 39 if (!goog.inHtmlDocument_() || goog.dependencies_.written[src]) { |
40 goog.dependencies_.written[src]) { | |
41 return false; | 40 return false; |
42 } | 41 } |
43 goog.dependencies_.written[src] = true; | 42 goog.dependencies_.written[src] = true; |
44 function loadNextScript() { | 43 function loadNextScript() { |
45 if (goog.global.queue_.length == 0) | 44 if (goog.global.queue_.length == 0) |
46 return; | 45 return; |
47 | 46 |
48 var src = goog.global.queue_[0]; | 47 var src = goog.global.queue_[0]; |
49 | 48 |
50 if (window.CLOSURE_USE_EXT_MESSAGES) { | 49 if (window.CLOSURE_USE_EXT_MESSAGES) { |
51 var relativeSrc = src.substr(src.indexOf('closure/..') + 11); | 50 var relativeSrc = src.substr(src.indexOf('closure/..') + 11); |
52 chrome.extension.sendMessage( | 51 chrome.extension.sendMessage( |
53 {'srcFile': relativeSrc}, | 52 {'srcFile': relativeSrc}, function(response) { |
54 function(response) { | |
55 try { | 53 try { |
56 eval(response['code']); | 54 eval(response['code']); |
57 } catch (e) { | 55 } catch (e) { |
58 console.error('Script error: ' + e + ' in ' + src); | 56 console.error('Script error: ' + e + ' in ' + src); |
59 } | 57 } |
60 goog.global.queue_ = goog.global.queue_.slice(1); | 58 goog.global.queue_ = goog.global.queue_.slice(1); |
61 loadNextScript(); | 59 loadNextScript(); |
62 }); | 60 }); |
63 return; | 61 return; |
64 } | 62 } |
(...skipping 21 matching lines...) Expand all Loading... |
86 } | 84 } |
87 goog.global.queue_.push(src); | 85 goog.global.queue_.push(src); |
88 if (goog.global.queue_.length == 1) { | 86 if (goog.global.queue_.length == 1) { |
89 loadNextScript(); | 87 loadNextScript(); |
90 } | 88 } |
91 return true; | 89 return true; |
92 } else { | 90 } else { |
93 return goog.writeScriptTag_(src); | 91 return goog.writeScriptTag_(src); |
94 } | 92 } |
95 }; | 93 }; |
OLD | NEW |