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

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

Issue 8296011: Make setting the user agent work with the zygote on linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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
« webkit/glue/webkit_glue.h ('K') | « webkit/glue/webkit_glue.h ('k') | no next file » | 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) 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
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
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
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
OLDNEW
« webkit/glue/webkit_glue.h ('K') | « webkit/glue/webkit_glue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698