From 5b0033037cded34d2ce97c157f8bd18ca29d1557 Mon Sep 17 00:00:00 2001 From: "bauerb@chromium.org" Date: Fri, 21 Mar 2014 00:09:31 +0000 Subject: [PATCH] Add a reload button to the "plugin crashed" infobar. BUG=307323 Review URL: https://codereview.chromium.org/204623004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258463 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/generated_resources.grd | 5 ++- chrome/browser/plugins/plugin_observer.cc | 72 ++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index f0fbddd94071..c032c23c3711 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -11255,7 +11255,7 @@ Would you like to start $1Add/Remove Pr </p> - + $1Add/Remove Pr $1Shockwave has encountered an error. + + Reload + Could not load $1Shockwave. diff --git a/chrome/browser/plugins/plugin_observer.cc b/chrome/browser/plugins/plugin_observer.cc index 3d2eb2ea181b..66b8612e58a8 100644 --- a/chrome/browser/plugins/plugin_observer.cc +++ b/chrome/browser/plugins/plugin_observer.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" #include "chrome/browser/lifetime/application_lifetime.h" @@ -119,6 +120,72 @@ void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() { Cancel(); } #endif // defined(ENABLE_PLUGIN_INSTALLATION) + +// ReloadPluginInfoBarDelegate ------------------------------------------------- + +class ReloadPluginInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + static void Create(InfoBarService* infobar_service, + content::NavigationController* controller, + const base::string16& message); + + private: + ReloadPluginInfoBarDelegate(content::NavigationController* controller, + const base::string16& message); + virtual ~ReloadPluginInfoBarDelegate(); + + // ConfirmInfobarDelegate: + virtual int GetIconID() const OVERRIDE; + virtual base::string16 GetMessageText() const OVERRIDE; + virtual int GetButtons() const OVERRIDE; + virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; + virtual bool Accept() OVERRIDE; + + content::NavigationController* controller_; + base::string16 message_; +}; + +// static +void ReloadPluginInfoBarDelegate::Create( + InfoBarService* infobar_service, + content::NavigationController* controller, + const base::string16& message) { + infobar_service->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr( + new ReloadPluginInfoBarDelegate(controller, message)))); +} + +ReloadPluginInfoBarDelegate::ReloadPluginInfoBarDelegate( + content::NavigationController* controller, + const base::string16& message) + : controller_(controller), + message_(message) {} + +ReloadPluginInfoBarDelegate::~ReloadPluginInfoBarDelegate(){ } + +int ReloadPluginInfoBarDelegate::GetIconID() const { + return IDR_INFOBAR_PLUGIN_CRASHED; +} + +base::string16 ReloadPluginInfoBarDelegate::GetMessageText() const { + return message_; +} + +int ReloadPluginInfoBarDelegate::GetButtons() const { + return BUTTON_OK; +} + +base::string16 ReloadPluginInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { + DCHECK_EQ(BUTTON_OK, button); + return l10n_util::GetStringUTF16(IDS_RELOAD_PAGE_WITH_PLUGIN); +} + +bool ReloadPluginInfoBarDelegate::Accept() { + controller_->Reload(true); + return true; +} + } // namespace // PluginObserver ------------------------------------------------------------- @@ -257,9 +324,10 @@ void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, UMA_HISTOGRAM_COUNTS("Plugin.ShowCrashedInfobar", 1); #endif - SimpleAlertInfoBarDelegate::Create( + ReloadPluginInfoBarDelegate::Create( InfoBarService::FromWebContents(web_contents()), - IDR_INFOBAR_PLUGIN_CRASHED, infobar_text, true); + &web_contents()->GetController(), + infobar_text); } bool PluginObserver::OnMessageReceived(const IPC::Message& message) { -- 2.11.4.GIT