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

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

Issue 8002003: Revert "Remove webkit_glue::BuildUserAgent(), change the contract in webkit_glue" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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/webkit_glue.h ('k') | webkit/support/webkit_support.cc » ('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) 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 336 }
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);
347 const std::string& Get(const GURL& url) const; 347 const std::string& Get(const GURL& url) const;
348 348
349 private: 349 private:
350 mutable std::string user_agent_; 350 mutable std::string user_agent_;
351 // The UA string when we're pretending to be Windows Chrome.
352 mutable std::string mimic_windows_user_agent_;
351 // The UA string when we're pretending to be Mac Safari. 353 // The UA string when we're pretending to be Mac Safari.
352 mutable std::string mimic_mac_safari_user_agent_; 354 mutable std::string mimic_mac_safari_user_agent_;
353 355
354 mutable bool user_agent_requested_; 356 mutable bool user_agent_requested_;
355 bool user_agent_is_overridden_; 357 bool user_agent_is_overridden_;
356 358
357 // This object can be accessed from multiple threads, so use a lock around 359 // This object can be accessed from multiple threads, so use a lock around
358 // accesses to the data members. 360 // accesses to the data members.
359 mutable base::Lock lock_; 361 mutable base::Lock lock_;
360 }; 362 };
361 363
362 UserAgentState::UserAgentState() 364 UserAgentState::UserAgentState()
363 : user_agent_requested_(false), 365 : user_agent_requested_(false),
364 user_agent_is_overridden_(false) { 366 user_agent_is_overridden_(false) {
365 } 367 }
366 368
367 UserAgentState::~UserAgentState() { 369 UserAgentState::~UserAgentState() {
368 } 370 }
369 371
370 void UserAgentState::Set(const std::string& user_agent, bool overriding) { 372 void UserAgentState::Set(const std::string& user_agent) {
371 base::AutoLock auto_lock(lock_); 373 base::AutoLock auto_lock(lock_);
372 if (user_agent == user_agent_) {
373 // 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 // given g_user_agent is a global.
376 return;
377 }
378 DCHECK(!user_agent.empty());
379 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " 374 DCHECK(!user_agent_requested_) << "Setting the user agent after someone has "
380 "already requested it can result in unexpected behavior."; 375 "already requested it can result in unexpected behavior.";
381 user_agent_is_overridden_ = overriding; 376 user_agent_is_overridden_ = true;
382 user_agent_ = user_agent; 377 user_agent_ = user_agent;
383 } 378 }
384 379
385 const std::string& UserAgentState::Get(const GURL& url) const { 380 const std::string& UserAgentState::Get(const GURL& url) const {
386 base::AutoLock auto_lock(lock_); 381 base::AutoLock auto_lock(lock_);
387 user_agent_requested_ = true; 382 user_agent_requested_ = true;
388 383
389 DCHECK(!user_agent_.empty()); 384 if (user_agent_.empty())
385 user_agent_ = BuildUserAgent(false);
390 386
391 // Workarounds for sites that use misguided UA sniffing. 387 // Workarounds for sites that use misguided UA sniffing.
392 if (!user_agent_is_overridden_) { 388 if (!user_agent_is_overridden_) {
389 #if defined(OS_POSIX) && !defined(OS_MACOSX)
390 if (MatchPattern(url.host(), "*.mail.yahoo.com")) {
391 // mail.yahoo.com is ok with Windows Chrome but not Linux Chrome.
392 // http://bugs.chromium.org/11136
393 // TODO(evanm): remove this if Yahoo fixes their sniffing.
394 if (mimic_windows_user_agent_.empty())
395 mimic_windows_user_agent_ = BuildUserAgent(true);
396 return mimic_windows_user_agent_;
397 }
398 #endif
393 #if defined(OS_MACOSX) 399 #if defined(OS_MACOSX)
394 if (url.host() == "www.microsoft.com" && 400 if (url.host() == "www.microsoft.com" &&
395 StartsWithASCII(url.path(), "/getsilverlight", false)) { 401 StartsWithASCII(url.path(), "/getsilverlight", false)) {
396 // The landing page for updating Silverlight gives a confusing experience 402 // The landing page for updating Silverlight gives a confusing experience
397 // in browsers that Silverlight doesn't officially support; spoof as 403 // in browsers that Silverlight doesn't officially support; spoof as
398 // Safari to reduce the chance that users won't complete updates. 404 // Safari to reduce the chance that users won't complete updates.
399 // Should be removed if the sniffing is removed: http://crbug.com/88211 405 // Should be removed if the sniffing is removed: http://crbug.com/88211
400 if (mimic_mac_safari_user_agent_.empty()) { 406 if (mimic_mac_safari_user_agent_.empty()) {
401 mimic_mac_safari_user_agent_ = 407 mimic_mac_safari_user_agent_ =
402 BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); 408 BuildUserAgentHelper(false, "Version/5.0.4 Safari/533.20.27");
403 } 409 }
404 return mimic_mac_safari_user_agent_; 410 return mimic_mac_safari_user_agent_;
405 } 411 }
406 #endif 412 #endif
407 } 413 }
408 414
409 return user_agent_; 415 return user_agent_;
410 } 416 }
411 417
412 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); 418 base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED);
413 419
414 } // namespace 420 } // namespace
415 421
416 void SetUserAgent(const std::string& user_agent, bool overriding) { 422 void SetUserAgent(const std::string& new_user_agent) {
417 g_user_agent.Get().Set(user_agent, overriding); 423 g_user_agent.Get().Set(new_user_agent);
418 } 424 }
419 425
420 const std::string& GetUserAgent(const GURL& url) { 426 const std::string& GetUserAgent(const GURL& url) {
421 return g_user_agent.Get().Get(url); 427 return g_user_agent.Get().Get(url);
422 } 428 }
423 429
424 void SetForcefullyTerminatePluginProcess(bool value) { 430 void SetForcefullyTerminatePluginProcess(bool value) {
425 g_forcefully_terminate_plugin_process = value; 431 g_forcefully_terminate_plugin_process = value;
426 } 432 }
427 433
(...skipping 10 matching lines...) Expand all
438 NOTIMPLEMENTED(); 444 NOTIMPLEMENTED();
439 return NULL; 445 return NULL;
440 #endif 446 #endif
441 } 447 }
442 448
443 int GetGlyphPageCount() { 449 int GetGlyphPageCount() {
444 return WebGlyphCache::pageCount(); 450 return WebGlyphCache::pageCount();
445 } 451 }
446 452
447 } // namespace webkit_glue 453 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/webkit_glue.h ('k') | webkit/support/webkit_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698