Bug 1454441 - 3. Move remote debugging setting to runtime; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Mon, 23 Apr 2018 12:07:34 -0400
changeset 786583 7d7f6c1d367c467a40a79557cc9d02d05cc8cb8c
parent 786582 956a0355cb401b34b5f75f2f42305fce7b7e1f48
child 786584 2621fd683f44b6d245ad04a9b384808cac763a32
push id107530
push userbmo:nchen@mozilla.com
push dateMon, 23 Apr 2018 16:15:55 +0000
reviewersesawin
bugs1454441
milestone61.0a1
Bug 1454441 - 3. Move remote debugging setting to runtime; r?esawin Move the remote debugging setting to GeckoRuntimeSettings and use it in geckoview_example. MozReview-Commit-ID: G2IINILQAOm
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -120,20 +120,16 @@ public class CustomTabsActivity extends 
         actionBarPresenter.displayUrlOnly(intent.getDataString());
         actionBarPresenter.setBackgroundColor(IntentUtil.getToolbarColor(intent), getWindow());
         actionBarPresenter.setTextLongClickListener(new UrlCopyListener());
 
         mGeckoView = (GeckoView) findViewById(R.id.gecko_view);
 
         final GeckoSessionSettings settings = new GeckoSessionSettings();
         settings.setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, false);
-        settings.setBoolean(
-            GeckoSessionSettings.USE_REMOTE_DEBUGGER,
-            GeckoSharedPrefs.forApp(this).getBoolean(
-                GeckoPreferences.PREFS_DEVTOOLS_REMOTE_USB_ENABLED, false));
         mGeckoSession = new GeckoSession(settings);
         mGeckoSession.setNavigationDelegate(this);
         mGeckoSession.setProgressDelegate(this);
         mGeckoSession.setContentDelegate(this);
 
         mGeckoView.setSession(mGeckoSession, GeckoRuntime.getDefault(this));
 
         mPromptService = new PromptService(this, mGeckoView.getEventDispatcher());
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -88,20 +88,16 @@ public class WebAppActivity extends AppC
         }
 
         super.onCreate(savedInstanceState);
         setContentView(R.layout.webapp_activity);
         mGeckoView = (GeckoView) findViewById(R.id.pwa_gecko_view);
 
         final GeckoSessionSettings settings = new GeckoSessionSettings();
         settings.setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, false);
