summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/http/nsHttpHandler.cpp
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-08-26 07:45:17 +0200
committerGitHub <noreply@github.com>2018-08-26 07:45:17 +0200
commit2dc1703c09b080b12e81895cafc1113e860cfe9a (patch)
tree98a0e285554ed33dafd3834261017c6b23fe3a17 /netwerk/protocol/http/nsHttpHandler.cpp
parent4cbcba7876e1d85e9fadeb20a1ce34c58ffd7b93 (diff)
parent02211f8448876cd7c72784380b9e9229959392bb (diff)
downloadUXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.gz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.lz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.tar.xz
UXP-2dc1703c09b080b12e81895cafc1113e860cfe9a.zip
Merge pull request #733 from JustOff/PR_locale_changed_refresh
Refresh nsStringBundleService and nsHttpHandler when the browser locale is changed
Diffstat (limited to 'netwerk/protocol/http/nsHttpHandler.cpp')
-rw-r--r--netwerk/protocol/http/nsHttpHandler.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp
index f9bcc391d..89f09190d 100644
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -203,6 +203,7 @@ nsHttpHandler::nsHttpHandler()
, mCompatFirefoxEnabled(false)
, mCompatFirefoxVersion("52.9")
, mUserAgentIsDirty(true)
+ , mAcceptLanguagesIsDirty(true)
, mPromptTempRedirect(true)
, mEnablePersistentHttpsCaching(false)
, mDoNotTrackEnabled(false)
@@ -419,6 +420,7 @@ nsHttpHandler::Init()
obsService->AddObserver(this, "browser:purge-session-history", true);
obsService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
obsService->AddObserver(this, "application-background", true);
+ obsService->AddObserver(this, "string-bundles-have-flushed", true);
}
MakeNewRequestTokenBucket();
@@ -489,8 +491,13 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpRequestHead *request, bool isSecu
// Add the "Accept-Language" header. This header is also exposed to the
// service worker.
+ if (mAcceptLanguagesIsDirty) {
+ rv = SetAcceptLanguages();
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
+ }
+
+ // Add the "Accept-Language" header
if (!mAcceptLanguages.IsEmpty()) {
- // Add the "Accept-Language" header
rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages,
false,
nsHttpHeaderArray::eVarietyRequestOverride);
@@ -1511,16 +1518,10 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
//
if (PREF_CHANGED(INTL_ACCEPT_LANGUAGES)) {
- nsCOMPtr<nsIPrefLocalizedString> pls;
- prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES,
- NS_GET_IID(nsIPrefLocalizedString),
- getter_AddRefs(pls));
- if (pls) {
- nsXPIDLString uval;
- pls->ToString(getter_Copies(uval));
- if (uval)
- SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get());
- }
+ // We don't want to set the new accept languages here since
+ // this pref is a complex type and it may be racy with flushing
+ // string resources.
+ mAcceptLanguagesIsDirty = true;
}
//
@@ -1897,12 +1898,18 @@ PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLangua
}
nsresult
-nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
+nsHttpHandler::SetAcceptLanguages()
{
+ mAcceptLanguagesIsDirty = false;
+
+ const nsAdoptingCString& acceptLanguages =
+ Preferences::GetLocalizedCString(INTL_ACCEPT_LANGUAGES);
+
nsAutoCString buf;
- nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf);
- if (NS_SUCCEEDED(rv))
+ nsresult rv = PrepareAcceptLanguages(acceptLanguages.get(), buf);
+ if (NS_SUCCEEDED(rv)) {
mAcceptLanguages.Assign(buf);
+ }
return rv;
}
@@ -2233,6 +2240,8 @@ nsHttpHandler::Observe(nsISupports *subject,
if (mConnMgr) {
mConnMgr->DoShiftReloadConnectionCleanup(nullptr);
}
+ } else if (!strcmp(topic, "string-bundles-have-flushed")) {
+ mAcceptLanguagesIsDirty = true;
}
return NS_OK;