| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/plugins/plugin_observer.h" | 5 #include "chrome/browser/plugins/plugin_observer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/debug/crash_logging.h" | 11 #include "base/debug/crash_logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/stl_util.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 20 #include "chrome/browser/plugins/flash_download_interception.h" | 19 #include "chrome/browser/plugins/flash_download_interception.h" |
| 21 #include "chrome/browser/plugins/plugin_finder.h" | 20 #include "chrome/browser/plugins/plugin_finder.h" |
| 22 #include "chrome/browser/plugins/plugin_infobar_delegates.h" | 21 #include "chrome/browser/plugins/plugin_infobar_delegates.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 23 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 std::string component_id_; | 296 std::string component_id_; |
| 298 DISALLOW_COPY_AND_ASSIGN(ComponentObserver); | 297 DISALLOW_COPY_AND_ASSIGN(ComponentObserver); |
| 299 }; | 298 }; |
| 300 | 299 |
| 301 PluginObserver::PluginObserver(content::WebContents* web_contents) | 300 PluginObserver::PluginObserver(content::WebContents* web_contents) |
| 302 : content::WebContentsObserver(web_contents), | 301 : content::WebContentsObserver(web_contents), |
| 303 weak_ptr_factory_(this) { | 302 weak_ptr_factory_(this) { |
| 304 } | 303 } |
| 305 | 304 |
| 306 PluginObserver::~PluginObserver() { | 305 PluginObserver::~PluginObserver() { |
| 307 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) | |
| 308 base::STLDeleteValues(&plugin_placeholders_); | |
| 309 #endif | |
| 310 } | 306 } |
| 311 | 307 |
| 312 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, | 308 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, |
| 313 base::ProcessId plugin_pid) { | 309 base::ProcessId plugin_pid) { |
| 314 DCHECK(!plugin_path.value().empty()); | 310 DCHECK(!plugin_path.value().empty()); |
| 315 | 311 |
| 316 base::string16 plugin_name = | 312 base::string16 plugin_name = |
| 317 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 313 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
| 318 base::string16 infobar_text; | 314 base::string16 infobar_text; |
| 319 #if defined(OS_WIN) | 315 #if defined(OS_WIN) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 380 } |
| 385 | 381 |
| 386 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, | 382 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, |
| 387 const std::string& identifier) { | 383 const std::string& identifier) { |
| 388 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) | 384 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| 389 PluginFinder* finder = PluginFinder::GetInstance(); | 385 PluginFinder* finder = PluginFinder::GetInstance(); |
| 390 // Find plugin to update. | 386 // Find plugin to update. |
| 391 PluginInstaller* installer = NULL; | 387 PluginInstaller* installer = NULL; |
| 392 std::unique_ptr<PluginMetadata> plugin; | 388 std::unique_ptr<PluginMetadata> plugin; |
| 393 if (finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) { | 389 if (finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) { |
| 394 plugin_placeholders_[placeholder_id] = new PluginPlaceholderHost( | 390 plugin_placeholders_[placeholder_id] = |
| 395 this, placeholder_id, plugin->name(), installer); | 391 base::MakeUnique<PluginPlaceholderHost>(this, placeholder_id, |
| 392 plugin->name(), installer); |
| 396 OutdatedPluginInfoBarDelegate::Create( | 393 OutdatedPluginInfoBarDelegate::Create( |
| 397 InfoBarService::FromWebContents(web_contents()), installer, | 394 InfoBarService::FromWebContents(web_contents()), installer, |
| 398 std::move(plugin)); | 395 std::move(plugin)); |
| 399 } else { | 396 } else { |
| 400 NOTREACHED(); | 397 NOTREACHED(); |
| 401 } | 398 } |
| 402 #else | 399 #else |
| 403 // If we don't support third-party plugin installation, we shouldn't have | 400 // If we don't support third-party plugin installation, we shouldn't have |
| 404 // outdated plugins. | 401 // outdated plugins. |
| 405 NOTREACHED(); | 402 NOTREACHED(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 417 } | 414 } |
| 418 | 415 |
| 419 void PluginObserver::RemoveComponentObserver(int placeholder_id) { | 416 void PluginObserver::RemoveComponentObserver(int placeholder_id) { |
| 420 auto it = component_observers_.find(placeholder_id); | 417 auto it = component_observers_.find(placeholder_id); |
| 421 DCHECK(it != component_observers_.end()); | 418 DCHECK(it != component_observers_.end()); |
| 422 component_observers_.erase(it); | 419 component_observers_.erase(it); |
| 423 } | 420 } |
| 424 | 421 |
| 425 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) | 422 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| 426 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { | 423 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { |
| 427 std::map<int, PluginPlaceholderHost*>::iterator it = | 424 auto it = plugin_placeholders_.find(placeholder_id); |
| 428 plugin_placeholders_.find(placeholder_id); | |
| 429 if (it == plugin_placeholders_.end()) { | 425 if (it == plugin_placeholders_.end()) { |
| 430 NOTREACHED(); | 426 NOTREACHED(); |
| 431 return; | 427 return; |
| 432 } | 428 } |
| 433 delete it->second; | |
| 434 plugin_placeholders_.erase(it); | 429 plugin_placeholders_.erase(it); |
| 435 } | 430 } |
| 436 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) | 431 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION) |
| 437 | 432 |
| 438 void PluginObserver::OnOpenAboutPlugins() { | 433 void PluginObserver::OnOpenAboutPlugins() { |
| 439 web_contents()->OpenURL( | 434 web_contents()->OpenURL( |
| 440 OpenURLParams(GURL(chrome::kChromeUIPluginsURL), | 435 OpenURLParams(GURL(chrome::kChromeUIPluginsURL), |
| 441 content::Referrer::SanitizeForRequest( | 436 content::Referrer::SanitizeForRequest( |
| 442 GURL(chrome::kChromeUIPluginsURL), | 437 GURL(chrome::kChromeUIPluginsURL), |
| 443 content::Referrer(web_contents()->GetURL(), | 438 content::Referrer(web_contents()->GetURL(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 459 base::string16 plugin_name = | 454 base::string16 plugin_name = |
| 460 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 455 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
| 461 SimpleAlertInfoBarDelegate::Create( | 456 SimpleAlertInfoBarDelegate::Create( |
| 462 InfoBarService::FromWebContents(web_contents()), | 457 InfoBarService::FromWebContents(web_contents()), |
| 463 infobars::InfoBarDelegate::PLUGIN_OBSERVER, 0, | 458 infobars::InfoBarDelegate::PLUGIN_OBSERVER, 0, |
| 464 gfx::VectorIconId::EXTENSION_CRASHED, | 459 gfx::VectorIconId::EXTENSION_CRASHED, |
| 465 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, | 460 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, |
| 466 plugin_name), | 461 plugin_name), |
| 467 true); | 462 true); |
| 468 } | 463 } |
| OLD | NEW |