Title: [253241] trunk/Source/WebInspectorUI
Revision
253241
Author
[email protected]
Date
2019-12-06 22:04:23 -0800 (Fri, 06 Dec 2019)

Log Message

Web Inspector: saving a file with the url "/" suggest the name "Untitled"
https://bugs.webkit.org/show_bug.cgi?id=204910

Reviewed by Timothy Hatcher.

* UserInterface/Base/FileUtilities.js:
(WI.FileUtilities.save):
Allow callers to specify a `suggestedName` that is used if possible.

* UserInterface/Views/ContextMenuUtilities.js:
(WI.appendContextMenuItemsForSourceCode):
(WI.appendContextMenuItemsForDOMNode):
* UserInterface/Views/TextResourceContentView.js:
(WI.TextResourceContentView.prototype.get saveData):
* UserInterface/Views/ResourceContentView.js:
(WI.ResourceContentView.prototype.get saveData):
If the path of the selected source code is just "/", set the `suggestedName` to "index" and
use an extension derived from the MIME type (if able).

* UserInterface/Controllers/AuditManager.js:
(WI.AuditManager.prototype.export):
* UserInterface/Views/ConsoleMessageView.js:
(WI.ConsoleMessageView.prototype._handleContextMenu):
* UserInterface/Views/HeapSnapshotContentView.js:
(WI.HeapSnapshotContentView.prototype._exportSnapshot):
* UserInterface/Views/LogContentView.js:
(WI.LogContentView.prototype.get saveData):
(WI.LogContentView.prototype._handleContextMenuEvent):
* UserInterface/Views/NetworkTableContentView.js:
(WI.NetworkTableContentView.prototype._exportHAR):
* UserInterface/Views/RecordingContentView.js:
(WI.RecordingContentView.prototype._exportRecording):
(WI.RecordingContentView.prototype._exportReduction):
* UserInterface/Views/ScriptContentView.js:
(WI.ScriptContentView.prototype.get saveData):
* UserInterface/Views/ShaderProgramContentView.js:
(WI.ShaderProgramContentView.prototype.get saveData):
* UserInterface/Views/TextContentView.js:
(WI.TextContentView.prototype.get saveData):
* UserInterface/Views/TimelineRecordingContentView.js:
(WI.TimelineRecordingContentView.prototype._exportTimelineRecording):
* UserInterface/Debug/ProtocolTrace.js:
(WI.ProtocolTrace.prototype.get saveData):
Prefer `suggestedName` vs `WI.FileUtilities.inspectorURLForFilename`, which is now always
called inside `WI.FileUtilities.save` anyways.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (253240 => 253241)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-12-07 06:04:23 UTC (rev 253241)
@@ -1,5 +1,53 @@
 2019-12-06  Devin Rousso  <[email protected]>
 
