Changeset 237396 in webkit
- Timestamp:
- Oct 24, 2018 12:27:27 PM (6 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r237349 r237396 1 2018-10-24 Devin Rousso <drousso@apple.com> 2 3 Web Inspector: CSP request payload on medium.com is unreadable, should be pretty-printed 4 https://bugs.webkit.org/show_bug.cgi?id=190354 5 <rdar://problem/45090894> 6 7 Reviewed by Joseph Pecoraro. 8 9 * UserInterface/Views/TextEditor.js: 10 (WI.TextEditor.prototype.set string.update): 11 (WI.TextEditor.prototype._attemptToDetermineMIMEType): Added. 12 If the content doesn't already have a MIME type, attempt to determine one by trying to 13 format it as "javascript" (e.g. request JSON that is simply missing a MIME type). 14 15 * UserInterface/Views/TextContentView.js: 16 (WI.TextContentView): 17 (WI.TextContentView.prototype._handleTextEditorMIMETypeChanged): Added. 18 * UserInterface/Views/TextResourceContentView.js: 19 (WI.TextResourceContentView): 20 (WI.TextResourceContentView.prototype._handleTextEditorMIMETypeChanged): Added. 21 * UserInterface/Views/ScriptContentView.js: 22 (WI.ScriptContentView): 23 (WI.ScriptContentView.prototype._handleTextEditorMIMETypeChanged): Added. 24 Enable the "Pretty Print" navigation button if the MIME type changes to something that is 25 able to be formatted. 26 Drive-by: reorder the creation of the "Pretty Print" button so that it exists if 27 `_attemptToDetermineMIMEType` finishes synchronously. 28 1 29 2018-10-23 Devin Rousso <drousso@apple.com> 2 30 -
trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js
r221338 r237396 46 46 console.assert(script.range.startColumn === 0); 47 47 48 this._textEditor = new WI.SourceCodeTextEditor(script);49 this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);50 this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);51 this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);52 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);53 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);54 55 48 var toolTip = WI.UIString("Pretty print"); 56 49 var activatedToolTip = WI.UIString("Original formatting"); … … 77 70 78 71 WI.enableControlFlowProfilerSetting.addEventListener(WI.Setting.Event.Changed, this._enableControlFlowProfilerSettingChanged, this); 72 73 this._textEditor = new WI.SourceCodeTextEditor(script); 74 this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this); 75 this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this); 76 this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this); 77 this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this); 78 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this); 79 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this); 79 80 } 80 81 … … 266 267 } 267 268 269 _handleTextEditorMIMETypeChanged(event) 270 { 271 this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted(); 272 } 273 268 274 _executionLineNumberDidChange(event) 269 275 { -
trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js
r221338 r237396 35 35 this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this); 36 36 this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this); 37 37 this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this); 38 38 this.addSubview(this._textEditor); 39 40 this._textEditor.readOnly = true;41 this._textEditor.mimeType = mimeType;42 this._textEditor.string = string;43 39 44 40 var toolTip = WI.UIString("Pretty print"); … … 46 42 this._prettyPrintButtonNavigationItem = new WI.ActivateButtonNavigationItem("pretty-print", toolTip, activatedToolTip, "Images/NavigationItemCurleyBraces.svg", 13, 13); 47 43 this._prettyPrintButtonNavigationItem.addEventListener(WI.ButtonNavigationItem.Event.Clicked, this._togglePrettyPrint, this); 48 this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();49 44 this._prettyPrintButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low; 50 45 … … 60 55 this._codeCoverageButtonNavigationItem.enabled = false; 61 56 this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low; 57 58 this._textEditor.readOnly = true; 59 this._textEditor.mimeType = mimeType; 60 this._textEditor.string = string; 61 this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted(); 62 62 } 63 63 … … 169 169 } 170 170 171 _handleTextEditorMIMETypeChanged(event) 172 { 173 this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted(); 174 } 175 171 176 _numberOfSearchResultsDidChange(event) 172 177 { -
trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js
r237232 r237396 141 141 this.performSearch(query); 142 142 } 143 144 if (this._codeMirror.getMode().name === "null") { 145 // If the content matches a known MIME type, but isn't explicitly declared as 146 // such, attempt to detect that so we can enable syntax highlighting and 147 // formatting features. 148 this._attemptToDetermineMIMEType(); 149 } 143 150 } 144 151 … … 244 251 this._mimeType = newMIMEType; 245 252 this._codeMirror.setOption("mode", {name: newMIMEType, globalVars: true}); 253 254 this.dispatchEventToListeners(WI.TextEditor.Event.MIMETypeChanged); 246 255 } 247 256 … … 886 895 { 887 896 return this._codeMirror.getMode().name === "javascript"; 897 } 898 899 _attemptToDetermineMIMEType() 900 { 901 let startTime = Date.now(); 902 903 const isModule = false; 904 const includeSourceMapData = false; 905 let workerProxy = WI.FormatterWorkerProxy.singleton(); 906 workerProxy.formatJavaScript(this.string, isModule, WI.indentString(), includeSourceMapData, ({formattedText}) => { 907 if (!formattedText) 908 return; 909 910 this.mimeType = "application/javascript"; 911 912 if (Date.now() - startTime < 100) 913 this.updateFormattedState(true); 914 }); 888 915 } 889 916 … … 1721 1748 NumberOfSearchResultsDidChange: "text-editor-number-of-search-results-did-change", 1722 1749 ContentDidChange: "text-editor-content-did-change", 1723 FormattingDidChange: "text-editor-formatting-did-change" 1750 FormattingDidChange: "text-editor-formatting-did-change", 1751 MIMETypeChanged: "text-editor-mime-type-changed", 1724 1752 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js
r236845 r237396 32 32 resource.addEventListener(WI.SourceCode.Event.ContentDidChange, this._sourceCodeContentDidChange, this); 33 33 34 this._textEditor = new WI.SourceCodeTextEditor(resource);35 this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);36 this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);37 this._textEditor.addEventListener(WI.TextEditor.Event.ContentDidChange, this._textEditorContentDidChange, this);38 this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);39 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);40 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);41 this._textEditor.readOnly = !this._shouldBeEditable();42 43 WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetAdded, this._probeSetsChanged, this);44 WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetRemoved, this._probeSetsChanged, this);45 46 34 var toolTip = WI.UIString("Pretty print"); 47 35 var activatedToolTip = WI.UIString("Original formatting"); … … 66 54 this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low; 67 55 WI.enableControlFlowProfilerSetting.addEventListener(WI.Setting.Event.Changed, this._enableControlFlowProfilerSettingChanged, this); 56 57 this._textEditor = new WI.SourceCodeTextEditor(resource); 58 this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this); 59 this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this); 60 this._textEditor.addEventListener(WI.TextEditor.Event.ContentDidChange, this._textEditorContentDidChange, this); 61 this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this); 62 this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this); 63 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this); 64 this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this); 65 this._textEditor.readOnly = !this._shouldBeEditable(); 66 67 WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetAdded, this._probeSetsChanged, this); 68 WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetRemoved, this._probeSetsChanged, this); 68 69 } 69 70 … … 256 257 } 257 258 259 _handleTextEditorMIMETypeChanged(event) 260 { 261 this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted(); 262 } 263 258 264 _sourceCodeContentDidChange(event) 259 265 {
Note: See TracChangeset
for help on using the changeset viewer.