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 "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 Loading... |
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 | |
48 using WebKit::WebCanvas; | 47 using WebKit::WebCanvas; |
49 using WebKit::WebData; | 48 using WebKit::WebData; |
50 using WebKit::WebElement; | 49 using WebKit::WebElement; |
51 using WebKit::WebFrame; | 50 using WebKit::WebFrame; |
52 using WebKit::WebGlyphCache; | 51 using WebKit::WebGlyphCache; |
53 using WebKit::WebHistoryItem; | 52 using WebKit::WebHistoryItem; |
54 using WebKit::WebImage; | 53 using WebKit::WebImage; |
55 using WebKit::WebSize; | 54 using WebKit::WebSize; |
56 using WebKit::WebString; | 55 using WebKit::WebString; |
57 using WebKit::WebVector; | 56 using WebKit::WebVector; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 305 } |
307 | 306 |
308 FilePath WebStringToFilePath(const WebString& str) { | 307 FilePath WebStringToFilePath(const WebString& str) { |
309 return FilePath(WebStringToFilePathString(str)); | 308 return FilePath(WebStringToFilePathString(str)); |
310 } | 309 } |
311 | 310 |
312 WebString FilePathToWebString(const FilePath& file_path) { | 311 WebString FilePathToWebString(const FilePath& file_path) { |
313 return FilePathStringToWebString(file_path.value()); | 312 return FilePathStringToWebString(file_path.value()); |
314 } | 313 } |
315 | 314 |
316 std::string GetWebKitVersion() { | |
317 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); | |
318 } | |
319 | |
320 namespace { | 315 namespace { |
321 | 316 |
322 struct UserAgentState { | 317 struct UserAgentState { |
323 UserAgentState() | 318 UserAgentState() |
324 : user_agent_requested(false), | 319 : user_agent_requested(false), |
325 user_agent_is_overridden(false) { | 320 user_agent_is_overridden(false) { |
326 } | 321 } |
327 | 322 |
328 std::string user_agent; | 323 std::string user_agent; |
329 | 324 |
330 // The UA string when we're pretending to be Windows Chrome. | 325 // The UA string when we're pretending to be Windows Chrome. |
331 std::string mimic_windows_user_agent; | 326 std::string mimic_windows_user_agent; |
332 | 327 |
333 bool user_agent_requested; | 328 bool user_agent_requested; |
334 bool user_agent_is_overridden; | 329 bool user_agent_is_overridden; |
335 }; | 330 }; |
336 | 331 |
337 Singleton<UserAgentState> g_user_agent; | 332 Singleton<UserAgentState> g_user_agent; |
338 | 333 |
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() { | 334 void SetUserAgentToDefault() { |
435 BuildUserAgent(false, &g_user_agent->user_agent); | 335 BuildUserAgent(false, &g_user_agent->user_agent); |
436 } | 336 } |
437 | 337 |
438 } // namespace | 338 } // namespace |
439 | 339 |
440 void SetUserAgent(const std::string& new_user_agent) { | 340 void SetUserAgent(const std::string& new_user_agent) { |
441 // If you combine this with the previous line, the function only works the | 341 // If you combine this with the previous line, the function only works the |
442 // first time. | 342 // first time. |
443 DCHECK(!g_user_agent->user_agent_requested) << | 343 DCHECK(!g_user_agent->user_agent_requested) << |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 399 |
500 bool IsMediaCacheEnabled() { | 400 bool IsMediaCacheEnabled() { |
501 return g_enable_media_cache; | 401 return g_enable_media_cache; |
502 } | 402 } |
503 | 403 |
504 void SetMediaCacheEnabled(bool enabled) { | 404 void SetMediaCacheEnabled(bool enabled) { |
505 g_enable_media_cache = enabled; | 405 g_enable_media_cache = enabled; |
506 } | 406 } |
507 | 407 |
508 } // namespace webkit_glue | 408 } // namespace webkit_glue |
OLD | NEW |