Bug 1529972 - Add GeckoView API to control CSS prefers-color-scheme query. r=esawin,geckoview-reviewers
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 01 Apr 2019 17:44:39 +0000
changeset 467088 0d5da6e22753f0995109072b4c3c0c76bb9f46e6
parent 467087 40ac7ce8acc94d1dad863bda32ade463aa9138bd
child 467089 80fcea2e4efc22e871e4206675debca7cdc62664
push id35795
push usercsabou@mozilla.com
push dateMon, 01 Apr 2019 21:54:51 +0000
treeherdermozilla-central@5a85cf971fef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin, geckoview-reviewers
bugs1529972
milestone68.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 1529972 - Add GeckoView API to control CSS prefers-color-scheme query. r=esawin,geckoview-reviewers Differential Revision: https://phabricator.services.mozilla.com/D24943
mobile/android/geckoview/api.txt
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
--- a/mobile/android/geckoview/api.txt
+++ b/mobile/android/geckoview/api.txt
@@ -217,33 +217,38 @@ package org.mozilla.geckoview {
     method @android.support.annotation.Nullable public java.lang.Float getDisplayDensityOverride();
     method @android.support.annotation.Nullable public java.lang.Integer getDisplayDpiOverride();
     method @android.support.annotation.NonNull public android.os.Bundle getExtras();
     method public boolean getFontInflationEnabled();
     method public float getFontSizeFactor();
     method public boolean getJavaScriptEnabled();
     method @android.support.annotation.Nullable public java.lang.String[] getLocales();
     method public boolean getPauseForDebuggerEnabled();
+    method public int getPreferredColorScheme();
     method public boolean getRemoteDebuggingEnabled();
     method @android.support.annotation.Nullable public org.mozilla.geckoview.GeckoRuntime getRuntime();
     method @android.support.annotation.Nullable public android.graphics.Rect getScreenSizeOverride();
     method public boolean getUseContentProcessHint();
     method public boolean getUseMaxScreenDepth();
     method public boolean getWebFontsEnabled();
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setAutomaticFontSizeAdjustment(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setAutoplayDefault(int);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setConsoleOutputEnabled(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setFontInflationEnabled(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setFontSizeFactor(float);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setJavaScriptEnabled(boolean);
     method public void setLocales(@android.support.annotation.Nullable java.lang.String[]);
+    method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setPreferredColorScheme(int);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setRemoteDebuggingEnabled(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setWebFontsEnabled(boolean);
     field public static final int AUTOPLAY_DEFAULT_ALLOWED = 0;
     field public static final int AUTOPLAY_DEFAULT_BLOCKED = 1;
+    field public static final int COLOR_SCHEME_DARK = 1;
+    field public static final int COLOR_SCHEME_LIGHT = 0;
+    field public static final int COLOR_SCHEME_SYSTEM = -1;
     field public static final android.os.Parcelable.Creator<org.mozilla.geckoview.GeckoRuntimeSettings> CREATOR;
   }
 
   @android.support.annotation.AnyThread public static final class GeckoRuntimeSettings.Builder extends org.mozilla.geckoview.RuntimeSettings.Builder<Settings extends org.mozilla.geckoview.RuntimeSettings> {
     ctor public Builder();
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder arguments(@android.support.annotation.NonNull java.lang.String[]);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder automaticFontSizeAdjustment(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder autoplayDefault(int);
@@ -253,16 +258,17 @@ package org.mozilla.geckoview {
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder displayDensityOverride(float);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder displayDpiOverride(int);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder extras(@android.support.annotation.NonNull android.os.Bundle);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder fontInflation(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder fontSizeFactor(float);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder javaScriptEnabled(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder locales(java.lang.String[]);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder pauseForDebugger(boolean);
+    method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder preferredColorScheme(int);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder remoteDebuggingEnabled(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder screenSizeOverride(int, int);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder useContentProcessHint(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder useMaxScreenDepth(boolean);
     method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder webFontsEnabled(boolean);
     method @android.support.annotation.NonNull protected org.mozilla.geckoview.GeckoRuntimeSettings newSettings(org.mozilla.geckoview.GeckoRuntimeSettings);
   }
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -307,16 +307,28 @@ public final class GeckoRuntimeSettings 
          * May be either {@link GeckoRuntimeSettings#AUTOPLAY_DEFAULT_ALLOWED} or {@link GeckoRuntimeSettings#AUTOPLAY_DEFAULT_BLOCKED}
          * @param autoplay Allows or blocks video autoplay.
          * @return This Builder instance.
          */
         public @NonNull Builder autoplayDefault(final @AutoplayDefault int autoplay) {
             getSettings().mAutoplayDefault.set(autoplay);
             return this;
         }
+
+        /**
+         * Sets the preferred color scheme override for web content.
+         *
+         * @param scheme The preferred color scheme. Must be one of the
+         *               {@link GeckoRuntimeSettings#COLOR_SCHEME_LIGHT COLOR_SCHEME_*} constants.
+         * @return This Builder instance.
+         */
+        public @NonNull Builder preferredColorScheme(final @ColorScheme int scheme) {
+            getSettings().mPreferredColorScheme.set(scheme);
+            return this;
+        }
     }
 
     private GeckoRuntime mRuntime;
     /* package */ boolean mUseContentProcess;
     /* package */ String[] mArgs;
     /* package */ Bundle mExtras;
 
     /* package */ ContentBlocking.Settings mContentBlocking;
@@ -334,16 +346,18 @@ public final class GeckoRuntimeSettings 
     /* package */ final Pref<Boolean> mConsoleOutput = new Pref<Boolean>(
         "geckoview.console.enabled", false);
     /* package */ final Pref<Integer> mAutoplayDefault = new Pref<Integer>(
         "media.autoplay.default", AUTOPLAY_DEFAULT_BLOCKED);
     /* package */ final Pref<Integer> mFontSizeFactor = new Pref<>(
         "font.size.systemFontScale", 100);
     /* package */ final Pref<Integer> mFontInflationMinTwips = new Pref<>(
         "font.size.inflation.minTwips", 0);
+    /* package */ final Pref<Integer> mPreferredColorScheme = new Pref<>(
+        "ui.systemUsesDarkTheme", -1);
 
     /* package */ boolean mDebugPause;
     /* package */ boolean mUseMaxScreenDepth;
     /* package */ float mDisplayDensityOverride = -1.0f;
     /* package */ int mDisplayDpiOverride;
     /* package */ int mScreenWidthOverride;
     /* package */ int mScreenHeightOverride;
     /* package */ Class<? extends Service> mCrashHandler;
@@ -754,16 +768,50 @@ public final class GeckoRuntimeSettings 
      * Get whether or not font inflation for non mobile-friendly pages is currently enabled.
      *
      * @return True if font inflation is enabled.
      */
     public boolean getFontInflationEnabled() {
         return mFontInflationMinTwips.get() > 0;
     }
 
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef({COLOR_SCHEME_LIGHT,
+             COLOR_SCHEME_DARK,
+             COLOR_SCHEME_SYSTEM})
+    /* package */ @interface ColorScheme {}
+
+    /** A light theme for web content is preferred. */
+    public static final int COLOR_SCHEME_LIGHT = 0;
+    /** A dark theme for web content is preferred. */
+    public static final int COLOR_SCHEME_DARK = 1;
+    /** The preferred color scheme will be based on system settings. */
+    public static final int COLOR_SCHEME_SYSTEM = -1;
+
+    /**
+     * Gets the preferred color scheme override for web content.
+     *
+     * @return One of the {@link GeckoRuntimeSettings#COLOR_SCHEME_LIGHT COLOR_SCHEME_*} constants.
+     */
+    public @ColorScheme int getPreferredColorScheme() {
+        return mPreferredColorScheme.get();
+    }
+
+    /**
+     * Sets the preferred color scheme override for web content.
+     *
+     * @param scheme The preferred color scheme. Must be one of the
+     *               {@link GeckoRuntimeSettings#COLOR_SCHEME_LIGHT COLOR_SCHEME_*} constants.
+     * @return This GeckoRuntimeSettings instance.
+     */
+    public @NonNull GeckoRuntimeSettings setPreferredColorScheme(final @ColorScheme int scheme) {
+        mPreferredColorScheme.commit(scheme);
+        return this;
+    }
+
     @Override // Parcelable
     public void writeToParcel(final Parcel out, final int flags) {
         super.writeToParcel(out, flags);
 
         ParcelableUtils.writeBoolean(out, mUseContentProcess);
         out.writeStringArray(mArgs);
         mExtras.writeToParcel(out, flags);
         ParcelableUtils.writeBoolean(out, mDebugPause);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
@@ -26,21 +26,26 @@ exclude: true
   [`ContentBlocking#CB_DEFAULT`][68.6] and [`ContentBlocking#CB_STRICT`][68.7]
   for clearer app default selections.
 
 [68.4]: ../ContentBlocking.html$AT_DEFAULT
 [68.5]: ../ContentBlocking.html$AT_STRICT
 [68.6]: ../ContentBlocking.html$CB_DEFAULT
 [68.7]: ../ContentBlocking.html$CB_STRICT
 
-- Added [`GeckoSession.SessionState.fromString`][. This can be used to deserialize a
-  `GeckoSession.SessionState` instance previously serialized to a `String` vai
-  `GeckoSession.SessionState.toString`.
+- Added [`GeckoSession.SessionState.fromString`][68.8]. This can be used to
+  deserialize a `GeckoSession.SessionState` instance previously serialized to
+  a `String` via `GeckoSession.SessionState.toString`.
 
-[68.4]: ../GeckoSession.SessionState.html#fromString-java.lang.String-
+[68.8]: ../GeckoSession.SessionState.html#fromString-java.lang.String-
+
+- Added [`GeckoRuntimeSettings#setPreferredColorScheme`][68.9] to override
+  the default color theme for web content ("light" or "dark").
+
+[68.9]: ../GeckoRuntimeSettings.html#setPreferredColorScheme-int-
 
 ## v67
 - Added [`setAutomaticFontSizeAdjustment`][67.2] to
   [`GeckoRuntimeSettings`][67.3] for automatically adjusting font size settings
   depending on the OS-level font size setting.
 
 [67.2]: ../GeckoRuntimeSettings.html#setAutomaticFontSizeAdjustment-boolean-
 [67.3]: ../GeckoRuntimeSettings.html
@@ -238,9 +243,9 @@ exclude: true
 [65.23]: ../GeckoSession.FinderResult.html
 
 - Update [`CrashReporter#sendCrashReport`][65.24] to return the crash ID as a
   [`GeckoResult<String>`][65.25].
 
 [65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
 [65.25]: ../GeckoResult.html
 
-[api-version]: d35c31c60693caf8467b98a196b382707c3bd044
+[api-version]: 053d9b4164690ff13996be9e7288dd183e2a1db4