+        Web Inspector: saving a file with the url "/" suggest the name "Untitled"
+        https://bugs.webkit.org/show_bug.cgi?id=204910
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Base/FileUtilities.js:
+        (WI.FileUtilities.save):
+        Allow callers to specify a `suggestedName` that is used if possible.
+
+        * UserInterface/Views/ContextMenuUtilities.js:
+        (WI.appendContextMenuItemsForSourceCode):
+        (WI.appendContextMenuItemsForDOMNode):
+        * UserInterface/Views/TextResourceContentView.js:
+        (WI.TextResourceContentView.prototype.get saveData):
+        * UserInterface/Views/ResourceContentView.js:
+        (WI.ResourceContentView.prototype.get saveData):
+        If the path of the selected source code is just "/", set the `suggestedName` to "index" and
+        use an extension derived from the MIME type (if able).
+
+        * UserInterface/Controllers/AuditManager.js:
+        (WI.AuditManager.prototype.export):
+        * UserInterface/Views/ConsoleMessageView.js:
+        (WI.ConsoleMessageView.prototype._handleContextMenu):
+        * UserInterface/Views/HeapSnapshotContentView.js:
+        (WI.HeapSnapshotContentView.prototype._exportSnapshot):
+        * UserInterface/Views/LogContentView.js:
+        (WI.LogContentView.prototype.get saveData):
+        (WI.LogContentView.prototype._handleContextMenuEvent):
+        * UserInterface/Views/NetworkTableContentView.js:
+        (WI.NetworkTableContentView.prototype._exportHAR):
+        * UserInterface/Views/RecordingContentView.js:
+        (WI.RecordingContentView.prototype._exportRecording):
+        (WI.RecordingContentView.prototype._exportReduction):
+        * UserInterface/Views/ScriptContentView.js:
+        (WI.ScriptContentView.prototype.get saveData):
+        * UserInterface/Views/ShaderProgramContentView.js:
+        (WI.ShaderProgramContentView.prototype.get saveData):
+        * UserInterface/Views/TextContentView.js:
+        (WI.TextContentView.prototype.get saveData):
+        * UserInterface/Views/TimelineRecordingContentView.js:
+        (WI.TimelineRecordingContentView.prototype._exportTimelineRecording):
+        * UserInterface/Debug/ProtocolTrace.js:
+        (WI.ProtocolTrace.prototype.get saveData):
+        Prefer `suggestedName` vs `WI.FileUtilities.inspectorURLForFilename`, which is now always
+        called inside `WI.FileUtilities.save` anyways.
+
+2019-12-06  Devin Rousso  <[email protected]>
+
         Web Inspector: REGRESSION(r252652): Local Overrides: creating a local override for a resource loaded before Web Inspector was opened shows NaN for the Status Code
         https://bugs.webkit.org/show_bug.cgi?id=204965
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/FileUtilities.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Base/FileUtilities.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/FileUtilities.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -63,18 +63,23 @@
         if (!saveData.content)
             return;
 
