Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js b/third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js |
| index 0c827449e481f1cf49502fbd4f9c77e79043e360..5df1aa2f93671e37f7db0efddee0f26b0a700683 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js |
| @@ -37,6 +37,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| */ |
| constructor(uiSourceCode) { |
| super(uiSourceCode); |
| + this._debuggerSourceCode = uiSourceCode; |
| this._scriptsPanel = Sources.SourcesPanel.instance(); |
| this._breakpointManager = Bindings.breakpointManager; |
| @@ -59,8 +60,6 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this); |
| this.uiSourceCode().addEventListener( |
| - Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this); |
| - this.uiSourceCode().addEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this); |
| this.uiSourceCode().addEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this); |
| @@ -74,22 +73,25 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| /** @type {!Map.<!SDK.Target, !Bindings.ResourceScriptFile>}*/ |
| this._scriptFileForTarget = new Map(); |
| - var targets = SDK.targetManager.targets(); |
| - for (var i = 0; i < targets.length; ++i) { |
| - var scriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(uiSourceCode, targets[i]); |
| - if (scriptFile) |
| - this._updateScriptFile(targets[i]); |
| - } |
| - |
| - if (this._scriptFileForTarget.size || uiSourceCode.extension() === 'js' || |
| - uiSourceCode.project().type() === Workspace.projectTypes.Snippets) |
| - this._compiler = new Sources.JavaScriptCompiler(this); |
| Common.moduleSetting('skipStackFramesPattern').addChangeListener(this._showBlackboxInfobarIfNeeded, this); |
| Common.moduleSetting('skipContentScripts').addChangeListener(this._showBlackboxInfobarIfNeeded, this); |
| - this._showBlackboxInfobarIfNeeded(); |
| + |
| /** @type {!Map.<number, !Element>} */ |
| this._valueWidgets = new Map(); |
| + this.onBindingChanged(); |
| + } |
| + |
| + _updateDebuggerSourceCode() { |
| + if (this._debuggerSourceCode) { |
| + this._debuggerSourceCode.removeEventListener( |
| + Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this); |
| + } |
| + |
| + var binding = Persistence.persistence.binding(this.uiSourceCode()); |
| + this._debuggerSourceCode = binding ? binding.network : this.uiSourceCode(); |
| + this._debuggerSourceCode.addEventListener( |
| + Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this); |
| } |
| /** |
| @@ -98,7 +100,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| */ |
| syncToolbarItems() { |
| var result = super.syncToolbarItems(); |
| - var originURL = Bindings.CompilerScriptMapping.uiSourceCodeOrigin(this.uiSourceCode()); |
| + var originURL = Bindings.CompilerScriptMapping.uiSourceCodeOrigin(this._debuggerSourceCode); |
| if (originURL) { |
| var parsedURL = originURL.asParsedURL(); |
| if (parsedURL) |
| @@ -116,7 +118,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| } |
| _showBlackboxInfobarIfNeeded() { |
| - var uiSourceCode = this.uiSourceCode(); |
| + var uiSourceCode = this._debuggerSourceCode; |
| if (!uiSourceCode.contentType().hasScripts()) |
| return; |
| var projectType = uiSourceCode.project().type(); |
| @@ -209,7 +211,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| * @this {Sources.JavaScriptSourceFrame} |
| */ |
| function populate(resolve, reject) { |
| - var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0); |
| + var uiLocation = new Workspace.UILocation(this._debuggerSourceCode, lineNumber, 0); |
| this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation); |
| var breakpoints = this._lineBreakpointDecorations(lineNumber) |
| .map(decoration => decoration.breakpoint) |
| @@ -276,9 +278,9 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| * @this {Sources.JavaScriptSourceFrame} |
| */ |
| function populateSourceMapMembers() { |
| - if (this.uiSourceCode().project().type() === Workspace.projectTypes.Network && |
| + if (this._debuggerSourceCode.project().type() === Workspace.projectTypes.Network && |
| Common.moduleSetting('jsSourceMapsEnabled').get() && |
| - !Bindings.blackboxManager.isBlackboxedUISourceCode(this.uiSourceCode())) { |
| + !Bindings.blackboxManager.isBlackboxedUISourceCode(this._debuggerSourceCode)) { |
| if (this._scriptFileForTarget.size) { |
| var scriptFile = this._scriptFileForTarget.valuesArray()[0]; |
| var addSourceMapURLLabel = Common.UIString.capitalize('Add ^source ^map\u2026'); |
| @@ -442,7 +444,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| var evaluationText = line.substring(startHighlight, endHighlight + 1); |
| Sources.SourceMapNamesResolver |
| .resolveExpression( |
| - selectedCallFrame, evaluationText, this.uiSourceCode(), lineNumber, startHighlight, endHighlight) |
| + selectedCallFrame, evaluationText, this._debuggerSourceCode, lineNumber, startHighlight, endHighlight) |
| .then(onResolve.bind(this)); |
| /** |
| @@ -595,8 +597,8 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| var functionUILocation = Bindings.debuggerWorkspaceBinding.rawLocationToUILocation( |
| /** @type {!SDK.DebuggerModel.Location} */ (callFrame.functionLocation())); |
| var executionUILocation = Bindings.debuggerWorkspaceBinding.rawLocationToUILocation(callFrame.location()); |
| - if (functionUILocation.uiSourceCode !== this.uiSourceCode() || |
| - executionUILocation.uiSourceCode !== this.uiSourceCode()) { |
| + if (functionUILocation.uiSourceCode !== this._debuggerSourceCode || |
| + executionUILocation.uiSourceCode !== this._debuggerSourceCode) { |
| this._clearValueWidgets(); |
| return; |
| } |
| @@ -876,7 +878,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| */ |
| _shouldIgnoreExternalBreakpointEvents(event) { |
| var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation); |
| - if (uiLocation.uiSourceCode !== this.uiSourceCode() || !this.loaded) |
| + if (uiLocation.uiSourceCode !== this._debuggerSourceCode || !this.loaded) |
| return true; |
| if (this._supportsEnabledBreakpointsWhileEditing()) |
| return false; |
| @@ -998,6 +1000,35 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| } |
| /** |
| + * @override |
| + */ |
| + onBindingChanged() { |
| + this._updateDebuggerSourceCode(); |
| + this._updateScriptFiles(); |
| + this._refreshBreakpoints(); |
| + |
| + var canLiveCompileJavascript = this._scriptFileForTarget.size || this._debuggerSourceCode.extension() === 'js' || |
| + this._debuggerSourceCode.project().type() === Workspace.projectTypes.Snippets; |
| + if (!!canLiveCompileJavascript !== !!this._compiler) |
| + this._compiler = canLiveCompileJavascript ? new Sources.JavaScriptCompiler(this) : null; |
| + |
| + this._showBlackboxInfobarIfNeeded(); |
| + this._updateLinesWithoutMappingHighlight(); |
| + } |
| + |
| + _refreshBreakpoints() { |
| + if (!this.loaded) |
| + return; |
| + for (var lineDecoration of this._breakpointDecorations.valuesArray()) { |
| + this._breakpointDecorations.delete(lineDecoration); |
| + this._updateBreakpointDecoration(lineDecoration); |
| + } |
| + var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._debuggerSourceCode); |
| + for (var i = 0; i < breakpointLocations.length; ++i) |
| + this._breakpointAdded(/** @type {!Common.Event} */ ({data: breakpointLocations[i]})); |
|
dgozman
2016/12/06 01:14:27
Let's do this properly please.
lushnikov
2016/12/06 02:21:05
Done.
|
| + } |
| + |
| + /** |
| * @param {!Common.Event} event |
| */ |
| _onSourceMappingChanged(event) { |
| @@ -1009,7 +1040,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| _updateLinesWithoutMappingHighlight() { |
| var linesCount = this.textEditor.linesCount; |
| for (var i = 0; i < linesCount; ++i) { |
| - var lineHasMapping = Bindings.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCode(), i); |
| + var lineHasMapping = Bindings.debuggerWorkspaceBinding.uiLineHasMapping(this._debuggerSourceCode, i); |
| if (!lineHasMapping) |
| this._hasLineWithoutMapping = true; |
| if (this._hasLineWithoutMapping) |
| @@ -1017,12 +1048,20 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| } |
| } |
| + _updateScriptFiles() { |
| + for (var target of SDK.targetManager.targets()) { |
| + var scriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(this._debuggerSourceCode, target); |
| + if (scriptFile) |
| + this._updateScriptFile(target); |
| + } |
| + } |
| + |
| /** |
| * @param {!SDK.Target} target |
| */ |
| _updateScriptFile(target) { |
| var oldScriptFile = this._scriptFileForTarget.get(target); |
| - var newScriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(this.uiSourceCode(), target); |
| + var newScriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(this._debuggerSourceCode, target); |
| this._scriptFileForTarget.remove(target); |
| if (oldScriptFile) { |
| oldScriptFile.removeEventListener(Bindings.ResourceScriptFile.Events.DidMergeToVM, this._didMergeToVM, this); |
| @@ -1063,7 +1102,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| if (this._executionLocation) |
| this.setExecutionLocation(this._executionLocation); |
| - var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this.uiSourceCode()); |
| + var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._debuggerSourceCode); |
| for (var i = 0; i < breakpointLocations.length; ++i) |
| this._breakpointAdded(/** @type {!Common.Event} */ ({data: breakpointLocations[i]})); |
| @@ -1173,7 +1212,7 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| if (this._textEditor.line(lineNumber).length >= maxLengthToCheck) |
| return Promise.resolve(/** @type {?Array<!Workspace.UILocation>} */ ([])); |
| return this._breakpointManager |
| - .possibleBreakpoints(this.uiSourceCode(), new Common.TextRange(lineNumber, 0, lineNumber + 1, 0)) |
| + .possibleBreakpoints(this._debuggerSourceCode, new Common.TextRange(lineNumber, 0, lineNumber + 1, 0)) |
| .then(locations => locations.length ? locations : null); |
| } |
| @@ -1223,10 +1262,10 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| * @param {boolean} enabled |
| */ |
| _setBreakpoint(lineNumber, columnNumber, condition, enabled) { |
| - if (!Bindings.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCode(), lineNumber)) |
| + if (!Bindings.debuggerWorkspaceBinding.uiLineHasMapping(this._debuggerSourceCode, lineNumber)) |
| return; |
| - this._breakpointManager.setBreakpoint(this.uiSourceCode(), lineNumber, columnNumber, condition, enabled); |
| + this._breakpointManager.setBreakpoint(this._debuggerSourceCode, lineNumber, columnNumber, condition, enabled); |
| this._breakpointWasSetForTest(lineNumber, columnNumber, condition, enabled); |
| } |
| @@ -1248,13 +1287,16 @@ Sources.JavaScriptSourceFrame = class extends Sources.UISourceCodeFrame { |
| this._breakpointManager.removeEventListener( |
| Bindings.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this); |
| this.uiSourceCode().removeEventListener( |
| - Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this); |
| - this.uiSourceCode().removeEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this); |
| this.uiSourceCode().removeEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this); |
| this.uiSourceCode().removeEventListener( |
| Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfNeeded, this); |
| + if (this._debuggerSourceCode) { |
| + this._debuggerSourceCode.removeEventListener( |
| + Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this); |
| + } |
| + |
| Common.moduleSetting('skipStackFramesPattern').removeChangeListener(this._showBlackboxInfobarIfNeeded, this); |
| Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBlackboxInfobarIfNeeded, this); |
| super.dispose(); |