Chromium Code Reviews| Index: chrome/browser/intents/web_intents_registry.cc |
| diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc |
| index 87a09858f51c55f43757c8b6408a51d0fa9eff64..2b550ac2337a3c5886f6e7e062c1ecd138be73cf 100644 |
| --- a/chrome/browser/intents/web_intents_registry.cc |
| +++ b/chrome/browser/intents/web_intents_registry.cc |
| @@ -4,16 +4,21 @@ |
| #include "chrome/browser/intents/web_intents_registry.h" |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/callback.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/intents/default_web_intent_service.h" |
| #include "chrome/browser/webdata/web_data_service.h" |
| +#include "chrome/common/extensions/extension.h" |
| #include "chrome/common/extensions/extension_set.h" |
| #include "googleurl/src/gurl.h" |
| #include "net/base/mime_util.h" |
| namespace { |
| +typedef WebIntentsRegistry::IntentServiceList IntentServiceList; |
| + |
| // Compares two mime types for equality. Supports wild cards in both |
| // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. |
| bool MimeTypesAreEqual(const string16& type1, const string16& type2) { |
| @@ -25,6 +30,29 @@ bool MimeTypesAreEqual(const string16& type1, const string16& type2) { |
| return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1)); |
| } |
| +void AddMatchingServicesForExtension(const Extension& extension, |
|
James Hawkins
2012/03/15 01:05:20
Document method and params.
binji
2012/03/15 17:53:14
Done.
|
| + const string16& action, |
| + IntentServiceList* matching_services) { |
| + const IntentServiceList& services(extension.intents_services()); |
|
James Hawkins
2012/03/15 01:05:20
Use '=' here? It seems strange to use a copy cons
binji
2012/03/15 17:53:14
Done.
|
| + for (IntentServiceList::const_iterator i = services.begin(); |
| + i != services.end(); ++i) { |
| + if (action.empty() || action == i->action) |
| + matching_services->push_back(*i); |
| + } |
| +} |
| + |
| +void FilterServicesByMimetype(const string16& mimetype, |
|
James Hawkins
2012/03/15 01:05:20
Document method and params.
binji
2012/03/15 17:53:14
Done.
|
| + IntentServiceList* matching_services) { |
| + // Filter out all services not matching the query type. |
| + IntentServiceList::iterator iter(matching_services->begin()); |
| + while (iter != matching_services->end()) { |
| + if (MimeTypesAreEqual(iter->type, mimetype)) |
| + ++iter; |
| + else |
| + iter = matching_services->erase(iter); |
| + } |
| +} |
| + |
| } // namespace |
| using webkit_glue::WebIntentServiceData; |
| @@ -111,24 +139,15 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone( |
| if (extensions) { |
| for (ExtensionSet::const_iterator i(extensions->begin()); |
| i != extensions->end(); ++i) { |
| - const IntentServiceList& services((*i)->intents_services()); |
| - for (IntentServiceList::const_iterator j(services.begin()); |
| - j != services.end(); ++j) { |
| - if (query->action_.empty() || query->action_ == j->action) |
| - matching_services.push_back(*j); |
| - } |
| + AddMatchingServicesForExtension(**i, |
| + query->action_, |
| + &matching_services); |
| } |
| } |
| } |
| // Filter out all services not matching the query type. |
| - IntentServiceList::iterator iter(matching_services.begin()); |
| - while (iter != matching_services.end()) { |
| - if (MimeTypesAreEqual(iter->type, query->type_)) |
| - ++iter; |
| - else |
| - iter = matching_services.erase(iter); |
| - } |
| + FilterServicesByMimetype(query->type_, &matching_services); |
| query->consumer_->OnIntentsQueryDone(query->query_id_, matching_services); |
| delete query; |
| @@ -269,6 +288,43 @@ WebIntentsRegistry::QueryID WebIntentsRegistry::IntentServiceExists( |
| return query->query_id_; |
| } |
| +WebIntentsRegistry::QueryID |
| + WebIntentsRegistry::GetIntentServicesWithExtensionId( |
| + const string16& action, |
| + const string16& mimetype, |
| + const std::string& extension_id, |
| + Consumer* consumer) { |
|
James Hawkins
2012/03/15 01:05:20
DCHECK(consumer);
binji
2012/03/15 17:53:14
Done.
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + IntentsQuery* query = |
|
James Hawkins
2012/03/15 01:05:20
Document ownership of |query|.
binji
2012/03/15 17:53:14
Done.
|
| + new IntentsQuery(next_query_id_++, consumer, action, mimetype); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&WebIntentsRegistry::DoGetIntentServicesWithExtensionId, |
| + base::Unretained(this), |
| + query, extension_id)); |
| + |
| + return query->query_id_; |
| +} |
| + |
| +void WebIntentsRegistry::DoGetIntentServicesWithExtensionId( |
| + IntentsQuery* query, |
| + const std::string& extension_id) { |
| + IntentServiceList matching_services; |
| + |
| + if (extension_service_) { |
| + const Extension* extension = |
| + extension_service_->GetExtensionById(extension_id, false); |
| + AddMatchingServicesForExtension(*extension, query->action_, |
|
James Hawkins
2012/03/15 01:05:20
nit: Start of parameter lines must align on the sa
binji
2012/03/15 17:53:14
Done.
|
| + &matching_services); |
| + FilterServicesByMimetype(query->type_, &matching_services); |
| + } |
| + |
| + query->consumer_->OnIntentsQueryDone(query->query_id_, matching_services); |
| + delete query; |
|
James Hawkins
2012/03/15 01:05:20
Now I see the ownership. Seems dangerous; why not
binji
2012/03/15 17:53:14
Done.
|
| +} |
| + |
| void WebIntentsRegistry::RegisterDefaultIntentService( |
| const DefaultWebIntentService& default_service) { |
| DCHECK(wds_.get()); |