| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/intents/web_intents_registry.h" | 5 #include "chrome/browser/intents/web_intents_registry.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/webdata/web_data_service.h" | 8 #include "chrome/browser/webdata/web_data_service.h" |
| 9 #include "net/base/mime_util.h" | 9 #include "net/base/mime_util.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Compares two mime types for equality. Supports wild cards in both | 13 // Compares two mime types for equality. Supports wild cards in both |
| 14 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. | 14 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. |
| 15 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { | 15 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { |
| 16 // We don't have a MIME matcher that allows patterns on both sides | 16 // We don't have a MIME matcher that allows patterns on both sides |
| 17 // Instead, we do two comparison, treating each type in turn as a | 17 // Instead, we do two comparison, treating each type in turn as a |
| 18 // pattern. If either one matches, we consider this a MIME match. | 18 // pattern. If either one matches, we consider this a MIME match. |
| 19 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2))) | 19 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2))) |
| 20 return true; | 20 return true; |
| 21 return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1)); | 21 return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 using webkit_glue::WebIntentServiceData; |
| 27 |
| 26 // Internal object representing all data associated with a single query. | 28 // Internal object representing all data associated with a single query. |
| 27 struct WebIntentsRegistry::IntentsQuery { | 29 struct WebIntentsRegistry::IntentsQuery { |
| 28 // Unique query identifier. | 30 // Unique query identifier. |
| 29 QueryID query_id_; | 31 QueryID query_id_; |
| 30 | 32 |
| 31 // Underlying data query. | 33 // Underlying data query. |
| 32 WebDataService::Handle pending_query_; | 34 WebDataService::Handle pending_query_; |
| 33 | 35 |
| 34 // The consumer for this particular query. | 36 // The consumer for this particular query. |
| 35 Consumer* consumer_; | 37 Consumer* consumer_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 DCHECK(result); | 68 DCHECK(result); |
| 67 DCHECK(result->GetType() == WEB_INTENTS_RESULT); | 69 DCHECK(result->GetType() == WEB_INTENTS_RESULT); |
| 68 | 70 |
| 69 QueryMap::iterator it = queries_.find(h); | 71 QueryMap::iterator it = queries_.find(h); |
| 70 DCHECK(it != queries_.end()); | 72 DCHECK(it != queries_.end()); |
| 71 | 73 |
| 72 IntentsQuery* query(it->second); | 74 IntentsQuery* query(it->second); |
| 73 DCHECK(query); | 75 DCHECK(query); |
| 74 queries_.erase(it); | 76 queries_.erase(it); |
| 75 | 77 |
| 76 IntentList matching_intents = static_cast< | 78 IntentServiceList matching_services = static_cast< |
| 77 const WDResult<IntentList>*>(result)->GetValue(); | 79 const WDResult<IntentServiceList>*>(result)->GetValue(); |
| 78 | 80 |
| 79 // Loop over all intents in all extensions, collect ones matching the query. | 81 // Loop over all intents in all extensions, collect ones matching the query. |
| 80 if (extension_service_) { | 82 if (extension_service_) { |
| 81 const ExtensionList* extensions = extension_service_->extensions(); | 83 const ExtensionList* extensions = extension_service_->extensions(); |
| 82 if (extensions) { | 84 if (extensions) { |
| 83 for (ExtensionList::const_iterator i(extensions->begin()); | 85 for (ExtensionList::const_iterator i(extensions->begin()); |
| 84 i != extensions->end(); ++i) { | 86 i != extensions->end(); ++i) { |
| 85 const IntentList& intents((*i)->intents()); | 87 const IntentServiceList& intents((*i)->intents_services()); |
| 86 for (IntentList::const_iterator j(intents.begin()); | 88 for (IntentServiceList::const_iterator j(intents.begin()); |
| 87 j != intents.end(); ++j) { | 89 j != intents.end(); ++j) { |
| 88 if (query->action_.empty() || query->action_ == j->action) | 90 if (query->action_.empty() || query->action_ == j->action) |
| 89 matching_intents.push_back(*j); | 91 matching_services.push_back(*j); |
| 90 } | 92 } |
| 91 } | 93 } |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 | 96 |
| 95 // Filter out all intents not matching the query type. | 97 // Filter out all intents not matching the query type. |
| 96 IntentList::iterator iter(matching_intents.begin()); | 98 IntentServiceList::iterator iter(matching_services.begin()); |
| 97 while (iter != matching_intents.end()) { | 99 while (iter != matching_services.end()) { |
| 98 if (MimeTypesAreEqual(iter->type, query->type_)) | 100 if (MimeTypesAreEqual(iter->type, query->type_)) |
| 99 ++iter; | 101 ++iter; |
| 100 else | 102 else |
| 101 iter = matching_intents.erase(iter); | 103 iter = matching_services.erase(iter); |
| 102 } | 104 } |
| 103 | 105 |
| 104 query->consumer_->OnIntentsQueryDone(query->query_id_, matching_intents); | 106 query->consumer_->OnIntentsQueryDone(query->query_id_, matching_services); |
| 105 delete query; | 107 delete query; |
| 106 } | 108 } |
| 107 | 109 |
| 108 WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders( | 110 WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders( |
| 109 const string16& action, const string16& mimetype, Consumer* consumer) { | 111 const string16& action, const string16& mimetype, Consumer* consumer) { |
| 110 DCHECK(consumer); | 112 DCHECK(consumer); |
| 111 DCHECK(wds_.get()); | 113 DCHECK(wds_.get()); |
| 112 | 114 |
| 113 IntentsQuery* query = new IntentsQuery; | 115 IntentsQuery* query = new IntentsQuery; |
| 114 query->query_id_ = next_query_id_++; | 116 query->query_id_ = next_query_id_++; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 140 const WebIntentServiceData& service) { | 142 const WebIntentServiceData& service) { |
| 141 DCHECK(wds_.get()); | 143 DCHECK(wds_.get()); |
| 142 wds_->AddWebIntent(service); | 144 wds_->AddWebIntent(service); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void WebIntentsRegistry::UnregisterIntentProvider( | 147 void WebIntentsRegistry::UnregisterIntentProvider( |
| 146 const WebIntentServiceData& service) { | 148 const WebIntentServiceData& service) { |
| 147 DCHECK(wds_.get()); | 149 DCHECK(wds_.get()); |
| 148 wds_->RemoveWebIntent(service); | 150 wds_->RemoveWebIntent(service); |
| 149 } | 151 } |
| OLD | NEW |