forked from mirrors/gecko-dev
Bug 1843926 - Add a new ExtensionsProcessEnabled GeckoRuntimeSettings and expose it in GeckoViewExample Settings UI. r=amejiamarmol,geckoview-reviewers,zmckenney
Differential Revision: https://phabricator.services.mozilla.com/D183779
This commit is contained in:
parent
7d98e65195
commit
7ea21d9c6c
8 changed files with 164 additions and 6 deletions
|
|
@ -835,6 +835,7 @@ package org.mozilla.geckoview {
|
|||
method public boolean getDoubleTapZoomingEnabled();
|
||||
method public boolean getEnterpriseRootsEnabled();
|
||||
method @AnyThread @Nullable public ExperimentDelegate getExperimentDelegate();
|
||||
method @Nullable public Boolean getExtensionsProcessEnabled();
|
||||
method public boolean getExtensionsWebAPIEnabled();
|
||||
method @NonNull public Bundle getExtras();
|
||||
method public boolean getFontInflationEnabled();
|
||||
|
|
@ -861,6 +862,7 @@ package org.mozilla.geckoview {
|
|||
method @NonNull public GeckoRuntimeSettings setConsoleOutputEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setDoubleTapZoomingEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setEnterpriseRootsEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setExtensionsProcessEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setExtensionsWebAPIEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setFontInflationEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings setFontSizeFactor(float);
|
||||
|
|
@ -900,6 +902,7 @@ package org.mozilla.geckoview {
|
|||
method @NonNull public GeckoRuntimeSettings.Builder doubleTapZoomingEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings.Builder enterpriseRootsEnabled(boolean);
|
||||
method @AnyThread @NonNull public GeckoRuntimeSettings.Builder experimentDelegate(@Nullable ExperimentDelegate);
|
||||
method @NonNull public GeckoRuntimeSettings.Builder extensionsProcessEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings.Builder extensionsWebAPIEnabled(boolean);
|
||||
method @NonNull public GeckoRuntimeSettings.Builder extras(@NonNull Bundle);
|
||||
method @NonNull public GeckoRuntimeSettings.Builder fontInflation(boolean);
|
||||
|
|
|
|||
|
|
@ -3091,4 +3091,39 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
equalTo(geckoPrefs[0] as Boolean),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExtensionsProcessDisabledByDefault() {
|
||||
val settings = GeckoRuntimeSettings.Builder()
|
||||
.build()
|
||||
|
||||
assertThat(
|
||||
"extensionsProcessEnabled setting default should be null",
|
||||
settings.extensionsProcessEnabled,
|
||||
equalTo(null),
|
||||
)
|
||||
|
||||
val geckoPrefs = sessionRule.getPrefs(
|
||||
"extensions.webextensions.remote",
|
||||
)
|
||||
|
||||
assertThat(
|
||||
"extensions.webextensions.remote pref default value should be false",
|
||||
geckoPrefs[0] as Boolean,
|
||||
equalTo(false),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExtensionsProcessControlledFromSettings() {
|
||||
val settings = GeckoRuntimeSettings.Builder()
|
||||
.extensionsProcessEnabled(true)
|
||||
.build()
|
||||
|
||||
assertThat(
|
||||
"extensionsProcessEnabled setting should be set to true",
|
||||
settings.extensionsProcessEnabled,
|
||||
equalTo(true),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,18 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether Extensions Process support should be enabled.
|
||||
*
|
||||
* @param flag A flag determining whether Extensions Process support should be enabled. Default
|
||||
* is false.
|
||||
* @return This Builder instance.
|
||||
*/
|
||||
public @NonNull Builder extensionsProcessEnabled(final boolean flag) {
|
||||
getSettings().mExtensionsProcess.set(flag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether JavaScript support should be enabled.
|
||||
*
|
||||
|
|
@ -528,6 +540,8 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
|
|||
/* package */ final Pref<Integer> mProcessCount = new Pref<>("dom.ipc.processCount", 2);
|
||||
/* package */ final Pref<Boolean> mExtensionsWebAPIEnabled =
|
||||
new Pref<>("extensions.webapi.enabled", false);
|
||||
/* package */ final PrefWithoutDefault<Boolean> mExtensionsProcess =
|
||||
new PrefWithoutDefault<Boolean>("extensions.webextensions.remote");
|
||||
|
||||
/* package */ int mPreferredColorScheme = COLOR_SCHEME_SYSTEM;
|
||||
|
||||
|
|
@ -657,6 +671,26 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether Extensions Process support is enabled.
|
||||
*
|
||||
* @return Whether Extensions Process support is enabled.
|
||||
*/
|
||||
public @Nullable Boolean getExtensionsProcessEnabled() {
|
||||
return mExtensionsProcess.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether Extensions Process support should be enabled.
|
||||
*
|
||||
* @param flag A flag determining whether Extensions Process support should be enabled.
|
||||
* @return This GeckoRuntimeSettings instance.
|
||||
*/
|
||||
public @NonNull GeckoRuntimeSettings setExtensionsProcessEnabled(final boolean flag) {
|
||||
mExtensionsProcess.commit(flag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether remote debugging support is enabled.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -109,6 +109,10 @@ public abstract class RuntimeSettings implements Parcelable {
|
|||
return mIsSet;
|
||||
}
|
||||
|
||||
public boolean hasDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
mValue = defaultValue;
|
||||
mIsSet = false;
|
||||
|
|
@ -128,6 +132,48 @@ public abstract class RuntimeSettings implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to handle pref-based settings that should not have a default value, so that they will be
|
||||
* controlled by GeckoView only when they are set.
|
||||
*
|
||||
* <p>When no value is set for a PrefWithoutDefault, its value on the GeckoView side is expected
|
||||
* to be null, and the value set on the Gecko side to stay set to the either the prefs file
|
||||
* included in the GeckoView build, or the user prefs file created by the xpcshell and mochitest
|
||||
* test harness.
|
||||
*/
|
||||
/* package */ class PrefWithoutDefault<T> extends Pref<T> {
|
||||
public PrefWithoutDefault(@NonNull final String name) {
|
||||
super(name, null);
|
||||
}
|
||||
|
||||
public boolean hasDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public @Nullable T get() {
|
||||
if (!isSet()) {
|
||||
return null;
|
||||
}
|
||||
return super.get();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
if (!isSet()) {
|
||||
// Only add to the bundle prefs and
|
||||
// propagate to Gecko when explicitly set.
|
||||
return;
|
||||
}
|
||||
super.commit();
|
||||
}
|
||||
|
||||
private void addToBundle(final GeckoBundle bundle) {
|
||||
if (!isSet()) {
|
||||
return;
|
||||
}
|
||||
super.addToBundle(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
private RuntimeSettings mParent;
|
||||
private final ArrayList<RuntimeSettings> mChildren;
|
||||
private final ArrayList<Pref<?>> mPrefs;
|
||||
|
|
@ -231,7 +277,15 @@ public abstract class RuntimeSettings implements Parcelable {
|
|||
*/
|
||||
/* package */ void commitResetPrefs() {
|
||||
final ArrayList<String> names = new ArrayList<String>();
|
||||
forAllPrefs(pref -> names.add(pref.name));
|
||||
forAllPrefs(
|
||||
pref -> {
|
||||
// Do not reset prefs that don't have a default value
|
||||
// and are not set.
|
||||
if (!pref.hasDefault() && !pref.isSet()) {
|
||||
return;
|
||||
}
|
||||
names.add(pref.name);
|
||||
});
|
||||
|
||||
final GeckoBundle data = new GeckoBundle(1);
|
||||
data.putStringArray("names", names);
|
||||
|
|
@ -257,10 +311,21 @@ public abstract class RuntimeSettings implements Parcelable {
|
|||
@SuppressWarnings("checkstyle:javadocmethod")
|
||||
public void readFromParcel(final @NonNull Parcel source) {
|
||||
for (final Pref<?> pref : mPrefs) {
|
||||
// We know this is safe.
|
||||
@SuppressWarnings("unchecked")
|
||||
final Pref<Object> uncheckedPref = (Pref<Object>) pref;
|
||||
uncheckedPref.commit(source.readValue(getClass().getClassLoader()));
|
||||
if (pref.hasDefault()) {
|
||||
// We know this is safe.
|
||||
@SuppressWarnings("unchecked")
|
||||
final Pref<Object> uncheckedPref = (Pref<Object>) pref;
|
||||
uncheckedPref.commit(source.readValue(getClass().getClassLoader()));
|
||||
} else {
|
||||
// Don't commit PrefWithoutDefault instances where the value read
|
||||
// from the Parcel is null.
|
||||
@SuppressWarnings("unchecked")
|
||||
final PrefWithoutDefault<Object> uncheckedPref = (PrefWithoutDefault<Object>) pref;
|
||||
final Object sourceValue = source.readValue(getClass().getClassLoader());
|
||||
if (sourceValue != null) {
|
||||
uncheckedPref.commit(sourceValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ exclude: true
|
|||
- Changed [`GeckoSession.AccountSelectorPrompt`][118.8]: added the Provider to which the Account belongs ([bug 1847059]({{bugzilla}}1847059))
|
||||
- Added [`getExperimentDelegate`][118.9] and [`setExperimentDelegate`][118.10] to the GeckoSession allow GeckoView to get and set the experiment delegate for the session. Default is to use the runtime delegate.
|
||||
- ⚠️ Deprecated [`onGetNimbusFeature`][115.5] by 122, please use `ExperimentDelegate.onGetExperimentFeature` instead.
|
||||
- Added [`GeckoRuntimeSettings.Builder.extensionsProcessEnabled`][118.11] for setting whether extensions process is enabled. ([bug 1843926]({{bugzilla}}1843926))
|
||||
|
||||
[118.1]: {{javadoc_uri}}/ExperimentDelegate.html
|
||||
[118.2]: {{javadoc_uri}}/WebExtension.InstallException.ErrorCodes.html#ERROR_BLOCKLISTED
|
||||
|
|
@ -35,6 +36,7 @@ exclude: true
|
|||
[118.8]: {{javadoc_uri}}/GeckoSession.html#AccountSelectorPrompt
|
||||
[118.9]: {{javadoc_uri}}/GeckoSession.html#getExperimentDelegate()
|
||||
[118.10]: {{javadoc_uri}}/GeckoSession.html#setExperimentDelegate(org.mozilla.geckoview.ExperimentDelegate)
|
||||
[118.11]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#extensionsProcessEnabled(Boolean)
|
||||
|
||||
## v116
|
||||
- Added [`GeckoSession.didPrintPageContent`][116.1] to included extra print status for a standard print and new `GeckoPrintException.ERROR_NO_PRINT_DELEGATE`
|
||||
|
|
@ -1415,4 +1417,4 @@ to allow adding gecko profiler markers.
|
|||
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
|
||||
[65.25]: {{javadoc_uri}}/GeckoResult.html
|
||||
|
||||
[api-version]: fd5137f14714faddcffb5d0ba63dd0cfa6721611
|
||||
[api-version]: 5743799f9da8509cfb6546e154f0e2d7989edc72
|
||||
|
|
|
|||
|
|
@ -650,6 +650,17 @@ public class GeckoViewActivity extends AppCompatActivity
|
|||
}
|
||||
};
|
||||
|
||||
private final BooleanSetting mExtensionsProcessEnabled =
|
||||
new BooleanSetting(
|
||||
R.string.key_extensions_process_enabled,
|
||||
R.bool.extensions_process_enabled_default,
|
||||
/* reloadCurrentSession */ true) {
|
||||
@Override
|
||||
public void setValue(final GeckoRuntimeSettings settings, final Boolean value) {
|
||||
settings.setExtensionsProcessEnabled(value);
|
||||
}
|
||||
};
|
||||
|
||||
private final BooleanSetting mTrackingProtection =
|
||||
new BooleanSetting(R.string.key_tracking_protection, R.bool.tracking_protection_default) {
|
||||
@Override
|
||||
|
|
@ -831,6 +842,7 @@ public class GeckoViewActivity extends AppCompatActivity
|
|||
.preferredColorScheme(mPreferredColorScheme.value())
|
||||
.telemetryDelegate(new ExampleTelemetryDelegate())
|
||||
.javaScriptEnabled(mJavascriptEnabled.value())
|
||||
.extensionsProcessEnabled(mExtensionsProcessEnabled.value())
|
||||
.aboutConfigEnabled(true);
|
||||
|
||||
sGeckoRuntime = GeckoRuntime.create(this, runtimeSettingsBuilder.build());
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@
|
|||
<string name="key_javascript_enabled">javascript_enabled</string>
|
||||
<item type="bool" name="javascript_enabled_default">true</item>
|
||||
|
||||
<string name="key_extensions_process_enabled">extensions_process_enabled</string>
|
||||
<item type="bool" name="extensions_process_enabled_default">false</item>
|
||||
|
||||
<string name="key_remote_debugging">remote_debugging</string>
|
||||
<item type="bool" name="remote_debugging_default">true</item>
|
||||
|
||||
|
|
|
|||
|
|
@ -67,5 +67,9 @@
|
|||
app:key="@string/key_javascript_enabled"
|
||||
app:title="Javascript Enabled"
|
||||
app:defaultValue="@bool/javascript_enabled_default"/>
|
||||
<SwitchPreferenceCompat
|
||||
app:key="@string/key_extensions_process_enabled"
|
||||
app:title="Extensions Process Enabled"
|
||||
app:defaultValue="@bool/extensions_process_enabled_default"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
Loading…
Reference in a new issue