Bug 1400059 - Replace strings in ProgressListener.SecurityInformation with ints. r=snorp
authorDylan Roeh <droeh@mozilla.com>
Fri, 15 Sep 2017 09:00:26 -0500
changeset 665506 ff8b9eddddc4068a878fd561ea734a1531382406
parent 665505 160e7920634dbba36c550fec9655bb7ecd5cd535
child 665507 f89ae3c450ce33915e4d2fff0b11b942dec17f1a
push id80093
push userbmo:ttromey@mozilla.com
push dateFri, 15 Sep 2017 16:41:29 +0000
reviewerssnorp
bugs1400059
milestone57.0a1
Bug 1400059 - Replace strings in ProgressListener.SecurityInformation with ints. r=snorp
mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsSecurityPopup.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
mobile/android/modules/geckoview/GeckoViewProgress.jsm
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
@@ -203,23 +203,23 @@ public class ActionBarPresenter {
      * @param security A SecurityInformation object giving the current security information
      */
     @UiThread
     private void updateCustomView(final String title, final String url, final SecurityInformation security) {
         if (security == null) {
             mIconView.setVisibility(View.INVISIBLE);
         } else {
             SecurityModeUtil.IconType icon;
-            if ("unknown".equals(security.securityMode)) {
+            if (SecurityInformation.SECURITY_MODE_UNKNOWN == security.securityMode) {
                 icon = SecurityModeUtil.IconType.UNKNOWN;
             } else {
                 icon = SecurityModeUtil.IconType.LOCK_SECURE;
             }
 
-            if ("loaded".equals(security.mixedModePassive)) {
+            if (SecurityInformation.CONTENT_LOADED == security.mixedModePassive) {
                 icon = SecurityModeUtil.IconType.WARNING;
             }
 
             mIconView.setVisibility(View.VISIBLE);
             mIconView.setImageLevel(SecurityModeUtil.getImageLevel(icon));
             mIdentityPopup.setSecurityInformation(security);
 
             if (icon == SecurityModeUtil.IconType.LOCK_SECURE) {
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsSecurityPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsSecurityPopup.java
@@ -100,18 +100,18 @@ public class CustomTabsSecurityPopup ext
         mVerifier = (TextView) mIdentityKnownContainer.findViewById(R.id.verifier);
     }
 
     private void updateSecurityInformation(final SecurityInformation security) {
         if (!mInflated) {
             init();
         }
 
-        final boolean isIdentityKnown = ("identified".equals(security.securityMode) ||
-                                         "verified".equals(security.securityMode));
+        final boolean isIdentityKnown = (SecurityInformation.SECURITY_MODE_IDENTIFIED == security.securityMode ||
+                                         SecurityInformation.SECURITY_MODE_VERIFIED == security.securityMode);
         updateConnectionState(security);
         toggleIdentityKnownContainerVisibility(isIdentityKnown);
 
         if (isIdentityKnown) {
             updateIdentityInformation(security);
         }
     }
 
@@ -127,61 +127,60 @@ public class CustomTabsSecurityPopup ext
      * a) Connection encryption
      * b) Mixed Content state (Active/Display Mixed content, loaded, blocked, none, etc)
      * and update the icons and strings to inform the user of that state.
      *
      * @param security SecurityInformation about the connection.
      */
     private void updateConnectionState(final SecurityInformation security) {
         if (!security.isSecure) {
-            if ("loaded".equals(security.mixedModeActive)) {
+            if (SecurityInformation.CONTENT_LOADED == security.mixedModeActive) {
                 // Active Mixed Content loaded because user has disabled blocking.
                 mIcon.setImageResource(R.drawable.ic_lock_disabled);
                 clearSecurityStateIcon();
                 mMixedContentActivity.setVisibility(View.VISIBLE);
                 mMixedContentActivity.setText(R.string.mixed_content_protection_disabled);
-            } else if ("loaded".equals(security.mixedModePassive)) {
+            } else if (SecurityInformation.CONTENT_LOADED == security.mixedModePassive) {
                 // Passive Mixed Content loaded.
                 mIcon.setImageResource(R.drawable.ic_lock_inactive);
                 setSecurityStateIcon(R.drawable.ic_warning_major, 1);
                 mMixedContentActivity.setVisibility(View.VISIBLE);
-                if ("blocked".equals(security.mixedModeActive)) {
+                if (SecurityInformation.CONTENT_BLOCKED == security.mixedModeActive) {
                     mMixedContentActivity.setText(R.string.mixed_content_blocked_some);
                 } else {
                     mMixedContentActivity.setText(R.string.mixed_content_display_loaded);
                 }
             } else {
                 // Unencrypted connection with no mixed content.
                 mIcon.setImageResource(R.drawable.globe_light);
                 clearSecurityStateIcon();
 
                 mMixedContentActivity.setVisibility(View.GONE);
             }
 
             mSecurityState.setText(R.string.identity_connection_insecure);
             mSecurityState.setTextColor(ContextCompat.getColor(mContext, R.color.placeholder_active_grey));
 
         } else if (security.isException) {
-
             mIcon.setImageResource(R.drawable.ic_lock_inactive);
             setSecurityStateIcon(R.drawable.ic_warning_major, 1);
             mSecurityState.setText(R.string.identity_connection_insecure);
             mSecurityState.setTextColor(ContextCompat.getColor(mContext, R.color.placeholder_active_grey));
 
         } else {
             // Connection is secure.
             mIcon.setImageResource(R.drawable.ic_lock);
 
             setSecurityStateIcon(R.drawable.img_check, 2);
             mSecurityState.setTextColor(ContextCompat.getColor(mContext, R.color.affirmative_green));
             mSecurityState.setText(R.string.identity_connection_secure);
 
             // Mixed content has been blocked, if present.
-            if ("blocked".equals(security.mixedModeActive) ||
-                "blocked".equals(security.mixedModePassive)) {
+            if (SecurityInformation.CONTENT_BLOCKED == security.mixedModeActive ||
+                SecurityInformation.CONTENT_BLOCKED == security.mixedModePassive) {
                 mMixedContentActivity.setVisibility(View.VISIBLE);
                 mMixedContentActivity.setText(R.string.mixed_content_blocked_all);
             } else {
                 mMixedContentActivity.setVisibility(View.GONE);
             }
         }
     }
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -1230,16 +1230,23 @@ public class GeckoView extends LayerView
         return mEventDispatcher;
     }
 
     public interface ProgressListener {
         /**
          * Class representing security information for a site.
          */
         public class SecurityInformation {
+            public static final int SECURITY_MODE_UNKNOWN = 0;
+            public static final int SECURITY_MODE_IDENTIFIED = 1;
+            public static final int SECURITY_MODE_VERIFIED = 2;
+
+            public static final int CONTENT_UNKNOWN = 0;
+            public static final int CONTENT_BLOCKED = 1;
+            public static final int CONTENT_LOADED = 2;
             /**
              * Indicates whether or not the site is secure.
              */
             public final boolean isSecure;
             /**
              * Indicates whether or not the site is a security exception.
              */
             public final boolean isException;
@@ -1263,45 +1270,45 @@ public class GeckoView extends LayerView
              * Contains the common name of the issuing authority.
              */
             public final String issuerCommonName;
             /**
              * Contains the full/proper name of the issuing authority.
              */
             public final String issuerOrganization;
             /**
-             * Indicates the security level of the site; possible values are "unknown",
-             * "identified", and "verified". "identified" indicates domain validation only,
-             * while "verified" indicates extended validation.
+             * Indicates the security level of the site; possible values are SECURITY_MODE_UNKNOWN,
+             * SECURITY_MODE_IDENTIFIED, and SECURITY_MODE_VERIFIED. SECURITY_MODE_IDENTIFIED 
+             * indicates domain validation only, while SECURITY_MODE_VERIFIED indicates extended validation.
              */
-            public final String securityMode;
+            public final int securityMode;
             /**
              * Indicates the presence of passive mixed content; possible values are
-             * "unknown", "blocked", and "loaded".
+             * CONTENT_UNKNOWN, CONTENT_BLOCKED, and CONTENT_LOADED.
              */
-            public final String mixedModePassive;
+            public final int mixedModePassive;
             /**
              * Indicates the presence of active mixed content; possible values are
-             * "unknown", "blocked", and "loaded".
+             * CONTENT_UNKNOWN, CONTENT_BLOCKED, and CONTENT_LOADED.
              */
-            public final String mixedModeActive;
+            public final int mixedModeActive;
             /**
              * Indicates the status of tracking protection; possible values are
-             * "unknown", "blocked", and "loaded".
+             * CONTENT_UNKNOWN, CONTENT_BLOCKED, and CONTENT_LOADED.
              */
-            public final String trackingMode;
+            public final int trackingMode;
 
             /* package */ SecurityInformation(GeckoBundle identityData) {
                 final GeckoBundle mode = identityData.getBundle("mode");
 
-                mixedModePassive = mode.getString("mixed_display");
-                mixedModeActive = mode.getString("mixed_active");
-                trackingMode = mode.getString("tracking");
+                mixedModePassive = mode.getInt("mixed_display");
+                mixedModeActive = mode.getInt("mixed_active");
+                trackingMode = mode.getInt("tracking");
 
-                securityMode = mode.getString("identity");
+                securityMode = mode.getInt("identity");
 
                 isSecure = identityData.getBoolean("secure");
                 isException = identityData.getBoolean("securityException");
                 origin = identityData.getString("origin");
                 host = identityData.getString("host");
                 organization = identityData.getString("organization");
                 subjectName = identityData.getString("subjectName");
                 issuerCommonName = identityData.getString("issuerCommonName");
--- a/mobile/android/modules/geckoview/GeckoViewProgress.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewProgress.jsm
@@ -19,48 +19,49 @@ XPCOMUtils.defineLazyGetter(this, "dump"
     Cu.import("resource://gre/modules/AndroidLog.jsm",
               {}).AndroidLog.d.bind(null, "ViewProgress"));
 
 function debug(aMsg) {
   // dump(aMsg);
 }
 
 var IdentityHandler = {
+  // The definitions below should be kept in sync with those in GeckoView.ProgressListener.SecurityInformation
   // No trusted identity information. No site identity icon is shown.
-  IDENTITY_MODE_UNKNOWN: "unknown",
+  IDENTITY_MODE_UNKNOWN: 0,
 
   // Domain-Validation SSL CA-signed domain verification (DV).
-  IDENTITY_MODE_IDENTIFIED: "identified",
+  IDENTITY_MODE_IDENTIFIED: 1,
 
   // Extended-Validation SSL CA-signed identity information (EV). A more rigorous validation process.
-  IDENTITY_MODE_VERIFIED: "verified",
+  IDENTITY_MODE_VERIFIED: 2,
 
   // The following mixed content modes are only used if "security.mixed_content.block_active_content"
   // is enabled. Our Java frontend coalesces them into one indicator.
 
   // No mixed content information. No mixed content icon is shown.
-  MIXED_MODE_UNKNOWN: "unknown",
+  MIXED_MODE_UNKNOWN: 0,
 
   // Blocked active mixed content.
-  MIXED_MODE_CONTENT_BLOCKED: "blocked",
+  MIXED_MODE_CONTENT_BLOCKED: 1,
 
   // Loaded active mixed content.
-  MIXED_MODE_CONTENT_LOADED: "loaded",
+  MIXED_MODE_CONTENT_LOADED: 2,
 
   // The following tracking content modes are only used if tracking protection
   // is enabled. Our Java frontend coalesces them into one indicator.
 
   // No tracking content information. No tracking content icon is shown.
-  TRACKING_MODE_UNKNOWN: "unknown",
+  TRACKING_MODE_UNKNOWN: 0,
 
   // Blocked active tracking content. Shield icon is shown, with a popup option to load content.
-  TRACKING_MODE_CONTENT_BLOCKED: "blocked",
+  TRACKING_MODE_CONTENT_BLOCKED: 1,
 
   // Loaded active tracking content. Yellow triangle icon is shown.
-  TRACKING_MODE_CONTENT_LOADED: "loaded",
+  TRACKING_MODE_CONTENT_LOADED: 2,
 
   _useTrackingProtection: false,
   _usePrivateMode: false,
 
   setUseTrackingProtection: function(aUse) {
     this._useTrackingProtection = aUse;
   },