Closed Bug 1512997 Opened 10 months ago Closed 8 months ago

Provide synchronous API to retrieve user agent string

Categories

(GeckoView :: General, enhancement, P1)

enhancement

Tracking

(firefox65 wontfix, firefox66 wontfix, firefox67 fixed)

RESOLVED FIXED
mozilla67
Tracking Status
firefox65 --- wontfix
firefox66 --- wontfix
firefox67 --- fixed

People

(Reporter: csadilek, Assigned: Agi)

Details

(Whiteboard: [geckoview:fenix:p1] [gvtv])

Attachments

(1 file, 1 obsolete file)

We've just added support for getting and setting the user agent string to our engine-gecko module in Android components. This makes use of the override setting introduced in https://bugzilla.mozilla.org/show_bug.cgi?id=1507369.

However, there's one use case we can't cover with this. We want to provide a way to read the engine default user agent string if none was set by the application. This is used by applications like Firefox for Fire TV to parse the existing value and customize it on startup: https://github.com/mozilla-mobile/firefox-tv/blob/00b61b4f5344eb878b0efa4cafb61d535f1b9bc3/app/src/main/java/org/mozilla/tv/firefox/webrender/UserAgent.kt#L58

The existing API (GeckoSession#getUserAgent) is asynchronous and requires a session to be initialized, which isn't practical in this case. After taking to snorp it might be feasible to add a static value / method to retrieve the default setting?
Product: Firefox for Android → GeckoView
Assignee: nobody → agi
Fenix and Fire TV want this.
Priority: -- → P1
Whiteboard: [geckoview:fenix:p1] [gvtv]

I've looked into this, and the code that generates the UA string is not really build-time friendly (see nsHttpHandler::buildUserAgent).

If having a GeckoSession is the problem we might be able to offer a GeckoRuntime API to get the default UA, but that would still be async (e.g. the native layer may not be ready yet).

Would that be helpful?

Flags: needinfo?(csadilek)

I think we had a similar problem in Fennec and that lead to this duplication:
https://searchfox.org/mozilla-central/source/mobile/android/base/AppConstants.java.in#147-158

Having a GeckoRuntime (vs GeckoSession) API would make this more practical, yes, but it would make the application bootstrap logic more complicated if this new API is async. Now the bootstrapping logic is synchronous and A-C (and GeckoView) deal with initialization internally (apps don't need to observe or wait for engine initialization or any engine ready states).

How bad would it be to add public static Strings for the default user agents to GeckoView?

I suppose if correctness is a concern we can add a test for our static string and the generated one?

(In reply to David Bolter [:davidb] (NeedInfo me for attention) from comment #5)

I suppose if correctness is a concern we can add a test for our static string and the generated one?

My gut feeling was that we shouldn't provide something like this since every app could do this without our help. But I guess it would be something most apps want and very low maintenance for us (I wouldn't expect our UA to change that often). I'll send a patch for this as soon as I have an empty slot.

Flags: needinfo?(csadilek)
Attachment #9045364 - Attachment is obsolete: true
Attachment #9043935 - Attachment description: Bug 1512997 - Add GeckoSession.getDefaultUserAgent API. #geckoview-reviewers!,nalexander! → Bug 1512997 - Add GeckoSession.getDefaultUserAgent API.
Pushed by asferro@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4e46fb46408d
Add GeckoSession.getDefaultUserAgent API. r=nalexander,rbarker
Status: NEW → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67

Agi, is there an A-C or FFTV issue filed to make use of this new user agent string API?

Flags: needinfo?(agi)

Nice.

Flags: needinfo?(agi)
You need to log in before you can comment on or make changes to this bug.