Bug 1255773 - Account for multiple media elements per node for Page Info. r=florian, a=lizzard
authorMike Conley <mconley@mozilla.com>
Tue, 05 Apr 2016 12:39:24 -0400
changeset 325779 f1668f8aebd7f845f793d09998a9dc8344c5e7c3
parent 325778 29f1480e9931de5ef94055e97f74411aeddb16ad
child 325780 f76dce9226157f99a2bf015167a58cc609e9b6a9
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, lizzard
bugs1255773
milestone47.0a2
Bug 1255773 - Account for multiple media elements per node for Page Info. r=florian, a=lizzard MozReview-Commit-ID: GwzIYVsLgue
browser/base/content/content.js
browser/base/content/pageinfo/pageInfo.js
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -1063,42 +1063,44 @@ var PageInfoListener = {
   processFrames: function*(document, frameList, strings)
   {
     let nodeCount = 0;
     for (let doc of frameList) {
       let iterator = doc.createTreeWalker(doc, content.NodeFilter.SHOW_ELEMENT);
 
       // Goes through all the elements on the doc. imageViewRows takes only the media elements.
       while (iterator.nextNode()) {
-        let mediaNode = this.getMediaNode(document, strings, iterator.currentNode);
+        let mediaItems = this.getMediaItems(document, strings, iterator.currentNode);
 
-        if (mediaNode) {
+        if (mediaItems.length) {
           sendAsyncMessage("PageInfo:mediaData",
-                           {imageViewRow: mediaNode, isComplete: false});
+                           {mediaItems, isComplete: false});
         }
 
         if (++nodeCount % 500 == 0) {
           // setTimeout every 500 elements so we don't keep blocking the content process.
           yield new Promise(resolve => setTimeout(resolve, 10));
         }
       }
     }
     // Send that page info media fetching has finished.
     sendAsyncMessage("PageInfo:mediaData", {isComplete: true});
   },
 
-  getMediaNode: function(document, strings, elem)
+  getMediaItems: function(document, strings, elem)
   {
-    // Check for images defined in CSS (e.g. background, borders), any node may have multiple.
+    // Check for images defined in CSS (e.g. background, borders)
     let computedStyle = elem.ownerDocument.defaultView.getComputedStyle(elem, "");
-    let mediaElement = null;
+    // A node can have multiple media items associated with it - for example,
+    // multiple background images.
+    let mediaItems = [];
 
     let addImage = (url, type, alt, elem, isBg) => {
       let element = this.serializeElementInfo(document, url, type, alt, elem, isBg);
-      mediaElement = [url, type, alt, element, isBg];
+      mediaItems.push([url, type, alt, element, isBg]);
     };
 
     if (computedStyle) {
       let addImgFunc = (label, val) => {
         if (val.primitiveType == content.CSSPrimitiveValue.CSS_URI) {
           addImage(val.getStringValue(), label, strings.notSet, elem, true);
         }
         else if (val.primitiveType == content.CSSPrimitiveValue.CSS_STRING) {
@@ -1156,17 +1158,17 @@ var PageInfoListener = {
     }
     else if (elem instanceof content.HTMLObjectElement) {
       addImage(elem.data, strings.mediaObject, this.getValueText(elem), elem, false);
     }
     else if (elem instanceof content.HTMLEmbedElement) {
       addImage(elem.src, strings.mediaEmbed, "", elem, false);
     }
 
-    return mediaElement;
+    return mediaItems;
   },
 
   /**
    * Set up a JSON element object with all the instanceOf and other infomation that
    * makePreview in pageInfo.js uses to figure out how to display the preview.
    */
 
   serializeElementInfo: function(document, url, type, alt, item, isBG)
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -400,17 +400,20 @@ function loadPageInfo(frameOuterWindowID
 
     // The page info media fetching has been completed.
     if (message.data.isComplete) {
       mm.removeMessageListener("PageInfo:mediaData", onmessage);
       onFinished.forEach(function(func) { func(pageInfoData); });
       return;
     }
 
-    addImage(message.data.imageViewRow);
+    for (let item of message.data.mediaItems) {
+      addImage(item);
+    }
+
     selectImage();
   });
 
   /* Call registered overlay init functions */
   onLoadRegistry.forEach(function(func) { func(); });
 }
 
 function resetPageInfo(args)