OLD | NEW |
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 17 matching lines...) Expand all Loading... |
28 #include "RenderTreeAsText.h" | 28 #include "RenderTreeAsText.h" |
29 #include "RenderView.h" | 29 #include "RenderView.h" |
30 #include "ScriptController.h" | 30 #include "ScriptController.h" |
31 #include "SharedBuffer.h" | 31 #include "SharedBuffer.h" |
32 MSVC_POP_WARNING(); | 32 MSVC_POP_WARNING(); |
33 | 33 |
34 #undef LOG | 34 #undef LOG |
35 #include "webkit/glue/webkit_glue.h" | 35 #include "webkit/glue/webkit_glue.h" |
36 | 36 |
37 #include "base/file_version_info.h" | 37 #include "base/file_version_info.h" |
| 38 #include "base/singleton.h" |
38 #include "base/string_util.h" | 39 #include "base/string_util.h" |
39 #include "skia/include/SkBitmap.h" | 40 #include "skia/include/SkBitmap.h" |
40 #include "webkit/glue/event_conversion.h" | 41 #include "webkit/glue/event_conversion.h" |
41 #include "webkit/glue/glue_util.h" | 42 #include "webkit/glue/glue_util.h" |
42 #include "webkit/glue/weburlrequest_impl.h" | 43 #include "webkit/glue/weburlrequest_impl.h" |
43 #include "webkit/glue/webframe_impl.h" | 44 #include "webkit/glue/webframe_impl.h" |
44 #include "webkit/glue/webview_impl.h" | 45 #include "webkit/glue/webview_impl.h" |
45 | 46 |
46 //------------------------------------------------------------------------------ | 47 //------------------------------------------------------------------------------ |
47 // webkit_glue impl: | 48 // webkit_glue impl: |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return; | 310 return; |
310 delegate->OnNavStateChanged(webview); | 311 delegate->OnNavStateChanged(webview); |
311 } | 312 } |
312 | 313 |
313 std::string GetWebKitVersion() { | 314 std::string GetWebKitVersion() { |
314 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); | 315 return StringPrintf("%d.%d", WEBKIT_VERSION_MAJOR, WEBKIT_VERSION_MINOR); |
315 } | 316 } |
316 | 317 |
317 namespace { | 318 namespace { |
318 | 319 |
319 const std::string* user_agent = NULL; | 320 struct UserAgentState { |
320 bool user_agent_requested = false; | 321 UserAgentState() |
321 bool user_agent_is_overridden = false; | 322 : user_agent_requested(false), |
| 323 user_agent_is_overridden(false) { |
| 324 } |
| 325 |
| 326 std::string user_agent; |
| 327 std::string mimic_safari_user_agent; |
| 328 bool user_agent_requested; |
| 329 bool user_agent_is_overridden; |
| 330 }; |
| 331 |
| 332 Singleton<UserAgentState> g_user_agent; |
322 | 333 |
323 void BuildUserAgent(bool mimic_safari, std::string* result) { | 334 void BuildUserAgent(bool mimic_safari, std::string* result) { |
324 #if defined(OS_WIN) || defined(OS_MACOSX) | 335 #if defined(OS_WIN) || defined(OS_MACOSX) |
325 int32 os_major_version = 0; | 336 int32 os_major_version = 0; |
326 int32 os_minor_version = 0; | 337 int32 os_minor_version = 0; |
327 int32 os_bugfix_version = 0; | 338 int32 os_bugfix_version = 0; |
328 #if defined(OS_WIN) | 339 #if defined(OS_WIN) |
329 OSVERSIONINFO info = {0}; | 340 OSVERSIONINFO info = {0}; |
330 info.dwOSVersionInfoSize = sizeof(info); | 341 info.dwOSVersionInfoSize = sizeof(info); |
331 GetVersionEx(&info); | 342 GetVersionEx(&info); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 result, | 396 result, |
386 "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/525.13 " | 397 "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/525.13 " |
387 "(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13"); | 398 "(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13"); |
388 #else | 399 #else |
389 // TODO(port): we need something like FileVersionInfo for our UA string. | 400 // TODO(port): we need something like FileVersionInfo for our UA string. |
390 NOTIMPLEMENTED(); | 401 NOTIMPLEMENTED(); |
391 #endif | 402 #endif |
392 } | 403 } |
393 | 404 |
394 void SetUserAgentToDefault() { | 405 void SetUserAgentToDefault() { |
395 static std::string default_user_agent; | 406 BuildUserAgent(false, &g_user_agent->user_agent); |
396 BuildUserAgent(false, &default_user_agent); | |
397 user_agent = &default_user_agent; | |
398 } | 407 } |
399 | 408 |
400 } // namespace | 409 } // namespace |
401 | 410 |
402 void SetUserAgent(const std::string& new_user_agent) { | 411 void SetUserAgent(const std::string& new_user_agent) { |
403 DCHECK(!user_agent_requested) << "Setting the user agent after someone has " | 412 // If you combine this with the previous line, the function only works the |
| 413 // first time. |
| 414 DCHECK(!g_user_agent->user_agent_requested) << |
| 415 "Setting the user agent after someone has " |
404 "already requested it can result in unexpected behavior."; | 416 "already requested it can result in unexpected behavior."; |
405 static std::string overridden_user_agent; | 417 g_user_agent->user_agent_is_overridden = true; |
406 overridden_user_agent = new_user_agent; // If you combine this with the | 418 g_user_agent->user_agent = new_user_agent; |
407 // previous line, the function only | |
408 // works the first time. | |
409 user_agent_is_overridden = true; | |
410 user_agent = &overridden_user_agent; | |
411 } | 419 } |
412 | 420 |
413 const std::string& GetUserAgent(const GURL& url) { | 421 const std::string& GetUserAgent(const GURL& url) { |
414 if (!user_agent) | 422 if (g_user_agent->user_agent.empty()) |
415 SetUserAgentToDefault(); | 423 SetUserAgentToDefault(); |
416 user_agent_requested = true; | 424 g_user_agent->user_agent_requested = true; |
417 if (!user_agent_is_overridden) { | 425 if (!g_user_agent->user_agent_is_overridden) { |
418 static std::string mimic_safari_user_agent; | |
419 // For hotmail, we need to spoof as Safari (bug 4111). | 426 // For hotmail, we need to spoof as Safari (bug 4111). |
420 if (MatchPattern(url.host(), "*.mail.live.com")) { | 427 if (MatchPattern(url.host(), "*.mail.live.com")) { |
421 if (mimic_safari_user_agent.empty()) | 428 if (g_user_agent->mimic_safari_user_agent.empty()) |
422 BuildUserAgent(true, &mimic_safari_user_agent); | 429 BuildUserAgent(true, &g_user_agent->mimic_safari_user_agent); |
423 return mimic_safari_user_agent; | 430 return g_user_agent->mimic_safari_user_agent; |
424 } | 431 } |
425 } | 432 } |
426 return *user_agent; | 433 return g_user_agent->user_agent; |
427 } | 434 } |
428 | 435 |
429 void NotifyJSOutOfMemory(WebCore::Frame* frame) { | 436 void NotifyJSOutOfMemory(WebCore::Frame* frame) { |
430 if (!frame) | 437 if (!frame) |
431 return; | 438 return; |
432 | 439 |
433 // Dispatch to the delegate of the view that owns the frame. | 440 // Dispatch to the delegate of the view that owns the frame. |
434 WebFrame* webframe = WebFrameImpl::FromFrame(frame); | 441 WebFrame* webframe = WebFrameImpl::FromFrame(frame); |
435 WebView* webview = webframe->GetView(); | 442 WebView* webview = webframe->GetView(); |
436 if (!webview) | 443 if (!webview) |
(...skipping 11 matching lines...) Expand all Loading... |
448 } | 455 } |
449 | 456 |
450 g_forcefully_terminate_plugin_process = value; | 457 g_forcefully_terminate_plugin_process = value; |
451 } | 458 } |
452 | 459 |
453 bool ShouldForcefullyTerminatePluginProcess() { | 460 bool ShouldForcefullyTerminatePluginProcess() { |
454 return g_forcefully_terminate_plugin_process; | 461 return g_forcefully_terminate_plugin_process; |
455 } | 462 } |
456 | 463 |
457 } // namespace webkit_glue | 464 } // namespace webkit_glue |
OLD | NEW |