Bug 1249594 - Show name of owner (EV certificate) in URL bar if available. r=mcomella
authorSebastian Kaspari <s.kaspari@gmail.com>
Sun, 21 Feb 2016 14:32:31 +0100
changeset 336932 e082689e684d1bac1255f29786befe907fbf5942
parent 336931 398739346a3a872fd5aaf09098243b3dc8c9f4af
child 336944 711d94dd73a57d27a6e8d5bdd479c6a9831d24c1
child 336947 152399db5417b0ecf8200e88e93697becafb9693
child 336948 c3a501635246e9e7408d3f00e2c778dedaf8e22b
push id12209
push users.kaspari@gmail.com
push dateFri, 04 Mar 2016 11:25:40 +0000
reviewersmcomella
bugs1249594
milestone47.0a1
Bug 1249594 - Show name of owner (EV certificate) in URL bar if available. r=mcomella MozReview-Commit-ID: 8A15R9KoBh
mobile/android/base/java/org/mozilla/gecko/SiteIdentity.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/SiteIdentity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SiteIdentity.java
@@ -15,16 +15,17 @@ public class SiteIdentity {
     private boolean mSecure;
     private boolean mLoginInsecure;
     private MixedMode mMixedModeActive;
     private MixedMode mMixedModeDisplay;
     private TrackingMode mTrackingMode;
     private String mHost;
     private String mOwner;
     private String mSupplemental;
+    private String mCountry;
     private String mVerifier;
     private String mOrigin;
 
     // The order of the items here relate to image levels in
     // site_security_level.xml
     public enum SecurityMode {
         UNKNOWN("unknown"),
         IDENTIFIED("identified"),
@@ -128,16 +129,17 @@ public class SiteIdentity {
     }
 
     public void resetIdentity() {
         mSecurityMode = SecurityMode.UNKNOWN;
         mOrigin = null;
         mHost = null;
         mOwner = null;
         mSupplemental = null;
+        mCountry = null;
         mVerifier = null;
         mSecure = false;
         mLoginInsecure = false;
     }
 
     public void reset() {
         resetIdentity();
         mMixedModeActive = MixedMode.UNKNOWN;
@@ -179,16 +181,17 @@ public class SiteIdentity {
                 return;
             }
 
             try {
                 mOrigin = identityData.getString("origin");
                 mHost = identityData.optString("host", null);
                 mOwner = identityData.optString("owner", null);
                 mSupplemental = identityData.optString("supplemental", null);
+                mCountry = identityData.optString("country", null);
                 mVerifier = identityData.optString("verifier", null);
                 mSecure = identityData.optBoolean("secure", false);
             } catch (Exception e) {
                 resetIdentity();
             }
         } catch (Exception e) {
             reset();
         }
@@ -205,20 +208,32 @@ public class SiteIdentity {
     public String getHost() {
         return mHost;
     }
 
     public String getOwner() {
         return mOwner;
     }
 
+    public boolean hasOwner() {
+        return !TextUtils.isEmpty(mOwner);
+    }
+
     public String getSupplemental() {
         return mSupplemental;
     }
 
+    public String getCountry() {
+        return mCountry;
+    }
+
+    public boolean hasCountry() {
+        return !TextUtils.isEmpty(mCountry);
+    }
+
     public String getVerifier() {
         return mVerifier;
     }
 
     public boolean isSecure() {
         return mSecure;
     }
 
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -25,17 +25,19 @@ import org.mozilla.gecko.util.ColorUtils
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
 import android.os.SystemClock;
 import android.support.annotation.Nullable;
 import android.support.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
 import android.text.Spannable;
+import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.text.style.ForegroundColorSpan;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Button;
@@ -262,17 +264,33 @@ public class ToolbarDisplayLayout extend
             strippedURL = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(strippedURL));
         }
 
         // This value is not visible to screen readers but we rely on it when running UI tests. Screen
         // readers will instead focus BrowserToolbar and read the "base domain" from there. UI tests
         // will read the content description to obtain the full URL for performing assertions.
         setContentDescription(strippedURL);
 
-        if (!TextUtils.isEmpty(baseDomain)) {
+        final SiteIdentity siteIdentity = tab.getSiteIdentity();
+        if (siteIdentity.hasOwner()) {
+            final String title;
+
+            if (siteIdentity.hasCountry()) {
+                title = String.format("%s (%s)", siteIdentity.getOwner(), siteIdentity.getCountry());
+            } else {
+                title = siteIdentity.getOwner();
+            }
+
+            final int color = ContextCompat.getColor(getContext(), R.color.affirmative_green);
+
+            final SpannableString spannable = new SpannableString(title);
+            spannable.setSpan(new ForegroundColorSpan(color), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+            setTitle(spannable);
+        } else if (!TextUtils.isEmpty(baseDomain)) {
             setTitle(baseDomain);
         } else {
             setTitle(strippedURL);
         }
     }
 
     private String stripAboutReaderURL(final String url) {
         if (!AboutPages.isAboutReader(url)) {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -6371,24 +6371,28 @@ var IdentityHandler = {
     result.verifier = Strings.browser.formatStringFromName("identity.identified.verifier", [iData.caOrg], 1);
 
     // If the cert is identified, then we can populate the results with credentials
     if (aState & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL) {
       result.owner = iData.subjectOrg;
 
       // Build an appropriate supplemental block out of whatever location data we have
       let supplemental = "";
-      if (iData.city)
+      if (iData.city) {
         supplemental += iData.city + "\n";
-      if (iData.state && iData.country)
+      }
+      if (iData.state && iData.country) {
         supplemental += Strings.browser.formatStringFromName("identity.identified.state_and_country", [iData.state, iData.country], 2);
-      else if (iData.state) // State only
+        result.country = iData.country;
+      } else if (iData.state) { // State only
         supplemental += iData.state;
-      else if (iData.country) // Country only
+      } else if (iData.country) { // Country only
         supplemental += iData.country;
+        result.country = iData.country;
+      }
       result.supplemental = supplemental;
 
       return result;
     }
 
     // Cache the override service the first time we need to check it
     if (!this._overrideService)
       this._overrideService = Cc["@mozilla.org/security/certoverride;1"].getService(Ci.nsICertOverrideService);