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

Side by Side Diff: chrome/browser/plugin_updater.cc

Issue 2811037: Group plugins in about:plugins and show update link for out-of-date ones. (Closed) Base URL: git://codf21.jail.google.com/chromium.git
Patch Set: Fix some HTML issues. Created 10 years, 5 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/plugin_updater.h ('k') | chrome/browser/plugin_updater_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/plugin_updater.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/path_service.h"
11 #include "base/scoped_ptr.h"
12 #include "base/string_util.h"
13 #include "base/values.h"
14 #include "base/version.h"
15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/pref_service.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/browser/profile.h"
19 #include "chrome/common/pref_names.h"
20 #include "webkit/glue/plugins/plugin_list.h"
21 #include "webkit/glue/plugins/webplugininfo.h"
22
23 /*private*/
24 PluginGroup::PluginGroup(const string16& group_name,
25 const string16& name_matcher,
26 const std::string& version_range_low,
27 const std::string& version_range_high,
28 const std::string& min_version,
29 const std::string& update_url) {
30 group_name_ = group_name;
31 name_matcher_ = name_matcher;
32 version_range_low_str_ = version_range_low;
33 if (!version_range_low.empty()) {
34 version_range_low_.reset(
35 Version::GetVersionFromString(version_range_low));
36 }
37 version_range_high_str_ = version_range_high;
38 if (!version_range_high.empty()) {
39 version_range_high_.reset(
40 Version::GetVersionFromString(version_range_high));
41 }
42 min_version_str_ = min_version;
43 if (!min_version.empty()) {
44 min_version_.reset(Version::GetVersionFromString(min_version));
45 }
46 update_url_ = update_url;
47 enabled_ = false;
48 max_version_.reset(Version::GetVersionFromString("0"));
49 }
50
51 PluginGroup* PluginGroup::FromPluginGroupDefinition(
52 const PluginGroupDefinition& definition) {
53 return new PluginGroup(ASCIIToUTF16(definition.name),
54 ASCIIToUTF16(definition.name_matcher),
55 definition.version_matcher_low,
56 definition.version_matcher_high,
57 definition.min_version,
58 definition.update_url);
59 }
60
61 PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) {
62 // Create a matcher from the name of this plugin.
63 return new PluginGroup(wpi.name, wpi.name,
64 "", "", "", "");
65 }
66
67 PluginGroup* PluginGroup::Copy() {
68 return new PluginGroup(group_name_, name_matcher_, version_range_low_str_,
69 version_range_high_str_, min_version_str_,
70 update_url_);
71 }
72
73 const string16 PluginGroup::GetGroupName() const {
74 return group_name_;
75 }
76
77 bool PluginGroup::Match(const WebPluginInfo& plugin) const {
78 if (name_matcher_.empty()) {
79 return false;
80 }
81
82 // Look for the name matcher anywhere in the plugin name.
83 if (plugin.name.find(name_matcher_) == string16::npos) {
84 return false;
85 }
86
87 if (version_range_low_.get() == NULL ||
88 version_range_high_.get() == NULL) {
89 return true;
90 }
91
92 // There's a version range, we must be in it.
93 scoped_ptr<Version> plugin_version(
94 Version::GetVersionFromString(UTF16ToWide(plugin.version)));
95 if (plugin_version.get() == NULL) {
96 // No version could be extracted, assume we don't match the range.
97 return false;
98 }
99
100 // We match if we are in the range: [low, high)
101 return (version_range_low_->CompareTo(*plugin_version) <= 0 &&
102 version_range_high_->CompareTo(*plugin_version) > 0);
103 }
104
105 void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) {
106 web_plugin_infos_.push_back(plugin);
107 // The position of this plugin relative to the global list of plugins.
108 web_plugin_positions_.push_back(position);
109 description_ = plugin.desc;
110
111 // A group is enabled if any of the files are enabled.
112 if (plugin.enabled) {
113 enabled_ = true;
114 }
115
116 // update max_version_. Remove spaces and ')' from the version string,
117 // Replace any instances of 'r', ',' or '(' with a dot.
118 std::wstring version = UTF16ToWide(plugin.version);
119 RemoveChars(version, L") ", &version);
120 std::replace(version.begin(), version.end(), 'r', '.');
121 std::replace(version.begin(), version.end(), ',', '.');
122 std::replace(version.begin(), version.end(), '(', '.');
123
124 scoped_ptr<Version> plugin_version(
125 Version::GetVersionFromString(version));
126 if (plugin_version.get() != NULL) {
127 if (plugin_version->CompareTo(*(max_version_)) > 0) {
128 max_version_.reset(plugin_version.release());
129 }
130 }
131 }
132
133 DictionaryValue* PluginGroup::GetSummary() const {
134 DictionaryValue* result = new DictionaryValue();
135 result->SetStringFromUTF16(L"name", group_name_);
136 result->SetBoolean(L"enabled", enabled_);
137 return result;
138 }
139
140 DictionaryValue* PluginGroup::GetData() const {
141 DictionaryValue* result = new DictionaryValue();
142 result->SetStringFromUTF16(L"name", group_name_);
143 result->SetStringFromUTF16(L"description", description_);
144 result->SetString(L"version", max_version_->GetString());
145 result->SetString(L"update_url", update_url_);
146 result->SetBoolean(L"critical", IsVulnerable());
147 result->SetBoolean(L"enabled", enabled_);
148
149 ListValue* plugin_files = new ListValue();
150 for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
151 const WebPluginInfo& web_plugin = web_plugin_infos_[i];
152 int priority = web_plugin_positions_[i];
153 DictionaryValue* plugin_file = new DictionaryValue();
154 plugin_file->SetStringFromUTF16(L"name", web_plugin.name);
155 plugin_file->SetStringFromUTF16(L"description", web_plugin.desc);
156 plugin_file->SetString(L"path", web_plugin.path.value());
157 plugin_file->SetStringFromUTF16(L"version", web_plugin.version);
158 plugin_file->SetBoolean(L"enabled", web_plugin.enabled);
159 plugin_file->SetInteger(L"priority", priority);
160
161 ListValue* mime_types = new ListValue();
162 for (std::vector<WebPluginMimeType>::const_iterator type_it =
163 web_plugin.mime_types.begin();
164 type_it != web_plugin.mime_types.end();
165 ++type_it) {
166 DictionaryValue* mime_type = new DictionaryValue();
167 mime_type->SetString(L"mimeType", type_it->mime_type);
168 mime_type->SetStringFromUTF16(L"description", type_it->description);
169
170 ListValue* file_extensions = new ListValue();
171 for (std::vector<std::string>::const_iterator ext_it =
172 type_it->file_extensions.begin();
173 ext_it != type_it->file_extensions.end();
174 ++ext_it) {
175 file_extensions->Append(new StringValue(*ext_it));
176 }
177 mime_type->Set(L"fileExtensions", file_extensions);
178
179 mime_types->Append(mime_type);
180 }
181 plugin_file->Set(L"mimeTypes", mime_types);
182
183 plugin_files->Append(plugin_file);
184 }
185 result->Set(L"plugin_files", plugin_files);
186
187 return result;
188 }
189
190 // Returns true if the latest version of this plugin group is vulnerable.
191 bool PluginGroup::IsVulnerable() const {
192 if (min_version_.get() == NULL || max_version_->GetString() == "0") {
193 return false;
194 }
195 return max_version_->CompareTo(*min_version_) < 0;
196 }
197
198 void PluginGroup::Enable(bool enable) {
199 for (std::vector<WebPluginInfo>::const_iterator it =
200 web_plugin_infos_.begin();
201 it != web_plugin_infos_.end(); ++it) {
202 if (enable) {
203 NPAPI::PluginList::Singleton()->EnablePlugin(
204 FilePath(it->path));
205 } else {
206 NPAPI::PluginList::Singleton()->DisablePlugin(
207 FilePath(it->path));
208 }
209 }
210 }
211
212 #if defined(OS_MACOSX)
213 // Plugin Groups for Mac.
214 // Plugins are listed here as soon as vulnerabilities and solutions
215 // (new versions) are published.
216 // TODO(panayiotis): Track Java as soon as it's supported on Chrome Mac.
217 // TODO(panayiotis): Get the Real Player version on Mac, somehow.
218 static const PluginGroupDefinition kGroupDefinitions[] = {
219 { "Quicktime", "QuickTime Plug-in", "", "", "7.6.6",
220 "http://www.apple.com/quicktime/download/" },
221 { "Flash", "Shockwave Flash", "", "", "10.0.45",
222 "http://get.adobe.com/flashplayer/" },
223 { "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0",
224 "http://go.microsoft.com/fwlink/?LinkID=185927" },
225 { "Silverlight 4", "Silverlight", "4", "5", "",
226 "http://go.microsoft.com/fwlink/?LinkID=185927" },
227 { "Flip4Mac", "Flip4Mac", "", "", "2.2.1",
228 "http://www.telestream.net/flip4mac-wmv/overview.htm" },
229 { "Shockwave", "Shockwave for Director", "", "", "11.5.7.609",
230 "http://www.adobe.com/shockwave/download/" }
231 };
232
233 #elif defined(OS_WIN)
234 // TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of
235 // the RealPlayer files.
236 static const PluginGroupDefinition kGroupDefinitions[] = {
237 { "Quicktime", "QuickTime Plug-in", "", "", "7.6.6",
238 "http://www.apple.com/quicktime/download/" },
239 { "Java 6", "Java", "", "6", "6.0.200",
240 "http://www.java.com/" },
241 { "Adobe Reader 9", "Adobe Acrobat", "9", "10", "9.3.2",
242 "http://get.adobe.com/reader/" },
243 { "Adobe Reader 8", "Adobe Acrobat", "0", "9", "8.2.2",
244 "http://get.adobe.com/reader/" },
245 { "Flash", "Shockwave Flash", "", "", "10.0.45",
246 "http://get.adobe.com/flashplayer/" },
247 { "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0",
248 "http://go.microsoft.com/fwlink/?LinkID=185927" },
249 { "Silverlight 4", "Silverlight", "4", "5", "",
250 "http://go.microsoft.com/fwlink/?LinkID=185927" },
251 { "Shockwave", "Shockwave for Director", "", "", "11.5.7.609",
252 "http://www.adobe.com/shockwave/download/" },
253 { "DivX Player", "DivX Web Player", "", "", "1.4.3.4",
254 "http://download.divx.com/divx/autoupdate/player/DivXWebPlayerInstaller.exe" },
255 // These are here for grouping, no vulnerabilies known.
256 { "Windows Media Player", "Windows Media Player", "", "", "", "" },
257 { "Microsoft Office", "Microsoft Office", "", "", "", "" },
258 // TODO(panayiotis): The vulnerable versions are
259 // (v >= 6.0.12.1040 && v <= 6.0.12.1663)
260 // || v == 6.0.12.1698 || v == 6.0.12.1741
261 { "RealPlayer", "RealPlayer", "", "", "",
262 "http://www.adobe.com/shockwave/download/" },
263 };
264
265 #else
266 static const PluginGroupDefinition kGroupDefinitions[] = {};
267 #endif
268
269 /*static*/
270 const PluginGroupDefinition* PluginUpdater::GetPluginGroupDefinitions() {
271 return kGroupDefinitions;
272 }
273
274 /*static*/
275 const size_t PluginUpdater::GetPluginGroupDefinitionsSize() {
276 // TODO(viettrungluu): |arraysize()| doesn't work with zero-size arrays.
277 return ARRAYSIZE_UNSAFE(kGroupDefinitions);
278 }
279
280 // static
281 PluginUpdater* PluginUpdater::GetInstance() {
282 return Singleton<PluginUpdater>::get();
283 }
284
285 PluginUpdater::PluginUpdater() {
286 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions();
287 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) {
288 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition(
289 definitions[i]);
290 plugin_group_definitions_.push_back(linked_ptr<PluginGroup>(
291 definition_group));
292 }
293 }
294
295 PluginUpdater::~PluginUpdater() {
296 }
297
298 // Convert to a List of Groups
299 void PluginUpdater::GetPluginGroups(
300 std::vector<linked_ptr<PluginGroup> >* plugin_groups) {
301 // Read all plugins and convert them to plugin groups
302 std::vector<WebPluginInfo> web_plugins;
303 NPAPI::PluginList::Singleton()->GetPlugins(false, &web_plugins);
304
305 // We first search for an existing group that matches our name,
306 // and only create a new group if we can't find any.
307 for (size_t i = 0; i < web_plugins.size(); ++i) {
308 const WebPluginInfo& web_plugin = web_plugins[i];
309 bool found = false;
310 for (std::vector<linked_ptr<PluginGroup> >::iterator existing_it =
311 plugin_groups->begin();
312 existing_it != plugin_groups->end();
313 ++existing_it) {
314 if ((*existing_it)->Match(web_plugin)) {
315 (*existing_it)->AddPlugin(web_plugin, i);
316 found = true;
317 break;
318 }
319 }
320
321 if (!found) {
322 // See if this plugin matches any of the hardcoded groups.
323 for (std::vector<linked_ptr<PluginGroup> >::iterator defs_it =
324 plugin_group_definitions_.begin();
325 defs_it != plugin_group_definitions_.end();
326 ++defs_it) {
327 if ((*defs_it)->Match(web_plugin)) {
328 // Make a copy, otherwise we'd be modifying plugin_group_defs_ every
329 // time this method is called.
330 PluginGroup* copy = (*defs_it)->Copy();
331 copy->AddPlugin(web_plugin, i);
332 plugin_groups->push_back(linked_ptr<PluginGroup>(copy));
333 found = true;
334 break;
335 }
336 }
337 }
338
339 // Not found in our hardcoded list, create a new one.
340 if (!found) {
341 PluginGroup* plugin_group = PluginGroup::FromWebPluginInfo(web_plugin);
342 plugin_group->AddPlugin(web_plugin, i);
343 plugin_groups->push_back(linked_ptr<PluginGroup>(plugin_group));
344 }
345 }
346 }
347
348 ListValue* PluginUpdater::GetPluginGroupsData() {
349 std::vector<linked_ptr<PluginGroup> > plugin_groups;
350 GetPluginGroups(&plugin_groups);
351
352 // Construct DictionaryValues to return to the UI
353 ListValue* plugin_groups_data = new ListValue();
354 for (std::vector<linked_ptr<PluginGroup> >::iterator it =
355 plugin_groups.begin();
356 it != plugin_groups.end();
357 ++it) {
358 plugin_groups_data->Append((*it)->GetData());
359 }
360 return plugin_groups_data;
361 }
362
363 ListValue* PluginUpdater::GetPluginGroupsSummary() {
364 std::vector<linked_ptr<PluginGroup> > plugin_groups;
365 GetPluginGroups(&plugin_groups);
366
367 // Construct DictionaryValues to return to the UI
368 ListValue* plugin_groups_data = new ListValue();
369 for (std::vector<linked_ptr<PluginGroup> >::iterator it =
370 plugin_groups.begin();
371 it != plugin_groups.end();
372 ++it) {
373 plugin_groups_data->Append((*it)->GetSummary());
374 }
375 return plugin_groups_data;
376 }
377
378 void PluginUpdater::EnablePluginGroup(bool enable,
379 const string16& group_name) {
380 std::vector<linked_ptr<PluginGroup> > plugin_groups;
381 GetPluginGroups(&plugin_groups);
382
383 for (std::vector<linked_ptr<PluginGroup> >::iterator it =
384 plugin_groups.begin();
385 it != plugin_groups.end();
386 ++it) {
387 if ((*it)->GetGroupName() == group_name) {
388 (*it)->Enable(enable);
389 }
390 }
391 }
392
393 void PluginUpdater::EnablePluginFile(bool enable,
394 const FilePath::StringType& file_path) {
395 if (enable)
396 NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(file_path));
397 else
398 NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(file_path));
399 }
400
401 // static
402 #if defined(OS_CHROMEOS)
403 bool PluginUpdater::enable_internal_pdf_ = true;
404 #else
405 bool PluginUpdater::enable_internal_pdf_ = false;
406 #endif
407
408 void PluginUpdater::DisablePluginGroupsFromPrefs(Profile* profile) {
409 bool update_internal_dir = false;
410 FilePath last_internal_dir =
411 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory);
412 FilePath cur_internal_dir;
413 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) &&
414 cur_internal_dir != last_internal_dir) {
415 update_internal_dir = true;
416 profile->GetPrefs()->SetFilePath(
417 prefs::kPluginsLastInternalDirectory, cur_internal_dir);
418 }
419
420 bool found_internal_pdf = false;
421 bool force_enable_internal_pdf = false;
422 FilePath pdf_path;
423 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
424 FilePath::StringType pdf_path_str = pdf_path.value();
425 if (enable_internal_pdf_ &&
426 !profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) {
427 // We switched to the internal pdf plugin being on by default, and so we
428 // need to force it to be enabled. We only want to do it this once though,
429 // i.e. we don't want to enable it again if the user disables it afterwards.
430 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true);
431 force_enable_internal_pdf = true;
432 }
433
434 if (ListValue* saved_plugins_list =
435 profile->GetPrefs()->GetMutableList(prefs::kPluginsPluginsList)) {
436 for (ListValue::const_iterator it = saved_plugins_list->begin();
437 it != saved_plugins_list->end();
438 ++it) {
439 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) {
440 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList;
441 continue; // Oops, don't know what to do with this item.
442 }
443
444 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it);
445 string16 group_name;
446 bool enabled = true;
447 plugin->GetBoolean(L"enabled", &enabled);
448
449 FilePath::StringType path;
450 // The plugin list constains all the plugin files in addition to the
451 // plugin groups.
452 if (plugin->GetString(L"path", &path)) {
453 // Files have a path attribute, groups don't.
454 FilePath plugin_path(path);
455 if (update_internal_dir &&
456 FilePath::CompareIgnoreCase(plugin_path.DirName().value(),
457 last_internal_dir.value()) == 0) {
458 // If the internal plugin directory has changed and if the plugin
459 // looks internal, update its path in the prefs.
460 plugin_path = cur_internal_dir.Append(plugin_path.BaseName());
461 path = plugin_path.value();
462 plugin->SetString(L"path", path);
463 }
464
465 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) {
466 found_internal_pdf = true;
467 if (!enabled && force_enable_internal_pdf) {
468 enabled = true;
469 plugin->SetBoolean(L"enabled", true);
470 }
471 }
472 if (!enabled)
473 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path);
474 } else if (!enabled && plugin->GetStringAsUTF16(L"name", &group_name)) {
475 // Otherwise this is a list of groups.
476 EnablePluginGroup(false, group_name);
477 }
478 }
479 }
480
481 if (!enable_internal_pdf_ && !found_internal_pdf) {
482 // The internal PDF plugin is disabled by default, and the user hasn't
483 // overridden the default.
484 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path);
485 }
486 }
487
488 DictionaryValue* PluginUpdater::CreatePluginFileSummary(
489 const WebPluginInfo& plugin) {
490 DictionaryValue* data = new DictionaryValue();
491 data->SetString(L"path", plugin.path.value());
492 data->SetStringFromUTF16(L"name", plugin.name);
493 data->SetStringFromUTF16(L"version", plugin.version);
494 data->SetBoolean(L"enabled", plugin.enabled);
495 return data;
496 }
497
498 void PluginUpdater::UpdatePreferences(Profile* profile) {
499 ListValue* plugins_list = profile->GetPrefs()->GetMutableList(
500 prefs::kPluginsPluginsList);
501 plugins_list->Clear();
502
503 FilePath internal_dir;
504 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
505 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory,
506 internal_dir);
507
508 // Add the plugin files.
509 std::vector<WebPluginInfo> plugins;
510 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
511 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin();
512 it != plugins.end();
513 ++it) {
514 plugins_list->Append(CreatePluginFileSummary(*it));
515 }
516
517 // Add the groups as well.
518 ListValue* plugin_groups = GetPluginGroupsSummary();
519 for (ListValue::const_iterator it = plugin_groups->begin();
520 it != plugin_groups->end();
521 ++it) {
522 plugins_list->Append(*it);
523 }
524 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_updater.h ('k') | chrome/browser/plugin_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698