Bug 1240919 - Part 5: Remove references to org.json.simple in org.mozilla.gecko.background.fxa. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Tue, 19 Jan 2016 14:46:02 -0800
changeset 303132 ed222e27eb642c27d4d24dd437121f1047c97744
parent 303131 a4056a35eaa108d44ab669cae0ce9e871c555fc3
child 303133 31202b9037c8aac5e5b172c9a00337a0605880cf
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1240919
milestone46.0a1
Bug 1240919 - Part 5: Remove references to org.json.simple in org.mozilla.gecko.background.fxa. r=rnewman
mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20CreateDelegate.java
mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient20.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20CreateDelegate.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20CreateDelegate.java
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.background.fxa;
 
-import org.json.simple.JSONObject;
+import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.Utils;
 
 import java.io.UnsupportedEncodingException;
 import java.security.GeneralSecurityException;
 
 public class FxAccount20CreateDelegate {
   protected final byte[] emailUTF8;
   protected final byte[] authPW;
@@ -29,19 +29,18 @@ public class FxAccount20CreateDelegate {
    * @throws GeneralSecurityException
    */
   public FxAccount20CreateDelegate(byte[] emailUTF8, byte[] quickStretchedPW, boolean preVerified) throws UnsupportedEncodingException, GeneralSecurityException {
     this.emailUTF8 = emailUTF8;
     this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
     this.preVerified = preVerified;
   }
 
-  @SuppressWarnings("unchecked")
-  public JSONObject getCreateBody() throws FxAccountClientException {
-    final JSONObject body = new JSONObject();
+  public ExtendedJSONObject getCreateBody() throws FxAccountClientException {
+    final ExtendedJSONObject body = new ExtendedJSONObject();
     try {
       body.put("email", new String(emailUTF8, "UTF-8"));
       body.put("authPW", Utils.byte2Hex(authPW));
       if (preVerified) {
         // Production endpoints do not allow preVerified; this assumes we only
         // set it when it's okay to send it.
         body.put("preVerified", preVerified);
       }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
@@ -1,36 +1,35 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.background.fxa;
 
+import org.mozilla.gecko.sync.ExtendedJSONObject;
+import org.mozilla.gecko.sync.Utils;
+
 import java.io.UnsupportedEncodingException;
 import java.security.GeneralSecurityException;
 
-import org.json.simple.JSONObject;
-import org.mozilla.gecko.sync.Utils;
-
 /**
  * An abstraction around providing an email and authorization token to the auth
  * server.
  */
 public class FxAccount20LoginDelegate {
   protected final byte[] emailUTF8;
   protected final byte[] authPW;
 
   public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException {
     this.emailUTF8 = emailUTF8;
     this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
   }
 
-  @SuppressWarnings("unchecked")
-  public JSONObject getCreateBody() throws FxAccountClientException {
-    final JSONObject body = new JSONObject();
+  public ExtendedJSONObject getCreateBody() throws FxAccountClientException {
+    final ExtendedJSONObject body = new ExtendedJSONObject();
     try {
       body.put("email", new String(emailUTF8, "UTF-8"));
       body.put("authPW", Utils.byte2Hex(authPW));
       return body;
     } catch (UnsupportedEncodingException e) {
       throw new FxAccountClientException(e);
     }
   }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient20.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient20.java
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.background.fxa;
 
-import org.json.simple.JSONObject;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountClientException
         .FxAccountClientMalformedResponseException;
 import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.crypto.HKDF;
@@ -281,26 +280,21 @@ public class FxAccountClient20 implement
 
       // The basics.
       final Locale locale = Locale.getDefault();
       request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Utils.getLanguageTag(locale));
       request.addHeader(HttpHeaders.ACCEPT, ACCEPT_HEADER);
     }
   }
 
-  protected <T> void post(BaseResource resource, final JSONObject requestBody, final RequestDelegate<T> delegate) {
-    try {
-      if (requestBody == null) {
-        resource.post((HttpEntity) null);
-      } else {
-        resource.post(requestBody);
-      }
-    } catch (UnsupportedEncodingException e) {
-      invokeHandleError(delegate, e);
-      return;
+  protected <T> void post(BaseResource resource, final ExtendedJSONObject requestBody, final RequestDelegate<T> delegate) {
+    if (requestBody == null) {
+      resource.post((HttpEntity) null);
+    } else {
+      resource.post(requestBody);
     }
   }
 
   @SuppressWarnings("static-method")
   public long now() {
     return System.currentTimeMillis();
   }
 
@@ -497,17 +491,17 @@ public class FxAccountClient20 implement
         }
       }
     };
     resource.get();
   }
 
   @SuppressWarnings("unchecked")
   public void sign(final byte[] sessionToken, final ExtendedJSONObject publicKey, long durationInMilliseconds, final RequestDelegate<String> delegate) {
-    final JSONObject body = new JSONObject();
+    final ExtendedJSONObject body = new ExtendedJSONObject();
     body.put("publicKey", publicKey);
     body.put("duration", durationInMilliseconds);
 
     final byte[] tokenId = new byte[32];
     final byte[] reqHMACKey = new byte[32];
     try {
       HKDF.deriveMany(sessionToken, new byte[0], FxAccountUtils.KW("sessionToken"), tokenId, reqHMACKey);
     } catch (Exception e) {
@@ -564,17 +558,17 @@ public class FxAccountClient20 implement
     }
   }
 
   // Public for testing only; prefer login and loginAndGetKeys (without boolean parameter).
   public void login(final byte[] emailUTF8, final byte[] quickStretchedPW, final boolean getKeys,
                     final Map<String, String> queryParameters,
                     final RequestDelegate<LoginResponse> delegate) {
     final BaseResource resource;
-    final JSONObject body;
+    final ExtendedJSONObject body;
     try {
       final String path = "account/login";
       final Map<String, String> modifiedParameters = new HashMap<>();
       if (queryParameters != null) {
         modifiedParameters.putAll(queryParameters);
       }
       if (getKeys) {
         modifiedParameters.put("keys", "true");
@@ -618,17 +612,17 @@ public class FxAccountClient20 implement
   }
 
   public void createAccount(final byte[] emailUTF8, final byte[] quickStretchedPW,
                             final boolean getKeys,
                             final boolean preVerified,
                             final Map<String, String> queryParameters,
                             final RequestDelegate<LoginResponse> delegate) {
     final BaseResource resource;
-    final JSONObject body;
+    final ExtendedJSONObject body;
     try {
       final String path = "account/create";
       final Map<String, String> modifiedParameters = new HashMap<>();
       if (queryParameters != null) {
         modifiedParameters.putAll(queryParameters);
       }
       if (getKeys) {
         modifiedParameters.put("keys", "true");