Bug 1175300 - Switch password manager to using displayOrigin to display the origin in the capture doorhanger. r=MattN
authorRiadh Chtara <rchtara@mozilla.com>
Wed, 15 Jul 2015 21:26:54 -0700
changeset 253384 bbe1e03d109a70c1216b1d1c3fa48bb697e8cc8b
parent 253383 343b87d1887624822952c8c2406b854ad0b4b54c
child 253385 c659b71f0acf08a309f3ef68c808699b47f83591
push id62438
push userryanvm@gmail.com
push dateFri, 17 Jul 2015 14:27:33 +0000
treeherdermozilla-inbound@ea2b6887033b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1175300
milestone42.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 1175300 - Switch password manager to using displayOrigin to display the origin in the capture doorhanger. r=MattN
browser/base/content/browser-addons.js
browser/base/content/urlbarBindings.xml
browser/components/nsBrowserGlue.js
browser/modules/WebappManager.jsm
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -42,25 +42,20 @@ const gXPInstallObserver = {
       }
       return;
     }
 
     const anchorID = "addons-notification-icon";
 
     // Make notifications persist a minimum of 30 seconds
     var options = {
-      timeout: Date.now() + 30000
+      displayURI: installInfo.originatingURI,
+      timeout: Date.now() + 30000,
     };
 
