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

Unified Diff: chrome/browser/custom_handlers/protocol_handler_registry.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/custom_handlers/protocol_handler_registry.cc
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc
index 596682630c3681d2be89ec853dc14be19117e1ab..82f75e256e1104607f8f385fd66bca20cecc08c6 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.cc
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc
@@ -238,6 +238,7 @@ void ProtocolHandlerRegistry::Delegate::RegisterExternalHandler(
const std::string& protocol) {
ChildProcessSecurityPolicy* policy =
ChildProcessSecurityPolicy::GetInstance();
+ CHECK(CanSchemeBeOverridden(protocol));
if (!policy->IsWebSafeScheme(protocol)) {
policy->RegisterWebSafeScheme(protocol);
}
@@ -247,11 +248,11 @@ void ProtocolHandlerRegistry::Delegate::DeregisterExternalHandler(
const std::string& protocol) {
}
-bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered(
+bool ProtocolHandlerRegistry::Delegate::CanSchemeBeOverridden(
const std::string& protocol) {
// NOTE(koz): This function is safe to call from any thread, despite living
// in ProfileIOData.
- return ProfileIOData::IsHandledProtocol(protocol);
+ return !ProfileIOData::IsBuiltInProtocol(protocol);
}
scoped_refptr<shell_integration::DefaultProtocolClientWorker>
@@ -480,12 +481,10 @@ void ProtocolHandlerRegistry::GetRegisteredProtocols(
bool ProtocolHandlerRegistry::CanSchemeBeOverridden(
const std::string& scheme) const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- const ProtocolHandlerList* handlers = GetHandlerList(scheme);
- // If we already have a handler for this scheme, we can add more.
- if (handlers != NULL && !handlers->empty())
- return true;
- // Don't override a scheme if it already has an external handler.
- return !delegate_->IsExternalHandlerRegistered(scheme);
+
+ // Don't override a scheme if it has an built-in handler (http, https, chrome-
+ // extension, etc).
+ return delegate_->CanSchemeBeOverridden(scheme);
}
bool ProtocolHandlerRegistry::IsRegistered(
@@ -795,7 +794,11 @@ void ProtocolHandlerRegistry::RegisterProtocolHandler(
const ProtocolHandler& handler,
const HandlerSource source) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK(CanSchemeBeOverridden(handler.protocol()));
+ if (!CanSchemeBeOverridden(handler.protocol())) {
+ NOTREACHED();
+ return;
+ }
+
DCHECK(!handler.IsEmpty());
ProtocolHandlerMultiMap& map =
(source == POLICY) ? policy_protocol_handlers_ : user_protocol_handlers_;
@@ -805,7 +808,7 @@ void ProtocolHandlerRegistry::RegisterProtocolHandler(
if (IsRegistered(handler)) {
return;
}
- if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol()))
+ if (enabled_)
delegate_->RegisterExternalHandler(handler.protocol());
InsertHandler(handler);
}

Powered by Google App Engine
This is Rietveld 408576698