Bug 1369815 - Add display mode to GeckoViewSettings r=esawin
--- 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,
+ `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;
}
}