Bug 1484071 - Crop large data URLs before displaying them in the status bar r=Felipe
authorNikki S <nikkisharpley@gmail.com>
Wed, 06 Mar 2019 14:09:31 +0000
changeset 462614 f25fac04788d3ac6d2b442021bcf2eb74f423e18
parent 462613 5cc66e233192de72cf4eac10c20e85b952285f12
child 462615 6da9d84ec24327d87748021aae54ef5321e5f3f5
push id79751
push userfgomes@mozilla.com
push dateWed, 06 Mar 2019 14:10:13 +0000
treeherderautoland@f25fac04788d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1484071
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484071 - Crop large data URLs before displaying them in the status bar r=Felipe This commit provides a simple fix to reduce the time spent rendering larger data URLs (such as large screenshots) in the status panel when the Highlights tab is hovered over. By limiting the number of characters displayed, this decreases the time spent in the _showDelayed function. Differential Revision: https://phabricator.services.mozilla.com/D21593
browser/base/content/tabbrowser.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -5346,22 +5346,34 @@ var StatusPanel = {
     }
     types.push("defaultStatus");
     for (type of types) {
       if ((text = XULBrowserWindow[type])) {
         break;
       }
     }
 
+    // If it's a long data: URI that uses base64 encoding, truncate to
+    // a reasonable length rather than trying to display the entire thing.
+    // We can't shorten arbitrary URIs like this, as bidi etc might mean
+    // we need the trailing characters for display. But a base64-encoded
+    // data-URI is plain ASCII, so this is OK for status panel display.
+    // (See bug 1484071.)
+    let textCropped = false;
+    if (text.length > 500 && text.match(/^data:[^,]+;base64,/)) {
+      text = text.substring(0, 500) + "\u2026";
+      textCropped = true;
+    }
+
     if (this._labelElement.value != text ||
         (text && !this.isVisible)) {
       this.panel.setAttribute("previoustype", this.panel.getAttribute("type"));
       this.panel.setAttribute("type", type);
       this._label = text;
-      this._labelElement.setAttribute("crop", type == "overLink" ? "center" : "end");
+      this._labelElement.setAttribute("crop", (type == "overLink" && !textCropped) ? "center" : "end");
     }
   },
 
   get _labelElement() {
     delete this._labelElement;
     return this._labelElement = document.getElementById("statuspanel-label");
   },