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

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

Issue 19025: Add support for UA spoofing, and spoof Safari's UA string when loading URLs... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 10 months 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 | Annotate | Revision Log
OLDNEW
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return; 309 return;
310 delegate->OnNavStateChanged(webview); 310 delegate->OnNavStateChanged(webview);
311 } 311 }
312 312
313 std::string GetWebKitVersion() { 313 std::string GetWebKitVersion() {
314 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); 314 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR);
315 } 315 }
316 316
317 namespace { 317 namespace {
318 318
319 std::string* user_agent = NULL; 319 const std::string* user_agent = NULL;
320 bool user_agent_requested = false; 320 bool user_agent_requested = false;
321 bool user_agent_is_overridden = false;
321 322
322 void SetUserAgentToDefault() { 323 void BuildUserAgent(bool mimic_safari, std::string* result) {
323 static std::string default_user_agent;
324 #if defined(OS_WIN) || defined(OS_MACOSX) 324 #if defined(OS_WIN) || defined(OS_MACOSX)
325 int32 os_major_version = 0; 325 int32 os_major_version = 0;
326 int32 os_minor_version = 0; 326 int32 os_minor_version = 0;
327 int32 os_bugfix_version = 0; 327 int32 os_bugfix_version = 0;
328 #if defined(OS_WIN) 328 #if defined(OS_WIN)
329 OSVERSIONINFO info = {0}; 329 OSVERSIONINFO info = {0};
330 info.dwOSVersionInfoSize = sizeof(info); 330 info.dwOSVersionInfoSize = sizeof(info);
331 GetVersionEx(&info); 331 GetVersionEx(&info);
332 os_major_version = info.dwMajorVersion; 332 os_major_version = info.dwMajorVersion;
333 os_minor_version = info.dwMinorVersion; 333 os_minor_version = info.dwMinorVersion;
334 #elif defined(OS_MACOSX) 334 #elif defined(OS_MACOSX)
335 Gestalt(gestaltSystemVersionMajor, 335 Gestalt(gestaltSystemVersionMajor,
336 reinterpret_cast<SInt32*>(&os_major_version)); 336 reinterpret_cast<SInt32*>(&os_major_version));
337 Gestalt(gestaltSystemVersionMinor, 337 Gestalt(gestaltSystemVersionMinor,
338 reinterpret_cast<SInt32*>(&os_minor_version)); 338 reinterpret_cast<SInt32*>(&os_minor_version));
339 Gestalt(gestaltSystemVersionBugFix, 339 Gestalt(gestaltSystemVersionBugFix,
340 reinterpret_cast<SInt32*>(&os_bugfix_version)); 340 reinterpret_cast<SInt32*>(&os_bugfix_version));
341 #endif 341 #endif
342 342
343 // Get the product name and version, and replace Safari's Version/X string 343 // Get the product name and version, and replace Safari's Version/X string
344 // with it. This is done to expose our product name in a manner that is 344 // with it. This is done to expose our product name in a manner that is
345 // maximally compatible with Safari, we hope!! 345 // maximally compatible with Safari, we hope!!
346 std::string product; 346 std::string product;
347 347
348 scoped_ptr<FileVersionInfo> version_info( 348 if (!mimic_safari) {
349 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); 349 scoped_ptr<FileVersionInfo> version_info(
350 if (version_info.get()) 350 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
351 product = "Chrome/" + WideToASCII(version_info->product_version()); 351 if (version_info.get())
352 product = "Chrome/" + WideToASCII(version_info->product_version());
353 }
352 354
353 if (product.empty()) 355 if (product.empty())
354 product = "Version/3.1"; 356 product = "Version/3.2.1";
wtc 2009/01/27 19:19:24 Nit: We should move the hardcoded Safari version 3
darin (slow to review) 2009/01/27 19:52:06 Agreed, but I'll defer that to a subsequent patch.
355 357
356 // Derived from Safari's UA string. 358 // Derived from Safari's UA string.
357 StringAppendF( 359 StringAppendF(
358 &default_user_agent, 360 result,
359 #if defined(OS_WIN) 361 #if defined(OS_WIN)
360 "Mozilla/5.0 (Windows; U; Windows NT %d.%d; en-US) AppleWebKit/%d.%d" 362 "Mozilla/5.0 (Windows; U; Windows NT %d.%d; en-US) AppleWebKit/%d.%d"
361 #elif defined(OS_MACOSX) 363 #elif defined(OS_MACOSX)
362 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X %d_%d_%d; en-US) " 364 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X %d_%d_%d; en-US) "
363 "AppleWebKit/%d.%d" 365 "AppleWebKit/%d.%d"
364 #endif 366 #endif
365 " (KHTML, like Gecko) %s Safari/%d.%d", 367 " (KHTML, like Gecko) %s Safari/%d.%d",
366 os_major_version, 368 os_major_version,
367 os_minor_version, 369 os_minor_version,
368 #if defined(OS_MACOSX) 370 #if defined(OS_MACOSX)
369 os_bugfix_version, 371 os_bugfix_version,
370 #endif 372 #endif
371 WEBKIT_VERSION_MAJOR, 373 WEBKIT_VERSION_MAJOR,
372 WEBKIT_VERSION_MINOR, 374 WEBKIT_VERSION_MINOR,
373 product.c_str(), 375 product.c_str(),
374 WEBKIT_VERSION_MAJOR, 376 WEBKIT_VERSION_MAJOR,
375 WEBKIT_VERSION_MINOR 377 WEBKIT_VERSION_MINOR
376 ); 378 );
377 #elif defined(OS_LINUX) 379 #elif defined(OS_LINUX)
378 // TODO(agl): We don't have version information embedded in files under Linux 380 // TODO(agl): We don't have version information embedded in files under Linux
379 // so we use the following string which is based off the UA string for 381 // so we use the following string which is based off the UA string for
380 // Windows. Some solution for embedding the Chrome version number needs to be 382 // Windows. Some solution for embedding the Chrome version number needs to be
381 // found here. 383 // found here.
382 StringAppendF( 384 StringAppendF(
383 &default_user_agent, 385 result,
384 "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/525.13 " 386 "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/525.13 "
385 "(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13"); 387 "(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13");
386 #else 388 #else
387 // TODO(port): we need something like FileVersionInfo for our UA string. 389 // TODO(port): we need something like FileVersionInfo for our UA string.
388 NOTIMPLEMENTED(); 390 NOTIMPLEMENTED();
389 #endif 391 #endif
392 }
393
394 void SetUserAgentToDefault() {
395 static std::string default_user_agent;
396 BuildUserAgent(false, &default_user_agent);
390 user_agent = &default_user_agent; 397 user_agent = &default_user_agent;
391 } 398 }
392 399
393 }; 400 } // namespace
394 401
395 void SetUserAgent(const std::string& new_user_agent) { 402 void SetUserAgent(const std::string& new_user_agent) {
396 DCHECK(!user_agent_requested) << "Setting the user agent after someone has " 403 DCHECK(!user_agent_requested) << "Setting the user agent after someone has "
397 "already requested it can result in unexpected behavior."; 404 "already requested it can result in unexpected behavior.";
398 static std::string overridden_user_agent; 405 static std::string overridden_user_agent;
399 overridden_user_agent = new_user_agent; // If you combine this with the 406 overridden_user_agent = new_user_agent; // If you combine this with the
400 // previous line, the function only 407 // previous line, the function only
401 // works the first time. 408 // works the first time.
409 user_agent_is_overridden = true;
402 user_agent = &overridden_user_agent; 410 user_agent = &overridden_user_agent;
403 } 411 }
404 412
405 const std::string& GetUserAgent() { 413 const std::string& GetUserAgent(const GURL& url) {
406 if (!user_agent) 414 if (!user_agent)
407 SetUserAgentToDefault(); 415 SetUserAgentToDefault();
408 user_agent_requested = true; 416 user_agent_requested = true;
417 if (!user_agent_is_overridden) {
418 static std::string mimic_safari_user_agent;
wtc 2009/01/27 19:19:24 Because you're using a static object here, please
darin (slow to review) 2009/01/27 19:52:06 hmm... good point. i believe it is.
419 // For hotmail, we need to spoof as Safari (bug 4111).
wtc 2009/01/27 19:19:24 Nit: is this comment over-indented?
darin (slow to review) 2009/01/27 19:52:06 oops.. a <TAB> slipped in there.
420 if (MatchPattern(url.host(), "*.mail.live.com")) {
421 if (mimic_safari_user_agent.empty())
422 BuildUserAgent(true, &mimic_safari_user_agent);
423 return mimic_safari_user_agent;
424 }
425 }
409 return *user_agent; 426 return *user_agent;
410 } 427 }
411 428
412 void NotifyJSOutOfMemory(WebCore::Frame* frame) { 429 void NotifyJSOutOfMemory(WebCore::Frame* frame) {
413 if (!frame) 430 if (!frame)
414 return; 431 return;
415 432
416 // Dispatch to the delegate of the view that owns the frame. 433 // Dispatch to the delegate of the view that owns the frame.
417 WebFrame* webframe = WebFrameImpl::FromFrame(frame); 434 WebFrame* webframe = WebFrameImpl::FromFrame(frame);
418 WebView* webview = webframe->GetView(); 435 WebView* webview = webframe->GetView();
(...skipping 12 matching lines...) Expand all
431 } 448 }
432 449
433 g_forcefully_terminate_plugin_process = value; 450 g_forcefully_terminate_plugin_process = value;
434 } 451 }
435 452
436 bool ShouldForcefullyTerminatePluginProcess() { 453 bool ShouldForcefullyTerminatePluginProcess() {
437 return g_forcefully_terminate_plugin_process; 454 return g_forcefully_terminate_plugin_process;
438 } 455 }
439 456
440 } // namespace webkit_glue 457 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698