OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 337 } |
338 | 338 |
339 namespace { | 339 namespace { |
340 | 340 |
341 class UserAgentState { | 341 class UserAgentState { |
342 public: | 342 public: |
343 UserAgentState(); | 343 UserAgentState(); |
344 ~UserAgentState(); | 344 ~UserAgentState(); |
345 | 345 |
346 void Set(const std::string& user_agent, bool overriding); | 346 void Set(const std::string& user_agent, bool overriding); |
| 347 void Reset(const std::string& user_agent, bool overriding); |
347 const std::string& Get(const GURL& url) const; | 348 const std::string& Get(const GURL& url) const; |
348 | 349 |
349 private: | 350 private: |
350 mutable std::string user_agent_; | 351 mutable std::string user_agent_; |
351 // The UA string when we're pretending to be Mac Safari. | 352 // The UA string when we're pretending to be Mac Safari. |
352 mutable std::string mimic_mac_safari_user_agent_; | 353 mutable std::string mimic_mac_safari_user_agent_; |
353 | 354 |
354 mutable bool user_agent_requested_; | 355 mutable bool user_agent_requested_; |
355 bool user_agent_is_overridden_; | 356 bool user_agent_is_overridden_; |
356 | 357 |
(...skipping 11 matching lines...) Expand all Loading... |
368 } | 369 } |
369 | 370 |
370 void UserAgentState::Set(const std::string& user_agent, bool overriding) { | 371 void UserAgentState::Set(const std::string& user_agent, bool overriding) { |
371 base::AutoLock auto_lock(lock_); | 372 base::AutoLock auto_lock(lock_); |
372 if (user_agent == user_agent_) { | 373 if (user_agent == user_agent_) { |
373 // We allow the user agent to be set multiple times as long as it | 374 // We allow the user agent to be set multiple times as long as it |
374 // is set to the same value, in order to simplify unit testing | 375 // is set to the same value, in order to simplify unit testing |
375 // given g_user_agent is a global. | 376 // given g_user_agent is a global. |
376 return; | 377 return; |
377 } | 378 } |
378 DCHECK(!user_agent.empty()); | |
379 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " | 379 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " |
380 "already requested it can result in unexpected behavior."; | 380 "already requested it can result in unexpected behavior."; |
| 381 lock_.Release(); |
| 382 UserAgentState::Reset(user_agent, overriding); |
| 383 lock_.Acquire(); |
| 384 } |
| 385 |
| 386 void UserAgentState::Reset(const std::string& user_agent, bool overriding) { |
| 387 base::AutoLock auto_lock(lock_); |
| 388 DCHECK(!user_agent.empty()); |
381 user_agent_is_overridden_ = overriding; | 389 user_agent_is_overridden_ = overriding; |
382 user_agent_ = user_agent; | 390 user_agent_ = user_agent; |
383 } | 391 } |
384 | 392 |
385 const std::string& UserAgentState::Get(const GURL& url) const { | 393 const std::string& UserAgentState::Get(const GURL& url) const { |
386 base::AutoLock auto_lock(lock_); | 394 base::AutoLock auto_lock(lock_); |
387 user_agent_requested_ = true; | 395 user_agent_requested_ = true; |
388 | 396 |
389 DCHECK(!user_agent_.empty()); | 397 DCHECK(!user_agent_.empty()); |
390 | 398 |
(...skipping 19 matching lines...) Expand all Loading... |
410 } | 418 } |
411 | 419 |
412 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); | 420 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); |
413 | 421 |
414 } // namespace | 422 } // namespace |
415 | 423 |
416 void SetUserAgent(const std::string& user_agent, bool overriding) { | 424 void SetUserAgent(const std::string& user_agent, bool overriding) { |
417 g_user_agent.Get().Set(user_agent, overriding); | 425 g_user_agent.Get().Set(user_agent, overriding); |
418 } | 426 } |
419 | 427 |
| 428 void ResetUserAgent(const std::string& user_agent, bool overriding) { |
| 429 g_user_agent.Get().Reset(user_agent, overriding); |
| 430 } |
| 431 |
420 const std::string& GetUserAgent(const GURL& url) { | 432 const std::string& GetUserAgent(const GURL& url) { |
421 return g_user_agent.Get().Get(url); | 433 return g_user_agent.Get().Get(url); |
422 } | 434 } |
423 | 435 |
424 void SetForcefullyTerminatePluginProcess(bool value) { | 436 void SetForcefullyTerminatePluginProcess(bool value) { |
425 g_forcefully_terminate_plugin_process = value; | 437 g_forcefully_terminate_plugin_process = value; |
426 } | 438 } |
427 | 439 |
428 bool ShouldForcefullyTerminatePluginProcess() { | 440 bool ShouldForcefullyTerminatePluginProcess() { |
429 return g_forcefully_terminate_plugin_process; | 441 return g_forcefully_terminate_plugin_process; |
430 } | 442 } |
431 | 443 |
432 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { | 444 WebCanvas* ToWebCanvas(skia::PlatformCanvas* canvas) { |
433 #if WEBKIT_USING_SKIA | 445 #if WEBKIT_USING_SKIA |
434 return canvas; | 446 return canvas; |
435 #elif WEBKIT_USING_CG | 447 #elif WEBKIT_USING_CG |
436 return skia::GetBitmapContext(skia::GetTopDevice(*canvas)); | 448 return skia::GetBitmapContext(skia::GetTopDevice(*canvas)); |
437 #else | 449 #else |
438 NOTIMPLEMENTED(); | 450 NOTIMPLEMENTED(); |
439 return NULL; | 451 return NULL; |
440 #endif | 452 #endif |
441 } | 453 } |
442 | 454 |
443 int GetGlyphPageCount() { | 455 int GetGlyphPageCount() { |
444 return WebGlyphCache::pageCount(); | 456 return WebGlyphCache::pageCount(); |
445 } | 457 } |
446 | 458 |
447 } // namespace webkit_glue | 459 } // namespace webkit_glue |
OLD | NEW |