Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Side by Side Diff: webkit/glue/webkit_glue.cc

Issue 340016: Spoof UA as Chrome 1.0 when loading URLs from *.pointroll.com. (Closed)
Patch Set: Nits addressed, good to go. Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 namespace { 61 namespace {
62 62
63 static const char kLayoutTestsPattern[] = "/LayoutTests/"; 63 static const char kLayoutTestsPattern[] = "/LayoutTests/";
64 static const std::string::size_type kLayoutTestsPatternSize = 64 static const std::string::size_type kLayoutTestsPatternSize =
65 arraysize(kLayoutTestsPattern) - 1; 65 arraysize(kLayoutTestsPattern) - 1;
66 static const char kFileUrlPattern[] = "file:/"; 66 static const char kFileUrlPattern[] = "file:/";
67 static const char kDataUrlPattern[] = "data:"; 67 static const char kDataUrlPattern[] = "data:";
68 static const std::string::size_type kDataUrlPatternSize = 68 static const std::string::size_type kDataUrlPatternSize =
69 arraysize(kDataUrlPattern) - 1; 69 arraysize(kDataUrlPattern) - 1;
70 static const char kFileTestPrefix[] = "(file test):"; 70 static const char kFileTestPrefix[] = "(file test):";
71 static const char kChrome1ProductString[] = "Chrome/1.0.154.53";
71 72
72 } 73 }
73 74
74 //------------------------------------------------------------------------------ 75 //------------------------------------------------------------------------------
75 // webkit_glue impl: 76 // webkit_glue impl:
76 77
77 namespace webkit_glue { 78 namespace webkit_glue {
78 79
79 // Global variable used by the plugin quirk "die after unload". 80 // Global variable used by the plugin quirk "die after unload".
80 bool g_forcefully_terminate_plugin_process = false; 81 bool g_forcefully_terminate_plugin_process = false;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 316
316 namespace { 317 namespace {
317 318
318 struct UserAgentState { 319 struct UserAgentState {
319 UserAgentState() 320 UserAgentState()
320 : user_agent_requested(false), 321 : user_agent_requested(false),
321 user_agent_is_overridden(false) { 322 user_agent_is_overridden(false) {
322 } 323 }
323 324
324 std::string user_agent; 325 std::string user_agent;
326 std::string mimic_chrome1_user_agent;
325 bool user_agent_requested; 327 bool user_agent_requested;
326 bool user_agent_is_overridden; 328 bool user_agent_is_overridden;
327 }; 329 };
328 330
329 Singleton<UserAgentState> g_user_agent; 331 Singleton<UserAgentState> g_user_agent;
330 332
331 std::string BuildOSCpuInfo() { 333 std::string BuildOSCpuInfo() {
332 std::string os_cpu; 334 std::string os_cpu;
333 335
334 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 336 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 #else 376 #else
375 "%s %s", 377 "%s %s",
376 unixinfo.sysname, // e.g. Linux 378 unixinfo.sysname, // e.g. Linux
377 cputype.c_str() // e.g. i686 379 cputype.c_str() // e.g. i686
378 #endif 380 #endif
379 ); 381 );
380 382
381 return os_cpu; 383 return os_cpu;
382 } 384 }
383 385
384 void BuildUserAgent(std::string* result) { 386 void BuildUserAgent(bool mimic_chrome1, std::string* result) {
385 const char kUserAgentPlatform[] = 387 const char kUserAgentPlatform[] =
386 #if defined(OS_WIN) 388 #if defined(OS_WIN)
387 "Windows"; 389 "Windows";
388 #elif defined(OS_MACOSX) 390 #elif defined(OS_MACOSX)
389 "Macintosh"; 391 "Macintosh";
390 #elif defined(OS_LINUX) 392 #elif defined(OS_LINUX)
391 "X11"; // strange, but that's what Firefox uses 393 "X11"; // strange, but that's what Firefox uses
392 #else 394 #else
393 "?"; 395 "?";
394 #endif 396 #endif
395 397
396 const char kUserAgentSecurity = 'U'; // "US" strength encryption 398 const char kUserAgentSecurity = 'U'; // "US" strength encryption
397 399
398 // TODO(port): figure out correct locale 400 // TODO(port): figure out correct locale
399 const char kUserAgentLocale[] = "en-US"; 401 const char kUserAgentLocale[] = "en-US";
400 402
401 // Get the product name and version, and replace Safari's Version/X string 403 // Get the product name and version, and replace Safari's Version/X string
402 // with it. This is done to expose our product name in a manner that is 404 // with it. This is done to expose our product name in a manner that is
403 // maximally compatible with Safari, we hope!! 405 // maximally compatible with Safari, we hope!!
404 std::string product; 406 std::string product;
405 407
406 scoped_ptr<FileVersionInfo> version_info( 408 if (mimic_chrome1) {
407 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); 409 product = kChrome1ProductString;
408 if (version_info.get()) {
409 product = "Chrome/" + WideToASCII(version_info->product_version());
410 } else { 410 } else {
411 DLOG(WARNING) << "Unknown product version"; 411 scoped_ptr<FileVersionInfo> version_info(
412 product = "Chrome/0.0.0.0"; 412 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
413 if (version_info.get()) {
414 product = "Chrome/" + WideToASCII(version_info->product_version());
415 } else {
416 DLOG(WARNING) << "Unknown product version";
417 product = "Chrome/0.0.0.0";
418 }
413 } 419 }
414 420
415 // Derived from Safari's UA string. 421 // Derived from Safari's UA string.
416 StringAppendF( 422 StringAppendF(
417 result, 423 result,
418 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d" 424 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d"
419 " (KHTML, like Gecko) %s Safari/%d.%d", 425 " (KHTML, like Gecko) %s Safari/%d.%d",
420 kUserAgentPlatform, 426 kUserAgentPlatform,
421 kUserAgentSecurity, 427 kUserAgentSecurity,
422 BuildOSCpuInfo().c_str(), 428 BuildOSCpuInfo().c_str(),
423 kUserAgentLocale, 429 kUserAgentLocale,
424 WEBKIT_VERSION_MAJOR, 430 WEBKIT_VERSION_MAJOR,
425 WEBKIT_VERSION_MINOR, 431 WEBKIT_VERSION_MINOR,
426 product.c_str(), 432 product.c_str(),
427 WEBKIT_VERSION_MAJOR, 433 WEBKIT_VERSION_MAJOR,
428 WEBKIT_VERSION_MINOR 434 WEBKIT_VERSION_MINOR
429 ); 435 );
430 } 436 }
431 437
432 void SetUserAgentToDefault() { 438 void SetUserAgentToDefault() {
433 BuildUserAgent(&g_user_agent->user_agent); 439 BuildUserAgent(false, &g_user_agent->user_agent);
434 } 440 }
435 441
436 } // namespace 442 } // namespace
437 443
438 void SetUserAgent(const std::string& new_user_agent) { 444 void SetUserAgent(const std::string& new_user_agent) {
439 // If you combine this with the previous line, the function only works the 445 // If you combine this with the previous line, the function only works the
440 // first time. 446 // first time.
441 DCHECK(!g_user_agent->user_agent_requested) << 447 DCHECK(!g_user_agent->user_agent_requested) <<
442 "Setting the user agent after someone has " 448 "Setting the user agent after someone has "
443 "already requested it can result in unexpected behavior."; 449 "already requested it can result in unexpected behavior.";
444 g_user_agent->user_agent_is_overridden = true; 450 g_user_agent->user_agent_is_overridden = true;
445 g_user_agent->user_agent = new_user_agent; 451 g_user_agent->user_agent = new_user_agent;
446 } 452 }
447 453
448 const std::string& GetUserAgent(const GURL& url) { 454 const std::string& GetUserAgent(const GURL& url) {
449 if (g_user_agent->user_agent.empty()) 455 if (g_user_agent->user_agent.empty())
450 SetUserAgentToDefault(); 456 SetUserAgentToDefault();
451 g_user_agent->user_agent_requested = true; 457 g_user_agent->user_agent_requested = true;
458 if (!g_user_agent->user_agent_is_overridden) {
459 // For cnn.com, which uses pointroll.com to serve their front door promo,
460 // we must spoof Chrome 1.0 in order to avoid blank page due to mis-sniffing
461 // of the UA on the server side (http://crbug.com/25934)
462 // TODO(dglazkov): Remove this once CNN's front door promo is over or when
463 // pointroll fixes their sniffing.
464 if (MatchPattern(url.host(), "*.pointroll.com")) {
465 if (g_user_agent->mimic_chrome1_user_agent.empty())
466 BuildUserAgent(true, &g_user_agent->mimic_chrome1_user_agent);
467 return g_user_agent->mimic_chrome1_user_agent;
468 }
469 }
452 return g_user_agent->user_agent; 470 return g_user_agent->user_agent;
453 } 471 }
454 472
455 void SetForcefullyTerminatePluginProcess(bool value) { 473 void SetForcefullyTerminatePluginProcess(bool value) {
456 if (IsPluginRunningInRendererProcess()) { 474 if (IsPluginRunningInRendererProcess()) {
457 // Ignore this quirk when the plugins are not running in their own process. 475 // Ignore this quirk when the plugins are not running in their own process.
458 return; 476 return;
459 } 477 }
460 478
461 g_forcefully_terminate_plugin_process = value; 479 g_forcefully_terminate_plugin_process = value;
(...skipping 22 matching lines...) Expand all
484 502
485 bool IsMediaCacheEnabled() { 503 bool IsMediaCacheEnabled() {
486 return g_enable_media_cache; 504 return g_enable_media_cache;
487 } 505 }
488 506
489 void SetMediaCacheEnabled(bool enabled) { 507 void SetMediaCacheEnabled(bool enabled) {
490 g_enable_media_cache = enabled; 508 g_enable_media_cache = enabled;
491 } 509 }
492 510
493 } // namespace webkit_glue 511 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698