Open Bug 1888979 Opened 1 year ago Updated 4 months ago

Consider adding a persistant preference option in GeckoView as a preference type

Categories

(GeckoView :: General, enhancement)

All
Android
enhancement

Tracking

(Not tracked)

People

(Reporter: olivia, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

(Whiteboard: [geckoview:2024H2?][fxdroid][geckoview])

Background

When investigating bug 1884442, I looked into preferences in GeckoView to try and understand more.

From that investigation, I learned:

  • I don't think users were ever intended to be able to manipulate prefs under GeckoRuntimeSettings.java
    • For example, an embedder connects setTranslationsOfferPopup to a UI toggle.
    • The way the Pref<Boolean> currently works is that the default is set at runtime. So, user's Gecko preferences are not persisted, because they will be overwrote. Therefore, the embedder must persist the setting, if they would like it to persist.
  • The current architecture on similar preferences has Fenix maintain the persistence as a setting.
    For example:
  • Related tangent: PrefWithoutDefault may have a bug that causes a runtime setting where a <T> is null when attempting to get. (Encountered when thinking that changing from Pref to PrefWithoutDefault might be a solution.)

For bug 1884442, I followed the existing pattern and allowed Fenix to control persistence. However, this flow feels like it could be improved with a GV API. There are likely many situations where the Gecko known value is fine and even expected.

The GV change to consider in this bug is:

The recommended consideration is to add an option in GeckoView preferences to persist the preference based on what Gecko knows the value to be and not overwrite the value with a new default value at startup.

  • First ensure and investigate Gecko can correctly persist preferences as expected on mobile.
    • It seems it does, because other translations prefs set and get via TranslationsParent and those prefs persist as expected. setLanguageSettings -> GeckoView:Translations:SetLanguageSettings -> set in toolkit.
    • Additionally, I have seen preferences manipulated in about:config persist. (However, if a pref is controlled via a GeckoView Pref then it will rest back to the default on startup.)
  • Create something like class PersistentGeckoPref<T> extends Pref<T>
    • For getting, it should add an event like GeckoView:GetGeckoPrefs in GeckoViewStartup.sys.mjs to ask Gecko for the current value
    • For setting, it should set via an event like GeckoView:SetGeckoPrefs in GeckoViewStartup.sys.mjs (or reuse an existing one)
    • Should allow a default, but that default is only ever set if getting the Gecko pref fails
    • First use case could be converting final Pref<Boolean> mAutomaticallyOfferPopup = new Pref<Boolean>("browser.translations.automaticallyPopup", true); to final PersistentGeckoPref<Boolean> mAutomaticallyOfferPopup = new PersistentGeckoPref<Boolean>("browser.translations.automaticallyPopup", true);
Severity: -- → N/A
See Also: → 1884442

Moving to General

Component: Permissions → General
See Also: → 1908134
Blocks: 1908182

Related tangent: PrefWithoutDefault may have a bug that causes a runtime setting where a <T> is null when attempting to get. (Encountered when thinking that changing from Pref to PrefWithoutDefault might be a solution.)

Filed bug 1908134 to fix the null state.

See Also: → 1909024

Bug 1909024 is an example of a Gecko about:config preference getting clobbered and losing state in the wild.

See Also: → 1865010
Whiteboard: [geckoview:2024H2?]

This bug is likely just solving bug 1908134 to fix PrefWithoutDefault to get the right behavior and switching over to that in a few places.

Leaving this open, because it is really dependent on how bug 1908134 is solved.

Depends on: 1909024
Whiteboard: [geckoview:2024H2?] → [geckoview:2024H2?][fxdroid][geckoview]
Depends on: 1908134
No longer depends on: 1909024
You need to log in before you can comment on or make changes to this bug.