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

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

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make win and mac compilers happy. Created 9 years, 11 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 | 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/plugins/npapi/plugin_list.h" 5 #include "webkit/plugins/npapi/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/stl_util-inl.h"
13 #include "base/string_split.h" 12 #include "base/string_split.h"
14 #include "base/string_util.h" 13 #include "base/string_util.h"
15 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
18 #include "net/base/mime_util.h" 17 #include "net/base/mime_util.h"
19 #include "webkit/glue/webkit_glue.h" 18 #include "webkit/glue/webkit_glue.h"
20 #include "webkit/plugins/npapi/plugin_constants_win.h" 19 #include "webkit/plugins/npapi/plugin_constants_win.h"
21 #include "webkit/plugins/npapi/plugin_lib.h" 20 #include "webkit/plugins/npapi/plugin_lib.h"
22 #include "webkit/plugins/plugin_switches.h" 21 #include "webkit/plugins/plugin_switches.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void PluginList::RegisterInternalPlugin(const FilePath& filename, 226 void PluginList::RegisterInternalPlugin(const FilePath& filename,
228 const std::string& name, 227 const std::string& name,
229 const std::string& description, 228 const std::string& description,
230 const std::string& mime_type_str, 229 const std::string& mime_type_str,
231 const PluginEntryPoints& entry_points) { 230 const PluginEntryPoints& entry_points) {
232 InternalPlugin plugin; 231 InternalPlugin plugin;
233 plugin.info.path = filename; 232 plugin.info.path = filename;
234 plugin.info.name = ASCIIToUTF16(name); 233 plugin.info.name = ASCIIToUTF16(name);
235 plugin.info.version = ASCIIToUTF16("1"); 234 plugin.info.version = ASCIIToUTF16("1");
236 plugin.info.desc = ASCIIToUTF16(description); 235 plugin.info.desc = ASCIIToUTF16(description);
237 plugin.info.enabled = true; 236 plugin.info.enabled = WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED;
238 237
239 WebPluginMimeType mime_type; 238 WebPluginMimeType mime_type;
240 mime_type.mime_type = mime_type_str; 239 mime_type.mime_type = mime_type_str;
241 plugin.info.mime_types.push_back(mime_type); 240 plugin.info.mime_types.push_back(mime_type);
242 241
243 plugin.entry_points = entry_points; 242 plugin.entry_points = entry_points;
244 243
245 AutoLock lock(lock_); 244 AutoLock lock(lock_);
246 internal_plugins_.push_back(plugin); 245 internal_plugins_.push_back(plugin);
247 } 246 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 316
318 parsed_mime_types->push_back(mime_type); 317 parsed_mime_types->push_back(mime_type);
319 } 318 }
320 319
321 return true; 320 return true;
322 } 321 }
323 322
324 PluginList::PluginList() 323 PluginList::PluginList()
325 : plugins_loaded_(false), 324 : plugins_loaded_(false),
326 plugins_need_refresh_(false), 325 plugins_need_refresh_(false),
327 disable_outdated_plugins_(false), 326 disable_outdated_plugins_(false) {
328 next_priority_(0) {
329 PlatformInit(); 327 PlatformInit();
330 AddHardcodedPluginGroups(); 328 AddHardcodedPluginGroups();
331 } 329 }
332 330
333 bool PluginList::ShouldDisableGroup(const string16& group_name) {
334 AutoLock lock(lock_);
335 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) {
336 disabled_groups_.insert(group_name);
337 return true;
338 }
339 return disabled_groups_.count(group_name) > 0;
340 }
341
342 void PluginList::LoadPlugins(bool refresh) { 331 void PluginList::LoadPlugins(bool refresh) {
343 // Don't want to hold the lock while loading new plugins, so we don't block 332 // Don't want to hold the lock while loading new plugins, so we don't block
344 // other methods if they're called on other threads. 333 // other methods if they're called on other threads.
345 std::vector<FilePath> extra_plugin_paths; 334 std::vector<FilePath> extra_plugin_paths;
346 std::vector<FilePath> extra_plugin_dirs; 335 std::vector<FilePath> extra_plugin_dirs;
347 std::vector<InternalPlugin> internal_plugins; 336 std::vector<InternalPlugin> internal_plugins;
348 { 337 {
349 AutoLock lock(lock_); 338 AutoLock lock(lock_);
350 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) 339 if (plugins_loaded_ && !refresh && !plugins_need_refresh_)
351 return; 340 return;
352 341
353 // Clear the refresh bit now, because it might get set again before we 342 // Clear the refresh bit now, because it might get set again before we
354 // reach the end of the method. 343 // reach the end of the method.
355 plugins_need_refresh_ = false; 344 plugins_need_refresh_ = false;
356 extra_plugin_paths = extra_plugin_paths_; 345 extra_plugin_paths = extra_plugin_paths_;
357 extra_plugin_dirs = extra_plugin_dirs_; 346 extra_plugin_dirs = extra_plugin_dirs_;
358 internal_plugins = internal_plugins_; 347 internal_plugins = internal_plugins_;
359 } 348 }
360 349
361 std::vector<WebPluginInfo> new_plugins; 350 ScopedVector<PluginGroup> new_plugin_groups;
362 std::set<FilePath> visited_plugins; 351 std::set<FilePath> visited_plugins;
363 352
364 std::vector<FilePath> directories_to_scan; 353 std::vector<FilePath> directories_to_scan;
365 GetPluginDirectories(&directories_to_scan); 354 GetPluginDirectories(&directories_to_scan);
366 355
367 // Load internal plugins first so that, if both an internal plugin and a 356 // Load internal plugins first so that, if both an internal plugin and a
368 // "discovered" plugin want to handle the same type, the internal plugin 357 // "discovered" plugin want to handle the same type, the internal plugin
369 // will have precedence. 358 // will have precedence.
370 for (size_t i = 0; i < internal_plugins.size(); ++i) { 359 for (size_t i = 0; i < internal_plugins.size(); ++i) {
371 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName) 360 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName)
372 continue; 361 continue;
373 LoadPlugin(internal_plugins[i].info.path, &new_plugins); 362 LoadPlugin(internal_plugins[i].info.path, &new_plugin_groups);
374 } 363 }
375 364
376 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { 365 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) {
377 const FilePath& path = extra_plugin_paths[i]; 366 const FilePath& path = extra_plugin_paths[i];
378 if (visited_plugins.find(path) != visited_plugins.end()) 367 if (visited_plugins.find(path) != visited_plugins.end())
379 continue; 368 continue;
380 LoadPlugin(path, &new_plugins); 369 LoadPlugin(path, &new_plugin_groups);
381 visited_plugins.insert(path); 370 visited_plugins.insert(path);
382 } 371 }
383 372
384 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { 373 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) {
385 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); 374 LoadPluginsFromDir(
375 extra_plugin_dirs[i], &new_plugin_groups, &visited_plugins);
386 } 376 }
387 377
388 for (size_t i = 0; i < directories_to_scan.size(); ++i) { 378 for (size_t i = 0; i < directories_to_scan.size(); ++i) {
389 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); 379 LoadPluginsFromDir(
380 directories_to_scan[i], &new_plugin_groups, &visited_plugins);
390 } 381 }
391 382
392 #if defined(OS_WIN) 383 #if defined(OS_WIN)
393 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); 384 LoadPluginsFromRegistry(&new_plugin_groups, &visited_plugins);
394 #endif 385 #endif
395 386
396 // Load the default plugin last. 387 // Load the default plugin last.
397 if (webkit_glue::IsDefaultPluginEnabled()) 388 if (webkit_glue::IsDefaultPluginEnabled())
398 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugins); 389 LoadPlugin(FilePath(kDefaultPluginLibraryName), &new_plugin_groups);
399 390
391 AutoLock lock(lock_);
392
393 // Grab all plugins that were found before to copy enabled statuses.
394 std::vector<WebPluginInfo> old_plugins;
395 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
396 const std::vector<WebPluginInfo>& gr_plugins =
397 plugin_groups_[i]->web_info_plugins();
398 old_plugins.insert(old_plugins.end(), gr_plugins.begin(), gr_plugins.end());
399 }
400 // Disable all of the plugins and plugin groups that are disabled by policy. 400 // Disable all of the plugins and plugin groups that are disabled by policy.
401 // There's currenly a bug that makes it impossible to correctly re-enable 401 for (size_t i = 0; i < new_plugin_groups.size(); ++i) {
402 // plugins or plugin-groups to their original, "pre-policy" state, so 402 PluginGroup* group = new_plugin_groups[i];
403 // plugins and groups are only changed to a more "safe" state after a policy
404 // change, i.e. from enabled to disabled. See bug 54681.
405 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin();
406 it != plugin_groups_.end(); ++it) {
407 PluginGroup* group = it->second;
408 string16 group_name = group->GetGroupName(); 403 string16 group_name = group->GetGroupName();
409 if (ShouldDisableGroup(group_name)) { 404
410 group->Enable(false); 405 std::vector<WebPluginInfo>& gr_plugins = group->web_info_plugins();
406 for (size_t j = 0; j < gr_plugins.size(); ++j) {
407 int plugin_found = -1;
408 for (size_t k = 0; k < old_plugins.size(); ++k) {
409 if (gr_plugins[j].path == old_plugins[k].path) {
410 plugin_found = k;
411 break;
412 }
413 }
414 if (plugin_found >= 0) {
jam 2011/01/20 18:22:34 nit: no need for brace brackets
pastarmovj 2011/01/20 22:59:49 Done.
415 gr_plugins[j].enabled = old_plugins[plugin_found].enabled;
416 }
417 // Set the disabled flag of all plugins scheduled for disabling.
418 for (size_t k = 0; k < prematurely_disabled_plugins_.size(); ++k) {
419 if (gr_plugins[j].path == prematurely_disabled_plugins_[k]) {
420 group->DisablePlugin(gr_plugins[j].path);
421 }
422 }
423 }
424 if (group->IsEmpty()) {
425 if (!group->Enabled())
426 prematurely_disabled_groups_.push_back(group->GetGroupName());
427 new_plugin_groups.erase(new_plugin_groups.begin() + i);
428 --i;
429 continue;
411 } 430 }
412 431
413 if (disable_outdated_plugins_) { 432 group->EnforceGroupPolicy();
433 if (disable_outdated_plugins_)
414 group->DisableOutdatedPlugins(); 434 group->DisableOutdatedPlugins();
415 }
416 if (!group->Enabled()) {
417 AutoLock lock(lock_);
418 disabled_groups_.insert(group_name);
419 }
420 } 435 }
421 436
422 // Only update the data now since loading plugins can take a while. 437 // We flush the list of prematurely disabled plugins after the load has
423 AutoLock lock(lock_); 438 // finished. If for some reason a plugin reappears on a second load it is
439 // going to be loaded normally. This is only true for non-policy controlled
440 // plugins though.
441 prematurely_disabled_plugins_.clear();
424 442
425 plugins_ = new_plugins; 443 plugin_groups_.swap(new_plugin_groups);
426 plugins_loaded_ = true; 444 plugins_loaded_ = true;
427 } 445 }
428 446
429 void PluginList::LoadPlugin(const FilePath& path, 447 void PluginList::LoadPlugin(const FilePath& path,
430 std::vector<WebPluginInfo>* plugins) { 448 ScopedVector<PluginGroup>* plugin_groups) {
431 LOG_IF(ERROR, PluginList::DebugPluginLoading()) 449 LOG_IF(ERROR, PluginList::DebugPluginLoading())
432 << "Loading plugin " << path.value(); 450 << "Loading plugin " << path.value();
433
434 WebPluginInfo plugin_info; 451 WebPluginInfo plugin_info;
435 const PluginEntryPoints* entry_points; 452 const PluginEntryPoints* entry_points;
436 453
437 if (!ReadPluginInfo(path, &plugin_info, &entry_points)) 454 if (!ReadPluginInfo(path, &plugin_info, &entry_points))
438 return; 455 return;
439 456
440 if (!ShouldLoadPlugin(plugin_info, plugins)) 457 if (!ShouldLoadPlugin(plugin_info, plugin_groups))
441 return; 458 return;
442 459
443 if (path.value() != kDefaultPluginLibraryName 460 if (path.value() != kDefaultPluginLibraryName
444 #if defined(OS_WIN) && !defined(NDEBUG) 461 #if defined(OS_WIN) && !defined(NDEBUG)
445 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY 462 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY
446 #endif 463 #endif
447 ) { 464 ) {
448 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { 465 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) {
449 // TODO: don't load global handlers for now. 466 // TODO: don't load global handlers for now.
450 // WebKit hands to the Plugin before it tries 467 // WebKit hands to the Plugin before it tries
451 // to handle mimeTypes on its own. 468 // to handle mimeTypes on its own.
452 const std::string &mime_type = plugin_info.mime_types[i].mime_type; 469 const std::string &mime_type = plugin_info.mime_types[i].mime_type;
453 if (mime_type == "*" ) 470 if (mime_type == "*" )
454 return; 471 return;
455 } 472 }
456 } 473 }
457 474
458 // Mark disabled plugins as such. (This has to happen before calling 475 AddToPluginGroups(plugin_info, plugin_groups);
459 // |AddToPluginGroups(plugin_info)|.)
460 if (disabled_plugins_.count(plugin_info.path)) {
461 plugin_info.enabled = false;
462 } else {
463 plugin_info.enabled = true;
464 }
465
466 AutoLock lock(lock_);
467 plugins->push_back(plugin_info);
468 AddToPluginGroups(plugin_info);
469 } 476 }
470 477
471 bool PluginList::SupportsType(const WebPluginInfo& info,
472 const std::string &mime_type,
473 bool allow_wildcard) {
474 // Webkit will ask for a plugin to handle empty mime types.
475 if (mime_type.empty())
476 return false;
477
478 for (size_t i = 0; i < info.mime_types.size(); ++i) {
479 const WebPluginMimeType& mime_info = info.mime_types[i];
480 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
481 if (!allow_wildcard && mime_info.mime_type == "*") {
482 continue;
483 }
484 return true;
485 }
486 }
487 return false;
488 }
489
490 bool PluginList::SupportsExtension(const WebPluginInfo& info,
491 const std::string &extension,
492 std::string* actual_mime_type) {
493 for (size_t i = 0; i < info.mime_types.size(); ++i) {
494 const WebPluginMimeType& mime_type = info.mime_types[i];
495 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
496 if (mime_type.file_extensions[j] == extension) {
497 if (actual_mime_type)
498 *actual_mime_type = mime_type.mime_type;
499 return true;
500 }
501 }
502 }
503
504 return false;
505 }
506
507
508 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { 478 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) {
509 LoadPlugins(refresh); 479 LoadPlugins(refresh);
510 480
511 AutoLock lock(lock_); 481 AutoLock lock(lock_);
512 *plugins = plugins_; 482 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
483 const std::vector<WebPluginInfo>& gr_plugins =
484 plugin_groups_[i]->web_info_plugins();
485 plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end());
486 }
513 } 487 }
514 488
515 void PluginList::GetEnabledPlugins(bool refresh, 489 void PluginList::GetEnabledPlugins(bool refresh,
516 std::vector<WebPluginInfo>* plugins) { 490 std::vector<WebPluginInfo>* plugins) {
517 LoadPlugins(refresh); 491 LoadPlugins(refresh);
518 492
519 plugins->clear(); 493 plugins->clear();
520 AutoLock lock(lock_); 494 AutoLock lock(lock_);
521 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); 495 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
522 it != plugins_.end(); 496 const std::vector<WebPluginInfo>& gr_plugins =
523 ++it) { 497 plugin_groups_[i]->web_info_plugins();
524 if (it->enabled) 498 for (size_t i = 0; i < gr_plugins.size(); ++i) {
525 plugins->push_back(*it); 499 if (IsPluginEnabled(gr_plugins[i]))
500 plugins->push_back(gr_plugins[i]);
501 }
526 } 502 }
527 } 503 }
528 504
529 void PluginList::GetPluginInfoArray( 505 void PluginList::GetPluginInfoArray(
530 const GURL& url, 506 const GURL& url,
531 const std::string& mime_type, 507 const std::string& mime_type,
532 bool allow_wildcard, 508 bool allow_wildcard,
533 std::vector<WebPluginInfo>* info, 509 std::vector<WebPluginInfo>* info,
534 std::vector<std::string>* actual_mime_types) { 510 std::vector<std::string>* actual_mime_types) {
535 DCHECK(mime_type == StringToLowerASCII(mime_type)); 511 DCHECK(mime_type == StringToLowerASCII(mime_type));
536 DCHECK(info); 512 DCHECK(info);
537 513
538 LoadPlugins(false); 514 LoadPlugins(false);
539 AutoLock lock(lock_); 515 AutoLock lock(lock_);
540 info->clear(); 516 info->clear();
541 if (actual_mime_types) 517 if (actual_mime_types)
542 actual_mime_types->clear(); 518 actual_mime_types->clear();
543 519
544 std::set<FilePath> visited_plugins; 520 std::set<FilePath> visited_plugins;
545 521
546 // Add in enabled plugins by mime type. 522 // Add in enabled plugins by mime type.
547 WebPluginInfo default_plugin; 523 WebPluginInfo default_plugin;
548 for (size_t i = 0; i < plugins_.size(); ++i) { 524 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
549 if (plugins_[i].enabled && 525 const std::vector<WebPluginInfo>& plugins =
550 SupportsType(plugins_[i], mime_type, allow_wildcard)) { 526 plugin_groups_[i]->web_info_plugins();
551 FilePath path = plugins_[i].path; 527 for (size_t i = 0; i < plugins.size(); ++i) {
552 if (path.value() != kDefaultPluginLibraryName && 528 if (IsPluginEnabled(plugins[i]) && SupportsType(plugins[i],
553 visited_plugins.insert(path).second) { 529 mime_type, allow_wildcard)) {
554 info->push_back(plugins_[i]); 530 FilePath path = plugins[i].path;
555 if (actual_mime_types) 531 if (path.value() != kDefaultPluginLibraryName &&
556 actual_mime_types->push_back(mime_type); 532 visited_plugins.insert(path).second) {
533 info->push_back(plugins[i]);
534 if (actual_mime_types)
535 actual_mime_types->push_back(mime_type);
536 }
557 } 537 }
558 } 538 }
559 } 539 }
560 540
561 // Add in enabled plugins by url. 541 // Add in enabled plugins by url.
562 std::string path = url.path(); 542 std::string path = url.path();
563 std::string::size_type last_dot = path.rfind('.'); 543 std::string::size_type last_dot = path.rfind('.');
564 if (last_dot != std::string::npos) { 544 if (last_dot != std::string::npos) {
565 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); 545 std::string extension = StringToLowerASCII(std::string(path, last_dot+1));
566 std::string actual_mime_type; 546 std::string actual_mime_type;
567 for (size_t i = 0; i < plugins_.size(); ++i) { 547 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
568 if (plugins_[i].enabled && 548 const std::vector<WebPluginInfo>& plugins =
569 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { 549 plugin_groups_[i]->web_info_plugins();
570 FilePath path = plugins_[i].path; 550 for (size_t i = 0; i < plugins.size(); ++i) {
571 if (path.value() != kDefaultPluginLibraryName && 551 if (IsPluginEnabled(plugins[i]) &&
572 visited_plugins.insert(path).second) { 552 SupportsExtension(plugins[i], extension, &actual_mime_type)) {
573 info->push_back(plugins_[i]); 553 FilePath path = plugins[i].path;
574 if (actual_mime_types) 554 if (path.value() != kDefaultPluginLibraryName &&
575 actual_mime_types->push_back(actual_mime_type); 555 visited_plugins.insert(path).second) {
556 info->push_back(plugins[i]);
557 if (actual_mime_types)
558 actual_mime_types->push_back(actual_mime_type);
559 }
576 } 560 }
577 } 561 }
578 } 562 }
579 } 563 }
580 564
581 // Add in disabled plugins by mime type. 565 // Add in disabled plugins by mime type.
582 for (size_t i = 0; i < plugins_.size(); ++i) { 566 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
583 if (!plugins_[i].enabled && 567 const std::vector<WebPluginInfo>& plugins =
584 SupportsType(plugins_[i], mime_type, allow_wildcard)) { 568 plugin_groups_[i]->web_info_plugins();
585 FilePath path = plugins_[i].path; 569 for (size_t i = 0; i < plugins.size(); ++i) {
586 if (path.value() != kDefaultPluginLibraryName && 570 if (!IsPluginEnabled(plugins[i]) &&
587 visited_plugins.insert(path).second) { 571 SupportsType(plugins[i], mime_type, allow_wildcard)) {
588 info->push_back(plugins_[i]); 572 FilePath path = plugins[i].path;
589 if (actual_mime_types) 573 if (path.value() != kDefaultPluginLibraryName &&
590 actual_mime_types->push_back(mime_type); 574 visited_plugins.insert(path).second) {
575 info->push_back(plugins[i]);
576 if (actual_mime_types)
577 actual_mime_types->push_back(mime_type);
578 }
591 } 579 }
592 } 580 }
593 } 581 }
594 582
595 // Add the default plugin at the end if it supports the mime type given, 583 // Add the default plugin at the end if it supports the mime type given,
596 // and the default plugin is enabled. 584 // and the default plugin is enabled.
597 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { 585 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
598 const WebPluginInfo& default_info = plugins_.back(); 586 #if defined(OS_WIN)
599 if (SupportsType(default_info, mime_type, allow_wildcard)) { 587 if (plugin_groups_[i]->identifier().compare(
600 info->push_back(default_info); 588 WideToUTF8(kDefaultPluginLibraryName)) == 0) {
601 if (actual_mime_types) 589 #else
602 actual_mime_types->push_back(mime_type); 590 if (plugin_groups_[i]->identifier().compare(
591 kDefaultPluginLibraryName) == 0) {
592 #endif
593 DCHECK_NE(0U, plugin_groups_[i]->web_info_plugins().size());
594 const WebPluginInfo& default_info =
595 plugin_groups_[i]->web_info_plugins()[0];
596 if (SupportsType(default_info, mime_type, allow_wildcard)) {
597 info->push_back(default_info);
598 if (actual_mime_types)
599 actual_mime_types->push_back(mime_type);
600 }
603 } 601 }
604 } 602 }
605 } 603 }
606 604
607 bool PluginList::GetPluginInfo(const GURL& url, 605 bool PluginList::GetPluginInfo(const GURL& url,
608 const std::string& mime_type, 606 const std::string& mime_type,
609 bool allow_wildcard, 607 bool allow_wildcard,
610 WebPluginInfo* info, 608 WebPluginInfo* info,
611 std::string* actual_mime_type) { 609 std::string* actual_mime_type) {
612 DCHECK(info); 610 DCHECK(info);
(...skipping 17 matching lines...) Expand all
630 return true; 628 return true;
631 } 629 }
632 } 630 }
633 return false; 631 return false;
634 } 632 }
635 633
636 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, 634 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path,
637 WebPluginInfo* info) { 635 WebPluginInfo* info) {
638 LoadPlugins(false); 636 LoadPlugins(false);
639 AutoLock lock(lock_); 637 AutoLock lock(lock_);
640 for (size_t i = 0; i < plugins_.size(); ++i) { 638 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
641 if (plugins_[i].path == plugin_path) { 639 const std::vector<WebPluginInfo>& plugins =
642 *info = plugins_[i]; 640 plugin_groups_[i]->web_info_plugins();
643 return true; 641 for (size_t i = 0; i < plugins.size(); ++i) {
642 if (plugins[i].path == plugin_path) {
643 *info = plugins[i];
644 return true;
645 }
644 } 646 }
645 } 647 }
646 648
647 return false; 649 return false;
648 } 650 }
649 651
650 void PluginList::GetPluginGroups( 652 void PluginList::GetPluginGroups(
651 bool load_if_necessary, 653 bool load_if_necessary,
652 std::vector<PluginGroup>* plugin_groups) { 654 std::vector<PluginGroup>* plugin_groups) {
653 if (load_if_necessary) 655 if (load_if_necessary)
654 LoadPlugins(false); 656 LoadPlugins(false);
657 AutoLock lock(lock_);
655 plugin_groups->clear(); 658 plugin_groups->clear();
656 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); 659 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
657 it != plugin_groups_.end(); ++it) { 660 // In some unit tests we can get confronted with empty groups but in real
658 if (!it->second->IsEmpty()) 661 // world code this if should never be false here.
659 plugin_groups->push_back(*it->second); 662 if(!plugin_groups_[i]->IsEmpty())
663 plugin_groups->push_back(*plugin_groups_[i]);
660 } 664 }
661 } 665 }
662 666
663 const PluginGroup* PluginList::GetPluginGroup( 667 const PluginGroup* PluginList::GetPluginGroup(
664 const WebPluginInfo& web_plugin_info) { 668 const WebPluginInfo& web_plugin_info) {
665 AutoLock lock(lock_); 669 AutoLock lock(lock_);
666 return AddToPluginGroups(web_plugin_info); 670 return AddToPluginGroups(web_plugin_info, &plugin_groups_);
667 } 671 }
668 672
669 string16 PluginList::GetPluginGroupName(std::string identifier) { 673 string16 PluginList::GetPluginGroupName(const std::string& identifier) {
670 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); 674 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
671 if (it == plugin_groups_.end()) { 675 if(plugin_groups_[i]->identifier() == identifier)
672 return string16(); 676 return plugin_groups_[i]->GetGroupName();
673 } 677 }
674 return it->second->GetGroupName(); 678 return string16();
675 } 679 }
676 680
677 std::string PluginList::GetPluginGroupIdentifier( 681 std::string PluginList::GetPluginGroupIdentifier(
678 const WebPluginInfo& web_plugin_info) { 682 const WebPluginInfo& web_plugin_info) {
679 AutoLock lock(lock_); 683 AutoLock lock(lock_);
680 PluginGroup* group = AddToPluginGroups(web_plugin_info); 684 PluginGroup* group = AddToPluginGroups(web_plugin_info, &plugin_groups_);
681 return group->identifier(); 685 return group->identifier();
682 } 686 }
683 687
684 void PluginList::AddHardcodedPluginGroups() { 688 void PluginList::AddHardcodedPluginGroups() {
685 AutoLock lock(lock_); 689 AutoLock lock(lock_);
686 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); 690 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions();
687 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { 691 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) {
688 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( 692 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition(
689 definitions[i]); 693 definitions[i]);
690 std::string identifier = definition_group->identifier(); 694 ProcessGroupAfterInitialize(definition_group);
691 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); 695 plugin_groups_.push_back(definition_group);
692 plugin_groups_.insert(std::make_pair(identifier, definition_group));
693 } 696 }
694 } 697 }
695 698
696 PluginGroup* PluginList::AddToPluginGroups( 699 PluginGroup* PluginList::AddToPluginGroups(
697 const WebPluginInfo& web_plugin_info) { 700 const WebPluginInfo& web_plugin_info,
701 ScopedVector<PluginGroup>* plugin_groups) {
698 PluginGroup* group = NULL; 702 PluginGroup* group = NULL;
699 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); 703 for (size_t i = 0; i < plugin_groups->size(); ++i) {
700 it != plugin_groups_.end(); ++it) { 704 if ((*plugin_groups)[i]->Match(web_plugin_info)) {
701 if (it->second->Match(web_plugin_info)) 705 group = (*plugin_groups)[i];
702 group = it->second; 706 break;
707 }
703 } 708 }
704 if (!group) { 709 if (!group) {
705 group = PluginGroup::FromWebPluginInfo(web_plugin_info); 710 group = PluginGroup::FromWebPluginInfo(web_plugin_info);
711 // If group is scheduled for disabling do that now and remove it from the
712 // list.
713 for(size_t i = 0; i < prematurely_disabled_groups_.size(); ++i) {
714 if (group->GetGroupName() == prematurely_disabled_groups_[i]) {
715 group->EnableGroup(false);
716 prematurely_disabled_groups_.erase(
717 prematurely_disabled_groups_.begin() + i);
718 }
719 }
720 ProcessGroupAfterInitialize(group);
706 std::string identifier = group->identifier(); 721 std::string identifier = group->identifier();
707 // If the identifier is not unique, use the full path. This means that we 722 // If the identifier is not unique, use the full path. This means that we
708 // probably won't be able to search for this group by identifier, but at 723 // probably won't be able to search for this group by identifier, but at
709 // least it's going to be in the set of plugin groups, and if there 724 // least it's going to be in the set of plugin groups, and if there
710 // is already a plug-in with the same filename, it's probably going to 725 // is already a plug-in with the same filename, it's probably going to
711 // handle the same MIME types (and it has a higher priority), so this one 726 // handle the same MIME types (and it has a higher priority), so this one
712 // is not going to run anyway. 727 // is not going to run anyway.
713 if (plugin_groups_.find(identifier) != plugin_groups_.end()) 728 for (size_t i = 0; i < plugin_groups->size(); ++i) {
714 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); 729 if ((*plugin_groups)[i]->identifier() == identifier) {
715 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); 730 group->identifier() = PluginGroup::GetLongIdentifier(web_plugin_info);
716 plugin_groups_.insert(std::make_pair(identifier, group)); 731 break;
732 }
733 }
734 plugin_groups->push_back(group);
717 } 735 }
718 group->AddPlugin(web_plugin_info, next_priority_++); 736 group->AddPlugin(web_plugin_info);
719 return group; 737 return group;
720 } 738 }
721 739
722 bool PluginList::EnablePlugin(const FilePath& filename) { 740 bool PluginList::EnablePlugin(const FilePath& filename) {
723 AutoLock lock(lock_); 741 AutoLock lock(lock_);
724 742 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
725 bool did_enable = false; 743 if (plugin_groups_[i]->ContainsPlugin(filename))
726 744 return plugin_groups_[i]->EnablePlugin(filename);
727 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename);
728 if (entry == disabled_plugins_.end())
729 return did_enable; // Early exit if plugin not in disabled list.
730
731 disabled_plugins_.erase(entry); // Remove from disabled list.
732
733 // Set enabled flags if necessary.
734 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
735 it != plugins_.end();
736 ++it) {
737 if (it->path == filename) {
738 DCHECK(!it->enabled); // Should have been disabled.
739 it->enabled = true;
740 did_enable = true;
741 }
742 } 745 }
743 746
744 return did_enable; 747 // Non existing plugin is beig enabled. Ignore this request for now because
748 // plugins are anyway born enabled.
749 return true;
745 } 750 }
746 751
747 bool PluginList::DisablePlugin(const FilePath& filename) { 752 bool PluginList::DisablePlugin(const FilePath& filename) {
748 AutoLock lock(lock_); 753 AutoLock lock(lock_);
749 754 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
750 bool did_disable = false; 755 if (plugin_groups_[i]->ContainsPlugin(filename))
751 756 return plugin_groups_[i]->DisablePlugin(filename);
752 if (disabled_plugins_.find(filename) != disabled_plugins_.end())
753 return did_disable; // Early exit if plugin already in disabled list.
754
755 disabled_plugins_.insert(filename); // Add to disabled list.
756
757 // Unset enabled flags if necessary.
758 for (std::vector<WebPluginInfo>::iterator it = plugins_.begin();
759 it != plugins_.end();
760 ++it) {
761 if (it->path == filename) {
762 DCHECK(it->enabled); // Should have been enabled.
763 it->enabled = false;
764 did_disable = true;
765 }
766 } 757 }
767 758
768 return did_disable; 759 // Non existing plugin is being disabled. Queue the plugin so that on the next
760 // load plugins call they will be disabled.
761 prematurely_disabled_plugins_.push_back(filename);
762 return true;
769 } 763 }
770 764
771 bool PluginList::EnableGroup(bool enable, const string16& group_name) { 765 bool PluginList::EnableGroup(bool enable, const string16& group_name) {
772 bool did_change = false; 766 AutoLock lock(lock_);
773 { 767 PluginGroup* group = NULL;
774 AutoLock lock(lock_); 768 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
775 769 if (plugin_groups_[i]->GetGroupName().find(group_name) != string16::npos) {
776 std::set<string16>::iterator entry = disabled_groups_.find(group_name); 770 group = plugin_groups_[i];
777 if (enable) { 771 break;
778 if (entry == disabled_groups_.end())
779 return did_change; // Early exit if group not in disabled list.
780 disabled_groups_.erase(entry); // Remove from disabled list.
781 } else {
782 if (entry != disabled_groups_.end())
783 return did_change; // Early exit if group already in disabled list.
784 disabled_groups_.insert(group_name);
785 } 772 }
786 } 773 }
774 if (!group) {
775 // Non existing group is being enabled. Queue the group so that on the next
776 // load plugins call they will be disabled.
777 if(!enable)
778 prematurely_disabled_groups_.push_back(group_name);
779 return true;
780 }
787 781
788 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); 782 return group->EnableGroup(enable);
789 it != plugin_groups_.end(); ++it) { 783 }
790 if (it->second->GetGroupName() == group_name) { 784
791 if (it->second->Enabled() != enable) { 785 bool PluginList::SupportsType(const WebPluginInfo& plugin,
792 it->second->Enable(enable); 786 const std::string& mime_type,
793 did_change = true; 787 bool allow_wildcard) {
794 break; 788 // Webkit will ask for a plugin to handle empty mime types.
789 if (mime_type.empty())
790 return false;
791
792 for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
793 const WebPluginMimeType& mime_info = plugin.mime_types[i];
794 if (net::MatchesMimeType(mime_info.mime_type, mime_type)) {
795 if (!allow_wildcard && mime_info.mime_type == "*")
796 continue;
797 return true;
798 }
799 }
800 return false;
801 }
802
803 bool PluginList::SupportsExtension(const WebPluginInfo& plugin,
804 const std::string& extension,
805 std::string* actual_mime_type) {
806 for (size_t i = 0; i < plugin.mime_types.size(); ++i) {
807 const WebPluginMimeType& mime_type = plugin.mime_types[i];
808 for (size_t j = 0; j < mime_type.file_extensions.size(); ++j) {
809 if (mime_type.file_extensions[j] == extension) {
810 if (actual_mime_type)
811 *actual_mime_type = mime_type.mime_type;
812 return true;
795 } 813 }
796 } 814 }
797 } 815 }
798 816 return false;
799 return did_change;
800 } 817 }
801 818
802 void PluginList::DisableOutdatedPluginGroups() { 819 void PluginList::DisableOutdatedPluginGroups() {
803 disable_outdated_plugins_ = true; 820 disable_outdated_plugins_ = true;
804 } 821 }
805 822
806 PluginList::~PluginList() { 823 PluginList::~PluginList() {
807 Shutdown();
808 } 824 }
809 825
810 void PluginList::Shutdown() {
811 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(),
812 plugin_groups_.end());
813 }
814 826
815 } // namespace npapi 827 } // namespace npapi
816 } // namespace webkit 828 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698