diff options
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 52 insertions, 82 deletions
diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc index 7f8c8b8..b9bace4 100644 --- a/chrome/browser/extensions/api/debugger/debugger_api.cc +++ b/chrome/browser/extensions/api/debugger/debugger_api.cc @@ -66,10 +66,6 @@ namespace OnDetach = extensions::api::debugger::OnDetach; namespace OnEvent = extensions::api::debugger::OnEvent; namespace SendCommand = extensions::api::debugger::SendCommand; -namespace { -class ExtensionDevToolsInfoBarDelegate; -} // namespace - // ExtensionDevToolsClientHost ------------------------------------------------ @@ -82,7 +78,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, const std::string& extension_id, const std::string& extension_name, const Debuggee& debuggee, - ExtensionDevToolsInfoBarDelegate* infobar); + InfoBar* infobar); virtual ~ExtensionDevToolsClientHost(); @@ -117,7 +113,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > PendingRequests; PendingRequests pending_requests_; - ExtensionDevToolsInfoBarDelegate* infobar_; + InfoBar* infobar_; OnDetach::Reason detach_reason_; DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); @@ -145,20 +141,17 @@ void CopyDebuggee(Debuggee* dst, const Debuggee& src) { class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an extension dev tools infobar delegate and adds it to the - // InfoBarService associated with |rvh|. Returns the delegate if it was + // Creates an extension dev tools infobar and delegate and adds the infobar to + // the InfoBarService associated with |rvh|. Returns the infobar if it was // successfully added. - static ExtensionDevToolsInfoBarDelegate* Create( - RenderViewHost* rvh, - const std::string& client_name); + static InfoBar* Create(RenderViewHost* rvh, const std::string& client_name); void set_client_host(ExtensionDevToolsClientHost* client_host) { client_host_ = client_host; } private: - ExtensionDevToolsInfoBarDelegate(InfoBarService* infobar_service, - const std::string& client_name); + explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); virtual ~ExtensionDevToolsInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -177,7 +170,7 @@ class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( +InfoBar* ExtensionDevToolsInfoBarDelegate::Create( RenderViewHost* rvh, const std::string& client_name) { if (!rvh) @@ -192,15 +185,14 @@ ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( if (!infobar_service) return NULL; - return static_cast<ExtensionDevToolsInfoBarDelegate*>( - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name)))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new ExtensionDevToolsInfoBarDelegate(client_name)))); } ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( - InfoBarService* infobar_service, const std::string& client_name) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), client_name_(client_name), client_host_(NULL) { } @@ -303,7 +295,7 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( const std::string& extension_id, const std::string& extension_name, const Debuggee& debuggee, - ExtensionDevToolsInfoBarDelegate* infobar) + InfoBar* infobar) : profile_(profile), agent_host_(agent_host), extension_id_(extension_id), @@ -329,7 +321,8 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( agent_host_.get(), this); if (infobar_) { - infobar_->set_client_host(this); + static_cast<ExtensionDevToolsInfoBarDelegate*>( + infobar_->delegate())->set_client_host(this); registrar_.Add( this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::Source<InfoBarService>(InfoBarService::FromWebContents( @@ -344,7 +337,8 @@ ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { registrar_.RemoveAll(); if (infobar_) { - infobar_->set_client_host(NULL); + static_cast<ExtensionDevToolsInfoBarDelegate*>( + infobar_->delegate())->set_client_host(NULL); InfoBarService::FromWebContents(WebContents::FromRenderViewHost( agent_host_->GetRenderViewHost()))->RemoveInfoBar(infobar_); } @@ -569,13 +563,13 @@ bool DebuggerAttachFunction::RunImpl() { return false; } - ExtensionDevToolsInfoBarDelegate* infobar = NULL; + InfoBar* infobar = NULL; if (!CommandLine::ForCurrentProcess()-> HasSwitch(switches::kSilentDebuggerExtensionAPI)) { // Do not attach to the target if for any reason the infobar cannot be shown // for this WebContents instance. infobar = ExtensionDevToolsInfoBarDelegate::Create( - agent_host_->GetRenderViewHost(), GetExtension()->name()); + agent_host_->GetRenderViewHost(), GetExtension()->name()); if (!infobar) { error_ = ErrorUtils::FormatErrorMessage( keys::kSilentDebuggingRequired, diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc index 1c74eef..601da47 100644 --- a/chrome/browser/extensions/extension_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_infobar_delegate.cc @@ -16,8 +16,6 @@ #include "extensions/common/extension.h" ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { - if (observer_) - observer_->OnDelegateDeleted(); } // static @@ -26,25 +24,22 @@ void ExtensionInfoBarDelegate::Create(content::WebContents* web_contents, const extensions::Extension* extension, const GURL& url, int height) { - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ExtensionInfoBarDelegate(browser, infobar_service, extension, url, - web_contents, height))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( + browser, extension, url, web_contents, height)))); } ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( Browser* browser, - InfoBarService* infobar_service, const extensions::Extension* extension, const GURL& url, content::WebContents* web_contents, int height) - : InfoBarDelegate(infobar_service), + : InfoBarDelegate(), #if defined(TOOLKIT_VIEWS) browser_(browser), #endif - observer_(NULL), extension_(extension), closing_(false) { extension_view_host_.reset( @@ -56,21 +51,15 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, content::Source<Profile>(browser->profile())); -#if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) || defined(OS_ANDROID) - // TODO(dtrainor): On Android, this is not used. Might need to pull this from - // Android UI level in the future. Tracked via issue 115303. - int default_height = InfoBar::kDefaultBarTargetHeight; -#elif defined(OS_MACOSX) - // TODO(pkasting): Once Infobars have been ported to Mac, we can remove the - // ifdefs and just use the Infobar constant below. - int default_height = 36; -#endif height_ = std::max(0, height); - height_ = std::min(2 * default_height, height_); + height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_); if (height_ == 0) - height_ = default_height; + height_ = InfoBar::kDefaultBarTargetHeight; } +// ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific +// files. + bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { ExtensionInfoBarDelegate* extension_delegate = delegate->AsExtensionInfoBarDelegate(); @@ -107,11 +96,11 @@ void ExtensionInfoBarDelegate::Observe( if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { if (extension_view_host_.get() == content::Details<extensions::ExtensionHost>(details).ptr()) - RemoveSelf(); + infobar()->RemoveSelf(); } else { DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( details)->extension) - RemoveSelf(); + infobar()->RemoveSelf(); } } diff --git a/chrome/browser/extensions/extension_infobar_delegate.h b/chrome/browser/extensions/extension_infobar_delegate.h index 3b4ba5b..b9a337f 100644 --- a/chrome/browser/extensions/extension_infobar_delegate.h +++ b/chrome/browser/extensions/extension_infobar_delegate.h @@ -23,19 +23,10 @@ class ExtensionViewHost; class ExtensionInfoBarDelegate : public InfoBarDelegate, public content::NotificationObserver { public: - // The observer for when the delegate dies. - class DelegateObserver { - public: - virtual void OnDelegateDeleted() = 0; - - protected: - virtual ~DelegateObserver() {} - }; - virtual ~ExtensionInfoBarDelegate(); - // Creates an extension infobar delegate and adds it to the infobar service - // for |web_contents|. + // Creates an extension infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. static void Create(content::WebContents* web_contents, Browser* browser, const extensions::Extension* extension, @@ -48,20 +39,20 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate, } int height() { return height_; } - void set_observer(DelegateObserver* observer) { observer_ = observer; } - bool closing() const { return closing_; } private: ExtensionInfoBarDelegate(Browser* browser, - InfoBarService* infobar_service, const extensions::Extension* extension, const GURL& url, content::WebContents* web_contents, int height); + // Returns an extension infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate); + // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; virtual void InfoBarDismissed() OVERRIDE; virtual Type GetInfoBarType() const OVERRIDE; @@ -76,15 +67,10 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate, Browser* browser_; // We pass this to the ExtensionInfoBar. #endif - // The extension host we are showing the InfoBar for. The delegate needs to - // own this since the InfoBar gets deleted and recreated when you switch tabs - // and come back (and we don't want the user's interaction with the InfoBar to - // get lost at that point). + // The extension host we are showing the InfoBar for. + // TODO(pkasting): Should this live on the InfoBar instead? scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; - // The observer monitoring when the delegate dies. - DelegateObserver* observer_; - const extensions::Extension* extension_; content::NotificationRegistrar registrar_; diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index 72d8069..d91cf30 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.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/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -42,7 +43,7 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { InfoBarService::FromWebContents(web_contents); ASSERT_EQ(1U, infobar_service->infobar_count()); ConfirmInfoBarDelegate* delegate = - infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Cancel(); ASSERT_EQ(0U, infobar_service->infobar_count()); diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc index 11766fa..2c22bc6 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -47,16 +48,17 @@ void ThemeInstalledInfoBarDelegate::Create( InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); - scoped_ptr<InfoBarDelegate> new_infobar(new ThemeInstalledInfoBarDelegate( - infobar_service, profile->GetExtensionService(), theme_service, new_theme, - previous_theme_id, previous_using_native_theme)); + scoped_ptr<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ThemeInstalledInfoBarDelegate( + profile->GetExtensionService(), theme_service, new_theme, + previous_theme_id, previous_using_native_theme)))); // If there's a previous theme infobar, just replace that instead of adding a // new one. for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBarDelegate* old_infobar = infobar_service->infobar_at(i); + InfoBar* old_infobar = infobar_service->infobar_at(i); ThemeInstalledInfoBarDelegate* theme_infobar = - old_infobar->AsThemePreviewInfobarDelegate(); + old_infobar->delegate()->AsThemePreviewInfobarDelegate(); if (theme_infobar) { // If the user installed the same theme twice, ignore the second install // and keep the first install info bar, so that they can easily undo to @@ -75,13 +77,12 @@ void ThemeInstalledInfoBarDelegate::Create( } ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( - InfoBarService* infobar_service, ExtensionService* extension_service, ThemeService* theme_service, const extensions::Extension* new_theme, const std::string& previous_theme_id, bool previous_using_native_theme) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), extension_service_(extension_service), theme_service_(theme_service), name_(new_theme->name()), @@ -154,5 +155,5 @@ void ThemeInstalledInfoBarDelegate::Observe( // If the new theme is different from what this info bar is associated with, // close this info bar since it is no longer relevant. if (theme_id_ != theme_service_->GetThemeID()) - RemoveSelf(); + infobar()->RemoveSelf(); } diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h index f37efcc..94727a7 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.h +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h @@ -26,16 +26,15 @@ class Extension; class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate, public content::NotificationObserver { public: - // Creates a theme installed infobar delegate and adds it to the last active - // tab on |profile|. + // Creates a theme installed infobar and delegate and adds the infobar to the + // last active tab on |profile|. static void Create(const extensions::Extension* new_theme, Profile* profile, const std::string& previous_theme_id, bool previous_using_native_theme); private: - ThemeInstalledInfoBarDelegate(InfoBarService* infobar_service, - ExtensionService* extension_service, + ThemeInstalledInfoBarDelegate(ExtensionService* extension_service, ThemeService* theme_service, const extensions::Extension* new_theme, const std::string& previous_theme_id, |