OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "config.h" | 5 #include "config.h" |
6 #include "webkit/glue/webkit_glue.h" | 6 #include "webkit/glue/webkit_glue.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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 namespace { | 288 namespace { |
289 | 289 |
290 struct UserAgentState { | 290 struct UserAgentState { |
291 UserAgentState() | 291 UserAgentState() |
292 : user_agent_requested(false), | 292 : user_agent_requested(false), |
293 user_agent_is_overridden(false) { | 293 user_agent_is_overridden(false) { |
294 } | 294 } |
295 | 295 |
296 std::string user_agent; | 296 std::string user_agent; |
297 std::string mimic_safari_user_agent; | |
298 bool user_agent_requested; | 297 bool user_agent_requested; |
299 bool user_agent_is_overridden; | 298 bool user_agent_is_overridden; |
300 }; | 299 }; |
301 | 300 |
302 Singleton<UserAgentState> g_user_agent; | 301 Singleton<UserAgentState> g_user_agent; |
303 | 302 |
304 std::string BuildOSCpuInfo() { | 303 std::string BuildOSCpuInfo() { |
305 std::string os_cpu; | 304 std::string os_cpu; |
306 | 305 |
307 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 306 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 #else | 346 #else |
348 "%s %s", | 347 "%s %s", |
349 unixinfo.sysname, // e.g. Linux | 348 unixinfo.sysname, // e.g. Linux |
350 cputype.c_str() // e.g. i686 | 349 cputype.c_str() // e.g. i686 |
351 #endif | 350 #endif |
352 ); | 351 ); |
353 | 352 |
354 return os_cpu; | 353 return os_cpu; |
355 } | 354 } |
356 | 355 |
357 void BuildUserAgent(bool mimic_safari, std::string* result) { | 356 void BuildUserAgent(std::string* result) { |
358 const char kUserAgentPlatform[] = | 357 const char kUserAgentPlatform[] = |
359 #if defined(OS_WIN) | 358 #if defined(OS_WIN) |
360 "Windows"; | 359 "Windows"; |
361 #elif defined(OS_MACOSX) | 360 #elif defined(OS_MACOSX) |
362 "Macintosh"; | 361 "Macintosh"; |
363 #elif defined(OS_LINUX) | 362 #elif defined(OS_LINUX) |
364 "X11"; // strange, but that's what Firefox uses | 363 "X11"; // strange, but that's what Firefox uses |
365 #else | 364 #else |
366 "?"; | 365 "?"; |
367 #endif | 366 #endif |
368 | 367 |
369 const char kUserAgentSecurity = 'U'; // "US" strength encryption | 368 const char kUserAgentSecurity = 'U'; // "US" strength encryption |
370 | 369 |
371 // TODO(port): figure out correct locale | 370 // TODO(port): figure out correct locale |
372 const char kUserAgentLocale[] = "en-US"; | 371 const char kUserAgentLocale[] = "en-US"; |
373 | 372 |
374 // Get the product name and version, and replace Safari's Version/X string | 373 // Get the product name and version, and replace Safari's Version/X string |
375 // with it. This is done to expose our product name in a manner that is | 374 // with it. This is done to expose our product name in a manner that is |
376 // maximally compatible with Safari, we hope!! | 375 // maximally compatible with Safari, we hope!! |
377 std::string product; | 376 std::string product; |
378 | 377 |
379 if (!mimic_safari) { | 378 scoped_ptr<FileVersionInfo> version_info( |
380 scoped_ptr<FileVersionInfo> version_info( | 379 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
381 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | 380 if (version_info.get()) { |
382 if (version_info.get()) | 381 product = "Chrome/" + WideToASCII(version_info->product_version()); |
383 product = "Chrome/" + WideToASCII(version_info->product_version()); | 382 } else { |
| 383 DLOG(WARNING) << "Unknown product version"; |
| 384 product = "Chrome/0.0.0.0"; |
384 } | 385 } |
385 | 386 |
386 if (product.empty()) | |
387 product = "Version/3.2.1"; | |
388 | |
389 // Derived from Safari's UA string. | 387 // Derived from Safari's UA string. |
390 StringAppendF( | 388 StringAppendF( |
391 result, | 389 result, |
392 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d" | 390 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d" |
393 " (KHTML, like Gecko) %s Safari/%d.%d", | 391 " (KHTML, like Gecko) %s Safari/%d.%d", |
394 kUserAgentPlatform, | 392 kUserAgentPlatform, |
395 kUserAgentSecurity, | 393 kUserAgentSecurity, |
396 BuildOSCpuInfo().c_str(), | 394 BuildOSCpuInfo().c_str(), |
397 kUserAgentLocale, | 395 kUserAgentLocale, |
398 WEBKIT_VERSION_MAJOR, | 396 WEBKIT_VERSION_MAJOR, |
(...skipping 17 matching lines...) Expand all Loading... |
416 "Setting the user agent after someone has " | 414 "Setting the user agent after someone has " |
417 "already requested it can result in unexpected behavior."; | 415 "already requested it can result in unexpected behavior."; |
418 g_user_agent->user_agent_is_overridden = true; | 416 g_user_agent->user_agent_is_overridden = true; |
419 g_user_agent->user_agent = new_user_agent; | 417 g_user_agent->user_agent = new_user_agent; |
420 } | 418 } |
421 | 419 |
422 const std::string& GetUserAgent(const GURL& url) { | 420 const std::string& GetUserAgent(const GURL& url) { |
423 if (g_user_agent->user_agent.empty()) | 421 if (g_user_agent->user_agent.empty()) |
424 SetUserAgentToDefault(); | 422 SetUserAgentToDefault(); |
425 g_user_agent->user_agent_requested = true; | 423 g_user_agent->user_agent_requested = true; |
426 if (!g_user_agent->user_agent_is_overridden) { | |
427 // For hotmail, we need to spoof as Safari (bug 4111). | |
428 if (MatchPattern(url.host(), "*.mail.live.com")) { | |
429 if (g_user_agent->mimic_safari_user_agent.empty()) | |
430 BuildUserAgent(true, &g_user_agent->mimic_safari_user_agent); | |
431 return g_user_agent->mimic_safari_user_agent; | |
432 } | |
433 } | |
434 return g_user_agent->user_agent; | 424 return g_user_agent->user_agent; |
435 } | 425 } |
436 | 426 |
437 void SetForcefullyTerminatePluginProcess(bool value) { | 427 void SetForcefullyTerminatePluginProcess(bool value) { |
438 if (IsPluginRunningInRendererProcess()) { | 428 if (IsPluginRunningInRendererProcess()) { |
439 // Ignore this quirk when the plugins are not running in their own process. | 429 // Ignore this quirk when the plugins are not running in their own process. |
440 return; | 430 return; |
441 } | 431 } |
442 | 432 |
443 g_forcefully_terminate_plugin_process = value; | 433 g_forcefully_terminate_plugin_process = value; |
444 } | 434 } |
445 | 435 |
446 bool ShouldForcefullyTerminatePluginProcess() { | 436 bool ShouldForcefullyTerminatePluginProcess() { |
447 return g_forcefully_terminate_plugin_process; | 437 return g_forcefully_terminate_plugin_process; |
448 } | 438 } |
449 | 439 |
450 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { | 440 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { |
451 #if WEBKIT_USING_SKIA | 441 #if WEBKIT_USING_SKIA |
452 return canvas; | 442 return canvas; |
453 #elif WEBKIT_USING_CG | 443 #elif WEBKIT_USING_CG |
454 return canvas->getTopPlatformDevice().GetBitmapContext(); | 444 return canvas->getTopPlatformDevice().GetBitmapContext(); |
455 #else | 445 #else |
456 NOTIMPLEMENTED(); | 446 NOTIMPLEMENTED(); |
457 return NULL; | 447 return NULL; |
458 #endif | 448 #endif |
459 } | 449 } |
460 | 450 |
461 } // namespace webkit_glue | 451 } // namespace webkit_glue |
OLD | NEW |