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/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 Loading... | |
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 17 matching lines...) Expand all Loading... | |
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_(0) { |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 | 332 |
341 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | 333 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { |
342 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); | 334 LoadPluginsFromDir(extra_plugin_dirs[i], &new_plugins, &visited_plugins); |
343 } | 335 } |
344 | 336 |
345 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | 337 for (size_t i = 0; i < directories_to_scan.size(); ++i) { |
346 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); | 338 LoadPluginsFromDir(directories_to_scan[i], &new_plugins, &visited_plugins); |
347 } | 339 } |
348 | 340 |
349 #if defined(OS_WIN) | 341 #if defined(OS_WIN) |
350 LoadPluginsFromRegistry(&new_plugins, &visited_plugins); | 342 LoadPluginsFromRegistry(&visited_plugins, &new_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->Enable(false); |
368 } | |
369 | 356 |
370 if (disable_outdated_plugins_) { | 357 if (disable_outdated_plugins_) |
371 group->DisableOutdatedPlugins(); | 358 group->DisableOutdatedPlugins(); |
372 } | |
373 if (!group->Enabled()) { | |
374 AutoLock lock(lock_); | |
375 disabled_groups_.insert(group_name); | |
376 } | |
377 } | 359 } |
378 | 360 |
379 // Only update the data now since loading plugins can take a while. | |
380 AutoLock lock(lock_); | 361 AutoLock lock(lock_); |
381 | |
382 plugins_ = new_plugins; | |
383 plugins_loaded_ = true; | 362 plugins_loaded_ = true; |
384 } | 363 } |
385 | 364 |
386 void PluginList::LoadPlugin(const FilePath& path, | 365 void PluginList::LoadPlugin(const FilePath& path, |
387 std::vector<WebPluginInfo>* plugins) { | 366 std::vector<WebPluginInfo>* plugins) { |
388 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 367 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
389 << "Loading plugin " << path.value(); | 368 << "Loading plugin " << path.value(); |
390 | 369 |
391 WebPluginInfo plugin_info; | 370 WebPluginInfo plugin_info; |
392 const PluginEntryPoints* entry_points; | 371 const PluginEntryPoints* entry_points; |
(...skipping 12 matching lines...) Expand all Loading... | |
405 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { | 384 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { |
406 // TODO: don't load global handlers for now. | 385 // TODO: don't load global handlers for now. |
407 // WebKit hands to the Plugin before it tries | 386 // WebKit hands to the Plugin before it tries |
408 // to handle mimeTypes on its own. | 387 // to handle mimeTypes on its own. |
409 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 388 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
410 if (mime_type == "*" ) | 389 if (mime_type == "*" ) |
411 return; | 390 return; |
412 } | 391 } |
413 } | 392 } |
414 | 393 |
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_); | 394 AutoLock lock(lock_); |
395 AddToPluginGroups(plugin_info); | |
424 plugins->push_back(plugin_info); | 396 plugins->push_back(plugin_info); |
425 AddToPluginGroups(plugin_info); | |
426 } | 397 } |
427 | 398 |
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) { | 399 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
466 LoadPlugins(refresh); | 400 LoadPlugins(refresh); |
467 | 401 |
468 AutoLock lock(lock_); | 402 AutoLock lock(lock_); |
469 *plugins = plugins_; | 403 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
404 group != plugin_groups_.end(); ++group) { | |
405 const std::vector<WebPluginInfo>& gr_plugins = group->second->GetPlugins(); | |
406 plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end()); | |
407 } | |
470 } | 408 } |
471 | 409 |
472 void PluginList::GetEnabledPlugins(bool refresh, | 410 void PluginList::GetEnabledPlugins(bool refresh, |
473 std::vector<WebPluginInfo>* plugins) { | 411 std::vector<WebPluginInfo>* plugins) { |
474 LoadPlugins(refresh); | 412 LoadPlugins(refresh); |
475 | 413 |
476 plugins->clear(); | 414 plugins->clear(); |
477 AutoLock lock(lock_); | 415 AutoLock lock(lock_); |
478 for (std::vector<WebPluginInfo>::const_iterator it = plugins_.begin(); | 416 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
479 it != plugins_.end(); | 417 group != plugin_groups_.end(); ++group) { |
480 ++it) { | 418 const std::vector<WebPluginInfo>& gr_plugins = group->second->GetPlugins(); |
481 if (it->enabled) | 419 for (std::vector<WebPluginInfo>::const_iterator it = gr_plugins.begin(); |
jam
2010/12/17 19:14:45
size_t
pastarmovj
2010/12/20 19:57:37
Done.
| |
482 plugins->push_back(*it); | 420 it != gr_plugins.end(); ++it) { |
421 if (it->IsEnabled()) | |
422 plugins->push_back(*it); | |
423 } | |
483 } | 424 } |
484 } | 425 } |
485 | 426 |
486 void PluginList::GetPluginInfoArray( | 427 void PluginList::GetPluginInfoArray( |
487 const GURL& url, | 428 const GURL& url, |
488 const std::string& mime_type, | 429 const std::string& mime_type, |
489 bool allow_wildcard, | 430 bool allow_wildcard, |
490 std::vector<WebPluginInfo>* info, | 431 std::vector<WebPluginInfo>* info, |
491 std::vector<std::string>* actual_mime_types) { | 432 std::vector<std::string>* actual_mime_types) { |
492 DCHECK(mime_type == StringToLowerASCII(mime_type)); | 433 DCHECK(mime_type == StringToLowerASCII(mime_type)); |
493 DCHECK(info); | 434 DCHECK(info); |
494 | 435 |
495 LoadPlugins(false); | 436 LoadPlugins(false); |
496 AutoLock lock(lock_); | 437 AutoLock lock(lock_); |
497 info->clear(); | 438 info->clear(); |
498 if (actual_mime_types) | 439 if (actual_mime_types) |
499 actual_mime_types->clear(); | 440 actual_mime_types->clear(); |
500 | 441 |
501 std::set<FilePath> visited_plugins; | 442 std::set<FilePath> visited_plugins; |
502 | 443 |
503 // Add in enabled plugins by mime type. | 444 // Add in enabled plugins by mime type. |
504 WebPluginInfo default_plugin; | 445 WebPluginInfo default_plugin; |
505 for (size_t i = 0; i < plugins_.size(); ++i) { | 446 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
506 if (plugins_[i].enabled && | 447 group != plugin_groups_.end(); ++group) { |
507 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 448 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins(); |
508 FilePath path = plugins_[i].path; | 449 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
jam
2010/12/17 19:14:45
size_t
pastarmovj
2010/12/20 19:57:37
Done.
| |
509 if (path.value() != kDefaultPluginLibraryName && | 450 it != plugins.end(); ++it) { |
510 visited_plugins.insert(path).second) { | 451 if (it->IsEnabled() && it->SupportsType(mime_type, allow_wildcard)) { |
511 info->push_back(plugins_[i]); | 452 FilePath path = it->path; |
512 if (actual_mime_types) | 453 if (path.value() != kDefaultPluginLibraryName && |
513 actual_mime_types->push_back(mime_type); | 454 visited_plugins.insert(path).second) { |
455 info->push_back(*it); | |
456 if (actual_mime_types) | |
457 actual_mime_types->push_back(mime_type); | |
458 } | |
514 } | 459 } |
515 } | 460 } |
516 } | 461 } |
517 | 462 |
518 // Add in enabled plugins by url. | 463 // Add in enabled plugins by url. |
519 std::string path = url.path(); | 464 std::string path = url.path(); |
520 std::string::size_type last_dot = path.rfind('.'); | 465 std::string::size_type last_dot = path.rfind('.'); |
521 if (last_dot != std::string::npos) { | 466 if (last_dot != std::string::npos) { |
522 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); | 467 std::string extension = StringToLowerASCII(std::string(path, last_dot+1)); |
523 std::string actual_mime_type; | 468 std::string actual_mime_type; |
524 for (size_t i = 0; i < plugins_.size(); ++i) { | 469 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
525 if (plugins_[i].enabled && | 470 group != plugin_groups_.end(); ++group) { |
526 SupportsExtension(plugins_[i], extension, &actual_mime_type)) { | 471 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins(); |
527 FilePath path = plugins_[i].path; | 472 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
jam
2010/12/17 19:14:45
size_t
pastarmovj
2010/12/20 19:57:37
Done.
| |
528 if (path.value() != kDefaultPluginLibraryName && | 473 it != plugins.end(); ++it) { |
529 visited_plugins.insert(path).second) { | 474 if (it->IsEnabled() && |
530 info->push_back(plugins_[i]); | 475 it->SupportsExtension(extension, &actual_mime_type)) { |
531 if (actual_mime_types) | 476 FilePath path = it->path; |
532 actual_mime_types->push_back(actual_mime_type); | 477 if (path.value() != kDefaultPluginLibraryName && |
478 visited_plugins.insert(path).second) { | |
479 info->push_back(*it); | |
480 if (actual_mime_types) | |
481 actual_mime_types->push_back(actual_mime_type); | |
482 } | |
533 } | 483 } |
534 } | 484 } |
535 } | 485 } |
536 } | 486 } |
537 | 487 |
538 // Add in disabled plugins by mime type. | 488 // Add in disabled plugins by mime type. |
539 for (size_t i = 0; i < plugins_.size(); ++i) { | 489 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
540 if (!plugins_[i].enabled && | 490 group != plugin_groups_.end(); ++group) { |
541 SupportsType(plugins_[i], mime_type, allow_wildcard)) { | 491 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins(); |
542 FilePath path = plugins_[i].path; | 492 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
jam
2010/12/17 19:14:45
size_t
pastarmovj
2010/12/20 19:57:37
Done.
| |
543 if (path.value() != kDefaultPluginLibraryName && | 493 it != plugins.end(); ++it) { |
544 visited_plugins.insert(path).second) { | 494 if (!it->IsEnabled() && it->SupportsType(mime_type, allow_wildcard)) { |
545 info->push_back(plugins_[i]); | 495 FilePath path = it->path; |
546 if (actual_mime_types) | 496 if (path.value() != kDefaultPluginLibraryName && |
547 actual_mime_types->push_back(mime_type); | 497 visited_plugins.insert(path).second) { |
498 info->push_back(*it); | |
499 if (actual_mime_types) | |
500 actual_mime_types->push_back(mime_type); | |
501 } | |
548 } | 502 } |
549 } | 503 } |
550 } | 504 } |
551 | 505 |
552 // Add the default plugin at the end if it supports the mime type given, | 506 // Add the default plugin at the end if it supports the mime type given, |
553 // and the default plugin is enabled. | 507 // and the default plugin is enabled. |
554 if (!plugins_.empty() && webkit_glue::IsDefaultPluginEnabled()) { | 508 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
555 const WebPluginInfo& default_info = plugins_.back(); | 509 group != plugin_groups_.end(); ++group) { |
556 if (SupportsType(default_info, mime_type, allow_wildcard)) { | 510 if (group->first.compare(kDefaultPluginLibraryName) == 0) { |
557 info->push_back(default_info); | 511 DCHECK_NE(0U, group->second->GetPlugins().size()); |
558 if (actual_mime_types) | 512 const WebPluginInfo& default_info = group->second->GetPlugins().front(); |
559 actual_mime_types->push_back(mime_type); | 513 if (default_info.SupportsType(mime_type, allow_wildcard)) { |
514 info->push_back(default_info); | |
515 if (actual_mime_types) | |
516 actual_mime_types->push_back(mime_type); | |
517 } | |
560 } | 518 } |
561 } | 519 } |
562 } | 520 } |
563 | 521 |
564 bool PluginList::GetPluginInfo(const GURL& url, | 522 bool PluginList::GetPluginInfo(const GURL& url, |
565 const std::string& mime_type, | 523 const std::string& mime_type, |
566 bool allow_wildcard, | 524 bool allow_wildcard, |
567 WebPluginInfo* info, | 525 WebPluginInfo* info, |
568 std::string* actual_mime_type) { | 526 std::string* actual_mime_type) { |
569 DCHECK(info); | 527 DCHECK(info); |
(...skipping 17 matching lines...) Expand all Loading... | |
587 return true; | 545 return true; |
588 } | 546 } |
589 } | 547 } |
590 return false; | 548 return false; |
591 } | 549 } |
592 | 550 |
593 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, | 551 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, |
594 WebPluginInfo* info) { | 552 WebPluginInfo* info) { |
595 LoadPlugins(false); | 553 LoadPlugins(false); |
596 AutoLock lock(lock_); | 554 AutoLock lock(lock_); |
597 for (size_t i = 0; i < plugins_.size(); ++i) { | 555 for (PluginGroup::PluginMap::const_iterator group = plugin_groups_.begin(); |
598 if (plugins_[i].path == plugin_path) { | 556 group != plugin_groups_.end(); ++group) { |
599 *info = plugins_[i]; | 557 const std::vector<WebPluginInfo>& plugins = group->second->GetPlugins(); |
600 return true; | 558 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
jam
2010/12/17 19:14:45
size_t
pastarmovj
2010/12/20 19:57:37
Done.
| |
559 it != plugins.end(); ++it) { | |
560 if (it->path == plugin_path) { | |
561 *info = *it; | |
562 return true; | |
563 } | |
601 } | 564 } |
602 } | 565 } |
603 | 566 |
604 return false; | 567 return false; |
605 } | 568 } |
606 | 569 |
607 void PluginList::GetPluginGroups( | 570 void PluginList::GetPluginGroups( |
608 bool load_if_necessary, | 571 bool load_if_necessary, |
609 std::vector<PluginGroup>* plugin_groups) { | 572 std::vector<PluginGroup>* plugin_groups) { |
610 if (load_if_necessary) | 573 if (load_if_necessary) |
611 LoadPlugins(false); | 574 LoadPlugins(false); |
575 AutoLock lock(lock_); | |
612 plugin_groups->clear(); | 576 plugin_groups->clear(); |
613 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); | 577 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); |
614 it != plugin_groups_.end(); ++it) { | 578 it != plugin_groups_.end(); ++it) { |
615 plugin_groups->push_back(*it->second); | 579 plugin_groups->push_back(*it->second); |
616 } | 580 } |
617 } | 581 } |
618 | 582 |
619 const PluginGroup* PluginList::GetPluginGroup( | 583 const PluginGroup* PluginList::GetPluginGroup( |
620 const WebPluginInfo& web_plugin_info) { | 584 const WebPluginInfo& web_plugin_info) { |
621 AutoLock lock(lock_); | 585 AutoLock lock(lock_); |
(...skipping 25 matching lines...) Expand all Loading... | |
647 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 611 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
648 plugin_groups_.insert(std::make_pair(identifier, definition_group)); | 612 plugin_groups_.insert(std::make_pair(identifier, definition_group)); |
649 } | 613 } |
650 } | 614 } |
651 | 615 |
652 PluginGroup* PluginList::AddToPluginGroups( | 616 PluginGroup* PluginList::AddToPluginGroups( |
653 const WebPluginInfo& web_plugin_info) { | 617 const WebPluginInfo& web_plugin_info) { |
654 PluginGroup* group = NULL; | 618 PluginGroup* group = NULL; |
655 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 619 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
656 it != plugin_groups_.end(); ++it) { | 620 it != plugin_groups_.end(); ++it) { |
657 if (it->second->Match(web_plugin_info)) | 621 if (it->second->Match(web_plugin_info)) { |
658 group = it->second; | 622 group = it->second; |
623 break; | |
624 } | |
659 } | 625 } |
660 if (!group) { | 626 if (!group) { |
661 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | 627 group = PluginGroup::FromWebPluginInfo(web_plugin_info); |
662 std::string identifier = group->identifier(); | 628 std::string identifier = group->identifier(); |
663 // If the identifier is not unique, use the full path. This means that we | 629 // 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 | 630 // 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 | 631 // 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 | 632 // 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 | 633 // handle the same MIME types (and it has a higher priority), so this one |
668 // is not going to run anyway. | 634 // is not going to run anyway. |
669 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 635 if (plugin_groups_.find(identifier) != plugin_groups_.end()) |
670 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 636 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); |
671 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 637 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
672 plugin_groups_.insert(std::make_pair(identifier, group)); | 638 plugin_groups_.insert(std::make_pair(identifier, group)); |
673 } | 639 } |
674 group->AddPlugin(web_plugin_info, next_priority_++); | 640 bool is_new_addition = group->AddPlugin(web_plugin_info, next_priority_); |
641 if (is_new_addition) | |
642 next_priority_++; | |
675 return group; | 643 return group; |
676 } | 644 } |
677 | 645 |
678 bool PluginList::EnablePlugin(const FilePath& filename) { | 646 PluginGroup* PluginList::AddToPluginGroups( |
Bernhard Bauer
2010/12/17 18:50:59
There is already a method AddToPluginGroups, and w
pastarmovj
2010/12/20 19:57:37
Renamed to AddPlaceholderToPluginGroup. I explicit
| |
679 AutoLock lock(lock_); | 647 const FilePath& filename, const string16& name) { |
680 | 648 WebPluginInfo plugin_info; |
681 bool did_enable = false; | 649 plugin_info.path = filename; |
682 | 650 plugin_info.name = name; |
683 std::set<FilePath>::iterator entry = disabled_plugins_.find(filename); | 651 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 } | 652 } |
702 | 653 |
703 bool PluginList::DisablePlugin(const FilePath& filename) { | 654 bool PluginList::EnablePlugin(const FilePath& filename, const string16& name) { |
jam
2010/12/17 19:14:45
I still don't understand why name is needed :)
pastarmovj
2010/12/20 19:57:37
For us to be able to have a meaningful placeholder
| |
704 AutoLock lock(lock_); | 655 AutoLock lock(lock_); |
656 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | |
657 it != plugin_groups_.end(); ++it) { | |
658 if (it->second->HasPlugin(filename)) | |
659 return it->second->EnablePlugin(filename); | |
660 } | |
661 // No such group yet add one as a placeholder. | |
Bernhard Bauer
2010/12/17 18:50:59
Nit: Add punctuation please: "No such group yet; a
pastarmovj
2010/12/20 19:57:37
Done.
| |
662 PluginGroup* group = AddToPluginGroups(filename, name); | |
663 return group->EnablePlugin(filename); | |
664 } | |
705 | 665 |
706 bool did_disable = false; | 666 bool PluginList::DisablePlugin(const FilePath& filename, const string16& name) { |
707 | 667 AutoLock lock(lock_); |
708 if (disabled_plugins_.find(filename) != disabled_plugins_.end()) | 668 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
709 return did_disable; // Early exit if plugin already in disabled list. | 669 it != plugin_groups_.end(); ++it) { |
710 | 670 if (it->second->HasPlugin(filename)) |
711 disabled_plugins_.insert(filename); // Add to disabled list. | 671 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 } | 672 } |
723 | 673 // No such group yet add one as a placeholder. |
Bernhard Bauer
2010/12/17 18:50:59
Same nit here.
pastarmovj
2010/12/20 19:57:37
Done.
| |
724 return did_disable; | 674 PluginGroup* group = AddToPluginGroups(filename, name); |
675 return group->DisablePlugin(filename); | |
725 } | 676 } |
726 | 677 |
727 bool PluginList::EnableGroup(bool enable, const string16& group_name) { | 678 bool PluginList::EnableGroup(bool enable, const string16& group_name) { |
728 bool did_change = false; | 679 AutoLock lock(lock_); |
729 { | 680 PluginGroup* group = NULL; |
730 AutoLock lock(lock_); | 681 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
731 | 682 it != plugin_groups_.end(); ++it) { |
732 std::set<string16>::iterator entry = disabled_groups_.find(group_name); | 683 if (it->second->GetGroupName().find(group_name) != string16::npos) { |
733 if (enable) { | 684 group = it->second; |
734 if (entry == disabled_groups_.end()) | 685 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 } | 686 } |
742 } | 687 } |
743 | 688 if (!group) { |
744 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 689 group = PluginGroup::CreateEmptyGroup(group_name); |
745 it != plugin_groups_.end(); ++it) { | 690 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 } | 691 } |
754 | 692 |
755 return did_change; | 693 return group->Enable(enable); |
756 } | 694 } |
757 | 695 |
758 void PluginList::DisableOutdatedPluginGroups() { | 696 void PluginList::DisableOutdatedPluginGroups() { |
759 disable_outdated_plugins_ = true; | 697 disable_outdated_plugins_ = true; |
760 } | 698 } |
761 | 699 |
762 PluginList::~PluginList() { | 700 PluginList::~PluginList() { |
763 Shutdown(); | 701 Shutdown(); |
764 } | 702 } |
765 | 703 |
766 void PluginList::Shutdown() { | 704 void PluginList::Shutdown() { |
767 // TODO | 705 // TODO |
768 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but | 706 // Note: plugin_groups_ contains simple pointers of type PluginGroup*, but |
769 // since this singleton lives until the process is destroyed, no explicit | 707 // since this singleton lives until the process is destroyed, no explicit |
770 // cleanup is necessary. | 708 // cleanup is necessary. |
771 // However, when running on Valgrind, we need to do the cleanup to keep the | 709 // However, when running on Valgrind, we need to do the cleanup to keep the |
772 // memory tree green. | 710 // memory tree green. |
773 #if defined(OS_POSIX) | 711 #if defined(OS_POSIX) |
774 if (RUNNING_ON_VALGRIND) { | 712 if (RUNNING_ON_VALGRIND) { |
775 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 713 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), |
776 plugin_groups_.end()); | 714 plugin_groups_.end()); |
777 } | 715 } |
778 #endif | 716 #endif |
779 } | 717 } |
780 | 718 |
781 } // namespace NPAPI | 719 } // namespace NPAPI |
OLD | NEW |