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

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

Issue 371063: Integrate BlacklistManager with Profile. (Closed)
Patch Set: trybot fixes Created 11 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/privacy_blacklist/blacklist.h" 10 #include "chrome/browser/privacy_blacklist/blacklist.h"
11 #include "chrome/browser/chrome_thread.h" 11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/extensions/user_script_master.h" 13 #include "chrome/browser/extensions/user_script_master.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_manager.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "net/ftp/ftp_network_layer.h" 24 #include "net/ftp/ftp_network_layer.h"
24 #include "net/http/http_cache.h" 25 #include "net/http/http_cache.h"
25 #include "net/http/http_network_layer.h" 26 #include "net/http/http_network_layer.h"
26 #include "net/http/http_util.h" 27 #include "net/http/http_util.h"
27 #include "net/proxy/proxy_config_service_fixed.h" 28 #include "net/proxy/proxy_config_service_fixed.h"
28 #include "net/proxy/proxy_script_fetcher.h" 29 #include "net/proxy/proxy_script_fetcher.h"
29 #include "net/proxy/proxy_service.h" 30 #include "net/proxy/proxy_service.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 #include "webkit/glue/webkit_glue.h" 32 #include "webkit/glue/webkit_glue.h"
32 33
33 #if defined(OS_LINUX) 34 #if defined(OS_LINUX)
34 #include "net/ocsp/nss_ocsp.h" 35 #include "net/ocsp/nss_ocsp.h"
35 #endif 36 #endif
36 37
37 namespace { 38 namespace {
38 // TODO(eroman): The ChromeURLRequestContext's Blacklist* is shared with the
39 // Profile... This is a problem since the Profile dies before
40 // the IO thread, so we may end up accessing a deleted variable.
41 // http://crbug.com/26733.
42 39
43 // ---------------------------------------------------------------------------- 40 // ----------------------------------------------------------------------------
44 // Helper methods to check current thread 41 // Helper methods to check current thread
45 // ---------------------------------------------------------------------------- 42 // ----------------------------------------------------------------------------
46 43
47 void CheckCurrentlyOnIOThread() { 44 void CheckCurrentlyOnIOThread() {
48 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 45 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
49 } 46 }
50 47
51 void CheckCurrentlyOnMainThread() { 48 void CheckCurrentlyOnMainThread() {
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 677 }
681 678
682 bool ChromeURLRequestContext::InterceptCookie(const URLRequest* request, 679 bool ChromeURLRequestContext::InterceptCookie(const URLRequest* request,
683 std::string* cookie) { 680 std::string* cookie) {
684 const URLRequest::UserData* d = 681 const URLRequest::UserData* d =
685 request->GetUserData(&Blacklist::kRequestDataKey); 682 request->GetUserData(&Blacklist::kRequestDataKey);
686 if (d) { 683 if (d) {
687 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); 684 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
688 if (match->attributes() & Blacklist::kDontStoreCookies) { 685 if (match->attributes() & Blacklist::kDontStoreCookies) {
689 NotificationService::current()->Notify( 686 NotificationService::current()->Notify(
690 NotificationType::BLACKLIST_BLOCKED_RESOURCE, 687 NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED,
691 Source<const ChromeURLRequestContext>(this), 688 Source<const ChromeURLRequestContext>(this),
692 Details<const URLRequest>(request)); 689 Details<const URLRequest>(request));
693 690
694 cookie->clear(); 691 cookie->clear();
695 return false; 692 return false;
696 } 693 }
697 if (match->attributes() & Blacklist::kDontPersistCookies) { 694 if (match->attributes() & Blacklist::kDontPersistCookies) {
698 *cookie = Blacklist::StripCookieExpiry(*cookie); 695 *cookie = Blacklist::StripCookieExpiry(*cookie);
699 } 696 }
700 } 697 }
701 return true; 698 return true;
702 } 699 }
703 700
704 bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request) 701 bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request)
705 const { 702 const {
706 const URLRequest::UserData* d = 703 const URLRequest::UserData* d =
707 request->GetUserData(&Blacklist::kRequestDataKey); 704 request->GetUserData(&Blacklist::kRequestDataKey);
708 if (d) { 705 if (d) {
709 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); 706 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
710 if (match->attributes() & Blacklist::kDontSendCookies) { 707 if (match->attributes() & Blacklist::kDontSendCookies) {
711 NotificationService::current()->Notify( 708 NotificationService::current()->Notify(
712 NotificationType::BLACKLIST_BLOCKED_RESOURCE, 709 NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED,
713 Source<const ChromeURLRequestContext>(this), 710 Source<const ChromeURLRequestContext>(this),
714 Details<const URLRequest>(request)); 711 Details<const URLRequest>(request));
715 712
716 return false; 713 return false;
717 } 714 }
718 } 715 }
719 return true; 716 return true;
720 } 717 }
721 718
719 const Blacklist* ChromeURLRequestContext::GetBlacklist() const {
720 // TODO(phajdan.jr): Remove the check when Privacy Blacklists become stable.
721 if (!blacklist_manager_)
722 return NULL;
723 return blacklist_manager_->GetCompiledBlacklist();
724 }
725
722 void ChromeURLRequestContext::OnNewExtensions(const std::string& id, 726 void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
723 const FilePath& path) { 727 const FilePath& path) {
724 if (!is_off_the_record_) 728 if (!is_off_the_record_)
725 extension_paths_[id] = path; 729 extension_paths_[id] = path;
726 } 730 }
727 731
728 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) { 732 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
729 CheckCurrentlyOnIOThread(); 733 CheckCurrentlyOnIOThread();
730 if (is_off_the_record_) 734 if (is_off_the_record_)
731 return; 735 return;
(...skipping 14 matching lines...) Expand all
746 ftp_transaction_factory_ = other->ftp_transaction_factory_; 750 ftp_transaction_factory_ = other->ftp_transaction_factory_;
747 cookie_store_ = other->cookie_store_; 751 cookie_store_ = other->cookie_store_;
748 cookie_policy_.set_type(other->cookie_policy_.type()); 752 cookie_policy_.set_type(other->cookie_policy_.type());
749 strict_transport_security_state_ = other->strict_transport_security_state_; 753 strict_transport_security_state_ = other->strict_transport_security_state_;
750 accept_language_ = other->accept_language_; 754 accept_language_ = other->accept_language_;
751 accept_charset_ = other->accept_charset_; 755 accept_charset_ = other->accept_charset_;
752 referrer_charset_ = other->referrer_charset_; 756 referrer_charset_ = other->referrer_charset_;
753 757
754 // Set ChromeURLRequestContext members 758 // Set ChromeURLRequestContext members
755 appcache_service_ = other->appcache_service_; 759 appcache_service_ = other->appcache_service_;
760 blacklist_manager_ = other->blacklist_manager_;
756 extension_paths_ = other->extension_paths_; 761 extension_paths_ = other->extension_paths_;
757 user_script_dir_path_ = other->user_script_dir_path_; 762 user_script_dir_path_ = other->user_script_dir_path_;
758 blacklist_ = other->blacklist_;
759 is_media_ = other->is_media_; 763 is_media_ = other->is_media_;
760 is_off_the_record_ = other->is_off_the_record_; 764 is_off_the_record_ = other->is_off_the_record_;
761 } 765 }
762 766
767 void ChromeURLRequestContext::set_blacklist_manager(
768 BlacklistManager* blacklist_manager) {
769 blacklist_manager_ = blacklist_manager;
770 }
771
763 void ChromeURLRequestContext::OnAcceptLanguageChange( 772 void ChromeURLRequestContext::OnAcceptLanguageChange(
764 const std::string& accept_language) { 773 const std::string& accept_language) {
765 CheckCurrentlyOnIOThread(); 774 CheckCurrentlyOnIOThread();
766 accept_language_ = 775 accept_language_ =
767 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); 776 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language);
768 } 777 }
769 778
770 void ChromeURLRequestContext::OnCookiePolicyChange( 779 void ChromeURLRequestContext::OnCookiePolicyChange(
771 net::CookiePolicy::Type type) { 780 net::CookiePolicy::Type type) {
772 CheckCurrentlyOnIOThread(); 781 CheckCurrentlyOnIOThread();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 // For the latter, we need a change on the webkit-side. 822 // For the latter, we need a change on the webkit-side.
814 // We initialize it to the default charset here and a user will 823 // We initialize it to the default charset here and a user will
815 // have an *arguably* better default charset for interpreting a raw 8bit 824 // have an *arguably* better default charset for interpreting a raw 8bit
816 // C-D header field. It means the native OS codepage fallback in 825 // C-D header field. It means the native OS codepage fallback in
817 // net_util::GetSuggestedFilename is unlikely to be taken. 826 // net_util::GetSuggestedFilename is unlikely to be taken.
818 referrer_charset_ = default_charset; 827 referrer_charset_ = default_charset;
819 828
820 cookie_policy_type_ = net::CookiePolicy::FromInt( 829 cookie_policy_type_ = net::CookiePolicy::FromInt(
821 prefs->GetInteger(prefs::kCookieBehavior)); 830 prefs->GetInteger(prefs::kCookieBehavior));
822 831
823 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! 832 blacklist_manager_ = profile->GetBlacklistManager();
824 blacklist_ = profile->GetBlacklist();
825 833
826 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! 834 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
827 strict_transport_security_state_ = profile->GetStrictTransportSecurityState(); 835 strict_transport_security_state_ = profile->GetStrictTransportSecurityState();
828 836
829 if (profile->GetExtensionsService()) { 837 if (profile->GetExtensionsService()) {
830 const ExtensionList* extensions = 838 const ExtensionList* extensions =
831 profile->GetExtensionsService()->extensions(); 839 profile->GetExtensionsService()->extensions();
832 for (ExtensionList::const_iterator iter = extensions->begin(); 840 for (ExtensionList::const_iterator iter = extensions->begin();
833 iter != extensions->end(); ++iter) { 841 iter != extensions->end(); ++iter) {
834 extension_paths_[(*iter)->id()] = (*iter)->path(); 842 extension_paths_[(*iter)->id()] = (*iter)->path();
(...skipping 18 matching lines...) Expand all
853 // Apply all the parameters. NOTE: keep this in sync with 861 // Apply all the parameters. NOTE: keep this in sync with
854 // ChromeURLRequestContextFactory(Profile*). 862 // ChromeURLRequestContextFactory(Profile*).
855 context->set_is_media(is_media_); 863 context->set_is_media(is_media_);
856 context->set_is_off_the_record(is_off_the_record_); 864 context->set_is_off_the_record(is_off_the_record_);
857 context->set_accept_language(accept_language_); 865 context->set_accept_language(accept_language_);
858 context->set_accept_charset(accept_charset_); 866 context->set_accept_charset(accept_charset_);
859 context->set_referrer_charset(referrer_charset_); 867 context->set_referrer_charset(referrer_charset_);
860 context->set_cookie_policy_type(cookie_policy_type_); 868 context->set_cookie_policy_type(cookie_policy_type_);
861 context->set_extension_paths(extension_paths_); 869 context->set_extension_paths(extension_paths_);
862 context->set_user_script_dir_path(user_script_dir_path_); 870 context->set_user_script_dir_path(user_script_dir_path_);
863 context->set_blacklist(blacklist_); 871 context->set_blacklist_manager(blacklist_manager_.get());
864 context->set_strict_transport_security_state( 872 context->set_strict_transport_security_state(
865 strict_transport_security_state_); 873 strict_transport_security_state_);
866 context->set_ssl_config_service(ssl_config_service_); 874 context->set_ssl_config_service(ssl_config_service_);
867 } 875 }
868 876
869 // ---------------------------------------------------------------------------- 877 // ----------------------------------------------------------------------------
870 878
871 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) { 879 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
872 // Scan for all "enable" type proxy switches. 880 // Scan for all "enable" type proxy switches.
873 static const char* proxy_switches[] = { 881 static const char* proxy_switches[] = {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 } 926 }
919 927
920 if (command_line.HasSwitch(switches::kProxyBypassList)) { 928 if (command_line.HasSwitch(switches::kProxyBypassList)) {
921 proxy_config->ParseNoProxyList( 929 proxy_config->ParseNoProxyList(
922 WideToASCII(command_line.GetSwitchValue( 930 WideToASCII(command_line.GetSwitchValue(
923 switches::kProxyBypassList))); 931 switches::kProxyBypassList)));
924 } 932 }
925 933
926 return proxy_config; 934 return proxy_config;
927 } 935 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/privacy_blacklist/blacklist_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698