Where is navigator.languages set in the Chromium code?

399 views
Skip to first unread message

Yves Arrouye

unread,
Feb 19, 2021, 1:54:34 PM2/19/21
to chromium-dev
I've been looking at where the Accept-Language header and navigator.languages properties are set in Chromium. I think the former (Accept-Language) is set here (and the value provided by ComputeAcceptLanguage). I can't find how navigator.languages (as accessible from JS) is defined. Can someone help me understand it (and, for example, if changing the above directly affects navigator.languages)?

Thanks!

YA

Dave Tapuska

unread,
Feb 19, 2021, 2:01:31 PM2/19/21
to drc...@chromium.org, chromium-dev

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAFpPgjqDQ4rp%3DZLgM-7CbijZUegZ8cYJPcd1MYH6uG2oYMNSCg%40mail.gmail.com.

David Dorwin

unread,
Feb 19, 2021, 2:06:43 PM2/19/21
to dtap...@chromium.org, Wez, drc...@chromium.org, chromium-dev
+Wez was looking at this recently. If I recall correctly, there are three mechanisms.

Dave Tapuska

unread,
Feb 19, 2021, 2:11:23 PM2/19/21
to David Dorwin, Wez, drc...@chromium.org, chromium-dev
Sorry if what I indicated wasn't clear, navigator.languages comes to the renderer as a RendererPreference which is set by the browser here and the value is loaded from the preference service. So no updating the code where you indicated does not influence navigator.languages.

dave.

Yves Arrouye

unread,
Feb 19, 2021, 2:17:36 PM2/19/21
to Dave Tapuska, David Dorwin, Wez, chromium-dev
Thanks Dave. Interestingly, that code you linked to (lines 101 to 108) is the same as ProfileNetworkContextService::ComputeAcceptLanguage(). I wonder if a common method would be good there. Not sure what the best place to have this would be, but can dig in. (Some language methods are in HttpUtil but "HTTP" doesn't seem right for the renderer).

YA

Yves Arrouye

unread,
Feb 19, 2021, 8:07:33 PM2/19/21
to Dave Tapuska, David Dorwin, Wez, chromium-dev
A quick follow up... What we're looking at is inject a private language tag when a preference set by Chrome OS's demo mode exists. If I wanted to only check for this under Chrome OS, with the new proliferation of IS_CHROMEOS_XXX defines, do I need to check for more than one e.g. so the renderer and the browser are in sync?  

Wez

unread,
Feb 22, 2021, 2:03:25 AM2/22/21
to Yves Arrouye, Dave Tapuska, David Dorwin, chromium-dev
Things are a little confusing right now but basically you if you want to update both navigator.languages and the (to-be-deprecated, apparently) ClientHints language header, then you can change what the ChromeContentBrowserClient::GetAcceptLangs() function returns.  The accept-language header is set separately, at the moment; it is based on GetApplicationLocale() in tests (see https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/chrome_content_browser_client.cc;l=4993) and is determine by the ProfileNetworkContextService in production (see https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/chrome_content_browser_client.cc;l=4987).

Depending on where Chrome can determine whether it is in "ChromeOS demo mode", you could e.g. plumb something in to the ComputeAcceptLanguage() function at https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/net/profile_network_context_service.cc;l=656

Note that the ClientHints language header is being removed from the spec, which will be a good opportunity to make the relationship between GetApplicationLocale(), GetAcceptLangs(), ConfigureNetworkContextParams(), navigator.languages and accept-language clearer.
Reply all
Reply to author
Forward
0 new messages