| 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 21 matching lines...) Expand all Loading... |
| 32 * @constructor | 32 * @constructor |
| 33 * @implements {WebInspector.ContentProvider} | 33 * @implements {WebInspector.ContentProvider} |
| 34 */ | 34 */ |
| 35 WebInspector.ScriptContentProvider = function(script) | 35 WebInspector.ScriptContentProvider = function(script) |
| 36 { | 36 { |
| 37 this._mimeType = "text/javascript"; | 37 this._mimeType = "text/javascript"; |
| 38 this._script = script; | 38 this._script = script; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 WebInspector.ScriptContentProvider.prototype = { | 41 WebInspector.ScriptContentProvider.prototype = { |
| 42 /** |
| 43 * @param {function(string,string)} callback |
| 44 */ |
| 42 requestContent: function(callback) | 45 requestContent: function(callback) |
| 43 { | 46 { |
| 44 function didRequestSource(source) | 47 function didRequestSource(source) |
| 45 { | 48 { |
| 46 callback(this._mimeType, source); | 49 callback(this._mimeType, source); |
| 47 } | 50 } |
| 48 this._script.requestSource(didRequestSource.bind(this)); | 51 this._script.requestSource(didRequestSource.bind(this)); |
| 49 }, | 52 }, |
| 50 | 53 |
| 51 searchInContent: function(query, callback) | 54 /** |
| 55 * @param {string} query |
| 56 * @param {boolean} caseSensitive |
| 57 * @param {boolean} isRegex |
| 58 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 59 */ |
| 60 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 52 { | 61 { |
| 53 this._script.searchInContent(query, callback); | 62 this._script.searchInContent(query, caseSensitive, isRegex, callback); |
| 54 } | 63 } |
| 55 } | 64 } |
| 56 | 65 |
| 57 WebInspector.ScriptContentProvider.prototype.__proto__ = WebInspector.ContentPro
vider.prototype; | 66 WebInspector.ScriptContentProvider.prototype.__proto__ = WebInspector.ContentPro
vider.prototype; |
| 58 | 67 |
| 59 /** | 68 /** |
| 60 * @constructor | 69 * @constructor |
| 61 * @implements {WebInspector.ContentProvider} | 70 * @implements {WebInspector.ContentProvider} |
| 62 */ | 71 */ |
| 63 WebInspector.ConcatenatedScriptsContentProvider = function(scripts) | 72 WebInspector.ConcatenatedScriptsContentProvider = function(scripts) |
| 64 { | 73 { |
| 65 this._mimeType = "text/html"; | 74 this._mimeType = "text/html"; |
| 66 this._scripts = scripts; | 75 this._scripts = scripts; |
| 67 }; | 76 }; |
| 68 | 77 |
| 69 WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>"; | 78 WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>"; |
| 70 WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>"; | 79 WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>"; |
| 71 | 80 |
| 72 WebInspector.ConcatenatedScriptsContentProvider.prototype = { | 81 WebInspector.ConcatenatedScriptsContentProvider.prototype = { |
| 82 /** |
| 83 * @return {Array.<WebInspector.Script>} |
| 84 */ |
| 73 _sortedScripts: function() | 85 _sortedScripts: function() |
| 74 { | 86 { |
| 75 if (this._sortedScriptsArray) | 87 if (this._sortedScriptsArray) |
| 76 return this._sortedScriptsArray; | 88 return this._sortedScriptsArray; |
| 77 | 89 |
| 78 this._sortedScriptsArray = []; | 90 this._sortedScriptsArray = []; |
| 79 | 91 |
| 80 var scripts = this._scripts.slice(); | 92 var scripts = this._scripts.slice(); |
| 81 scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.co
lumnOffset - y.columnOffset; }); | 93 scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.co
lumnOffset - y.columnOffset; }); |
| 82 | 94 |
| 83 var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvide
r.scriptOpenTag.length; | 95 var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvide
r.scriptOpenTag.length; |
| 84 var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvid
er.scriptCloseTag.length; | 96 var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvid
er.scriptCloseTag.length; |
| 85 | 97 |
| 86 this._sortedScriptsArray.push(scripts[0]); | 98 this._sortedScriptsArray.push(scripts[0]); |
| 87 for (var i = 1; i < scripts.length; ++i) { | 99 for (var i = 1; i < scripts.length; ++i) { |
| 88 var previousScript = this._sortedScriptsArray[this._sortedScriptsArr
ay.length - 1]; | 100 var previousScript = this._sortedScriptsArray[this._sortedScriptsArr
ay.length - 1]; |
| 89 | 101 |
| 90 var lineNumber = previousScript.endLine; | 102 var lineNumber = previousScript.endLine; |
| 91 var columnNumber = previousScript.endColumn + scriptCloseTagLength +
scriptOpenTagLength; | 103 var columnNumber = previousScript.endColumn + scriptCloseTagLength +
scriptOpenTagLength; |
| 92 | 104 |
| 93 if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i]
.lineOffset && columnNumber <= scripts[i].columnOffset)) | 105 if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i]
.lineOffset && columnNumber <= scripts[i].columnOffset)) |
| 94 this._sortedScriptsArray.push(scripts[i]); | 106 this._sortedScriptsArray.push(scripts[i]); |
| 95 } | 107 } |
| 96 return this._sortedScriptsArray; | 108 return this._sortedScriptsArray; |
| 97 }, | 109 }, |
| 98 | 110 |
| 111 /** |
| 112 * @param {function(string,string)} callback |
| 113 */ |
| 99 requestContent: function(callback) | 114 requestContent: function(callback) |
| 100 { | 115 { |
| 101 var scripts = this._sortedScripts(); | 116 var scripts = this._sortedScripts(); |
| 102 var sources = []; | 117 var sources = []; |
| 103 function didRequestSource(source) | 118 function didRequestSource(source) |
| 104 { | 119 { |
| 105 sources.push(source); | 120 sources.push(source); |
| 106 if (sources.length == scripts.length) | 121 if (sources.length == scripts.length) |
| 107 callback(this._mimeType, this._concatenateScriptsContent(scripts
, sources)); | 122 callback(this._mimeType, this._concatenateScriptsContent(scripts
, sources)); |
| 108 } | 123 } |
| 109 for (var i = 0; i < scripts.length; ++i) | 124 for (var i = 0; i < scripts.length; ++i) |
| 110 scripts[i].requestSource(didRequestSource.bind(this)); | 125 scripts[i].requestSource(didRequestSource.bind(this)); |
| 111 }, | 126 }, |
| 112 | 127 |
| 113 searchInContent: function(query, callback) | 128 /** |
| 129 * @param {string} query |
| 130 * @param {boolean} caseSensitive |
| 131 * @param {boolean} isRegex |
| 132 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 133 */ |
| 134 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 114 { | 135 { |
| 115 var results = {}; | 136 var results = {}; |
| 116 var scripts = this._sortedScripts(); | 137 var scripts = this._sortedScripts(); |
| 117 var scriptsLeft = scripts.length; | 138 var scriptsLeft = scripts.length; |
| 118 | 139 |
| 119 function maybeCallback() | 140 function maybeCallback() |
| 120 { | 141 { |
| 121 if (scriptsLeft) | 142 if (scriptsLeft) |
| 122 return; | 143 return; |
| 123 | 144 |
| 124 var result = []; | 145 var result = []; |
| 125 for (var i = 0; i < scripts.length; ++i) | 146 for (var i = 0; i < scripts.length; ++i) |
| 126 result = result.concat(results[scripts[i].scriptId]); | 147 result = result.concat(results[scripts[i].scriptId]); |
| 127 callback(result); | 148 callback(result); |
| 128 } | 149 } |
| 129 | 150 |
| 151 /** |
| 152 * @param {WebInspector.Script} script |
| 153 * @param {Array.<PageAgent.SearchMatch>} searchMatches |
| 154 */ |
| 130 function searchCallback(script, searchMatches) | 155 function searchCallback(script, searchMatches) |
| 131 { | 156 { |
| 132 results[script.scriptId] = []; | 157 results[script.scriptId] = []; |
| 133 for (var i = 0; i < searchMatches.length; ++i) { | 158 for (var i = 0; i < searchMatches.length; ++i) { |
| 134 var searchMatch = {}; | 159 var searchMatch = new WebInspector.ContentProvider.SearchMatch(s
earchMatches[i].lineNumber + script.lineOffset, searchMatches[i].lineContent); |
| 135 searchMatch.lineNumber = searchMatches[i].lineNumber + script.li
neOffset; | |
| 136 searchMatch.lineContent = searchMatches[i].lineContent; | |
| 137 results[script.scriptId].push(searchMatch); | 160 results[script.scriptId].push(searchMatch); |
| 138 } | 161 } |
| 139 scriptsLeft--; | 162 scriptsLeft--; |
| 140 maybeCallback.call(this); | 163 maybeCallback.call(this); |
| 141 } | 164 } |
| 142 | 165 |
| 143 maybeCallback(); | 166 maybeCallback(); |
| 144 for (var i = 0; i < scripts.length; ++i) | 167 for (var i = 0; i < scripts.length; ++i) |
| 145 scripts[i].searchInContent(query, searchCallback.bind(this, scripts[
i])); | 168 scripts[i].searchInContent(query, caseSensitive, isRegex, searchCall
back.bind(this, scripts[i])); |
| 146 }, | 169 }, |
| 147 | 170 |
| 171 /** |
| 172 * @return {string} |
| 173 */ |
| 148 _concatenateScriptsContent: function(scripts, sources) | 174 _concatenateScriptsContent: function(scripts, sources) |
| 149 { | 175 { |
| 150 var content = ""; | 176 var content = ""; |
| 151 var lineNumber = 0; | 177 var lineNumber = 0; |
| 152 var columnNumber = 0; | 178 var columnNumber = 0; |
| 153 | 179 |
| 154 var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scri
ptOpenTag; | 180 var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scri
ptOpenTag; |
| 155 var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scr
iptCloseTag; | 181 var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scr
iptCloseTag; |
| 156 for (var i = 0; i < scripts.length; ++i) { | 182 for (var i = 0; i < scripts.length; ++i) { |
| 157 // Fill the gap with whitespace characters. | 183 // Fill the gap with whitespace characters. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 180 * @constructor | 206 * @constructor |
| 181 * @implements {WebInspector.ContentProvider} | 207 * @implements {WebInspector.ContentProvider} |
| 182 */ | 208 */ |
| 183 WebInspector.ResourceContentProvider = function(resource) | 209 WebInspector.ResourceContentProvider = function(resource) |
| 184 { | 210 { |
| 185 this._mimeType = resource.type === WebInspector.Resource.Type.Script ? "text
/javascript" : "text/html"; | 211 this._mimeType = resource.type === WebInspector.Resource.Type.Script ? "text
/javascript" : "text/html"; |
| 186 this._resource = resource; | 212 this._resource = resource; |
| 187 }; | 213 }; |
| 188 | 214 |
| 189 WebInspector.ResourceContentProvider.prototype = { | 215 WebInspector.ResourceContentProvider.prototype = { |
| 216 /** |
| 217 * @param {function(string,string)} callback |
| 218 */ |
| 190 requestContent: function(callback) | 219 requestContent: function(callback) |
| 191 { | 220 { |
| 192 function didRequestContent(content) | 221 function didRequestContent(content) |
| 193 { | 222 { |
| 194 callback(this._mimeType, content); | 223 callback(this._mimeType, content); |
| 195 } | 224 } |
| 196 this._resource.requestContent(didRequestContent.bind(this)); | 225 this._resource.requestContent(didRequestContent.bind(this)); |
| 197 }, | 226 }, |
| 198 | 227 |
| 199 searchInContent: function(query, callback) | 228 /** |
| 229 * @param {string} query |
| 230 * @param {boolean} caseSensitive |
| 231 * @param {boolean} isRegex |
| 232 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 233 */ |
| 234 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 200 { | 235 { |
| 201 this._resource.searchInContent(query, callback); | 236 this._resource.searchInContent(query, caseSensitive, isRegex, callback); |
| 202 } | 237 } |
| 203 } | 238 } |
| 204 | 239 |
| 205 WebInspector.ResourceContentProvider.prototype.__proto__ = WebInspector.ContentP
rovider.prototype; | 240 WebInspector.ResourceContentProvider.prototype.__proto__ = WebInspector.ContentP
rovider.prototype; |
| 206 | 241 |
| 207 /** | 242 /** |
| 208 * @constructor | 243 * @constructor |
| 209 * @implements {WebInspector.ContentProvider} | 244 * @implements {WebInspector.ContentProvider} |
| 210 */ | 245 */ |
| 211 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, compiler
SourceMappingProvider) | 246 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, compiler
SourceMappingProvider) |
| 212 { | 247 { |
| 213 this._mimeType = "text/javascript"; | 248 this._mimeType = "text/javascript"; |
| 214 this._sourceURL = sourceURL; | 249 this._sourceURL = sourceURL; |
| 215 this._compilerSourceMappingProvider = compilerSourceMappingProvider; | 250 this._compilerSourceMappingProvider = compilerSourceMappingProvider; |
| 216 }; | 251 }; |
| 217 | 252 |
| 218 WebInspector.CompilerSourceMappingContentProvider.prototype = { | 253 WebInspector.CompilerSourceMappingContentProvider.prototype = { |
| 254 /** |
| 255 * @param {function(string,string)} callback |
| 256 */ |
| 219 requestContent: function(callback) | 257 requestContent: function(callback) |
| 220 { | 258 { |
| 221 function didLoadSourceCode(sourceCode) | 259 function didLoadSourceCode(sourceCode) |
| 222 { | 260 { |
| 223 callback(this._mimeType, sourceCode); | 261 callback(this._mimeType, sourceCode); |
| 224 } | 262 } |
| 225 this._compilerSourceMappingProvider.loadSourceCode(this._sourceURL, didL
oadSourceCode.bind(this)); | 263 this._compilerSourceMappingProvider.loadSourceCode(this._sourceURL, didL
oadSourceCode.bind(this)); |
| 226 }, | 264 }, |
| 227 | 265 |
| 228 searchInContent: function(query, callback) | 266 /** |
| 267 * @param {string} query |
| 268 * @param {boolean} caseSensitive |
| 269 * @param {boolean} isRegex |
| 270 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 271 */ |
| 272 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 229 { | 273 { |
| 230 callback([]); | 274 callback([]); |
| 231 } | 275 } |
| 232 } | 276 } |
| 233 | 277 |
| 234 WebInspector.CompilerSourceMappingContentProvider.prototype.__proto__ = WebInspe
ctor.ContentProvider.prototype; | 278 WebInspector.CompilerSourceMappingContentProvider.prototype.__proto__ = WebInspe
ctor.ContentProvider.prototype; |
| 235 | 279 |
| 236 /** | 280 /** |
| 237 * @constructor | 281 * @constructor |
| 238 * @implements {WebInspector.ContentProvider} | 282 * @implements {WebInspector.ContentProvider} |
| 239 */ | 283 */ |
| 240 WebInspector.StaticContentProvider = function(mimeType, content) | 284 WebInspector.StaticContentProvider = function(mimeType, content) |
| 241 { | 285 { |
| 242 this._mimeType = mimeType; | 286 this._mimeType = mimeType; |
| 243 this._content = content; | 287 this._content = content; |
| 244 }; | 288 }; |
| 245 | 289 |
| 246 WebInspector.StaticContentProvider.prototype = { | 290 WebInspector.StaticContentProvider.prototype = { |
| 291 /** |
| 292 * @param {function(string,string)} callback |
| 293 */ |
| 247 requestContent: function(callback) | 294 requestContent: function(callback) |
| 248 { | 295 { |
| 249 callback(this._mimeType, this._content); | 296 callback(this._mimeType, this._content); |
| 250 }, | 297 }, |
| 251 | 298 |
| 252 searchInContent: function(query, callback) | 299 /** |
| 300 * @param {string} query |
| 301 * @param {boolean} caseSensitive |
| 302 * @param {boolean} isRegex |
| 303 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 304 */ |
| 305 searchInContent: function(query, caseSensitive, isRegex, callback) |
| 253 { | 306 { |
| 254 callback([]); | 307 callback([]); |
| 255 } | 308 } |
| 256 } | 309 } |
| 257 | 310 |
| 258 WebInspector.StaticContentProvider.prototype.__proto__ = WebInspector.ContentPro
vider.prototype; | 311 WebInspector.StaticContentProvider.prototype.__proto__ = WebInspector.ContentPro
vider.prototype; |
| OLD | NEW |