Bug 1500155 - Part 2 - Make old methods and fields for get/set<DataType> in `GeckoSessionSettings` private. r=snorp
☠☠ backed out by f7c35130959c ☠ ☠
authorEmily Toop <etoop@mozilla.com>
Wed, 12 Dec 2018 13:18:13 +0000
changeset 450249 fcfa609101f8e4efb877d10e4ff6a65ddc286eb6
parent 450248 a9410d9b3f16d13be22b81701f890ba7af676697
child 450250 0d03623732b6f0ee20cb02c7446ae1086c48b13f
push id74573
push useretoop@mozilla.com
push dateWed, 12 Dec 2018 13:20:44 +0000
treeherderautoland@0f66513c5f23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1500155
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1500155 - Part 2 - Make old methods and fields for get/set<DataType> in `GeckoSessionSettings` private. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D13418
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
@@ -368,44 +368,44 @@ class NavigationDelegateTest : BaseSessi
         assertThat("User agent should be set to mobile",
                    sessionRule.session.evaluateJS(userAgentJs) as String,
                    containsString(mobileSubStr))
 
         var userAgent = sessionRule.waitForResult(sessionRule.session.userAgent)
         assertThat("User agent should be reported as mobile",
                     userAgent, containsString(mobileSubStr))
 
-        sessionRule.session.settings.setUserAgentMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP)
+        sessionRule.session.settings.userAgentMode = GeckoSessionSettings.USER_AGENT_MODE_DESKTOP
 
         sessionRule.session.reload()
         sessionRule.session.waitForPageStop()
 
         assertThat("User agent should be set to desktop",
                    sessionRule.session.evaluateJS(userAgentJs) as String,
                    containsString(desktopSubStr))
 
         userAgent = sessionRule.waitForResult(sessionRule.session.userAgent)
         assertThat("User agent should be reported as desktop",
                     userAgent, containsString(desktopSubStr))
 
-        sessionRule.session.settings.setUserAgentMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE)
+        sessionRule.session.settings.userAgentMode = GeckoSessionSettings.USER_AGENT_MODE_MOBILE
 
         sessionRule.session.reload()
         sessionRule.session.waitForPageStop()
 
         assertThat("User agent should be set to mobile",
                    sessionRule.session.evaluateJS(userAgentJs) as String,
                    containsString(mobileSubStr))
 
         userAgent = sessionRule.waitForResult(sessionRule.session.userAgent)
         assertThat("User agent should be reported as mobile",
                     userAgent, containsString(mobileSubStr))
 
         val vrSubStr = "Mobile VR"
-        sessionRule.session.settings.setUserAgentMode(GeckoSessionSettings.USER_AGENT_MODE_VR)
+        sessionRule.session.settings.userAgentMode = GeckoSessionSettings.USER_AGENT_MODE_VR
 
         sessionRule.session.reload()
         sessionRule.session.waitForPageStop()
 
         assertThat("User agent should be set to VR",
                 sessionRule.session.evaluateJS(userAgentJs) as String,
                 containsString(vrSubStr))
 
@@ -434,17 +434,17 @@ class NavigationDelegateTest : BaseSessi
         sessionRule.session.reload()
         sessionRule.session.waitForPageStop()
 
         userAgent = sessionRule.session.evaluateJS(userAgentJs) as String
 
         assertThat("User agent should be reported as override",
                 userAgent, equalTo(overrideUserAgent))
 
