Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/browser/plugin_metadata.cc

Issue 10910168: Separate plugin_metadata from plugin_installer, thread-safe plugin_finder (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/plugin_metadata.h"
6
7 #include "base/logging.h"
8 #include "webkit/plugins/npapi/plugin_utils.h"
9 #include "webkit/plugins/webplugininfo.h"
10
11 PluginMetadata::PluginMetadata(const std::string& identifier,
12 const string16& name,
13 bool url_for_display,
14 const GURL& plugin_url,
15 const GURL& help_url,
16 const string16& group_name_matcher)
17 : identifier_(identifier),
18 name_(name),
19 group_name_matcher_(group_name_matcher),
20 url_for_display_(url_for_display),
21 plugin_url_(plugin_url),
22 help_url_(help_url) {
23 }
24
25 PluginMetadata::~PluginMetadata() {
26 }
27
28 void PluginMetadata::AddVersion(const Version& version,
29 SecurityStatus status) {
30 DCHECK(versions_.find(version) == versions_.end());
31 versions_[version] = status;
32 }
33
34 bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) {
35 return plugin.name.find(group_name_matcher_) != string16::npos;
36 }
37
38 // static
39 bool PluginMetadata::ParseSecurityStatus(
40 const std::string& status_str,
41 PluginMetadata::SecurityStatus* status) {
42 if (status_str == "up_to_date")
43 *status = SECURITY_STATUS_UP_TO_DATE;
44 else if (status_str == "out_of_date")
45 *status = SECURITY_STATUS_OUT_OF_DATE;
46 else if (status_str == "requires_authorization")
47 *status = SECURITY_STATUS_REQUIRES_AUTHORIZATION;
48 else
49 return false;
50
51 return true;
52 }
53
54 PluginMetadata::SecurityStatus PluginMetadata::GetSecurityStatus(
55 const webkit::WebPluginInfo& plugin) const {
56 // If there are no versions defined, the plug-in should require authorization.
57 if (versions_.empty())
58 return SECURITY_STATUS_REQUIRES_AUTHORIZATION;
59
60 Version version;
61 webkit::npapi::CreateVersionFromString(plugin.version, &version);
62 if (!version.IsValid())
63 version = Version("0");
64
65 // |lower_bound| returns the latest version that is not newer than |version|.
66 std::map<Version, SecurityStatus, VersionComparator>::const_iterator it =
67 versions_.lower_bound(version);
68 // If there is at least one version defined, everything older than the oldest
69 // defined version is considered out-of-date.
70 if (it == versions_.end())
71 return SECURITY_STATUS_OUT_OF_DATE;
72
73 return it->second;
74 }
75
76 bool PluginMetadata::VersionComparator::operator() (const Version& lhs,
77 const Version& rhs) const {
78 // Keep versions ordered by newest (biggest) first.
79 return lhs.CompareTo(rhs) > 0;
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698