Bug 1439410 - 2. Add copy constructor for GeckoSessionSettings; r=snorp draft
authorJim Chen <nchen@mozilla.com>
Thu, 22 Feb 2018 18:39:11 -0500
changeset 758758 99c81c34ab2203e3517e07d286f865f5e93869c8
parent 758757 e304d25d09291bc0a3faa29bf36f9d01eadc8524
child 758759 23e2489eed328bf0a08358c58c633d527d8a85c2
push id100161
push userbmo:nchen@mozilla.com
push dateThu, 22 Feb 2018 23:39:58 +0000
reviewerssnorp
bugs1439410
milestone60.0a1
Bug 1439410 - 2. Add copy constructor for GeckoSessionSettings; r=snorp Right now there's no good way for a GeckoSession consumer to make a copy of a GeckoSessionSettings object. MozReview-Commit-ID: 199K5J51Y9x
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -454,22 +454,17 @@ public class GeckoSession extends LayerS
     protected Window mWindow;
     private GeckoSessionSettings mSettings;
 
     public GeckoSession() {
         this(null);
     }
 
     public GeckoSession(final GeckoSessionSettings settings) {
-        if (settings == null) {
-            mSettings = new GeckoSessionSettings(this);
-        } else {
-            mSettings = new GeckoSessionSettings(settings, this);
-        }
-
+        mSettings = new GeckoSessionSettings(settings, this);
         mListener.registerListeners();
     }
 
     private void transferFrom(final Window window, final GeckoSessionSettings settings,
                               final String id) {
         if (isOpen()) {
             throw new IllegalStateException("Session is open");
         }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
@@ -5,16 +5,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.geckoview;
 
 import org.mozilla.gecko.util.GeckoBundle;
 
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.util.Log;
 
 import java.util.Arrays;
 import java.util.Collection;
 
 public final class GeckoSessionSettings implements Parcelable {
     private static final String LOGTAG = "GeckoSessionSettings";
     private static final boolean DEBUG = false;
@@ -83,38 +85,42 @@ public final class GeckoSessionSettings 
 
     public static final Key<Boolean> USE_REMOTE_DEBUGGER =
         new Key<Boolean>("useRemoteDebugger");
 
     private final GeckoSession mSession;
     private final GeckoBundle mBundle;
 
     public GeckoSessionSettings() {
-        this(null);
+        this(null, null);
+    }
+
+    public GeckoSessionSettings(final @NonNull GeckoSessionSettings settings) {
+        this(settings, null);
     }
 
-    /* package */ GeckoSessionSettings(final GeckoSession session) {
+    /* package */ GeckoSessionSettings(final @Nullable GeckoSessionSettings settings,
+                                       final @Nullable GeckoSession session) {
         mSession = session;
+
+        if (settings != null) {
+            mBundle = new GeckoBundle(settings.mBundle);
+            return;
+        }
+
         mBundle = new GeckoBundle();
-
         mBundle.putString(CHROME_URI.name, null);
         mBundle.putInt(SCREEN_ID.name, 0);
         mBundle.putBoolean(USE_TRACKING_PROTECTION.name, false);
         mBundle.putBoolean(USE_PRIVATE_MODE.name, false);
         mBundle.putBoolean(USE_MULTIPROCESS.name, true);
         mBundle.putInt(DISPLAY_MODE.name, DISPLAY_MODE_BROWSER);
         mBundle.putBoolean(USE_REMOTE_DEBUGGER.name, false);
     }
 
-    /* package */ GeckoSessionSettings(final GeckoSessionSettings settings,
-                                       final GeckoSession session) {
-        mSession = session;
-        mBundle = new GeckoBundle(settings.mBundle);
-    }
-
     public void setBoolean(final Key<Boolean> key, final boolean value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putBoolean(key.name, value);
                 dispatchUpdate();
             }
         }
     }