-        let url = "" || "";
-        let suggestedName = parseURL(url).lastPathComponent;
+        let suggestedName = saveData.suggestedName;
         if (!suggestedName) {
-            suggestedName = WI.UIString("Untitled");
-            let dataURLTypeMatch = /^data:([^;]+)/.exec(url);
-            if (dataURLTypeMatch) {
-                let fileExtension = WI.fileExtensionForMIMEType(dataURLTypeMatch[1]);
-                if (fileExtension)
-                    suggestedName += "." + fileExtension;
+            let url = "" || "";
+            suggestedName = parseURL(url).lastPathComponent;
+            if (!suggestedName) {
+                suggestedName = WI.UIString("Untitled");
+                let dataURLTypeMatch = /^data:([^;]+)/.exec(url);
+                if (dataURLTypeMatch) {
+                    let fileExtension = WI.fileExtensionForMIMEType(dataURLTypeMatch[1]);
+                    if (fileExtension)
+                        suggestedName += "." + fileExtension;
+                }
             }
         }
 
+        suggestedName = FileUtilities.inspectorURLForFilename(suggestedName);
+
         if (typeof saveData.content === "string") {
             const base64Encoded = saveData.base64Encoded || false;
             InspectorFrontendHost.save(suggestedName, saveData.content, base64Encoded, forceSaveAs || saveData.forceSaveAs);

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -235,8 +235,8 @@
             filename = WI.UIString("%s Result").format(filename);
 
         WI.FileUtilities.save({
-            url: WI.FileUtilities.inspectorURLForFilename(filename + ".json"),
             content: JSON.stringify(object),
+            suggestedName: filename + ".json",
             forceSaveAs: true,
         });
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Debug/ProtocolTrace.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Debug/ProtocolTrace.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Debug/ProtocolTrace.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -50,10 +50,9 @@
         // This follows the file name of screen shots on OS X (en-US):
         // "Protocol Trace 2015-12-31 at 12.43.04.json".
         // When the Intl API is implemented, we can do a better job.
-        let filename = WI.unlocalizedString(`Protocol Trace at ${YYYY}-${MM}-${DD} ${hh}.${mm}.${ss}.json`);
         return {
-            url: WI.FileUtilities.inspectorURLForFilename(filename),
             content: JSON.stringify(this._entries),
+            suggestedName: WI.unlocalizedString(`Protocol Trace at ${YYYY}-${MM}-${DD} ${hh}.${mm}.${ss}.json`),
         };
     }
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -1041,9 +1041,9 @@
         contextMenu.appendItem(WI.UIString("Save Image"), () => {
             const forceSaveAs = true;
             WI.FileUtilities.save({
-                url: WI.FileUtilities.inspectorURLForFilename(image.getAttribute("filename")),
                 content: parseDataURL(this._message.messageText).data,
                 base64Encoded: true,
+                suggestedName: image.getAttribute("filename"),
             }, forceSaveAs);
         });
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -148,11 +148,19 @@
 
     contextMenu.appendItem(WI.UIString("Save File"), () => {
         sourceCode.requestContent().then(() => {
+            let saveData = {
+                url: sourceCode.url,
+                content: sourceCode.content,
+            };
+
+            if (sourceCode.urlComponents.path === "/") {
+                let extension = WI.fileExtensionForMIMEType(sourceCode.mimeType);
+                if (extension)
+                    saveData.suggestedName = `index.${extension}`;
+            }
+
             const forceSaveAs = true;
-            WI.FileUtilities.save({
-                url: sourceCode.url || "",
-                content: sourceCode.content
-            }, forceSaveAs);
+            WI.FileUtilities.save(saveData, forceSaveAs);
         });
     });
 
@@ -328,9 +336,9 @@
                     }
 
                     WI.FileUtilities.save({
-                        url: WI.FileUtilities.inspectorURLForFilename(WI.FileUtilities.screenshotString() + ".png"),
                         content: parseDataURL(dataURL).data,
                         base64Encoded: true,
+                        suggestedName: WI.FileUtilities.screenshotString() + ".png",
                     });
                 });
             });

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -125,10 +125,9 @@
             Number.zeroPad(date.getMinutes(), 2),
             Number.zeroPad(date.getSeconds(), 2),
         ];
-        let filename = WI.UIString("Heap Snapshot %s-%s-%s at %s.%s.%s").format(...values);
         WI.FileUtilities.save({
-            url: WI.FileUtilities.inspectorURLForFilename(filename + ".json"),
             content: this.representedObject.snapshotStringData,
+            suggestedName: WI.UIString("Heap Snapshot %s-%s-%s at %s.%s.%s").format(...values) + ".json",
             forceSaveAs: true,
         });
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/LogContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/LogContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/LogContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -276,8 +276,8 @@
     get saveData()
     {
         return {
-            url: WI.FileUtilities.inspectorURLForFilename("Console.txt"),
             content: this._formatMessagesAsData(false),
+            suggestedName: WI.UIString("Console") + ".txt",
             forceSaveAs: true,
         };
     }
@@ -509,8 +509,8 @@
             contextMenu.appendItem(WI.UIString("Save Selected"), () => {
                 const forceSaveAs = true;
                 WI.FileUtilities.save({
-                    url: WI.FileUtilities.inspectorURLForFilename("Console.txt"),
                     content: this._formatMessagesAsData(true),
+                    suggestedName: WI.UIString("Console") + ".txt",
                 }, forceSaveAs);
             });
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -2151,8 +2151,8 @@
             let mainFrame = WI.networkManager.mainFrame;
             let archiveName = mainFrame.mainResource.urlComponents.host || mainFrame.mainResource.displayName || "Archive";
             WI.FileUtilities.save({
-                url: WI.FileUtilities.inspectorURLForFilename(archiveName + ".har"),
                 content: JSON.stringify(har, null, 2),
+                suggestedName: archiveName + ".har",
                 forceSaveAs: true,
             });
         });

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/RecordingContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/RecordingContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/RecordingContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -192,8 +192,8 @@
         let filename = this.representedObject.displayName;
 
         WI.FileUtilities.save({
-            url: WI.FileUtilities.inspectorURLForFilename(filename + ".json"),
             content: JSON.stringify(this.representedObject.toJSON()),
+            suggestedName: filename + ".json",
             forceSaveAs: true,
         });
     }
