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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 556095: Changes to support new cookie policy.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/net/chrome_url_request_context.h" 5 #include "chrome/browser/net/chrome_url_request_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/extensions/extensions_service.h" 11 #include "chrome/browser/extensions/extensions_service.h"
12 #include "chrome/browser/extensions/user_script_master.h" 12 #include "chrome/browser/extensions/user_script_master.h"
13 #include "chrome/browser/io_thread.h" 13 #include "chrome/browser/io_thread.h"
14 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" 14 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
15 #include "chrome/browser/net/dns_global.h" 15 #include "chrome/browser/net/dns_global.h"
16 #include "chrome/browser/privacy_blacklist/blacklist.h" 16 #include "chrome/browser/privacy_blacklist/blacklist.h"
17 #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" 17 #include "chrome/browser/privacy_blacklist/blacklist_request_info.h"
18 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/notification_service.h" 22 #include "chrome/common/notification_service.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "net/base/static_cookie_policy.h"
25 #include "net/ftp/ftp_network_layer.h" 26 #include "net/ftp/ftp_network_layer.h"
26 #include "net/http/http_cache.h" 27 #include "net/http/http_cache.h"
27 #include "net/http/http_network_layer.h" 28 #include "net/http/http_network_layer.h"
28 #include "net/http/http_util.h" 29 #include "net/http/http_util.h"
29 #include "net/proxy/proxy_config_service_fixed.h" 30 #include "net/proxy/proxy_config_service_fixed.h"
30 #include "net/proxy/proxy_script_fetcher.h" 31 #include "net/proxy/proxy_script_fetcher.h"
31 #include "net/proxy/proxy_service.h" 32 #include "net/proxy/proxy_service.h"
32 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
33 #include "webkit/glue/webkit_glue.h" 34 #include "webkit/glue/webkit_glue.h"
34 35
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 DCHECK(pref_name_in && prefs); 538 DCHECK(pref_name_in && prefs);
538 if (*pref_name_in == prefs::kAcceptLanguages) { 539 if (*pref_name_in == prefs::kAcceptLanguages) {
539 std::string accept_language = 540 std::string accept_language =
540 WideToASCII(prefs->GetString(prefs::kAcceptLanguages)); 541 WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
541 ChromeThread::PostTask( 542 ChromeThread::PostTask(
542 ChromeThread::IO, FROM_HERE, 543 ChromeThread::IO, FROM_HERE,
543 NewRunnableMethod( 544 NewRunnableMethod(
544 this, 545 this,
545 &ChromeURLRequestContextGetter::OnAcceptLanguageChange, 546 &ChromeURLRequestContextGetter::OnAcceptLanguageChange,
546 accept_language)); 547 accept_language));
547 } else if (*pref_name_in == prefs::kCookieBehavior) {
548 net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
549 prefs_->GetInteger(prefs::kCookieBehavior));
550 ChromeThread::PostTask(
551 ChromeThread::IO, FROM_HERE,
552 NewRunnableMethod(
553 this,
554 &ChromeURLRequestContextGetter::OnCookiePolicyChange,
555 policy_type));
556 } else if (*pref_name_in == prefs::kDefaultCharset) { 548 } else if (*pref_name_in == prefs::kDefaultCharset) {
557 std::string default_charset = 549 std::string default_charset =
558 WideToASCII(prefs->GetString(prefs::kDefaultCharset)); 550 WideToASCII(prefs->GetString(prefs::kDefaultCharset));
559 ChromeThread::PostTask( 551 ChromeThread::PostTask(
560 ChromeThread::IO, FROM_HERE, 552 ChromeThread::IO, FROM_HERE,
561 NewRunnableMethod( 553 NewRunnableMethod(
562 this, 554 this,
563 &ChromeURLRequestContextGetter::OnDefaultCharsetChange, 555 &ChromeURLRequestContextGetter::OnDefaultCharsetChange,
564 default_charset)); 556 default_charset));
565 } 557 }
(...skipping 23 matching lines...) Expand all
589 disk_cache_path, 581 disk_cache_path,
590 cache_size, 582 cache_size,
591 off_the_record)); 583 off_the_record));
592 } 584 }
593 585
594 void ChromeURLRequestContextGetter::OnAcceptLanguageChange( 586 void ChromeURLRequestContextGetter::OnAcceptLanguageChange(
595 const std::string& accept_language) { 587 const std::string& accept_language) {
596 GetIOContext()->OnAcceptLanguageChange(accept_language); 588 GetIOContext()->OnAcceptLanguageChange(accept_language);
597 } 589 }
598 590
599 void ChromeURLRequestContextGetter::OnCookiePolicyChange(
600 net::CookiePolicy::Type type) {
601 GetIOContext()->OnCookiePolicyChange(type);
602 }
603
604 void ChromeURLRequestContextGetter::OnDefaultCharsetChange( 591 void ChromeURLRequestContextGetter::OnDefaultCharsetChange(
605 const std::string& default_charset) { 592 const std::string& default_charset) {
606 GetIOContext()->OnDefaultCharsetChange(default_charset); 593 GetIOContext()->OnDefaultCharsetChange(default_charset);
607 } 594 }
608 595
609 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper( 596 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper(
610 base::WaitableEvent* completion, 597 base::WaitableEvent* completion,
611 net::CookieStore** result) { 598 net::CookieStore** result) {
612 // Note that CookieStore is refcounted, yet we do not add a reference. 599 // Note that CookieStore is refcounted, yet we do not add a reference.
613 *result = GetURLRequestContext()->cookie_store(); 600 *result = GetURLRequestContext()->cookie_store();
614 completion->Signal(); 601 completion->Signal();
615 } 602 }
616 603
617 // ---------------------------------------------------------------------------- 604 // ----------------------------------------------------------------------------
618 // ChromeURLRequestContext 605 // ChromeURLRequestContext
619 // ---------------------------------------------------------------------------- 606 // ----------------------------------------------------------------------------
620 607
621 ChromeURLRequestContext::ChromeURLRequestContext() { 608 ChromeURLRequestContext::ChromeURLRequestContext() {
622 CheckCurrentlyOnIOThread(); 609 CheckCurrentlyOnIOThread();
610
611 cookie_policy_ = this; // We implement CookiePolicy
612
623 url_request_tracker()->SetGraveyardFilter( 613 url_request_tracker()->SetGraveyardFilter(
624 &ChromeURLRequestContext::ShouldTrackRequest); 614 &ChromeURLRequestContext::ShouldTrackRequest);
625 } 615 }
626 616
627 ChromeURLRequestContext::~ChromeURLRequestContext() { 617 ChromeURLRequestContext::~ChromeURLRequestContext() {
628 CheckCurrentlyOnIOThread(); 618 CheckCurrentlyOnIOThread();
619
629 if (appcache_service_.get() && appcache_service_->request_context() == this) 620 if (appcache_service_.get() && appcache_service_->request_context() == this)
630 appcache_service_->set_request_context(NULL); 621 appcache_service_->set_request_context(NULL);
631 622
632 if (proxy_service_ && 623 if (proxy_service_ &&
633 proxy_service_->GetProxyScriptFetcher() && 624 proxy_service_->GetProxyScriptFetcher() &&
634 proxy_service_->GetProxyScriptFetcher()->GetRequestContext() == this) { 625 proxy_service_->GetProxyScriptFetcher()->GetRequestContext() == this) {
635 // Remove the ProxyScriptFetcher's weak reference to this context. 626 // Remove the ProxyScriptFetcher's weak reference to this context.
636 proxy_service_->SetProxyScriptFetcher(NULL); 627 proxy_service_->SetProxyScriptFetcher(NULL);
637 } 628 }
638 629
639 #if defined(OS_LINUX) 630 #if defined(OS_LINUX)
640 if (this == net::GetURLRequestContextForOCSP()) { 631 if (this == net::GetURLRequestContextForOCSP()) {
641 // We are releasing the URLRequestContext used by OCSP handlers. 632 // We are releasing the URLRequestContext used by OCSP handlers.
642 net::SetURLRequestContextForOCSP(NULL); 633 net::SetURLRequestContextForOCSP(NULL);
643 } 634 }
644 #endif 635 #endif
645 636
646 NotificationService::current()->Notify( 637 NotificationService::current()->Notify(
647 NotificationType::URL_REQUEST_CONTEXT_RELEASED, 638 NotificationType::URL_REQUEST_CONTEXT_RELEASED,
648 Source<URLRequestContext>(this), 639 Source<URLRequestContext>(this),
649 NotificationService::NoDetails()); 640 NotificationService::NoDetails());
650 641
651 delete ftp_transaction_factory_; 642 delete ftp_transaction_factory_;
652 delete http_transaction_factory_; 643 delete http_transaction_factory_;
644
645 cookie_policy_ = NULL;
653 } 646 }
654 647
655 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) { 648 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
656 ExtensionInfoMap::iterator iter = extension_info_.find(id); 649 ExtensionInfoMap::iterator iter = extension_info_.find(id);
657 if (iter != extension_info_.end()) 650 if (iter != extension_info_.end())
658 return iter->second->path; 651 return iter->second->path;
659 else 652 else
660 return FilePath(); 653 return FilePath();
661 } 654 }
662 655
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 744
752 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) { 745 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
753 CheckCurrentlyOnIOThread(); 746 CheckCurrentlyOnIOThread();
754 if (is_off_the_record_) 747 if (is_off_the_record_)
755 return; 748 return;
756 ExtensionInfoMap::iterator iter = extension_info_.find(id); 749 ExtensionInfoMap::iterator iter = extension_info_.find(id);
757 DCHECK(iter != extension_info_.end()); 750 DCHECK(iter != extension_info_.end());
758 extension_info_.erase(iter); 751 extension_info_.erase(iter);
759 } 752 }
760 753
754 bool ChromeURLRequestContext::AreCookiesEnabled() const {
755 ContentSetting setting =
756 host_content_settings_map_->GetDefaultContentSetting(
757 CONTENT_SETTINGS_TYPE_COOKIES);
758 return setting != CONTENT_SETTING_BLOCK;
759 }
760
761 bool ChromeURLRequestContext::CanGetCookies(const GURL& url,
762 const GURL& first_party) {
763 if (host_content_settings_map_->BlockThirdPartyCookies()) {
764 net::StaticCookiePolicy policy(
765 net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
766 if (!policy.CanGetCookies(url, first_party))
767 return false;
768 }
769
770 ContentSetting setting = host_content_settings_map_->GetContentSetting(
771 url.host(), CONTENT_SETTINGS_TYPE_COOKIES);
772 if (setting == CONTENT_SETTING_BLOCK)
773 return false;
774
775 // TODO(darin): Implement CONTENT_SETTING_ASK
776 return true;
777 }
778
779 bool ChromeURLRequestContext::CanSetCookie(const GURL& url,
780 const GURL& first_party) {
781 if (host_content_settings_map_->BlockThirdPartyCookies()) {
782 net::StaticCookiePolicy policy(
783 net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
784 if (!policy.CanSetCookie(url, first_party))
785 return false;
786 }
787
788 ContentSetting setting = host_content_settings_map_->GetContentSetting(
789 url.host(), CONTENT_SETTINGS_TYPE_COOKIES);
790 if (setting == CONTENT_SETTING_BLOCK)
791 return false;
792
793 // TODO(darin): Implement CONTENT_SETTING_ASK
794 return true;
795 }
796
761 ChromeURLRequestContext::ChromeURLRequestContext( 797 ChromeURLRequestContext::ChromeURLRequestContext(
762 ChromeURLRequestContext* other) { 798 ChromeURLRequestContext* other) {
763 CheckCurrentlyOnIOThread(); 799 CheckCurrentlyOnIOThread();
764 800
801 cookie_policy_ = this; // We implement CookiePolicy
802
765 // Set URLRequestContext members 803 // Set URLRequestContext members
766 host_resolver_ = other->host_resolver_; 804 host_resolver_ = other->host_resolver_;
767 proxy_service_ = other->proxy_service_; 805 proxy_service_ = other->proxy_service_;
768 ssl_config_service_ = other->ssl_config_service_; 806 ssl_config_service_ = other->ssl_config_service_;
769 http_transaction_factory_ = other->http_transaction_factory_; 807 http_transaction_factory_ = other->http_transaction_factory_;
770 ftp_transaction_factory_ = other->ftp_transaction_factory_; 808 ftp_transaction_factory_ = other->ftp_transaction_factory_;
771 cookie_store_ = other->cookie_store_; 809 cookie_store_ = other->cookie_store_;
772 cookie_policy_.set_type(other->cookie_policy_.type());
773 transport_security_state_ = other->transport_security_state_; 810 transport_security_state_ = other->transport_security_state_;
774 accept_language_ = other->accept_language_; 811 accept_language_ = other->accept_language_;
775 accept_charset_ = other->accept_charset_; 812 accept_charset_ = other->accept_charset_;
776 referrer_charset_ = other->referrer_charset_; 813 referrer_charset_ = other->referrer_charset_;
777 814
778 // Set ChromeURLRequestContext members 815 // Set ChromeURLRequestContext members
779 extension_info_ = other->extension_info_; 816 extension_info_ = other->extension_info_;
780 user_script_dir_path_ = other->user_script_dir_path_; 817 user_script_dir_path_ = other->user_script_dir_path_;
781 appcache_service_ = other->appcache_service_; 818 appcache_service_ = other->appcache_service_;
782 host_content_settings_map_ = other->host_content_settings_map_; 819 host_content_settings_map_ = other->host_content_settings_map_;
783 host_zoom_map_ = other->host_zoom_map_; 820 host_zoom_map_ = other->host_zoom_map_;
784 privacy_blacklist_ = other->privacy_blacklist_; 821 privacy_blacklist_ = other->privacy_blacklist_;
785 is_media_ = other->is_media_; 822 is_media_ = other->is_media_;
786 is_off_the_record_ = other->is_off_the_record_; 823 is_off_the_record_ = other->is_off_the_record_;
787 } 824 }
788 825
789 void ChromeURLRequestContext::OnAcceptLanguageChange( 826 void ChromeURLRequestContext::OnAcceptLanguageChange(
790 const std::string& accept_language) { 827 const std::string& accept_language) {
791 CheckCurrentlyOnIOThread(); 828 CheckCurrentlyOnIOThread();
792 accept_language_ = 829 accept_language_ =
793 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); 830 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language);
794 } 831 }
795 832
796 void ChromeURLRequestContext::OnCookiePolicyChange(
797 net::CookiePolicy::Type type) {
798 CheckCurrentlyOnIOThread();
799 cookie_policy_.set_type(type);
800 }
801
802 void ChromeURLRequestContext::OnDefaultCharsetChange( 833 void ChromeURLRequestContext::OnDefaultCharsetChange(
803 const std::string& default_charset) { 834 const std::string& default_charset) {
804 CheckCurrentlyOnIOThread(); 835 CheckCurrentlyOnIOThread();
805 referrer_charset_ = default_charset; 836 referrer_charset_ = default_charset;
806 accept_charset_ = 837 accept_charset_ =
807 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); 838 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
808 } 839 }
809 840
810 // static 841 // static
811 bool ChromeURLRequestContext::ShouldTrackRequest(const GURL& url) { 842 bool ChromeURLRequestContext::ShouldTrackRequest(const GURL& url) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // when download request is made through the context menu in a web page). 874 // when download request is made through the context menu in a web page).
844 // At the moment, it'll remain 'undeterministic' when a user 875 // At the moment, it'll remain 'undeterministic' when a user
845 // types a URL in the omnibar or click on a download link in a page. 876 // types a URL in the omnibar or click on a download link in a page.
846 // For the latter, we need a change on the webkit-side. 877 // For the latter, we need a change on the webkit-side.
847 // We initialize it to the default charset here and a user will 878 // We initialize it to the default charset here and a user will
848 // have an *arguably* better default charset for interpreting a raw 8bit 879 // have an *arguably* better default charset for interpreting a raw 8bit
849 // C-D header field. It means the native OS codepage fallback in 880 // C-D header field. It means the native OS codepage fallback in
850 // net_util::GetSuggestedFilename is unlikely to be taken. 881 // net_util::GetSuggestedFilename is unlikely to be taken.
851 referrer_charset_ = default_charset; 882 referrer_charset_ = default_charset;
852 883
853 cookie_policy_type_ = net::CookiePolicy::FromInt(
854 prefs->GetInteger(prefs::kCookieBehavior));
855
856 host_content_settings_map_ = profile->GetHostContentSettingsMap(); 884 host_content_settings_map_ = profile->GetHostContentSettingsMap();
857 885
858 host_zoom_map_ = profile->GetHostZoomMap(); 886 host_zoom_map_ = profile->GetHostZoomMap();
859 887
860 privacy_blacklist_ = profile->GetPrivacyBlacklist(); 888 privacy_blacklist_ = profile->GetPrivacyBlacklist();
861 889
862 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! 890 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
863 transport_security_state_ = profile->GetTransportSecurityState(); 891 transport_security_state_ = profile->GetTransportSecurityState();
864 892
865 if (profile->GetExtensionsService()) { 893 if (profile->GetExtensionsService()) {
(...skipping 25 matching lines...) Expand all
891 919
892 void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( 920 void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
893 ChromeURLRequestContext* context) { 921 ChromeURLRequestContext* context) {
894 // Apply all the parameters. NOTE: keep this in sync with 922 // Apply all the parameters. NOTE: keep this in sync with
895 // ChromeURLRequestContextFactory(Profile*). 923 // ChromeURLRequestContextFactory(Profile*).
896 context->set_is_media(is_media_); 924 context->set_is_media(is_media_);
897 context->set_is_off_the_record(is_off_the_record_); 925 context->set_is_off_the_record(is_off_the_record_);
898 context->set_accept_language(accept_language_); 926 context->set_accept_language(accept_language_);
899 context->set_accept_charset(accept_charset_); 927 context->set_accept_charset(accept_charset_);
900 context->set_referrer_charset(referrer_charset_); 928 context->set_referrer_charset(referrer_charset_);
901 context->set_cookie_policy_type(cookie_policy_type_);
902 context->set_extension_info(extension_info_); 929 context->set_extension_info(extension_info_);
903 context->set_user_script_dir_path(user_script_dir_path_); 930 context->set_user_script_dir_path(user_script_dir_path_);
904 context->set_host_content_settings_map(host_content_settings_map_); 931 context->set_host_content_settings_map(host_content_settings_map_);
905 context->set_host_zoom_map(host_zoom_map_); 932 context->set_host_zoom_map(host_zoom_map_);
906 context->set_privacy_blacklist(privacy_blacklist_); 933 context->set_privacy_blacklist(privacy_blacklist_);
907 context->set_transport_security_state( 934 context->set_transport_security_state(
908 transport_security_state_); 935 transport_security_state_);
909 context->set_ssl_config_service(ssl_config_service_); 936 context->set_ssl_config_service(ssl_config_service_);
910 } 937 }
911 938
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 988 }
962 989
963 if (command_line.HasSwitch(switches::kProxyBypassList)) { 990 if (command_line.HasSwitch(switches::kProxyBypassList)) {
964 proxy_config->ParseNoProxyList( 991 proxy_config->ParseNoProxyList(
965 WideToASCII(command_line.GetSwitchValue( 992 WideToASCII(command_line.GetSwitchValue(
966 switches::kProxyBypassList))); 993 switches::kProxyBypassList)));
967 } 994 }
968 995
969 return proxy_config; 996 return proxy_config;
970 } 997 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/net/cookie_policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698