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

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

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More fixes and cleanups. Created 10 years 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 | Annotate | Revision Log
OLDNEW
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_list.h" 5 #include "webkit/glue/plugins/plugin_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "net/base/mime_util.h"
18 #include "webkit/glue/plugins/plugin_constants_win.h" 17 #include "webkit/glue/plugins/plugin_constants_win.h"
19 #include "webkit/glue/plugins/plugin_lib.h" 18 #include "webkit/glue/plugins/plugin_lib.h"
20 #include "webkit/glue/webkit_glue.h" 19 #include "webkit/glue/webkit_glue.h"
21 #include "webkit/plugins/plugin_switches.h" 20 #include "webkit/plugins/plugin_switches.h"
22 21
23 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
24 #include "base/stl_util-inl.h" 23 #include "base/stl_util-inl.h"
25 #include "base/third_party/valgrind/valgrind.h" 24 #include "base/third_party/valgrind/valgrind.h"
26 #endif // defined(OS_POSIX) 25 #endif // defined(OS_POSIX)
27 26
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 LOG_IF(ERROR, PluginList::DebugPluginLoading()) 242 LOG_IF(ERROR, PluginList::DebugPluginLoading())
244 << "Plugin " << pvi.product_name << " has no MIME types, skipping"; 243 << "Plugin " << pvi.product_name << " has no MIME types, skipping";
245 return false; 244 return false;
246 } 245 }
247 246
248 info->name = WideToUTF16(pvi.product_name); 247 info->name = WideToUTF16(pvi.product_name);
249 info->desc = WideToUTF16(pvi.file_description); 248 info->desc = WideToUTF16(pvi.file_description);
250 info->version = WideToUTF16(pvi.file_version); 249 info->version = WideToUTF16(pvi.file_version);
251 info->path = pvi.path; 250 info->path = pvi.path;
252 info->enabled = true; 251 info->enabled = true;
252 info->priority = 0;
253 info->reason = WebPluginInfo::USER;
253 254
254 for (size_t i = 0; i < mime_types.size(); ++i) { 255 for (size_t i = 0; i < mime_types.size(); ++i) {
255 WebPluginMimeType mime_type; 256 WebPluginMimeType mime_type;
256 mime_type.mime_type = StringToLowerASCII(mime_types[i]); 257 mime_type.mime_type = StringToLowerASCII(mime_types[i]);
257 if (file_extensions.size() > i) 258 if (file_extensions.size() > i)
258 base::SplitString(file_extensions[i], ',', &mime_type.file_extensions); 259 base::SplitString(file_extensions[i], ',', &mime_type.file_extensions);
259 260
260 if (descriptions.size() > i) { 261 if (descriptions.size() > i) {
261 mime_type.description = descriptions[i]; 262 mime_type.description = descriptions[i];
262 263
(...skipping 12 matching lines...) Expand all
275 info->mime_types.push_back(mime_type); 276 info->mime_types.push_back(mime_type);
276 } 277 }
277 278
278 return true; 279 return true;
279 } 280 }
280 281
281 PluginList::PluginList() 282 PluginList::PluginList()
282 : plugins_loaded_(false), 283 : plugins_loaded_(false),
283 plugins_need_refresh_(false), 284 plugins_need_refresh_(false),
284 disable_outdated_plugins_(false), 285 disable_outdated_plugins_(false),
285 next_priority_(0) { 286 next_priority_(1) {
286 PlatformInit(); 287 PlatformInit();
287 AddHardcodedPluginGroups(); 288 AddHardcodedPluginGroups();
288 } 289 }
289 290
290 bool PluginList::ShouldDisableGroup(const string16& group_name) {
291 AutoLock lock(lock_);
292 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) {
293 disabled_groups_.insert(group_name);
294 return true;
295 }
296 return disabled_groups_.count(group_name) > 0;
297 }
298
299 void PluginList::LoadPlugins(bool refresh) { 291 void PluginList::LoadPlugins(bool refresh) {
300 // Don't want to hold the lock while loading new plugins, so we don't block 292 // Don't want to hold the lock while loading new plugins, so we don't block
301 // other methods if they're called on other threads. 293 // other methods if they're called on other threads.
302 std::vector<FilePath> extra_plugin_paths; 294 std::vector<FilePath> extra_plugin_paths;
303 std::vector<FilePath> extra_plugin_dirs; 295 std::vector<FilePath> extra_plugin_dirs;
304 std::vector<PluginVersionInfo> internal_plugins; 296 std::vector<PluginVersionInfo> internal_plugins;
305 { 297 {
306 AutoLock lock(lock_); 298 AutoLock lock(lock_);
307 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) 299 if (plugins_loaded_ && !refresh && !plugins_need_refresh_)
308 return; 300 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 340
349 #if defined(OS_WIN) 341 #if defined(OS_WIN)
350 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); 342 LoadPluginsFromRegistry(&new_plugins, &visited_plugins);
351 #endif 343 #endif
352 344
353 // Load the default plugin last. 345 // Load the default plugin last.
354 if (webkit_glue::IsDefaultPluginEnabled()) 346 if (webkit_glue::IsDefaultPluginEnabled())
355 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); 347 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins);
356 348
357 // Disable all of the plugins and plugin groups that are disabled by policy. 349 // Disable all of the plugins and plugin groups that are disabled by policy.
358 // There's currenly a bug that makes it impossible to correctly re-enable
359 // plugins or plugin-groups to their original, "pre-policy" state, so
360 // plugins and groups are only changed to a more "safe" state after a policy
361 // change, i.e. from enabled to disabled. See bug 54681.
362 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); 350 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
363 it != plugin_groups_.end(); ++it) { 351 it != plugin_groups_.end(); ++it) {
364 PluginGroup* group = it->second; 352 PluginGroup* group = it->second;
365 string16 group_name = group->GetGroupName(); 353 string16 group_name = group->GetGroupName();
366 if (ShouldDisableGroup(group_name)) { 354 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name))
367 group->Enable(false); 355 group->EnableGroup(false);
368 }
369 356
370 if (disable_outdated_plugins_) { 357 if (disable_outdated_plugins_)
371 group->DisableOutdatedPlugins(); 358 group->DisableOutdatedPlugins();
372 } 359 }
373 if (!group->Enabled()) { 360
374 AutoLock lock(lock_); 361 AutoLock lock(lock_);
375 disabled_groups_.insert(group_name); 362 // Clean up the plugins that has disappeared from the groups.
363 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
364 group != plugin_groups_.end(); ++group) {
365 std::vector<WebPluginInfo>& gr_plugins = group->second->GetPlugins();
366 for (size_t i = 0; i < gr_plugins.size(); ++i) {
367 bool plugin_found = false;
368 for (size_t j = 0; j < new_plugins.size(); ++j)
369 if (gr_plugins[i].path == new_plugins[j].path) {
370 plugin_found = true;
371 break;
372 }
373 if (!plugin_found)
374 if(gr_plugins[i].priority)
375 gr_plugins[i].priority = 0;
376 } 376 }
377 } 377 }
378
379 // Only update the data now since loading plugins can take a while.
380 AutoLock lock(lock_);
381
382 plugins_ = new_plugins;
383 plugins_loaded_ = true; 378 plugins_loaded_ = true;
384 } 379 }
385 380
386 void PluginList::LoadPlugin(const FilePath& path, 381 void PluginList::LoadPlugin(const FilePath& path,
387 std::vector<WebPluginInfo>* plugins) { 382 std::vector<WebPluginInfo>* plugins) {
388 LOG_IF(ERROR, PluginList::DebugPluginLoading()) 383 LOG_IF(ERROR, PluginList::DebugPluginLoading())
389 << "Loading plugin " << path.value(); 384 << "Loading plugin " << path.value();
390 385
391 WebPluginInfo plugin_info; 386 WebPluginInfo plugin_info;
392 const PluginEntryPoints* entry_points; 387 const PluginEntryPoints* entry_points;
(...skipping 12 matching lines...) Expand all
405 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { 400 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) {
406 // TODO: don't load global handlers for now. 401 // TODO: don't load global handlers for now.
407 // WebKit hands to the Plugin before it tries 402 // WebKit hands to the Plugin before it tries
408 // to handle mimeTypes on its own. 403 // to handle mimeTypes on its own.
409 const std::string &mime_type = plugin_info.mime_types[i].mime_type; 404 const std::string &mime_type = plugin_info.mime_types[i].mime_type;
410 if (mime_type == "*" ) 405 if (mime_type == "*" )
411 return; 406 return;
412 } 407 }
413 } 408 }
414 409
415 // Mark disabled plugins as such. (This has to happen before calling
416 // |AddToPluginGroups(plugin_info)|.)
417 if (disabled_plugins_.count(plugin_info.path)) {
418 plugin_info.enabled = false;
419 } else {
420 plugin_info.enabled = true;
421 }
422
423 AutoLock lock(lock_); 410 AutoLock lock(lock_);
411 AddToPluginGroups(plugin_info);
424 plugins->push_back(plugin_info); 412 plugins->push_back(plugin_info);
425 AddToPluginGroups(plugin_info);
426 } 413 }
427 414
428 bool PluginList::SupportsType(const WebPluginInfo& info,
429 const std::string &mime_type,
430 bool allow_wildcard) {
431 // Webkit will ask for a plugin to handle empty mime types.
432 if (mime_type.empty())
433 return false;
434
435 for (size_t i = 0; i < info.mime_types.size(); ++i) {
436 const WebPluginMimeType& mime_info = info.mime_types[i];
437 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
438 if (!allow_wildcard && mime_info.mime_type == "*") {
439 continue;
440 }
441 return true;
442 }
443 }
444 return false;
445 }
446
447 bool PluginList::SupportsExtension(const WebPluginInfo& info,
448 const std::string &extension,
449 std::string* actual_mime_type) {
450 for (size_t i = 0; i < info.mime_types.size(); ++i) {
451 const WebPluginMimeType& mime_type = info.mime_types[i];
452 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
453 if (mime_type.file_extensions[j] == extension) {
454 if (actual_mime_type)
455 *actual_mime_type = mime_type.mime_type;
456 return true;
457 }
458 }
459 }
460
461 return false;
462 }
463
464
465 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { 415 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) {
466 LoadPlugins(refresh); 416 LoadPlugins(refresh);
467 417
468 AutoLock lock(lock_); 418 AutoLock lock(lock_);
469 *plugins = plugins_; 419 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
420 group != plugin_groups_.end(); ++group) {
421 const std::vector<WebPluginInfo>& gr_plugins = group->second->GetPlugins();
422 for (size_t i = 0; i < gr_plugins.size(); ++i)
423 if(gr_plugins[i].priority != 0)
424 plugins->push_back(gr_plugins[i]);
425 }
470 } 426 }
471 427
472 void PluginList::GetEnabledPlugins(bool refresh, 428 void PluginList::GetEnabledPlugins(bool refresh,
473 std::vector<WebPluginInfo>* plugins) { 429 std::vector<WebPluginInfo>* plugins) {
474 LoadPlugins(refresh); 430 LoadPlugins(refresh);
475 431
476 plugins->clear(); 432 plugins->clear();
477 AutoLock lock(lock_); 433 AutoLock lock(lock_);
478 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); 434 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
479 it != plugins_.end(); 435 group != plugin_groups_.end(); ++group) {
480 ++it) { 436 const std::vector<WebPluginInfo>& gr_plugins = group->second->GetPlugins();
481 if (it->enabled) 437 for (size_t i = 0; i < gr_plugins.size(); ++i) {
482 plugins->push_back(*it); 438 if (gr_plugins[i].priority != 0 && gr_plugins[i].IsEnabled())
439 plugins->push_back(gr_plugins[i]);
440 }
483 } 441 }
484 } 442 }
485 443
486 void PluginList::GetPluginInfoArray( 444 void PluginList::GetPluginInfoArray(
487 const GURL& url, 445 const GURL& url,
488 const std::string& mime_type, 446 const std::string& mime_type,
489 bool allow_wildcard, 447 bool allow_wildcard,
490 std::vector<WebPluginInfo>* info, 448 std::vector<WebPluginInfo>* info,
491 std::vector<std::string>* actual_mime_types) { 449 std::vector<std::string>* actual_mime_types) {
492 DCHECK(mime_type == StringToLowerASCII(mime_type)); 450 DCHECK(mime_type == StringToLowerASCII(mime_type));
493 DCHECK(info); 451 DCHECK(info);
494 452
495 LoadPlugins(false); 453 LoadPlugins(false);
496 AutoLock lock(lock_); 454 AutoLock lock(lock_);
497 info->clear(); 455 info->clear();
498 if (actual_mime_types) 456 if (actual_mime_types)
499 actual_mime_types->clear(); 457 actual_mime_types->clear();
500 458
501 std::set<FilePath> visited_plugins; 459 std::set<FilePath> visited_plugins;
502 460
503 // Add in enabled plugins by mime type. 461 // Add in enabled plugins by mime type.
504 WebPluginInfo default_plugin; 462 WebPluginInfo default_plugin;
505 for (size_t i = 0; i < plugins_.size(); ++i) { 463 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
506 if (plugins_[i].enabled && 464 group != plugin_groups_.end(); ++group) {
507 SupportsType(plugins_[i], mime_type, allow_wildcard)) { 465 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins();
508 FilePath path = plugins_[i].path; 466 for (size_t i = 0; i < plugins.size(); ++i) {
509 if (path.value() != kDefaultPluginLibraryName && 467 if (plugins[i].priority != 0 && plugins[i].IsEnabled() &&
510 visited_plugins.insert(path).second) { 468 plugins[i].SupportsType(mime_type, allow_wildcard)) {
511 info->push_back(plugins_[i]); 469 FilePath path = plugins[i].path;
512 if (actual_mime_types) 470 if (path.value() != kDefaultPluginLibraryName &&
513 actual_mime_types->push_back(mime_type); 471 visited_plugins.insert(path).second) {
472 info->push_back(plugins[i]);
473 if (actual_mime_types)
474 actual_mime_types->push_back(mime_type);
475 }
514 } 476 }
515 } 477 }
516 } 478 }
517 479
518 // Add in enabled plugins by url. 480 // Add in enabled plugins by url.
519 std::string path = url.path(); 481 std::string path = url.path();
520 std::string::size_type last_dot = path.rfind('.'); 482 std::string::size_type last_dot = path.rfind('.');
521 if (last_dot != std::string::npos) { 483 if (last_dot != std::string::npos) {
522 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); 484 std::string extension = StringToLowerASCII(std::string(path, last_dot+1));
523 std::string actual_mime_type; 485 std::string actual_mime_type;
524 for (size_t i = 0; i < plugins_.size(); ++i) { 486 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
525 if (plugins_[i].enabled && 487 group != plugin_groups_.end(); ++group) {
526 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { 488 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins();
527 FilePath path = plugins_[i].path; 489 for (size_t i = 0; i < plugins.size(); ++i) {
528 if (path.value() != kDefaultPluginLibraryName && 490 if (plugins[i].priority != 0 && plugins[i].IsEnabled() &&
529 visited_plugins.insert(path).second) { 491 plugins[i].SupportsExtension(extension, &actual_mime_type)) {
530 info->push_back(plugins_[i]); 492 FilePath path = plugins[i].path;
531 if (actual_mime_types) 493 if (path.value() != kDefaultPluginLibraryName &&
532 actual_mime_types->push_back(actual_mime_type); 494 visited_plugins.insert(path).second) {
495 info->push_back(plugins[i]);
496 if (actual_mime_types)
497 actual_mime_types->push_back(actual_mime_type);
498 }
533 } 499 }
534 } 500 }
535 } 501 }
536 } 502 }
537 503
538 // Add in disabled plugins by mime type. 504 // Add in disabled plugins by mime type.
539 for (size_t i = 0; i < plugins_.size(); ++i) { 505 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
540 if (!plugins_[i].enabled && 506 group != plugin_groups_.end(); ++group) {
541 SupportsType(plugins_[i], mime_type, allow_wildcard)) { 507 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins();
542 FilePath path = plugins_[i].path; 508 for (size_t i = 0; i < plugins.size(); ++i) {
543 if (path.value() != kDefaultPluginLibraryName && 509 if (plugins[i].priority != 0 && !plugins[i].IsEnabled() &&
544 visited_plugins.insert(path).second) { 510 plugins[i].SupportsType(mime_type, allow_wildcard)) {
545 info->push_back(plugins_[i]); 511 FilePath path = plugins[i].path;
546 if (actual_mime_types) 512 if (path.value() != kDefaultPluginLibraryName &&
547 actual_mime_types->push_back(mime_type); 513 visited_plugins.insert(path).second) {
514 info->push_back(plugins[i]);
515 if (actual_mime_types)
516 actual_mime_types->push_back(mime_type);
517 }
548 } 518 }
549 } 519 }
550 } 520 }
551 521
552 // Add the default plugin at the end if it supports the mime type given, 522 // Add the default plugin at the end if it supports the mime type given,
553 // and the default plugin is enabled. 523 // and the default plugin is enabled.
554 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { 524 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
555 const WebPluginInfo& default_info = plugins_.back(); 525 group != plugin_groups_.end(); ++group) {
556 if (SupportsType(default_info, mime_type, allow_wildcard)) { 526 #if defined(OS_WIN)
557 info->push_back(default_info); 527 if (group->first.compare(WideToUTF8(kDefaultPluginLibraryName)) == 0) {
558 if (actual_mime_types) 528 #else
559 actual_mime_types->push_back(mime_type); 529 if (group->first.compare(kDefaultPluginLibraryName) == 0) {
530 #endif
531 DCHECK_NE(0U, group->second->GetPlugins().size());
532 const WebPluginInfo& default_info = group->second->GetPlugins().front();
533 if (default_info.SupportsType(mime_type, allow_wildcard)) {
534 info->push_back(default_info);
535 if (actual_mime_types)
536 actual_mime_types->push_back(mime_type);
537 }
560 } 538 }
561 } 539 }
562 } 540 }
563 541
564 bool PluginList::GetPluginInfo(const GURL& url, 542 bool PluginList::GetPluginInfo(const GURL& url,
565 const std::string& mime_type, 543 const std::string& mime_type,
566 bool allow_wildcard, 544 bool allow_wildcard,
567 WebPluginInfo* info, 545 WebPluginInfo* info,
568 std::string* actual_mime_type) { 546 std::string* actual_mime_type) {
569 DCHECK(info); 547 DCHECK(info);
(...skipping 17 matching lines...) Expand all
587 return true; 565 return true;
588 } 566 }
589 } 567 }
590 return false; 568 return false;
591 } 569 }
592 570
593 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, 571 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path,
594 WebPluginInfo* info) { 572 WebPluginInfo* info) {
595 LoadPlugins(false); 573 LoadPlugins(false);
596 AutoLock lock(lock_); 574 AutoLock lock(lock_);
597 for (size_t i = 0; i < plugins_.size(); ++i) { 575 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin();
598 if (plugins_[i].path == plugin_path) { 576 group != plugin_groups_.end(); ++group) {
599 *info = plugins_[i]; 577 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins();
600 return true; 578 for (size_t i = 0; i < plugins.size(); ++i) {
579 if (plugins[i].priority != 0 && plugins[i].path == plugin_path) {
580 *info = plugins[i];
581 return true;
582 }
601 } 583 }
602 } 584 }
603 585
604 return false; 586 return false;
605 } 587 }
606 588
607 void PluginList::GetPluginGroups( 589 void PluginList::GetPluginGroups(
608 bool load_if_necessary, 590 bool load_if_necessary,
609 std::vector<PluginGroup>* plugin_groups) { 591 std::vector<PluginGroup>* plugin_groups) {
610 if (load_if_necessary) 592 if (load_if_necessary)
611 LoadPlugins(false); 593 LoadPlugins(false);
594 AutoLock lock(lock_);
612 plugin_groups->clear(); 595 plugin_groups->clear();
613 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); 596 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin();
614 it != plugin_groups_.end(); ++it) { 597 it != plugin_groups_.end(); ++it) {
615 plugin_groups->push_back(*it->second); 598 if(!it->second->IsEmpty())
599 plugin_groups->push_back(*it->second);
616 } 600 }
617 } 601 }
618 602
619 const PluginGroup* PluginList::GetPluginGroup( 603 const PluginGroup* PluginList::GetPluginGroup(
620 const WebPluginInfo& web_plugin_info) { 604 const WebPluginInfo& web_plugin_info) {
621 AutoLock lock(lock_); 605 AutoLock lock(lock_);
622 return AddToPluginGroups(web_plugin_info); 606 return AddToPluginGroups(web_plugin_info);
623 } 607 }
624 608
625 string16 PluginList::GetPluginGroupName(std::string identifier) { 609 string16 PluginList::GetPluginGroupName(std::string identifier) {
(...skipping 10 matching lines...) Expand all
636 PluginGroup* group = AddToPluginGroups(web_plugin_info); 620 PluginGroup* group = AddToPluginGroups(web_plugin_info);
637 return group->identifier(); 621 return group->identifier();
638 } 622 }
639 623
640 void PluginList::AddHardcodedPluginGroups() { 624 void PluginList::AddHardcodedPluginGroups() {
641 AutoLock lock(lock_); 625 AutoLock lock(lock_);
642 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); 626 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions();
643 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { 627 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) {
644 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( 628 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition(
645 definitions[i]); 629 definitions[i]);
630 ProcessGroupAfterInitialize(definition_group);
646 std::string identifier = definition_group->identifier(); 631 std::string identifier = definition_group->identifier();
647 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); 632 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end());
648 plugin_groups_.insert(std::make_pair(identifier, definition_group)); 633 plugin_groups_.insert(std::make_pair(identifier, definition_group));
649 } 634 }
650 } 635 }
651 636
652 PluginGroup* PluginList::AddToPluginGroups( 637 PluginGroup* PluginList::AddToPluginGroups(
653 const WebPluginInfo& web_plugin_info) { 638 const WebPluginInfo& web_plugin_info) {
654 PluginGroup* group = NULL; 639 PluginGroup* group = NULL;
655 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); 640 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
656 it != plugin_groups_.end(); ++it) { 641 it != plugin_groups_.end(); ++it) {
657 if (it->second->Match(web_plugin_info)) 642 if (it->second->Match(web_plugin_info)) {
658 group = it->second; 643 group = it->second;
644 break;
645 }
659 } 646 }
660 if (!group) { 647 if (!group) {
661 group = PluginGroup::FromWebPluginInfo(web_plugin_info); 648 group = PluginGroup::FromWebPluginInfo(web_plugin_info);
649 ProcessGroupAfterInitialize(group);
662 std::string identifier = group->identifier(); 650 std::string identifier = group->identifier();
663 // If the identifier is not unique, use the full path. This means that we 651 // If the identifier is not unique, use the full path. This means that we
664 // probably won't be able to search for this group by identifier, but at 652 // probably won't be able to search for this group by identifier, but at
665 // least it's going to be in the set of plugin groups, and if there 653 // least it's going to be in the set of plugin groups, and if there
666 // is already a plug-in with the same filename, it's probably going to 654 // is already a plug-in with the same filename, it's probably going to
667 // handle the same MIME types (and it has a higher priority), so this one 655 // handle the same MIME types (and it has a higher priority), so this one
668 // is not going to run anyway. 656 // is not going to run anyway.
669 if (plugin_groups_.find(identifier) != plugin_groups_.end()) 657 if (plugin_groups_.find(identifier) != plugin_groups_.end())
670 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); 658 identifier = PluginGroup::GetLongIdentifier(web_plugin_info);
671 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); 659 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end());
672 plugin_groups_.insert(std::make_pair(identifier, group)); 660 plugin_groups_.insert(std::make_pair(identifier, group));
673 } 661 }
674 group->AddPlugin(web_plugin_info, next_priority_++); 662 bool is_new_addition = group->AddPlugin(web_plugin_info, next_priority_);
663 if (is_new_addition)
664 next_priority_++;
675 return group; 665 return group;
676 } 666 }
677 667
678 bool PluginList::EnablePlugin(const FilePath& filename) { 668 PluginGroup* PluginList::AddPlaceholderToPluginGroups(
679 AutoLock lock(lock_); 669 const FilePath& filename, const string16& name) {
680 670 WebPluginInfo plugin_info;
681 bool did_enable = false; 671 plugin_info.path = filename;
682 672 plugin_info.name = name;
683 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); 673 return AddToPluginGroups(plugin_info);
684 if (entry == disabled_plugins_.end())
685 return did_enable; // Early exit if plugin not in disabled list.
686
687 disabled_plugins_.erase(entry); // Remove from disabled list.
688
689 // Set enabled flags if necessary.
690 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
691 it != plugins_.end();
692 ++it) {
693 if (it->path == filename) {
694 DCHECK(!it->enabled); // Should have been disabled.
695 it->enabled = true;
696 did_enable = true;
697 }
698 }
699
700 return did_enable;
701 } 674 }
702 675
703 bool PluginList::DisablePlugin(const FilePath& filename) { 676 bool PluginList::EnablePlugin(const FilePath& filename, const string16& name) {
704 AutoLock lock(lock_); 677 AutoLock lock(lock_);
678 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
679 it != plugin_groups_.end(); ++it) {
680 if (it->second->ContainsPlugin(filename))
681 return it->second->EnablePlugin(filename);
682 }
683 // No such group yet; add one as a placeholder.
684 PluginGroup* group = AddPlaceholderToPluginGroups(filename, name);
685 return group->EnablePlugin(filename);
686 }
705 687
706 bool did_disable = false; 688 bool PluginList::DisablePlugin(const FilePath& filename, const string16& name) {
707 689 AutoLock lock(lock_);
708 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) 690 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
709 return did_disable; // Early exit if plugin already in disabled list. 691 it != plugin_groups_.end(); ++it) {
710 692 if (it->second->ContainsPlugin(filename))
711 disabled_plugins_.insert(filename); // Add to disabled list. 693 return it->second->DisablePlugin(filename);
712
713 // Unset enabled flags if necessary.
714 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
715 it != plugins_.end();
716 ++it) {
717 if (it->path == filename) {
718 DCHECK(it->enabled); // Should have been enabled.
719 it->enabled = false;
720 did_disable = true;
721 }
722 } 694 }
723 695 // No such group yet; add one as a placeholder.
724 return did_disable; 696 PluginGroup* group = AddPlaceholderToPluginGroups(filename, name);
697 return group->DisablePlugin(filename);
725 } 698 }
726 699
727 bool PluginList::EnableGroup(bool enable, const string16& group_name) { 700 bool PluginList::EnableGroup(bool enable, const string16& group_name) {
728 bool did_change = false; 701 AutoLock lock(lock_);
729 { 702 PluginGroup* group = NULL;
730 AutoLock lock(lock_); 703 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
731 704 it != plugin_groups_.end(); ++it) {
732 std::set<string16>::iterator entry = disabled_groups_.find(group_name); 705 if (it->second->GetGroupName().find(group_name) != string16::npos) {
733 if (enable) { 706 group = it->second;
734 if (entry == disabled_groups_.end()) 707 break;
735 return did_change; // Early exit if group not in disabled list.
736 disabled_groups_.erase(entry); // Remove from disabled list.
737 } else {
738 if (entry != disabled_groups_.end())
739 return did_change; // Early exit if group already in disabled list.
740 disabled_groups_.insert(group_name);
741 } 708 }
742 } 709 }
743 710 if (!group) {
744 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); 711 group = PluginGroup::CreateEmptyGroup(group_name);
745 it != plugin_groups_.end(); ++it) { 712 plugin_groups_.insert(std::make_pair(UTF16ToUTF8(group_name), group));
746 if (it->second->GetGroupName() == group_name) {
747 if (it->second->Enabled() != enable) {
748 it->second->Enable(enable);
749 did_change = true;
750 break;
751 }
752 }
753 } 713 }
754 714
755 return did_change; 715 return group->EnableGroup(enable);
756 } 716 }
757 717
758 void PluginList::DisableOutdatedPluginGroups() { 718 void PluginList::DisableOutdatedPluginGroups() {
759 disable_outdated_plugins_ = true; 719 disable_outdated_plugins_ = true;
760 } 720 }
761 721
762 PluginList::~PluginList() { 722 PluginList::~PluginList() {
763 Shutdown(); 723 Shutdown();
764 } 724 }
765 725
766 void PluginList::Shutdown() { 726 void PluginList::Shutdown() {
767 // TODO 727 // TODO
768 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but 728 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but
769 // since this singleton lives until the process is destroyed, no explicit 729 // since this singleton lives until the process is destroyed, no explicit
770 // cleanup is necessary. 730 // cleanup is necessary.
771 // However, when running on Valgrind, we need to do the cleanup to keep the 731 // However, when running on Valgrind, we need to do the cleanup to keep the
772 // memory tree green. 732 // memory tree green.
773 #if defined(OS_POSIX) 733 #if defined(OS_POSIX)
774 if (RUNNING_ON_VALGRIND) { 734 if (RUNNING_ON_VALGRIND) {
775 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), 735 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(),
776 plugin_groups_.end()); 736 plugin_groups_.end());
777 } 737 }
778 #endif 738 #endif
779 } 739 }
780 740
781 } // namespace NPAPI 741 } // namespace NPAPI
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698