OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "google_apis/google_api_keys.h" | 5 #include "google_apis/google_api_keys.h" |
6 | 6 |
7 // If you add more includes to this list, you also need to add them to | 7 // If you add more includes to this list, you also need to add them to |
8 // google_api_keys_unittest.cc. | 8 // google_api_keys_unittest.cc. |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return SPDY_PROXY_AUTH_VALUE; | 239 return SPDY_PROXY_AUTH_VALUE; |
240 #else | 240 #else |
241 return std::string(); | 241 return std::string(); |
242 #endif | 242 #endif |
243 } | 243 } |
244 | 244 |
245 private: | 245 private: |
246 // Gets a value for a key. In priority order, this will be the value | 246 // Gets a value for a key. In priority order, this will be the value |
247 // provided via a command-line switch, the value provided via an | 247 // provided via a command-line switch, the value provided via an |
248 // environment variable, or finally a value baked into the build. | 248 // environment variable, or finally a value baked into the build. |
249 // |command_line_switch| may be NULL. | 249 // |command_line_switch| may be NULL. Official Google Chrome builds will not |
| 250 // use the value provided by an environment variable. |
250 static std::string CalculateKeyValue(const char* baked_in_value, | 251 static std::string CalculateKeyValue(const char* baked_in_value, |
251 const char* environment_variable_name, | 252 const char* environment_variable_name, |
252 const char* command_line_switch, | 253 const char* command_line_switch, |
253 const std::string& default_if_unset, | 254 const std::string& default_if_unset, |
254 base::Environment* environment, | 255 base::Environment* environment, |
255 base::CommandLine* command_line) { | 256 base::CommandLine* command_line) { |
256 std::string key_value = baked_in_value; | 257 std::string key_value = baked_in_value; |
257 std::string temp; | 258 std::string temp; |
258 #if defined(OS_MACOSX) | 259 #if defined(OS_MACOSX) |
259 // macOS and iOS can also override the API key with a value from the | 260 // macOS and iOS can also override the API key with a value from the |
260 // Info.plist. | 261 // Info.plist. |
261 temp = ::google_apis::GetAPIKeyFromInfoPlist(environment_variable_name); | 262 temp = ::google_apis::GetAPIKeyFromInfoPlist(environment_variable_name); |
262 if (!temp.empty()) { | 263 if (!temp.empty()) { |
263 key_value = temp; | 264 key_value = temp; |
264 VLOG(1) << "Overriding API key " << environment_variable_name | 265 VLOG(1) << "Overriding API key " << environment_variable_name |
265 << " with value " << key_value << " from Info.plist."; | 266 << " with value " << key_value << " from Info.plist."; |
266 } | 267 } |
267 #endif | 268 #endif |
| 269 |
| 270 #if !defined(GOOGLE_CHROME_BUILD) |
| 271 // Don't allow using the environment to override API keys for official |
| 272 // Google Chrome builds. There have been reports of mangled environments |
| 273 // affecting users (crbug.com/710575). |
268 if (environment->GetVar(environment_variable_name, &temp)) { | 274 if (environment->GetVar(environment_variable_name, &temp)) { |
269 key_value = temp; | 275 key_value = temp; |
270 VLOG(1) << "Overriding API key " << environment_variable_name | 276 VLOG(1) << "Overriding API key " << environment_variable_name |
271 << " with value " << key_value << " from environment variable."; | 277 << " with value " << key_value << " from environment variable."; |
272 } | 278 } |
| 279 #endif |
273 | 280 |
274 if (command_line_switch && command_line->HasSwitch(command_line_switch)) { | 281 if (command_line_switch && command_line->HasSwitch(command_line_switch)) { |
275 key_value = command_line->GetSwitchValueASCII(command_line_switch); | 282 key_value = command_line->GetSwitchValueASCII(command_line_switch); |
276 VLOG(1) << "Overriding API key " << environment_variable_name | 283 VLOG(1) << "Overriding API key " << environment_variable_name |
277 << " with value " << key_value << " from command-line switch."; | 284 << " with value " << key_value << " from command-line switch."; |
278 } | 285 } |
279 | 286 |
280 if (key_value == DUMMY_API_TOKEN) { | 287 if (key_value == DUMMY_API_TOKEN) { |
281 #if defined(GOOGLE_CHROME_BUILD) | 288 #if defined(GOOGLE_CHROME_BUILD) |
282 // No key should be unset in an official build except the | 289 // No key should be unset in an official build except the |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 372 |
366 bool IsGoogleChromeAPIKeyUsed() { | 373 bool IsGoogleChromeAPIKeyUsed() { |
367 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 374 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
368 return true; | 375 return true; |
369 #else | 376 #else |
370 return false; | 377 return false; |
371 #endif | 378 #endif |
372 } | 379 } |
373 | 380 |
374 } // namespace google_apis | 381 } // namespace google_apis |
OLD | NEW |