| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 24 matching lines...) Expand all Loading... |
| 35 * @param {!WebInspector.Workspace} workspace | 35 * @param {!WebInspector.Workspace} workspace |
| 36 * @param {!WebInspector.NetworkMapping} networkMapping | 36 * @param {!WebInspector.NetworkMapping} networkMapping |
| 37 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 37 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 38 */ | 38 */ |
| 39 WebInspector.ResourceScriptMapping = function(debuggerModel, workspace, networkM
apping, debuggerWorkspaceBinding) | 39 WebInspector.ResourceScriptMapping = function(debuggerModel, workspace, networkM
apping, debuggerWorkspaceBinding) |
| 40 { | 40 { |
| 41 this._target = debuggerModel.target(); | 41 this._target = debuggerModel.target(); |
| 42 this._debuggerModel = debuggerModel; | 42 this._debuggerModel = debuggerModel; |
| 43 this._networkMapping = networkMapping; | 43 this._networkMapping = networkMapping; |
| 44 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | 44 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; |
| 45 /** @type {!Array.<!WebInspector.UISourceCode>} */ | 45 /** @type {!Set<!WebInspector.UISourceCode>} */ |
| 46 this._boundUISourceCodes = []; | 46 this._boundUISourceCodes = new Set(); |
| 47 | 47 |
| 48 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.ResourceScriptFil
e>} */ | 48 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.ResourceScriptFil
e>} */ |
| 49 this._uiSourceCodeToScriptFile = new Map(); | 49 this._uiSourceCodeToScriptFile = new Map(); |
| 50 | 50 |
| 51 this._eventListeners = [ | 51 this._eventListeners = [ |
| 52 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalO
bjectCleared, this._debuggerReset, this), | 52 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalO
bjectCleared, this._debuggerReset, this), |
| 53 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd
ed, this._uiSourceCodeAdded, this), | 53 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd
ed, this._uiSourceCodeAdded, this), |
| 54 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem
oved, this._uiSourceCodeRemoved, this) | 54 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem
oved, this._uiSourceCodeRemoved, this) |
| 55 ]; | 55 ]; |
| 56 } | 56 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 else | 153 else |
| 154 this._uiSourceCodeToScriptFile.remove(uiSourceCode); | 154 this._uiSourceCodeToScriptFile.remove(uiSourceCode); |
| 155 }, | 155 }, |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * @param {!WebInspector.Event} event | 158 * @param {!WebInspector.Event} event |
| 159 */ | 159 */ |
| 160 _uiSourceCodeAdded: function(event) | 160 _uiSourceCodeAdded: function(event) |
| 161 { | 161 { |
| 162 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); | 162 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); |
| 163 if (!this._networkMapping.networkURL(uiSourceCode)) | |
| 164 return; | |
| 165 if (uiSourceCode.isFromServiceProject()) | 163 if (uiSourceCode.isFromServiceProject()) |
| 166 return; | 164 return; |
| 167 | |
| 168 var scripts = this._scriptsForUISourceCode(uiSourceCode); | 165 var scripts = this._scriptsForUISourceCode(uiSourceCode); |
| 169 if (!scripts.length) | 166 if (!scripts.length) |
| 170 return; | 167 return; |
| 171 | 168 |
| 172 this._bindUISourceCodeToScripts(uiSourceCode, scripts); | 169 this._bindUISourceCodeToScripts(uiSourceCode, scripts); |
| 173 }, | 170 }, |
| 174 | 171 |
| 175 /** | 172 /** |
| 176 * @param {!WebInspector.Event} event | 173 * @param {!WebInspector.Event} event |
| 177 */ | 174 */ |
| 178 _uiSourceCodeRemoved: function(event) | 175 _uiSourceCodeRemoved: function(event) |
| 179 { | 176 { |
| 180 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); | 177 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); |
| 181 if (!this._networkMapping.networkURL(uiSourceCode)) | 178 if (uiSourceCode.isFromServiceProject() || !this._boundUISourceCodes.has
(uiSourceCode)) |
| 182 return; | |
| 183 if (uiSourceCode.isFromServiceProject()) | |
| 184 return; | 179 return; |
| 185 | 180 |
| 186 this._unbindUISourceCode(uiSourceCode); | 181 this._unbindUISourceCode(uiSourceCode); |
| 187 }, | 182 }, |
| 188 | 183 |
| 189 /** | 184 /** |
| 190 * @param {!WebInspector.UISourceCode} uiSourceCode | 185 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 191 */ | 186 */ |
| 192 _updateLocations: function(uiSourceCode) | 187 _updateLocations: function(uiSourceCode) |
| 193 { | 188 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 return this._networkMapping.uiSourceCodeForScriptURL(script.sourceURL, s
cript); | 204 return this._networkMapping.uiSourceCodeForScriptURL(script.sourceURL, s
cript); |
| 210 }, | 205 }, |
| 211 | 206 |
| 212 /** | 207 /** |
| 213 * @param {!WebInspector.UISourceCode} uiSourceCode | 208 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 214 * @return {!Array.<!WebInspector.Script>} | 209 * @return {!Array.<!WebInspector.Script>} |
| 215 */ | 210 */ |
| 216 _scriptsForUISourceCode: function(uiSourceCode) | 211 _scriptsForUISourceCode: function(uiSourceCode) |
| 217 { | 212 { |
| 218 var target = WebInspector.NetworkProject.targetForUISourceCode(uiSourceC
ode); | 213 var target = WebInspector.NetworkProject.targetForUISourceCode(uiSourceC
ode); |
| 219 if (target && target !== this._debuggerModel.target()) | 214 if (target !== this._debuggerModel.target()) |
| 220 return []; | 215 return []; |
| 221 if (!this._networkMapping.networkURL(uiSourceCode)) | 216 return this._debuggerModel.scriptsForSourceURL(uiSourceCode.url()); |
| 222 return []; | |
| 223 return this._debuggerModel.scriptsForSourceURL(this._networkMapping.netw
orkURL(uiSourceCode)); | |
| 224 }, | 217 }, |
| 225 | 218 |
| 226 /** | 219 /** |
| 227 * @param {!WebInspector.UISourceCode} uiSourceCode | 220 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 228 * @param {!Array.<!WebInspector.Script>} scripts | 221 * @param {!Array.<!WebInspector.Script>} scripts |
| 229 */ | 222 */ |
| 230 _bindUISourceCodeToScripts: function(uiSourceCode, scripts) | 223 _bindUISourceCodeToScripts: function(uiSourceCode, scripts) |
| 231 { | 224 { |
| 232 console.assert(scripts.length); | 225 console.assert(scripts.length); |
| 233 // Due to different listeners order, a script file could be created just
before uiSourceCode | 226 // Due to different listeners order, a script file could be created just
before uiSourceCode |
| 234 // for the corresponding script was created. Check that we don't create
scriptFile twice. | 227 // for the corresponding script was created. Check that we don't create
scriptFile twice. |
| 235 var boundScriptFile = this.scriptFile(uiSourceCode); | 228 var boundScriptFile = this.scriptFile(uiSourceCode); |
| 236 if (boundScriptFile && boundScriptFile._hasScripts(scripts)) | 229 if (boundScriptFile && boundScriptFile._hasScripts(scripts)) |
| 237 return; | 230 return; |
| 238 | 231 |
| 239 var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode,
scripts); | 232 var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode,
scripts); |
| 240 this._setScriptFile(uiSourceCode, scriptFile); | 233 this._setScriptFile(uiSourceCode, scriptFile); |
| 241 for (var i = 0; i < scripts.length; ++i) | 234 for (var i = 0; i < scripts.length; ++i) |
| 242 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); | 235 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); |
| 243 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo
de, this); | 236 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo
de, this); |
| 244 this._boundUISourceCodes.push(uiSourceCode); | 237 this._boundUISourceCodes.add(uiSourceCode); |
| 245 }, | 238 }, |
| 246 | 239 |
| 247 /** | 240 /** |
| 248 * @param {!WebInspector.UISourceCode} uiSourceCode | 241 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 249 */ | 242 */ |
| 250 _unbindUISourceCode: function(uiSourceCode) | 243 _unbindUISourceCode: function(uiSourceCode) |
| 251 { | 244 { |
| 252 var scriptFile = this.scriptFile(uiSourceCode); | 245 var scriptFile = this.scriptFile(uiSourceCode); |
| 253 if (scriptFile) { | 246 if (scriptFile) { |
| 254 scriptFile.dispose(); | 247 scriptFile.dispose(); |
| 255 this._setScriptFile(uiSourceCode, null); | 248 this._setScriptFile(uiSourceCode, null); |
| 256 } | 249 } |
| 257 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo
de, null); | 250 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo
de, null); |
| 258 this._boundUISourceCodes.remove(uiSourceCode); | 251 this._boundUISourceCodes.delete(uiSourceCode); |
| 259 }, | 252 }, |
| 260 | 253 |
| 261 _debuggerReset: function() | 254 _debuggerReset: function() |
| 262 { | 255 { |
| 263 var sourceCodes = this._boundUISourceCodes; | 256 for (var uiSourceCode of this._boundUISourceCodes.valuesArray()) |
| 264 this._boundUISourceCodes = []; | 257 this._unbindUISourceCode(uiSourceCode); |
| 265 sourceCodes.forEach(this._unbindUISourceCode.bind(this)); | 258 this._boundUISourceCodes.clear(); |
| 266 console.assert(!this._uiSourceCodeToScriptFile.size); | 259 console.assert(!this._uiSourceCodeToScriptFile.size); |
| 267 }, | 260 }, |
| 268 | 261 |
| 269 dispose: function() | 262 dispose: function() |
| 270 { | 263 { |
| 271 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 264 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
| 272 this._debuggerReset(); | 265 this._debuggerReset(); |
| 273 } | 266 } |
| 274 } | 267 } |
| 275 | 268 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 /** | 464 /** |
| 472 * @return {boolean} | 465 * @return {boolean} |
| 473 */ | 466 */ |
| 474 hasSourceMapURL: function() | 467 hasSourceMapURL: function() |
| 475 { | 468 { |
| 476 return this._script && !!this._script.sourceMapURL; | 469 return this._script && !!this._script.sourceMapURL; |
| 477 }, | 470 }, |
| 478 | 471 |
| 479 __proto__: WebInspector.Object.prototype | 472 __proto__: WebInspector.Object.prototype |
| 480 } | 473 } |
| OLD | NEW |