| 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_; |
| 358 | 356 |
| 359 // This object can be accessed from multiple threads, so use a lock around | 357 // This object can be accessed from multiple threads, so use a lock around |
| 360 // accesses to the data members. | 358 // accesses to the data members. |
| 361 mutable base::Lock lock_; | 359 mutable base::Lock lock_; |
| 362 }; | 360 }; |
| 363 | 361 |
| 364 UserAgentState::UserAgentState() | 362 UserAgentState::UserAgentState() |
| 365 : user_agent_requested_(false), | 363 : user_agent_requested_(false), |
| 366 user_agent_is_overridden_(false) { | 364 user_agent_is_overridden_(false) { |
| 367 } | 365 } |
| 368 | 366 |
| 369 UserAgentState::~UserAgentState() { | 367 UserAgentState::~UserAgentState() { |
| 370 } | 368 } |
| 371 | 369 |
| 372 void UserAgentState::Set(const std::string& user_agent) { | 370 void UserAgentState::Set(const std::string& user_agent, bool overriding) { |
| 373 base::AutoLock auto_lock(lock_); | 371 base::AutoLock auto_lock(lock_); |
| 372 if (user_agent == user_agent_) { |
| 373 // We allow the user agent to be set multiple times as long as it |
| 374 // is set to the same value, in order to simplify unit testing |
| 375 // given g_user_agent is a global. |
| 376 return; |
| 377 } |
| 378 DCHECK(!user_agent.empty()); |
| 374 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " | 379 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " |
| 375 "already requested it can result in unexpected behavior."; | 380 "already requested it can result in unexpected behavior."; |
| 376 user_agent_is_overridden_ = true; | 381 user_agent_is_overridden_ = overriding; |
| 377 user_agent_ = user_agent; | 382 user_agent_ = user_agent; |
| 378 } | 383 } |
| 379 | 384 |
| 380 const std::string& UserAgentState::Get(const GURL& url) const { | 385 const std::string& UserAgentState::Get(const GURL& url) const { |
| 381 base::AutoLock auto_lock(lock_); | 386 base::AutoLock auto_lock(lock_); |
| 382 user_agent_requested_ = true; | 387 user_agent_requested_ = true; |
| 383 | 388 |
| 384 if (user_agent_.empty()) | 389 DCHECK(!user_agent_.empty()); |
| 385 user_agent_ = BuildUserAgent(false); | |
| 386 | 390 |
| 387 // Workarounds for sites that use misguided UA sniffing. | 391 // Workarounds for sites that use misguided UA sniffing. |
| 388 if (!user_agent_is_overridden_) { | 392 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) | 393 #if defined(OS_MACOSX) |
| 400 if (url.host() == "www.microsoft.com" && | 394 if (url.host() == "www.microsoft.com" && |
| 401 StartsWithASCII(url.path(), "/getsilverlight", false)) { | 395 StartsWithASCII(url.path(), "/getsilverlight", false)) { |
| 402 // The landing page for updating Silverlight gives a confusing experience | 396 // The landing page for updating Silverlight gives a confusing experience |
| 403 // in browsers that Silverlight doesn't officially support; spoof as | 397 // in browsers that Silverlight doesn't officially support; spoof as |
| 404 // Safari to reduce the chance that users won't complete updates. | 398 // Safari to reduce the chance that users won't complete updates. |
| 405 // Should be removed if the sniffing is removed: http://crbug.com/88211 | 399 // Should be removed if the sniffing is removed: http://crbug.com/88211 |
| 406 if (mimic_mac_safari_user_agent_.empty()) { | 400 if (mimic_mac_safari_user_agent_.empty()) { |
| 407 mimic_mac_safari_user_agent_ = | 401 mimic_mac_safari_user_agent_ = |
| 408 BuildUserAgentHelper(false, "Version/5.0.4 Safari/533.20.27"); | 402 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); |
| 409 } | 403 } |
| 410 return mimic_mac_safari_user_agent_; | 404 return mimic_mac_safari_user_agent_; |
| 411 } | 405 } |
| 412 #endif | 406 #endif |
| 413 } | 407 } |
| 414 | 408 |
| 415 return user_agent_; | 409 return user_agent_; |
| 416 } | 410 } |
| 417 | 411 |
| 418 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); | 412 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); |
| 419 | 413 |
| 420 } // namespace | 414 } // namespace |
| 421 | 415 |
| 422 void SetUserAgent(const std::string& new_user_agent) { | 416 void SetUserAgent(const std::string& user_agent, bool overriding) { |
| 423 g_user_agent.Get().Set(new_user_agent); | 417 g_user_agent.Get().Set(user_agent, overriding); |
| 424 } | 418 } |
| 425 | 419 |
| 426 const std::string& GetUserAgent(const GURL& url) { | 420 const std::string& GetUserAgent(const GURL& url) { |
| 427 return g_user_agent.Get().Get(url); | 421 return g_user_agent.Get().Get(url); |
| 428 } | 422 } |
| 429 | 423 |
| 430 void SetForcefullyTerminatePluginProcess(bool value) { | 424 void SetForcefullyTerminatePluginProcess(bool value) { |
| 431 g_forcefully_terminate_plugin_process = value; | 425 g_forcefully_terminate_plugin_process = value; |
| 432 } | 426 } |
| 433 | 427 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 444 NOTIMPLEMENTED(); | 438 NOTIMPLEMENTED(); |
| 445 return NULL; | 439 return NULL; |
| 446 #endif | 440 #endif |
| 447 } | 441 } |
| 448 | 442 |
| 449 int GetGlyphPageCount() { | 443 int GetGlyphPageCount() { |
| 450 return WebGlyphCache::pageCount(); | 444 return WebGlyphCache::pageCount(); |
| 451 } | 445 } |
| 452 | 446 |
| 453 } // namespace webkit_glue | 447 } // namespace webkit_glue |
| OLD | NEW |