-        settings.setBoolean(
-            GeckoSessionSettings.USE_REMOTE_DEBUGGER,
-            GeckoSharedPrefs.forApp(this).getBoolean(
-                GeckoPreferences.PREFS_DEVTOOLS_REMOTE_USB_ENABLED, false));
         mGeckoSession = new GeckoSession(settings);
         mGeckoView.setSession(mGeckoSession, GeckoRuntime.getDefault(this));
 
         mGeckoSession.setNavigationDelegate(this);
         mGeckoSession.setContentDelegate(this);
         mGeckoSession.setProgressDelegate(new GeckoSession.ProgressDelegate() {
             @Override
             public void onPageStart(GeckoSession session, String url) {
--- 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
@@ -140,17 +140,16 @@ public class GeckoSessionTestRule extend
     @Retention(RetentionPolicy.RUNTIME)
     public @interface Setting {
         enum Key {
             CHROME_URI,
             DISPLAY_MODE,
             SCREEN_ID,
             USE_MULTIPROCESS,
             USE_PRIVATE_MODE,
-            USE_REMOTE_DEBUGGER,
             USE_TRACKING_PROTECTION;
 
             private final GeckoSessionSettings.Key<?> mKey;
             private final Class<?> mType;
 
             Key() {
                 final Field field;
                 try {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -78,16 +78,26 @@ public final class GeckoRuntimeSettings 
          * @param flag A flag determining whether JavaScript should be enabled.
          */
         public @NonNull Builder javaScriptEnabled(final boolean flag) {
             mSettings.mJavaScript.set(flag);
             return this;
         }
 
         /**
+         * Set whether remote debugging support should be enabled.
+         *
+         * @param enabled True if remote debugging should be enabled.
+         */
+        public @NonNull Builder remoteDebuggingEnabled(final boolean enabled) {
+            mSettings.mRemoteDebugging.set(enabled);
+            return this;
+        }
+
+        /**
          * Set whether support for web fonts should be enabled.
          *
          * @param flag A flag determining whether web fonts should be enabled.
          */
         public @NonNull Builder webFontsEnabled(final boolean flag) {
             mSettings.mWebFonts.set(flag);
             return this;
         }
@@ -125,41 +135,49 @@ public final class GeckoRuntimeSettings 
             if (GeckoRuntimeSettings.this.runtime != null) {
                 GeckoRuntimeSettings.this.runtime.setPref(name, value);
             }
         }
     }
 
     /* package */ Pref<Boolean> mJavaScript = new Pref<Boolean>(
         "javascript.enabled", true);
+    /* package */ Pref<Boolean> mRemoteDebugging = new Pref<Boolean>(
+        "devtools.debugger.remote-enabled", false);
     /* package */ Pref<Boolean> mWebFonts = new Pref<Boolean>(
         "browser.display.use_document_fonts", true);
 
     private final Pref<?>[] mPrefs = new Pref<?>[] {
-        mJavaScript, mWebFonts
+        mJavaScript, mRemoteDebugging, mWebFonts
     };
 
     /* package */ GeckoRuntimeSettings() {
         this(null);
     }
 
     /* package */ GeckoRuntimeSettings(final @Nullable GeckoRuntimeSettings settings) {
         if (BuildConfig.DEBUG && prefCount != mPrefs.length) {
             throw new AssertionError("Add new pref to prefs list");
         }
 
         if (settings == null) {
             mArgs = new String[0];
             mExtras = new Bundle();
-        } else {
-            mUseContentProcess = settings.getUseContentProcessHint();
-            mArgs = settings.getArguments().clone();
-            mExtras = new Bundle(settings.getExtras());
-            mJavaScript.set(settings.mJavaScript.get());
-            mWebFonts.set(settings.mWebFonts.get());
+            return;
+        }
+
+        mUseContentProcess = settings.getUseContentProcessHint();
+        mArgs = settings.getArguments().clone();
+        mExtras = new Bundle(settings.getExtras());
+
+        for (int i = 0; i < mPrefs.length; i++) {
+            // We know this is safe.
+            @SuppressWarnings("unchecked")
+            final Pref<Object> uncheckedPref = (Pref<Object>) mPrefs[i];
+            uncheckedPref.set(settings.mPrefs[i].get());
         }
     }
 
     /* package */ void flush() {
         for (final Pref<?> pref: mPrefs) {
             pref.flush();
         }
     }
@@ -206,16 +224,35 @@ public final class GeckoRuntimeSettings 
      * @param flag A flag determining whether JavaScript should be enabled.
      */
     public @NonNull GeckoRuntimeSettings setJavaScriptEnabled(final boolean flag) {
         mJavaScript.set(flag);
         return this;
     }
 
     /**
+     * Get whether remote debugging support is enabled.
+     *
+     * @return True if remote debugging support is enabled.
+     */
+    public boolean getRemoteDebuggingEnabled() {
+        return mRemoteDebugging.get();
+    }
+
+    /**
+     * Set whether remote debugging support should be enabled.
+     *
+     * @param enabled True if remote debugging should be enabled.
+     */
+    public @NonNull GeckoRuntimeSettings setRemoteDebuggingEnabled(final boolean enabled) {
+        mRemoteDebugging.set(enabled);
+        return this;
+    }
+
+    /**
      * Get whether web fonts support is enabled.
      *
      * @return Whether web fonts support is enabled.
      */
     public boolean getWebFontsEnabled() {
         return mWebFonts.get();
     }
 
@@ -234,27 +271,34 @@ public final class GeckoRuntimeSettings 
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         out.writeByte((byte) (mUseContentProcess ? 1 : 0));
         out.writeStringArray(mArgs);
         mExtras.writeToParcel(out, flags);
-        out.writeByte((byte) (mJavaScript.get() ? 1 : 0));
-        out.writeByte((byte) (mWebFonts.get() ? 1 : 0));
+
+        for (final Pref<?> pref : mPrefs) {
+            out.writeValue(pref.get());
+        }
     }
 
     // AIDL code may call readFromParcel even though it's not part of Parcelable.
     public void readFromParcel(final Parcel source) {
         mUseContentProcess = source.readByte() == 1;
         mArgs = source.createStringArray();
         mExtras.readFromParcel(source);
-        mJavaScript.set(source.readByte() == 1);
-        mWebFonts.set(source.readByte() == 1);
+
+        for (final Pref<?> pref : mPrefs) {
+            // We know this is safe.
+            @SuppressWarnings("unchecked")
+            final Pref<Object> uncheckedPref = (Pref<Object>) pref;
+            uncheckedPref.set(source.readValue(getClass().getClassLoader()));
+        }
     }
 
     public static final Parcelable.Creator<GeckoRuntimeSettings> CREATOR
         = new Parcelable.Creator<GeckoRuntimeSettings>() {
         @Override
         public GeckoRuntimeSettings createFromParcel(final Parcel in) {
             final GeckoRuntimeSettings settings = new GeckoRuntimeSettings();
             settings.readFromParcel(in);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
@@ -85,19 +85,16 @@ public final class GeckoSessionSettings 
     /*
      * Key to specify which display-mode we should use
      */
     public 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));
 
-    public static final Key<Boolean> USE_REMOTE_DEBUGGER =
-        new Key<Boolean>("useRemoteDebugger");
-
     private final GeckoSession mSession;
     private final GeckoBundle mBundle;
 
     public GeckoSessionSettings() {
         this(null, null);
     }
 
     public GeckoSessionSettings(final @NonNull GeckoSessionSettings settings) {
@@ -116,17 +113,16 @@ public final class GeckoSessionSettings 
         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.putBoolean(USE_DESKTOP_MODE.name, false);
         mBundle.putInt(DISPLAY_MODE.name, DISPLAY_MODE_BROWSER);
-        mBundle.putBoolean(USE_REMOTE_DEBUGGER.name, false);
     }
 
     public void setBoolean(final Key<Boolean> key, final boolean value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putBoolean(key.name, value);
                 dispatchUpdate();
             }
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -133,22 +133,18 @@ public class GeckoViewActivity extends A
     }
 
     private void loadFromIntent(final Intent intent) {
         final Uri uri = intent.getData();
         mGeckoSession.loadUri(uri != null ? uri.toString() : DEFAULT_URL);
     }
 
     private void loadSettings(final Intent intent) {
-        final GeckoSessionSettings settings = mGeckoSession.getSettings();
-        settings.setBoolean(
-            GeckoSessionSettings.USE_REMOTE_DEBUGGER,
+        sGeckoRuntime.getSettings().setRemoteDebuggingEnabled(
             intent.getBooleanExtra(USE_REMOTE_DEBUGGER_EXTRA, false));
-
-        Log.i(LOGTAG, "Load with settings " + settings);
     }
 
     @Override
     protected void onActivityResult(final int requestCode, final int resultCode,
                                     final Intent data) {
         if (requestCode == REQUEST_FILE_PICKER) {
             final BasicGeckoViewPrompt prompt = (BasicGeckoViewPrompt)
                     mGeckoSession.getPromptDelegate();