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) |
11 #include <sys/utsname.h> | 11 #include <sys/utsname.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "base/lazy_instance.h" | |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
19 #include "base/path_service.h" | 18 #include "base/path_service.h" |
20 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
21 #include "base/string_tokenizer.h" | 20 #include "base/string_tokenizer.h" |
22 #include "base/string_util.h" | 21 #include "base/string_util.h" |
23 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
24 #include "base/synchronization/lock.h" | |
25 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
26 #include "base/sys_string_conversions.h" | 24 #include "base/sys_string_conversions.h" |
27 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
28 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
29 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
30 #include "skia/ext/platform_canvas.h" | 28 #include "skia/ext/platform_canvas.h" |
31 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
32 #include "skia/ext/skia_utils_mac.h" | 30 #include "skia/ext/skia_utils_mac.h" |
33 #endif | 31 #endif |
34 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 11 matching lines...) Expand all Loading... |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGlyphCache.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGlyphCache.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" |
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
51 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
52 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" |
53 #endif | 51 #endif |
54 #include "v8/include/v8.h" | 52 #include "v8/include/v8.h" |
55 #include "webkit/glue/glue_serialize.h" | 53 #include "webkit/glue/glue_serialize.h" |
56 #include "webkit/glue/user_agent.h" | |
57 | 54 |
58 using WebKit::WebCanvas; | 55 using WebKit::WebCanvas; |
59 using WebKit::WebData; | 56 using WebKit::WebData; |
60 using WebKit::WebDevToolsAgent; | 57 using WebKit::WebDevToolsAgent; |
61 using WebKit::WebElement; | 58 using WebKit::WebElement; |
62 using WebKit::WebFrame; | 59 using WebKit::WebFrame; |
63 using WebKit::WebGlyphCache; | 60 using WebKit::WebGlyphCache; |
64 using WebKit::WebHistoryItem; | 61 using WebKit::WebHistoryItem; |
65 using WebKit::WebImage; | 62 using WebKit::WebImage; |
66 using WebKit::WebPrintParams; | 63 using WebKit::WebPrintParams; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 web_file_info->modificationTime = std::numeric_limits<double>::quiet_NaN(); | 311 web_file_info->modificationTime = std::numeric_limits<double>::quiet_NaN(); |
315 else | 312 else |
316 web_file_info->modificationTime = file_info.last_modified.ToDoubleT(); | 313 web_file_info->modificationTime = file_info.last_modified.ToDoubleT(); |
317 web_file_info->length = file_info.size; | 314 web_file_info->length = file_info.size; |
318 if (file_info.is_directory) | 315 if (file_info.is_directory) |
319 web_file_info->type = WebKit::WebFileInfo::TypeDirectory; | 316 web_file_info->type = WebKit::WebFileInfo::TypeDirectory; |
320 else | 317 else |
321 web_file_info->type = WebKit::WebFileInfo::TypeFile; | 318 web_file_info->type = WebKit::WebFileInfo::TypeFile; |
322 } | 319 } |
323 | 320 |
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) { | 321 void SetForcefullyTerminatePluginProcess(bool value) { |
454 g_forcefully_terminate_plugin_process = value; | 322 g_forcefully_terminate_plugin_process = value; |
455 } | 323 } |
456 | 324 |
457 bool ShouldForcefullyTerminatePluginProcess() { | 325 bool ShouldForcefullyTerminatePluginProcess() { |
458 return g_forcefully_terminate_plugin_process; | 326 return g_forcefully_terminate_plugin_process; |
459 } | 327 } |
460 | 328 |
461 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { | 329 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { |
462 return canvas; | 330 return canvas; |
(...skipping 27 matching lines...) Expand all Loading... |
490 case WebKit::WebReferrerPolicyOrigin: | 358 case WebKit::WebReferrerPolicyOrigin: |
491 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER; | 359 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER; |
492 break; | 360 break; |
493 } | 361 } |
494 request->set_referrer_policy(net_referrer_policy); | 362 request->set_referrer_policy(net_referrer_policy); |
495 } | 363 } |
496 | 364 |
497 COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN); | 365 COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN); |
498 | 366 |
499 } // namespace webkit_glue | 367 } // namespace webkit_glue |
OLD | NEW |