Bug 1573592 - Update pageinfo gImageView.getCellProperties. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Fri, 23 Aug 2019 01:15:53 +0200
changeset 32279 659566cf19f93d5d76e305f016ed7a417ce65c8c
parent 32278 7bff5b3654dfcf207aaf8eb611f63f6f9b0ea37a
child 32280 1719d53875e21a68c0f5c7bb9fea3cc9156f2aad
push id211
push userfrgrahl@gmx.net
push dateThu, 22 Aug 2019 23:17:49 +0000
treeherdercomm-esr60@75fdb3e8faed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1573592
Bug 1573592 - Update pageinfo gImageView.getCellProperties. r=frg a=frg
suite/browser/pageinfo/pageInfo.js
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -169,20 +169,22 @@ const COPYCOL_IMAGE = COL_IMAGE_ADDRESS;
 // one nsITreeView for each tree in the window
 var gMetaView = new pageInfoTreeView("metatree", COPYCOL_META_CONTENT);
 var gFormView = new pageInfoTreeView("formtree", COPYCOL_FORM_ACTION);
 var gFieldView = new pageInfoTreeView("formpreview", COPYCOL_FIELD_VALUE);
 var gLinkView = new pageInfoTreeView("linktree", COPYCOL_LINK_ADDRESS);
 var gImageView = new pageInfoTreeView("imagetree", COPYCOL_IMAGE);
 
 gImageView.getCellProperties = function(row, col) {
+  var data = gImageView.data[row];
+  var item = gImageView.data[row][COL_IMAGE_NODE];
   var properties = col.id == "image-address" ? "ltr" : "";
-
-  if (gImageView.data[row][COL_IMAGE_SIZE] == gStrings.unknown &&
-      !/^https:/.test(gImageView.data[row][COL_IMAGE_ADDRESS]))
+  if (!checkProtocol(data) ||
+      item instanceof HTMLEmbedElement ||
+      (item instanceof HTMLObjectElement && !item.type.startsWith("image/")))
     properties += " broken";
 
   return properties;
 };
 
 gFormView.getCellProperties = function(row, col) {
   return col.id == "form-action" ? "ltr" : "";
 };
@@ -1100,21 +1102,18 @@ function makePreview(row)
     imageType = gImageView.data[row][COL_IMAGE_TYPE];
   }
 
   setItemValue("imagetypetext", imageType);
 
   var imageContainer = document.getElementById("theimagecontainer");
   var oldImage = document.getElementById("thepreviewimage");
 
-  const regex = /^(https?|ftp|file|about|chrome|resource):/;
-  var isProtocolAllowed = regex.test(url);
-  var isImageType = /^image\//.test(mimeType);
-  if (/^data:/.test(url) && isImageType)
-    isProtocolAllowed = true;
+  var isProtocolAllowed = checkProtocol(gImageView.data[row]);
+  var isImageType = mimeType && mimeType.startsWith("image/");
 
   var newImage = new Image;
   newImage.id = "thepreviewimage";
   var physWidth = 0, physHeight = 0;
   var width = 0, height = 0;
 
   if ((item instanceof HTMLLinkElement ||
        item instanceof HTMLInputElement ||
@@ -1169,17 +1168,17 @@ function makePreview(row)
     newImage.controls = true;
     newImage.preload = "metadata";
     isAudio = true;
 
     document.getElementById("theimagecontainer").collapsed = false
     document.getElementById("brokenimagecontainer").collapsed = true;
   }
   else {
-    // fallback image for protocols not allowed (e.g., data: or javascript:)
+    // fallback image for protocols not allowed (e.g., javascript:)
     // or elements not [yet] handled (e.g., object, embed).
     document.getElementById("brokenimagecontainer").collapsed = false;
     document.getElementById("theimagecontainer").collapsed = true;
   }
 
   var imageSize = "";
   if (url && !isAudio)
     imageSize = gBundle.getFormattedString("mediaSize",
@@ -1403,15 +1402,22 @@ function selectImage() {
       tree.view.selection.select(i);
       tree.treeBoxObject.ensureRowIsVisible(i);
       tree.focus();
       return;
     }
   }
 }
 
+function checkProtocol(img)
+{
+  var url = img[COL_IMAGE_ADDRESS];
+  return /^data:image\//i.test(url) ||
+    /^(https?|ftp|file|about|chrome|resource):/.test(url);
+}
+
 function onOpenIn(mode)
 {
   var linkList = getSelectedItems(true);
 
   if (linkList.length)
     openUILinkArrayIn(linkList, mode);
 }