Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Unified Diff: components/cronet/ios/Cronet.mm

Issue 2665703002: [cronet] Make getAcceptLanguages index a static table instead of the application bundle. (Closed)
Patch Set: add NSLocale-receiving method Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/Cronet.mm
diff --git a/components/cronet/ios/Cronet.mm b/components/cronet/ios/Cronet.mm
index efbe206e01f44c3c951b00c5c713d51525fa6e23..31b85be0b34351a3e016fb565b88b5eec29e56ec 100644
--- a/components/cronet/ios/Cronet.mm
+++ b/components/cronet/ios/Cronet.mm
@@ -43,6 +43,7 @@ RequestFilterBlock gRequestFilterBlock = nil;
std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
NSURLCache* gPreservedSharedURLCache = nil;
BOOL gEnableTestCertVerifierForTesting = FALSE;
+NSString* gAcceptLanguages = nil;
// CertVerifier, which allows any certificates for testing.
class TestCertVerifier : public net::CertVerifier {
@@ -114,22 +115,84 @@ class CronetHttpProtocolHandlerDelegate
}
}
-+ (NSString*)getAcceptLanguages {
- // Use the framework bundle to search for resources.
- NSBundle* frameworkBundle = [NSBundle bundleForClass:self];
- NSString* bundlePath =
- [frameworkBundle pathForResource:@"cronet_resources" ofType:@"bundle"];
- NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
- NSString* acceptLanguages = NSLocalizedStringWithDefaultValue(
- @"IDS_ACCEPT_LANGUAGES", @"Localizable", bundle, @"en-US,en",
- @"These values are copied from Chrome's .xtb files, so the same "
- "values are used in the |Accept-Language| header. Key name matches "
- "Chrome's.");
- if (acceptLanguages == Nil)
- acceptLanguages = @"";
++ (NSString*)getAcceptLanguagesFromNSLocale:(NSLocale*)locale {
lilyhoughton 2017/02/01 20:58:29 Started writing tests for this, but I don't know h
robgaunt 2017/02/02 18:44:33 One trick is to use a category to make it visible
lilyhoughton 2017/02/03 18:36:24 Done.
+ // TODO(lilyhoughton) this is maybe not the best place for this
+ NSDictionary* acceptLangs = @{
+ @"am" : @"am,en-GB,en",
+ @"ar" : @"ar,en-US,en",
+ @"bg" : @"bg-BG,bg",
+ @"bn" : @"bn-IN,bn,en-US,en",
+ @"ca" : @"ca-ES,ca",
+ @"cs" : @"cs-CZ,cs",
+ @"da" : @"da-DK,da,en-US,en",
+ @"de" : @"de-DE,de,en-US,en",
+ @"el" : @"el-GR,el",
+ @"en-GB" : @"en-GB,en-US,en",
+ @"en" : @"en-US,en",
+ @"es-419 " : @"es-419,es",
+ @"es" : @"es-ES,es",
+ @"fa" : @"fa,en-US,en",
+ @"fi" : @"fi-FI,fi,en-US,en",
+ @"fil" : @"fil,fil-PH,tl,en-US,en",
+ @"fr" : @"fr-FR,fr,en-US,en",
+ @"gu" : @"gu-IN,gu,hi-IN,hi,en-US,en",
+ @"he" : @"he-IL,he,en-US,en",
+ @"hi" : @"hi-IN,hi,en-US,en",
+ @"hr" : @"hr-HR,hr,en-US,en",
+ @"hu" : @"hu-HU,hu,en-US,en",
+ @"id" : @"id-ID,id,en-US,en",
+ @"it" : @"it-IT,it,en-US,en",
+ @"ja" : @"ja,en-US,en",
+ @"kn" : @"kn-IN,kn,en-US,en",
+ @"ko" : @"ko-KR,ko,en-US,en",
+ @"lt" : @"lt,en-US,en,ru,pl",
+ @"lv" : @"lv-LV,lv,en-US,en",
+ @"ml" : @"ml-IN,ml,en-US,en",
+ @"mr" : @"mr-IN,mr,hi-IN,hi,en-US,en",
+ @"ms" : @"ms,en-US,en",
+ @"nb" : @"nb-NO,nb,no,nn,en-US,en",
+ @"nl" : @"nl-NL,nl,en-US,en",
+ @"pl" : @"pl-PL,pl,en-US,en",
+ @"pt-BR" : @"pt-BR,pt,en-US,en",
+ @"pt-PT" : @"pt-PT,pt,en-US,en",
+ @"pt" : @"pt-PT,pt,en-US,en",
+ @"ro" : @"ro-RO,ro,en-US,en",
+ @"ru" : @"ru-RU,ru,en-US,en",
+ @"sk" : @"sk-SK,sk,cs,en-US,en",
+ @"sl" : @"sl-SI,sl,en-GB,en",
+ @"sr" : @"sr-RS,sr,en-US,en",
+ @"sv" : @"sv-SE,sv,en-US,en",
+ @"sw" : @"sw,en-GB,en",
+ @"ta" : @"ta-IN,ta,en-US,en",
+ @"te" : @"te-IN,te,hi-IN,hi,en-US,en",
+ @"th" : @"th-TH,th",
+ @"tr" : @"tr-TR,tr,en-US,en",
+ @"uk" : @"uk-UA,uk,ru,en-US,en",
+ @"vi" : @"vi-VN,vi,fr-FR,fr,en-US,en",
+ @"zh-Hans" : @"zh-CN,zh",
+ @"zh-Hant" : @"zh-TW,zh,en-US,en",
+ @"zh" : @"zh-CN,zh",
+ };
+
+ // TODO(lilyhoughton) reasonably sure this is wrong
robgaunt 2017/02/02 18:44:33 I am not an expert on localization, so I'm not sur
+ NSString* region = [NSString
+ stringWithFormat:@"%@-%@", [[NSLocale currentLocale] languageCode],
robgaunt 2017/02/02 18:44:33 s/[NSLocale currentLocale]/locale
lilyhoughton 2017/02/03 18:36:24 Done.
+ [locale countryCode]];
+ NSString* lang = [locale languageCode];
+ NSString* acceptLanguages =
+ acceptLangs[region] ? acceptLangs[region]
+ : acceptLangs[lang] ? acceptLangs[lang] : @"en-US,en";
robgaunt 2017/02/02 18:44:33 Tip: you can use the ?: operator. acceptLangs[reg
lilyhoughton 2017/02/03 18:36:24 Done.
return acceptLanguages;
}
++ (NSString*)getAcceptLanguages {
+ return [self getAcceptLanguagesFromNSLocale:[NSLocale currentLocale]];
+}
+
++ (void)setAcceptLanguages:(NSString*)acceptLanguages {
robgaunt 2017/02/02 18:44:33 This new method isn't called from anywhere or expo
lilyhoughton 2017/02/03 18:36:24 Done.
+ gAcceptLanguages = acceptLanguages;
+}
+
+ (void)checkNotStarted {
CHECK(gChromeNet == NULL) << "Cronet is already started.";
}
@@ -190,8 +253,8 @@ class CronetHttpProtocolHandlerDelegate
std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
gChromeNet.Get().reset(
new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
- gChromeNet.Get()->set_accept_language(
- base::SysNSStringToUTF8([self getAcceptLanguages]));
+ gChromeNet.Get()->set_accept_language(base::SysNSStringToUTF8(
+ gAcceptLanguages ? gAcceptLanguages : [self getAcceptLanguages]));
gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
« no previous file with comments | « no previous file | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698