Chromium Code Reviews| 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 /** @typedef {!{line: number, column: number}} */ | |
| 6 var ScriptPosition; | |
| 7 | |
| 5 /** | 8 /** |
| 6 * @constructor | 9 * @constructor |
| 7 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 10 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 8 * @param {!WebInspector.NetworkMapping} networkMapping | 11 * @param {!WebInspector.NetworkMapping} networkMapping |
| 12 * @implements {WebInspector.TargetManager.Observer} | |
| 9 */ | 13 */ |
| 10 WebInspector.BlackboxManager = function(debuggerWorkspaceBinding, networkMapping ) | 14 WebInspector.BlackboxManager = function(debuggerWorkspaceBinding, networkMapping ) |
| 11 { | 15 { |
| 12 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | 16 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; |
| 13 this._networkMapping = networkMapping; | 17 this._networkMapping = networkMapping; |
| 14 | 18 |
| 15 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this ); | 19 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this ); |
| 16 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, th is); | 20 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, th is); |
| 17 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this. _patternChanged.bind(this)); | 21 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this. _patternChanged.bind(this)); |
| 18 WebInspector.moduleSetting("skipContentScripts").addChangeListener(this._pat ternChanged.bind(this)); | 22 WebInspector.moduleSetting("skipContentScripts").addChangeListener(this._pat ternChanged.bind(this)); |
| 19 | 23 |
| 20 /** @type {!Map<!WebInspector.DebuggerModel, !Map<string, !Array<!DebuggerAg ent.ScriptPosition>>>} */ | 24 /** @type {!Map<!WebInspector.DebuggerModel, !Map<string, !Array<!ScriptPosi tion>>>} */ |
| 21 this._debuggerModelData = new Map(); | 25 this._debuggerModelData = new Map(); |
| 22 /** @type {!Map<string, boolean>} */ | 26 /** @type {!Map<string, boolean>} */ |
| 23 this._isBlackboxedURLCache = new Map(); | 27 this._isBlackboxedURLCache = new Map(); |
| 28 | |
| 29 WebInspector.targetManager.observeTargets(this); | |
| 24 } | 30 } |
| 25 | 31 |
| 26 WebInspector.BlackboxManager.prototype = { | 32 WebInspector.BlackboxManager.prototype = { |
| 27 /** | 33 /** |
| 28 * @param {function(!WebInspector.Event)} listener | 34 * @param {function(!WebInspector.Event)} listener |
| 29 * @param {!Object=} thisObject | 35 * @param {!Object=} thisObject |
| 30 */ | 36 */ |
| 31 addChangeListener: function(listener, thisObject) | 37 addChangeListener: function(listener, thisObject) |
| 32 { | 38 { |
| 33 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(l istener, thisObject); | 39 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(l istener, thisObject); |
| 34 }, | 40 }, |
| 35 | 41 |
| 36 /** | 42 /** |
| 37 * @param {function(!WebInspector.Event)} listener | 43 * @param {function(!WebInspector.Event)} listener |
| 38 * @param {!Object=} thisObject | 44 * @param {!Object=} thisObject |
| 39 */ | 45 */ |
| 40 removeChangeListener: function(listener, thisObject) | 46 removeChangeListener: function(listener, thisObject) |
| 41 { | 47 { |
| 42 WebInspector.moduleSetting("skipStackFramesPattern").removeChangeListene r(listener, thisObject); | 48 WebInspector.moduleSetting("skipStackFramesPattern").removeChangeListene r(listener, thisObject); |
| 43 }, | 49 }, |
| 44 | 50 |
| 45 /** | 51 /** |
| 52 * @override | |
| 53 * @param {!WebInspector.Target} target | |
| 54 */ | |
| 55 targetAdded: function(target) | |
| 56 { | |
| 57 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | |
| 58 if (debuggerModel) | |
| 59 this._addBlackboxPatterns(debuggerModel); | |
| 60 }, | |
| 61 | |
| 62 /** | |
| 63 * @override | |
| 64 * @param {!WebInspector.Target} target | |
| 65 */ | |
| 66 targetRemoved: function(target) | |
| 67 { | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * @param {!WebInspector.DebuggerModel} debuggerModel | |
| 72 * @return {!Promise<boolean>} | |
| 73 */ | |
| 74 _addBlackboxPatterns: function(debuggerModel) | |
| 75 { | |
| 76 var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern") .getAsArray(); | |
| 77 var patterns = /** @type {!Array<string>} */([]); | |
| 78 for (var item of regexPatterns) { | |
| 79 if (!item.disabled && item.pattern) | |
| 80 patterns.push(item.pattern); | |
| 81 } | |
| 82 return debuggerModel.setBlackboxPatterns(patterns); | |
| 83 }, | |
| 84 | |
| 85 /** | |
| 46 * @param {!WebInspector.DebuggerModel.Location} location | 86 * @param {!WebInspector.DebuggerModel.Location} location |
| 47 * @return {boolean} | 87 * @return {boolean} |
| 48 */ | 88 */ |
| 49 isBlackboxedRawLocation: function(location) | 89 isBlackboxedRawLocation: function(location) |
| 50 { | 90 { |
| 51 var positions = this._scriptPositions(location.script()); | 91 var positions = this._scriptPositions(location.script()); |
| 52 if (!positions) | 92 if (!positions) |
| 53 return this._isBlackboxedScript(location.script()); | 93 return this._isBlackboxedScript(location.script()); |
| 54 var index = positions.lowerBound(location, comparator); | 94 var index = positions.lowerBound(location, comparator); |
| 55 return !!(index % 2); | 95 return !!(index % 2); |
| 56 | 96 |
| 57 /** | 97 /** |
| 58 * @param {!WebInspector.DebuggerModel.Location} a | 98 * @param {!WebInspector.DebuggerModel.Location} a |
| 59 * @param {!DebuggerAgent.ScriptPosition} b | 99 * @param {!ScriptPosition} b |
| 60 * @return {number} | 100 * @return {number} |
| 61 */ | 101 */ |
| 62 function comparator(a, b) | 102 function comparator(a, b) |
| 63 { | 103 { |
| 64 if (a.lineNumber !== b.line) | 104 if (a.lineNumber !== b.line) |
| 65 return a.lineNumber - b.line; | 105 return a.lineNumber - b.line; |
| 66 return a.columnNumber - b.column; | 106 return a.columnNumber - b.column; |
| 67 } | 107 } |
| 68 }, | 108 }, |
| 69 | 109 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 return Promise.resolve(); | 149 return Promise.resolve(); |
| 110 var previousScriptState = this._scriptPositions(script); | 150 var previousScriptState = this._scriptPositions(script); |
| 111 if (!previousScriptState) | 151 if (!previousScriptState) |
| 112 return Promise.resolve(); | 152 return Promise.resolve(); |
| 113 | 153 |
| 114 var mappings = sourceMap.mappings().slice(); | 154 var mappings = sourceMap.mappings().slice(); |
| 115 mappings.sort(mappingComparator); | 155 mappings.sort(mappingComparator); |
| 116 | 156 |
| 117 if (!mappings.length) { | 157 if (!mappings.length) { |
| 118 if (previousScriptState.length > 0) | 158 if (previousScriptState.length > 0) |
| 119 return this._setScriptState(script, []); | 159 return this._setScriptState(script, null); |
| 120 return Promise.resolve(); | 160 return Promise.resolve(); |
| 121 } | 161 } |
| 122 | 162 |
| 123 var currentBlackboxed = false; | 163 var ranges = []; |
| 124 var isBlackboxed = false; | 164 var prevMapping = null; |
| 125 var positions = []; | 165 for (var mapping of mappings) { |
| 126 // If content in script file begin is not mapped and one or more ranges are blackboxed then blackbox it. | 166 if (mapping.sourceURL && !this.isBlackboxedURL(mapping.sourceURL)) { |
| 127 if (mappings[0].lineNumber !== 0 || mappings[0].columnNumber !== 0) { | 167 prevMapping = mapping; |
| 128 positions.push({ line: 0, column: 0}); | 168 continue; |
| 129 currentBlackboxed = true; | 169 } |
| 170 if (prevMapping) | |
| 171 ranges.push({ startLine: prevMapping.lineNumber, startColumn: pr evMapping.columnNumber, endLine: mapping.lineNumber, endColumn: mapping.columnNu mber }); | |
| 172 else | |
| 173 ranges.push({ startLine: 0, startColumn: 0, endLine: mapping.lin eNumber, endColumn: mapping.columnNumber }); | |
|
dgozman
2016/04/20 02:06:40
Let's send merged ranges.
| |
| 174 prevMapping = mapping; | |
| 130 } | 175 } |
| 131 for (var mapping of mappings) { | 176 return this._setScriptState(script, ranges); |
| 132 if (mapping.sourceURL && currentBlackboxed !== this.isBlackboxedURL( mapping.sourceURL)) { | |
| 133 positions.push({ line: mapping.lineNumber, column: mapping.colum nNumber }); | |
| 134 currentBlackboxed = !currentBlackboxed; | |
| 135 } | |
| 136 isBlackboxed = currentBlackboxed || isBlackboxed; | |
| 137 } | |
| 138 return this._setScriptState(script, !isBlackboxed ? [] : positions); | |
| 139 /** | 177 /** |
| 140 * @param {!WebInspector.SourceMapEntry} a | 178 * @param {!WebInspector.SourceMapEntry} a |
| 141 * @param {!WebInspector.SourceMapEntry} b | 179 * @param {!WebInspector.SourceMapEntry} b |
| 142 * @return {number} | 180 * @return {number} |
| 143 */ | 181 */ |
| 144 function mappingComparator(a, b) | 182 function mappingComparator(a, b) |
| 145 { | 183 { |
| 146 if (a.lineNumber !== b.lineNumber) | 184 if (a.lineNumber !== b.lineNumber) |
| 147 return a.lineNumber - b.lineNumber; | 185 return a.lineNumber - b.lineNumber; |
| 148 return a.columnNumber - b.columnNumber; | 186 return a.columnNumber - b.columnNumber; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 289 } |
| 252 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPat terns); | 290 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPat terns); |
| 253 }, | 291 }, |
| 254 | 292 |
| 255 _patternChanged: function() | 293 _patternChanged: function() |
| 256 { | 294 { |
| 257 this._isBlackboxedURLCache.clear(); | 295 this._isBlackboxedURLCache.clear(); |
| 258 | 296 |
| 259 var promises = []; | 297 var promises = []; |
| 260 for (var debuggerModel of WebInspector.DebuggerModel.instances()) { | 298 for (var debuggerModel of WebInspector.DebuggerModel.instances()) { |
| 299 promises.push(this._addBlackboxPatterns.bind(this, debuggerModel)); | |
| 261 for (var scriptId in debuggerModel.scripts) { | 300 for (var scriptId in debuggerModel.scripts) { |
| 262 var script = debuggerModel.scripts[scriptId]; | 301 var script = debuggerModel.scripts[scriptId]; |
| 263 promises.push(this._addScript(script) | 302 promises.push(this._addScript(script) |
| 264 .then(loadSourceMap.bind(this, script))); | 303 .then(loadSourceMap.bind(this, script))); |
| 265 } | 304 } |
| 266 } | 305 } |
| 267 Promise.all(promises).then(this._patternChangeFinishedForTests.bind(this )); | 306 Promise.all(promises).then(this._patternChangeFinishedForTests.bind(this )); |
| 268 | 307 |
| 269 /** | 308 /** |
| 270 * @param {!WebInspector.Script} script | 309 * @param {!WebInspector.Script} script |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 301 this._addScript(script); | 340 this._addScript(script); |
| 302 }, | 341 }, |
| 303 | 342 |
| 304 /** | 343 /** |
| 305 * @param {!WebInspector.Script} script | 344 * @param {!WebInspector.Script} script |
| 306 * @return {!Promise<undefined>} | 345 * @return {!Promise<undefined>} |
| 307 */ | 346 */ |
| 308 _addScript: function(script) | 347 _addScript: function(script) |
| 309 { | 348 { |
| 310 var blackboxed = this._isBlackboxedScript(script); | 349 var blackboxed = this._isBlackboxedScript(script); |
| 311 return this._setScriptState(script, blackboxed ? [ { line: 0, column: 0 } ] : []); | 350 return this._setScriptState(script, blackboxed ? null : []); |
| 312 }, | 351 }, |
| 313 | 352 |
| 314 /** | 353 /** |
| 315 * @param {!WebInspector.Script} script | 354 * @param {!WebInspector.Script} script |
| 316 * @return {boolean} | 355 * @return {boolean} |
| 317 */ | 356 */ |
| 318 _isBlackboxedScript: function(script) | 357 _isBlackboxedScript: function(script) |
| 319 { | 358 { |
| 320 return this.isBlackboxedURL(script.sourceURL, script.isContentScript()); | 359 return this.isBlackboxedURL(script.sourceURL, script.isContentScript()); |
| 321 }, | 360 }, |
| 322 | 361 |
| 323 /** | 362 /** |
| 324 * @param {!WebInspector.Script} script | 363 * @param {!WebInspector.Script} script |
| 325 * @return {?Array<!DebuggerAgent.ScriptPosition>} | 364 * @return {?Array<!ScriptPosition>} |
| 326 */ | 365 */ |
| 327 _scriptPositions: function(script) | 366 _scriptPositions: function(script) |
| 328 { | 367 { |
| 329 if (this._debuggerModelData.has(script.debuggerModel)) | 368 if (this._debuggerModelData.has(script.debuggerModel)) |
| 330 return this._debuggerModelData.get(script.debuggerModel).get(script. scriptId) || null; | 369 return this._debuggerModelData.get(script.debuggerModel).get(script. scriptId) || null; |
| 331 return null; | 370 return null; |
| 332 }, | 371 }, |
| 333 | 372 |
| 334 /** | 373 /** |
| 335 * @param {!WebInspector.Script} script | 374 * @param {!WebInspector.Script} script |
| 336 * @param {!Array<!DebuggerAgent.ScriptPosition>} positions | 375 * @param {!Array<!ScriptPosition>} positions |
| 337 */ | 376 */ |
| 338 _setScriptPositions: function(script, positions) | 377 _setScriptPositions: function(script, positions) |
| 339 { | 378 { |
| 340 var debuggerModel = script.debuggerModel; | 379 var debuggerModel = script.debuggerModel; |
| 341 if (!this._debuggerModelData.has(debuggerModel)) | 380 if (!this._debuggerModelData.has(debuggerModel)) |
| 342 this._debuggerModelData.set(debuggerModel, new Map()); | 381 this._debuggerModelData.set(debuggerModel, new Map()); |
| 343 this._debuggerModelData.get(debuggerModel).set(script.scriptId, position s); | 382 this._debuggerModelData.get(debuggerModel).set(script.scriptId, position s); |
| 344 }, | 383 }, |
| 345 | 384 |
| 346 /** | 385 /** |
| 347 * @param {!WebInspector.Script} script | 386 * @param {!WebInspector.Script} script |
| 348 * @param {!Array<!DebuggerAgent.ScriptPosition>} positions | 387 * @param {?Array<!RuntimeAgent.SourceRange>} ranges |
| 349 * @return {!Promise<undefined>} | 388 * @return {!Promise<undefined>} |
| 350 */ | 389 */ |
| 351 _setScriptState: function(script, positions) | 390 _setScriptState: function(script, ranges) |
| 352 { | 391 { |
| 392 var positions = []; | |
| 393 if (ranges) { | |
| 394 for (var range of ranges) { | |
| 395 positions.push({ line: range.startLine, column: range.startColum n }); | |
| 396 positions.push({ line: range.endLine, column: range.endColumn }) ; | |
| 397 } | |
| 398 } else { | |
| 399 positions.push({ line: 0, column: 0 }); | |
| 400 } | |
| 401 | |
| 353 var previousScriptState = this._scriptPositions(script); | 402 var previousScriptState = this._scriptPositions(script); |
| 354 if (previousScriptState) { | 403 if (previousScriptState) { |
| 355 var hasChanged = false; | 404 var hasChanged = false; |
| 356 hasChanged = previousScriptState.length !== positions.length; | 405 hasChanged = previousScriptState.length !== positions.length; |
| 357 for (var i = 0; !hasChanged && i < positions.length; ++i) | 406 for (var i = 0; !hasChanged && i < positions.length; ++i) |
| 358 hasChanged = positions[i].line !== previousScriptState[i].line | | positions[i].column !== previousScriptState[i].column; | 407 hasChanged = positions[i].line !== previousScriptState[i].line | | positions[i].column !== previousScriptState[i].column; |
| 359 if (!hasChanged) | 408 if (!hasChanged) |
| 360 return Promise.resolve(); | 409 return Promise.resolve(); |
| 361 } else { | 410 } else { |
| 362 if (positions.length === 0) | 411 if (positions.length === 0) |
| 363 return Promise.resolve().then(updateState.bind(this, false)); | 412 return Promise.resolve().then(updateState.bind(this, false)); |
| 364 } | 413 } |
| 365 | 414 |
| 366 return script.setBlackboxedRanges(positions).then(updateState.bind(this) ); | 415 return script.setBlackboxedRanges(ranges).then(updateState.bind(this)); |
| 367 | 416 |
| 368 /** | 417 /** |
| 369 * @param {boolean} success | 418 * @param {boolean} success |
| 370 * @this {WebInspector.BlackboxManager} | 419 * @this {WebInspector.BlackboxManager} |
| 371 */ | 420 */ |
| 372 function updateState(success) | 421 function updateState(success) |
| 373 { | 422 { |
| 374 if (success) { | 423 if (success) { |
| 375 this._setScriptPositions(script, positions); | 424 this._setScriptPositions(script, positions); |
| 376 this._debuggerWorkspaceBinding.updateLocations(script); | 425 this._debuggerWorkspaceBinding.updateLocations(script); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 if (scheme === "chrome-extension") | 461 if (scheme === "chrome-extension") |
| 413 prefix += parsedURL.host + "\\b"; | 462 prefix += parsedURL.host + "\\b"; |
| 414 prefix += ".*"; | 463 prefix += ".*"; |
| 415 } | 464 } |
| 416 return prefix + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\ b"); | 465 return prefix + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\ b"); |
| 417 } | 466 } |
| 418 } | 467 } |
| 419 | 468 |
| 420 /** @type {!WebInspector.BlackboxManager} */ | 469 /** @type {!WebInspector.BlackboxManager} */ |
| 421 WebInspector.blackboxManager; | 470 WebInspector.blackboxManager; |
| OLD | NEW |