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"
9 #include "base/logging.h"
10 #include "base/strings/string_util.h"
11 #include "content/public/common/webplugininfo.h"
14 const char PluginMetadata::kAdobeReaderGroupName
[] = "Adobe Reader";
15 const char PluginMetadata::kJavaGroupName
[] = "Java(TM)";
16 const char PluginMetadata::kQuickTimeGroupName
[] = "QuickTime Player";
17 const char PluginMetadata::kShockwaveGroupName
[] = "Adobe Shockwave Player";
18 const char PluginMetadata::kRealPlayerGroupName
[] = "RealPlayer";
19 const char PluginMetadata::kSilverlightGroupName
[] = "Silverlight";
20 const char PluginMetadata::kWindowsMediaPlayerGroupName
[] =
21 "Windows Media Player";
22 const char PluginMetadata::kGoogleTalkGroupName
[] = "Google Talk";
23 const char PluginMetadata::kGoogleEarthGroupName
[] = "Google Earth";
25 PluginMetadata::PluginMetadata(const std::string
& identifier
,
26 const base::string16
& name
,
28 const GURL
& plugin_url
,
30 const base::string16
& group_name_matcher
,
31 const std::string
& language
)
32 : identifier_(identifier
),
34 group_name_matcher_(group_name_matcher
),
35 url_for_display_(url_for_display
),
36 plugin_url_(plugin_url
),
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 content::WebPluginInfo
& plugin
) {
64 for (size_t i
= 0; i
< matching_mime_types_
.size(); ++i
) {
65 // To have a match, every one of the |matching_mime_types_|
66 // must be handled by the plugin.
68 for (; j
< plugin
.mime_types
.size(); ++j
) {
69 if (plugin
.mime_types
[j
].mime_type
== matching_mime_types_
[i
])
72 if (j
== plugin
.mime_types
.size())
76 return MatchPattern(plugin
.name
, group_name_matcher_
);
80 bool PluginMetadata::ParseSecurityStatus(
81 const std::string
& status_str
,
82 PluginMetadata::SecurityStatus
* status
) {
83 if (status_str
== "up_to_date")
84 *status
= SECURITY_STATUS_UP_TO_DATE
;
85 else if (status_str
== "out_of_date")
86 *status
= SECURITY_STATUS_OUT_OF_DATE
;
87 else if (status_str
== "requires_authorization")
88 *status
= SECURITY_STATUS_REQUIRES_AUTHORIZATION
;
95 PluginMetadata::SecurityStatus
PluginMetadata::GetSecurityStatus(
96 const content::WebPluginInfo
& plugin
) const {
97 if (versions_
.empty()) {
98 // Unknown plugins require authorization.
99 return SECURITY_STATUS_REQUIRES_AUTHORIZATION
;
103 content::WebPluginInfo::CreateVersionFromString(plugin
.version
, &version
);
104 if (!version
.IsValid())
105 version
= Version("0");
107 // |lower_bound| returns the latest version that is not newer than |version|.
108 std::map
<Version
, SecurityStatus
, VersionComparator
>::const_iterator it
=
109 versions_
.lower_bound(version
);
110 // If there is at least one version defined, everything older than the oldest
111 // defined version is considered out-of-date.
112 if (it
== versions_
.end())
113 return SECURITY_STATUS_OUT_OF_DATE
;
118 bool PluginMetadata::VersionComparator::operator() (const Version
& lhs
,
119 const Version
& rhs
) const {
120 // Keep versions ordered by newest (biggest) first.
121 return lhs
.CompareTo(rhs
) > 0;
124 scoped_ptr
<PluginMetadata
> PluginMetadata::Clone() const {
125 PluginMetadata
* copy
= new PluginMetadata(identifier_
,
132 copy
->versions_
= versions_
;
133 return make_scoped_ptr(copy
);