diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-31 16:33:58 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-31 16:33:58 +0000 |
commit | 67c052e53987c8ca3d09a259fab64c82787bb418 (patch) | |
tree | e27c57945f55caee9ba3a4f71b0633ea9c7af4bf /chrome/browser/tab_contents | |
parent | 7822132061ad3d7bb671334b2afd2b80133a6415 (diff) | |
download | chromium_src-67c052e53987c8ca3d09a259fab64c82787bb418.zip chromium_src-67c052e53987c8ca3d09a259fab64c82787bb418.tar.gz chromium_src-67c052e53987c8ca3d09a259fab64c82787bb418.tar.bz2 |
Move plugin message handling from TabContents into PluginMessageFilter.
Also, close infobars after allowing plugins to run (regressed in http://crrev.com/72166).
BUG=71116
TEST=none
Review URL: http://codereview.chromium.org/6336021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 263 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 12 |
2 files changed, 6 insertions, 269 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 536948a..8a941cd 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -50,7 +50,7 @@ #include "chrome/browser/omnibox_search_hint.h" #include "chrome/browser/pdf_unsupported_feature.h" #include "chrome/browser/platform_util.h" -#include "chrome/browser/plugin_installer_infobar_delegate.h" +#include "chrome/browser/plugin_observer.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_plt_recorder.h" @@ -108,7 +108,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/glue/password_form.h" -#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/glue/webpreferences.h" #if defined(OS_MACOSX) @@ -250,214 +249,6 @@ void MakeNavigateParams(const NavigationEntry& entry, params->request_time = base::Time::Now(); } -// PluginInfoBar -------------------------------------------------------------- - -class PluginInfoBar : public ConfirmInfoBarDelegate { - public: - PluginInfoBar(TabContents* tab_contents, const string16& name); - - // ConfirmInfoBarDelegate: - virtual void InfoBarClosed() = 0; - virtual SkBitmap* GetIcon() const; - virtual string16 GetMessageText() const = 0; - virtual int GetButtons() const; - virtual string16 GetButtonLabel(InfoBarButton button) const = 0; - virtual bool Accept() = 0; - virtual bool Cancel() = 0; - virtual string16 GetLinkText(); - virtual bool LinkClicked(WindowOpenDisposition disposition) = 0; - - protected: - virtual ~PluginInfoBar(); - - void CommonCancel(); - void CommonClose(); - void CommonLearnMore(WindowOpenDisposition disposition); - - string16 name_; - TabContents* tab_contents_; - - private: - DISALLOW_COPY_AND_ASSIGN(PluginInfoBar); -}; - -PluginInfoBar::PluginInfoBar(TabContents* tab_contents, const string16& name) - : ConfirmInfoBarDelegate(tab_contents), - name_(name), - tab_contents_(tab_contents) { -} - -PluginInfoBar::~PluginInfoBar() { -} - -void PluginInfoBar::CommonClose() { - delete this; -} - -SkBitmap* PluginInfoBar::GetIcon() const { - return ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFOBAR_PLUGIN_INSTALL); -} - -int PluginInfoBar::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - -void PluginInfoBar::CommonCancel() { - tab_contents_->render_view_host()->LoadBlockedPlugins(); -} - -string16 PluginInfoBar::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 ------------------------------------------------------- - -class BlockedPluginInfoBar : public PluginInfoBar { - public: - BlockedPluginInfoBar(TabContents* tab_contents, - const string16& name); - - // ConfirmInfoBarDelegate: - virtual string16 GetMessageText() const; - virtual string16 GetButtonLabel(InfoBarButton button) const; - virtual bool Accept(); - virtual bool Cancel(); - virtual void InfoBarClosed(); - virtual bool LinkClicked(WindowOpenDisposition disposition); - - protected: - virtual ~BlockedPluginInfoBar(); - - private: - DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar); -}; - -BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents, - const string16& name) - : PluginInfoBar(tab_contents, name) { - tab_contents->AddInfoBar(this); - UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); -} - -BlockedPluginInfoBar::~BlockedPluginInfoBar() { -} - -string16 BlockedPluginInfoBar::GetMessageText() const { - return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); -} - -string16 BlockedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { - return l10n_util::GetStringUTF16((button == BUTTON_OK) ? - IDS_PLUGIN_ENABLE_ALWAYS : IDS_PLUGIN_ENABLE_TEMPORARILY); -} - -bool BlockedPluginInfoBar::Accept() { - UserMetrics::RecordAction( - UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); - tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL( - tab_contents_->GetURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), - CONTENT_SETTING_ALLOW); - tab_contents_->render_view_host()->LoadBlockedPlugins(); - return false; -} - -bool BlockedPluginInfoBar::Cancel() { - UserMetrics::RecordAction( - UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); - CommonCancel(); - return false; -} - -void BlockedPluginInfoBar::InfoBarClosed() { - UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); - CommonClose(); -} - -bool BlockedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { - UserMetrics::RecordAction( - UserMetricsAction("BlockedPluginInfobar.LearnMore")); - CommonLearnMore(disposition); - return false; -} - -// OutdatedPluginInfoBar ------------------------------------------------------ - -class OutdatedPluginInfoBar : public PluginInfoBar { - public: - OutdatedPluginInfoBar(TabContents* tab_contents, - const string16& name, - const GURL& update_url); - - // ConfirmInfoBarDelegate: - virtual string16 GetMessageText() const; - virtual string16 GetButtonLabel(InfoBarButton button) const; - virtual bool Accept(); - virtual bool Cancel(); - virtual void InfoBarClosed(); - virtual bool LinkClicked(WindowOpenDisposition disposition); - - protected: - virtual ~OutdatedPluginInfoBar(); - - private: - GURL update_url_; - - DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar); -}; - -OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, - const string16& name, - const GURL& update_url) - : PluginInfoBar(tab_contents, name), update_url_(update_url) { - tab_contents->AddInfoBar(this); - UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); -} - -OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { -} - -string16 OutdatedPluginInfoBar::GetMessageText() const { - return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); -} - -string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { - return l10n_util::GetStringUTF16((button == BUTTON_OK) ? - IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); -} - -bool OutdatedPluginInfoBar::Accept() { - UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); - tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, - PageTransition::LINK); - return false; -} - -bool OutdatedPluginInfoBar::Cancel() { - UserMetrics::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); - CommonCancel(); - return false; -} - -void OutdatedPluginInfoBar::InfoBarClosed() { - UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); - CommonClose(); -} - -bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { - UserMetrics::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.LearnMore")); - CommonLearnMore(disposition); - return false; -} - } // namespace @@ -485,7 +276,6 @@ TabContents::TabContents(Profile* profile, save_package_(), autocomplete_history_manager_(), autofill_manager_(), - plugin_installer_(), prerender_plt_recorder_(), bookmark_drag_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), @@ -599,6 +389,8 @@ TabContents::TabContents(Profile* profile, desktop_notification_handler_.reset( new DesktopNotificationHandler(this, GetRenderProcessHost())); AddObserver(desktop_notification_handler_.get()); + plugin_observer_.reset(new PluginObserver(this)); + AddObserver(plugin_observer_.get()); } TabContents::~TabContents() { @@ -748,10 +540,6 @@ bool TabContents::OnMessageReceived(const IPC::Message& message) { OnPDFHasUnsupportedFeature) IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) - IPC_MESSAGE_HANDLER(ViewHostMsg_MissingPluginStatus, OnMissingPluginStatus) - IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) - IPC_MESSAGE_HANDLER(ViewHostMsg_BlockedOutdatedPlugin, - OnBlockedOutdatedPlugin) IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo, OnDidGetApplicationInfo) IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication, @@ -778,12 +566,6 @@ bool TabContents::HostsExtension() const { return GetURL().SchemeIs(chrome::kExtensionScheme); } -PluginInstallerInfoBarDelegate* TabContents::GetPluginInstaller() { - if (plugin_installer_.get() == NULL) - plugin_installer_.reset(new PluginInstallerInfoBarDelegate(this)); - return plugin_installer_.get(); -} - TabContentsSSLHelper* TabContents::GetSSLHelper() { if (ssl_helper_.get() == NULL) ssl_helper_.reset(new TabContentsSSLHelper(this)); @@ -2443,37 +2225,6 @@ void TabContents::OnGoToEntryAtOffset(int offset) { } } -void TabContents::OnMissingPluginStatus(int status) { -#if defined(OS_WIN) -// TODO(PORT): pull in when plug-ins work - GetPluginInstaller()->OnMissingPluginStatus(status); -#endif -} - -void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { - DCHECK(!plugin_path.value().empty()); - - std::wstring plugin_name = plugin_path.ToWStringHack(); - webkit::npapi::WebPluginInfo plugin_info; - if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( - plugin_path, &plugin_info) && - !plugin_info.name.empty()) { - plugin_name = UTF16ToWide(plugin_info.name); -#if defined(OS_MACOSX) - // Many plugins on the Mac have .plugin in the actual name, which looks - // terrible, so look for that and strip it off if present. - const std::wstring plugin_extension(L".plugin"); - if (EndsWith(plugin_name, plugin_extension, true)) - plugin_name.erase(plugin_name.length() - plugin_extension.length()); -#endif // OS_MACOSX - } - SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFOBAR_PLUGIN_CRASHED); - AddInfoBar(new SimpleAlertInfoBarDelegate(this, crash_icon, - l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, - WideToUTF16Hack(plugin_name)), true)); -} - void TabContents::OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info) { web_app_info_ = info; @@ -2487,14 +2238,6 @@ void TabContents::OnInstallApplication(const WebApplicationInfo& info) { delegate()->OnInstallApplication(this, info); } -void TabContents::OnBlockedOutdatedPlugin(const string16& name, - const GURL& update_url) { - if (!update_url.is_empty()) - new OutdatedPluginInfoBar(this, name, update_url); - else - new BlockedPluginInfoBar(this, name); -} - void TabContents::OnPageContents(const GURL& url, int32 page_id, const string16& contents, diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 3f11028..fa7a6a5 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -66,7 +66,7 @@ class FileSelectHelper; class InfoBarDelegate; class LoadNotificationDetails; class OmniboxSearchHint; -class PluginInstallerInfoBarDelegate; +class PluginObserver; class Profile; class PrerenderManager; class PrerenderPLTRecorder; @@ -147,9 +147,6 @@ class TabContents : public PageNavigator, // Returns true if contains content rendered by an extension. bool HostsExtension() const; - // Returns the PluginInstallerInfoBarDelegate, creating it if necessary. - PluginInstallerInfoBarDelegate* GetPluginInstaller(); - // Returns the TabContentsSSLHelper, creating it if necessary. TabContentsSSLHelper* GetSSLHelper(); @@ -823,11 +820,8 @@ class TabContents : public PageNavigator, int active_match_ordinal, bool final_update); void OnGoToEntryAtOffset(int offset); - void OnMissingPluginStatus(int status); - void OnCrashedPlugin(const FilePath& plugin_path); void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); void OnInstallApplication(const WebApplicationInfo& info); - void OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url); void OnPageContents(const GURL& url, int32 page_id, const string16& contents, @@ -1123,8 +1117,8 @@ class TabContents : public PageNavigator, // AutoFillManager. scoped_ptr<AutoFillManager> autofill_manager_; - // PluginInstallerInfoBarDelegate, lazily created. - scoped_ptr<PluginInstallerInfoBarDelegate> plugin_installer_; + // Handles plugin messages. + scoped_ptr<PluginObserver> plugin_observer_; // Prerender PageLoadTime Recorder. scoped_ptr<PrerenderPLTRecorder> prerender_plt_recorder_; |