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

Side by Side Diff: webkit/glue/webkit_glue.cc

Issue 8590022: Work around wrong UA sniffing by Yahoo! JAPAN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a comment Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 12 matching lines...) Expand all
377 // given g_user_agent is a global. 377 // given g_user_agent is a global.
378 return; 378 return;
379 } 379 }
380 DCHECK(!user_agent.empty()); 380 DCHECK(!user_agent.empty());
381 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " 381 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has "
382 "already requested it can result in unexpected behavior."; 382 "already requested it can result in unexpected behavior.";
383 user_agent_is_overridden_ = overriding; 383 user_agent_is_overridden_ = overriding;
384 user_agent_ = user_agent; 384 user_agent_ = user_agent;
385 } 385 }
386 386
387 bool IsMicrosoftSiteThatNeedsSpoofing(const GURL& url) {
388 #if defined(OS_MACOSX)
389 // The landing page for updating Silverlight gives a confusing experience
390 // in browsers that Silverlight doesn't officially support; spoof as
391 // Safari to reduce the chance that users won't complete updates.
392 // Should be removed if the sniffing is removed: http://crbug.com/88211
393 if (url.host() == "www.microsoft.com" &&
394 StartsWithASCII(url.path(), "/getsilverlight", false)) {
395 return true;
396 }
397 #endif
398 return false;
399 }
400
401 bool IsYahooSiteThatNeedsSpoofing(const GURL& url) {
402 // The following Yahoo! JAPAN pages erroneously judge that Silverlight does
403 // not support Chromium. Until the pages are fixed, spoof the UA.
404 // http://crbug.com/104426
405 if (url.host() == "headlines.yahoo.co.jp" &&
406 StartsWithASCII(url.path(), "/videonews/", true)) {
407 return true;
408 }
409 #if defined(OS_MACOSX)
410 if ((url.host() == "downloads.yahoo.co.jp" &&
411 StartsWithASCII(url.path(), "/docs/silverlight/", true)) ||
stuartmorgan 2011/11/28 08:34:46 Indentation is off here and in the next if
412 url.host() == "gyao.yahoo.co.jp") {
413 return true;
414 }
415 #elif defined(OS_WIN)
416 if ((url.host() == "weather.yahoo.co.jp" &&
417 StartsWithASCII(url.path(), "/weather/zoomradar/", true)) ||
418 url.host() == "promotion.shopping.yahoo.co.jp") {
419 return true;
420 }
421 #endif
422 return false;
423 }
424
387 const std::string& UserAgentState::Get(const GURL& url) const { 425 const std::string& UserAgentState::Get(const GURL& url) const {
388 base::AutoLock auto_lock(lock_); 426 base::AutoLock auto_lock(lock_);
389 user_agent_requested_ = true; 427 user_agent_requested_ = true;
390 428
391 DCHECK(!user_agent_.empty()); 429 DCHECK(!user_agent_.empty());
392 430
393 // Workarounds for sites that use misguided UA sniffing. 431 // Workarounds for sites that use misguided UA sniffing.
394 if (!user_agent_is_overridden_) { 432 if (!user_agent_is_overridden_) {
433 if (IsMicrosoftSiteThatNeedsSpoofing(url) ||
434 IsYahooSiteThatNeedsSpoofing(url)) {
435 if (user_agent_for_spoofing_hack_.empty()) {
395 #if defined(OS_MACOSX) 436 #if defined(OS_MACOSX)
396 if (url.host() == "www.microsoft.com" && 437 user_agent_for_spoofing_hack_ =
397 StartsWithASCII(url.path(), "/getsilverlight", false)) {
398 // The landing page for updating Silverlight gives a confusing experience
399 // in browsers that Silverlight doesn't officially support; spoof as
400 // Safari to reduce the chance that users won't complete updates.
401 // Should be removed if the sniffing is removed: http://crbug.com/88211
402 if (mimic_mac_safari_user_agent_.empty()) {
403 mimic_mac_safari_user_agent_ =
404 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); 438 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27");
stuartmorgan 2011/11/28 08:34:46 As long as you are in this code, it would be a goo
439 #elif defined(OS_WIN)
440 // Pretend to be Firefox. Silverlight doesn't support Win Safari.
441 base::StringAppendF(
442 &user_agent_for_spoofing_hack_,
443 "Mozilla/5.0 (%s) Gecko/20100101 Firefox/8.0",
444 webkit_glue::BuildOSCpuInfo().c_str());
445 #endif
405 } 446 }
406 return mimic_mac_safari_user_agent_; 447 return user_agent_for_spoofing_hack_;
407 } 448 }
408 #endif
409 } 449 }
410 450
411 return user_agent_; 451 return user_agent_;
412 } 452 }
413 453
414 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; 454 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER;
415 455
416 } // namespace 456 } // namespace
417 457
418 void SetUserAgent(const std::string& user_agent, bool overriding) { 458 void SetUserAgent(const std::string& user_agent, bool overriding) {
(...skipping 30 matching lines...) Expand all
449 std::string GetInspectorProtocolVersion() { 489 std::string GetInspectorProtocolVersion() {
450 return WebDevToolsAgent::inspectorProtocolVersion().utf8(); 490 return WebDevToolsAgent::inspectorProtocolVersion().utf8();
451 } 491 }
452 492
453 bool IsInspectorProtocolVersionSupported(const std::string& version) { 493 bool IsInspectorProtocolVersionSupported(const std::string& version) {
454 return WebDevToolsAgent::supportsInspectorProtocolVersion( 494 return WebDevToolsAgent::supportsInspectorProtocolVersion(
455 WebString::fromUTF8(version)); 495 WebString::fromUTF8(version));
456 } 496 }
457 497
458 } // namespace webkit_glue 498 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698