|
1 |
|
2 # HG changeset patch |
|
3 # User Zibi Braniecki <gandalf@mozilla.com> |
|
4 # Date 1492502585 25200 |
|
5 # Node ID 4e489e84adfd63b84c8ee55a8ea4cc05984cfdd8 |
|
6 # Parent b04931b8cbcb2620b4760ccafd66a9b1190acca4 |
|
7 Bug 1005640 - Flush StringBundle cache when app-locales change. r=valentin |
|
8 |
|
9 StringBundle caches bundles, so when language chain changes we should |
|
10 flush the cache to enable new strings to be loaded. |
|
11 This also affects localized prefs like intl.accept_languages. |
|
12 |
|
13 Then in HttpHandler we have to mark the value as dirty so that next |
|
14 time it's called it actually recalculates using flushed string bundle |
|
15 with the new locale. |
|
16 |
|
17 MozReview-Commit-ID: DKWEDUli4yH |
|
18 |
|
19 diff --git a/intl/strres/nsStringBundle.cpp b/intl/strres/nsStringBundle.cpp |
|
20 --- a/intl/strres/nsStringBundle.cpp |
|
21 +++ b/intl/strres/nsStringBundle.cpp |
|
22 @@ -524,16 +524,17 @@ nsresult |
|
23 nsStringBundleService::Init() |
|
24 { |
|
25 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
|
26 if (os) { |
|
27 os->AddObserver(this, "memory-pressure", true); |
|
28 os->AddObserver(this, "profile-do-change", true); |
|
29 os->AddObserver(this, "chrome-flush-caches", true); |
|
30 os->AddObserver(this, "xpcom-category-entry-added", true); |
|
31 + os->AddObserver(this, "intl:app-locales-changed", true); |
|
32 } |
|
33 |
|
34 // instantiate the override service, if there is any. |
|
35 // at some point we probably want to make this a category, and |
|
36 // support multiple overrides |
|
37 mOverrideStrings = do_GetService(NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID); |
|
38 |
|
39 return NS_OK; |
|
40 @@ -541,17 +542,18 @@ nsStringBundleService::Init() |
|
41 |
|
42 NS_IMETHODIMP |
|
43 nsStringBundleService::Observe(nsISupports* aSubject, |
|
44 const char* aTopic, |
|
45 const char16_t* aSomeData) |
|
46 { |
|
47 if (strcmp("memory-pressure", aTopic) == 0 || |
|
48 strcmp("profile-do-change", aTopic) == 0 || |
|
49 - strcmp("chrome-flush-caches", aTopic) == 0) |
|
50 + strcmp("chrome-flush-caches", aTopic) == 0 || |
|
51 + strcmp("intl:app-locales-changed", aTopic) == 0) |
|
52 { |
|
53 flushBundleCache(); |
|
54 } |
|
55 else if (strcmp("xpcom-category-entry-added", aTopic) == 0 && |
|
56 NS_LITERAL_STRING("xpcom-autoregistration").Equals(aSomeData)) |
|
57 { |
|
58 mOverrideStrings = do_GetService(NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID); |
|
59 } |
|
60 diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp |
|
61 --- a/netwerk/protocol/http/nsHttpHandler.cpp |
|
62 +++ b/netwerk/protocol/http/nsHttpHandler.cpp |
|
63 @@ -197,16 +197,17 @@ nsHttpHandler::nsHttpHandler() |
|
64 , mEnforceAssocReq(false) |
|
65 , mLastUniqueID(NowInSeconds()) |
|
66 , mSessionStartTime(0) |
|
67 , mLegacyAppName("Mozilla") |
|
68 , mLegacyAppVersion("5.0") |
|
69 , mProduct("Gecko") |
|
70 , mCompatFirefoxEnabled(false) |
|
71 , mUserAgentIsDirty(true) |
|
72 + , mAcceptLanguagesIsDirty(true) |
|
73 , mPromptTempRedirect(true) |
|
74 , mEnablePersistentHttpsCaching(false) |
|
75 , mDoNotTrackEnabled(false) |
|
76 , mSafeHintEnabled(false) |
|
77 , mParentalControlEnabled(false) |
|
78 , mHandlerActive(false) |
|
79 , mTelemetryEnabled(false) |
|
80 , mAllowExperiments(true) |
|
81 @@ -460,18 +461,23 @@ nsHttpHandler::AddStandardRequestHeaders |
|
82 // service worker expects to see it. The other "default" headers are |
|
83 // hidden from service worker interception. |
|
84 rv = request->SetHeader(nsHttp::Accept, mAccept, |
|
85 false, nsHttpHeaderArray::eVarietyRequestOverride); |
|
86 if (NS_FAILED(rv)) return rv; |
|
87 |
|
88 // Add the "Accept-Language" header. This header is also exposed to the |
|
89 // service worker. |
|
90 + if (mAcceptLanguagesIsDirty) { |
|
91 + rv = SetAcceptLanguages(); |
|
92 + MOZ_ASSERT(NS_SUCCEEDED(rv)); |
|
93 + } |
|
94 + |
|
95 + // Add the "Accept-Language" header |
|
96 if (!mAcceptLanguages.IsEmpty()) { |
|
97 - // Add the "Accept-Language" header |
|
98 rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages, |
|
99 false, |
|
100 nsHttpHeaderArray::eVarietyRequestOverride); |
|
101 if (NS_FAILED(rv)) return rv; |
|
102 } |
|
103 |
|
104 // Add the "Accept-Encoding" header |
|
105 if (isSecure) { |
|
106 @@ -1472,26 +1478,20 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc |
|
107 mMaxHttpResponseHeaderSize = val; |
|
108 } |
|
109 } |
|
110 // |
|
111 // INTL options |
|
112 // |
|
113 |
|
114 if (PREF_CHANGED(INTL_ACCEPT_LANGUAGES)) { |
|
115 - nsCOMPtr<nsIPrefLocalizedString> pls; |
|
116 - prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES, |
|
117 - NS_GET_IID(nsIPrefLocalizedString), |
|
118 - getter_AddRefs(pls)); |
|
119 - if (pls) { |
|
120 - nsXPIDLString uval; |
|
121 - pls->ToString(getter_Copies(uval)); |
|
122 - if (uval) |
|
123 - SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get()); |
|
124 - } |
|
125 + // We don't want to set the new accept languages here since |
|
126 + // this pref is a complex type and it may be racy with flushing |
|
127 + // string resources. |
|
128 + mAcceptLanguagesIsDirty = true; |
|
129 } |
|
130 |
|
131 // |
|
132 // Tracking options |
|
133 // |
|
134 |
|
135 if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) { |
|
136 cVar = false; |
|
137 @@ -1858,22 +1858,28 @@ PrepareAcceptLanguages(const char *i_Acc |
|
138 |
|
139 o_AcceptLanguages.Assign((const char *) q_Accept); |
|
140 delete [] q_Accept; |
|
141 |
|
142 return NS_OK; |
|
143 } |
|
144 |
|
145 nsresult |
|
146 -nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages) |
|
147 +nsHttpHandler::SetAcceptLanguages() |
|
148 { |
|
149 + mAcceptLanguagesIsDirty = false; |
|
150 + |
|
151 + const nsAdoptingCString& acceptLanguages = |
|
152 + Preferences::GetLocalizedCString(INTL_ACCEPT_LANGUAGES); |
|
153 + |
|
154 nsAutoCString buf; |
|
155 - nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf); |
|
156 - if (NS_SUCCEEDED(rv)) |
|
157 + nsresult rv = PrepareAcceptLanguages(acceptLanguages.get(), buf); |
|
158 + if (NS_SUCCEEDED(rv)) { |
|
159 mAcceptLanguages.Assign(buf); |
|
160 + } |
|
161 return rv; |
|
162 } |
|
163 |
|
164 nsresult |
|
165 nsHttpHandler::SetAccept(const char *aAccept) |
|
166 { |
|
167 mAccept = aAccept; |
|
168 return NS_OK; |
|
169 diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h |
|
170 --- a/netwerk/protocol/http/nsHttpHandler.h |
|
171 +++ b/netwerk/protocol/http/nsHttpHandler.h |
|
172 @@ -385,17 +385,17 @@ private: |
|
173 // |
|
174 // Useragent/prefs helper methods |
|
175 // |
|
176 void BuildUserAgent(); |
|
177 void InitUserAgentComponents(); |
|
178 void PrefsChanged(nsIPrefBranch *prefs, const char *pref); |
|
179 |
|
180 nsresult SetAccept(const char *); |
|
181 - nsresult SetAcceptLanguages(const char *); |
|
182 + nsresult SetAcceptLanguages(); |
|
183 nsresult SetAcceptEncodings(const char *, bool mIsSecure); |
|
184 |
|
185 nsresult InitConnectionMgr(); |
|
186 |
|
187 void NotifyObservers(nsIHttpChannel *chan, const char *event); |
|
188 |
|
189 static void TimerCallback(nsITimer * aTimer, void * aClosure); |
|
190 private: |
|
191 @@ -488,16 +488,17 @@ private: |
|
192 nsCString mCompatFirefox; |
|
193 bool mCompatFirefoxEnabled; |
|
194 nsXPIDLCString mCompatDevice; |
|
195 nsCString mDeviceModelId; |
|
196 |
|
197 nsCString mUserAgent; |
|
198 nsXPIDLCString mUserAgentOverride; |
|
199 bool mUserAgentIsDirty; // true if mUserAgent should be rebuilt |
|
200 + bool mAcceptLanguagesIsDirty; |
|
201 |
|
202 |
|
203 bool mPromptTempRedirect; |
|
204 |
|
205 // Persistent HTTPS caching flag |
|
206 bool mEnablePersistentHttpsCaching; |
|
207 |
|
208 // For broadcasting tracking preference |