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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 class UserAgentState { | 343 class UserAgentState { |
| 344 public: | 344 public: |
| 345 UserAgentState(); | 345 UserAgentState(); |
| 346 ~UserAgentState(); | 346 ~UserAgentState(); |
| 347 | 347 |
| 348 void Set(const std::string& user_agent, bool overriding); | 348 void Set(const std::string& user_agent, bool overriding); |
| 349 const std::string& Get(const GURL& url) const; | 349 const std::string& Get(const GURL& url) const; |
| 350 | 350 |
| 351 private: | 351 private: |
| 352 mutable std::string user_agent_; | 352 mutable std::string user_agent_; |
| 353 // The UA string when we're pretending to be Mac Safari. | 353 // The UA string when we're pretending to be Mac Safari or Win Firefox. |
| 354 mutable std::string mimic_mac_safari_user_agent_; | 354 mutable std::string user_agent_for_spoofing_hack_; |
| 355 | 355 |
| 356 mutable bool user_agent_requested_; | 356 mutable bool user_agent_requested_; |
| 357 bool user_agent_is_overridden_; | 357 bool user_agent_is_overridden_; |
| 358 | 358 |
| 359 // This object can be accessed from multiple threads, so use a lock around | 359 // This object can be accessed from multiple threads, so use a lock around |
| 360 // accesses to the data members. | 360 // accesses to the data members. |
| 361 mutable base::Lock lock_; | 361 mutable base::Lock lock_; |
| 362 }; | 362 }; |
| 363 | 363 |
| 364 UserAgentState::UserAgentState() | 364 UserAgentState::UserAgentState() |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 386 | 386 |
| 387 const std::string& UserAgentState::Get(const GURL& url) const { | 387 const std::string& UserAgentState::Get(const GURL& url) const { |
| 388 base::AutoLock auto_lock(lock_); | 388 base::AutoLock auto_lock(lock_); |
| 389 user_agent_requested_ = true; | 389 user_agent_requested_ = true; |
| 390 | 390 |
| 391 DCHECK(!user_agent_.empty()); | 391 DCHECK(!user_agent_.empty()); |
| 392 | 392 |
| 393 // Workarounds for sites that use misguided UA sniffing. | 393 // Workarounds for sites that use misguided UA sniffing. |
| 394 if (!user_agent_is_overridden_) { | 394 if (!user_agent_is_overridden_) { |
| 395 #if defined(OS_MACOSX) | 395 #if defined(OS_MACOSX) |
| 396 if (url.host() == "www.microsoft.com" && | 396 if ((url.host() == "www.microsoft.com" && |
| 397 StartsWithASCII(url.path(), "/getsilverlight", false)) { | 397 StartsWithASCII(url.path(), "/getsilverlight", false)) || |
| 398 // Problematic Yahoo! JAPAN pages | |
| 399 (url.host() == "headlines.yahoo.co.jp" && | |
| 400 StartsWithASCII(url.path(), "/videonews/", true)) || | |
| 401 (url.host() == "downloads.yahoo.co.jp" && | |
| 402 StartsWithASCII(url.path(), "/docs/silverlight/", true)) || | |
| 403 url.host() == "gyao.yahoo.co.jp") { | |
|
tony
2011/11/18 18:35:10
Please make a helper function for the yahoo cases.
Yuzo
2011/11/21 02:22:01
Done.
| |
| 398 // The landing page for updating Silverlight gives a confusing experience | 404 // The landing page for updating Silverlight gives a confusing experience |
| 399 // in browsers that Silverlight doesn't officially support; spoof as | 405 // in browsers that Silverlight doesn't officially support; spoof as |
| 400 // Safari to reduce the chance that users won't complete updates. | 406 // Safari to reduce the chance that users won't complete updates. |
| 401 // Should be removed if the sniffing is removed: http://crbug.com/88211 | 407 // Should be removed if the sniffing is removed: http://crbug.com/88211 |
| 402 if (mimic_mac_safari_user_agent_.empty()) { | 408 |
| 403 mimic_mac_safari_user_agent_ = | 409 // The above Yahoo! JAPAN pages erroneously judge that Silverlight does |
| 410 // not support Chromium. Until the pages are fixed, spoof the UA. | |
| 411 // http://crbug.com/104426 | |
| 412 if (user_agent_for_spoofing_hack_.empty()) { | |
| 413 user_agent_for_spoofing_hack_ = | |
| 404 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); | 414 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); |
| 405 } | 415 } |
| 406 return mimic_mac_safari_user_agent_; | 416 return user_agent_for_spoofing_hack_; |
| 417 } | |
| 418 #elif defined(OS_WIN) | |
| 419 if ((url.host() == "headlines.yahoo.co.jp" && | |
| 420 StartsWithASCII(url.path(), "/videonews/", true)) || | |
| 421 (url.host() == "weather.yahoo.co.jp" && | |
| 422 StartsWithASCII(url.path(), "/weather/zoomradar/", true)) || | |
| 423 url.host() == "promotion.shopping.yahoo.co.jp") { | |
| 424 // The above Yahoo! JAPAN pages erroneously judge that Silverlight does | |
| 425 // not support Chromium. Until the pages are fixed, spoof the UA. | |
| 426 // Note that the set of the pages can be different from that for Mac. | |
| 427 // http://crbug.com/104426 | |
| 428 if (user_agent_for_spoofing_hack_.empty()) { | |
| 429 // Pretend to be Firefox. Mac Safari doesn't support Silverlight. | |
| 430 user_agent_for_spoofing_hack_ = | |
| 431 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 " | |
| 432 "Firefox/8.0"; | |
| 433 } | |
| 434 return user_agent_for_spoofing_hack_; | |
| 407 } | 435 } |
| 408 #endif | 436 #endif |
| 409 } | 437 } |
| 410 | 438 |
| 411 return user_agent_; | 439 return user_agent_; |
| 412 } | 440 } |
| 413 | 441 |
| 414 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; | 442 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; |
| 415 | 443 |
| 416 } // namespace | 444 } // namespace |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 std::string GetInspectorProtocolVersion() { | 477 std::string GetInspectorProtocolVersion() { |
| 450 return WebDevToolsAgent::inspectorProtocolVersion().utf8(); | 478 return WebDevToolsAgent::inspectorProtocolVersion().utf8(); |
| 451 } | 479 } |
| 452 | 480 |
| 453 bool IsInspectorProtocolVersionSupported(const std::string& version) { | 481 bool IsInspectorProtocolVersionSupported(const std::string& version) { |
| 454 return WebDevToolsAgent::supportsInspectorProtocolVersion( | 482 return WebDevToolsAgent::supportsInspectorProtocolVersion( |
| 455 WebString::fromUTF8(version)); | 483 WebString::fromUTF8(version)); |
| 456 } | 484 } |
| 457 | 485 |
| 458 } // namespace webkit_glue | 486 } // namespace webkit_glue |
| OLD | NEW |