Chromium Code Reviews| Index: chrome/browser/plugins/plugin_metadata.cc |
| diff --git a/chrome/browser/plugins/plugin_metadata.cc b/chrome/browser/plugins/plugin_metadata.cc |
| index 5013c7f173401114be3753373d115038778ea23b..2e2d2587d8d807a7cb4fd7f613d7ae27939f904b 100644 |
| --- a/chrome/browser/plugins/plugin_metadata.cc |
| +++ b/chrome/browser/plugins/plugin_metadata.cc |
| @@ -4,10 +4,27 @@ |
| #include "chrome/browser/plugins/plugin_metadata.h" |
| +#include <functional> |
| + |
| #include "base/logging.h" |
| +#include "base/string_util.h" |
| +#include "base/utf_string_conversions.h" |
| #include "webkit/plugins/npapi/plugin_utils.h" |
| #include "webkit/plugins/webplugininfo.h" |
| +using webkit::WebPluginMimeType; |
| + |
| +namespace { |
| + |
| +struct MimeTypesCompare |
| + : public std::binary_function<WebPluginMimeType, std::string, bool> { |
| + bool operator() (const WebPluginMimeType& lhs, const std::string& rhs) const { |
| + return lhs.mime_type == rhs; |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| // static |
| const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader"; |
| const char PluginMetadata::kJavaGroupName[] = "Java(TM)"; |
| @@ -23,13 +40,15 @@ PluginMetadata::PluginMetadata(const std::string& identifier, |
| bool url_for_display, |
| const GURL& plugin_url, |
| const GURL& help_url, |
| - const string16& group_name_matcher) |
| + const string16& group_name_matcher, |
| + const std::string& language) |
| : identifier_(identifier), |
| name_(name), |
| group_name_matcher_(group_name_matcher), |
| url_for_display_(url_for_display), |
| plugin_url_(plugin_url), |
| - help_url_(help_url) { |
| + help_url_(help_url), |
| + language_(language) { |
| } |
| PluginMetadata::~PluginMetadata() { |
| @@ -41,7 +60,34 @@ void PluginMetadata::AddVersion(const Version& version, |
| versions_[version] = status; |
| } |
| -bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) { |
| +void PluginMetadata::AddMimeType(const std::string& mime_type) { |
| + all_mime_types_.push_back(mime_type); |
| +} |
| + |
| +void PluginMetadata::AddMatchingMimeType(const std::string& mime_type) { |
| + matching_mime_types_.push_back(mime_type); |
| +} |
| + |
| +bool PluginMetadata::HasMimeType(const std::string& mime_type) const { |
| + return std::find(all_mime_types_.begin(), all_mime_types_.end(), mime_type) != |
| + all_mime_types_.end(); |
| +} |
| + |
| +bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin, |
| + string16* matching_name) { |
| + MimeTypesCompare mime_types_cmp; |
| + for (size_t i = 0; i < matching_mime_types_.size(); ++i) { |
| + std::vector<WebPluginMimeType>::const_iterator result_it = |
| + std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), |
| + std::bind2nd(mime_types_cmp, matching_mime_types_[i])); |
| + // To have a match, every one of the |matching_mime_types_| |
| + // must be handled by the plug-in |
|
Bernhard Bauer
2012/10/04 11:37:19
Nit: end the sentence with a period please.
ibraaaa
2012/10/04 12:24:12
Done.
|
| + if (result_it == plugin.mime_types.end()) |
| + return false; |
| + } |
| + |
| + *matching_name = matching_mime_types_.size() > 0 ? |
| + ASCIIToUTF16(JoinString(matching_mime_types_, '+')) : name_; |
| return plugin.name.find(group_name_matcher_) != string16::npos; |
| } |
| @@ -100,7 +146,8 @@ scoped_ptr<PluginMetadata> PluginMetadata::Clone() const { |
| url_for_display_, |
| plugin_url_, |
| help_url_, |
| - group_name_matcher_); |
| + group_name_matcher_, |
| + language_); |
| copy->versions_ = versions_; |
| return make_scoped_ptr(copy); |
| } |