[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / plugins / plugin_metadata.cc
blobdabc7d11bda28229775a2b0fb9ba398a73a1551a
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/strings/string_util.h"
11 #include "content/public/common/webplugininfo.h"
13 // static
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,
27 bool url_for_display,
28 const GURL& plugin_url,
29 const GURL& help_url,
30 const base::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 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.
67 size_t j = 0;
68 for (; j < plugin.mime_types.size(); ++j) {
69 if (plugin.mime_types[j].mime_type == matching_mime_types_[i])
70 break;
72 if (j == plugin.mime_types.size())
73 return false;
76 return MatchPattern(plugin.name, group_name_matcher_);
79 // static
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;
89 else
90 return false;
92 return true;
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;
102 Version version;
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;
115 return it->second;
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_,
126 name_,
127 url_for_display_,
128 plugin_url_,
129 help_url_,
130 group_name_matcher_,
131 language_);
132 copy->versions_ = versions_;
133 return make_scoped_ptr(copy);