Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (237395 => 237396)
--- trunk/Source/WebInspectorUI/ChangeLog 2018-10-24 18:49:03 UTC (rev 237395)
+++ trunk/Source/WebInspectorUI/ChangeLog 2018-10-24 19:27:27 UTC (rev 237396)
@@ -1,3 +1,31 @@
+2018-10-24 Devin Rousso <[email protected]>
+
+ Web Inspector: CSP request payload on medium.com is unreadable, should be pretty-printed
+ https://bugs.webkit.org/show_bug.cgi?id=190354
+ <rdar://problem/45090894>
+
+ Reviewed by Joseph Pecoraro.
+
+ * UserInterface/Views/TextEditor.js:
+ (WI.TextEditor.prototype.set string.update):
+ (WI.TextEditor.prototype._attemptToDetermineMIMEType): Added.
+ If the content doesn't already have a MIME type, attempt to determine one by trying to
+ format it as "_javascript_" (e.g. request JSON that is simply missing a MIME type).
+
+ * UserInterface/Views/TextContentView.js:
+ (WI.TextContentView):
+ (WI.TextContentView.prototype._handleTextEditorMIMETypeChanged): Added.
+ * UserInterface/Views/TextResourceContentView.js:
+ (WI.TextResourceContentView):
+ (WI.TextResourceContentView.prototype._handleTextEditorMIMETypeChanged): Added.
+ * UserInterface/Views/ScriptContentView.js:
+ (WI.ScriptContentView):
+ (WI.ScriptContentView.prototype._handleTextEditorMIMETypeChanged): Added.
+ Enable the "Pretty Print" navigation button if the MIME type changes to something that is
+ able to be formatted.
+ Drive-by: reorder the creation of the "Pretty Print" button so that it exists if
+ `_attemptToDetermineMIMEType` finishes synchronously.
+
2018-10-23 Devin Rousso <[email protected]>
Uncaught Exception: TypeError: null is not an object (evaluating 'mouseBlock.addEventListener')
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js (237395 => 237396)
--- trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js 2018-10-24 18:49:03 UTC (rev 237395)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js 2018-10-24 19:27:27 UTC (rev 237396)
@@ -45,13 +45,6 @@
console.assert(script.range.startLine === 0);
console.assert(script.range.startColumn === 0);
- this._textEditor = new WI.SourceCodeTextEditor(script);
- this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);
- this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
- this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
- this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);
- this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);
-
var toolTip = WI.UIString("Pretty print");
var activatedToolTip = WI.UIString("Original formatting");
this._prettyPrintButtonNavigationItem = new WI.ActivateButtonNavigationItem("pretty-print", toolTip, activatedToolTip, "Images/NavigationItemCurleyBraces.svg", 13, 13);
@@ -76,6 +69,14 @@
this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
WI.enableControlFlowProfilerSetting.addEventListener(WI.Setting.Event.Changed, this._enableControlFlowProfilerSettingChanged, this);
+
+ this._textEditor = new WI.SourceCodeTextEditor(script);
+ this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this);
+ this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);
+ this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);
}
// Public
@@ -265,6 +266,11 @@
this._prettyPrintButtonNavigationItem.activated = this._textEditor.formatted;
}
+ _handleTextEditorMIMETypeChanged(event)
+ {
+ this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
+ }
+
_executionLineNumberDidChange(event)
{
this.dispatchEventToListeners(WI.ContentView.Event.SupplementalRepresentedObjectsDidChange);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js (237395 => 237396)
--- trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js 2018-10-24 18:49:03 UTC (rev 237395)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js 2018-10-24 19:27:27 UTC (rev 237396)
@@ -34,18 +34,13 @@
this._textEditor = new WI.TextEditor;
this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
-
+ this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this);
this.addSubview(this._textEditor);
- this._textEditor.readOnly = true;
- this._textEditor.mimeType = mimeType;
- this._textEditor.string = string;
-
var toolTip = WI.UIString("Pretty print");
var activatedToolTip = WI.UIString("Original formatting");
this._prettyPrintButtonNavigationItem = new WI.ActivateButtonNavigationItem("pretty-print", toolTip, activatedToolTip, "Images/NavigationItemCurleyBraces.svg", 13, 13);
this._prettyPrintButtonNavigationItem.addEventListener(WI.ButtonNavigationItem.Event.Clicked, this._togglePrettyPrint, this);
- this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
this._prettyPrintButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
var toolTipTypes = WI.UIString("Show type information");
@@ -59,6 +54,11 @@
this._codeCoverageButtonNavigationItem = new WI.ActivateButtonNavigationItem("code-coverage", toolTipCodeCoverage, activatedToolTipCodeCoverage, "Images/NavigationItemCodeCoverage.svg", 13, 14);
this._codeCoverageButtonNavigationItem.enabled = false;
this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
+
+ this._textEditor.readOnly = true;
+ this._textEditor.mimeType = mimeType;
+ this._textEditor.string = string;
+ this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
}
// Public
@@ -168,6 +168,11 @@
this._prettyPrintButtonNavigationItem.activated = this._textEditor.formatted;
}
+ _handleTextEditorMIMETypeChanged(event)
+ {
+ this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
+ }
+
_numberOfSearchResultsDidChange(event)
{
this.dispatchEventToListeners(WI.ContentView.Event.NumberOfSearchResultsDidChange);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js (237395 => 237396)
--- trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js 2018-10-24 18:49:03 UTC (rev 237395)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js 2018-10-24 19:27:27 UTC (rev 237396)
@@ -140,6 +140,13 @@
this._searchQuery = null;
this.performSearch(query);
}
+
+ if (this._codeMirror.getMode().name === "null") {
+ // If the content matches a known MIME type, but isn't explicitly declared as
+ // such, attempt to detect that so we can enable syntax highlighting and
+ // formatting features.
+ this._attemptToDetermineMIMEType();
+ }
}
// Update the execution line now that we might have content for that line.
@@ -243,6 +250,8 @@
this._mimeType = newMIMEType;
this._codeMirror.setOption("mode", {name: newMIMEType, globalVars: true});
+
+ this.dispatchEventToListeners(WI.TextEditor.Event.MIMETypeChanged);
}
get executionLineNumber()
@@ -887,6 +896,24 @@
return this._codeMirror.getMode().name === "_javascript_";
}
+ _attemptToDetermineMIMEType()
+ {
+ let startTime = Date.now();
+
+ const isModule = false;
+ const includeSourceMapData = false;
+ let workerProxy = WI.FormatterWorkerProxy.singleton();
+ workerProxy.formatJavaScript(this.string, isModule, WI.indentString(), includeSourceMapData, ({formattedText}) => {
+ if (!formattedText)
+ return;
+
+ this.mimeType = "application/_javascript_";
+
+ if (Date.now() - startTime < 100)
+ this.updateFormattedState(true);
+ });
+ }
+
_startWorkerPrettyPrint(beforePrettyPrintState, callback)
{
let sourceText = this._codeMirror.getValue();
@@ -1720,5 +1747,6 @@
ExecutionLineNumberDidChange: "text-editor-execution-line-number-did-change",
NumberOfSearchResultsDidChange: "text-editor-number-of-search-results-did-change",
ContentDidChange: "text-editor-content-did-change",
- FormattingDidChange: "text-editor-formatting-did-change"
+ FormattingDidChange: "text-editor-formatting-did-change",
+ MIMETypeChanged: "text-editor-mime-type-changed",
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js (237395 => 237396)
--- trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js 2018-10-24 18:49:03 UTC (rev 237395)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js 2018-10-24 19:27:27 UTC (rev 237396)
@@ -31,18 +31,6 @@
resource.addEventListener(WI.SourceCode.Event.ContentDidChange, this._sourceCodeContentDidChange, this);
- this._textEditor = new WI.SourceCodeTextEditor(resource);
- this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);
- this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
- this._textEditor.addEventListener(WI.TextEditor.Event.ContentDidChange, this._textEditorContentDidChange, this);
- this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
- this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);
- this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);
- this._textEditor.readOnly = !this._shouldBeEditable();
-
- WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetAdded, this._probeSetsChanged, this);
- WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetRemoved, this._probeSetsChanged, this);
-
var toolTip = WI.UIString("Pretty print");
var activatedToolTip = WI.UIString("Original formatting");
this._prettyPrintButtonNavigationItem = new WI.ActivateButtonNavigationItem("pretty-print", toolTip, activatedToolTip, "Images/NavigationItemCurleyBraces.svg", 13, 13);
@@ -65,6 +53,19 @@
this._codeCoverageButtonNavigationItem.enabled = false;
this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
WI.enableControlFlowProfilerSetting.addEventListener(WI.Setting.Event.Changed, this._enableControlFlowProfilerSettingChanged, this);
+
+ this._textEditor = new WI.SourceCodeTextEditor(resource);
+ this._textEditor.addEventListener(WI.TextEditor.Event.ExecutionLineNumberDidChange, this._executionLineNumberDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.ContentDidChange, this._textEditorContentDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
+ this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this);
+ this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);
+ this._textEditor.addEventListener(WI.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);
+ this._textEditor.readOnly = !this._shouldBeEditable();
+
+ WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetAdded, this._probeSetsChanged, this);
+ WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ProbeSetRemoved, this._probeSetsChanged, this);
}
// Public
@@ -255,6 +256,11 @@
this._prettyPrintButtonNavigationItem.activated = this._textEditor.formatted;
}
+ _handleTextEditorMIMETypeChanged(event)
+ {
+ this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
+ }
+
_sourceCodeContentDidChange(event)
{
if (this._ignoreSourceCodeContentDidChangeEvent)