Fix build break
[chromium-blink-merge.git] / chrome / browser / plugins / plugin_metadata.cc
blobcb049a270d478f3f1dd0f049507ffd2b3bdd9ee7
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
3 // found in the LICENSE file.
5 #include "chrome/browser/plugins/plugin_metadata.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/string_util.h"
11 #include "webkit/plugins/npapi/plugin_list.h"
12 #include "webkit/plugins/npapi/plugin_utils.h"
13 #include "webkit/plugins/webplugininfo.h"
15 // static
16 const char PluginMetadata::kAdobeReaderGroupName[] = "Adobe Reader";
17 const char PluginMetadata::kJavaGroupName[] = "Java(TM)";
18 const char PluginMetadata::kQuickTimeGroupName[] = "QuickTime Player";
19 const char PluginMetadata::kShockwaveGroupName[] = "Adobe Shockwave Player";
20 const char PluginMetadata::kRealPlayerGroupName[] = "RealPlayer";
21 const char PluginMetadata::kSilverlightGroupName[] = "Silverlight";
22 const char PluginMetadata::kWindowsMediaPlayerGroupName[] =
23 "Windows Media Player";
25 PluginMetadata::PluginMetadata(const std::string& identifier,
26 const string16& name,
27 bool url_for_display,
28 const GURL& plugin_url,
29 const GURL& help_url,
30 const string16& group_name_matcher,
31 const std::string& language)
32 : identifier_(identifier),
33 name_(name),
34 group_name_matcher_(group_name_matcher),
35 url_for_display_(url_for_display),
36 plugin_url_(plugin_url),
37 help_url_(help_url),
38 language_(language) {
41 PluginMetadata::~PluginMetadata() {
44 void PluginMetadata::AddVersion(const Version& version,
45 SecurityStatus status) {
46 DCHECK(versions_.find(version) == versions_.end());
47 versions_[version] = status;
50 void PluginMetadata::AddMimeType(const std::string& mime_type) {
51 all_mime_types_.push_back(mime_type);
54 void PluginMetadata::AddMatchingMimeType(const std::string& mime_type) {
55 matching_mime_types_.push_back(mime_type);
58 bool PluginMetadata::HasMimeType(const std::string& mime_type) const {
59 return std::find(all_mime_types_.begin(), all_mime_types_.end(), mime_type) !=
60 all_mime_types_.end();
63 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) {
64 using webkit::npapi::PluginList;
66 for (size_t i = 0; i < matching_mime_types_.size(); ++i) {
67 // To have a match, every one of the |matching_mime_types_|
68 // must be handled by the plug-in.
69 if (!PluginList::SupportsType(plugin, matching_mime_types_[i], false))
70 return false;
73 return MatchPattern(plugin.name, group_name_matcher_);
76 // static
77 bool PluginMetadata::ParseSecurityStatus(
78 const std::string& status_str,
79 PluginMetadata::SecurityStatus* status) {
80 if (status_str == "up_to_date")
81 *status = SECURITY_STATUS_UP_TO_DATE;
82 else if (status_str == "out_of_date")
83 *status = SECURITY_STATUS_OUT_OF_DATE;
84 else if (status_str == "requires_authorization")
85 *status = SECURITY_STATUS_REQUIRES_AUTHORIZATION;
86 else
87 return false;
89 return true;
92 PluginMetadata::SecurityStatus PluginMetadata::GetSecurityStatus(
93 const webkit::WebPluginInfo& plugin) const {
94 if (versions_.empty()) {
95 #if defined(OS_LINUX)
96 // On Linux, unknown plugins require authorization.
97 return SECURITY_STATUS_REQUIRES_AUTHORIZATION;
98 #else
99 return SECURITY_STATUS_UP_TO_DATE;
100 #endif
103 Version version;
104 webkit::npapi::CreateVersionFromString(plugin.version, &version);
105 if (!version.IsValid())
106 version = Version("0");
108 // |lower_bound| returns the latest version that is not newer than |version|.
109 std::map<Version, SecurityStatus, VersionComparator>::const_iterator it =
110 versions_.lower_bound(version);
111 // If there is at least one version defined, everything older than the oldest
112 // defined version is considered out-of-date.
113 if (it == versions_.end())
114 return SECURITY_STATUS_OUT_OF_DATE;
116 return it->second;
119 bool PluginMetadata::VersionComparator::operator() (const Version& lhs,
120 const Version& rhs) const {
121 // Keep versions ordered by newest (biggest) first.
122 return lhs.CompareTo(rhs) > 0;
125 scoped_ptr<PluginMetadata> PluginMetadata::Clone() const {
126 PluginMetadata* copy = new PluginMetadata(identifier_,
127 name_,
128 url_for_display_,
129 plugin_url_,
130 help_url_,
131 group_name_matcher_,
132 language_);
133 copy->versions_ = versions_;
134 return make_scoped_ptr(copy);