diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 00:27:44 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 00:27:44 +0000 |
commit | 3fc07c5701fa6fdd4c7ed86b935458cece8eacf7 (patch) | |
tree | 0787f38f50add4a178358c1f910c3f3fad9fda36 | |
parent | 4e87da9fcc4a9735c06b71314421651d020995ec (diff) | |
download | chromium_src-3fc07c5701fa6fdd4c7ed86b935458cece8eacf7.zip chromium_src-3fc07c5701fa6fdd4c7ed86b935458cece8eacf7.tar.gz chromium_src-3fc07c5701fa6fdd4c7ed86b935458cece8eacf7.tar.bz2 |
Move CrashedPlugin() and PluginHungStatusChanged() from WebContentsDelegate into WebContentsObserver, and implement them in PluginObserver and HungPluginTabHelper.
This removes some code from Browser that only forwarded to other helpers.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/10117025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133099 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/external_tab/external_tab_container_win.cc | 5 | ||||
-rw-r--r-- | chrome/browser/external_tab/external_tab_container_win.h | 2 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.cc | 19 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 41 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 11 | ||||
-rw-r--r-- | chrome/browser/ui/hung_plugin_tab_helper.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/hung_plugin_tab_helper.h | 21 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl.cc | 7 | ||||
-rw-r--r-- | content/public/browser/web_contents_delegate.h | 15 | ||||
-rw-r--r-- | content/public/browser/web_contents_observer.h | 13 |
11 files changed, 47 insertions, 92 deletions
diff --git a/chrome/browser/external_tab/external_tab_container_win.cc b/chrome/browser/external_tab/external_tab_container_win.cc index 056c3d1..f9ae285 100644 --- a/chrome/browser/external_tab/external_tab_container_win.cc +++ b/chrome/browser/external_tab/external_tab_container_win.cc @@ -768,11 +768,6 @@ void ExternalTabContainer::FindReply(WebContents* tab, active_match_ordinal, final_update); } -void ExternalTabContainer::CrashedPlugin(WebContents* tab, - const FilePath& plugin_path) { - Browser::CrashedPluginHelper(tab, plugin_path); -} - bool ExternalTabContainer::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(ExternalTabContainer, message) diff --git a/chrome/browser/external_tab/external_tab_container_win.h b/chrome/browser/external_tab/external_tab_container_win.h index 0d635d5..523f283 100644 --- a/chrome/browser/external_tab/external_tab_container_win.h +++ b/chrome/browser/external_tab/external_tab_container_win.h @@ -191,8 +191,6 @@ class ExternalTabContainer : public content::WebContentsDelegate, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update) OVERRIDE; - virtual void CrashedPlugin(content::WebContents* tab, - const FilePath& plugin_path) OVERRIDE; void RegisterRenderViewHost(content::RenderViewHost* render_view_host); void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index f14605b..34a708d 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -15,10 +15,12 @@ #include "chrome/browser/plugin_infobar_delegates.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" +#include "content/public/browser/plugin_service.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" @@ -36,6 +38,7 @@ #endif // defined(ENABLE_PLUGIN_INSTALLATION) using content::OpenURLParams; +using content::PluginService; using content::Referrer; using content::WebContents; @@ -169,6 +172,22 @@ PluginObserver::~PluginObserver() { #endif } +void PluginObserver::PluginCrashed(const FilePath& plugin_path) { + DCHECK(!plugin_path.value().empty()); + + string16 plugin_name = + PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); + gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( + IDR_INFOBAR_PLUGIN_CRASHED); + InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); + infobar_helper->AddInfoBar( + new SimpleAlertInfoBarDelegate( + infobar_helper, + icon, + l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), + true)); +} + bool PluginObserver::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, diff --git a/chrome/browser/plugin_observer.h b/chrome/browser/plugin_observer.h index 4cce117..0cde5e4 100644 --- a/chrome/browser/plugin_observer.h +++ b/chrome/browser/plugin_observer.h @@ -29,6 +29,7 @@ class PluginObserver : public content::WebContentsObserver { virtual ~PluginObserver(); // content::WebContentsObserver implementation. + virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; #if defined(ENABLE_PLUGIN_INSTALLATION) diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 0874578..320b9c9 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -2884,33 +2884,6 @@ void Browser::FindReplyHelper(WebContents* tab, } // static -void Browser::CrashedPluginHelper(WebContents* tab, - const FilePath& plugin_path) { - TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( - tab); - if (!tcw) - return; - - // Tell the hung plugin infobars about this crash so they can close any - // related ones. - tcw->hung_plugin_tab_helper()->PluginCrashed(plugin_path); - - DCHECK(!plugin_path.value().empty()); - - string16 plugin_name = - PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); - gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( - IDR_INFOBAR_PLUGIN_CRASHED); - InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); - infobar_helper->AddInfoBar( - new SimpleAlertInfoBarDelegate( - infobar_helper, - icon, - l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), - true)); -} - -// static void Browser::UpdateTargetURLHelper(WebContents* tab, int32 page_id, const GURL& url) { TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( @@ -4241,20 +4214,6 @@ void Browser::FindReply(WebContents* tab, active_match_ordinal, final_update); } -void Browser::CrashedPlugin(WebContents* tab, const FilePath& plugin_path) { - CrashedPluginHelper(tab, plugin_path); -} - -void Browser::PluginHungStatusChanged(WebContents* tab, - int plugin_child_id, - const FilePath& plugin_path, - bool is_hung) { - TabContentsWrapper* tcw = - TabContentsWrapper::GetCurrentWrapperForContents(tab); - tcw->hung_plugin_tab_helper()->PluginHungStatusChanged( - plugin_child_id, plugin_path, is_hung); -} - void Browser::UpdatePreferredSize(WebContents* source, const gfx::Size& pref_size) { window_->UpdatePreferredSize(source, pref_size); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index a7bb965..376be7f 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -755,10 +755,6 @@ class Browser : public TabHandlerDelegate, int active_match_ordinal, bool final_update); - // Helper function to handle crashed plugin notifications. - static void CrashedPluginHelper(content::WebContents* tab, - const FilePath& plugin_path); - // Helper function to handle url update notifications. static void UpdateTargetURLHelper(content::WebContents* tab, int32 page_id, const GURL& url); @@ -1080,13 +1076,6 @@ class Browser : public TabHandlerDelegate, int active_match_ordinal, bool final_update) OVERRIDE; - virtual void CrashedPlugin(content::WebContents* tab, - const FilePath& plugin_path) OVERRIDE; - virtual void PluginHungStatusChanged(content::WebContents* tab, - int plugin_child_id, - const FilePath& plugin_path, - bool is_hung) OVERRIDE; - virtual void RequestToLockMouse(content::WebContents* tab) OVERRIDE; virtual void LostMouseLock() OVERRIDE; diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc index df2cf8c..0b748dd 100644 --- a/chrome/browser/ui/hung_plugin_tab_helper.cc +++ b/chrome/browser/ui/hung_plugin_tab_helper.cc @@ -141,7 +141,7 @@ HungPluginTabHelper::PluginState::~PluginState() { // ----------------------------------------------------------------------------- HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents) - : contents_(contents) { + : content::WebContentsObserver(contents) { } HungPluginTabHelper::~HungPluginTabHelper() { @@ -261,7 +261,7 @@ void HungPluginTabHelper::CloseBar(PluginState* state) { InfoBarTabHelper* HungPluginTabHelper::GetInfoBarHelper() { TabContentsWrapper* tcw = - TabContentsWrapper::GetCurrentWrapperForContents(contents_); + TabContentsWrapper::GetCurrentWrapperForContents(web_contents()); if (!tcw) return NULL; return tcw->infobar_tab_helper(); diff --git a/chrome/browser/ui/hung_plugin_tab_helper.h b/chrome/browser/ui/hung_plugin_tab_helper.h index bea4e38..ca96a16 100644 --- a/chrome/browser/ui/hung_plugin_tab_helper.h +++ b/chrome/browser/ui/hung_plugin_tab_helper.h @@ -12,14 +12,11 @@ #include "base/string16.h" #include "base/time.h" #include "base/timer.h" +#include "content/public/browser/web_contents_observer.h" class FilePath; class InfoBarTabHelper; -namespace content { -class WebContents; -} - // Manages per-tab state with regard to hung plugins. This only handles // Pepper plugins which we know are windowless. Hung NPAPI plugins (which // may have native windows) can not be handled with infobars and have a @@ -32,16 +29,16 @@ class WebContents; // terminating the plugin. // - Hide the infobar if the plugin starts responding again. // - Keep track of all of this for any number of plugins. -class HungPluginTabHelper { +class HungPluginTabHelper : public content::WebContentsObserver { public: explicit HungPluginTabHelper(content::WebContents* contents); - ~HungPluginTabHelper(); - - void PluginCrashed(const FilePath& plugin_path); + virtual ~HungPluginTabHelper(); - void PluginHungStatusChanged(int plugin_child_id, - const FilePath& plugin_path, - bool is_hung); + // content::WebContentsObserver overrides: + virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE; + virtual void PluginHungStatusChanged(int plugin_child_id, + const FilePath& plugin_path, + bool is_hung) OVERRIDE; private: class InfoBarDelegate; @@ -97,8 +94,6 @@ class HungPluginTabHelper { // Possibly returns null. InfoBarTabHelper* GetInfoBarHelper(); - content::WebContents* contents_; - // All currently hung plugins. PluginStateMap hung_plugins_; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 32560b3..928b7c1 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -1737,7 +1737,8 @@ void WebContentsImpl::OnFindReply(int request_id, } void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) { - delegate_->CrashedPlugin(this, plugin_path); + FOR_EACH_OBSERVER(WebContentsObserver, observers_, + PluginCrashed(plugin_path)); } void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, @@ -1768,8 +1769,8 @@ void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id, void WebContentsImpl::OnPepperPluginHung(int plugin_child_id, const FilePath& path, bool is_hung) { - if (delegate_) - delegate_->PluginHungStatusChanged(this, plugin_child_id, path, is_hung); + FOR_EACH_OBSERVER(WebContentsObserver, observers_, + PluginHungStatusChanged(plugin_child_id, path, is_hung)); } // This exists for render views that don't have a WebUI, but do have WebUI diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index 922b995..569d1ec 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -374,21 +374,6 @@ class CONTENT_EXPORT WebContentsDelegate { int active_match_ordinal, bool final_update) {} - // Notification that a plugin has crashed. - virtual void CrashedPlugin(WebContents* web_contents, - const FilePath& plugin_path) {} - - // Notication that the given plugin has hung or become unhung. This - // notification is only for Pepper plugins. - // - // The plugin_child_id is the unique child process ID from the plugin. Note - // that this ID is supplied by the renderer, so should be validated before - // it's used for anything in case there's an exploited renderer. - virtual void PluginHungStatusChanged(WebContents* web_contents, - int plugin_child_id, - const FilePath& plugin_path, - bool is_hung) {} - // Invoked when the preferred size of the contents has been changed. virtual void UpdatePreferredSize(WebContents* web_contents, const gfx::Size& pref_size) {} diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index e3db1f1..b0b77a8 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -93,6 +93,19 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Channel::Listener, virtual void AppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy) {} + // Notification that a plugin has crashed. + virtual void PluginCrashed(const FilePath& plugin_path) {} + + // Notication that the given plugin has hung or become unhung. This + // notification is only for Pepper plugins. + // + // The plugin_child_id is the unique child process ID from the plugin. Note + // that this ID is supplied by the renderer, so should be validated before + // it's used for anything in case there's an exploited renderer. + virtual void PluginHungStatusChanged(int plugin_child_id, + const FilePath& plugin_path, + bool is_hung) {} + // Invoked when the WebContents is being destroyed. Gives subclasses a chance // to cleanup. At the time this is invoked |web_contents()| returns NULL. // It is safe to delete 'this' from here. |