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 b4991e264c8eb07f5d5bc186582dc4099161575a..036891e1c6a457ce28ba484ef5adb5ed66e4d49a 100644 |
--- a/chrome/browser/custom_handlers/protocol_handler_registry.cc |
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc |
@@ -14,6 +14,7 @@ |
#include "chrome/browser/profiles/profile_io_data.h" |
#include "chrome/common/pref_names.h" |
#include "content/browser/child_process_security_policy.h" |
+#include "content/common/notification_service.h" |
#include "net/base/network_delegate.h" |
#include "net/url_request/url_request_redirect_job.h" |
@@ -30,13 +31,14 @@ ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, |
ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { |
} |
-ProtocolHandlerRegistry::ProtocolHandlerList& |
-ProtocolHandlerRegistry::GetHandlerListFor(const std::string& scheme) { |
- ProtocolHandlerMultiMap::iterator p = protocol_handlers_.find(scheme); |
+const ProtocolHandlerRegistry::ProtocolHandlerList* |
+ProtocolHandlerRegistry::GetHandlersFor( |
+ const std::string& scheme) const { |
+ ProtocolHandlerMultiMap::const_iterator p = protocol_handlers_.find(scheme); |
if (p == protocol_handlers_.end()) { |
- protocol_handlers_[scheme] = ProtocolHandlerList(); |
+ return NULL; |
} |
- return protocol_handlers_[scheme]; |
+ return &p->second; |
} |
void ProtocolHandlerRegistry::RegisterProtocolHandler( |
@@ -49,7 +51,22 @@ void ProtocolHandlerRegistry::RegisterProtocolHandler( |
if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol())) { |
delegate_->RegisterExternalHandler(handler.protocol()); |
} |
- GetHandlerListFor(handler.protocol()).push_back(handler); |
+ InsertHandler(handler); |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
willchan no longer on Chromium
2011/05/21 00:06:05
Which thread does this happen on? Is this the UI t
koz (OOO until 15th September)
2011/05/24 08:47:49
It will be called on Load(), but in that case it d
|
+} |
+ |
+void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) { |
+ ProtocolHandlerMultiMap::iterator p = |
+ protocol_handlers_.find(handler.protocol()); |
+ |
+ if (p != protocol_handlers_.end()) { |
+ p->second.push_back(handler); |
+ return; |
+ } |
+ |
+ ProtocolHandlerList new_list; |
+ new_list.push_back(handler); |
+ protocol_handlers_[handler.protocol()] = new_list; |
} |
void ProtocolHandlerRegistry::IgnoreProtocolHandler( |
@@ -66,6 +83,7 @@ void ProtocolHandlerRegistry::Enable() { |
p != protocol_handlers_.end(); ++p) { |
delegate_->RegisterExternalHandler(p->first); |
} |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
willchan no longer on Chromium
2011/05/21 00:06:05
Looks like this is probably the UI thread, right?
koz (OOO until 15th September)
2011/05/24 08:47:49
Yep, it's called when the user toggles the checkbo
|
} |
void ProtocolHandlerRegistry::Disable() { |
@@ -77,6 +95,7 @@ void ProtocolHandlerRegistry::Disable() { |
p != protocol_handlers_.end(); ++p) { |
delegate_->DeregisterExternalHandler(p->first); |
} |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
} |
std::vector<const DictionaryValue*> |
@@ -126,6 +145,7 @@ void ProtocolHandlerRegistry::Load() { |
IgnoreProtocolHandler(ProtocolHandler::CreateProtocolHandler(*p)); |
} |
is_loading_ = false; |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_LOADED); |
} |
void ProtocolHandlerRegistry::RegisterHandlerFromValue( |
@@ -161,24 +181,32 @@ void ProtocolHandlerRegistry::GetHandledProtocols( |
std::vector<std::string>* output) const { |
ProtocolHandlerMultiMap::const_iterator p; |
for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) { |
- output->push_back(p->first); |
+ if (!p->second.empty()) { |
+ output->push_back(p->first); |
+ } |
} |
} |
void ProtocolHandlerRegistry::RemoveIgnoredHandler( |
const ProtocolHandler& handler) { |
- for (ProtocolHandlerList::iterator p = ignored_protocol_handlers_.begin(); |
- p != ignored_protocol_handlers_.end(); ++p) { |
- if (handler == *p) { |
- ignored_protocol_handlers_.erase(p); |
- break; |
- } |
+ ProtocolHandlerList::iterator p = |
+ std::find(ignored_protocol_handlers_.begin(), |
+ ignored_protocol_handlers_.end(), handler); |
+ if (p != ignored_protocol_handlers_.end()) { |
+ ignored_protocol_handlers_.erase(p); |
} |
+ Save(); |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
} |
-bool ProtocolHandlerRegistry::IsRegistered(const ProtocolHandler& handler) { |
- ProtocolHandlerList& handlers(GetHandlerListFor(handler.protocol())); |
- return std::find(handlers.begin(), handlers.end(), handler) != handlers.end(); |
+bool ProtocolHandlerRegistry::IsRegistered( |
+ const ProtocolHandler& handler) const { |
+ const ProtocolHandlerList* handlers = GetHandlersFor(handler.protocol()); |
+ if (!handlers) { |
+ return false; |
+ } |
+ return std::find(handlers->begin(), handlers->end(), handler) != |
+ handlers->end(); |
} |
bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { |
@@ -194,21 +222,27 @@ bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { |
bool ProtocolHandlerRegistry::IsHandledProtocol( |
const std::string& scheme) const { |
- return protocol_handlers_.find(scheme) != protocol_handlers_.end(); |
+ return !GetHandlerFor(scheme).IsEmpty(); |
} |
void ProtocolHandlerRegistry::RemoveHandler(const ProtocolHandler& handler) { |
- ProtocolHandlerList& handlers(GetHandlerListFor(handler.protocol())); |
+ ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; |
ProtocolHandlerList::iterator p = |
std::find(handlers.begin(), handlers.end(), handler); |
if (p != handlers.end()) { |
handlers.erase(p); |
} |
- ProtocolHandlerMap::iterator it = default_handlers_.find(handler.protocol()); |
- if (it != default_handlers_.end() && it->second == handler) { |
- default_handlers_.erase(it); |
+ ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); |
+ if (q != default_handlers_.end() && q->second == handler) { |
+ default_handlers_.erase(q); |
} |
+ |
+ if (!IsHandledProtocol(handler.protocol())) { |
+ delegate_->DeregisterExternalHandler(handler.protocol()); |
+ } |
+ Save(); |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
willchan no longer on Chromium
2011/05/21 00:06:05
What thread is this handled on?
koz (OOO until 15th September)
2011/05/24 08:47:49
The UI thread - it's called when the user clicks t
|
} |
net::URLRequestJob* ProtocolHandlerRegistry::MaybeCreateJob( |
@@ -284,11 +318,13 @@ void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) { |
default_handlers_.erase(handler.protocol()); |
default_handlers_.insert(std::make_pair(handler.protocol(), handler)); |
Save(); |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
} |
void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) { |
default_handlers_.erase(scheme); |
Save(); |
+ Notify(NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED); |
} |
bool ProtocolHandlerRegistry::IsDefault(const ProtocolHandler& handler) const { |
@@ -301,12 +337,28 @@ const ProtocolHandler& ProtocolHandlerRegistry::GetHandlerFor( |
if (p != default_handlers_.end()) { |
return p->second; |
} |
- ProtocolHandlerMultiMap::const_iterator q = |
- protocol_handlers_.find(scheme); |
- if (q != protocol_handlers_.end() && q->second.size() == 1) { |
- return q->second[0]; |
+ ProtocolHandlerMultiMap::const_iterator q = protocol_handlers_.find(scheme); |
+ if (q == protocol_handlers_.end() || q->second.empty()) { |
+ return ProtocolHandler::EmptyProtocolHandler(); |
} |
- return ProtocolHandler::EmptyProtocolHandler(); |
+ return q->second.back(); |
+} |
+ |
+int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const { |
+ const ProtocolHandler& handler = GetHandlerFor(scheme); |
+ const ProtocolHandlerList* handlers = GetHandlersFor(scheme); |
+ if (!handlers) { |
+ return -1; |
+ } |
+ |
+ ProtocolHandlerList::const_iterator p; |
+ int i; |
+ for (i = 0, p = handlers->begin(); p != handlers->end(); ++p, ++i) { |
+ if (*p == handler) { |
+ return i; |
+ } |
+ } |
+ return -1; |
} |
bool ProtocolHandlerRegistry::HasDefault( |
@@ -314,10 +366,6 @@ bool ProtocolHandlerRegistry::HasDefault( |
return !GetHandlerFor(scheme).IsEmpty(); |
} |
-bool ProtocolHandlerRegistry::HasHandler(const std::string& scheme) { |
- return !GetHandlerListFor(scheme).empty(); |
-} |
- |
// Delegate -------------------------------------------------------------------- |
ProtocolHandlerRegistry::Delegate::~Delegate() { |
@@ -340,3 +388,9 @@ bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered( |
const std::string& protocol) { |
return ProfileIOData::IsHandledProtocol(protocol); |
} |
+ |
+void ProtocolHandlerRegistry::Notify(NotificationType type) { |
willchan no longer on Chromium
2011/05/20 22:48:50
What thread is Notify() being called on? That my m
koz (OOO until 15th September)
2011/05/20 23:18:57
Ah, I wasn't aware that the thread that Notify() i
|
+ NotificationService::current()->Notify(type, |
+ Source<Profile>(profile_), |
+ NotificationService::NoDetails()); |
+} |