| OLD | NEW | 
|---|
| (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/plugins/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 (versions_.empty()) { | 
|  | 57 #if defined(OS_LINUX) | 
|  | 58     // On Linux, unknown plugins require authorization. | 
|  | 59     return SECURITY_STATUS_REQUIRES_AUTHORIZATION; | 
|  | 60 #else | 
|  | 61     return SECURITY_STATUS_UP_TO_DATE; | 
|  | 62 #endif | 
|  | 63   } | 
|  | 64 | 
|  | 65   Version version; | 
|  | 66   webkit::npapi::CreateVersionFromString(plugin.version, &version); | 
|  | 67   if (!version.IsValid()) | 
|  | 68     version = Version("0"); | 
|  | 69 | 
|  | 70   // |lower_bound| returns the latest version that is not newer than |version|. | 
|  | 71   std::map<Version, SecurityStatus, VersionComparator>::const_iterator it = | 
|  | 72       versions_.lower_bound(version); | 
|  | 73   // If there is at least one version defined, everything older than the oldest | 
|  | 74   // defined version is considered out-of-date. | 
|  | 75   if (it == versions_.end()) | 
|  | 76     return SECURITY_STATUS_OUT_OF_DATE; | 
|  | 77 | 
|  | 78   return it->second; | 
|  | 79 } | 
|  | 80 | 
|  | 81 bool PluginMetadata::VersionComparator::operator() (const Version& lhs, | 
|  | 82                                                     const Version& rhs) const { | 
|  | 83   // Keep versions ordered by newest (biggest) first. | 
|  | 84   return lhs.CompareTo(rhs) > 0; | 
|  | 85 } | 
| OLD | NEW | 
|---|