Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugins/plugin_metadata.h" | 5 #include "chrome/browser/plugins/plugin_metadata.h" |
| 6 | 6 |
| 7 #include <functional> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 8 #include "webkit/plugins/npapi/plugin_utils.h" | 12 #include "webkit/plugins/npapi/plugin_utils.h" |
| 9 #include "webkit/plugins/webplugininfo.h" | 13 #include "webkit/plugins/webplugininfo.h" |
| 10 | 14 |
| 15 using webkit::WebPluginMimeType; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 struct MimeTypesCompare | |
| 20 : public std::binary_function<WebPluginMimeType, std::string, bool> { | |
| 21 bool operator() (const WebPluginMimeType& lhs, const std::string& rhs) const { | |
| 22 return lhs.mime_type == rhs; | |
| 23 } | |
| 24 }; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 11 // static | 28 // static |
| 12 const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader"; | 29 const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader"; |
| 13 const char PluginMetadata::kJavaGroupName[] = "Java(TM)"; | 30 const char PluginMetadata::kJavaGroupName[] = "Java(TM)"; |
| 14 const char PluginMetadata::kQuickTimeGroupName[] = "QuickTime Player"; | 31 const char PluginMetadata::kQuickTimeGroupName[] = "QuickTime Player"; |
| 15 const char PluginMetadata::kShockwaveGroupName[] = "Adobe Shockwave Player"; | 32 const char PluginMetadata::kShockwaveGroupName[] = "Adobe Shockwave Player"; |
| 16 const char PluginMetadata::kRealPlayerGroupName[] = "RealPlayer"; | 33 const char PluginMetadata::kRealPlayerGroupName[] = "RealPlayer"; |
| 17 const char PluginMetadata::kSilverlightGroupName[] = "Silverlight"; | 34 const char PluginMetadata::kSilverlightGroupName[] = "Silverlight"; |
| 18 const char PluginMetadata::kWindowsMediaPlayerGroupName[] = | 35 const char PluginMetadata::kWindowsMediaPlayerGroupName[] = |
| 19 "Windows Media Player"; | 36 "Windows Media Player"; |
| 20 | 37 |
| 21 PluginMetadata::PluginMetadata(const std::string& identifier, | 38 PluginMetadata::PluginMetadata(const std::string& identifier, |
| 22 const string16& name, | 39 const string16& name, |
| 23 bool url_for_display, | 40 bool url_for_display, |
| 24 const GURL& plugin_url, | 41 const GURL& plugin_url, |
| 25 const GURL& help_url, | 42 const GURL& help_url, |
| 26 const string16& group_name_matcher) | 43 const string16& group_name_matcher, |
| 44 const std::string& language) | |
| 27 : identifier_(identifier), | 45 : identifier_(identifier), |
| 28 name_(name), | 46 name_(name), |
| 29 group_name_matcher_(group_name_matcher), | 47 group_name_matcher_(group_name_matcher), |
| 30 url_for_display_(url_for_display), | 48 url_for_display_(url_for_display), |
| 31 plugin_url_(plugin_url), | 49 plugin_url_(plugin_url), |
| 32 help_url_(help_url) { | 50 help_url_(help_url), |
| 51 language_(language) { | |
| 33 } | 52 } |
| 34 | 53 |
| 35 PluginMetadata::~PluginMetadata() { | 54 PluginMetadata::~PluginMetadata() { |
| 36 } | 55 } |
| 37 | 56 |
| 38 void PluginMetadata::AddVersion(const Version& version, | 57 void PluginMetadata::AddVersion(const Version& version, |
| 39 SecurityStatus status) { | 58 SecurityStatus status) { |
| 40 DCHECK(versions_.find(version) == versions_.end()); | 59 DCHECK(versions_.find(version) == versions_.end()); |
| 41 versions_[version] = status; | 60 versions_[version] = status; |
| 42 } | 61 } |
| 43 | 62 |
| 44 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) { | 63 void PluginMetadata::AddMimeType(const std::string& mime_type) { |
| 64 all_mime_types_.push_back(mime_type); | |
| 65 } | |
| 66 | |
| 67 void PluginMetadata::AddMatchingMimeType(const std::string& mime_type) { | |
| 68 matching_mime_types_.push_back(mime_type); | |
| 69 } | |
| 70 | |
| 71 bool PluginMetadata::HasMimeType(const std::string& mime_type) const { | |
| 72 return std::find(all_mime_types_.begin(), all_mime_types_.end(), mime_type) != | |
| 73 all_mime_types_.end(); | |
| 74 } | |
| 75 | |
| 76 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin, | |
| 77 string16* matching_name) { | |
| 78 MimeTypesCompare mime_types_cmp; | |
| 79 for (size_t i = 0; i < matching_mime_types_.size(); ++i) { | |
| 80 std::vector<WebPluginMimeType>::const_iterator result_it = | |
| 81 std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), | |
| 82 std::bind2nd(mime_types_cmp, matching_mime_types_[i])); | |
| 83 // To have a match, every one of the |matching_mime_types_| | |
| 84 // 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.
| |
| 85 if (result_it == plugin.mime_types.end()) | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 *matching_name = matching_mime_types_.size() > 0 ? | |
| 90 ASCIIToUTF16(JoinString(matching_mime_types_, '+')) : name_; | |
| 45 return plugin.name.find(group_name_matcher_) != string16::npos; | 91 return plugin.name.find(group_name_matcher_) != string16::npos; |
| 46 } | 92 } |
| 47 | 93 |
| 48 // static | 94 // static |
| 49 bool PluginMetadata::ParseSecurityStatus( | 95 bool PluginMetadata::ParseSecurityStatus( |
| 50 const std::string& status_str, | 96 const std::string& status_str, |
| 51 PluginMetadata::SecurityStatus* status) { | 97 PluginMetadata::SecurityStatus* status) { |
| 52 if (status_str == "up_to_date") | 98 if (status_str == "up_to_date") |
| 53 *status = SECURITY_STATUS_UP_TO_DATE; | 99 *status = SECURITY_STATUS_UP_TO_DATE; |
| 54 else if (status_str == "out_of_date") | 100 else if (status_str == "out_of_date") |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // Keep versions ordered by newest (biggest) first. | 139 // Keep versions ordered by newest (biggest) first. |
| 94 return lhs.CompareTo(rhs) > 0; | 140 return lhs.CompareTo(rhs) > 0; |
| 95 } | 141 } |
| 96 | 142 |
| 97 scoped_ptr<PluginMetadata> PluginMetadata::Clone() const { | 143 scoped_ptr<PluginMetadata> PluginMetadata::Clone() const { |
| 98 PluginMetadata* copy = new PluginMetadata(identifier_, | 144 PluginMetadata* copy = new PluginMetadata(identifier_, |
| 99 name_, | 145 name_, |
| 100 url_for_display_, | 146 url_for_display_, |
| 101 plugin_url_, | 147 plugin_url_, |
| 102 help_url_, | 148 help_url_, |
| 103 group_name_matcher_); | 149 group_name_matcher_, |
| 150 language_); | |
| 104 copy->versions_ = versions_; | 151 copy->versions_ = versions_; |
| 105 return make_scoped_ptr(copy); | 152 return make_scoped_ptr(copy); |
| 106 } | 153 } |
| OLD | NEW |