Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <objidl.h> | 8 #include <objidl.h> |
| 9 #include <mlang.h> | 9 #include <mlang.h> |
| 10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 namespace { | 339 namespace { |
| 340 | 340 |
| 341 class UserAgentState { | 341 class UserAgentState { |
| 342 public: | 342 public: |
| 343 UserAgentState(); | 343 UserAgentState(); |
| 344 ~UserAgentState(); | 344 ~UserAgentState(); |
| 345 | 345 |
| 346 void Set(const std::string& user_agent); | 346 void Set(const std::string& user_agent, bool overriding); |
| 347 const std::string& Get(const GURL& url) const; | 347 const std::string& Get(const GURL& url) const; |
| 348 | 348 |
| 349 private: | 349 private: |
| 350 mutable std::string user_agent_; | 350 mutable std::string user_agent_; |
| 351 // The UA string when we're pretending to be Windows Chrome. | |
| 352 mutable std::string mimic_windows_user_agent_; | |
| 353 // The UA string when we're pretending to be Mac Safari. | 351 // The UA string when we're pretending to be Mac Safari. |
| 354 mutable std::string mimic_mac_safari_user_agent_; | 352 mutable std::string mimic_mac_safari_user_agent_; |
| 355 | 353 |
| 356 mutable bool user_agent_requested_; | 354 mutable bool user_agent_requested_; |
| 357 bool user_agent_is_overridden_; | 355 bool user_agent_is_overridden_; |
| 356 bool user_agent_is_set_; | |
|
Evan Martin
2011/09/21 20:27:24
Is it possible to remove this and instead use user
Dirk Pranke
2011/09/21 21:02:35
Yes, I think this is possible; it wasn't at some p
| |
| 358 | 357 |
| 359 // This object can be accessed from multiple threads, so use a lock around | 358 // This object can be accessed from multiple threads, so use a lock around |
| 360 // accesses to the data members. | 359 // accesses to the data members. |
| 361 mutable base::Lock lock_; | 360 mutable base::Lock lock_; |
| 362 }; | 361 }; |
| 363 | 362 |
| 364 UserAgentState::UserAgentState() | 363 UserAgentState::UserAgentState() |
| 365 : user_agent_requested_(false), | 364 : user_agent_requested_(false), |
| 366 user_agent_is_overridden_(false) { | 365 user_agent_is_overridden_(false), |
| 366 user_agent_is_set_(false) { | |
| 367 } | 367 } |
| 368 | 368 |
| 369 UserAgentState::~UserAgentState() { | 369 UserAgentState::~UserAgentState() { |
| 370 } | 370 } |
| 371 | 371 |
| 372 void UserAgentState::Set(const std::string& user_agent) { | 372 void UserAgentState::Set(const std::string& user_agent, bool overriding) { |
| 373 base::AutoLock auto_lock(lock_); | 373 base::AutoLock auto_lock(lock_); |
| 374 if (user_agent == user_agent_) { | |
| 375 // We allow the user agent to be set multiple times as long as it | |
| 376 // is set to the same value, in order to simplify unit testing | |
| 377 // given g_user_agent is a global. | |
| 378 return; | |
| 379 } | |
| 374 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " | 380 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " |
| 375 "already requested it can result in unexpected behavior."; | 381 "already requested it can result in unexpected behavior."; |
| 376 user_agent_is_overridden_ = true; | 382 user_agent_is_set_ = true; |
| 383 user_agent_is_overridden_ = overriding; | |
| 377 user_agent_ = user_agent; | 384 user_agent_ = user_agent; |
| 378 } | 385 } |
| 379 | 386 |
| 380 const std::string& UserAgentState::Get(const GURL& url) const { | 387 const std::string& UserAgentState::Get(const GURL& url) const { |
| 381 base::AutoLock auto_lock(lock_); | 388 base::AutoLock auto_lock(lock_); |
| 382 user_agent_requested_ = true; | 389 user_agent_requested_ = true; |
| 383 | 390 |
| 384 if (user_agent_.empty()) | 391 DCHECK(user_agent_is_set_); |
| 385 user_agent_ = BuildUserAgent(false); | |
| 386 | 392 |
| 387 // Workarounds for sites that use misguided UA sniffing. | 393 // Workarounds for sites that use misguided UA sniffing. |
| 388 if (!user_agent_is_overridden_) { | 394 if (!user_agent_is_overridden_) { |
| 389 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 390 if (MatchPattern(url.host(), "*.mail.yahoo.com")) { | |
| 391 // mail.yahoo.com is ok with Windows Chrome but not Linux Chrome. | |
| 392 // http://bugs.chromium.org/11136 | |
| 393 // TODO(evanm): remove this if Yahoo fixes their sniffing. | |
| 394 if (mimic_windows_user_agent_.empty()) | |
| 395 mimic_windows_user_agent_ = BuildUserAgent(true); | |
| 396 return mimic_windows_user_agent_; | |
| 397 } | |
| 398 #endif | |
| 399 #if defined(OS_MACOSX) | 395 #if defined(OS_MACOSX) |
| 400 if (url.host() == "www.microsoft.com" && | 396 if (url.host() == "www.microsoft.com" && |
| 401 StartsWithASCII(url.path(), "/getsilverlight", false)) { | 397 StartsWithASCII(url.path(), "/getsilverlight", false)) { |
| 402 // The landing page for updating Silverlight gives a confusing experience | 398 // The landing page for updating Silverlight gives a confusing experience |
| 403 // in browsers that Silverlight doesn't officially support; spoof as | 399 // in browsers that Silverlight doesn't officially support; spoof as |
| 404 // Safari to reduce the chance that users won't complete updates. | 400 // Safari to reduce the chance that users won't complete updates. |
| 405 // Should be removed if the sniffing is removed: http://crbug.com/88211 | 401 // Should be removed if the sniffing is removed: http://crbug.com/88211 |
|
jam
2011/09/21 21:27:36
this whole overriding thing seems like a lot of co
Dirk Pranke
2011/09/21 22:19:59
It's a good question; I'm not sure what the impact
jam
2011/09/21 22:26:29
given that it adds some complexity to ContentClien
| |
| 406 if (mimic_mac_safari_user_agent_.empty()) { | 402 if (mimic_mac_safari_user_agent_.empty()) { |
| 407 mimic_mac_safari_user_agent_ = | 403 mimic_mac_safari_user_agent_ = |
| 408 BuildUserAgentHelper(false, "Version/5.0.4 Safari/533.20.27"); | 404 BuildUserAgentHelper("Version/5.0.4 Safari/533.20.27"); |
| 409 } | 405 } |
| 410 return mimic_mac_safari_user_agent_; | 406 return mimic_mac_safari_user_agent_; |
| 411 } | 407 } |
| 412 #endif | 408 #endif |
| 413 } | 409 } |
| 414 | 410 |
| 415 return user_agent_; | 411 return user_agent_; |
| 416 } | 412 } |
| 417 | 413 |
| 418 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); | 414 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); |
| 419 | 415 |
| 420 } // namespace | 416 } // namespace |
| 421 | 417 |
| 422 void SetUserAgent(const std::string& new_user_agent) { | 418 void SetUserAgent(const std::string& user_agent, bool overriding) { |
| 423 g_user_agent.Get().Set(new_user_agent); | 419 g_user_agent.Get().Set(user_agent, overriding); |
| 424 } | 420 } |
| 425 | 421 |
| 426 const std::string& GetUserAgent(const GURL& url) { | 422 const std::string& GetUserAgent(const GURL& url) { |
| 427 return g_user_agent.Get().Get(url); | 423 return g_user_agent.Get().Get(url); |
| 428 } | 424 } |
| 429 | 425 |
| 430 void SetForcefullyTerminatePluginProcess(bool value) { | 426 void SetForcefullyTerminatePluginProcess(bool value) { |
| 431 g_forcefully_terminate_plugin_process = value; | 427 g_forcefully_terminate_plugin_process = value; |
| 432 } | 428 } |
| 433 | 429 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 444 NOTIMPLEMENTED(); | 440 NOTIMPLEMENTED(); |
| 445 return NULL; | 441 return NULL; |
| 446 #endif | 442 #endif |
| 447 } | 443 } |
| 448 | 444 |
| 449 int GetGlyphPageCount() { | 445 int GetGlyphPageCount() { |
| 450 return WebGlyphCache::pageCount(); | 446 return WebGlyphCache::pageCount(); |
| 451 } | 447 } |
| 452 | 448 |
| 453 } // namespace webkit_glue | 449 } // namespace webkit_glue |
| OLD | NEW |