Bug 590206: Make the site identity UI display something sensible for about: and chrome: uris. r=gavin, a=blocks-final
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 24 Nov 2010 12:29:56 -0800
changeset 58187 a0c57346cb22fb2f1b78a0c5f8fdfb98ca498f03
parent 58186 d744f676a7583c67f842773935158ba331f30a92
child 58188 ee357cb142cb47545456dc889c4c56465ba34011
push id17191
push userdtownsend@mozilla.com
push dateWed, 24 Nov 2010 20:30:54 +0000
treeherdermozilla-central@a0c57346cb22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, blocks-final
bugs590206
milestone2.0b8pre
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 590206: Make the site identity UI display something sensible for about: and chrome: uris. r=gavin, a=blocks-final
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug590206.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4322,16 +4322,18 @@ var XULBrowserWindow = {
     }
 
     // Don't pass in the actual location object, since it can cause us to
     // hold on to the window object too long.  Just pass in the fields we
     // care about. (bug 424829)
     var location = gBrowser.contentWindow.location;
     var locationObj = {};
     try {
+      // about:blank can be used by webpages so pretend it is http
+      locationObj.protocol = location == "about:blank" ? "http:" : location.protocol;
       locationObj.host = location.host;
       locationObj.hostname = location.hostname;
       locationObj.port = location.port;
     } catch (ex) {
       // Can sometimes throw if the URL being visited has no host/hostname,
       // e.g. about:blank. The _state for these pages means we won't need these
       // properties anyways, though.
     }
