OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/plugin_group.h" | 5 #include "webkit/glue/plugins/plugin_group.h" |
6 | 6 |
7 #include "base/linked_ptr.h" | 7 #include "base/linked_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "webkit/glue/plugins/plugin_list.h" | 13 #include "webkit/glue/plugins/plugin_list.h" |
14 #include "webkit/glue/plugins/webplugininfo.h" | 14 #include "webkit/glue/plugins/webplugininfo.h" |
15 | 15 |
16 const char* PluginGroup::kAdobeReader8GroupName = "Adobe Reader 8"; | 16 const char* PluginGroup::kAdobeReader8GroupName = "Adobe Reader 8"; |
17 const char* PluginGroup::kAdobeReader9GroupName = "Adobe Reader 9"; | 17 const char* PluginGroup::kAdobeReader9GroupName = "Adobe Reader 9"; |
18 | 18 |
19 #if defined(OS_MACOSX) | |
20 // Plugin Groups for Mac. | |
21 // Plugins are listed here as soon as vulnerabilities and solutions | |
22 // (new versions) are published. | |
23 // TODO(panayiotis): Get the Real Player version on Mac, somehow. | |
24 static const PluginGroupDefinition kGroupDefinitions[] = { | |
25 { "apple-quicktime", "Quicktime", "QuickTime Plug-in", "", "", "7.6.6", | |
26 "http://www.apple.com/quicktime/download/" }, | |
27 { "java-runtime-environment", "Java", "Java", "", "", "", | |
28 "http://support.apple.com/kb/HT1338" }, | |
29 { "adobe-flash-player", "Flash", "Shockwave Flash", "", "", "10.1.102", | |
30 "http://get.adobe.com/flashplayer/" }, | |
31 { "silverlight-3", "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0", | |
32 "http://www.microsoft.com/getsilverlight/" }, | |
33 { "silverlight-4", "Silverlight 4", "Silverlight", "4", "5", "", | |
34 "http://www.microsoft.com/getsilverlight/" }, | |
35 { "flip4mac", "Flip4Mac", "Flip4Mac", "", "", "2.2.1", | |
36 "http://www.telestream.net/flip4mac-wmv/overview.htm" }, | |
37 { "shockwave", "Shockwave", "Shockwave for Director", "", "", "11.5.9.615", | |
38 "http://www.adobe.com/shockwave/download/" } | |
39 }; | |
40 | |
41 #elif defined(OS_WIN) | |
42 // TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of | |
43 // the RealPlayer files. | |
44 static const PluginGroupDefinition kGroupDefinitions[] = { | |
45 { "apple-quicktime", "Quicktime", "QuickTime Plug-in", "", "", "7.6.8", | |
46 "http://www.apple.com/quicktime/download/" }, | |
47 { "java-runtime-environment", "Java 6", "Java", "", "6", "6.0.220", | |
48 "http://www.java.com/" }, | |
49 { "adobe-reader", PluginGroup::kAdobeReader9GroupName, "Adobe Acrobat", "9", | |
50 "10", "9.4.1", "http://get.adobe.com/reader/" }, | |
51 { "adobe-reader-8", PluginGroup::kAdobeReader8GroupName, "Adobe Acrobat", "0", | |
52 "9", "8.2.5", "http://get.adobe.com/reader/" }, | |
53 { "adobe-flash-player", "Flash", "Shockwave Flash", "", "", "10.1.102", | |
54 "http://get.adobe.com/flashplayer/" }, | |
55 { "silverlight-3", "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0", | |
56 "http://www.microsoft.com/getsilverlight/" }, | |
57 { "silverlight-4", "Silverlight 4", "Silverlight", "4", "5", "", | |
58 "http://www.microsoft.com/getsilverlight/" }, | |
59 { "shockwave", "Shockwave", "Shockwave for Director", "", "", "11.5.9.615", | |
60 "http://www.adobe.com/shockwave/download/" }, | |
61 { "divx-player", "DivX Player", "DivX Web Player", "", "", "1.4.3.4", | |
62 "http://download.divx.com/divx/autoupdate/player/" | |
63 "DivXWebPlayerInstaller.exe" }, | |
64 // These are here for grouping, no vulnerabilies known. | |
65 { "windows-media-player", "Windows Media Player", "Windows Media Player", | |
66 "", "", "", "" }, | |
67 { "microsoft-office", "Microsoft Office", "Microsoft Office", | |
68 "", "", "", "" }, | |
69 // TODO(panayiotis): The vulnerable versions are | |
70 // (v >= 6.0.12.1040 && v <= 6.0.12.1663) | |
71 // || v == 6.0.12.1698 || v == 6.0.12.1741 | |
72 { "realplayer", "RealPlayer", "RealPlayer", "", "", "", | |
73 "http://www.adobe.com/shockwave/download/" }, | |
74 }; | |
75 | |
76 #else | |
77 static const PluginGroupDefinition kGroupDefinitions[] = {}; | |
78 #endif | |
79 | |
80 /*static*/ | 19 /*static*/ |
81 std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_; | 20 std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_; |
82 | 21 |
83 /*static*/ | 22 /*static*/ |
84 const PluginGroupDefinition* PluginGroup::GetPluginGroupDefinitions() { | |
85 return kGroupDefinitions; | |
86 } | |
87 | |
88 /*static*/ | |
89 size_t PluginGroup::GetPluginGroupDefinitionsSize() { | |
90 // TODO(viettrungluu): |arraysize()| doesn't work with zero-size arrays. | |
91 return ARRAYSIZE_UNSAFE(kGroupDefinitions); | |
92 } | |
93 | |
94 /*static*/ | |
95 void PluginGroup::SetPolicyDisabledPluginPatterns( | 23 void PluginGroup::SetPolicyDisabledPluginPatterns( |
96 const std::set<string16>& set) { | 24 const std::set<string16>& set) { |
97 if (!policy_disabled_plugin_patterns_) | 25 if (!policy_disabled_plugin_patterns_) |
98 policy_disabled_plugin_patterns_ = new std::set<string16>(set); | 26 policy_disabled_plugin_patterns_ = new std::set<string16>(set); |
99 else | 27 else |
100 *policy_disabled_plugin_patterns_ = set; | 28 *policy_disabled_plugin_patterns_ = set; |
101 } | 29 } |
102 | 30 |
103 /*static*/ | 31 /*static*/ |
104 bool PluginGroup::IsPluginNameDisabledByPolicy(const string16& plugin_name) { | 32 bool PluginGroup::IsPluginNameDisabledByPolicy(const string16& plugin_name) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 if (!version_range_low.empty()) | 78 if (!version_range_low.empty()) |
151 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); | 79 version_range_low_.reset(Version::GetVersionFromString(version_range_low)); |
152 if (!version_range_high.empty()) { | 80 if (!version_range_high.empty()) { |
153 version_range_high_.reset( | 81 version_range_high_.reset( |
154 Version::GetVersionFromString(version_range_high)); | 82 Version::GetVersionFromString(version_range_high)); |
155 } | 83 } |
156 if (!min_version.empty()) | 84 if (!min_version.empty()) |
157 min_version_.reset(Version::GetVersionFromString(min_version)); | 85 min_version_.reset(Version::GetVersionFromString(min_version)); |
158 } | 86 } |
159 | 87 |
88 void PluginGroup::InitFrom(const PluginGroup& other) { | |
89 identifier_ = other.identifier_; | |
90 group_name_ = other.group_name_; | |
91 name_matcher_ = other.name_matcher_; | |
92 version_range_low_str_ = other.version_range_low_str_; | |
93 version_range_high_str_ = other.version_range_high_str_; | |
94 version_range_low_.reset( | |
95 Version::GetVersionFromString(version_range_low_str_)); | |
96 version_range_high_.reset( | |
97 Version::GetVersionFromString(version_range_high_str_)); | |
98 description_ = other.description_; | |
99 update_url_ = other.update_url_; | |
100 enabled_ = other.enabled_; | |
101 min_version_str_ = other.min_version_str_; | |
102 min_version_.reset(Version::GetVersionFromString(min_version_str_)); | |
103 DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); | |
Bernhard Bauer
2010/12/07 12:09:51
Nit: Use DCHECK_EQ(expected, actual) for nicer err
Jakob Kummerow
2010/12/07 17:08:56
Done.
| |
104 for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) | |
105 AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); | |
106 if (!version_.get()) | |
107 version_.reset(Version::GetVersionFromString("0")); | |
108 } | |
109 | |
110 PluginGroup::PluginGroup(const PluginGroup& other) { | |
111 InitFrom(other); | |
112 } | |
113 | |
114 PluginGroup& PluginGroup::operator=(const PluginGroup& other) { | |
115 InitFrom(other); | |
116 return *this; | |
117 } | |
118 | |
119 /*static*/ | |
160 PluginGroup* PluginGroup::FromPluginGroupDefinition( | 120 PluginGroup* PluginGroup::FromPluginGroupDefinition( |
161 const PluginGroupDefinition& definition) { | 121 const PluginGroupDefinition& definition) { |
162 return new PluginGroup(ASCIIToUTF16(definition.name), | 122 return new PluginGroup(ASCIIToUTF16(definition.name), |
163 ASCIIToUTF16(definition.name_matcher), | 123 ASCIIToUTF16(definition.name_matcher), |
164 definition.version_matcher_low, | 124 definition.version_matcher_low, |
165 definition.version_matcher_high, | 125 definition.version_matcher_high, |
166 definition.min_version, | 126 definition.min_version, |
167 definition.update_url, | 127 definition.update_url, |
168 definition.identifier); | 128 definition.identifier); |
169 } | 129 } |
170 | 130 |
171 PluginGroup::~PluginGroup() { } | 131 PluginGroup::~PluginGroup() { } |
172 | 132 |
133 /*static*/ | |
134 std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { | |
135 #if defined(OS_POSIX) | |
136 return wpi.path.BaseName().value(); | |
137 #elif defined(OS_WIN) | |
138 return base::SysWideToUTF8(wpi.path.BaseName().value()); | |
139 #endif | |
140 } | |
141 | |
142 /*static*/ | |
143 std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { | |
144 #if defined(OS_POSIX) | |
145 return wpi.path.value(); | |
146 #elif defined(OS_WIN) | |
147 return base::SysWideToUTF8(wpi.path.value()); | |
148 #endif | |
149 } | |
150 | |
151 /*static*/ | |
173 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { | 152 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
174 // Create a matcher from the name of this plugin. | 153 // Create a matcher from the name of this plugin. |
175 #if defined(OS_POSIX) | |
176 std::string identifier = wpi.path.BaseName().value(); | |
177 #elif defined(OS_WIN) | |
178 std::string identifier = base::SysWideToUTF8(wpi.path.BaseName().value()); | |
179 #endif | |
180 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), | 154 return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), |
181 std::string(), std::string(), identifier); | 155 std::string(), std::string(), |
182 } | 156 GetIdentifier(wpi)); |
183 | |
184 PluginGroup* PluginGroup::CopyOrCreatePluginGroup( | |
185 const WebPluginInfo& info) { | |
186 static PluginMap* hardcoded_plugin_groups = NULL; | |
187 if (!hardcoded_plugin_groups) { | |
188 PluginMap* groups = new PluginMap(); | |
189 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | |
190 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | |
191 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | |
192 definitions[i]); | |
193 std::string identifier = definition_group->identifier(); | |
194 DCHECK(groups->find(identifier) == groups->end()); | |
195 (*groups)[identifier] = linked_ptr<PluginGroup>(definition_group); | |
196 } | |
197 hardcoded_plugin_groups = groups; | |
198 } | |
199 | |
200 // See if this plugin matches any of the hardcoded groups. | |
201 PluginGroup* hardcoded_group = FindGroupMatchingPlugin( | |
202 *hardcoded_plugin_groups, info); | |
203 if (hardcoded_group) { | |
204 // Make a copy. | |
205 return hardcoded_group->Copy(); | |
206 } else { | |
207 // Not found in our hardcoded list, create a new one. | |
208 return PluginGroup::FromWebPluginInfo(info); | |
209 } | |
210 } | |
211 | |
212 PluginGroup* PluginGroup::FindGroupMatchingPlugin( | |
213 const PluginMap& plugin_groups, | |
214 const WebPluginInfo& plugin) { | |
215 for (std::map<std::string, linked_ptr<PluginGroup> >::const_iterator it = | |
216 plugin_groups.begin(); | |
217 it != plugin_groups.end(); | |
218 ++it) { | |
219 if (it->second->Match(plugin)) | |
220 return it->second.get(); | |
221 } | |
222 return NULL; | |
223 } | 157 } |
224 | 158 |
225 bool PluginGroup::Match(const WebPluginInfo& plugin) const { | 159 bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
226 if (name_matcher_.empty()) { | 160 if (name_matcher_.empty()) { |
227 return false; | 161 return false; |
228 } | 162 } |
229 | 163 |
230 // Look for the name matcher anywhere in the plugin name. | 164 // Look for the name matcher anywhere in the plugin name. |
231 if (plugin.name.find(name_matcher_) == string16::npos) { | 165 if (plugin.name.find(name_matcher_) == string16::npos) { |
232 return false; | 166 return false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 | 214 |
281 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { | 215 void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
282 description_ = plugin.desc; | 216 description_ = plugin.desc; |
283 if (Version* new_version = CreateVersionFromString(plugin.version)) | 217 if (Version* new_version = CreateVersionFromString(plugin.version)) |
284 version_.reset(new_version); | 218 version_.reset(new_version); |
285 else | 219 else |
286 version_.reset(Version::GetVersionFromString("0")); | 220 version_.reset(Version::GetVersionFromString("0")); |
287 } | 221 } |
288 | 222 |
289 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { | 223 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
224 // Check if this group already contains this plugin. | |
225 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { | |
226 if (web_plugin_infos_[i].name == plugin.name && | |
227 web_plugin_infos_[i].version == plugin.version && | |
228 FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), | |
229 plugin.path.value())) { | |
230 return; | |
231 } | |
232 } | |
290 web_plugin_infos_.push_back(plugin); | 233 web_plugin_infos_.push_back(plugin); |
291 // The position of this plugin relative to the global list of plugins. | 234 // The position of this plugin relative to the global list of plugins. |
292 web_plugin_positions_.push_back(position); | 235 web_plugin_positions_.push_back(position); |
293 UpdateActivePlugin(plugin); | 236 UpdateActivePlugin(plugin); |
294 } | 237 } |
295 | 238 |
296 string16 PluginGroup::GetGroupName() const { | 239 string16 PluginGroup::GetGroupName() const { |
297 if (!group_name_.empty()) | 240 if (!group_name_.empty()) |
298 return group_name_; | 241 return group_name_; |
299 DCHECK_EQ(1u, web_plugin_infos_.size()); | 242 DCHECK_EQ(1u, web_plugin_infos_.size()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 scoped_ptr<Version> version(CreateVersionFromString(it->version)); | 343 scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
401 if (version.get() && version->CompareTo(*min_version_) < 0) { | 344 if (version.get() && version->CompareTo(*min_version_) < 0) { |
402 it->enabled = false; | 345 it->enabled = false; |
403 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 346 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
404 } | 347 } |
405 UpdateActivePlugin(*it); | 348 UpdateActivePlugin(*it); |
406 } | 349 } |
407 } | 350 } |
408 | 351 |
409 void PluginGroup::Enable(bool enable) { | 352 void PluginGroup::Enable(bool enable) { |
410 for (std::vector<WebPluginInfo>::const_iterator it = | 353 bool enabled_plugin_exists = false; |
354 for (std::vector<WebPluginInfo>::iterator it = | |
411 web_plugin_infos_.begin(); | 355 web_plugin_infos_.begin(); |
412 it != web_plugin_infos_.end(); ++it) { | 356 it != web_plugin_infos_.end(); ++it) { |
413 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { | 357 if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
414 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); | 358 NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
359 it->enabled = true; | |
360 enabled_plugin_exists = true; | |
415 } else { | 361 } else { |
362 it->enabled = false; | |
416 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); | 363 NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
417 } | 364 } |
418 } | 365 } |
366 enabled_ = enabled_plugin_exists; | |
419 } | 367 } |
OLD | NEW |