| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 web_file_info->modificationTime = std::numeric_limits<double>::quiet_NaN(); | 314 web_file_info->modificationTime = std::numeric_limits<double>::quiet_NaN(); |
| 315 else | 315 else |
| 316 web_file_info->modificationTime = file_info.last_modified.ToDoubleT(); | 316 web_file_info->modificationTime = file_info.last_modified.ToDoubleT(); |
| 317 web_file_info->length = file_info.size; | 317 web_file_info->length = file_info.size; |
| 318 if (file_info.is_directory) | 318 if (file_info.is_directory) |
| 319 web_file_info->type = WebKit::WebFileInfo::TypeDirectory; | 319 web_file_info->type = WebKit::WebFileInfo::TypeDirectory; |
| 320 else | 320 else |
| 321 web_file_info->type = WebKit::WebFileInfo::TypeFile; | 321 web_file_info->type = WebKit::WebFileInfo::TypeFile; |
| 322 } | 322 } |
| 323 | 323 |
| 324 namespace { | |
| 325 | |
| 326 class UserAgentState { | |
| 327 public: | |
| 328 UserAgentState(); | |
| 329 ~UserAgentState(); | |
| 330 | |
| 331 void Set(const std::string& user_agent, bool overriding); | |
| 332 const std::string& Get(const GURL& url) const; | |
| 333 | |
| 334 private: | |
| 335 mutable std::string user_agent_; | |
| 336 // The UA string when we're pretending to be Mac Safari or Win Firefox. | |
| 337 mutable std::string user_agent_for_spoofing_hack_; | |
| 338 | |
| 339 mutable bool user_agent_requested_; | |
| 340 bool user_agent_is_overridden_; | |
| 341 | |
| 342 // This object can be accessed from multiple threads, so use a lock around | |
| 343 // accesses to the data members. | |
| 344 mutable base::Lock lock_; | |
| 345 }; | |
| 346 | |
| 347 UserAgentState::UserAgentState() | |
| 348 : user_agent_requested_(false), | |
| 349 user_agent_is_overridden_(false) { | |
| 350 } | |
| 351 | |
| 352 UserAgentState::~UserAgentState() { | |
| 353 } | |
| 354 | |
| 355 void UserAgentState::Set(const std::string& user_agent, bool overriding) { | |
| 356 base::AutoLock auto_lock(lock_); | |
| 357 if (user_agent == user_agent_) { | |
| 358 // We allow the user agent to be set multiple times as long as it | |
| 359 // is set to the same value, in order to simplify unit testing | |
| 360 // given g_user_agent is a global. | |
| 361 return; | |
| 362 } | |
| 363 DCHECK(!user_agent.empty()); | |
| 364 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " | |
| 365 "already requested it can result in unexpected behavior."; | |
| 366 user_agent_is_overridden_ = overriding; | |
| 367 user_agent_ = user_agent; | |
| 368 } | |
| 369 | |
| 370 bool IsMicrosoftSiteThatNeedsSpoofingForSilverlight(const GURL& url) { | |
| 371 #if defined(OS_MACOSX) | |
| 372 // The landing page for updating Silverlight gives a confusing experience | |
| 373 // in browsers that Silverlight doesn't officially support; spoof as | |
| 374 // Safari to reduce the chance that users won't complete updates. | |
| 375 // Should be removed if the sniffing is removed: http://crbug.com/88211 | |
| 376 if (url.host() == "www.microsoft.com" && | |
| 377 StartsWithASCII(url.path(), "/getsilverlight", false)) { | |
| 378 return true; | |
| 379 } | |
| 380 #endif | |
| 381 return false; | |
| 382 } | |
| 383 | |
| 384 bool IsYahooSiteThatNeedsSpoofingForSilverlight(const GURL& url) { | |
| 385 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 386 // The following Yahoo! JAPAN pages erroneously judge that Silverlight does | |
| 387 // not support Chromium. Until the pages are fixed, spoof the UA. | |
| 388 // http://crbug.com/104426 | |
| 389 if (url.host() == "headlines.yahoo.co.jp" && | |
| 390 StartsWithASCII(url.path(), "/videonews/", true)) { | |
| 391 return true; | |
| 392 } | |
| 393 #endif | |
| 394 #if defined(OS_MACOSX) | |
| 395 if ((url.host() == "downloads.yahoo.co.jp" && | |
| 396 StartsWithASCII(url.path(), "/docs/silverlight/", true)) || | |
| 397 url.host() == "gyao.yahoo.co.jp") { | |
| 398 return true; | |
| 399 } | |
| 400 #elif defined(OS_WIN) | |
| 401 if ((url.host() == "weather.yahoo.co.jp" && | |
| 402 StartsWithASCII(url.path(), "/weather/zoomradar/", true)) || | |
| 403 url.host() == "promotion.shopping.yahoo.co.jp" || | |
| 404 url.host() == "pokemon.kids.yahoo.co.jp") { | |
| 405 return true; | |
| 406 } | |
| 407 #endif | |
| 408 return false; | |
| 409 } | |
| 410 | |
| 411 const std::string& UserAgentState::Get(const GURL& url) const { | |
| 412 base::AutoLock auto_lock(lock_); | |
| 413 user_agent_requested_ = true; | |
| 414 | |
| 415 DCHECK(!user_agent_.empty()); | |
| 416 | |
| 417 // Workarounds for sites that use misguided UA sniffing. | |
| 418 if (!user_agent_is_overridden_) { | |
| 419 if (IsMicrosoftSiteThatNeedsSpoofingForSilverlight(url) || | |
| 420 IsYahooSiteThatNeedsSpoofingForSilverlight(url)) { | |
| 421 if (user_agent_for_spoofing_hack_.empty()) { | |
| 422 #if defined(OS_MACOSX) | |
| 423 user_agent_for_spoofing_hack_ = | |
| 424 BuildUserAgentFromProduct("Version/5.1.1 Safari/534.51.22"); | |
| 425 #elif defined(OS_WIN) | |
| 426 // Pretend to be Firefox. Silverlight doesn't support Win Safari. | |
| 427 base::StringAppendF( | |
| 428 &user_agent_for_spoofing_hack_, | |
| 429 "Mozilla/5.0 (%s) Gecko/20100101 Firefox/8.0", | |
| 430 webkit_glue::BuildOSCpuInfo().c_str()); | |
| 431 #endif | |
| 432 } | |
| 433 DCHECK(!user_agent_for_spoofing_hack_.empty()); | |
| 434 return user_agent_for_spoofing_hack_; | |
| 435 } | |
| 436 } | |
| 437 | |
| 438 return user_agent_; | |
| 439 } | |
| 440 | |
| 441 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; | |
| 442 | |
| 443 } // namespace | |
| 444 | |
| 445 void SetUserAgent(const std::string& user_agent, bool overriding) { | |
| 446 g_user_agent.Get().Set(user_agent, overriding); | |
| 447 } | |
| 448 | |
| 449 const std::string& GetUserAgent(const GURL& url) { | |
| 450 return g_user_agent.Get().Get(url); | |
| 451 } | |
| 452 | |
| 453 void SetForcefullyTerminatePluginProcess(bool value) { | 324 void SetForcefullyTerminatePluginProcess(bool value) { |
| 454 g_forcefully_terminate_plugin_process = value; | 325 g_forcefully_terminate_plugin_process = value; |
| 455 } | 326 } |
| 456 | 327 |
| 457 bool ShouldForcefullyTerminatePluginProcess() { | 328 bool ShouldForcefullyTerminatePluginProcess() { |
| 458 return g_forcefully_terminate_plugin_process; | 329 return g_forcefully_terminate_plugin_process; |
| 459 } | 330 } |
| 460 | 331 |
| 461 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { | 332 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { |
| 462 return canvas; | 333 return canvas; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 490 case WebKit::WebReferrerPolicyOrigin: | 361 case WebKit::WebReferrerPolicyOrigin: |
| 491 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER; | 362 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER; |
| 492 break; | 363 break; |
| 493 } | 364 } |
| 494 request->set_referrer_policy(net_referrer_policy); | 365 request->set_referrer_policy(net_referrer_policy); |
| 495 } | 366 } |
| 496 | 367 |
| 497 COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN); | 368 COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN); |
| 498 | 369 |
| 499 } // namespace webkit_glue | 370 } // namespace webkit_glue |
| OLD | NEW |