-    try {
-      options.displayOrigin = installInfo.originatingURI.host;
-    } catch (e) {
-      // originatingURI might be missing or 'host' might throw for non-nsStandardURL nsIURIs.
-    }
-
     let cancelInstallation = () => {
       if (installInfo) {
         for (let install of installInfo.installs)
           install.cancel();
       }
 
       this.acceptInstallation = null;
 
@@ -195,25 +190,20 @@ const gXPInstallObserver = {
 
     const anchorID = "addons-notification-icon";
     var messageString, action;
     var brandShortName = brandBundle.getString("brandShortName");
 
     var notificationID = aTopic;
     // Make notifications persist a minimum of 30 seconds
     var options = {
-      timeout: Date.now() + 30000
+      displayURI: installInfo.originatingURI,
+      timeout: Date.now() + 30000,
     };
 
-    try {
-      options.displayOrigin = installInfo.originatingURI.host;
-    } catch (e) {
-      // originatingURI might be missing or 'host' might throw for non-nsStandardURL nsIURIs.
-    }
-
     switch (aTopic) {
     case "addon-install-disabled": {
       notificationID = "xpinstall-disabled";
 
       if (gPrefService.prefIsLocked("xpinstall.enabled")) {
         messageString = gNavigatorBundle.getString("xpinstallDisabledMessageLocked");
         buttons = [];
       }
@@ -287,17 +277,23 @@ const gXPInstallObserver = {
         acceptButton.accessKey = gNavigatorBundle.getString("addonInstall.acceptButton.accesskey");
       } else {
         acceptButton.hidden = true;
       }
       break; }
     case "addon-install-failed": {
       // TODO This isn't terribly ideal for the multiple failure case
       for (let install of installInfo.installs) {
-        let host = options.displayOrigin;
+        let host;
+        try {
+          host  = options.displayURI.host;
+        } catch (e) {
+          // displayURI might be missing or 'host' might throw for non-nsStandardURL nsIURIs.
+        }
+
         if (!host)
           host = (install.sourceURI instanceof Ci.nsIStandardURL) &&
                  install.sourceURI.host;
 
         let error = (host || install.error == 0) ? "addonInstallError" : "addonLocalInstallError";
         let args;
         if (install.error < 0) {
           error += install.error;
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -3108,19 +3108,19 @@ file, You can obtain one at http://mozil
           if (!this._notificationType) {
             return;
           }
 
           let viewsLeft = this._viewsLeft;
           if (viewsLeft) {
             let notification = this._panel.firstElementChild.notification;
             if (this._notificationType == "passwords" && notification && notification.options &&
-                notification.options.origin) {
+                notification.options.displayURI instanceof Ci.nsIStandardURL) {
               let fxAOrigin = new URL(Services.prefs.getCharPref("identity.fxaccounts.remote.signup.uri")).origin
-              if (notification.options.origin == fxAOrigin) {
+              if (notification.options.displayURI.prePath == fxAOrigin) {
                 // Somewhat gross hack - we don't want to show the sync promo while
                 // the user may be logging into Sync.
                 return;
               }
             }
 
             if (Services.prefs.prefHasUserValue("services.sync.username") &&
                this._notificationType != "addons-sync-disabled") {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2435,19 +2435,17 @@ ContentPermissionPrompt.prototype = {
     let types = aRequest.types.QueryInterface(Ci.nsIArray);
     if (types.length != 1) {
       aRequest.cancel();
       return;
     }
 
     if (!aOptions)
       aOptions = {};
-    aOptions.displayOrigin = (requestPrincipal.URI instanceof Ci.nsIFileURL) ?
-                             requestPrincipal.URI.file.path :
-                             requestPrincipal.URI.host;
+    aOptions.displayOrigin = requestPrincipal.URI;
 
     return chromeWin.PopupNotifications.show(browser, aNotificationId, aMessage, aAnchorId,
                                              mainAction, secondaryActions, aOptions);
   },
 
   _promptPush : function(aRequest) {
     var message = gBrowserBundle.GetStringFromName("push.enablePush2");
 
--- a/browser/modules/WebappManager.jsm
+++ b/browser/modules/WebappManager.jsm
@@ -202,22 +202,19 @@ this.WebappManager = {
         );
       }
     };
 
     let requestingURI = chromeWin.makeURI(aData.from);
     let app = aData.app;
     let manifest = new ManifestHelper(jsonManifest, app.origin, app.manifestURL);
 
-    let options = {};
-    try {
-      options.displayOrigin = requestingURI.host;
-    } catch(e) {
-      options.displayOrigin = requestingURI.spec;
-    }
+    let options = {
+      displayURI: requestingURI,
+    };
 
     let message = bundle.getFormattedString("webapps.requestInstall2",
                                             [manifest.name]);
 
     let gBrowser = chromeWin.gBrowser;
     if (gBrowser) {
       let windowID = aData.oid;
 
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -968,17 +968,17 @@ LoginManagerPrompter.prototype = {
       browser,
       "password",
       promptMsg,
       "password-notification-icon",
       mainAction,
       secondaryActions,
       {
         timeout: Date.now() + 10000,
-        origin: login.hostname,
+        displayURI: Services.io.newURI(login.hostname, null, null),
         persistWhileVisible: true,
         passwordNotificationType: type,
         eventCallback: function (topic) {
           switch (topic) {
             case "showing":
               currentNotification = this;
               chromeDoc.getElementById("password-notification-username")
                        .addEventListener("input", onInput);
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -207,19 +207,16 @@ PopupNotifications.prototype = {
    * @param secondaryActions
    *        An optional JavaScript array describing the notification's alternate
    *        actions. The array should contain objects with the same properties
    *        as mainAction. These are used to populate the notification button's
    *        dropdown menu.
    * @param options
    *        An options JavaScript object holding additional properties for the
    *        notification. The following properties are currently supported:
-   *        origin:      A string representing the origin of the site presenting
-   *                     a notification so it can be shown to the user (possibly
-   *                     with a favicon). e.g. https://example.com:8080
    *        persistence: An integer. The notification will not automatically
    *                     dismiss for this many page loads.
    *        timeout:     A time in milliseconds. The notification will not
    *                     automatically dismiss before this time.
    *        persistWhileVisible:
    *                     A boolean. If true, a visible notification will always
    *                     persist across location changes.
    *        dismissed:   Whether the notification should be added as a dismissed
@@ -268,19 +265,21 @@ PopupNotifications.prototype = {
    *        popupIconURL:
    *                     A string. URL of the image to be displayed in the popup.
    *                     Normally specified in CSS using list-style-image and the
    *                     .popup-notification-icon[popupid=...] selector.
    *        learnMoreURL:
    *                     A string URL. Setting this property will make the
    *                     prompt display a "Learn More" link that, when clicked,
    *                     opens the URL in a new tab.
-   *        displayOrigin:
-   *                     The host name or file path of the page the notification came
+   *        displayURI:
+   *                     The nsIURI of the page the notification came
    *                     from. If present, this will be displayed above the message.
+   *                     If the nsIURI represents a file, the path will be displayed,
+   *                     otherwise the hostPort will be displayed.
    * @returns the Notification object corresponding to the added notification.
    */
   show: function PopupNotifications_show(browser, id, message, anchorID,
                                          mainAction, secondaryActions, options) {
     function isInvalidAction(a) {
       return !a || !(typeof(a.callback) == "function") || !a.label || !a.accessKey;
     }
 
@@ -566,19 +565,30 @@ PopupNotifications.prototype = {
       if (n.options.popupIconURL)
         popupnotification.setAttribute("icon", n.options.popupIconURL);
 
       if (n.options.learnMoreURL)
         popupnotification.setAttribute("learnmoreurl", n.options.learnMoreURL);
       else
         popupnotification.removeAttribute("learnmoreurl");
 
-      if (n.options.displayOrigin)
-        popupnotification.setAttribute("origin", n.options.displayOrigin);
-      else
+      if (n.options.displayURI) {
+        let uri;
+        try {
+           if (n.options.displayURI instanceof Ci.nsIFileURL) {
+            uri = n.options.displayURI.path;
+          } else {
+            uri = n.options.displayURI.hostPort;
+          }
+          popupnotification.setAttribute("origin", uri);
+        } catch (e) {
+          Cu.reportError(e);
+          popupnotification.removeAttribute("origin");
+        }
+      } else
         popupnotification.removeAttribute("origin");
 
       popupnotification.notification = n;
 
       if (n.secondaryActions) {
         n.secondaryActions.forEach(function (a) {
           let item = doc.createElementNS(XUL_NS, "menuitem");
           item.setAttribute("label", a.label);