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 |
354 mutable std::string mimic_mac_safari_user_agent_; | 354 #if defined(OS_MACOSX) || defined(OS_WIN) |
stuartmorgan
2011/11/17 09:59:17
Don't needlessly if-def things that are meaningful
Yuzo
2011/11/17 10:32:02
I have no strong opinions about this. If Tony also
stuartmorgan
2011/11/17 10:50:38
The concept of a UA hack is meaningful on Linux (a
tony
2011/11/17 18:13:06
I agree with Stuart. Fewer #ifs are better.
Yuzo
2011/11/18 07:31:44
Done.
| |
355 // The UA string when we're pretending to be Mac Safari or Win Firefox. | |
356 mutable std::string user_agent_for_spoofing_hack_; | |
357 #endif | |
355 | 358 |
356 mutable bool user_agent_requested_; | 359 mutable bool user_agent_requested_; |
357 bool user_agent_is_overridden_; | 360 bool user_agent_is_overridden_; |
358 | 361 |
359 // This object can be accessed from multiple threads, so use a lock around | 362 // This object can be accessed from multiple threads, so use a lock around |
360 // accesses to the data members. | 363 // accesses to the data members. |
361 mutable base::Lock lock_; | 364 mutable base::Lock lock_; |
362 }; | 365 }; |
363 | 366 |
364 UserAgentState::UserAgentState() | 367 UserAgentState::UserAgentState() |
(...skipping 12 matching lines...) Expand all Loading... | |
377 // given g_user_agent is a global. | 380 // given g_user_agent is a global. |
378 return; | 381 return; |
379 } | 382 } |
380 DCHECK(!user_agent.empty()); | 383 DCHECK(!user_agent.empty()); |
381 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " | 384 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " |
382 "already requested it can result in unexpected behavior."; | 385 "already requested it can result in unexpected behavior."; |
383 user_agent_is_overridden_ = overriding; | 386 user_agent_is_overridden_ = overriding; |
384 user_agent_ = user_agent; | 387 user_agent_ = user_agent; |
385 } | 388 } |
386 | 389 |
390 #if defined(OS_MACOSX) || defined(OS_WIN) | |
391 bool ShouldSpoofUAHack(const GURL& url) { | |
392 return | |
stuartmorgan
2011/11/17 09:59:17
Breaking the statement into a bunch of ifdef'd pie
Yuzo
2011/11/17 10:32:02
I have no strong opinion on this either. Let's wai
tony
2011/11/17 18:13:06
I agree with Stuart here too. The current form is
Yuzo
2011/11/18 07:31:44
Done.
| |
393 #if defined(OS_MACOSX) | |
394 // The landing page for updating Silverlight gives a confusing experience | |
395 // in browsers that Silverlight doesn't officially support; spoof as | |
396 // Safari to reduce the chance that users won't complete updates. | |
397 // Should be removed if the sniffing is removed: http://crbug.com/88211 | |
398 (url.host() == "www.microsoft.com" && | |
399 StartsWithASCII(url.path(), "/getsilverlight", false)) || | |
400 | |
401 // The following Yahoo! JAPAN pages erroneously judge that Chromium does | |
402 // not support Silverlight. Until the pages are fixed, spoof the UA. | |
403 // http://crbug.com/104426 | |
404 (url.host() == "downloads.yahoo.co.jp" && | |
405 StartsWithASCII(url.path(), "/docs/silverlight/", true)) || | |
406 url.host() == "gyao.yahoo.co.jp" || | |
407 #elif defined(OS_WIN) | |
408 (url.host() == "weather.yahoo.co.jp" && | |
409 StartsWithASCII(url.path(), "/weather/zoomradar/", true)) || | |
410 url.host() == "promotion.shopping.yahoo.co.jp" || | |
411 #endif | |
412 (url.host() == "headlines.yahoo.co.jp" && | |
413 StartsWithASCII(url.path(), "/videonews/", true)); | |
stuartmorgan
2011/11/17 09:59:17
So... on Windows you spoof this page as Windows Fi
Yuzo
2011/11/17 10:32:02
Silverlight is not supported on Linux.
I don't kno
stuartmorgan
2011/11/17 10:50:38
Please add a comment explaining why you are using
Yuzo
2011/11/18 07:31:44
Done.
| |
414 } | |
415 #endif | |
416 | |
387 const std::string& UserAgentState::Get(const GURL& url) const { | 417 const std::string& UserAgentState::Get(const GURL& url) const { |
388 base::AutoLock auto_lock(lock_); | 418 base::AutoLock auto_lock(lock_); |
389 user_agent_requested_ = true; | 419 user_agent_requested_ = true; |
390 | 420 |
391 DCHECK(!user_agent_.empty()); | 421 DCHECK(!user_agent_.empty()); |
392 | 422 |
393 // Workarounds for sites that use misguided UA sniffing. | 423 // Workarounds for sites that use misguided UA sniffing. |
394 if (!user_agent_is_overridden_) { | 424 if (!user_agent_is_overridden_) { |
425 #if defined(OS_MACOSX) || defined(OS_WIN) | |
426 if (ShouldSpoofUAHack(url)) { | |
stuartmorgan
2011/11/17 09:59:17
I really don't like adding code that appears to be
Yuzo
2011/11/17 10:32:02
I'm not pretending anything -- I've just extracted
stuartmorgan
2011/11/17 10:50:38
My point is that the refactoring suggests that the
Yuzo
2011/11/18 07:31:44
Done.
| |
427 if (user_agent_for_spoofing_hack_.empty()) { | |
428 user_agent_for_spoofing_hack_ = | |
395 #if defined(OS_MACOSX) | 429 #if defined(OS_MACOSX) |
396 if (url.host() == "www.microsoft.com" && | |
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"); | 430 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); |
431 #elif defined(OS_WIN) | |
432 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 " | |
433 "Firefox/8.0"; | |
tony
2011/11/17 18:13:06
Does Safari Win not work?
Yuzo
2011/11/18 07:31:44
No, it doesn't. Added a comment.
| |
434 #endif | |
405 } | 435 } |
406 return mimic_mac_safari_user_agent_; | 436 return user_agent_for_spoofing_hack_; |
407 } | 437 } |
408 #endif | 438 #endif |
409 } | 439 } |
410 | 440 |
411 return user_agent_; | 441 return user_agent_; |
412 } | 442 } |
413 | 443 |
414 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; | 444 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; |
415 | 445 |
416 } // namespace | 446 } // namespace |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 std::string GetInspectorProtocolVersion() { | 479 std::string GetInspectorProtocolVersion() { |
450 return WebDevToolsAgent::inspectorProtocolVersion().utf8(); | 480 return WebDevToolsAgent::inspectorProtocolVersion().utf8(); |
451 } | 481 } |
452 | 482 |
453 bool IsInspectorProtocolVersionSupported(const std::string& version) { | 483 bool IsInspectorProtocolVersionSupported(const std::string& version) { |
454 return WebDevToolsAgent::supportsInspectorProtocolVersion( | 484 return WebDevToolsAgent::supportsInspectorProtocolVersion( |
455 WebString::fromUTF8(version)); | 485 WebString::fromUTF8(version)); |
456 } | 486 } |
457 | 487 |
458 } // namespace webkit_glue | 488 } // namespace webkit_glue |
OLD | NEW |