@@ -208,8 +208,8 @@
         let filename = this.representedObject.displayName;
 
         WI.FileUtilities.save({
-            url: WI.FileUtilities.inspectorURLForFilename(filename + ".html"),
             content: this.representedObject.toHTML(),
+            suggestedName: filename + ".html",
             forceSaveAs: true,
         });
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -114,7 +114,18 @@
 
     get saveData()
     {
-        return {url: this._resource.url, content: this._resource.content};
+        let saveData = {
+            url: this._resource.url,
+            content: this._resource.content,
+        };
+
+        if (this._resource.urlComponents.path === "/") {
+            let extension = WI.fileExtensionForMIMEType(this._resource.mimeType);
+            if (extension)
+                saveData.suggestedName = `index.${extension}`;
+        }
+
+        return saveData;
     }
 
     contentAvailable(content, base64Encoded)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -157,8 +157,15 @@
 
     get saveData()
     {
-        let url = "" || WI.FileUtilities.inspectorURLForFilename(this._script.displayName + ".js");
-        return {url, content: this._textEditor.string};
+        let saveData = {
+            url: this._script.url,
+            content: this._textEditor.string,
+        };
+
+        if (!this._script.url)
+            saveData.suggestedName = this._script.displayName + ".js";
+
+        return saveData;
     }
 
     get supportsSearch()

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -194,8 +194,8 @@
         console.assert(extension);
 
         return {
-            url: WI.FileUtilities.inspectorURLForFilename(filename + extension),
             content: this._lastActiveEditor.string,
+            suggestedName: filename + extension,
             forceSaveAs: true,
         };
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -99,8 +99,11 @@
 
     get saveData()
     {
-        let url = "" + ".txt");
-        return {url, content: this._textEditor.string, forceSaveAs: true};
+        return {
+            content: this._textEditor.string,
+            suggestedName: WI.UIString("Untitled") + ".txt",
+            forceSaveAs: true,
+        };
     }
 
     get supportsSearch()

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -161,11 +161,24 @@
 
     get saveData()
     {
+        let saveData = {
+            content: this._textEditor.string,
+        };
+
         if (this.resource instanceof WI.CSSStyleSheet) {
-            let url = ""
-            return {url, content: this._textEditor.string, forceSaveAs: true};
+            saveData.suggestedName = "InspectorStyleSheet.css";
+            saveData.forceSaveAs = true;
+        } else {
+            saveData.url = ""
+
+            if (this.resource.urlComponents.path === "/") {
+                let extension = WI.fileExtensionForMIMEType(this.resource.mimeType);
+                if (extension)
+                    saveData.suggestedName = `index.${extension}`;
+            }
         }
-        return {url: this.resource.url, content: this._textEditor.string};
+
+        return saveData;
     }
 
     get supportsSearch()

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TimelineRecordingContentView.js (253240 => 253241)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TimelineRecordingContentView.js	2019-12-07 05:48:08 UTC (rev 253240)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TimelineRecordingContentView.js	2019-12-07 06:04:23 UTC (rev 253241)
@@ -608,8 +608,8 @@
         let filename = frameName ? `${frameName}-recording` : this._recording.displayName;
 
         WI.FileUtilities.save({
-            url: WI.FileUtilities.inspectorURLForFilename(filename + ".json"),
             content: JSON.stringify(json),
+            suggestedName: filename + ".json",
             forceSaveAs: true,
         });
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to