Changeset 237396 in webkit


Ignore:
Timestamp:
Oct 24, 2018 12:27:27 PM (6 years ago)
Author:
Devin Rousso
Message:

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.

Location:
trunk/Source/WebInspectorUI
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r237349 r237396  
     12018-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
    1292018-10-23  Devin Rousso  <drousso@apple.com>
    230
  • trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js

    r221338 r237396  
    4646        console.assert(script.range.startColumn === 0);
    4747
    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 
    5548        var toolTip = WI.UIString("Pretty print");
    5649        var activatedToolTip = WI.UIString("Original formatting");
     
    7770
    7871        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);
    7980    }
    8081
     
    266267    }
    267268
     269    _handleTextEditorMIMETypeChanged(event)
     270    {
     271        this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
     272    }
     273
    268274    _executionLineNumberDidChange(event)
    269275    {
  • trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js

    r221338 r237396  
    3535        this._textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
    3636        this._textEditor.addEventListener(WI.TextEditor.Event.FormattingDidChange, this._textEditorFormattingDidChange, this);
    37 
     37        this._textEditor.addEventListener(WI.TextEditor.Event.MIMETypeChanged, this._handleTextEditorMIMETypeChanged, this);
    3838        this.addSubview(this._textEditor);
    39 
    40         this._textEditor.readOnly = true;
    41         this._textEditor.mimeType = mimeType;
    42         this._textEditor.string = string;
    4339
    4440        var toolTip = WI.UIString("Pretty print");
     
    4642        this._prettyPrintButtonNavigationItem = new WI.ActivateButtonNavigationItem("pretty-print", toolTip, activatedToolTip, "Images/NavigationItemCurleyBraces.svg", 13, 13);
    4743        this._prettyPrintButtonNavigationItem.addEventListener(WI.ButtonNavigationItem.Event.Clicked, this._togglePrettyPrint, this);
    48         this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
    4944        this._prettyPrintButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
    5045
     
    6055        this._codeCoverageButtonNavigationItem.enabled = false;
    6156        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();
    6262    }
    6363
     
    169169    }
    170170
     171    _handleTextEditorMIMETypeChanged(event)
     172    {
     173        this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
     174    }
     175
    171176    _numberOfSearchResultsDidChange(event)
    172177    {
  • trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js

    r237232 r237396  
    141141                    this.performSearch(query);
    142142                }
     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                }
    143150            }
    144151
     
    244251        this._mimeType = newMIMEType;
    245252        this._codeMirror.setOption("mode", {name: newMIMEType, globalVars: true});
     253
     254        this.dispatchEventToListeners(WI.TextEditor.Event.MIMETypeChanged);
    246255    }
    247256
     
    886895    {
    887896        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        });
    888915    }
    889916
     
    17211748    NumberOfSearchResultsDidChange: "text-editor-number-of-search-results-did-change",
    17221749    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",
    17241752};
  • trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js

    r236845 r237396  
    3232        resource.addEventListener(WI.SourceCode.Event.ContentDidChange, this._sourceCodeContentDidChange, this);
    3333
    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 
    4634        var toolTip = WI.UIString("Pretty print");
    4735        var activatedToolTip = WI.UIString("Original formatting");
     
    6654        this._codeCoverageButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low;
    6755        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);
    6869    }
    6970
     
    256257    }
    257258
     259    _handleTextEditorMIMETypeChanged(event)
     260    {
     261        this._prettyPrintButtonNavigationItem.enabled = this._textEditor.canBeFormatted();
     262    }
     263
    258264    _sourceCodeContentDidChange(event)
    259265    {
Note: See TracChangeset for help on using the changeset viewer.