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
--- 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();
}
}
}