| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <objidl.h> | 9 #include <objidl.h> |
| 10 #include <mlang.h> | 10 #include <mlang.h> |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return; | 337 return; |
| 338 delegate->OnNavStateChanged(webview); | 338 delegate->OnNavStateChanged(webview); |
| 339 } | 339 } |
| 340 | 340 |
| 341 std::string GetWebKitVersion() { | 341 std::string GetWebKitVersion() { |
| 342 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); | 342 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); |
| 343 } | 343 } |
| 344 | 344 |
| 345 namespace { | 345 namespace { |
| 346 | 346 |
| 347 std::string* user_agent = NULL; | 347 const std::string* user_agent = NULL; |
| 348 bool user_agent_requested = false; | 348 bool user_agent_requested = false; |
| 349 bool user_agent_is_overridden = false; |
| 349 | 350 |
| 350 void SetUserAgentToDefault() { | 351 void BuildUserAgent(bool mimic_safari, std::string* result) { |
| 351 static std::string default_user_agent; | |
| 352 #if defined(OS_WIN) || defined(OS_MACOSX) | 352 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 353 int32 os_major_version = 0; | 353 int32 os_major_version = 0; |
| 354 int32 os_minor_version = 0; | 354 int32 os_minor_version = 0; |
| 355 int32 os_bugfix_version = 0; | 355 int32 os_bugfix_version = 0; |
| 356 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
| 357 OSVERSIONINFO info = {0}; | 357 OSVERSIONINFO info = {0}; |
| 358 info.dwOSVersionInfoSize = sizeof(info); | 358 info.dwOSVersionInfoSize = sizeof(info); |
| 359 GetVersionEx(&info); | 359 GetVersionEx(&info); |
| 360 os_major_version = info.dwMajorVersion; | 360 os_major_version = info.dwMajorVersion; |
| 361 os_minor_version = info.dwMinorVersion; | 361 os_minor_version = info.dwMinorVersion; |
| 362 #elif defined(OS_MACOSX) | 362 #elif defined(OS_MACOSX) |
| 363 Gestalt(gestaltSystemVersionMajor, | 363 Gestalt(gestaltSystemVersionMajor, |
| 364 reinterpret_cast<SInt32*>(&os_major_version)); | 364 reinterpret_cast<SInt32*>(&os_major_version)); |
| 365 Gestalt(gestaltSystemVersionMinor, | 365 Gestalt(gestaltSystemVersionMinor, |
| 366 reinterpret_cast<SInt32*>(&os_minor_version)); | 366 reinterpret_cast<SInt32*>(&os_minor_version)); |
| 367 Gestalt(gestaltSystemVersionBugFix, | 367 Gestalt(gestaltSystemVersionBugFix, |
| 368 reinterpret_cast<SInt32*>(&os_bugfix_version)); | 368 reinterpret_cast<SInt32*>(&os_bugfix_version)); |
| 369 #endif | 369 #endif |
| 370 | 370 |
| 371 // Get the product name and version, and replace Safari's Version/X string | 371 // Get the product name and version, and replace Safari's Version/X string |
| 372 // with it. This is done to expose our product name in a manner that is | 372 // with it. This is done to expose our product name in a manner that is |
| 373 // maximally compatible with Safari, we hope!! | 373 // maximally compatible with Safari, we hope!! |
| 374 std::string product; | 374 std::string product; |
| 375 | 375 |
| 376 FileVersionInfo* version_info = | 376 if (!mimic_safari) { |
| 377 FileVersionInfo::CreateFileVersionInfoForCurrentModule(); | 377 scoped_ptr<FileVersionInfo> version_info( |
| 378 if (version_info) | 378 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 379 product = "Chrome/" + WideToASCII(version_info->product_version()); | 379 if (version_info.get()) |
| 380 product = "Chrome/" + WideToASCII(version_info->product_version()); |
| 381 } |
| 380 | 382 |
| 381 if (product.empty()) | 383 if (product.empty()) |
| 382 product = "Version/3.1"; | 384 product = "Version/3.2.1"; |
| 383 | 385 |
| 384 // Derived from Safari's UA string. | 386 // Derived from Safari's UA string. |
| 385 StringAppendF( | 387 StringAppendF( |
| 386 &default_user_agent, | 388 result, |
| 387 #if defined(OS_WIN) | 389 #if defined(OS_WIN) |
| 388 "Mozilla/5.0 (Windows; U; Windows NT %d.%d; en-US) AppleWebKit/%d.%d" | 390 "Mozilla/5.0 (Windows; U; Windows NT %d.%d; en-US) AppleWebKit/%d.%d" |
| 389 #elif defined(OS_MACOSX) | 391 #elif defined(OS_MACOSX) |
| 390 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X %d_%d_%d; en-US) " | 392 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X %d_%d_%d; en-US) " |
| 391 "AppleWebKit/%d.%d" | 393 "AppleWebKit/%d.%d" |
| 392 #endif | 394 #endif |
| 393 " (KHTML, like Gecko) %s Safari/%d.%d", | 395 " (KHTML, like Gecko) %s Safari/%d.%d", |
| 394 os_major_version, | 396 os_major_version, |
| 395 os_minor_version, | 397 os_minor_version, |
| 396 #if defined(OS_MACOSX) | 398 #if defined(OS_MACOSX) |
| 397 os_bugfix_version, | 399 os_bugfix_version, |
| 398 #endif | 400 #endif |
| 399 WEBKIT_VERSION_MAJOR, | 401 WEBKIT_VERSION_MAJOR, |
| 400 WEBKIT_VERSION_MINOR, | 402 WEBKIT_VERSION_MINOR, |
| 401 product.c_str(), | 403 product.c_str(), |
| 402 WEBKIT_VERSION_MAJOR, | 404 WEBKIT_VERSION_MAJOR, |
| 403 WEBKIT_VERSION_MINOR | 405 WEBKIT_VERSION_MINOR |
| 404 ); | 406 ); |
| 405 #else | 407 #else |
| 406 // TODO(port): we need something like FileVersionInfo for our UA string. | 408 // TODO(port): we need something like FileVersionInfo for our UA string. |
| 407 NOTIMPLEMENTED(); | 409 NOTIMPLEMENTED(); |
| 408 #endif | 410 #endif |
| 411 } |
| 412 |
| 413 void SetUserAgentToDefault() { |
| 414 static std::string default_user_agent; |
| 415 BuildUserAgent(false, &default_user_agent); |
| 409 user_agent = &default_user_agent; | 416 user_agent = &default_user_agent; |
| 410 } | 417 } |
| 411 | 418 |
| 412 }; | 419 } // namespace |
| 413 | 420 |
| 414 void SetUserAgent(const std::string& new_user_agent) { | 421 void SetUserAgent(const std::string& new_user_agent) { |
| 415 DCHECK(!user_agent_requested) << "Setting the user agent after someone has " | 422 DCHECK(!user_agent_requested) << "Setting the user agent after someone has " |
| 416 "already requested it can result in unexpected behavior."; | 423 "already requested it can result in unexpected behavior."; |
| 417 static std::string overridden_user_agent; | 424 static std::string overridden_user_agent; |
| 418 overridden_user_agent = new_user_agent; // If you combine this with the | 425 overridden_user_agent = new_user_agent; // If you combine this with the |
| 419 // previous line, the function only | 426 // previous line, the function only |
| 420 // works the first time. | 427 // works the first time. |
| 428 user_agent_is_overridden = true; |
| 421 user_agent = &overridden_user_agent; | 429 user_agent = &overridden_user_agent; |
| 422 } | 430 } |
| 423 | 431 |
| 424 const std::string& GetUserAgent() { | 432 const std::string& GetUserAgent(const GURL& url) { |
| 425 if (!user_agent) | 433 if (!user_agent) |
| 426 SetUserAgentToDefault(); | 434 SetUserAgentToDefault(); |
| 427 user_agent_requested = true; | 435 user_agent_requested = true; |
| 436 if (!user_agent_is_overridden) { |
| 437 static std::string mimic_safari_user_agent; |
| 438 // For hotmail, we need to spoof as Safari (bug 4111). |
| 439 if (MatchPattern(url.host(), "*.mail.live.com")) { |
| 440 if (mimic_safari_user_agent.empty()) |
| 441 BuildUserAgent(true, &mimic_safari_user_agent); |
| 442 return mimic_safari_user_agent; |
| 443 } |
| 444 } |
| 428 return *user_agent; | 445 return *user_agent; |
| 429 } | 446 } |
| 430 | 447 |
| 431 void NotifyJSOutOfMemory(WebCore::Frame* frame) { | 448 void NotifyJSOutOfMemory(WebCore::Frame* frame) { |
| 432 if (!frame) | 449 if (!frame) |
| 433 return; | 450 return; |
| 434 | 451 |
| 435 // Dispatch to the delegate of the view that owns the frame. | 452 // Dispatch to the delegate of the view that owns the frame. |
| 436 WebFrame* webframe = WebFrameImpl::FromFrame(frame); | 453 WebFrame* webframe = WebFrameImpl::FromFrame(frame); |
| 437 WebView* webview = webframe->GetView(); | 454 WebView* webview = webframe->GetView(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 450 } | 467 } |
| 451 | 468 |
| 452 g_forcefully_terminate_plugin_process = value; | 469 g_forcefully_terminate_plugin_process = value; |
| 453 } | 470 } |
| 454 | 471 |
| 455 bool ShouldForcefullyTerminatePluginProcess() { | 472 bool ShouldForcefullyTerminatePluginProcess() { |
| 456 return g_forcefully_terminate_plugin_process; | 473 return g_forcefully_terminate_plugin_process; |
| 457 } | 474 } |
| 458 | 475 |
| 459 } // namespace webkit_glue | 476 } // namespace webkit_glue |
| OLD | NEW |