Mozilla Home
Privacy
Cookies
Legal
Bugzilla
Browse
Advanced Search
New Bug
Reports
Documentation
Log In
Log In with GitHub
or
Remember me
Browse
Advanced Search
New Bug
Reports
Documentation
Attachment 462244 Details for
Bug 55366
[patch]
Patch 5: Change navigator.language to use Accept-Language
lang-js-55366-5.diff (text/plain), 3.81 KB, created by
Ben Bucksch (:BenB)
(
hide
)
Description:
Patch 5: Change navigator.language to use Accept-Language
Filename:
MIME Type:
Creator:
Ben Bucksch (:BenB)
Size:
3.81 KB
patch
obsolete
>diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp >--- a/dom/base/nsGlobalWindow.cpp >+++ b/dom/base/nsGlobalWindow.cpp >@@ -25,16 +25,17 @@ > * Brendan Eich <brendan@mozilla.org> > * David Hyatt (hyatt@netscape.com) > * Dan Rosen <dr@netscape.com> > * Vidur Apparao <vidur@netscape.com> > * Johnny Stenback <jst@netscape.com> > * Mark Hammond <mhammond@skippinet.com.au> > * Ryan Jones <sciguyryan@gmail.com> > * Jeff Walden <jwalden+code@mit.edu> >+ * Ben Bucksch <ben.bucksch beonex.com> > * > * Alternatively, the contents of this file may be used under the terms of > * either of the GNU General Public License Version 2 or later (the "GPL"), > * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), > * in which case the provisions of the GPL or the LGPL are applicable instead > * of those above. If you wish to allow use of your version of this file only > * under the terms of either the GPL or the LGPL, and not to allow others to > * use your version of this file under the terms of the MPL, indicate your >@@ -62,16 +63,18 @@ > #include "nsXPIDLString.h" > #include "nsJSUtils.h" > #include "prmem.h" > #include "jsapi.h" // for JSAutoRequest > #include "jsdbgapi.h" // for JS_ClearWatchPointsForObject > #include "nsReadableUtils.h" > #include "nsDOMClassInfo.h" > #include "nsContentUtils.h" >+#include "nsCharSeparatedTokenizer.h" // for Accept-Language parsing >+#include "nsUnicharUtils.h" > > // Other Classes > #include "nsIEventListenerManager.h" > #include "nsEscape.h" > #include "nsStyleCoord.h" > #include "nsMimeTypeArray.h" > #include "nsNetUtil.h" > #include "nsICachingChannel.h" >@@ -9854,29 +9857,50 @@ nsNavigator::GetAppName(nsAString& aAppN > return NS_OK; > } > } > > aAppName.AssignLiteral("Netscape"); > return NS_OK; > } > >+/** >+ * JS property navigator.language, exposed to web content. >+ * Take first value from Accept-Languages (HTTP header), which is >+ * the "content language" freely set by the user in the Pref window. >+ * >+ * Do not use UI language (chosen app locale) here. >+ * See RFC 2616, Section 15.1.4 "Privacy Issues Connected to Accept Headers" >+ * >+ * "en", "en-US" and "i-cherokee" are valid. >+ * Fallback in case of invalid pref should be "" (empty string), to >+ * let site do fallback, e.g. to site's local language. >+ */ > NS_IMETHODIMP > nsNavigator::GetLanguage(nsAString& aLanguage) > { >- nsresult rv; >- nsCOMPtr<nsIHttpProtocolHandler> >- service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv)); >- if (NS_SUCCEEDED(rv)) { >- nsCAutoString lang; >- rv = service->GetLanguage(lang); >- CopyASCIItoUTF16(lang, aLanguage); >- } >- >- return rv; >+ // e.g. "de-de, en-us,en" >+ const nsAdoptingString& acceptLang = >+ nsContentUtils::GetLocalizedStringPref("intl.accept_languages"); >+ // take everything before the first "," or ";", without trailing space >+ nsCharSeparatedTokenizer langTokenizer(acceptLang, ','); >+ const nsSubstring &firstLangPart = langTokenizer.nextToken(); >+ nsCharSeparatedTokenizer qTokenizer(firstLangPart, ';'); >+ aLanguage.Assign(qTokenizer.nextToken()); >+ NS_ASSERTION(!aLanguage.IsEmpty(), "invalid intl.accept_languages pref"); >+ // replace "_" with "-", to avoid POSIX/Windows "en_US" notation >+ if (aLanguage.Length() > 2 && aLanguage[2] == PRUnichar('_')) >+ aLanguage.Replace(2, 1, PRUnichar('-')); // TODO replace all >+ if (aLanguage.Length() > 2 && aLanguage[2] == PRUnichar('-')) >+ { >+ nsAutoString upper(Substring(aLanguage, 3, aLanguage.Length() - 3)); >+ ::ToUpperCase(upper); >+ aLanguage.Replace(3, aLanguage.Length() - 3, upper); >+ } >+ return NS_OK; > } > > NS_IMETHODIMP > nsNavigator::GetPlatform(nsAString& aPlatform) > { > if (!nsContentUtils::IsCallerTrustedForRead()) { > const nsAdoptingCString& override = > nsContentUtils::GetCharPref("general.platform.override");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Flags:
bzbarsky
: review-
Actions:
View
|
Diff
|
Review
Attachments on
bug 55366
:
43864
|
460173
|
461774
|
462244
|
462638
|
462663