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