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

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

Issue 3214005: Factoring BuildUserAgent out to a separate lib for GCF can use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
« no previous file with comments | « webkit/glue/user_agent.cc ('k') | webkit/glue/webkit_glue.gypi » ('j') | 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 "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)
(...skipping 23 matching lines...) Expand all
34 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" 34 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
35 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" 35 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
36 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" 36 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
37 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 37 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
38 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" 38 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
39 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 39 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
40 #if defined(OS_WIN) 40 #if defined(OS_WIN)
41 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" 41 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h"
42 #endif 42 #endif
43 #include "webkit/glue/glue_serialize.h" 43 #include "webkit/glue/glue_serialize.h"
44 #include "webkit/glue/user_agent.h"
44 #include "v8/include/v8.h" 45 #include "v8/include/v8.h"
45 46
46 #include "webkit_version.h" // Generated 47 #include "webkit_version.h" // Generated
47 48
48 using WebKit::WebCanvas; 49 using WebKit::WebCanvas;
49 using WebKit::WebData; 50 using WebKit::WebData;
50 using WebKit::WebElement; 51 using WebKit::WebElement;
51 using WebKit::WebFrame; 52 using WebKit::WebFrame;
52 using WebKit::WebGlyphCache; 53 using WebKit::WebGlyphCache;
53 using WebKit::WebHistoryItem; 54 using WebKit::WebHistoryItem;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 330
330 // The UA string when we're pretending to be Windows Chrome. 331 // The UA string when we're pretending to be Windows Chrome.
331 std::string mimic_windows_user_agent; 332 std::string mimic_windows_user_agent;
332 333
333 bool user_agent_requested; 334 bool user_agent_requested;
334 bool user_agent_is_overridden; 335 bool user_agent_is_overridden;
335 }; 336 };
336 337
337 Singleton<UserAgentState> g_user_agent; 338 Singleton<UserAgentState> g_user_agent;
338 339
339 std::string BuildOSCpuInfo() {
340 std::string os_cpu;
341
342 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
343 int32 os_major_version = 0;
344 int32 os_minor_version = 0;
345 int32 os_bugfix_version = 0;
346 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
347 &os_minor_version,
348 &os_bugfix_version);
349 #endif
350 #if defined(OS_POSIX) && !defined(OS_MACOSX)
351 // Should work on any Posix system.
352 struct utsname unixinfo;
353 uname(&unixinfo);
354
355 std::string cputype;
356 // special case for biarch systems
357 if (strcmp(unixinfo.machine, "x86_64") == 0 &&
358 sizeof(void*) == sizeof(int32)) {
359 cputype.assign("i686 (x86_64)");
360 } else {
361 cputype.assign(unixinfo.machine);
362 }
363 #endif
364
365 StringAppendF(
366 &os_cpu,
367 #if defined(OS_WIN)
368 "Windows NT %d.%d",
369 os_major_version,
370 os_minor_version
371 #elif defined(OS_MACOSX)
372 "Intel Mac OS X %d_%d_%d",
373 os_major_version,
374 os_minor_version,
375 os_bugfix_version
376 #elif defined(OS_CHROMEOS)
377 "CrOS %s %d.%d.%d",
378 cputype.c_str(), // e.g. i686
379 os_major_version,
380 os_minor_version,
381 os_bugfix_version
382 #else
383 "%s %s",
384 unixinfo.sysname, // e.g. Linux
385 cputype.c_str() // e.g. i686
386 #endif
387 );
388
389 return os_cpu;
390 }
391
392 // Construct the User-Agent header, filling in |result|.
393 // The other parameters are workarounds for broken websites:
394 // - If mimic_windows is true, produce a fake Windows Chrome string.
395 void BuildUserAgent(bool mimic_windows, std::string* result) {
396 const char kUserAgentPlatform[] =
397 #if defined(OS_WIN)
398 "Windows";
399 #elif defined(OS_MACOSX)
400 "Macintosh";
401 #elif defined(USE_X11)
402 "X11"; // strange, but that's what Firefox uses
403 #else
404 "?";
405 #endif
406
407 const char kUserAgentSecurity = 'U'; // "US" strength encryption
408
409 // TODO(port): figure out correct locale
410 const char kUserAgentLocale[] = "en-US";
411
412 // Get the product name and version, and replace Safari's Version/X string
413 // with it. This is done to expose our product name in a manner that is
414 // maximally compatible with Safari, we hope!!
415 std::string product = GetProductVersion();
416
417 // Derived from Safari's UA string.
418 StringAppendF(
419 result,
420 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d"
421 " (KHTML, like Gecko) %s Safari/%d.%d",
422 mimic_windows ? "Windows" : kUserAgentPlatform,
423 kUserAgentSecurity,
424 ((mimic_windows ? "Windows " : "") + BuildOSCpuInfo()).c_str(),
425 kUserAgentLocale,
426 WEBKIT_VERSION_MAJOR,
427 WEBKIT_VERSION_MINOR,
428 product.c_str(),
429 WEBKIT_VERSION_MAJOR,
430 WEBKIT_VERSION_MINOR
431 );
432 }
433
434 void SetUserAgentToDefault() { 340 void SetUserAgentToDefault() {
435 BuildUserAgent(false, &g_user_agent->user_agent); 341 BuildUserAgent(false, &g_user_agent->user_agent);
436 } 342 }
437 343
438 } // namespace 344 } // namespace
439 345
440 void SetUserAgent(const std::string& new_user_agent) { 346 void SetUserAgent(const std::string& new_user_agent) {
441 // If you combine this with the previous line, the function only works the 347 // If you combine this with the previous line, the function only works the
442 // first time. 348 // first time.
443 DCHECK(!g_user_agent->user_agent_requested) << 349 DCHECK(!g_user_agent->user_agent_requested) <<
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 405
500 bool IsMediaCacheEnabled() { 406 bool IsMediaCacheEnabled() {
501 return g_enable_media_cache; 407 return g_enable_media_cache;
502 } 408 }
503 409
504 void SetMediaCacheEnabled(bool enabled) { 410 void SetMediaCacheEnabled(bool enabled) {
505 g_enable_media_cache = enabled; 411 g_enable_media_cache = enabled;
506 } 412 }
507 413
508 } // namespace webkit_glue 414 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/user_agent.cc ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698