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 Defines the ScriptInstaller functions which install scripts | 6 * @fileoverview Defines the ScriptInstaller functions which install scripts |
7 * into the web page (not a content script) | 7 * into the web page (not a content script) |
8 * | 8 * |
9 */ | 9 */ |
10 | 10 |
11 goog.provide('cvox.ScriptInstaller'); | 11 goog.provide('cvox.ScriptInstaller'); |
12 | 12 |
13 goog.require('cvox.DomUtil'); | |
14 | 13 |
15 /** | 14 /** |
16 * URL pattern where we do not allow script installation. | 15 * URL pattern where we do not allow script installation. |
17 * @type {RegExp} | 16 * @type {RegExp} |
18 */ | 17 */ |
19 cvox.ScriptInstaller.blacklistPattern = /chrome:\/\/|chrome-extension:\/\//; | 18 cvox.ScriptInstaller.blacklistPattern = /chrome:\/\/|chrome-extension:\/\//; |
20 | 19 |
21 /** | 20 /** |
22 * Installs a script in the web page. | 21 * Installs a script in the web page. |
23 * @param {Array<string>} srcs An array of URLs of scripts. | 22 * @param {Array<string>} srcs An array of URLs of scripts. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 if (xhr.readyState == 4) { | 81 if (xhr.readyState == 4) { |
83 var scriptText = xhr.responseText; | 82 var scriptText = xhr.responseText; |
84 // Add a magic comment to the bottom of the file so that | 83 // Add a magic comment to the bottom of the file so that |
85 // Chrome knows the name of the script in the JavaScript debugger. | 84 // Chrome knows the name of the script in the JavaScript debugger. |
86 scriptText += '\n//# sourceURL=' + scriptSrc + '\n'; | 85 scriptText += '\n//# sourceURL=' + scriptSrc + '\n'; |
87 | 86 |
88 var apiScript = document.createElement('script'); | 87 var apiScript = document.createElement('script'); |
89 apiScript.type = 'text/javascript'; | 88 apiScript.type = 'text/javascript'; |
90 apiScript.setAttribute(uid, '1'); | 89 apiScript.setAttribute(uid, '1'); |
91 apiScript.textContent = scriptText; | 90 apiScript.textContent = scriptText; |
91 console.log('inst!'+scriptText); | |
dmazzoni
2017/03/09 00:26:36
remove debugging?
| |
92 if (opt_chromevoxScriptBase) { | 92 if (opt_chromevoxScriptBase) { |
93 apiScript.setAttribute('chromevoxScriptBase', | 93 apiScript.setAttribute('chromevoxScriptBase', |
94 opt_chromevoxScriptBase); | 94 opt_chromevoxScriptBase); |
95 } | 95 } |
96 cvox.DomUtil.addNodeToHead(apiScript); | 96 var p = document.head || document.body; |
dmazzoni
2017/03/09 00:26:36
Give this a clearer name like scriptOwner or somet
| |
97 p.appendChild(apiScript); | |
97 next(); | 98 next(); |
98 } | 99 } |
99 }; | 100 }; |
100 | 101 |
101 try { | 102 try { |
102 xhr.open('GET', url, true); | 103 xhr.open('GET', url, true); |
103 xhr.send(null); | 104 xhr.send(null); |
104 } catch (exception) { | 105 } catch (exception) { |
105 console.log('Warning: ChromeVox external script loading for ' + | 106 console.log('Warning: ChromeVox external script loading for ' + |
106 document.location + ' stopped after failing to install ' + scriptSrc); | 107 document.location + ' stopped after failing to install ' + scriptSrc); |
107 next(); | 108 next(); |
108 } | 109 } |
109 }; | 110 }; |
OLD | NEW |