Bug 1140830 - Don't try to use a null JSONObject in SiteIdentity.update(). r=rnewman, a=lsblakk
authorJames Willcox <snorp@snorp.net>
Mon, 09 Mar 2015 22:37:17 -0700
changeset 250351 7e93dd7c7feb
parent 250350 0cd4e38e00b1
child 250352 71e45360880e
push id4555
push userryanvm@gmail.com
push date2015-03-11 19:14 +0000
treeherdermozilla-beta@7949e470a547 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs1140830
milestone37.0
Bug 1140830 - Don't try to use a null JSONObject in SiteIdentity.update(). r=rnewman, a=lsblakk This patch avoids a crash in ART on HTC One M8 devices, where a (deliberate?) NPE was used for init.
mobile/android/base/SiteIdentity.java
mobile/android/base/Tab.java
--- a/mobile/android/base/SiteIdentity.java
+++ b/mobile/android/base/SiteIdentity.java
@@ -114,32 +114,36 @@ public class SiteIdentity {
 
         @Override
         public String toString() {
             return mId;
         }
     }
 
     public SiteIdentity() {
-        resetIdentityData();
-
-        mMixedMode = MixedMode.UNKNOWN;
-        mTrackingMode = TrackingMode.UNKNOWN;
+        reset();
     }
 
-    private void resetIdentityData() {
+    public void reset() {
         mSecurityMode = SecurityMode.UNKNOWN;
         mHost = null;
         mOwner = null;
         mSupplemental = null;
         mVerifier = null;
         mEncrypted = null;
+        mMixedMode = MixedMode.UNKNOWN;
+        mTrackingMode = TrackingMode.UNKNOWN;
     }
 
     void update(JSONObject identityData) {
+        if (identityData == null) {
+            reset();
+            return;
+        }
+
         try {
             JSONObject mode = identityData.getJSONObject("mode");
 
             try {
                 mMixedMode = MixedMode.fromString(mode.getString("mixed"));
             } catch (Exception e) {
                 mMixedMode = MixedMode.UNKNOWN;
             }
@@ -148,31 +152,31 @@ public class SiteIdentity {
                 mTrackingMode = TrackingMode.fromString(mode.getString("tracking"));
             } catch (Exception e) {
                 mTrackingMode = TrackingMode.UNKNOWN;
             }
 
             try {
                 mSecurityMode = SecurityMode.fromString(mode.getString("identity"));
             } catch (Exception e) {
-                resetIdentityData();
+                reset();
                 return;
             }
 
             try {
                 mHost = identityData.getString("host");
                 mOwner = identityData.optString("owner", null);
                 mSupplemental = identityData.optString("supplemental", null);
                 mVerifier = identityData.getString("verifier");
                 mEncrypted = identityData.getString("encrypted");
             } catch (Exception e) {
-                resetIdentityData();
+                reset();
             }
         } catch (Exception e) {
-            resetIdentityData();
+            reset();
             mMixedMode = MixedMode.UNKNOWN;
             mTrackingMode = TrackingMode.UNKNOWN;
         }
     }
 
     public SecurityMode getSecurityMode() {
         return mSecurityMode;
     }
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -602,34 +602,34 @@ public class Tab {
         }
 
         setContentType(message.getString("contentType"));
         updateUserRequested(message.getString("userRequested"));
         mBaseDomain = message.optString("baseDomain");
 
         setHasFeeds(false);
         setHasOpenSearch(false);
-        updateIdentityData(null);
+        mSiteIdentity.reset();
         setZoomConstraints(new ZoomConstraints(true));
         setHasTouchListeners(false);
         setBackgroundColor(DEFAULT_BACKGROUND_COLOR);
         setErrorType(ErrorType.NONE);
         setLoadProgressIfLoading(LOAD_PROGRESS_LOCATION_CHANGE);
 
         Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, oldUrl);
     }
 
     private static boolean shouldShowProgress(final String url) {
         return !AboutPages.isAboutPage(url);
     }
 
     void handleDocumentStart(boolean restoring, String url) {
         setLoadProgress(LOAD_PROGRESS_START);
         setState((!restoring && shouldShowProgress(url)) ? STATE_LOADING : STATE_SUCCESS);
-        updateIdentityData(null);
+        mSiteIdentity.reset();
     }
 
     void handleDocumentStop(boolean success) {
         setState(success ? STATE_SUCCESS : STATE_ERROR);
 
         final String oldURL = getURL();
         final Tab tab = this;
         tab.setLoadProgress(LOAD_PROGRESS_STOP);