Title: [188739] trunk/Source/WebInspectorUI
Revision
188739
Author
[email protected]
Date
2015-08-20 19:34:34 -0700 (Thu, 20 Aug 2015)

Log Message

Web Inspector: Truncate data URIs
https://bugs.webkit.org/show_bug.cgi?id=148212

Reviewed by Timothy Hatcher.

* UserInterface/Base/URLUtilities.js:
(parseURL):
Exit early to avoid an expensive RegExp match on a potentially very large data URI.

(parseQueryString):
Fix typo.

(WebInspector.displayNameForURL):
(WebInspector.truncateURL):
By default, only show first and last 3 characters of data URIs.

* UserInterface/Models/Resource.js:
(WebInspector.Resource.prototype.get displayURL):
For tooltips, show first and last 32 characters of data URIs.

* UserInterface/Models/SourceCodeLocation.js:
(WebInspector.SourceCodeLocation.prototype._locationString):
* UserInterface/Views/ResourceTreeElement.js:
(WebInspector.ResourceTreeElement.prototype._updateToolTip):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (188738 => 188739)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-08-21 02:30:06 UTC (rev 188738)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-08-21 02:34:34 UTC (rev 188739)
@@ -1,3 +1,30 @@
+2015-08-20  Nikita Vasilyev  <[email protected]>
+
+        Web Inspector: Truncate data URIs
+        https://bugs.webkit.org/show_bug.cgi?id=148212
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Base/URLUtilities.js:
+        (parseURL):
+        Exit early to avoid an expensive RegExp match on a potentially very large data URI.
+
+        (parseQueryString):
+        Fix typo.
+
+        (WebInspector.displayNameForURL):
+        (WebInspector.truncateURL):
+        By default, only show first and last 3 characters of data URIs.
+
+        * UserInterface/Models/Resource.js:
+        (WebInspector.Resource.prototype.get displayURL):
+        For tooltips, show first and last 32 characters of data URIs.
+
+        * UserInterface/Models/SourceCodeLocation.js:
+        (WebInspector.SourceCodeLocation.prototype._locationString):
+        * UserInterface/Views/ResourceTreeElement.js:
+        (WebInspector.ResourceTreeElement.prototype._updateToolTip):
+
 2015-08-20  Devin Rousso  <[email protected]>
 
         Web Inspector: Add flex alignment section to Visual sidebar

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/URLUtilities.js (188738 => 188739)


--- trunk/Source/WebInspectorUI/UserInterface/Base/URLUtilities.js	2015-08-21 02:30:06 UTC (rev 188738)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/URLUtilities.js	2015-08-21 02:34:34 UTC (rev 188739)
@@ -74,6 +74,9 @@
 {
     url = "" ? url.trim() : "";
 
+    if (url.startsWith("data:"))
+        return {scheme: "data", host: null, port: null, path: null, queryString: null, fragment: null, lastPathComponent: null};
+
     var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
     if (!match)
         return {scheme: null, host: null, port: null, path: null, queryString: null, fragment: null, lastPathComponent: null};
@@ -169,7 +172,7 @@
     function decode(string)
     {
         try {
-            // Replace "+" with " " then decode precent encoded values.
+            // Replace "+" with " " then decode percent encoded values.
             return decodeURIComponent(string.replace(/\+/g, " "));
         } catch (e) {
             return string;
@@ -191,6 +194,9 @@
 
 WebInspector.displayNameForURL = function(url, urlComponents)
 {
+    if (url.startsWith("data:"))
+        return WebInspector.truncateURL(url);
+
     if (!urlComponents)
         urlComponents = parseURL(url);
 
@@ -204,6 +210,27 @@
     return displayName || WebInspector.displayNameForHost(urlComponents.host) || url;
 };
 
+WebInspector.truncateURL = function(url, multiline = false, dataURIMaxSize = 6)
+{
+    if (!url.startsWith("data:"))
+        return url;
+
+    const dataIndex = url.indexOf(",") + 1;
+    let header = url.slice(0, dataIndex);
+    if (multiline)
+        header += "\n";
+
+    const data = ""
+    if (data.length < dataURIMaxSize)
+        return header + data;
+
+    const firstChunk = data.slice(0, Math.ceil(dataURIMaxSize / 2));
+    const ellipsis = "\u2026";
+    const middleChunk = multiline ? `\n${ellipsis}\n` : ellipsis;
+    const lastChunk = data.slice(-Math.floor(dataURIMaxSize / 2));
+    return header + firstChunk + middleChunk + lastChunk;
+};
+
 WebInspector.displayNameForHost = function(host)
 {
     // FIXME <rdar://problem/11237413>: This should decode punycode hostnames.

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (188738 => 188739)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2015-08-21 02:30:06 UTC (rev 188738)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2015-08-21 02:34:34 UTC (rev 188739)
@@ -135,6 +135,13 @@
         return WebInspector.displayNameForURL(this._url, this.urlComponents);
     }
 
+    get displayURL()
+    {
+        const isMultiLine = true;
+        const dataURIMaxSize = 64;
+        return WebInspector.truncateURL(this._url, isMultiLine, dataURIMaxSize);
+    }
+
     get initiatorSourceCodeLocation()
     {
         return this._initiatorSourceCodeLocation;

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/SourceCodeLocation.js (188738 => 188739)


--- trunk/Source/WebInspectorUI/UserInterface/Models/SourceCodeLocation.js	2015-08-21 02:30:06 UTC (rev 188738)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/SourceCodeLocation.js	2015-08-21 02:34:34 UTC (rev 188739)
@@ -333,8 +333,9 @@
 
         case WebInspector.SourceCodeLocation.NameStyle.Short:
         case WebInspector.SourceCodeLocation.NameStyle.Full:
-            var lineSuffix = sourceCode.url ? ":" + lineString : WebInspector.UIString(" (line %s)").format(lineString);
-            return prefix + (nameStyle === WebInspector.SourceCodeLocation.NameStyle.Full && sourceCode.url ? sourceCode.url : sourceCode.displayName) + lineSuffix;
+            const displayURL = sourceCode.displayURL;
+            const lineSuffix = displayURL ? ":" + lineString : WebInspector.UIString(" (line %s)").format(lineString);
+            return prefix + (nameStyle === WebInspector.SourceCodeLocation.NameStyle.Full && displayURL ? displayURL : sourceCode.displayName) + lineSuffix;
 
         default:
             console.error("Unknown nameStyle: " + nameStyle);

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js (188738 => 188739)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js	2015-08-21 02:30:06 UTC (rev 188738)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js	2015-08-21 02:34:34 UTC (rev 188739)
@@ -170,7 +170,7 @@
 
     _updateToolTip()
     {
-        this.tooltip = this._resource.url;
+        this.tooltip = this._resource.displayURL;
     }
 
     _urlDidChange(event)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to