diff options
Diffstat (limited to 'chrome/browser/ui')
85 files changed, 554 insertions, 649 deletions
diff --git a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc index 6b76433..d5fbaf6 100644 --- a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc +++ b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" @@ -18,16 +19,17 @@ // static void PopupBlockedInfoBarDelegate::Create(InfoBarService* infobar_service, int num_popups) { - scoped_ptr<InfoBarDelegate> infobar( - new PopupBlockedInfoBarDelegate(infobar_service, num_popups)); + scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new PopupBlockedInfoBarDelegate(num_popups)))); // See if there is an existing popup infobar already. // TODO(dfalcantara) When triggering more than one popup the infobar // will be shown once, then hide then be shown again. // This will be fixed once we have an in place replace infobar mechanism. for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBarDelegate* existing_infobar = infobar_service->infobar_at(i); - if (existing_infobar->AsPopupBlockedInfoBarDelegate()) { + InfoBar* existing_infobar = infobar_service->infobar_at(i); + if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); return; } @@ -48,10 +50,8 @@ PopupBlockedInfoBarDelegate* return this; } -PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate( - InfoBarService* infobar_service, - int num_popups) - : ConfirmInfoBarDelegate(infobar_service), +PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate(int num_popups) + : ConfirmInfoBarDelegate(), num_popups_(num_popups) { } @@ -71,17 +71,16 @@ string16 PopupBlockedInfoBarDelegate::GetButtonLabel( bool PopupBlockedInfoBarDelegate::Accept() { // Create exceptions. - content::WebContents* web_contents = owner()->web_contents(); - const GURL& url = web_contents->GetURL(); + const GURL& url = web_contents()->GetURL(); Profile* profile = Profile::FromBrowserContext( - web_contents->GetBrowserContext()); + web_contents()->GetBrowserContext()); profile->GetHostContentSettingsMap()->AddExceptionForURL( url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_ALLOW); // Launch popups. PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); + PopupBlockerTabHelper::FromWebContents(web_contents()); DCHECK(popup_blocker_helper); PopupBlockerTabHelper::PopupIdMap blocked_popups = popup_blocker_helper->GetBlockedPopupRequests(); diff --git a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h index 8f21fae..1bbbb79 100644 --- a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h +++ b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h @@ -11,13 +11,14 @@ class InfoBarService; class PopupBlockedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a popup blocked infobar delegate and adds it to |infobar_service|. + // Creates a popup blocked infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, int num_popups); virtual ~PopupBlockedInfoBarDelegate(); private: - PopupBlockedInfoBarDelegate(InfoBarService* infobar_service, int num_popups); + explicit PopupBlockedInfoBarDelegate(int num_popups); // ConfirmInfoBarDelegate: virtual int GetIconID() const OVERRIDE; diff --git a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc index 6fa9b55..5651d01 100644 --- a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc +++ b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc @@ -8,6 +8,7 @@ #include "base/android/jni_helper.h" #include "base/android/jni_string.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" #include "chrome/browser/ui/auto_login_infobar_delegate.h" #include "content/public/browser/web_contents.h" @@ -21,10 +22,9 @@ using base::android::ScopedJavaLocalRef; AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( - InfoBarService* owner, const Params& params, Profile* profile) - : AutoLoginInfoBarDelegate(owner, params, profile), + : AutoLoginInfoBarDelegate(params, profile), params_(params) { } @@ -83,37 +83,36 @@ bool AutoLoginInfoBarDelegateAndroid::Cancel() { void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env, jobject obj, jstring result) { - if (!owner()) + if (!infobar()->owner()) return; // We're closing; don't call anything, it might access the owner. // TODO(miguelg): Test whether the Stop() and RemoveInfoBar() calls here are // necessary, or whether OpenURL() will do this for us. - content::WebContents* web_contents = owner()->web_contents(); - web_contents->Stop(); - owner()->RemoveInfoBar(this); + content::WebContents* contents = web_contents(); + contents->Stop(); + infobar()->RemoveSelf(); // WARNING: |this| may be deleted at this point! Do not access any members! - web_contents->OpenURL(content::OpenURLParams( + contents->OpenURL(content::OpenURLParams( GURL(base::android::ConvertJavaStringToUTF8(env, result)), content::Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); } void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { - if (!owner()) + if (!infobar()->owner()) return; // We're closing; don't call anything, it might access the owner. // TODO(miguelg): Using SimpleAlertInfoBarDelegate::Create() animates in a new // infobar while we animate the current one closed. It would be better to use // ReplaceInfoBar(). SimpleAlertInfoBarDelegate::Create( - owner(), IDR_INFOBAR_WARNING, + infobar()->owner(), IDR_INFOBAR_WARNING, l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { diff --git a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h index bec32cd..8d97b01 100644 --- a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h +++ b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h @@ -11,9 +11,7 @@ class AutoLoginInfoBarDelegateAndroid : public AutoLoginInfoBarDelegate { public: - AutoLoginInfoBarDelegateAndroid(InfoBarService* owner, - const Params& params, - Profile* profile); + AutoLoginInfoBarDelegateAndroid(const Params& params, Profile* profile); virtual ~AutoLoginInfoBarDelegateAndroid(); // AutoLoginInfoBarDelegate: diff --git a/chrome/browser/ui/android/infobars/confirm_infobar.cc b/chrome/browser/ui/android/infobars/confirm_infobar.cc index 59e6bff..48a3f14 100644 --- a/chrome/browser/ui/android/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/android/infobars/confirm_infobar.cc @@ -15,15 +15,16 @@ // ConfirmInfoBarDelegate ----------------------------------------------------- // static -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBar(owner, this); +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBar(delegate.Pass())); } // ConfirmInfoBar ------------------------------------------------------------- -ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBarAndroid(owner, delegate), +ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarAndroid(delegate.PassAs<InfoBarDelegate>()), java_confirm_delegate_() { } diff --git a/chrome/browser/ui/android/infobars/confirm_infobar.h b/chrome/browser/ui/android/infobars/confirm_infobar.h index f8e47b7..1156a02 100644 --- a/chrome/browser/ui/android/infobars/confirm_infobar.h +++ b/chrome/browser/ui/android/infobars/confirm_infobar.h @@ -12,7 +12,7 @@ class ConfirmInfoBar : public InfoBarAndroid { public: - ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate); + explicit ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate); virtual ~ConfirmInfoBar(); private: diff --git a/chrome/browser/ui/android/infobars/infobar_android.cc b/chrome/browser/ui/android/infobars/infobar_android.cc index f21841d..7b2f4b2 100644 --- a/chrome/browser/ui/android/infobars/infobar_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_android.cc @@ -28,8 +28,8 @@ const int InfoBar::kDefaultBarTargetHeight = 36; // InfoBarAndroid ------------------------------------------------------------- -InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate) { +InfoBarAndroid::InfoBarAndroid(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()) { } InfoBarAndroid::~InfoBarAndroid() { diff --git a/chrome/browser/ui/android/infobars/infobar_android.h b/chrome/browser/ui/android/infobars/infobar_android.h index 2359c51..95a7d09 100644 --- a/chrome/browser/ui/android/infobars/infobar_android.h +++ b/chrome/browser/ui/android/infobars/infobar_android.h @@ -31,7 +31,7 @@ class InfoBarAndroid : public InfoBar { ACTION_TRANSLATE_SHOW_ORIGINAL = 4, }; - InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarAndroid(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarAndroid(); // InfoBar: diff --git a/chrome/browser/ui/android/infobars/infobar_container_android.cc b/chrome/browser/ui/android/infobars/infobar_container_android.cc index b81c1a2..4012bb4 100644 --- a/chrome/browser/ui/android/infobars/infobar_container_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_container_android.cc @@ -79,7 +79,6 @@ void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar( void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar); android_infobar->CloseJavaInfoBar(); - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } diff --git a/chrome/browser/ui/android/infobars/translate_infobar.cc b/chrome/browser/ui/android/infobars/translate_infobar.cc index dcc6c70..258bf8a 100644 --- a/chrome/browser/ui/android/infobars/translate_infobar.cc +++ b/chrome/browser/ui/android/infobars/translate_infobar.cc @@ -16,16 +16,17 @@ // TranslateInfoBarDelegate --------------------------------------------------- // static -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new TranslateInfoBar(owner, this); +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new TranslateInfoBar(delegate.Pass())); } // TranslateInfoBar ----------------------------------------------------------- -TranslateInfoBar::TranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarAndroid(owner, delegate), +TranslateInfoBar::TranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarAndroid(delegate.PassAs<InfoBarDelegate>()), java_translate_delegate_() { } diff --git a/chrome/browser/ui/android/infobars/translate_infobar.h b/chrome/browser/ui/android/infobars/translate_infobar.h index 96899f0..548b10a 100644 --- a/chrome/browser/ui/android/infobars/translate_infobar.h +++ b/chrome/browser/ui/android/infobars/translate_infobar.h @@ -12,7 +12,7 @@ class TranslateInfoBar : public InfoBarAndroid { public: - TranslateInfoBar(InfoBarService* owner, TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBar(); // JNI methods specific to translate. diff --git a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc index 46dbfba..9ade4ad 100644 --- a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc +++ b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc @@ -9,6 +9,8 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/metro_utils/metro_chrome_win.h" #include "chrome/browser/profiles/profile.h" @@ -43,10 +45,9 @@ void AppMetroInfoBarDelegateWin::Create( content::Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); content::WebContents* web_contents = displayer.browser()->OpenURL(params); - InfoBarService* info_bar_service = - InfoBarService::FromWebContents(web_contents); - info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new AppMetroInfoBarDelegateWin(mode, extension_id)))); // Use PostTask because we can get here in a COM SendMessage, and // ActivateApplication can not be sent nested (returns error @@ -56,10 +57,9 @@ void AppMetroInfoBarDelegateWin::Create( } AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( - InfoBarService* info_bar_service, Mode mode, const std::string& extension_id) - : ConfirmInfoBarDelegate(info_bar_service), + : ConfirmInfoBarDelegate(), mode_(mode), extension_id_(extension_id) { DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty()); diff --git a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h index 920654e..03a384f 100644 --- a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h +++ b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h @@ -22,16 +22,14 @@ class AppMetroInfoBarDelegateWin : public ConfirmInfoBarDelegate { LAUNCH_PACKAGED_APP }; - // Creates an app metro infobar delegate, adds it to a new browser tab, then - // activates Metro mode. + // Creates an app metro infobar and delegate, adds the infobar to a new + // browser tab, then activates Metro mode. static void Create(Profile* profile, Mode mode, const std::string& extension_id); private: - AppMetroInfoBarDelegateWin(InfoBarService* infobar_service, - Mode mode, - const std::string& extension_id); + AppMetroInfoBarDelegateWin(Mode mode, const std::string& extension_id); virtual ~AppMetroInfoBarDelegateWin(); // ConfirmInfoBarDelegate overrides: diff --git a/chrome/browser/ui/auto_login_infobar_delegate.cc b/chrome/browser/ui/auto_login_infobar_delegate.cc index 72c38af..4c4076a 100644 --- a/chrome/browser/ui/auto_login_infobar_delegate.cc +++ b/chrome/browser/ui/auto_login_infobar_delegate.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/ubertoken_fetcher.h" @@ -136,20 +137,18 @@ bool AutoLoginInfoBarDelegate::Create(content::WebContents* web_contents, Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); - return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( #if defined(OS_ANDROID) - new AutoLoginInfoBarDelegateAndroid(infobar_service, params, profile) + typedef AutoLoginInfoBarDelegateAndroid Delegate; #else - new AutoLoginInfoBarDelegate(infobar_service, params, profile) + typedef AutoLoginInfoBarDelegate Delegate; #endif - )) != NULL; + return !!infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new Delegate(params, profile)))); } -AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( - InfoBarService* owner, - const Params& params, - Profile* profile) - : ConfirmInfoBarDelegate(owner), +AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate(const Params& params, + Profile* profile) + : ConfirmInfoBarDelegate(), params_(params), button_pressed_(false) { RecordHistogramAction(SHOWN); @@ -213,10 +212,7 @@ void AutoLoginInfoBarDelegate::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type); - // owner() can be NULL when InfoBarService removes us. See - // |InfoBarDelegate::clear_owner|. - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void AutoLoginInfoBarDelegate::RecordHistogramAction(Actions action) { diff --git a/chrome/browser/ui/auto_login_infobar_delegate.h b/chrome/browser/ui/auto_login_infobar_delegate.h index 85ebfde..db47dae 100644 --- a/chrome/browser/ui/auto_login_infobar_delegate.h +++ b/chrome/browser/ui/auto_login_infobar_delegate.h @@ -32,14 +32,13 @@ class AutoLoginInfoBarDelegate : public ConfirmInfoBarDelegate, std::string username; }; - // Creates an autologin infobar delegate and adds it to the infobar service - // for |web_contents|. Returns whether the infobar was successfully created. + // Creates an autologin infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. Returns whether the infobar was + // successfully added. static bool Create(content::WebContents* web_contents, const Params& params); protected: - AutoLoginInfoBarDelegate(InfoBarService* owner, - const Params& params, - Profile* profile); + AutoLoginInfoBarDelegate(const Params& params, Profile* profile); virtual ~AutoLoginInfoBarDelegate(); private: diff --git a/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm index 9d64080b..3d0be70 100644 --- a/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm @@ -57,10 +57,13 @@ @end -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<AlternateNavInfoBarController> controller( [[AlternateNavInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } diff --git a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm index b237083..99c34bb 100644 --- a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm @@ -137,10 +137,13 @@ @end -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<ConfirmInfoBarController> controller( [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } diff --git a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm index f7cdcee..e7eb9d4 100644 --- a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm @@ -89,14 +89,15 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, CocoaProfileTest::SetUp(); web_contents_.reset( WebContents::Create(WebContents::CreateParams(profile()))); - InfoBarService::CreateForWebContents(web_contents_.get()); + InfoBarService::CreateForWebContents(web_contents_.get()); - delegate_ = new MockConfirmInfoBarDelegate(this); - infobar_.reset(new InfoBarCocoa( - InfoBarService::FromWebContents(web_contents_.get()), delegate_)); + scoped_ptr<InfoBarDelegate> delegate( + new MockConfirmInfoBarDelegate(this)); + infobar_ = new InfoBarCocoa(delegate.Pass()); + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); controller_.reset([[TestConfirmInfoBarController alloc] - initWithInfoBar:infobar_.get()]); + initWithInfoBar:infobar_]); infobar_->set_controller(controller_); container_.reset( @@ -106,20 +107,22 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, closed_delegate_ok_clicked_ = false; closed_delegate_cancel_clicked_ = false; closed_delegate_link_clicked_ = false; + delegate_closed_ = false; } virtual void TearDown() OVERRIDE { [controller_ removeSelf]; - if (delegate_) - delete delegate_; CocoaProfileTest::TearDown(); } protected: - // Hopefully-obvious: If this returns true, you must not deref |delegate_|! - bool delegate_closed() const { return delegate_ == NULL; } + // True if delegate is closed. + bool delegate_closed() const { return delegate_closed_; } + + MockConfirmInfoBarDelegate* delegate() const { + return static_cast<MockConfirmInfoBarDelegate*>(infobar_->delegate()); + } - MockConfirmInfoBarDelegate* delegate_; // Owns itself. base::scoped_nsobject<id> container_; base::scoped_nsobject<ConfirmInfoBarController> controller_; bool closed_delegate_ok_clicked_; @@ -128,14 +131,16 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, private: virtual void OnInfoBarDelegateClosed() OVERRIDE { - closed_delegate_ok_clicked_ = delegate_->ok_clicked(); - closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); - closed_delegate_link_clicked_ = delegate_->link_clicked(); - delegate_ = NULL; + closed_delegate_ok_clicked_ = delegate()->ok_clicked(); + closed_delegate_cancel_clicked_ = delegate()->cancel_clicked(); + closed_delegate_link_clicked_ = delegate()->link_clicked(); + delegate_closed_ = true; + controller_.reset(); } scoped_ptr<WebContents> web_contents_; - scoped_ptr<InfoBarCocoa> infobar_; + InfoBarCocoa* infobar_; // Weak, will delete itself. + bool delegate_closed_; }; @@ -143,9 +148,9 @@ TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { // Make sure someone looked at the message, link, and icon. - EXPECT_TRUE(delegate_->message_text_accessed()); - EXPECT_TRUE(delegate_->link_text_accessed()); - EXPECT_TRUE(delegate_->icon_accessed()); + EXPECT_TRUE(delegate()->message_text_accessed()); + EXPECT_TRUE(delegate()->link_text_accessed()); + EXPECT_TRUE(delegate()->icon_accessed()); // Check to make sure the infobar message was set properly. EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage, @@ -170,15 +175,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking the OK button calls Accept() but does not close // the infobar. [controller_ ok:nil]; ASSERT_FALSE(delegate_closed()); - EXPECT_TRUE(delegate_->ok_clicked()); - EXPECT_FALSE(delegate_->cancel_clicked()); - EXPECT_FALSE(delegate_->link_clicked()); + EXPECT_TRUE(delegate()->ok_clicked()); + EXPECT_FALSE(delegate()->cancel_clicked()); + EXPECT_FALSE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { @@ -192,15 +197,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking the cancel button calls Cancel() but does not close // the infobar. [controller_ cancel:nil]; ASSERT_FALSE(delegate_closed()); - EXPECT_FALSE(delegate_->ok_clicked()); - EXPECT_TRUE(delegate_->cancel_clicked()); - EXPECT_FALSE(delegate_->link_clicked()); + EXPECT_FALSE(delegate()->ok_clicked()); + EXPECT_TRUE(delegate()->cancel_clicked()); + EXPECT_FALSE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { @@ -214,15 +219,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking on the link calls LinkClicked() on the // delegate. It should not close the infobar. [controller_ linkClicked]; ASSERT_FALSE(delegate_closed()); - EXPECT_FALSE(delegate_->ok_clicked()); - EXPECT_FALSE(delegate_->cancel_clicked()); - EXPECT_TRUE(delegate_->link_clicked()); + EXPECT_FALSE(delegate()->ok_clicked()); + EXPECT_FALSE(delegate()->cancel_clicked()); + EXPECT_TRUE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ResizeView) { diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h index 3f35f94..aea7693 100644 --- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h +++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h @@ -20,9 +20,6 @@ class InfobarBridge; // The native extension view retrieved from the extension host. Weak. NSView* extensionView_; - // The window containing this InfoBar. Weak. - NSWindow* window_; - // The InfoBar's button with the Extension's icon that launches the context // menu. base::scoped_nsobject<MenuButton> dropdownButton_; diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm index 97568c5..cba2222 100644 --- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm @@ -52,21 +52,15 @@ const CGFloat kToolbarMaxHeightPx = 72.0; // A helper class to bridge the asynchronous Skia bitmap loading mechanism to // the extension's button. -class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { +class InfobarBridge { public: explicit InfobarBridge(ExtensionInfoBarController* owner) : owner_(owner), delegate_([owner delegate]->AsExtensionInfoBarDelegate()), weak_ptr_factory_(this) { - delegate_->set_observer(this); LoadIcon(); } - virtual ~InfobarBridge() { - if (delegate_) - delegate_->set_observer(NULL); - } - // Load the Extension's icon image. void LoadIcon() { const extensions::Extension* extension = delegate_->extension_view_host()-> @@ -119,11 +113,6 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { canvas->ExtractImageRep().sk_bitmap())]; } - // Overridden from ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE { - delegate_ = NULL; - } - private: // Weak. Owns us. ExtensionInfoBarController* owner_; @@ -139,22 +128,11 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { @implementation ExtensionInfoBarController -- (id)initWithInfoBar:(InfoBarCocoa*)infobar - window:(NSWindow*)window { +- (id)initWithInfoBar:(InfoBarCocoa*)infobar { if ((self = [super initWithInfoBar:infobar])) { - window_ = window; dropdownButton_.reset([[MenuButton alloc] init]); [dropdownButton_ setOpenMenuOnClick:YES]; - extensions::ExtensionViewHost* extensionViewHost = - [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host(); - Browser* browser = chrome::FindBrowserWithWebContents( - [self infobar]->OwnerCocoa()->web_contents()); - contextMenuController_.reset([[ExtensionActionContextMenuController alloc] - initWithExtension:extensionViewHost->extension() - browser:browser - extensionAction:NULL]); - base::scoped_nsobject<NSMenu> contextMenu( [[NSMenu alloc] initWithTitle:@""]); [contextMenu setDelegate:self]; @@ -224,8 +202,13 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustExtensionViewSize) - name:NSWindowDidResizeNotification - object:window_]; + name:NSViewFrameDidChangeNotification + object:[self view]]; +} + +- (void)infobarWillHide { + [[dropdownButton_ menu] cancelTracking]; + [super infobarWillHide]; } - (void)infobarWillClose { @@ -246,7 +229,7 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { - (void)adjustExtensionViewSize { [extensionView_ setPostsFrameChangedNotifications:NO]; NSSize extensionViewSize = [extensionView_ frame].size; - extensionViewSize.width = NSWidth([window_ frame]); + extensionViewSize.width = NSWidth([[self view] frame]); extensionViewSize.height = [self clampedExtensionViewHeight]; [extensionView_ setFrameSize:extensionViewSize]; [extensionView_ setPostsFrameChangedNotifications:YES]; @@ -257,20 +240,32 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { } - (void)menuNeedsUpdate:(NSMenu*)menu { + DCHECK([self isOwned]); + + if (!contextMenuController_) { + extensions::ExtensionViewHost* extensionViewHost = + [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host(); + Browser* browser = chrome::FindBrowserWithWebContents( + [self infobar]->OwnerCocoa()->web_contents()); + contextMenuController_.reset([[ExtensionActionContextMenuController alloc] + initWithExtension:extensionViewHost->extension() + browser:browser + extensionAction:NULL]); + } + [menu removeAllItems]; [contextMenuController_ populateMenu:menu]; } @end -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); - NSWindow* window = - [(NSView*)owner->web_contents()->GetView()->GetContentNativeView() - window]; +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<ExtensionInfoBarController> controller( - [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get() - window:window]); + [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h index 7419f31..b48c6a4 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h @@ -15,7 +15,7 @@ // actually in InfoBarController. class InfoBarCocoa : public InfoBar { public: - InfoBarCocoa(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarCocoa(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarCocoa(); @@ -26,7 +26,6 @@ class InfoBarCocoa : public InfoBar { } // These functions allow access to protected InfoBar functions. - void RemoveSelfCocoa(); InfoBarService* OwnerCocoa(); base::WeakPtr<InfoBarCocoa> GetWeakPtr(); diff --git a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm index 398cd5f..b49579c 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm @@ -4,6 +4,8 @@ #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" +#import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" + const int InfoBar::kSeparatorLineHeight = 1; const int InfoBar::kDefaultArrowTargetHeight = 11; const int InfoBar::kMaximumArrowTargetHeight = 24; @@ -11,16 +13,14 @@ const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; const int InfoBar::kMaximumArrowTargetHalfWidth = 14; const int InfoBar::kDefaultBarTargetHeight = 36; -InfoBarCocoa::InfoBarCocoa(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarCocoa::InfoBarCocoa(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), weak_ptr_factory_(this) { } InfoBarCocoa::~InfoBarCocoa() { -} - -void InfoBarCocoa::RemoveSelfCocoa() { - RemoveSelf(); + if (controller()) + [controller() infobarWillClose]; } InfoBarService* InfoBarCocoa::OwnerCocoa() { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm index ffaa38c..9d9df42 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm @@ -6,7 +6,6 @@ #include "base/logging.h" #include "base/mac/mac_util.h" -#include "base/message_loop/message_loop.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_container.h" @@ -100,11 +99,8 @@ } - (void)removeInfoBar:(InfoBarCocoa*)infobar { - InfoBarController* controller = infobar->controller(); - [controller infobarWillClose]; - infobar->set_controller(nil); - [self removeController:controller]; - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); + [infobar->controller() infobarWillHide]; + [self removeController:infobar->controller()]; } - (void)positionInfoBarsAndRedraw:(BOOL)isAnimating { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm index 15a83b6..52b2412 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm @@ -9,6 +9,7 @@ #include "base/mac/scoped_nsobject.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" +#import "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h" #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" #import "chrome/browser/ui/cocoa/view_resizer_pong.h" @@ -59,17 +60,16 @@ TEST_F(InfoBarContainerControllerTest, BWCPong) { TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { NSView* view = [controller_ view]; - // This delegate deletes itself when they're told their infobars have closed. - InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); - - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents_.get()); - scoped_ptr<InfoBarCocoa> infobar(static_cast<InfoBarCocoa*>( - confirmDelegate->CreateInfoBar(infobar_service))); + scoped_ptr<InfoBarDelegate> confirm_delegate( + new MockConfirmInfoBarDelegate(NULL)); + scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(confirm_delegate.Pass())); + base::scoped_nsobject<ConfirmInfoBarController> controller( + [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); + infobar->set_controller(controller); [controller_ addInfoBar:infobar.get() position:0]; EXPECT_EQ(1U, [[view subviews] count]); - [controller_ removeInfoBar:infobar.release()]; + [controller_ removeInfoBar:infobar.get()]; EXPECT_EQ(0U, [[view subviews] count]); } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.h b/chrome/browser/ui/cocoa/infobars/infobar_controller.h index 0699d37..7755dab 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.h @@ -72,6 +72,10 @@ class InfoBarService; - (void)addAdditionalControls; // Subclasses must override this method to perform cleanup just before the +// infobar hides. +- (void)infobarWillHide; + +// Subclasses must override this method to perform cleanup just before the // infobar closes. - (void)infobarWillClose; @@ -85,8 +89,8 @@ class InfoBarService; @end @interface InfoBarController (Protected) -// Closes and disables the provided menu. Subclasses should call this for each -// popup menu in -infobarWillClose. +// Disables the provided menu. Subclasses should call this for each popup menu +// in -infobarWillClose. - (void)disablePopUpMenu:(NSMenu*)menu; @end diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm index 1385f81..bccb2df 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm @@ -116,13 +116,16 @@ } - (void)removeSelf { - infobar_->RemoveSelfCocoa(); + infobar_->RemoveSelf(); } - (void)addAdditionalControls { // Default implementation does nothing. } +- (void)infobarWillHide { +} + - (void)infobarWillClose { } @@ -149,9 +152,6 @@ } - (void)disablePopUpMenu:(NSMenu*)menu { - // Remove the menu if visible. - [menu cancelTracking]; - // If the menu is re-opened, prevent queries to update items. [menu setDelegate:nil]; diff --git a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc index da5f1a6..f772168 100644 --- a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc +++ b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc @@ -9,7 +9,7 @@ const char MockConfirmInfoBarDelegate::kMessage[] = "MockConfirmInfoBarMessage"; MockConfirmInfoBarDelegate::MockConfirmInfoBarDelegate(Owner* owner) - : ConfirmInfoBarDelegate(NULL), + : ConfirmInfoBarDelegate(), owner_(owner), closes_on_action_(true), icon_accessed_(false), diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm index 3afe320..4f0d7ff 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm @@ -27,11 +27,13 @@ using InfoBarUtilities::VerifyControlOrderAndSpacing; using InfoBarUtilities::CreateLabel; using InfoBarUtilities::AddMenuItem; -// TranslateInfoBarDelegate views specific method: -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; - switch (infobar_type_) { + switch (infobar->delegate()->AsTranslateInfoBarDelegate()->infobar_type()) { case BEFORE_TRANSLATE: infobar_controller.reset([[BeforeTranslateInfobarController alloc] initWithInfoBar:infobar.get()]); @@ -49,7 +51,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { NOTREACHED(); } infobar->set_controller(infobar_controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } @implementation TranslateInfoBarControllerBase (FrameChangeObserver) @@ -359,12 +361,17 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { [self updateState]; } +- (void)infobarWillHide { + [[fromLanguagePopUp_ menu] cancelTracking]; + [[toLanguagePopUp_ menu] cancelTracking]; + [[optionsPopUp_ menu] cancelTracking]; + [super infobarWillHide]; +} + - (void)infobarWillClose { [self disablePopUpMenu:[fromLanguagePopUp_ menu]]; [self disablePopUpMenu:[toLanguagePopUp_ menu]]; [self disablePopUpMenu:[optionsPopUp_ menu]]; - // [super infobarWillClose] clears the owner field which is relied on by the - // notification handler, so remove the handler first. [[NSNotificationCenter defaultCenter] removeObserver:self]; [super infobarWillClose]; } @@ -458,9 +465,6 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { } - (void)dealloc { - // Perhaps this was removed as an observer in -infobarWillClose, but there's - // no guarantee that that was the case. - [[NSNotificationCenter defaultCenter] removeObserver:self]; [showOriginalButton_ setTarget:nil]; [translateMessageButton_ setTarget:nil]; [super dealloc]; diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm index 3ecb8a24..45dce1e 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm @@ -36,13 +36,11 @@ TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { public: - MockTranslateInfoBarDelegate(InfoBarService* infobar_service, - TranslateInfoBarDelegate::Type type, + MockTranslateInfoBarDelegate(TranslateInfoBarDelegate::Type type, TranslateErrors::Type error, PrefService* prefs, ShortcutConfiguration config) - : TranslateInfoBarDelegate(infobar_service, type, NULL, "en", "es", error, - prefs, config) { + : TranslateInfoBarDelegate(type, NULL, "en", "es", error, prefs, config) { } MOCK_METHOD0(Translate, void()); @@ -58,8 +56,13 @@ class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { MOCK_METHOD0(ToggleAlwaysTranslate, void()); }; +} // namespace + class TranslationInfoBarTest : public CocoaProfileTest { public: + TranslationInfoBarTest() : CocoaProfileTest(), infobar_(NULL) { + } + // Each test gets a single Mock translate delegate for the lifetime of // the test. virtual void SetUp() OVERRIDE { @@ -68,32 +71,37 @@ class TranslationInfoBarTest : public CocoaProfileTest { web_contents_.reset( WebContents::Create(WebContents::CreateParams(profile()))); InfoBarService::CreateForWebContents(web_contents_.get()); - CreateInfoBar(); } - void CreateInfoBar() { - CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + virtual void TearDown() OVERRIDE { + if (infobar_) { + infobar_->CloseSoon(); + infobar_ = NULL; + } + CocoaProfileTest::TearDown(); } void CreateInfoBar(TranslateInfoBarDelegate::Type type) { TranslateErrors::Type error = TranslateErrors::NONE; if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) error = TranslateErrors::NETWORK; - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents_.get()); Profile* profile = Profile::FromBrowserContext(web_contents_->GetBrowserContext()); ShortcutConfiguration config; config.never_translate_min_count = 3; config.always_translate_min_count = 3; - infobar_delegate_.reset(new MockTranslateInfoBarDelegate( - infobar_service, type, error, profile->GetPrefs(), config)); [[infobar_controller_ view] removeFromSuperview]; - InfoBarDelegate* base = - static_cast<InfoBarDelegate*>(infobar_delegate_.get()); - infobar_.reset( - static_cast<InfoBarCocoa*>(base->CreateInfoBar(infobar_service))); + scoped_ptr<TranslateInfoBarDelegate> delegate( + new MockTranslateInfoBarDelegate(type, error, profile->GetPrefs(), + config)); + scoped_ptr<InfoBar> infobar( + TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); + if (infobar_) + infobar_->CloseSoon(); + infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); + infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( infobar_->controller()) retain]); @@ -104,23 +112,26 @@ class TranslationInfoBarTest : public CocoaProfileTest { [[test_window() contentView] addSubview:[infobar_controller_ view]]; } + MockTranslateInfoBarDelegate* infobar_delegate() const { + return static_cast<MockTranslateInfoBarDelegate*>(infobar_->delegate()); + } + scoped_ptr<WebContents> web_contents_; - scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate_; - scoped_ptr<InfoBarCocoa> infobar_; + InfoBarCocoa* infobar_; // weak, deletes itself base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; }; // Check that we can instantiate a Translate Infobar correctly. TEST_F(TranslationInfoBarTest, Instantiate) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); ASSERT_TRUE(infobar_controller_.get()); } // Check that clicking the Translate button calls Translate(). TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); - EXPECT_CALL(*infobar_delegate_, Translate()).Times(1); + EXPECT_CALL(*infobar_delegate(), Translate()).Times(1); [infobar_controller_ ok:nil]; } @@ -129,22 +140,23 @@ TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) { TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) { CreateInfoBar(TranslateInfoBarDelegate::TRANSLATION_ERROR); - EXPECT_CALL(*infobar_delegate_, Translate()).Times(1); + EXPECT_CALL(*infobar_delegate(), Translate()).Times(1); [infobar_controller_ ok:nil]; } // Check that clicking the "Show Original button calls RevertTranslation(). TEST_F(TranslationInfoBarTest, RevertCalledOnButtonPress) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); - EXPECT_CALL(*infobar_delegate_, RevertTranslation()).Times(1); + EXPECT_CALL(*infobar_delegate(), RevertTranslation()).Times(1); [infobar_controller_ showOriginal:nil]; } // Check that items in the options menu are hooked up correctly. TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { - EXPECT_CALL(*infobar_delegate_, Translate()) + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); [infobar_controller_ rebuildOptionsMenu:NO]; @@ -168,19 +180,19 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { NSMenuItem* aboutTranslateItem = [optionsMenuItems objectAtIndex:6]; { - EXPECT_CALL(*infobar_delegate_, ToggleAlwaysTranslate()) + EXPECT_CALL(*infobar_delegate(), ToggleAlwaysTranslate()) .Times(1); [infobar_controller_ optionsMenuChanged:alwaysTranslateLanguateItem]; } { - EXPECT_CALL(*infobar_delegate_, ToggleTranslatableLanguageByPrefs()) + EXPECT_CALL(*infobar_delegate(), ToggleTranslatableLanguageByPrefs()) .Times(1); [infobar_controller_ optionsMenuChanged:neverTranslateLanguateItem]; } { - EXPECT_CALL(*infobar_delegate_, ToggleSiteBlacklist()) + EXPECT_CALL(*infobar_delegate(), ToggleSiteBlacklist()) .Times(1); [infobar_controller_ optionsMenuChanged:neverTranslateSiteItem]; } @@ -198,13 +210,13 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { // translate" mode doesn't trigger a translation or change state. // http://crbug.com/36666 TEST_F(TranslationInfoBarTest, Bug36666) { - EXPECT_CALL(*infobar_delegate_, Translate()) + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); - CreateInfoBar(); int arbitrary_index = 2; [infobar_controller_ sourceLanguageModified:arbitrary_index]; - EXPECT_CALL(*infobar_delegate_, Translate()) + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); } @@ -212,11 +224,10 @@ TEST_F(TranslationInfoBarTest, Bug36666) { // each of the states. // http://crbug.com/36895 TEST_F(TranslationInfoBarTest, Bug36895) { - EXPECT_CALL(*infobar_delegate_, Translate()) - .Times(0); - for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) { CreateInfoBar(kTranslateToolbarStates[i]); + EXPECT_CALL(*infobar_delegate(), Translate()) + .Times(0); EXPECT_TRUE( [infobar_controller_ verifyLayout]) << "Layout wrong, for state #" << i; } @@ -251,5 +262,3 @@ TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) { EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); } - -} // namespace diff --git a/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm b/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm index 5f04437..b25ab67 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm @@ -15,6 +15,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #import "chrome/browser/mac/keystone_glue.h" #include "chrome/browser/profiles/profile.h" @@ -43,8 +44,7 @@ class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { static void Create(); private: - KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service, - PrefService* prefs); + explicit KeystonePromotionInfoBarDelegate(PrefService* prefs); virtual ~KeystonePromotionInfoBarDelegate(); // Sets this info bar to be able to expire. Called a predetermined amount @@ -83,17 +83,15 @@ void KeystonePromotionInfoBarDelegate::Create() { return; InfoBarService* infobar_service = InfoBarService::FromWebContents(webContents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new KeystonePromotionInfoBarDelegate( - infobar_service, + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate( Profile::FromBrowserContext( - webContents->GetBrowserContext())->GetPrefs()))); + webContents->GetBrowserContext())->GetPrefs())))); } KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( - InfoBarService* infobar_service, PrefService* prefs) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), prefs_(prefs), can_expire_(false), weak_ptr_factory_(this) { diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.cc b/chrome/browser/ui/collected_cookies_infobar_delegate.cc index b60761e..775b02e 100644 --- a/chrome/browser/ui/collected_cookies_infobar_delegate.cc +++ b/chrome/browser/ui/collected_cookies_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -14,13 +15,13 @@ // static void CollectedCookiesInfoBarDelegate::Create(InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new CollectedCookiesInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new CollectedCookiesInfoBarDelegate()))); } -CollectedCookiesInfoBarDelegate::CollectedCookiesInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +CollectedCookiesInfoBarDelegate::CollectedCookiesInfoBarDelegate() + : ConfirmInfoBarDelegate() { } CollectedCookiesInfoBarDelegate::~CollectedCookiesInfoBarDelegate() { diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.h b/chrome/browser/ui/collected_cookies_infobar_delegate.h index 2023026..2fb053a 100644 --- a/chrome/browser/ui/collected_cookies_infobar_delegate.h +++ b/chrome/browser/ui/collected_cookies_infobar_delegate.h @@ -16,12 +16,12 @@ class InfoBarService; // the reload right from the infobar. class CollectedCookiesInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a collected cookies infobar delegate and adds it to + // Creates a collected cookies infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit CollectedCookiesInfoBarDelegate(InfoBarService* infobar_service); + CollectedCookiesInfoBarDelegate(); virtual ~CollectedCookiesInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc index 8274edd..6e99a43 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc @@ -236,13 +236,9 @@ TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string())); - // Removing an |InfoBarDelegate| from the |InfoBarService| does not delete - // it. Hence the |delegate| must be cleaned up after it was removed from the - // |infobar_service|. InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents()); - scoped_ptr<InfoBarDelegate> delegate(infobar_service->infobar_at(0)); - infobar_service->RemoveInfoBar(delegate.get()); + infobar_service->RemoveInfoBar(infobar_service->infobar_at(0)); } TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { diff --git a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc index 8c1f841..7a93d5d 100644 --- a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc +++ b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -14,13 +15,13 @@ // static void MediaSettingChangedInfoBarDelegate::Create( InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new MediaSettingChangedInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new MediaSettingChangedInfoBarDelegate()))); } -MediaSettingChangedInfoBarDelegate::MediaSettingChangedInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +MediaSettingChangedInfoBarDelegate::MediaSettingChangedInfoBarDelegate() + : ConfirmInfoBarDelegate() { } MediaSettingChangedInfoBarDelegate::~MediaSettingChangedInfoBarDelegate() { diff --git a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h index cbd459e..7fdbe86 100644 --- a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h +++ b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h @@ -13,12 +13,12 @@ class InfoBarService; // settings, and allows a reload via a button on the infobar. class MediaSettingChangedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a media setting changed infobar delegate and adds it to - // |infobar_service|. + // Creates a media setting changed infobar and delegate and adds the infobar + // to |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit MediaSettingChangedInfoBarDelegate(InfoBarService* infobar_service); + MediaSettingChangedInfoBarDelegate(); virtual ~MediaSettingChangedInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/ui/extensions/extension_install_ui_default.cc b/chrome/browser/ui/extensions/extension_install_ui_default.cc index 8ebb594..cec3a91 100644 --- a/chrome/browser/ui/extensions/extension_install_ui_default.cc +++ b/chrome/browser/ui/extensions/extension_install_ui_default.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.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/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" @@ -80,13 +81,13 @@ void ShowExtensionInstalledBubble(const extensions::Extension* extension, // Helper class to put up an infobar when installation fails. class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an error infobar delegate and adds it to |infobar_service|. + // Creates an error infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, const extensions::CrxInstallerError& error); private: - ErrorInfoBarDelegate(InfoBarService* infobar_service, - const extensions::CrxInstallerError& error); + explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error); virtual ~ErrorInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -103,14 +104,13 @@ class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { // static void ErrorInfoBarDelegate::Create(InfoBarService* infobar_service, const extensions::CrxInstallerError& error) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ErrorInfoBarDelegate(infobar_service, error))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ErrorInfoBarDelegate(error)))); } ErrorInfoBarDelegate::ErrorInfoBarDelegate( - InfoBarService* infobar_service, const extensions::CrxInstallerError& error) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), error_(error) { } diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc index bb68ff6..41c27e8 100644 --- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc @@ -15,17 +15,16 @@ #include "ui/base/l10n/l10n_util.h" AfterTranslateInfoBar::AfterTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), weak_factory_(this) { } AfterTranslateInfoBar::~AfterTranslateInfoBar() { } -void AfterTranslateInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void AfterTranslateInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); bool swapped_language_combos = false; bool autodetermined_source_language = diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h index 8366119..000f2fd 100644 --- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h @@ -13,14 +13,13 @@ class TranslateInfoBarDelegate; class AfterTranslateInfoBar : public TranslateInfoBarBase { public: - AfterTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit AfterTranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~AfterTranslateInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual bool ShowOptionsMenuButton() const OVERRIDE; // These methods set the original/target language on the diff --git a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc index 68fbad9..a70d634 100644 --- a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc @@ -10,24 +10,25 @@ // AlternateNavInfoBarDelegate ------------------------------------------------- -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new AlternateNavInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new AlternateNavInfoBarGtk(delegate.Pass())); } // AlternateNavInfoBarGtk ------------------------------------------------------ AlternateNavInfoBarGtk::AlternateNavInfoBarGtk( - InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate) { + scoped_ptr<AlternateNavInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()) { } AlternateNavInfoBarGtk::~AlternateNavInfoBarGtk() { } -void AlternateNavInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void AlternateNavInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); size_t link_offset; string16 display_text = GetDelegate()->GetMessageTextWithOffset(&link_offset); diff --git a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h index 9cf6a79..45f3e00 100644 --- a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_ #define CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_ -#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" #include "ui/base/gtk/gtk_signal.h" @@ -14,14 +14,14 @@ class AlternateNavInfoBarDelegate; // An infobar that shows a string with an embedded link. class AlternateNavInfoBarGtk : public InfoBarGtk { public: - AlternateNavInfoBarGtk(InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate); + explicit AlternateNavInfoBarGtk( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); private: virtual ~AlternateNavInfoBarGtk(); // InfoBarGtk: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; AlternateNavInfoBarDelegate* GetDelegate(); diff --git a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc index 86de96f..ee8e228 100644 --- a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc @@ -13,16 +13,15 @@ #include "ui/base/l10n/l10n_util.h" BeforeTranslateInfoBar::BeforeTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate) { + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()) { } BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { } -void BeforeTranslateInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void BeforeTranslateInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); GtkWidget* new_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); gtk_util::CenterWidgetInHBox(hbox(), new_hbox, false, 0); diff --git a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h index 3e46456..25753be 100644 --- a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h @@ -12,14 +12,14 @@ class TranslateInfoBarDelegate; class BeforeTranslateInfoBar : public TranslateInfoBarBase { public: - BeforeTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit BeforeTranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~BeforeTranslateInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual bool ShowOptionsMenuButton() const OVERRIDE; CHROMEGTK_CALLBACK_0(BeforeTranslateInfoBar, void, OnLanguageModified); diff --git a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc index e5ca3cb..fbdfdb5 100644 --- a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc @@ -16,16 +16,18 @@ // ConfirmInfoBarDelegate ------------------------------------------------------ -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBarGtk(delegate.Pass())); } // ConfirmInfoBarGtk ----------------------------------------------------------- -ConfirmInfoBarGtk::ConfirmInfoBarGtk(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), +ConfirmInfoBarGtk::ConfirmInfoBarGtk( + scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), confirm_hbox_(NULL), size_group_(NULL) { } @@ -35,8 +37,8 @@ ConfirmInfoBarGtk::~ConfirmInfoBarGtk() { g_object_unref(size_group_); } -void ConfirmInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void ConfirmInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, kEndOfLabelSpacing); diff --git a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h index 3173efb..f670ca3 100644 --- a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h @@ -18,14 +18,13 @@ typedef struct _GtkWidget GtkWidget; // "Would you like to do X? [Yes] [No] _Learn More_ [x]" class ConfirmInfoBarGtk : public InfoBarGtk { public: - ConfirmInfoBarGtk(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate); + explicit ConfirmInfoBarGtk(scoped_ptr<ConfirmInfoBarDelegate> delegate); private: virtual ~ConfirmInfoBarGtk(); // InfoBarGtk: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; ConfirmInfoBarDelegate* GetDelegate(); diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc index 9ddfe4d..8cc4366 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc @@ -31,52 +31,32 @@ // ExtensionInfoBarDelegate --------------------------------------------------- -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ExtensionInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ExtensionInfoBarGtk(delegate.Pass())); } // ExtensionInfoBarGtk -------------------------------------------------------- -ExtensionInfoBarGtk::ExtensionInfoBarGtk(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), - delegate_(delegate), +ExtensionInfoBarGtk::ExtensionInfoBarGtk( + scoped_ptr<ExtensionInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), view_(NULL), button_(NULL), icon_(NULL), alignment_(NULL), weak_ptr_factory_(this) { - GetDelegate()->set_observer(this); - int height = GetDelegate()->height(); SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); } ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { - if (GetDelegate()) - GetDelegate()->set_observer(NULL); } -void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { - DCHECK(view_); - DCHECK(alignment_); - gtk_util::RemoveAllChildren(alignment_); -} - -void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - // Extension infobars are always drawn with chrome-theme colors. - *r = *g = *b = 233.0 / 255.0; -} - -void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - *r = *g = *b = 218.0 / 255.0; -} - -void ExtensionInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void ExtensionInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); // Always render the close button as if we were doing chrome style widget // rendering. For extension infobars, we force chrome style rendering because @@ -142,15 +122,28 @@ void ExtensionInfoBarGtk::InitWidgets() { G_CALLBACK(&OnSizeAllocateThunk), this); } +void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { + DCHECK(view_); + DCHECK(alignment_); + gtk_util::RemoveAllChildren(alignment_); +} + +void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + // Extension infobars are always drawn with chrome-theme colors. + *r = *g = *b = 233.0 / 255.0; +} + +void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + *r = *g = *b = 218.0 / 255.0; +} + void ExtensionInfoBarGtk::StoppedShowing() { if (button_) gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); } -void ExtensionInfoBarGtk::OnDelegateDeleted() { - delegate_ = NULL; -} - void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { DCHECK(icon_); @@ -188,7 +181,7 @@ void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { } ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() { - return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; + return delegate()->AsExtensionInfoBarDelegate(); } Browser* ExtensionInfoBarGtk::GetBrowser() { diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h index 71c9c2a..af6a856 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h @@ -16,30 +16,24 @@ class ExtensionContextMenuModel; class ExtensionViewGtk; class MenuGtk; -class ExtensionInfoBarGtk : public InfoBarGtk, - public MenuGtk::Delegate, - public ExtensionInfoBarDelegate::DelegateObserver { +class ExtensionInfoBarGtk : public InfoBarGtk, public MenuGtk::Delegate { public: - ExtensionInfoBarGtk(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate); + explicit ExtensionInfoBarGtk(scoped_ptr<ExtensionInfoBarDelegate> delegate); private: virtual ~ExtensionInfoBarGtk(); // InfoBarGtk: + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual void PlatformSpecificHide(bool animate) OVERRIDE; virtual void GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; virtual void GetBottomColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; - virtual void InitWidgets() OVERRIDE; // MenuGtk::Delegate: virtual void StoppedShowing() OVERRIDE; - // ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE; - void OnImageLoaded(const gfx::Image& image); ExtensionInfoBarDelegate* GetDelegate(); @@ -61,11 +55,6 @@ class ExtensionInfoBarGtk : public InfoBarGtk, CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, gboolean, OnExpose, GdkEventExpose*); - // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once - // InfoBars own their delegates (and thus we don't need the DelegateObserver - // functionality). For now, almost everyone should use GetDelegate() instead. - InfoBarDelegate* delegate_; - ExtensionViewGtk* view_; // The button that activates the extension popup menu. Non-NULL if the diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc index 6edd5d9..78f1116 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc @@ -8,7 +8,6 @@ #include <utility> -#include "base/message_loop/message_loop.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/ui/browser_window.h" @@ -53,7 +52,6 @@ bool InfoBarContainerGtk::ContainsInfobars() const { void InfoBarContainerGtk::PlatformSpecificAddInfoBar(InfoBar* infobar, size_t position) { InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); - infobar_gtk->InitWidgets(); infobars_gtk_.insert(infobars_gtk_.begin() + position, infobar_gtk); if (infobars_gtk_.back() == infobar_gtk) { @@ -81,8 +79,6 @@ void InfoBarContainerGtk::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { std::find(infobars_gtk_.begin(), infobars_gtk_.end(), infobar); if (it != infobars_gtk_.end()) infobars_gtk_.erase(it); - - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } void InfoBarContainerGtk::PlatformSpecificInfoBarStateChanged( diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc index ed157ec..514d9a7 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc @@ -52,8 +52,8 @@ const int InfoBar::kDefaultBarTargetHeight = 36; // static const int InfoBarGtk::kEndOfLabelSpacing = 6; -InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarGtk::InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), bg_box_(NULL), hbox_(NULL), theme_service_(NULL), @@ -63,7 +63,32 @@ InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) InfoBarGtk::~InfoBarGtk() { } -void InfoBarGtk::InitWidgets() { +GdkColor InfoBarGtk::GetBorderColor() const { + DCHECK(theme_service_); + return theme_service_->GetBorderColor(); +} + +int InfoBarGtk::AnimatingHeight() const { + return animation().is_animating() ? bar_target_height() : 0; +} + +SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { + double r, g, b; + (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); + return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); +} + +void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); +} + +void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); +} + +void InfoBarGtk::PlatformSpecificSetOwner() { DCHECK(owner()); DCHECK(!theme_service_); theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( @@ -114,31 +139,6 @@ void InfoBarGtk::InitWidgets() { UpdateBorderColor(); } -GdkColor InfoBarGtk::GetBorderColor() const { - DCHECK(theme_service_); - return theme_service_->GetBorderColor(); -} - -int InfoBarGtk::AnimatingHeight() const { - return animation().is_animating() ? bar_target_height() : 0; -} - -SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { - double r, g, b; - (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); - return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); -} - -void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); -} - -void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); -} - void InfoBarGtk::PlatformSpecificShow(bool animate) { DCHECK(bg_box_); @@ -274,7 +274,7 @@ void InfoBarGtk::UpdateBorderColor() { void InfoBarGtk::OnCloseButton(GtkWidget* button) { // If we're not owned, we're already closing, so don't call // InfoBarDismissed(), since this can lead to us double-recording dismissals. - if (delegate() && owner()) + if (owner()) delegate()->InfoBarDismissed(); RemoveSelf(); } diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.h b/chrome/browser/ui/gtk/infobars/infobar_gtk.h index 9b77635..e9e1d44 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.h @@ -33,21 +33,9 @@ class InfoBarGtk : public InfoBar, typedef void (InfoBarGtk::*ColorGetter)(InfoBarDelegate::Type, double* r, double* g, double* b); - InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarGtk(); - // Must be called before we try to show the infobar. Inits any widgets and - // related objects necessary. This must be called only once during the - // infobar's life. - // - // NOTE: Subclasses who need to init widgets should override this function and - // explicitly call their parent's implementation first, then continue with - // further work they need to do. Failing to call the parent implementation - // first (or at all), or setting up widgets in the constructor instead of - // here, will lead to bad side effects like crashing or having this function - // get called repeatedly. - virtual void InitWidgets(); - // Get the top level native GTK widget for this infobar. GtkWidget* widget() { return widget_.get(); } @@ -72,6 +60,16 @@ class InfoBarGtk : public InfoBar, static const int kEndOfLabelSpacing; // InfoBar: + + // Inits any widgets and related objects necessary. + // + // NOTE: Subclasses who need to init widgets should override this function and + // explicitly call their parent's implementation first, then continue with + // further work they need to do. Failing to call the parent implementation + // first (or at all), or setting up widgets in the constructor instead of + // here, will lead to bad side effects like crashing. + virtual void PlatformSpecificSetOwner() OVERRIDE; + virtual void PlatformSpecificShow(bool animate) OVERRIDE; virtual void PlatformSpecificOnCloseSoon() OVERRIDE; virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE; diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc index 686743c..a2489a6 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc @@ -21,24 +21,27 @@ // TranslateInfoBarDelegate --------------------------------------------------- -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - if (infobar_type_ == BEFORE_TRANSLATE) - return new BeforeTranslateInfoBar(owner, this); - if (infobar_type_ == AFTER_TRANSLATE) - return new AfterTranslateInfoBar(owner, this); - return new TranslateMessageInfoBar(owner, this); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + if (delegate->infobar_type() == BEFORE_TRANSLATE) + return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); + if (delegate->infobar_type() == AFTER_TRANSLATE) + return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); + return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); } // TranslateInfoBarBase ------------------------------------------------------- -TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), +TranslateInfoBarBase::TranslateInfoBarBase( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), background_error_percent_(0) { - DCHECK(delegate); + TranslateInfoBarDelegate* translate_delegate = GetDelegate(); + DCHECK(translate_delegate); TranslateInfoBarDelegate::BackgroundAnimationType animation = - delegate->background_animation_type(); + translate_delegate->background_animation_type(); if (animation != TranslateInfoBarDelegate::NONE) { background_color_animation_.reset(new gfx::SlideAnimation(this)); background_color_animation_->SetTweenType(gfx::Tween::LINEAR); @@ -52,7 +55,7 @@ TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, background_color_animation_->Hide(); } } else { - background_error_percent_ = delegate->is_error() ? 1 : 0; + background_error_percent_ = translate_delegate->is_error() ? 1 : 0; } } @@ -71,6 +74,22 @@ void TranslateInfoBarBase::AnimationProgressed( } } +void TranslateInfoBarBase::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); + + if (!ShowOptionsMenuButton()) + return; + + // The options button sits outside the translate_box so that it can be end + // packed in hbox(). + GtkWidget* options_menu_button = CreateMenuButton( + l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); + signals()->Connect(options_menu_button, "clicked", + G_CALLBACK(&OnOptionsClickedThunk), this); + gtk_widget_show_all(options_menu_button); + gtk_util::CenterWidgetInHBox(hbox(), options_menu_button, true, 0); +} + void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) { if (background_error_percent_ <= 0) { @@ -121,22 +140,6 @@ void TranslateInfoBarBase::GetBottomColor(InfoBarDelegate::Type type, } } -void TranslateInfoBarBase::InitWidgets() { - InfoBarGtk::InitWidgets(); - - if (!ShowOptionsMenuButton()) - return; - - // The options button sits outside the translate_box so that it can be end - // packed in hbox(). - GtkWidget* options_menu_button = CreateMenuButton( - l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); - signals()->Connect(options_menu_button, "clicked", - G_CALLBACK(&OnOptionsClickedThunk), this); - gtk_widget_show_all(options_menu_button); - gtk_util::CenterWidgetInHBox(hbox(), options_menu_button, true, 0); -} - bool TranslateInfoBarBase::ShowOptionsMenuButton() const { return false; } diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h index 863c7eb..6892e66 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h @@ -15,17 +15,16 @@ class TranslateInfoBarDelegate; // use. class TranslateInfoBarBase : public InfoBarGtk { protected: - TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBarBase(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBarBase(); // InfoBarGtk: virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual void GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; virtual void GetBottomColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; - virtual void InitWidgets() OVERRIDE; // Sub-classes that want to have the options menu button showing should // override and return true. diff --git a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc index 08f7897..e7938cb 100644 --- a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc @@ -11,16 +11,15 @@ #include "ui/base/gtk/gtk_signal_registrar.h" TranslateMessageInfoBar::TranslateMessageInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate) { + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()) { } TranslateMessageInfoBar::~TranslateMessageInfoBar() { } -void TranslateMessageInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void TranslateMessageInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); GtkWidget* new_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); gtk_util::CenterWidgetInHBox(hbox(), new_hbox, false, 0); diff --git a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h index adb38ec..bd08697 100644 --- a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h @@ -12,14 +12,14 @@ class TranslateInfoBarDelegate; class TranslateMessageInfoBar : public TranslateInfoBarBase { public: - TranslateMessageInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateMessageInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~TranslateMessageInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; CHROMEGTK_CALLBACK_0(TranslateMessageInfoBar, void, OnButtonPressed); diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc index 0269aea..c4da8bd 100644 --- a/chrome/browser/ui/hung_plugin_tab_helper.cc +++ b/chrome/browser/ui/hung_plugin_tab_helper.cc @@ -130,16 +130,15 @@ void KillPluginOnIOThread(int child_id) { class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a hung plugin infobar delegate and adds it to |infobar_service|. - // Returns the delegate if it was successfully added. - static HungPluginInfoBarDelegate* Create(InfoBarService* infobar_service, - HungPluginTabHelper* helper, - int plugin_child_id, - const string16& plugin_name); + // Creates a hung plugin infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service, + HungPluginTabHelper* helper, + int plugin_child_id, + const string16& plugin_name); private: HungPluginInfoBarDelegate(HungPluginTabHelper* helper, - InfoBarService* infobar_service, int plugin_child_id, const string16& plugin_name); virtual ~HungPluginInfoBarDelegate(); @@ -159,22 +158,20 @@ class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -HungPluginInfoBarDelegate* HungPluginInfoBarDelegate::Create( - InfoBarService* infobar_service, - HungPluginTabHelper* helper, - int plugin_child_id, - const string16& plugin_name) { - return static_cast<HungPluginInfoBarDelegate*>(infobar_service->AddInfoBar( - scoped_ptr<InfoBarDelegate>(new HungPluginInfoBarDelegate( - helper, infobar_service, plugin_child_id, plugin_name)))); +InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, + HungPluginTabHelper* helper, + int plugin_child_id, + const string16& plugin_name) { + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( + helper, plugin_child_id, plugin_name)))); } HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( HungPluginTabHelper* helper, - InfoBarService* infobar_service, int plugin_child_id, const string16& plugin_name) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), helper_(helper), plugin_child_id_(plugin_child_id), message_(l10n_util::GetStringFUTF16( @@ -223,7 +220,7 @@ struct HungPluginTabHelper::PluginState { string16 name; // Possibly-null if we're not showing an infobar right now. - InfoBarDelegate* infobar; + InfoBar* infobar; // Time to delay before re-showing the infobar for a hung plugin. This is // increased each time the user cancels it. @@ -327,14 +324,7 @@ void HungPluginTabHelper::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); - // Note: do not dereference. The InfoBarContainer will delete the object when - // it gets this notification, we only remove our tracking info, if we have - // any. - // - // TODO(pkasting): This comment will be incorrect and should be removed once - // InfoBars own their delegates. - InfoBarDelegate* infobar = - content::Details<InfoBar::RemovedDetails>(details)->first; + InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; for (PluginStateMap::iterator i = hung_plugins_.begin(); i != hung_plugins_.end(); ++i) { PluginState* state = i->second.get(); diff --git a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc index 47bd530..d1b5bc4 100644 --- a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc +++ b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc @@ -9,6 +9,7 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/shortcuts_backend.h" #include "chrome/browser/history/shortcuts_backend_factory.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/web_contents.h" @@ -17,6 +18,9 @@ #include "ui/base/l10n/l10n_util.h" +AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { +} + // static void AlternateNavInfoBarDelegate::Create( content::WebContents* web_contents, @@ -25,20 +29,18 @@ void AlternateNavInfoBarDelegate::Create( const GURL& search_url) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AlternateNavInfoBarDelegate( - infobar_service, + infobar_service->AddInfoBar(AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate>(new AlternateNavInfoBarDelegate( Profile::FromBrowserContext(web_contents->GetBrowserContext()), text, - match, search_url))); + match, search_url)))); } AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( - InfoBarService* owner, Profile* profile, const string16& text, const AutocompleteMatch& match, const GURL& search_url) - : InfoBarDelegate(owner), + : InfoBarDelegate(), profile_(profile), text_(text), match_(match), @@ -47,8 +49,8 @@ AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( DCHECK(search_url_.is_valid()); } -AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { -} +// AlternateNavInfoBarDelegate::CreateInfoBar() is implemented in +// platform-specific files. string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( size_t* link_offset) const { diff --git a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h index 4eaba50..7c92901 100644 --- a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h +++ b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h @@ -5,15 +5,16 @@ #ifndef CHROME_BROWSER_UI_OMNIBOX_ALTERNATE_NAV_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_UI_OMNIBOX_ALTERNATE_NAV_INFOBAR_DELEGATE_H_ -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/infobars/infobar_delegate.h" class AlternateNavInfoBarDelegate : public InfoBarDelegate { public: - // Creates an alternate nav infobar delegate and adds it to the infobar - // service for |web_contents|. + virtual ~AlternateNavInfoBarDelegate(); + + // Creates an alternate nav infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. static void Create(content::WebContents* web_contents, const string16& text, const AutocompleteMatch& match, @@ -24,15 +25,16 @@ class AlternateNavInfoBarDelegate : public InfoBarDelegate { bool LinkClicked(WindowOpenDisposition disposition); private: - AlternateNavInfoBarDelegate(InfoBarService* owner, - Profile* profile, + AlternateNavInfoBarDelegate(Profile* profile, const string16& text, const AutocompleteMatch& match, const GURL& search_url); - virtual ~AlternateNavInfoBarDelegate(); + + // Returns an alternate nav infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; virtual int GetIconID() const OVERRIDE; virtual Type GetInfoBarType() const OVERRIDE; diff --git a/chrome/browser/ui/startup/autolaunch_prompt_win.cc b/chrome/browser/ui/startup/autolaunch_prompt_win.cc index 4471fca..c10eab7 100644 --- a/chrome/browser/ui/startup/autolaunch_prompt_win.cc +++ b/chrome/browser/ui/startup/autolaunch_prompt_win.cc @@ -11,6 +11,7 @@ #include "chrome/browser/auto_launch_trial.h" #include "chrome/browser/first_run/first_run.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/ui/browser.h" @@ -36,12 +37,12 @@ namespace { // The delegate for the infobar shown when Chrome is auto-launched. class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an autolaunch infobar delegate and adds it to |infobar_service|. + // Creates an autolaunch infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, Profile* profile); private: - AutolaunchInfoBarDelegate(InfoBarService* infobar_service, - Profile* profile); + explicit AutolaunchInfoBarDelegate(Profile* profile); virtual ~AutolaunchInfoBarDelegate(); void set_should_expire() { should_expire_ = true; } @@ -70,14 +71,14 @@ class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { // static void AutolaunchInfoBarDelegate::Create(InfoBarService* infobar_service, Profile* profile) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AutolaunchInfoBarDelegate(infobar_service, profile))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new AutolaunchInfoBarDelegate(profile)))); } AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( - InfoBarService* infobar_service, Profile* profile) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), profile_(profile), should_expire_(false), weak_factory_(this) { diff --git a/chrome/browser/ui/startup/default_browser_prompt.cc b/chrome/browser/ui/startup/default_browser_prompt.cc index 786dcad..e24fe2c 100644 --- a/chrome/browser/ui/startup/default_browser_prompt.cc +++ b/chrome/browser/ui/startup/default_browser_prompt.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/first_run/first_run.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/shell_integration.h" @@ -58,15 +59,14 @@ void SetChromeAsDefaultBrowser(bool interactive_flow, PrefService* prefs) { // The delegate for the infobar shown when Chrome is not the default browser. class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a default browser infobar delegate and adds it to + // Creates a default browser infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required); private: - DefaultBrowserInfoBarDelegate(InfoBarService* infobar_service, - PrefService* prefs, + DefaultBrowserInfoBarDelegate(PrefService* prefs, bool interactive_flow_required); virtual ~DefaultBrowserInfoBarDelegate(); @@ -105,16 +105,15 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new DefaultBrowserInfoBarDelegate(infobar_service, prefs, - interactive_flow_required))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new DefaultBrowserInfoBarDelegate( + prefs, interactive_flow_required)))); } DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( - InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), prefs_(prefs), action_taken_(false), should_expire_(false), diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc index 42f1d55..7db67d4 100644 --- a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "google_apis/google_api_keys.h" @@ -17,13 +18,12 @@ void GoogleApiKeysInfoBarDelegate::Create(InfoBarService* infobar_service) { if (google_apis::HasKeysConfigured()) return; - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new GoogleApiKeysInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new GoogleApiKeysInfoBarDelegate()))); } -GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate() + : ConfirmInfoBarDelegate() { } GoogleApiKeysInfoBarDelegate::~GoogleApiKeysInfoBarDelegate() { diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h index dad3bf5..c949761 100644 --- a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h @@ -16,11 +16,11 @@ class InfoBarService; class GoogleApiKeysInfoBarDelegate : public ConfirmInfoBarDelegate { public: // If Google API keys are missing, creates a missing Google API Keys infobar - // delegate and adds it to |infobar_service|. + // and delegate and adds the infobar to |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit GoogleApiKeysInfoBarDelegate(InfoBarService* infobar_service); + GoogleApiKeysInfoBarDelegate(); virtual ~GoogleApiKeysInfoBarDelegate(); virtual string16 GetMessageText() const OVERRIDE; diff --git a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc index 359e755..b2bbeaa 100644 --- a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc +++ b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/startup/obsolete_os_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/chromium_strings.h" @@ -35,13 +36,12 @@ void ObsoleteOSInfoBarDelegate::Create(InfoBarService* infobar_service) { return; #endif - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ObsoleteOSInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ObsoleteOSInfoBarDelegate()))); } -ObsoleteOSInfoBarDelegate::ObsoleteOSInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +ObsoleteOSInfoBarDelegate::ObsoleteOSInfoBarDelegate() + : ConfirmInfoBarDelegate() { } ObsoleteOSInfoBarDelegate::~ObsoleteOSInfoBarDelegate() { diff --git a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h index 058ec48..3e0eec5 100644 --- a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h +++ b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h @@ -16,11 +16,12 @@ class InfoBarService; // a "Learn More" link. class ObsoleteOSInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an obsolete OS infobar delegate and adds it to |infobar_service|. + // Creates an obsolete OS infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit ObsoleteOSInfoBarDelegate(InfoBarService* infobar_service); + ObsoleteOSInfoBarDelegate(); virtual ~ObsoleteOSInfoBarDelegate(); virtual string16 GetMessageText() const OVERRIDE; diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc b/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc index d1d28cd..e49b81d 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/search.h" @@ -14,7 +13,6 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/url_constants.h" #include "content/public/browser/dom_storage_context.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/storage_partition.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -34,31 +32,21 @@ void SessionCrashedInfoBarDelegate::Create(Browser* browser) { if (profile->IsOffTheRecord() || !web_contents) return; - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new SessionCrashedInfoBarDelegate(infobar_service, profile))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new SessionCrashedInfoBarDelegate(profile)))); } -SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( - InfoBarService* infobar_service, - Profile* profile) - : ConfirmInfoBarDelegate(infobar_service), +SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(Profile* profile) + : ConfirmInfoBarDelegate(), accepted_(false), - removed_notification_received_(false), profile_(profile) { - // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed - // any more. Then we can rely on delegates getting destroyed, and we can - // initiate the session storage scavenging only in the destructor. (Currently, - // info bars are leaked if they get closed while they're in background tabs.) - registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::NotificationService::AllSources()); } SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { // If the info bar wasn't accepted, it was either dismissed or expired. In // that case, session restore won't happen. - if (!accepted_ && !removed_notification_received_) { + if (!accepted_) { content::BrowserContext::GetDefaultStoragePartition(profile_)-> GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); } @@ -84,8 +72,7 @@ string16 SessionCrashedInfoBarDelegate::GetButtonLabel( bool SessionCrashedInfoBarDelegate::Accept() { uint32 behavior = 0; - Browser* browser = - chrome::FindBrowserWithWebContents(owner()->web_contents()); + Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); if (browser->tab_strip_model()->count() == 1) { const content::WebContents* active_tab = browser->tab_strip_model()->GetWebContentsAt(0); @@ -102,17 +89,3 @@ bool SessionCrashedInfoBarDelegate::Accept() { accepted_ = true; return true; } - -void SessionCrashedInfoBarDelegate::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); - if (content::Details<InfoBar::RemovedDetails>(details)->first != this) - return; - if (!accepted_) { - content::BrowserContext::GetDefaultStoragePartition(profile_)-> - GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); - removed_notification_received_ = true; - } -} diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate.h b/chrome/browser/ui/startup/session_crashed_infobar_delegate.h index e842d5d..260a320 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate.h +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate.h @@ -5,32 +5,20 @@ #ifndef CHROME_BROWSER_UI_STARTUP_SESSION_CRASHED_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_UI_STARTUP_SESSION_CRASHED_INFOBAR_DELEGATE_H_ -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" class Browser; class Profile; // A delegate for the InfoBar shown when the previous session has crashed. -class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, - public content::NotificationObserver { +class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // If |browser| is not incognito, creates a session crashed infobar delegate - // and adds it to the InfoBarService for |browser|. + // If |browser| is not incognito, creates a session crashed infobar and + // delegate and adds the infobar to the InfoBarService for |browser|. static void Create(Browser* browser); private: - FRIEND_TEST_ALL_PREFIXES(SessionCrashedInfoBarDelegateUnitTest, - DetachingTabWithCrashedInfoBar); -#if defined(UNIT_TEST) - friend struct base::DefaultDeleter<SessionCrashedInfoBarDelegate>; -#endif - - SessionCrashedInfoBarDelegate(InfoBarService* infobar_service, - Profile* profile); + explicit SessionCrashedInfoBarDelegate(Profile* profile); virtual ~SessionCrashedInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -40,14 +28,7 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; virtual bool Accept() OVERRIDE; - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - content::NotificationRegistrar registrar_; bool accepted_; - bool removed_notification_received_; Profile* profile_; DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc b/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc index 473928d..d43d425 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc @@ -7,6 +7,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/testing_pref_service.h" #include "base/run_loop.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -61,8 +62,8 @@ TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); EXPECT_EQ(1U, infobar_service->infobar_count()); - scoped_ptr<ConfirmInfoBarDelegate> infobar(InfoBarService::FromWebContents( - web_contents)->infobar_at(0)->AsConfirmInfoBarDelegate()); + ConfirmInfoBarDelegate* infobar = + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar); // Open another browser. diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index 7620e15b..93c0bf4 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -16,9 +16,8 @@ #include "ui/views/controls/menu/menu_item_view.h" AfterTranslateInfoBar::AfterTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_1_(NULL), label_2_(NULL), label_3_(NULL), @@ -28,7 +27,8 @@ AfterTranslateInfoBar::AfterTranslateInfoBar( options_menu_button_(NULL), swapped_language_buttons_(false) { autodetermined_source_language_ = - delegate->original_language_index() == TranslateInfoBarDelegate::kNoIndex; + GetDelegate()->original_language_index() == + TranslateInfoBarDelegate::kNoIndex; } AfterTranslateInfoBar::~AfterTranslateInfoBar() { diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.h b/chrome/browser/ui/views/infobars/after_translate_infobar.h index 29e6acb..57fad6d 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.h +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.h @@ -19,8 +19,7 @@ class MenuButton; class AfterTranslateInfoBar : public TranslateInfoBarBase, public views::MenuButtonListener { public: - AfterTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit AfterTranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~AfterTranslateInfoBar(); diff --git a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc index 87ad887..700be5c 100644 --- a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc +++ b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc @@ -13,17 +13,18 @@ // AlternateNavInfoBarDelegate ------------------------------------------------- -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new AlternateNavInfoBarView(owner, this); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new AlternateNavInfoBarView(delegate.Pass())); } // AlternateNavInfoBarView ----------------------------------------------------- AlternateNavInfoBarView::AlternateNavInfoBarView( - InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), + scoped_ptr<AlternateNavInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), label_1_(NULL), link_(NULL), label_2_(NULL) { diff --git a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h index aba7c71..0d26a30 100644 --- a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h +++ b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h @@ -5,8 +5,7 @@ #ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_ -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/views/controls/link_listener.h" @@ -16,8 +15,8 @@ class AlternateNavInfoBarDelegate; class AlternateNavInfoBarView : public InfoBarView, public views::LinkListener { public: - AlternateNavInfoBarView(InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate); + explicit AlternateNavInfoBarView( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); private: virtual ~AlternateNavInfoBarView(); diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index bc865b9..4820b41 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -16,9 +16,8 @@ #include "ui/views/controls/menu/menu_item_view.h" BeforeTranslateInfoBar::BeforeTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_1_(NULL), label_2_(NULL), language_menu_button_(NULL), diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h index 3f368f2..855da51 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.h +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h @@ -19,8 +19,8 @@ class MenuButton; class BeforeTranslateInfoBar : public TranslateInfoBarBase, public views::MenuButtonListener { public: - BeforeTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit BeforeTranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~BeforeTranslateInfoBar(); diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc index 82da528..34cd4f8 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -14,16 +14,17 @@ // ConfirmInfoBarDelegate ----------------------------------------------------- -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBar(owner, this); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBar(delegate.Pass())); } // ConfirmInfoBar ------------------------------------------------------------- -ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), +ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), label_(NULL), ok_button_(NULL), cancel_button_(NULL), diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h index ccde806..fd257d1 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.h +++ b/chrome/browser/ui/views/infobars/confirm_infobar.h @@ -22,7 +22,7 @@ class Label; class ConfirmInfoBar : public InfoBarView, public views::LinkListener { public: - ConfirmInfoBar(InfoBarService* owner, ConfirmInfoBarDelegate* delegate); + explicit ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate); private: virtual ~ConfirmInfoBar(); diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index 937cc9e..aa9393e 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -29,8 +29,11 @@ // ExtensionInfoBarDelegate ---------------------------------------------------- -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ExtensionInfoBar(owner, this, browser_); +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + Browser* browser = delegate->browser_; + return scoped_ptr<InfoBar>(new ExtensionInfoBar(delegate.Pass(), browser)); } @@ -78,25 +81,20 @@ class MenuImageSource: public gfx::CanvasImageSource { } // namespace -ExtensionInfoBar::ExtensionInfoBar(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate, - Browser* browser) - : InfoBarView(owner, delegate), - delegate_(delegate), +ExtensionInfoBar::ExtensionInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate, + Browser* browser) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), browser_(browser), infobar_icon_(NULL), icon_as_menu_(NULL), icon_as_image_(NULL), weak_ptr_factory_(this) { - GetDelegate()->set_observer(this); - int height = GetDelegate()->height(); SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); } ExtensionInfoBar::~ExtensionInfoBar() { - if (GetDelegate()) - GetDelegate()->set_observer(NULL); } void ExtensionInfoBar::Layout() { @@ -166,10 +164,6 @@ int ExtensionInfoBar::ContentMinimumWidth() const { } -void ExtensionInfoBar::OnDelegateDeleted() { - delegate_ = NULL; -} - void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, const gfx::Point& point) { if (!owner()) @@ -215,5 +209,5 @@ void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { } ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { - return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; + return delegate()->AsExtensionInfoBarDelegate(); } diff --git a/chrome/browser/ui/views/infobars/extension_infobar.h b/chrome/browser/ui/views/infobars/extension_infobar.h index 459b9c3..953d390 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.h +++ b/chrome/browser/ui/views/infobars/extension_infobar.h @@ -6,11 +6,11 @@ #define CHROME_BROWSER_UI_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ #include "base/compiler_specific.h" -#include "chrome/browser/extensions/extension_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/views/controls/button/menu_button_listener.h" class Browser; +class ExtensionInfoBarDelegate; namespace views { class ImageView; @@ -18,11 +18,9 @@ class MenuButton; } class ExtensionInfoBar : public InfoBarView, - public ExtensionInfoBarDelegate::DelegateObserver, public views::MenuButtonListener { public: - ExtensionInfoBar(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate, + ExtensionInfoBar(scoped_ptr<ExtensionInfoBarDelegate> delegate, Browser* browser); private: @@ -34,9 +32,6 @@ class ExtensionInfoBar : public InfoBarView, const ViewHierarchyChangedDetails& details) OVERRIDE; virtual int ContentMinimumWidth() const OVERRIDE; - // ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE; - // views::MenuButtonListener: virtual void OnMenuButtonClicked(views::View* source, const gfx::Point& point) OVERRIDE; @@ -45,11 +40,6 @@ class ExtensionInfoBar : public InfoBarView, ExtensionInfoBarDelegate* GetDelegate(); - // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once - // InfoBars own their delegates (and thus we don't need the DelegateObserver - // functionality). For now, almost everyone should use GetDelegate() instead. - InfoBarDelegate* delegate_; - Browser* browser_; // The infobar icon used for the extension infobar. The icon can be either a diff --git a/chrome/browser/ui/views/infobars/infobar_container_view.cc b/chrome/browser/ui/views/infobars/infobar_container_view.cc index bcb9ca53..193330a 100644 --- a/chrome/browser/ui/views/infobars/infobar_container_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_container_view.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/views/infobars/infobar_container_view.h" -#include "base/message_loop/message_loop.h" #include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "grit/generated_resources.h" @@ -60,5 +59,4 @@ void InfoBarContainerView::PlatformSpecificAddInfoBar(InfoBar* infobar, void InfoBarContainerView::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { RemoveChildView(static_cast<InfoBarView*>(infobar)); - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index c89d2b3..105b037 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -54,8 +54,8 @@ const int InfoBarView::kButtonButtonSpacing = 10; const int InfoBarView::kEndOfLabelSpacing = 16; const int InfoBarView::kHorizontalPadding = 6; -InfoBarView::InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarView::InfoBarView(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), views::ExternalFocusTracker(this, NULL), icon_(NULL), close_button_(NULL) { @@ -376,11 +376,9 @@ void InfoBarView::PlatformSpecificOnHeightsRecalculated() { } void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) { - if (delegate()) { - state->name = l10n_util::GetStringUTF16( - (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? - IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); - } + state->name = l10n_util::GetStringUTF16( + (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? + IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); state->role = ui::AccessibilityTypes::ROLE_ALERT; } diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index 5797ec7..8914c17 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -35,7 +35,7 @@ class InfoBarView : public InfoBar, public views::ButtonListener, public views::ExternalFocusTracker { public: - InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarView(scoped_ptr<InfoBarDelegate> delegate); const SkPath& fill_path() const { return fill_path_; } const SkPath& stroke_path() const { return stroke_path_; } diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc index 896ac97..0c914e3 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" @@ -19,12 +20,14 @@ // TranslateInfoBarDelegate --------------------------------------------------- -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - if (infobar_type_ == BEFORE_TRANSLATE) - return new BeforeTranslateInfoBar(owner, this); - if (infobar_type_ == AFTER_TRANSLATE) - return new AfterTranslateInfoBar(owner, this); - return new TranslateMessageInfoBar(owner, this); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + if (delegate->infobar_type() == BEFORE_TRANSLATE) + return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); + if (delegate->infobar_type() == AFTER_TRANSLATE) + return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); + return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); } @@ -42,9 +45,9 @@ void TranslateInfoBarBase::UpdateLanguageButtonText(views::MenuButton* button, SchedulePaint(); } -TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), +TranslateInfoBarBase::TranslateInfoBarBase( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), error_background_(InfoBarDelegate::WARNING_TYPE) { } diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h index 971bf3f..2c7440f 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.h +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h @@ -24,8 +24,7 @@ class TranslateInfoBarBase : public InfoBarView { const string16& text); protected: - TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBarBase(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBarBase(); // InfoBarView: diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index b54e04e..d84a389 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -9,9 +9,8 @@ #include "ui/views/controls/label.h" TranslateMessageInfoBar::TranslateMessageInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_(NULL), button_(NULL) { } diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.h b/chrome/browser/ui/views/infobars/translate_message_infobar.h index 0452b95..1eda310 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.h +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.h @@ -9,8 +9,8 @@ class TranslateMessageInfoBar : public TranslateInfoBarBase { public: - TranslateMessageInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateMessageInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~TranslateMessageInfoBar(); diff --git a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc index f51f741..c995827 100644 --- a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc +++ b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -15,13 +16,13 @@ // static void WebsiteSettingsInfoBarDelegate::Create(InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new WebsiteSettingsInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new WebsiteSettingsInfoBarDelegate()))); } -WebsiteSettingsInfoBarDelegate::WebsiteSettingsInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +WebsiteSettingsInfoBarDelegate::WebsiteSettingsInfoBarDelegate() + : ConfirmInfoBarDelegate() { } WebsiteSettingsInfoBarDelegate::~WebsiteSettingsInfoBarDelegate() { diff --git a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h index 19fffa0..be68757 100644 --- a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h +++ b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h @@ -16,12 +16,12 @@ class InfoBarService; // the reload right from the infobar. class WebsiteSettingsInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a website settings infobar delegate and adds it to + // Creates a website settings infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit WebsiteSettingsInfoBarDelegate(InfoBarService* infobar_service); + WebsiteSettingsInfoBarDelegate(); virtual ~WebsiteSettingsInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/ui/website_settings/website_settings_unittest.cc b/chrome/browser/ui/website_settings/website_settings_unittest.cc index ab5cba0..20519ab 100644 --- a/chrome/browser/ui/website_settings/website_settings_unittest.cc +++ b/chrome/browser/ui/website_settings/website_settings_unittest.cc @@ -12,7 +12,7 @@ #include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/ui/website_settings/website_settings_ui.h" #include "chrome/common/content_settings.h" @@ -391,9 +391,5 @@ TEST_F(WebsiteSettingsTest, ShowInfoBar) { website_settings()->OnUIClosing(); ASSERT_EQ(1u, infobar_service()->infobar_count()); - // Removing an |InfoBarDelegate| from the |InfoBarService| does not delete - // it. Hence the |delegate| must be cleaned up after it was removed from the - // |infobar_service|. - scoped_ptr<InfoBarDelegate> delegate(infobar_service()->infobar_at(0)); - infobar_service()->RemoveInfoBar(delegate.get()); + infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); } |