-        sessionRule.session.settings.setUserAgentMode(GeckoSessionSettings.USER_AGENT_MODE_VR)
+        sessionRule.session.settings.userAgentMode = GeckoSessionSettings.USER_AGENT_MODE_VR
 
         sessionRule.session.reload()
         sessionRule.session.waitForPageStop()
 
         assertThat("User agent should still be reported as override even when USER_AGENT_MODE is set",
                 userAgent, equalTo(overrideUserAgent))
 
         sessionRule.session.settings.userAgentOverride = null
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -195,46 +195,57 @@ public class GeckoSessionTestRule implem
             FULL_ACCESSIBILITY_TREE;
 
             private final GeckoSessionSettings.Key<?> mKey;
             private final Class<?> mType;
 
             Key() {
                 final Field field;
                 try {
-                    field = GeckoSessionSettings.class.getField(name());
+                    field = GeckoSessionSettings.class.getDeclaredField(name());
+                    field.setAccessible(true);
                     mKey = (GeckoSessionSettings.Key<?>) field.get(null);
                 } catch (final NoSuchFieldException | IllegalAccessException e) {
                     throw new RuntimeException(e);
                 }
 
                 final ParameterizedType genericType = (ParameterizedType) field.getGenericType();
                 mType = (Class<?>) genericType.getActualTypeArguments()[0];
             }
 
             @SuppressWarnings("unchecked")
             public void set(final GeckoSessionSettings settings, final String value) {
-                if (boolean.class.equals(mType) || Boolean.class.equals(mType)) {
-                    settings.setBoolean((GeckoSessionSettings.Key<Boolean>) mKey,
-                            Boolean.valueOf(value));
-                } else if (int.class.equals(mType) || Integer.class.equals(mType)) {
-                    try {
-                        settings.setInt((GeckoSessionSettings.Key<Integer>) mKey,
-                                (Integer) GeckoSessionSettings.class.getField(value)
-                                        .get(null));
-                    } catch (final NoSuchFieldException | IllegalAccessException |
-                            ClassCastException e) {
-                        settings.setInt((GeckoSessionSettings.Key<Integer>) mKey,
-                                        Integer.valueOf(value));
+                try {
+                    if (boolean.class.equals(mType) || Boolean.class.equals(mType)) {
+                            Method method = GeckoSessionSettings.class.getDeclaredMethod("setBoolean", GeckoSessionSettings.Key.class, boolean.class);
+                            method.setAccessible(true);
+                            method.invoke(settings, mKey, Boolean.valueOf(value));
+                    } else if (int.class.equals(mType) || Integer.class.equals(mType)) {
+                        Method method = GeckoSessionSettings.class.getDeclaredMethod("setInt", GeckoSessionSettings.Key.class, int.class);
+                        method.setAccessible(true);
+                        try {
+                            method.invoke(settings, mKey,
+                                    GeckoSessionSettings.class.getField(value)
+                                            .get(null));
+                        }
+                        catch (final NoSuchFieldException | IllegalAccessException |
+                                ClassCastException e) {
+                            method.invoke(settings, mKey,
+                                    Integer.valueOf(value));
+                        }
+                    } else if (String.class.equals(mType)) {
+                        Method method = GeckoSessionSettings.class.getDeclaredMethod("setString", GeckoSessionSettings.Key.class, String.class);
+                        method.setAccessible(true);
+                        method.invoke(settings, mKey, value);
+                    } else {
+                        throw new IllegalArgumentException("Unsupported type: " +
+                                mType.getSimpleName());
                     }
-                } else if (String.class.equals(mType)) {
-                    settings.setString((GeckoSessionSettings.Key<String>) mKey, value);
-                } else {
-                    throw new IllegalArgumentException("Unsupported type: " +
-                            mType.getSimpleName());
+                } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+                    throw new RuntimeException(e);
                 }
             }
         }
 
         @Target({ElementType.METHOD, ElementType.TYPE})
         @Retention(RetentionPolicy.RUNTIME)
         @interface List {
             Setting[] value();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
@@ -48,81 +48,81 @@ public final class GeckoSessionSettings 
             this.values = values;
         }
     }
 
     /**
      * Key to set the chrome window URI, or null to use default URI.
      * Read-only once session is open.
      */
-    public static final Key<String> CHROME_URI =
+    private static final Key<String> CHROME_URI =
         new Key<String>("chromeUri", /* initOnly */ true, /* values */ null);
     /**
      * Key to set the window screen ID, or 0 to use default ID.
      * Read-only once session is open.
      */
-    public static final Key<Integer> SCREEN_ID =
+    private static final Key<Integer> SCREEN_ID =
         new Key<Integer>("screenId", /* initOnly */ true, /* values */ null);
 
     /**
      * Key to enable and disable tracking protection.
      */
-    public static final Key<Boolean> USE_TRACKING_PROTECTION =
+    private static final Key<Boolean> USE_TRACKING_PROTECTION =
         new Key<Boolean>("useTrackingProtection");
     /**
      * Key to enable and disable private mode browsing.
      * Read-only once session is open.
      */
-    public static final Key<Boolean> USE_PRIVATE_MODE =
+    private static final Key<Boolean> USE_PRIVATE_MODE =
         new Key<Boolean>("usePrivateMode", /* initOnly */ true, /* values */ null);
 
     /**
      * Key to enable and disable multiprocess browsing (e10s).
      * Read-only once session is open.
      */
-    public static final Key<Boolean> USE_MULTIPROCESS =
+    private static final Key<Boolean> USE_MULTIPROCESS =
         new Key<Boolean>("useMultiprocess", /* initOnly */ true, /* values */ null);
 
     /**
      * Key to specify which user agent mode we should use.
      */
-    public static final Key<Integer> USER_AGENT_MODE =
+    private static final Key<Integer> USER_AGENT_MODE =
         new Key<Integer>("userAgentMode", /* initOnly */ false,
                          Arrays.asList(USER_AGENT_MODE_MOBILE, USER_AGENT_MODE_DESKTOP, USER_AGENT_MODE_VR));
 
     /**
      * Key to specify the user agent override string.
      * Set value to null to use the user agent specified by USER_AGENT_MODE.
      */
