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

Side by Side Diff: components/cronet/ios/Cronet.mm

Issue 2665703002: [cronet] Make getAcceptLanguages index a static table instead of the application bundle. (Closed)
Patch Set: address rob's comments Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "components/cronet/ios/Cronet.h" 5 #import "components/cronet/ios/Cronet.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 25 matching lines...) Expand all
36 cronet::URLRequestContextConfig::HttpCacheType gHttpCache = 36 cronet::URLRequestContextConfig::HttpCacheType gHttpCache =
37 cronet::URLRequestContextConfig::HttpCacheType::DISK; 37 cronet::URLRequestContextConfig::HttpCacheType::DISK;
38 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; 38 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints;
39 NSString* gUserAgent = nil; 39 NSString* gUserAgent = nil;
40 BOOL gUserAgentPartial = NO; 40 BOOL gUserAgentPartial = NO;
41 NSString* gSslKeyLogFileName = nil; 41 NSString* gSslKeyLogFileName = nil;
42 RequestFilterBlock gRequestFilterBlock = nil; 42 RequestFilterBlock gRequestFilterBlock = nil;
43 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; 43 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
44 NSURLCache* gPreservedSharedURLCache = nil; 44 NSURLCache* gPreservedSharedURLCache = nil;
45 BOOL gEnableTestCertVerifierForTesting = FALSE; 45 BOOL gEnableTestCertVerifierForTesting = FALSE;
46 NSString* gAcceptLanguages = nil;
46 47
47 // CertVerifier, which allows any certificates for testing. 48 // CertVerifier, which allows any certificates for testing.
48 class TestCertVerifier : public net::CertVerifier { 49 class TestCertVerifier : public net::CertVerifier {
49 int Verify(const RequestParams& params, 50 int Verify(const RequestParams& params,
50 net::CRLSet* crl_set, 51 net::CRLSet* crl_set,
51 net::CertVerifyResult* verify_result, 52 net::CertVerifyResult* verify_result,
52 const net::CompletionCallback& callback, 53 const net::CompletionCallback& callback,
53 std::unique_ptr<Request>* out_req, 54 std::unique_ptr<Request>* out_req,
54 const net::NetLogWithSource& net_log) override { 55 const net::NetLogWithSource& net_log) override {
55 net::Error result = net::OK; 56 net::Error result = net::OK;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 + (void)configureCronetEnvironmentForTesting: 109 + (void)configureCronetEnvironmentForTesting:
109 (cronet::CronetEnvironment*)cronetEnvironment { 110 (cronet::CronetEnvironment*)cronetEnvironment {
110 if (gEnableTestCertVerifierForTesting) { 111 if (gEnableTestCertVerifierForTesting) {
111 std::unique_ptr<TestCertVerifier> test_cert_verifier = 112 std::unique_ptr<TestCertVerifier> test_cert_verifier =
112 base::MakeUnique<TestCertVerifier>(); 113 base::MakeUnique<TestCertVerifier>();
113 cronetEnvironment->set_mock_cert_verifier(std::move(test_cert_verifier)); 114 cronetEnvironment->set_mock_cert_verifier(std::move(test_cert_verifier));
114 } 115 }
115 } 116 }
116 117
118 + (NSString*)getAcceptLanguagesFromNSLocale:(NSLocale*)locale {
119 // TODO(lilyhoughton) this is maybe not the best place for this
120 NSDictionary* acceptLangs = @{
121 @"am" : @"am,en-GB,en",
122 @"ar" : @"ar,en-US,en",
123 @"bg" : @"bg-BG,bg",
124 @"bn" : @"bn-IN,bn,en-US,en",
125 @"ca" : @"ca-ES,ca",
126 @"cs" : @"cs-CZ,cs",
127 @"da" : @"da-DK,da,en-US,en",
128 @"de" : @"de-DE,de,en-US,en",
129 @"el" : @"el-GR,el",
130 @"en-GB" : @"en-GB,en-US,en",
131 @"en" : @"en-US,en",
132 @"es-419 " : @"es-419,es",
133 @"es" : @"es-ES,es",
134 @"fa" : @"fa,en-US,en",
135 @"fi" : @"fi-FI,fi,en-US,en",
136 @"fil" : @"fil,fil-PH,tl,en-US,en",
137 @"fr" : @"fr-FR,fr,en-US,en",
138 @"gu" : @"gu-IN,gu,hi-IN,hi,en-US,en",
139 @"he" : @"he-IL,he,en-US,en",
140 @"hi" : @"hi-IN,hi,en-US,en",
141 @"hr" : @"hr-HR,hr,en-US,en",
142 @"hu" : @"hu-HU,hu,en-US,en",
143 @"id" : @"id-ID,id,en-US,en",
144 @"it" : @"it-IT,it,en-US,en",
145 @"ja" : @"ja,en-US,en",
146 @"kn" : @"kn-IN,kn,en-US,en",
147 @"ko" : @"ko-KR,ko,en-US,en",
148 @"lt" : @"lt,en-US,en,ru,pl",
149 @"lv" : @"lv-LV,lv,en-US,en",
150 @"ml" : @"ml-IN,ml,en-US,en",
151 @"mr" : @"mr-IN,mr,hi-IN,hi,en-US,en",
152 @"ms" : @"ms,en-US,en",
153 @"nb" : @"nb-NO,nb,no,nn,en-US,en",
154 @"nl" : @"nl-NL,nl,en-US,en",
155 @"pl" : @"pl-PL,pl,en-US,en",
156 @"pt-BR" : @"pt-BR,pt,en-US,en",
157 @"pt-PT" : @"pt-PT,pt,en-US,en",
158 @"pt" : @"pt-PT,pt,en-US,en",
159 @"ro" : @"ro-RO,ro,en-US,en",
160 @"ru" : @"ru-RU,ru,en-US,en",
161 @"sk" : @"sk-SK,sk,cs,en-US,en",
162 @"sl" : @"sl-SI,sl,en-GB,en",
163 @"sr" : @"sr-RS,sr,en-US,en",
164 @"sv" : @"sv-SE,sv,en-US,en",
165 @"sw" : @"sw,en-GB,en",
166 @"ta" : @"ta-IN,ta,en-US,en",
167 @"te" : @"te-IN,te,hi-IN,hi,en-US,en",
168 @"th" : @"th-TH,th",
169 @"tr" : @"tr-TR,tr,en-US,en",
170 @"uk" : @"uk-UA,uk,ru,en-US,en",
171 @"vi" : @"vi-VN,vi,fr-FR,fr,en-US,en",
172 @"zh-Hans" : @"zh-CN,zh",
173 @"zh-Hant" : @"zh-TW,zh,en-US,en",
174 @"zh" : @"zh-CN,zh",
175 };
176
177 // TODO(lilyhoughton) reasonably sure this is wrong
178 NSString* region = [NSString
179 stringWithFormat:@"%@-%@", [locale languageCode], [locale countryCode]];
180 NSString* lang = [locale languageCode];
181 NSString* acceptLanguages =
182 acceptLangs[region] ?: acceptLangs[lang] ?: @"en-US,en";
183 return acceptLanguages;
184 }
185
117 + (NSString*)getAcceptLanguages { 186 + (NSString*)getAcceptLanguages {
118 // Use the framework bundle to search for resources. 187 return [self getAcceptLanguagesFromNSLocale:[NSLocale currentLocale]];
119 NSBundle* frameworkBundle = [NSBundle bundleForClass:self]; 188 }
120 NSString* bundlePath = 189
121 [frameworkBundle pathForResource:@"cronet_resources" ofType:@"bundle"]; 190 + (void)setAcceptLanguages:(NSString*)acceptLanguages {
robgaunt 2017/02/03 18:42:44 [self checkNotStarted];
122 NSBundle* bundle = [NSBundle bundleWithPath:bundlePath]; 191 gAcceptLanguages = acceptLanguages;
123 NSString* acceptLanguages = NSLocalizedStringWithDefaultValue(
124 @"IDS_ACCEPT_LANGUAGES", @"Localizable", bundle, @"en-US,en",
125 @"These values are copied from Chrome's .xtb files, so the same "
126 "values are used in the |Accept-Language| header. Key name matches "
127 "Chrome's.");
128 if (acceptLanguages == Nil)
129 acceptLanguages = @"";
130 return acceptLanguages;
131 } 192 }
132 193
133 + (void)checkNotStarted { 194 + (void)checkNotStarted {
134 CHECK(gChromeNet == NULL) << "Cronet is already started."; 195 CHECK(gChromeNet == NULL) << "Cronet is already started.";
135 } 196 }
136 197
137 + (void)setHttp2Enabled:(BOOL)http2Enabled { 198 + (void)setHttp2Enabled:(BOOL)http2Enabled {
138 [self checkNotStarted]; 199 [self checkNotStarted];
139 gHttp2Enabled = http2Enabled; 200 gHttp2Enabled = http2Enabled;
140 } 201 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block); 244 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block);
184 else 245 else
185 gRequestFilterBlock = block; 246 gRequestFilterBlock = block;
186 } 247 }
187 248
188 + (void)startInternal { 249 + (void)startInternal {
189 cronet::CronetEnvironment::Initialize(); 250 cronet::CronetEnvironment::Initialize();
190 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); 251 std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
191 gChromeNet.Get().reset( 252 gChromeNet.Get().reset(
192 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); 253 new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
193 gChromeNet.Get()->set_accept_language( 254 gChromeNet.Get()->set_accept_language(base::SysNSStringToUTF8(
194 base::SysNSStringToUTF8([self getAcceptLanguages])); 255 gAcceptLanguages ? gAcceptLanguages : [self getAcceptLanguages]));
robgaunt 2017/02/03 18:42:44 gAcceptLanguages ?: [self getAcceptLanguages]
195 256
196 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); 257 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
197 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); 258 gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
198 gChromeNet.Get()->set_http_cache(gHttpCache); 259 gChromeNet.Get()->set_http_cache(gHttpCache);
199 gChromeNet.Get()->set_ssl_key_log_file_name( 260 gChromeNet.Get()->set_ssl_key_log_file_name(
200 base::SysNSStringToUTF8(gSslKeyLogFileName)); 261 base::SysNSStringToUTF8(gSslKeyLogFileName));
201 for (const auto* quicHint : gQuicHints) { 262 for (const auto* quicHint : gQuicHints) {
202 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, 263 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port,
203 quicHint->alternate_port); 264 quicHint->alternate_port);
204 } 265 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 base::SysNSStringToUTF8(hostResolverRulesForTesting)); 371 base::SysNSStringToUTF8(hostResolverRulesForTesting));
311 } 372 }
312 373
313 // This is a non-public dummy method that prevents the linker from stripping out 374 // This is a non-public dummy method that prevents the linker from stripping out
314 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. 375 // the otherwise non-referenced methods from 'bidirectional_stream.cc'.
315 + (void)preventStrippingCronetBidirectionalStream { 376 + (void)preventStrippingCronetBidirectionalStream {
316 bidirectional_stream_create(NULL, 0, 0); 377 bidirectional_stream_create(NULL, 0, 0);
317 } 378 }
318 379
319 @end 380 @end
OLDNEW
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698