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

Side by Side Diff: chrome/browser/profiles/profile_io_data.cc

Issue 2458093003: Add DCHECKs to validate ProfileIOData's list of protocols.
Patch Set: Merge remote-tracking branch 'origin/master' into detect_unregistered_schemes Created 4 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profiles/profile_io_data.h" 5 #include "chrome/browser/profiles/profile_io_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 717 }
718 } 718 }
719 719
720 // static 720 // static
721 ProfileIOData* ProfileIOData::FromResourceContext( 721 ProfileIOData* ProfileIOData::FromResourceContext(
722 content::ResourceContext* rc) { 722 content::ResourceContext* rc) {
723 return (static_cast<ResourceContext*>(rc))->io_data_; 723 return (static_cast<ResourceContext*>(rc))->io_data_;
724 } 724 }
725 725
726 // static 726 // static
727 bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { 727 bool ProfileIOData::IsBuiltInProtocol(const std::string& scheme) {
728 DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); 728 DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
729 // The list below MUST include every protocol that could return a response.
729 static const char* const kProtocolList[] = { 730 static const char* const kProtocolList[] = {
730 url::kFileScheme, 731 url::kFileScheme,
731 content::kChromeDevToolsScheme, 732 content::kChromeDevToolsScheme,
732 dom_distiller::kDomDistillerScheme, 733 dom_distiller::kDomDistillerScheme,
733 #if defined(ENABLE_EXTENSIONS) 734 #if defined(ENABLE_EXTENSIONS)
734 extensions::kExtensionScheme, 735 extensions::kExtensionScheme,
735 extensions::kExtensionResourceScheme, 736 extensions::kExtensionResourceScheme,
736 #endif 737 #endif
737 content::kChromeUIScheme, 738 content::kChromeUIScheme,
738 url::kDataScheme, 739 url::kDataScheme,
(...skipping 12 matching lines...) Expand all
751 chrome::kChromeSearchScheme, 752 chrome::kChromeSearchScheme,
752 }; 753 };
753 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { 754 for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
754 if (scheme == kProtocolList[i]) 755 if (scheme == kProtocolList[i])
755 return true; 756 return true;
756 } 757 }
757 return net::URLRequest::IsHandledProtocol(scheme); 758 return net::URLRequest::IsHandledProtocol(scheme);
758 } 759 }
759 760
760 // static 761 // static
761 bool ProfileIOData::IsHandledURL(const GURL& url) { 762 bool ProfileIOData::HasBuiltInProtocol(const GURL& url) {
762 if (!url.is_valid()) { 763 if (!url.is_valid()) {
763 // We handle error cases. 764 // We handle error cases.
764 return true; 765 return true;
765 } 766 }
766 767
767 return IsHandledProtocol(url.scheme()); 768 return IsBuiltInProtocol(url.scheme());
768 } 769 }
769 770
770 // static 771 // static
771 void ProfileIOData::InstallProtocolHandlers( 772 void ProfileIOData::InstallProtocolHandlers(
772 net::URLRequestJobFactoryImpl* job_factory, 773 net::URLRequestJobFactoryImpl* job_factory,
773 content::ProtocolHandlerMap* protocol_handlers) { 774 content::ProtocolHandlerMap* protocol_handlers) {
774 for (content::ProtocolHandlerMap::iterator it = 775 for (content::ProtocolHandlerMap::iterator it =
775 protocol_handlers->begin(); 776 protocol_handlers->begin();
776 it != protocol_handlers->end(); 777 it != protocol_handlers->end();
777 ++it) { 778 ++it) {
779 DCHECK(IsBuiltInProtocol(it->first));
778 bool set_protocol = job_factory->SetProtocolHandler( 780 bool set_protocol = job_factory->SetProtocolHandler(
779 it->first, base::WrapUnique(it->second.release())); 781 it->first, base::WrapUnique(it->second.release()));
780 DCHECK(set_protocol); 782 DCHECK(set_protocol);
781 } 783 }
782 protocol_handlers->clear(); 784 protocol_handlers->clear();
783 } 785 }
784 786
785 // static 787 // static
786 void ProfileIOData::SetCertVerifierForTesting( 788 void ProfileIOData::SetCertVerifierForTesting(
787 net::CertVerifier* cert_verifier) { 789 net::CertVerifier* cert_verifier) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 } 1173 }
1172 1174
1173 std::unique_ptr<net::URLRequestJobFactory> 1175 std::unique_ptr<net::URLRequestJobFactory>
1174 ProfileIOData::SetUpJobFactoryDefaults( 1176 ProfileIOData::SetUpJobFactoryDefaults(
1175 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory, 1177 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory,
1176 content::URLRequestInterceptorScopedVector request_interceptors, 1178 content::URLRequestInterceptorScopedVector request_interceptors,
1177 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 1179 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
1178 protocol_handler_interceptor, 1180 protocol_handler_interceptor,
1179 net::NetworkDelegate* network_delegate, 1181 net::NetworkDelegate* network_delegate,
1180 net::HostResolver* host_resolver) const { 1182 net::HostResolver* host_resolver) const {
1181 // NOTE(willchan): Keep these protocol handlers in sync with 1183 // NOTE(nick): It is absolutely critical for the built-in protocol handlers to
1182 // ProfileIOData::IsHandledProtocol(). 1184 // be enumerated by ProfileIOData::IsBuiltInProtocol(), so use this lambda to
1183 bool set_protocol = job_factory->SetProtocolHandler( 1185 // make sure you've got it right.
1186 net::URLRequestJobFactoryImpl* job_factory_ptr = job_factory.get();
1187 auto install_builtin_handler = [job_factory_ptr](
1188 const char* p,
1189 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> h) {
1190 DCHECK(IsBuiltInProtocol(p)) << p;
1191 bool set_protocol_succeeded =
1192 job_factory_ptr->SetProtocolHandler(p, std::move(h));
1193 DCHECK(set_protocol_succeeded);
1194 };
1195
1196 install_builtin_handler(
1184 url::kFileScheme, 1197 url::kFileScheme,
1185 base::MakeUnique<net::FileProtocolHandler>( 1198 base::MakeUnique<net::FileProtocolHandler>(
1186 content::BrowserThread::GetBlockingPool() 1199 content::BrowserThread::GetBlockingPool()
1187 ->GetTaskRunnerWithShutdownBehavior( 1200 ->GetTaskRunnerWithShutdownBehavior(
1188 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); 1201 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
1189 DCHECK(set_protocol);
1190 1202
1191 #if defined(ENABLE_EXTENSIONS) 1203 #if defined(ENABLE_EXTENSIONS)
1192 DCHECK(extension_info_map_.get()); 1204 DCHECK(extension_info_map_.get());
1193 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE). 1205 // Check only for incognito (and not Chrome OS guest mode GUEST_PROFILE).
1194 bool is_incognito = profile_type() == Profile::INCOGNITO_PROFILE; 1206 bool is_incognito = profile_type() == Profile::INCOGNITO_PROFILE;
1195 set_protocol = job_factory->SetProtocolHandler( 1207 install_builtin_handler(extensions::kExtensionScheme,
1196 extensions::kExtensionScheme, 1208 extensions::CreateExtensionProtocolHandler(
1197 extensions::CreateExtensionProtocolHandler(is_incognito, 1209 is_incognito, extension_info_map_.get()));
1198 extension_info_map_.get())); 1210 install_builtin_handler(extensions::kExtensionResourceScheme,
1199 DCHECK(set_protocol); 1211 CreateExtensionResourceProtocolHandler());
1200 set_protocol = job_factory->SetProtocolHandler(
1201 extensions::kExtensionResourceScheme,
1202 CreateExtensionResourceProtocolHandler());
1203 DCHECK(set_protocol);
1204 #endif 1212 #endif
1205 set_protocol = job_factory->SetProtocolHandler( 1213 install_builtin_handler(url::kDataScheme,
1206 url::kDataScheme, base::MakeUnique<net::DataProtocolHandler>()); 1214 base::MakeUnique<net::DataProtocolHandler>());
1207 DCHECK(set_protocol);
1208 #if defined(OS_CHROMEOS) 1215 #if defined(OS_CHROMEOS)
1209 if (profile_params_) { 1216 if (profile_params_) {
1210 set_protocol = job_factory->SetProtocolHandler( 1217 install_builtin_handler(
1211 content::kExternalFileScheme, 1218 content::kExternalFileScheme,
1212 base::MakeUnique<chromeos::ExternalFileProtocolHandler>( 1219 base::MakeUnique<chromeos::ExternalFileProtocolHandler>(
1213 profile_params_->profile)); 1220 profile_params_->profile));
1214 DCHECK(set_protocol);
1215 } 1221 }
1216 #endif // defined(OS_CHROMEOS) 1222 #endif // defined(OS_CHROMEOS)
1217 #if defined(OS_ANDROID) 1223 #if defined(OS_ANDROID)
1218 set_protocol = job_factory->SetProtocolHandler( 1224 install_builtin_handler(
1219 url::kContentScheme, 1225 url::kContentScheme,
1220 content::ContentProtocolHandler::Create( 1226 content::ContentProtocolHandler::Create(
1221 content::BrowserThread::GetBlockingPool() 1227 content::BrowserThread::GetBlockingPool()
1222 ->GetTaskRunnerWithShutdownBehavior( 1228 ->GetTaskRunnerWithShutdownBehavior(
1223 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); 1229 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
1224 #endif 1230 #endif
1225 1231
1226 job_factory->SetProtocolHandler( 1232 install_builtin_handler(
1227 url::kAboutScheme, 1233 url::kAboutScheme,
1228 base::MakeUnique<about_handler::AboutProtocolHandler>()); 1234 base::MakeUnique<about_handler::AboutProtocolHandler>());
1229 1235
1230 #if !BUILDFLAG(DISABLE_FTP_SUPPORT) 1236 #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
1231 job_factory->SetProtocolHandler( 1237 install_builtin_handler(url::kFtpScheme,
1232 url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver)); 1238 net::FtpProtocolHandler::Create(host_resolver));
1233 #endif // !BUILDFLAG(DISABLE_FTP_SUPPORT) 1239 #endif // !BUILDFLAG(DISABLE_FTP_SUPPORT)
1234 1240
1235 #if defined(DEBUG_DEVTOOLS) 1241 #if defined(DEBUG_DEVTOOLS)
1236 request_interceptors.push_back(new DebugDevToolsInterceptor); 1242 request_interceptors.push_back(new DebugDevToolsInterceptor);
1237 #endif 1243 #endif
1238 1244
1239 // Set up interceptors in the reverse order. 1245 // Set up interceptors in the reverse order.
1240 std::unique_ptr<net::URLRequestJobFactory> top_job_factory = 1246 std::unique_ptr<net::URLRequestJobFactory> top_job_factory =
1241 std::move(job_factory); 1247 std::move(job_factory);
1242 for (content::URLRequestInterceptorScopedVector::reverse_iterator i = 1248 for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 void ProfileIOData::SetCookieSettingsForTesting( 1359 void ProfileIOData::SetCookieSettingsForTesting(
1354 content_settings::CookieSettings* cookie_settings) { 1360 content_settings::CookieSettings* cookie_settings) {
1355 DCHECK(!cookie_settings_.get()); 1361 DCHECK(!cookie_settings_.get());
1356 cookie_settings_ = cookie_settings; 1362 cookie_settings_ = cookie_settings;
1357 } 1363 }
1358 1364
1359 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState( 1365 policy::URLBlacklist::URLBlacklistState ProfileIOData::GetURLBlacklistState(
1360 const GURL& url) const { 1366 const GURL& url) const {
1361 return url_blacklist_manager_->GetURLBlacklistState(url); 1367 return url_blacklist_manager_->GetURLBlacklistState(url);
1362 } 1368 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.h ('k') | chrome/browser/renderer_context_menu/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698