-    public static final Key<String> USER_AGENT_OVERRIDE =
+    private static final Key<String> USER_AGENT_OVERRIDE =
         new Key<String>("userAgentOverride", /* initOnly */ false, /* values */ null);
 
     /**
      * Key to specify which display-mode we should use.
      */
-    public static final Key<Integer> DISPLAY_MODE =
+    private static final Key<Integer> DISPLAY_MODE =
         new Key<Integer>("displayMode", /* initOnly */ false,
                          Arrays.asList(DISPLAY_MODE_BROWSER, DISPLAY_MODE_MINIMAL_UI,
                                        DISPLAY_MODE_STANDALONE, DISPLAY_MODE_FULLSCREEN));
 
     /**
      * Key to specify if media should be suspended when the session is inactive.
      */
-    public static final Key<Boolean> SUSPEND_MEDIA_WHEN_INACTIVE =
+    private static final Key<Boolean> SUSPEND_MEDIA_WHEN_INACTIVE =
         new Key<Boolean>("suspendMediaWhenInactive", /* initOnly */ false, /* values */ null);
 
     /**
      * Key to specify if JavaScript should be allowed on this session.
      */
-    public static final Key<Boolean> ALLOW_JAVASCRIPT =
+    private static final Key<Boolean> ALLOW_JAVASCRIPT =
             new Key<Boolean>("allowJavascript", /* initOnly */ false, /* values */ null);
     /**
      * Key to specify if entire accessible tree should be exposed with no caching.
      */
-    public static final Key<Boolean> FULL_ACCESSIBILITY_TREE =
+    private static final Key<Boolean> FULL_ACCESSIBILITY_TREE =
             new Key<Boolean>("fullAccessibilityTree", /* initOnly */ false, /* values */ null);
 
     private final GeckoSession mSession;
     private final GeckoBundle mBundle;
 
     public GeckoSessionSettings() {
         this(null, null);
     }
@@ -173,17 +173,17 @@ public final class GeckoSessionSettings 
     public void setAllowJavascript(final boolean value) {
         setBoolean(ALLOW_JAVASCRIPT, value);
     }
 
     public void setFullAccessibilityTree(final boolean value) {
         setBoolean(FULL_ACCESSIBILITY_TREE, value);
     }
 
-    public void setBoolean(final Key<Boolean> key, final boolean value) {
+    private void setBoolean(final Key<Boolean> key, final boolean value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putBoolean(key.name, value);
                 dispatchUpdate();
             }
         }
     }
 
@@ -206,17 +206,17 @@ public final class GeckoSessionSettings 
     public boolean isAllowJavascript() {
         return getBoolean(ALLOW_JAVASCRIPT);
     }
 
     public boolean isFullAccessibilityTree() {
         return getBoolean(FULL_ACCESSIBILITY_TREE);
     }
 
-    public boolean getBoolean(final Key<Boolean> key) {
+    private boolean getBoolean(final Key<Boolean> key) {
         synchronized (mBundle) {
             return mBundle.getBoolean(key.name);
         }
     }
 
     public void setScreenId(final int value) {
         setInt(SCREEN_ID, value);
     }
@@ -224,69 +224,69 @@ public final class GeckoSessionSettings 
     public void setUserAgentMode(final int value) {
         setInt(USER_AGENT_MODE, value);
     }
 
     public void setDisplayMode(final int value) {
         setInt(DISPLAY_MODE, value);
     }
 
-    public void setInt(final Key<Integer> key, final int value) {
+    private void setInt(final Key<Integer> key, final int value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putInt(key.name, value);
                 dispatchUpdate();
             }
         }
     }
 
     public int getScreenId() {
         return getInt(SCREEN_ID);
     }
 
-    public int getUseAgentMode() {
+    public int getUserAgentMode() {
         return getInt(USER_AGENT_MODE);
     }
 
     public int getDisplayMode() {
         return getInt(DISPLAY_MODE);
     }
 
-    public int getInt(final Key<Integer> key) {
+    private int getInt(final Key<Integer> key) {
         synchronized (mBundle) {
             return mBundle.getInt(key.name);
         }
     }
 
     public void setChromeUri(final String value) {
         setString(CHROME_URI, value);
     }
 
     public void setUserAgentOverride(final String value) {
         setString(USER_AGENT_OVERRIDE, value);
     }
 
-    public void setString(final Key<String> key, final String value) {
+    private void setString(final Key<String> key, final String value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putString(key.name, value);
                 dispatchUpdate();
             }
         }
     }
 
     public String getChromeUri() {
         return getString(USER_AGENT_OVERRIDE);
     }
 
     public String getUserAgentOverride() {
         return getString(USER_AGENT_OVERRIDE);
     }
 
-    public String getString(final Key<String> key) {
+    private String getString(final Key<String> key) {
         synchronized (mBundle) {
             return mBundle.getString(key.name);
         }
     }
 
     /* package */ GeckoBundle toBundle() {
         return new GeckoBundle(mBundle);
     }