Bug 1369815 - Add display mode to GeckoViewSettings r=esawin
☠☠ backed out by 76f15802d69c ☠ ☠
authorJames Willcox <snorp@snorp.net>
Thu, 10 Aug 2017 15:29:28 -0500
changeset 374792 d25a5921d961a0f5dc392a785f5d46704ca82bfa
parent 374791 3b956ceaaf8bd8a1750ae4405fbe1220f25ae70d
child 374793 a758c86dd864ccabbdb4225075bf932d4c146683
push id93765
push userjwillcox@mozilla.com
push dateTue, 15 Aug 2017 14:30:19 +0000
treeherdermozilla-inbound@4fb119706335 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1369815
milestone57.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 1369815 - Add display mode to GeckoViewSettings r=esawin
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
mobile/android/modules/geckoview/GeckoViewSettings.jsm
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
@@ -17,26 +17,51 @@ public final class GeckoViewSettings {
     private static class Key<T> {
         private final String text;
 
         public Key(final String text) {
             this.text = text;
         }
     }
 
+    public enum DisplayMode {
+        // This needs to match nsIDocShell.idl
+        BROWSER(0),
+        MINIMAL_UI(1),
+        STANDALONE(2),
+        FULLSCREEN(3);
+
+        private final int mMode;
+
+        DisplayMode(int mode) {
+            mMode = mode;
+        }
+
+        public int value() {
+            return mMode;
+        }
+    }
+
     /*
      * Key to enabled and disable tracking protection.
      */
     public static final Key<Boolean> USE_TRACKING_PROTECTION =
         new Key<Boolean>("useTrackingProtection");
     /*
      * Key to enabled and disable private mode browsing.
      */
     public static final Key<Boolean> USE_PRIVATE_MODE =
         new Key<Boolean>("usePrivateMode");
+
+    /*
+     * Key to specify which display-mode we should use
+     */
+    public static final Key<Boolean> USE_DISPLAY_MODE =
+        new Key<Boolean>("useDisplayMode");
+
     /*
      * Key to enabled and disable multiprocess browsing (e10s).
      * Note: can only be set during GeckoView initialization, changes during an
      * active GeckoView session will be ignored.
      */
     public static final Key<Boolean> USE_MULTIPROCESS =
         new Key<Boolean>("useMultiprocess");
 
@@ -73,16 +98,33 @@ public final class GeckoViewSettings {
     }
 
     public boolean getBoolean(final Key<Boolean> key) {
         synchronized (mBundle) {
             return mBundle.getBoolean(key.text);
         }
     }
 
+    public void setInt(final Key<Boolean> key, int value) {
+        synchronized (mBundle) {
+            final Object old = mBundle.get(key.text);
+            if (old != null && old.equals(value)) {
+                return;
+            }
+            mBundle.putInt(key.text, value);
+        }
+        dispatchUpdate();
+    }
+
+    public int getInt(final Key<Boolean> key) {
+        synchronized (mBundle) {
+            return mBundle.getInt(key.text);
+        }
+    }
+
     /* package */ GeckoBundle asBundle() {
         return mBundle;
     }
 
     private void dispatchUpdate() {
         if (mEventDispatcher != null) {
             mEventDispatcher.dispatch("GeckoView:UpdateSettings", null);
         }
--- a/mobile/android/modules/geckoview/GeckoViewSettings.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewSettings.jsm
@@ -23,40 +23,42 @@ function debug(aMsg) {
 
 // Handles GeckoView settings including:
 // * tracking protection
 // * multiprocess
 class GeckoViewSettings extends GeckoViewModule {
   init() {
     this._isSafeBrowsingInit = false;
     this._useTrackingProtection = false;
+    this._displayMode = Ci.nsIDocShell.DISPLAY_MODE_BROWSER;
 
     // We only allow to set this setting during initialization, further updates
     // will be ignored.
     this.useMultiprocess = !!this.settings.useMultiprocess;
   }
 
   onSettingsUpdate() {
     debug("onSettingsUpdate: " + JSON.stringify(this.settings));
 
     this.useTrackingProtection = !!this.settings.useTrackingProtection;
+    this.useDisplayMode = this.settings.useDisplayMode;
   }
 
   get useTrackingProtection() {
     return this._useTrackingProtection;
   }
 
   set useTrackingProtection(aUse) {
     if (aUse && !this._isSafeBrowsingInit) {
       SafeBrowsing.init();
       this._isSafeBrowsingInit = true;
     }
     if (aUse != this._useTrackingProtection) {
-      this.messageManager.loadFrameScript("data:," +
-        "docShell.useTrackingProtection = " + aUse,
+      this.messageManager.loadFrameScript('data:,' +
+        `docShell.useTrackingProtection = ${aUse}`,
         true
       );
       this._useTrackingProtection = aUse;
     }
   }
 
   get useMultiprocess() {
     return this.browser.getAttribute("remote") == "true";
@@ -70,10 +72,32 @@ class GeckoViewSettings extends GeckoVie
     parentNode.removeChild(this.browser);
 
     if (aUse) {
       this.browser.setAttribute("remote", "true");
     } else {
       this.browser.removeAttribute("remote");
     }
     parentNode.appendChild(this.browser);
+
+    // Re-set the display mode, as we probably need to set it on
+    // a different docshell now
+    this.useDisplayMode = this.useDisplayMode;
+  }
+
+  get useDisplayMode() {
+    return this._displayMode;
+  }
+
+  set useDisplayMode(aMode) {
+    if (!this.useMultiprocess) {
+      this.window.QueryInterface(Ci.nsIInterfaceRequestor)
+                   .getInterface(Ci.nsIDocShell)
+                   .displayMode = aMode;
+    } else {
+      this.messageManager.loadFrameScript('data:,' +
+        `docShell.displayMode = ${aMode}`,
+        true
+      );
+    }
+    this._displayMode = aMode;
   }
 }