OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @implements {WebInspector.ContentProvider} | 33 * @implements {WebInspector.ContentProvider} |
34 * @param {!Array.<!WebInspector.Script>} scripts | |
35 */ | |
36 WebInspector.ConcatenatedScriptsContentProvider = function(scripts) | |
37 { | |
38 this._scripts = scripts; | |
39 } | |
40 | |
41 WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>"; | |
42 WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>"; | |
43 | |
44 WebInspector.ConcatenatedScriptsContentProvider.prototype = { | |
45 /** | |
46 * @return {!Array.<!WebInspector.Script>} | |
47 */ | |
48 _sortedScripts: function() | |
49 { | |
50 if (this._sortedScriptsArray) | |
51 return this._sortedScriptsArray; | |
52 | |
53 this._sortedScriptsArray = []; | |
54 | |
55 var scripts = this._scripts.slice(); | |
56 scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.co
lumnOffset - y.columnOffset; }); | |
57 | |
58 var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvide
r.scriptOpenTag.length; | |
59 var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvid
er.scriptCloseTag.length; | |
60 | |
61 this._sortedScriptsArray.push(scripts[0]); | |
62 for (var i = 1; i < scripts.length; ++i) { | |
63 var previousScript = this._sortedScriptsArray[this._sortedScriptsArr
ay.length - 1]; | |
64 | |
65 var lineNumber = previousScript.endLine; | |
66 var columnNumber = previousScript.endColumn + scriptCloseTagLength +
scriptOpenTagLength; | |
67 | |
68 if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i]
.lineOffset && columnNumber <= scripts[i].columnOffset)) | |
69 this._sortedScriptsArray.push(scripts[i]); | |
70 } | |
71 return this._sortedScriptsArray; | |
72 }, | |
73 | |
74 /** | |
75 * @override | |
76 * @return {string} | |
77 */ | |
78 contentURL: function() | |
79 { | |
80 return ""; | |
81 }, | |
82 | |
83 /** | |
84 * @override | |
85 * @return {!WebInspector.ResourceType} | |
86 */ | |
87 contentType: function() | |
88 { | |
89 return WebInspector.resourceTypes.Document; | |
90 }, | |
91 | |
92 /** | |
93 * @override | |
94 * @param {function(?string)} callback | |
95 */ | |
96 requestContent: function(callback) | |
97 { | |
98 var scripts = this._sortedScripts(); | |
99 var sources = []; | |
100 | |
101 /** | |
102 * @param {?string} content | |
103 * @this {WebInspector.ConcatenatedScriptsContentProvider} | |
104 */ | |
105 function didRequestSource(content) | |
106 { | |
107 sources.push(content); | |
108 if (sources.length == scripts.length) | |
109 callback(this._concatenateScriptsContent(scripts, sources)); | |
110 } | |
111 for (var i = 0; i < scripts.length; ++i) | |
112 scripts[i].requestContent(didRequestSource.bind(this)); | |
113 }, | |
114 | |
115 /** | |
116 * @override | |
117 * @param {string} query | |
118 * @param {boolean} caseSensitive | |
119 * @param {boolean} isRegex | |
120 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | |
121 */ | |
122 searchInContent: function(query, caseSensitive, isRegex, callback) | |
123 { | |
124 var results = {}; | |
125 var scripts = this._sortedScripts(); | |
126 var scriptsLeft = scripts.length; | |
127 | |
128 function maybeCallback() | |
129 { | |
130 if (scriptsLeft) | |
131 return; | |
132 | |
133 var result = []; | |
134 for (var i = 0; i < scripts.length; ++i) | |
135 result = result.concat(results[scripts[i].scriptId]); | |
136 callback(result); | |
137 } | |
138 | |
139 /** | |
140 * @param {!WebInspector.Script} script | |
141 * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches | |
142 */ | |
143 function searchCallback(script, searchMatches) | |
144 { | |
145 results[script.scriptId] = []; | |
146 for (var i = 0; i < searchMatches.length; ++i) { | |
147 var searchMatch = new WebInspector.ContentProvider.SearchMatch(s
earchMatches[i].lineNumber + script.lineOffset, searchMatches[i].lineContent); | |
148 results[script.scriptId].push(searchMatch); | |
149 } | |
150 scriptsLeft--; | |
151 maybeCallback(); | |
152 } | |
153 | |
154 maybeCallback(); | |
155 for (var i = 0; i < scripts.length; ++i) | |
156 scripts[i].searchInContent(query, caseSensitive, isRegex, searchCall
back.bind(null, scripts[i])); | |
157 }, | |
158 | |
159 /** | |
160 * @return {string} | |
161 */ | |
162 _concatenateScriptsContent: function(scripts, sources) | |
163 { | |
164 var content = ""; | |
165 var lineNumber = 0; | |
166 var columnNumber = 0; | |
167 | |
168 var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scri
ptOpenTag; | |
169 var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scr
iptCloseTag; | |
170 for (var i = 0; i < scripts.length; ++i) { | |
171 // Fill the gap with whitespace characters. | |
172 for (var newLinesCount = scripts[i].lineOffset - lineNumber; newLine
sCount > 0; --newLinesCount) { | |
173 columnNumber = 0; | |
174 content += "\n"; | |
175 } | |
176 for (var spacesCount = scripts[i].columnOffset - columnNumber - scri
ptOpenTag.length; spacesCount > 0; --spacesCount) | |
177 content += " "; | |
178 | |
179 // Add script tag. | |
180 content += scriptOpenTag; | |
181 content += sources[i]; | |
182 content += scriptCloseTag; | |
183 lineNumber = scripts[i].endLine; | |
184 columnNumber = scripts[i].endColumn + scriptCloseTag.length; | |
185 } | |
186 | |
187 return content; | |
188 } | |
189 } | |
190 | |
191 /** | |
192 * @constructor | |
193 * @implements {WebInspector.ContentProvider} | |
194 * @param {string} sourceURL | 34 * @param {string} sourceURL |
195 * @param {!WebInspector.ResourceType} contentType | 35 * @param {!WebInspector.ResourceType} contentType |
196 */ | 36 */ |
197 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, contentT
ype) | 37 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, contentT
ype) |
198 { | 38 { |
199 this._sourceURL = sourceURL; | 39 this._sourceURL = sourceURL; |
200 this._contentType = contentType; | 40 this._contentType = contentType; |
201 } | 41 } |
202 | 42 |
203 WebInspector.CompilerSourceMappingContentProvider.prototype = { | 43 WebInspector.CompilerSourceMappingContentProvider.prototype = { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 { | 103 { |
264 if (typeof content !== "string") { | 104 if (typeof content !== "string") { |
265 callback([]); | 105 callback([]); |
266 return; | 106 return; |
267 } | 107 } |
268 | 108 |
269 callback(WebInspector.ContentProvider.performSearchInContent(content
, query, caseSensitive, isRegex)); | 109 callback(WebInspector.ContentProvider.performSearchInContent(content
, query, caseSensitive, isRegex)); |
270 } | 110 } |
271 } | 111 } |
272 } | 112 } |
OLD | NEW |