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

Unified Diff: chrome/browser/plugins/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/plugins/plugin_metadata.h ('k') | chrome/browser/plugins/plugin_metadata_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/plugins/plugin_metadata.cc
diff --git a/chrome/browser/plugins/plugin_metadata.cc b/chrome/browser/plugins/plugin_metadata.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8dfd03e2baf6070670e125f3cfcdb5d8dffb590
--- /dev/null
+++ b/chrome/browser/plugins/plugin_metadata.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/plugins/plugin_metadata.h"
+
+#include "base/logging.h"
+#include "webkit/plugins/npapi/plugin_utils.h"
+#include "webkit/plugins/webplugininfo.h"
+
+PluginMetadata::PluginMetadata(const std::string& identifier,
+ const string16& name,
+ bool url_for_display,
+ const GURL& plugin_url,
+ const GURL& help_url,
+ const string16& group_name_matcher)
+ : identifier_(identifier),
+ name_(name),
+ group_name_matcher_(group_name_matcher),
+ url_for_display_(url_for_display),
+ plugin_url_(plugin_url),
+ help_url_(help_url) {
+}
+
+PluginMetadata::~PluginMetadata() {
+}
+
+void PluginMetadata::AddVersion(const Version& version,
+ SecurityStatus status) {
+ DCHECK(versions_.find(version) == versions_.end());
+ versions_[version] = status;
+}
+
+bool PluginMetadata::MatchesPlugin(const webkit::WebPluginInfo& plugin) {
+ return plugin.name.find(group_name_matcher_) != string16::npos;
+}
+
+// static
+bool PluginMetadata::ParseSecurityStatus(
+ const std::string& status_str,
+ PluginMetadata::SecurityStatus* status) {
+ if (status_str == "up_to_date")
+ *status = SECURITY_STATUS_UP_TO_DATE;
+ else if (status_str == "out_of_date")
+ *status = SECURITY_STATUS_OUT_OF_DATE;
+ else if (status_str == "requires_authorization")
+ *status = SECURITY_STATUS_REQUIRES_AUTHORIZATION;
+ else
+ return false;
+
+ return true;
+}
+
+PluginMetadata::SecurityStatus PluginMetadata::GetSecurityStatus(
+ const webkit::WebPluginInfo& plugin) const {
+ if (versions_.empty()) {
+#if defined(OS_LINUX)
+ // On Linux, unknown plugins require authorization.
+ return SECURITY_STATUS_REQUIRES_AUTHORIZATION;
+#else
+ return SECURITY_STATUS_UP_TO_DATE;
+#endif
+ }
+
+ Version version;
+ webkit::npapi::CreateVersionFromString(plugin.version, &version);
+ if (!version.IsValid())
+ version = Version("0");
+
+ // |lower_bound| returns the latest version that is not newer than |version|.
+ std::map<Version, SecurityStatus, VersionComparator>::const_iterator it =
+ versions_.lower_bound(version);
+ // If there is at least one version defined, everything older than the oldest
+ // defined version is considered out-of-date.
+ if (it == versions_.end())
+ return SECURITY_STATUS_OUT_OF_DATE;
+
+ return it->second;
+}
+
+bool PluginMetadata::VersionComparator::operator() (const Version& lhs,
+ const Version& rhs) const {
+ // Keep versions ordered by newest (biggest) first.
+ return lhs.CompareTo(rhs) > 0;
+}
« no previous file with comments | « chrome/browser/plugins/plugin_metadata.h ('k') | chrome/browser/plugins/plugin_metadata_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698