@@ -6887,20 +6889,22 @@ var gBookmarkAllTabsHandler = {
  * Utility object to handle manipulations of the identity indicators in the UI
  */
 var gIdentityHandler = {
   // Mode strings used to control CSS display
   IDENTITY_MODE_IDENTIFIED       : "verifiedIdentity", // High-quality identity information
   IDENTITY_MODE_DOMAIN_VERIFIED  : "verifiedDomain",   // Minimal SSL CA-signed domain verification
   IDENTITY_MODE_UNKNOWN          : "unknownIdentity",  // No trusted identity information
   IDENTITY_MODE_MIXED_CONTENT    : "unknownIdentity mixedContent",  // SSL with unauthenticated content
+  IDENTITY_MODE_CHROMEUI         : "chromeUI",         // Part of the product's UI
 
   // Cache the most recent SSLStatus and Location seen in checkIdentity
   _lastStatus : null,
   _lastLocation : null,
+  _mode : "unknownIdentity",
 
   // smart getters
   get _encryptionLabel () {
     delete this._encryptionLabel;
     this._encryptionLabel = {};
     this._encryptionLabel[this.IDENTITY_MODE_DOMAIN_VERIFIED] =
       gNavigatorBundle.getString("identity.encrypted");
     this._encryptionLabel[this.IDENTITY_MODE_IDENTIFIED] =
@@ -7030,17 +7034,19 @@ var gIdentityHandler = {
   checkIdentity : function(state, location) {
     var currentStatus = gBrowser.securityUI
                                 .QueryInterface(Components.interfaces.nsISSLStatusProvider)
                                 .SSLStatus;
     this._lastStatus = currentStatus;
     this._lastLocation = location;
 
     let nsIWebProgressListener = Ci.nsIWebProgressListener;
-    if (state & nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
+    if (location.protocol == "chrome:" || location.protocol == "about:")
+      this.setMode(this.IDENTITY_MODE_CHROMEUI);
+    else if (state & nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
       this.setMode(this.IDENTITY_MODE_IDENTIFIED);
     else if (state & nsIWebProgressListener.STATE_SECURE_HIGH)
       this.setMode(this.IDENTITY_MODE_DOMAIN_VERIFIED);
     else if (state & nsIWebProgressListener.STATE_IS_BROKEN)
       this.setMode(this.IDENTITY_MODE_MIXED_CONTENT);
     else
       this.setMode(this.IDENTITY_MODE_UNKNOWN);
   },
@@ -7079,16 +7085,18 @@ var gIdentityHandler = {
     }
 
     this._identityBox.className = newMode;
     this.setIdentityMessages(newMode);
 
     // Update the popup too, if it's open
     if (this._identityPopup.state == "open")
       this.setPopupMessages(newMode);
+
+    this._mode = newMode;
   },
 
   /**
    * Set up the messages for the primary identity UI based on the specified mode,
    * and the details of the SSL cert, where applicable
    *
    * @param newMode The newly set identity mode.  Should be one of the IDENTITY_MODE_* constants.
    */
@@ -7145,16 +7153,22 @@ var gIdentityHandler = {
       // swap the positions of the organization and country code labels.
       // The Unicode ranges reflect the definition of the UCS2_CHAR_IS_BIDI
       // macro in intl/unicharutil/util/nsBidiUtils.h. When bug 218823 gets
       // fixed, this test should be replaced by one adhering to the
       // Unicode Bidirectional Algorithm proper (at the paragraph level).
       icon_labels_dir = /^[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufefc]/.test(icon_label) ?
                         "rtl" : "ltr";
     }
+    else if (newMode == this.IDENTITY_MODE_CHROMEUI) {
+      icon_label = "";
+      tooltip = "";
+      icon_country_label = "";
+      icon_labels_dir = "ltr";
+    }
     else {
       tooltip = gNavigatorBundle.getString("identity.unknown.tooltip");
       icon_label = "";
       icon_country_label = "";
       icon_labels_dir = "ltr";
     }
 
     // Push the appropriate strings out to the UI
@@ -7239,16 +7253,19 @@ var gIdentityHandler = {
     if ((event.type == "click" && event.button != 0) ||
         (event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
          event.keyCode != KeyEvent.DOM_VK_RETURN))
       return; // Left click, space or enter only
 
     // Revert the contents of the location bar, see bug 406779
     gURLBar.handleRevert();
 
+    if (this._mode == this.IDENTITY_MODE_CHROMEUI)
+      return;
+
     // Make sure that the display:none style we set in xul is removed now that
     // the popup is actually needed
     this._identityPopup.hidden = false;
 
     // Tell the popup to consume dismiss clicks, to avoid bug 395314
     this._identityPopup.popupBoxObject
         .setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
 
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -150,16 +150,17 @@ endif
                  browser_bug577121.js \
                  browser_bug579872.js \
                  browser_bug580956.js \
                  browser_bug581242.js \
                  browser_bug581253.js \
                  browser_bug581947.js \
                  browser_bug585785.js \
                  browser_bug585830.js \
+                 browser_bug590206.js \
                  browser_bug592338.js \
                  browser_bug594131.js \
                  browser_bug595507.js \
                  browser_bug596687.js \
                  browser_bug597218.js \
                  browser_bug598923.js \
                  browser_bug599325.js \
                  browser_bug609700.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug590206.js
@@ -0,0 +1,136 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const DUMMY = "browser/browser/base/content/test/dummy_page.html";
+
+function loadNewTab(aURL, aCallback) {
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.loadURI(aURL);
+
+  gBrowser.selectedBrowser.addEventListener("load", function() {
+    if (gBrowser.selectedBrowser.currentURI.spec != aURL)
+      return;
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+
+    aCallback(gBrowser.selectedTab);
+  }, true);
+}
+
+function getIdentityMode() {
+  return document.getElementById("identity-box").className;
+}
+
+var TESTS = [
+function test_webpage() {
+  let oldTab = gBrowser.selectedTab;
+
+  loadNewTab("http://example.com/" + DUMMY, function(aNewTab) {
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = oldTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = aNewTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.removeTab(aNewTab);
+
+    runNextTest();
+  });
+},
+
+function test_blank() {
+  let oldTab = gBrowser.selectedTab;
+
+  loadNewTab("about:blank", function(aNewTab) {
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = oldTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = aNewTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.removeTab(aNewTab);
+
+    runNextTest();
+  });
+},
+
+function test_chrome() {
+  let oldTab = gBrowser.selectedTab;
+
+  loadNewTab("chrome://mozapps/content/extensions/extensions.xul", function(aNewTab) {
+    is(getIdentityMode(), "chromeUI", "Identity should be chrome");
+
+    gBrowser.selectedTab = oldTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = aNewTab;
+    is(getIdentityMode(), "chromeUI", "Identity should be chrome");
+
+    gBrowser.removeTab(aNewTab);
+
+    runNextTest();
+  });
+},
+
+function test_https() {
+  let oldTab = gBrowser.selectedTab;
+
+  loadNewTab("https://example.com/" + DUMMY, function(aNewTab) {
+    is(getIdentityMode(), "verifiedDomain", "Identity should be verified");
+
+    gBrowser.selectedTab = oldTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = aNewTab;
+    is(getIdentityMode(), "verifiedDomain", "Identity should be verified");
+
+    gBrowser.removeTab(aNewTab);
+
+    runNextTest();
+  });
+},
+
+function test_addons() {
+  let oldTab = gBrowser.selectedTab;
+
+  loadNewTab("about:addons", function(aNewTab) {
+    is(getIdentityMode(), "chromeUI", "Identity should be chrome");
+
+    gBrowser.selectedTab = oldTab;
+    is(getIdentityMode(), "unknownIdentity", "Identity should be unknown");
+
+    gBrowser.selectedTab = aNewTab;
+    is(getIdentityMode(), "chromeUI", "Identity should be chrome");
+
+    gBrowser.removeTab(aNewTab);
+
+    runNextTest();
+  });
+}
+];
+
+var gTestStart = null;
+
+function runNextTest() {
+  if (gTestStart)
+    info("Test part took " + (Date.now() - gTestStart) + "ms");
+
+  if (TESTS.length == 0) {
+    finish();
+    return;
+  }
+
+  info("Running " + TESTS[0].name);
+  gTestStart = Date.now();
+  TESTS.shift()();
+};
+
+function test() {
+  waitForExplicitFinish();
+
+  runNextTest();
+}