| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include <algorithm> | 5 #include <algorithm> | 
| 6 | 6 | 
| 7 #include "webkit/plugins/npapi/plugin_group.h" | 7 #include "webkit/plugins/npapi/plugin_group.h" | 
| 8 | 8 | 
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" | 
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" | 
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" | 
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" | 
| 13 #include "base/values.h" | 13 #include "base/values.h" | 
| 14 #include "base/version.h" | 14 #include "base/version.h" | 
| 15 #include "webkit/plugins/npapi/plugin_list.h" | 15 #include "webkit/plugins/npapi/plugin_list.h" | 
| 16 #include "webkit/plugins/webplugininfo.h" | 16 #include "webkit/plugins/webplugininfo.h" | 
| 17 | 17 | 
| 18 namespace webkit { | 18 namespace webkit { | 
| 19 namespace npapi { | 19 namespace npapi { | 
| 20 | 20 | 
| 21 // static | 21 // static | 
| 22 const char PluginGroup::kAdobeReaderGroupName[] = "Adobe Acrobat"; | 22 const char PluginGroup::kAdobeReaderGroupName[] = "Adobe Acrobat"; | 
| 23 const char PluginGroup::kAdobeReaderUpdateURL[] = |  | 
| 24     "http://get.adobe.com/reader/"; |  | 
| 25 const char PluginGroup::kJavaGroupName[] = "Java"; | 23 const char PluginGroup::kJavaGroupName[] = "Java"; | 
| 26 const char PluginGroup::kQuickTimeGroupName[] = "QuickTime"; | 24 const char PluginGroup::kQuickTimeGroupName[] = "QuickTime"; | 
| 27 const char PluginGroup::kShockwaveGroupName[] = "Shockwave"; | 25 const char PluginGroup::kShockwaveGroupName[] = "Shockwave"; | 
| 28 const char PluginGroup::kRealPlayerGroupName[] = "RealPlayer"; | 26 const char PluginGroup::kRealPlayerGroupName[] = "RealPlayer"; | 
| 29 const char PluginGroup::kSilverlightGroupName[] = "Silverlight"; | 27 const char PluginGroup::kSilverlightGroupName[] = "Silverlight"; | 
| 30 const char PluginGroup::kWindowsMediaPlayerGroupName[] = "Windows Media Player"; | 28 const char PluginGroup::kWindowsMediaPlayerGroupName[] = "Windows Media Player"; | 
| 31 | 29 | 
| 32 VersionRange::VersionRange(const VersionRangeDefinition& definition) | 30 VersionRange::VersionRange(const VersionRangeDefinition& definition) | 
| 33     : low_str(definition.version_matcher_low), | 31     : low_str(definition.version_matcher_low), | 
| 34       high_str(definition.version_matcher_high), | 32       high_str(definition.version_matcher_high), | 
| 35       min_str(definition.min_version), | 33       min_str(definition.min_version) { | 
| 36       requires_authorization(definition.requires_authorization) { |  | 
| 37   if (!low_str.empty()) | 34   if (!low_str.empty()) | 
| 38     low.reset(Version::GetVersionFromString(low_str)); | 35     low.reset(Version::GetVersionFromString(low_str)); | 
| 39   if (!high_str.empty()) | 36   if (!high_str.empty()) | 
| 40     high.reset(Version::GetVersionFromString(high_str)); | 37     high.reset(Version::GetVersionFromString(high_str)); | 
| 41   if (!min_str.empty()) | 38   if (!min_str.empty()) | 
| 42     min.reset(Version::GetVersionFromString(min_str)); | 39     min.reset(Version::GetVersionFromString(min_str)); | 
| 43 } | 40 } | 
| 44 | 41 | 
| 45 VersionRange::VersionRange(const VersionRange& other) { | 42 VersionRange::VersionRange(const VersionRange& other) { | 
| 46   InitFrom(other); | 43   InitFrom(other); | 
| 47 } | 44 } | 
| 48 | 45 | 
| 49 VersionRange& VersionRange::operator=(const VersionRange& other) { | 46 VersionRange& VersionRange::operator=(const VersionRange& other) { | 
| 50   InitFrom(other); | 47   InitFrom(other); | 
| 51   return *this; | 48   return *this; | 
| 52 } | 49 } | 
| 53 | 50 | 
| 54 VersionRange::~VersionRange() {} | 51 VersionRange::~VersionRange() {} | 
| 55 | 52 | 
| 56 void VersionRange::InitFrom(const VersionRange& other) { | 53 void VersionRange::InitFrom(const VersionRange& other) { | 
| 57   low_str = other.low_str; | 54   low_str = other.low_str; | 
| 58   high_str = other.high_str; | 55   high_str = other.high_str; | 
| 59   min_str = other.min_str; | 56   min_str = other.min_str; | 
| 60   low.reset(Version::GetVersionFromString(other.low_str)); | 57   low.reset(Version::GetVersionFromString(other.low_str)); | 
| 61   high.reset(Version::GetVersionFromString(other.high_str)); | 58   high.reset(Version::GetVersionFromString(other.high_str)); | 
| 62   min.reset(Version::GetVersionFromString(other.min_str)); | 59   min.reset(Version::GetVersionFromString(other.min_str)); | 
| 63   requires_authorization = other.requires_authorization; |  | 
| 64 } | 60 } | 
| 65 | 61 | 
| 66 PluginGroup::PluginGroup(const string16& group_name, | 62 PluginGroup::PluginGroup(const string16& group_name, | 
| 67                          const string16& name_matcher, | 63                          const string16& name_matcher, | 
| 68                          const std::string& update_url, |  | 
| 69                          const std::string& identifier) | 64                          const std::string& identifier) | 
| 70     : identifier_(identifier), | 65     : identifier_(identifier), | 
| 71       group_name_(group_name), | 66       group_name_(group_name), | 
| 72       name_matcher_(name_matcher), | 67       name_matcher_(name_matcher) { | 
| 73       update_url_(update_url) { |  | 
| 74 } | 68 } | 
| 75 | 69 | 
| 76 void PluginGroup::InitFrom(const PluginGroup& other) { | 70 void PluginGroup::InitFrom(const PluginGroup& other) { | 
| 77   identifier_ = other.identifier_; | 71   identifier_ = other.identifier_; | 
| 78   group_name_ = other.group_name_; | 72   group_name_ = other.group_name_; | 
| 79   name_matcher_ = other.name_matcher_; | 73   name_matcher_ = other.name_matcher_; | 
| 80   update_url_ = other.update_url_; |  | 
| 81   version_ranges_ = other.version_ranges_; | 74   version_ranges_ = other.version_ranges_; | 
| 82   web_plugin_infos_ = other.web_plugin_infos_; | 75   web_plugin_infos_ = other.web_plugin_infos_; | 
| 83 } | 76 } | 
| 84 | 77 | 
| 85 PluginGroup::PluginGroup(const PluginGroup& other) { | 78 PluginGroup::PluginGroup(const PluginGroup& other) { | 
| 86   InitFrom(other); | 79   InitFrom(other); | 
| 87 } | 80 } | 
| 88 | 81 | 
| 89 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 82 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | 
| 90   InitFrom(other); | 83   InitFrom(other); | 
| 91   return *this; | 84   return *this; | 
| 92 } | 85 } | 
| 93 | 86 | 
| 94 /*static*/ | 87 /*static*/ | 
| 95 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 88 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 
| 96     const PluginGroupDefinition& definition) { | 89     const PluginGroupDefinition& definition) { | 
| 97   PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), | 90   PluginGroup* group = new PluginGroup(ASCIIToUTF16(definition.name), | 
| 98                                        ASCIIToUTF16(definition.name_matcher), | 91                                        ASCIIToUTF16(definition.name_matcher), | 
| 99                                        definition.update_url, |  | 
| 100                                        definition.identifier); | 92                                        definition.identifier); | 
| 101   for (size_t i = 0; i < definition.num_versions; ++i) | 93   for (size_t i = 0; i < definition.num_versions; ++i) | 
| 102     group->version_ranges_.push_back(VersionRange(definition.versions[i])); | 94     group->version_ranges_.push_back(VersionRange(definition.versions[i])); | 
| 103   return group; | 95   return group; | 
| 104 } | 96 } | 
| 105 | 97 | 
| 106 PluginGroup::~PluginGroup() { } | 98 PluginGroup::~PluginGroup() { } | 
| 107 | 99 | 
| 108 /*static*/ | 100 /*static*/ | 
| 109 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | 101 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | 
| 110 #if defined(OS_POSIX) | 102 #if defined(OS_POSIX) | 
| 111   return wpi.path.BaseName().value(); | 103   return wpi.path.BaseName().value(); | 
| 112 #elif defined(OS_WIN) | 104 #elif defined(OS_WIN) | 
| 113   return base::SysWideToUTF8(wpi.path.BaseName().value()); | 105   return base::SysWideToUTF8(wpi.path.BaseName().value()); | 
| 114 #endif | 106 #endif | 
| 115 } | 107 } | 
| 116 | 108 | 
| 117 /*static*/ | 109 /*static*/ | 
| 118 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { | 110 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { | 
| 119 #if defined(OS_POSIX) | 111 #if defined(OS_POSIX) | 
| 120   return wpi.path.value(); | 112   return wpi.path.value(); | 
| 121 #elif defined(OS_WIN) | 113 #elif defined(OS_WIN) | 
| 122   return base::SysWideToUTF8(wpi.path.value()); | 114   return base::SysWideToUTF8(wpi.path.value()); | 
| 123 #endif | 115 #endif | 
| 124 } | 116 } | 
| 125 | 117 | 
| 126 /*static*/ | 118 /*static*/ | 
| 127 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 119 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 
| 128   // Create a matcher from the name of this plugin. | 120   // Create a matcher from the name of this plugin. | 
| 129   return new PluginGroup(wpi.name, wpi.name, std::string(), | 121   return new PluginGroup(wpi.name, wpi.name, | 
| 130                          GetIdentifier(wpi)); | 122                          GetIdentifier(wpi)); | 
| 131 } | 123 } | 
| 132 | 124 | 
| 133 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 125 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 
| 134   if (name_matcher_.empty()) { | 126   if (name_matcher_.empty()) { | 
| 135     return false; | 127     return false; | 
| 136   } | 128   } | 
| 137 | 129 | 
| 138   // Look for the name matcher anywhere in the plugin name. | 130   // Look for the name matcher anywhere in the plugin name. | 
| 139   if (plugin.name.find(name_matcher_) == string16::npos) { | 131   if (plugin.name.find(name_matcher_) == string16::npos) { | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249   if (!version.get()) | 241   if (!version.get()) | 
| 250     return false; | 242     return false; | 
| 251 | 243 | 
| 252   for (size_t i = 0; i < version_ranges_.size(); ++i) { | 244   for (size_t i = 0; i < version_ranges_.size(); ++i) { | 
| 253     if (IsPluginOutdated(*version, version_ranges_[i])) | 245     if (IsPluginOutdated(*version, version_ranges_[i])) | 
| 254       return true; | 246       return true; | 
| 255   } | 247   } | 
| 256   return false; | 248   return false; | 
| 257 } | 249 } | 
| 258 | 250 | 
| 259 bool PluginGroup::RequiresAuthorization(const WebPluginInfo& plugin) const { |  | 
| 260   scoped_ptr<Version> version(CreateVersionFromString(plugin.version)); |  | 
| 261   if (!version.get()) |  | 
| 262     return false; |  | 
| 263 |  | 
| 264   for (size_t i = 0; i < version_ranges_.size(); ++i) { |  | 
| 265     if (IsVersionInRange(*version, version_ranges_[i]) && |  | 
| 266         version_ranges_[i].requires_authorization) |  | 
| 267       return true; |  | 
| 268   } |  | 
| 269   return false; |  | 
| 270 } |  | 
| 271 |  | 
| 272 bool PluginGroup::IsEmpty() const { | 251 bool PluginGroup::IsEmpty() const { | 
| 273   return web_plugin_infos_.empty(); | 252   return web_plugin_infos_.empty(); | 
| 274 } | 253 } | 
| 275 | 254 | 
| 276 }  // namespace npapi | 255 }  // namespace npapi | 
| 277 }  // namespace webkit | 256 }  // namespace webkit | 
| OLD | NEW | 
|---|