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