diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 04:20:40 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 04:20:40 +0000 |
commit | ec8f51164d477d8d83726fe61c68977d17b03149 (patch) | |
tree | de1ea01984caab5a5841c8a7c1593805157ce60d /chrome/browser/plugin_observer.cc | |
parent | ef47ded033e48098e83bb94e63b6e44ca6b511b4 (diff) | |
download | chromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.zip chromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.tar.gz chromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.tar.bz2 |
Cleanup:
* Change int to size_t in a few APIs.
* Rename infobar_delegate_count() to infobar_count() in preparation for TabContents owning InfoBars rather than InfoBarDelegates.
* Move some code from PluginInstallerInfoBarDelegate to PluginObserver since it's more related to who's instantiating the infobar(delegate)s.
* Unify InfoBarDelegate behavior by making no delegates auto-add themselves to tabs (callers now all do this explicitly).
* Eliminate unused member TabContentsSSLHelper::SSLAddCertData::handler_.
* De-inline a couple classes.
* Make more functions private.
* Add some consts.
* Change DCHECK() to DCHECK_EQ() where possible.
* Rename the delegates in plugin_observer.cc to have "Delegate" in the names.
* Remove unnecessary qualifiers.
* Simplify.
* Misc. style issues, naming issues, etc.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6250172
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/plugin_observer.cc')
-rw-r--r-- | chrome/browser/plugin_observer.cc | 207 |
1 files changed, 112 insertions, 95 deletions
diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index d23542ff..058dff2 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -17,79 +17,82 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "webkit/plugins/npapi/default_plugin_shared.h" #include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/npapi/webplugininfo.h" namespace { -// PluginInfoBar -------------------------------------------------------------- +// PluginInfoBarDelegate ------------------------------------------------------ -class PluginInfoBar : public ConfirmInfoBarDelegate { +class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { public: - PluginInfoBar(TabContents* tab_contents, const string16& name); - - // ConfirmInfoBarDelegate: - virtual SkBitmap* GetIcon() const; - virtual int GetButtons() const; - virtual string16 GetLinkText(); + PluginInfoBarDelegate(TabContents* tab_contents, const string16& name); protected: - virtual ~PluginInfoBar(); + virtual ~PluginInfoBarDelegate(); - void CommonCancel(); - void CommonClose(); - void CommonLearnMore(WindowOpenDisposition disposition); + virtual void InfoBarClosed(); + virtual bool Cancel(); + virtual bool LinkClicked(WindowOpenDisposition disposition); string16 name_; TabContents* tab_contents_; private: - DISALLOW_COPY_AND_ASSIGN(PluginInfoBar); + // ConfirmInfoBarDelegate: + virtual SkBitmap* GetIcon() const; + virtual string16 GetLinkText(); + + DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate); }; -PluginInfoBar::PluginInfoBar(TabContents* tab_contents, const string16& name) +PluginInfoBarDelegate::PluginInfoBarDelegate(TabContents* tab_contents, + const string16& name) : ConfirmInfoBarDelegate(tab_contents), name_(name), tab_contents_(tab_contents) { } -PluginInfoBar::~PluginInfoBar() { +PluginInfoBarDelegate::~PluginInfoBarDelegate() { } -void PluginInfoBar::CommonClose() { +void PluginInfoBarDelegate::InfoBarClosed() { delete this; } -SkBitmap* PluginInfoBar::GetIcon() const { - return ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFOBAR_PLUGIN_INSTALL); +bool PluginInfoBarDelegate::Cancel() { + tab_contents_->render_view_host()->LoadBlockedPlugins(); + return true; } -int PluginInfoBar::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; +bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { + // TODO(bauerb): Navigate to a help page explaining why we disabled + // or blocked the plugin, once we have one. + return false; } -void PluginInfoBar::CommonCancel() { - tab_contents_->render_view_host()->LoadBlockedPlugins(); +SkBitmap* PluginInfoBarDelegate::GetIcon() const { + return ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_INFOBAR_PLUGIN_INSTALL); } -string16 PluginInfoBar::GetLinkText() { +string16 PluginInfoBarDelegate::GetLinkText() { return l10n_util::GetStringUTF16(IDS_LEARN_MORE); } -void PluginInfoBar::CommonLearnMore(WindowOpenDisposition disposition) { - // TODO(bauerb): Navigate to a help page explaining why we disabled - // or blocked the plugin, once we have one. -} -// BlockedPluginInfoBar ------------------------------------------------------- +// BlockedPluginInfoBarDelegate ----------------------------------------------- -class BlockedPluginInfoBar : public PluginInfoBar { +class BlockedPluginInfoBarDelegate : public PluginInfoBarDelegate { public: - BlockedPluginInfoBar(TabContents* tab_contents, - const string16& name); + BlockedPluginInfoBarDelegate(TabContents* tab_contents, + const string16& name); - // ConfirmInfoBarDelegate: + private: + virtual ~BlockedPluginInfoBarDelegate(); + + // PluginInfoBarDelegate: virtual string16 GetMessageText() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); @@ -97,33 +100,30 @@ class BlockedPluginInfoBar : public PluginInfoBar { virtual void InfoBarClosed(); virtual bool LinkClicked(WindowOpenDisposition disposition); - protected: - virtual ~BlockedPluginInfoBar(); - - private: - DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar); + DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate); }; -BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents, - const string16& name) - : PluginInfoBar(tab_contents, name) { - tab_contents->AddInfoBar(this); +BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate( + TabContents* tab_contents, + const string16& name) + : PluginInfoBarDelegate(tab_contents, name) { UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); } -BlockedPluginInfoBar::~BlockedPluginInfoBar() { +BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() { } -string16 BlockedPluginInfoBar::GetMessageText() const { +string16 BlockedPluginInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); } -string16 BlockedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { +string16 BlockedPluginInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PLUGIN_ENABLE_ALWAYS : IDS_PLUGIN_ENABLE_TEMPORARILY); } -bool BlockedPluginInfoBar::Accept() { +bool BlockedPluginInfoBarDelegate::Accept() { UserMetrics::RecordAction( UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL( @@ -133,34 +133,36 @@ bool BlockedPluginInfoBar::Accept() { return true; } -bool BlockedPluginInfoBar::Cancel() { +bool BlockedPluginInfoBarDelegate::Cancel() { UserMetrics::RecordAction( UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); - CommonCancel(); - return true; + return PluginInfoBarDelegate::Cancel(); } -void BlockedPluginInfoBar::InfoBarClosed() { +void BlockedPluginInfoBarDelegate::InfoBarClosed() { UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); - CommonClose(); + PluginInfoBarDelegate::InfoBarClosed(); } -bool BlockedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { +bool BlockedPluginInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { UserMetrics::RecordAction( UserMetricsAction("BlockedPluginInfobar.LearnMore")); - CommonLearnMore(disposition); - return false; + return PluginInfoBarDelegate::LinkClicked(disposition); } -// OutdatedPluginInfoBar ------------------------------------------------------ +// OutdatedPluginInfoBarDelegate ---------------------------------------------- -class OutdatedPluginInfoBar : public PluginInfoBar { +class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate { public: - OutdatedPluginInfoBar(TabContents* tab_contents, - const string16& name, - const GURL& update_url); + OutdatedPluginInfoBarDelegate(TabContents* tab_contents, + const string16& name, + const GURL& update_url); - // ConfirmInfoBarDelegate: + private: + virtual ~OutdatedPluginInfoBarDelegate(); + + // PluginInfoBarDelegate: virtual string16 GetMessageText() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); @@ -168,67 +170,68 @@ class OutdatedPluginInfoBar : public PluginInfoBar { virtual void InfoBarClosed(); virtual bool LinkClicked(WindowOpenDisposition disposition); - protected: - virtual ~OutdatedPluginInfoBar(); - - private: GURL update_url_; - DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar); + DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); }; -OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, - const string16& name, - const GURL& update_url) - : PluginInfoBar(tab_contents, name), update_url_(update_url) { - tab_contents->AddInfoBar(this); +OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( + TabContents* tab_contents, + const string16& name, + const GURL& update_url) + : PluginInfoBarDelegate(tab_contents, name), update_url_(update_url) { UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); } -OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { +OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() { } -string16 OutdatedPluginInfoBar::GetMessageText() const { +string16 OutdatedPluginInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); } -string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { +string16 OutdatedPluginInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); } -bool OutdatedPluginInfoBar::Accept() { +bool OutdatedPluginInfoBarDelegate::Accept() { UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); return false; } -bool OutdatedPluginInfoBar::Cancel() { +bool OutdatedPluginInfoBarDelegate::Cancel() { UserMetrics::RecordAction( UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); - CommonCancel(); - return true; + return PluginInfoBarDelegate::Cancel(); } -void OutdatedPluginInfoBar::InfoBarClosed() { +void OutdatedPluginInfoBarDelegate::InfoBarClosed() { UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); - CommonClose(); + PluginInfoBarDelegate::InfoBarClosed(); } -bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { +bool OutdatedPluginInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { UserMetrics::RecordAction( UserMetricsAction("OutdatedPluginInfobar.LearnMore")); - CommonLearnMore(disposition); - return false; + return PluginInfoBarDelegate::LinkClicked(disposition); } } // namespace + +// PluginObserver ------------------------------------------------------------- + PluginObserver::PluginObserver(TabContents* tab_contents) - : tab_contents_(tab_contents) { } + : tab_contents_(tab_contents) { +} -PluginObserver::~PluginObserver() { } +PluginObserver::~PluginObserver() { +} bool PluginObserver::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) @@ -243,15 +246,29 @@ bool PluginObserver::OnMessageReceived(const IPC::Message& message) { } PluginInstallerInfoBarDelegate* PluginObserver::GetPluginInstaller() { - if (plugin_installer_.get() == NULL) + if (plugin_installer_ == NULL) plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents_)); - return plugin_installer_.get(); + return plugin_installer_->AsPluginInstallerInfoBarDelegate(); } void PluginObserver::OnMissingPluginStatus(int status) { + // TODO(PORT): pull in when plug-ins work #if defined(OS_WIN) -// TODO(PORT): pull in when plug-ins work - GetPluginInstaller()->OnMissingPluginStatus(status); + if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) { + tab_contents_->AddInfoBar( + new PluginInstallerInfoBarDelegate(tab_contents_)); + return; + } + + DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD, + status); + for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { + InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); + if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) { + tab_contents_->RemoveInfoBar(delegate); + return; + } + } #endif } @@ -274,17 +291,17 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { } SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_INFOBAR_PLUGIN_CRASHED); - tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate( - tab_contents_, crash_icon, + tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents_, + crash_icon, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), true)); } void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, - const GURL& update_url) { - if (!update_url.is_empty()) - new OutdatedPluginInfoBar(tab_contents_, name, update_url); - else - new BlockedPluginInfoBar(tab_contents_, name); + const GURL& update_url) { + tab_contents_->AddInfoBar(update_url.is_empty() ? + static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( + tab_contents_, name)) : + new OutdatedPluginInfoBarDelegate(tab_contents_, name, update_url)); } |