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

Side by Side Diff: webkit/glue/plugins/plugin_list.cc

Issue 1085003: Implement chrome://plugins page that can disable plugins. (Closed)
Patch Set: merge ToT again Created 10 years, 9 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 | « webkit/glue/plugins/plugin_list.h ('k') | webkit/glue/webplugininfo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 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_list.h" 5 #include "webkit/glue/plugins/plugin_list.h"
6 6
7 #include <algorithm>
8
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/string_util.h" 11 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
11 #include "base/time.h" 13 #include "base/time.h"
12 #include "net/base/mime_util.h" 14 #include "net/base/mime_util.h"
13 #include "webkit/default_plugin/plugin_main.h" 15 #include "webkit/default_plugin/plugin_main.h"
14 #include "webkit/glue/plugins/plugin_constants_win.h" 16 #include "webkit/glue/plugins/plugin_constants_win.h"
15 #include "webkit/glue/plugins/plugin_lib.h" 17 #include "webkit/glue/plugins/plugin_lib.h"
16 #include "webkit/glue/webkit_glue.h" 18 #include "webkit/glue/webkit_glue.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 info->mime_types.clear(); 102 info->mime_types.clear();
101 103
102 if (mime_types.empty()) 104 if (mime_types.empty())
103 return false; 105 return false;
104 106
105 info->name = pvi.product_name; 107 info->name = pvi.product_name;
106 info->desc = pvi.file_description; 108 info->desc = pvi.file_description;
107 info->version = pvi.file_version; 109 info->version = pvi.file_version;
108 info->path = pvi.path; 110 info->path = pvi.path;
111 info->enabled = true;
109 112
110 for (size_t i = 0; i < mime_types.size(); ++i) { 113 for (size_t i = 0; i < mime_types.size(); ++i) {
111 WebPluginMimeType mime_type; 114 WebPluginMimeType mime_type;
112 mime_type.mime_type = StringToLowerASCII(mime_types[i]); 115 mime_type.mime_type = StringToLowerASCII(mime_types[i]);
113 if (file_extensions.size() > i) 116 if (file_extensions.size() > i)
114 SplitString(file_extensions[i], ',', &mime_type.file_extensions); 117 SplitString(file_extensions[i], ',', &mime_type.file_extensions);
115 118
116 if (descriptions.size() > i) { 119 if (descriptions.size() > i) {
117 mime_type.description = descriptions[i]; 120 mime_type.description = descriptions[i];
118 121
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 210 }
208 211
209 // Load the default plugin last. 212 // Load the default plugin last.
210 if (webkit_glue::IsDefaultPluginEnabled()) 213 if (webkit_glue::IsDefaultPluginEnabled())
211 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); 214 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins);
212 215
213 base::TimeTicks end_time = base::TimeTicks::Now(); 216 base::TimeTicks end_time = base::TimeTicks::Now();
214 base::TimeDelta elapsed = end_time - start_time; 217 base::TimeDelta elapsed = end_time - start_time;
215 DLOG(INFO) << "Loaded plugin list in " << elapsed.InMilliseconds() << " ms."; 218 DLOG(INFO) << "Loaded plugin list in " << elapsed.InMilliseconds() << " ms.";
216 219
220 // Only update the data now since loading plugins can take a while.
217 AutoLock lock(lock_); 221 AutoLock lock(lock_);
222
223 // Go through and mark new plugins in the disabled list as, well, disabled.
224 for (std::vector<WebPluginInfo>::iterator it = new_plugins.begin();
225 it != new_plugins.end();
226 ++it) {
227 if (disabled_plugins_.find(it->path) != disabled_plugins_.end())
228 it->enabled = false;
229 }
230
218 plugins_ = new_plugins; 231 plugins_ = new_plugins;
219 plugins_loaded_ = true; 232 plugins_loaded_ = true;
220 } 233 }
221 234
222 void PluginList::LoadPlugin(const FilePath& path, 235 void PluginList::LoadPlugin(const FilePath& path,
223 std::vector<WebPluginInfo>* plugins) { 236 std::vector<WebPluginInfo>* plugins) {
224 WebPluginInfo plugin_info; 237 WebPluginInfo plugin_info;
225 const PluginEntryPoints* entry_points; 238 const PluginEntryPoints* entry_points;
226 239
227 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) 240 if (!ReadPluginInfo(path, &plugin_info, &entry_points))
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 337 }
325 338
326 339
327 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { 340 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) {
328 LoadPlugins(refresh); 341 LoadPlugins(refresh);
329 342
330 AutoLock lock(lock_); 343 AutoLock lock(lock_);
331 *plugins = plugins_; 344 *plugins = plugins_;
332 } 345 }
333 346
347 void PluginList::GetEnabledPlugins(bool refresh,
348 std::vector<WebPluginInfo>* plugins) {
349 LoadPlugins(refresh);
350
351 plugins->clear();
352 AutoLock lock(lock_);
353 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin();
354 it != plugins_.end();
355 ++it) {
356 if (it->enabled)
357 plugins->push_back(*it);
358 }
359 }
360
334 bool PluginList::GetPluginInfo(const GURL& url, 361 bool PluginList::GetPluginInfo(const GURL& url,
335 const std::string& mime_type, 362 const std::string& mime_type,
336 bool allow_wildcard, 363 bool allow_wildcard,
337 WebPluginInfo* info, 364 WebPluginInfo* info,
338 std::string* actual_mime_type) { 365 std::string* actual_mime_type) {
339 bool found = FindPlugin(mime_type, allow_wildcard, info); 366 bool found = FindPlugin(mime_type, allow_wildcard, info);
340 if (!found || (info->path.value() == kDefaultPluginLibraryName)) { 367 if (!found || (info->path.value() == kDefaultPluginLibraryName)) {
341 WebPluginInfo info2; 368 WebPluginInfo info2;
342 if (FindPlugin(url, actual_mime_type, &info2)) { 369 if (FindPlugin(url, actual_mime_type, &info2)) {
343 found = true; 370 found = true;
(...skipping 11 matching lines...) Expand all
355 for (size_t i = 0; i < plugins_.size(); ++i) { 382 for (size_t i = 0; i < plugins_.size(); ++i) {
356 if (plugins_[i].path == plugin_path) { 383 if (plugins_[i].path == plugin_path) {
357 *info = plugins_[i]; 384 *info = plugins_[i];
358 return true; 385 return true;
359 } 386 }
360 } 387 }
361 388
362 return false; 389 return false;
363 } 390 }
364 391
392 bool PluginList::EnablePlugin(const FilePath& filename) {
393 AutoLock lock(lock_);
394
395 bool did_enable = false;
396
397 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename);
398 if (entry == disabled_plugins_.end())
399 return did_enable; // Early exit if plugin not in disabled list.
400
401 disabled_plugins_.erase(entry); // Remove from disabled list.
402
403 // Set enabled flags if necessary.
404 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
405 it != plugins_.end();
406 ++it) {
407 if (it->path == filename) {
408 DCHECK(!it->enabled); // Should have been disabled.
409 it->enabled = true;
410 did_enable = true;
411 }
412 }
413
414 return did_enable;
415 }
416
417 bool PluginList::DisablePlugin(const FilePath& filename) {
418 AutoLock lock(lock_);
419
420 bool did_disable = false;
421
422 if (disabled_plugins_.find(filename) != disabled_plugins_.end())
423 return did_disable; // Early exit if plugin already in disabled list.
424
425 disabled_plugins_.insert(filename); // Add to disabled list.
426
427 // Unset enabled flags if necessary.
428 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
429 it != plugins_.end();
430 ++it) {
431 if (it->path == filename) {
432 DCHECK(it->enabled); // Should have been enabled.
433 it->enabled = false;
434 did_disable = true;
435 }
436 }
437
438 return did_disable;
439 }
440
365 void PluginList::Shutdown() { 441 void PluginList::Shutdown() {
366 // TODO 442 // TODO
367 } 443 }
368 444
369 } // namespace NPAPI 445 } // namespace NPAPI
OLDNEW
« no previous file with comments | « webkit/glue/plugins/plugin_list.h ('k') | webkit/glue/webplugininfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698