Bug 1223741 - Make content unblocking for mail addresses and sites work again. r=Ratty a=ewong
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sat, 30 Apr 2016 19:16:15 +0200
changeset 24866 b9e78456cca7585fa9e610e695c827fc4a4e72cd
parent 24865 9d626f302fb6e27b80eb668919e7491ac35a19e8
child 24867 d27e0d778376e4d117c869124df897a838b007e5
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRatty, ewong
bugs1223741
Bug 1223741 - Make content unblocking for mail addresses and sites work again. r=Ratty a=ewong
suite/mailnews/mailWindowOverlay.js
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -2598,24 +2598,34 @@ var gMessageNotificationBar =
         }];
         this.mMsgNotificationBar.appendNotification(junkBarMsg, "junkContent",
           null, this.mMsgNotificationBar.PRIORITY_WARNING_HIGH, buttons);
         this.mMsgNotificationBar.collapsed = false;
       }
     }
   },
 
-  remoteHosts: null,
+  remoteOrigins: null,
 
   setRemoteContentMsg: function(aMsgHdr, aContentURI)
   {
-    // remoteHosts is a Set of all blockable hosts.
-    if (!this.remoteHosts)
-      this.remoteHosts = new Set();
-    this.remoteHosts.add(aContentURI.host);
+    // remoteOrigins is a Set of all blockable Origins.
+    if (!this.remoteOrigins)
+      this.remoteOrigins = new Set();
+
+    var origin = aContentURI.spec;
+    try
+    {
+      origin = aContentURI.scheme + "://" + aContentURI.hostPort;
+    }
+    // No hostport so likely a special url. Try to use the whole url and see
+    // what comes of it.
+    catch (e) { }
+
+    this.remoteOrigins.add(origin);
 
     if (this.mMsgNotificationBar.getNotificationWithValue("remoteContent"))
       return;
 
     var headerParser = MailServices.headerParser;
     // update the allow remote content for sender string
     var mailbox = headerParser.extractHeaderAddressMailboxes(aMsgHdr.author);
     var emailAddress = mailbox || aMsgHdr.author;
@@ -2739,60 +2749,68 @@ function LoadMsgWithRemoteContent()
   window.content.focus();
 }
 
 /**
  * Populate the remote content options for the current message.
  */
 function onRemoteContentOptionsShowing(aEvent)
 {
-  var hosts = [...gMessageNotificationBar.remoteHosts];
+  var origins = [...gMessageNotificationBar.remoteOrigins];
 
   var addresses = {};
   MailServices.headerParser.parseHeadersWithArray(
     gMessageDisplay.displayedMessage.author, addresses, {}, {});
   var authorEmailAddress = addresses.value[0];
-  if (authorEmailAddress)
-    hosts.unshift(authorEmailAddress);
+
+  var emailURI = Services.io.newURI(
+    "chrome://messenger/content/?email=" + authorEmailAddress, null, null);
+  var principal = Services.scriptSecurityManager
+                          .createCodebasePrincipal(emailURI, {});
+  // Put author email first in the menu.
+  origins.unshift(principal.origin);
 
   // Out with the old...
   let childNodes = aEvent.target.querySelectorAll(".allow-remote-uri");
   for (let child of childNodes)
     child.remove();
 
   var messengerBundle = gMessageNotificationBar.mStringBundle;
   var separator = document.getElementById("remoteContentSettingsMenuSeparator")
 
   // ... and in with the new.
-  for (let host of hosts)
+  for (let origin of origins)
   {
     let menuitem = document.createElement("menuitem");
-    menuitem.setAttribute("label",
-      messengerBundle.getFormattedString("remoteContentAllow", [host]));
-    menuitem.setAttribute("host", host);
+    let host = origin.replace("chrome://messenger/content/?email=", "");
+    let hostString = messengerBundle.getFormattedString("remoteContentAllow", [host]);
+    menuitem.setAttribute("label", hostString);
+    menuitem.setAttribute("value", origin);
     menuitem.setAttribute("class", "allow-remote-uri");
     aEvent.target.insertBefore(menuitem, separator);
   }
 }
 
 /**
  * Add privileges to display remote content for the given uri.
- * @param aItem |nsIDOMNode| Item that was selected. The host
+ * @param aItem |nsIDOMNode| Item that was selected. The origin
  *        is extracted and converted to a uri and used to add
  *        permissions for the site.
  */
 function allowRemoteContentForURI(aItem)
 {
-  var host = aItem.getAttribute("host");
-  if (!host)
+
+  var origin = aItem.getAttribute("value");
+
+  if (!origin)
     return;
 
-  var scheme = host.includes("@") ? "mailto:" : "http://";
-  var uri = Services.io.newURI(scheme + host, null, null);
+  let uri = Services.io.newURI(origin, null, null);
   Services.perms.add(uri, "image", Services.perms.ALLOW_ACTION);
+
   ReloadMessage();
 }
 
 /**
  * Displays fine-grained, per-site permissions for remote content.
  */
 function editRemoteContentSettings()
 {
@@ -2913,19 +2931,19 @@ function OnMsgLoaded(aUrl)
     // if the user clicks on another message then that message stays selected
     // and the selection does not "snap back" to the message chosen by
     // SetNextMessageAfterDelete() when the operation completes (bug 243532).
     var wintype = document.documentElement.getAttribute('windowtype');
     gNextMessageViewIndexAfterDelete = -2;
 
     var msgHdr = msgHdrForCurrentMessage();
     gMessageNotificationBar.setJunkMsg(msgHdr);
-    // Reset the blocked hosts so we can populate it again for this message.
+    // Reset the blocked origins so we can populate it again for this message.
     // Reset to null so it's only a Set if there's something in the Set.
-    gMessageNotificationBar.remoteHosts = null;
+    gMessageNotificationBar.remoteOrigins = null;
 
     var markReadAutoMode = Services.prefs.getBoolPref("mailnews.mark_message_read.auto");
 
     // We just finished loading a message. If messages are to be marked as read
     // automatically, set a timer to mark the message is read after n seconds
     // where n can be configured by the user.
     if (msgHdr && !msgHdr.isRead && markReadAutoMode)
     {