Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2968)

Unified Diff: chrome/browser/infobars/infobar_tab_helper.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/infobars/infobar_tab_helper.cc
===================================================================
--- chrome/browser/infobars/infobar_tab_helper.cc (revision 175396)
+++ chrome/browser/infobars/infobar_tab_helper.cc (working copy)
@@ -60,24 +60,23 @@
infobars_enabled_ = enabled;
}
-bool InfoBarTabHelper::AddInfoBar(InfoBarDelegate* delegate) {
- if (!infobars_enabled_) {
- delegate->InfoBarClosed();
- return false;
- }
+InfoBarDelegate* InfoBarTabHelper::AddInfoBar(
+ scoped_ptr<InfoBarDelegate> delegate) {
+ if (!infobars_enabled_)
+ return NULL;
for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end();
++i) {
- if ((*i)->EqualsDelegate(delegate)) {
- DCHECK_NE(*i, delegate);
- delegate->InfoBarClosed();
- return false;
+ if ((*i)->EqualsDelegate(delegate.get())) {
+ DCHECK_NE(*i, delegate.get());
+ return NULL;
}
}
// TODO(pkasting): Consider removing InfoBarTabHelper arg from delegate
// constructors and instead using a setter from here.
- infobars_.push_back(delegate);
+ InfoBarDelegate* delegate_ptr = delegate.release();
+ infobars_.push_back(delegate_ptr);
// Add ourselves as an observer for navigations the first time a delegate is
// added. We use this notification to expire InfoBars that need to expire on
// page transitions.
@@ -91,35 +90,37 @@
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
content::Source<InfoBarService>(this),
- content::Details<InfoBarAddedDetails>(delegate));
- return true;
+ content::Details<InfoBarAddedDetails>(delegate_ptr));
+ return delegate_ptr;
}
void InfoBarTabHelper::RemoveInfoBar(InfoBarDelegate* delegate) {
RemoveInfoBarInternal(delegate, true);
}
-bool InfoBarTabHelper::ReplaceInfoBar(InfoBarDelegate* old_delegate,
- InfoBarDelegate* new_delegate) {
+InfoBarDelegate* InfoBarTabHelper::ReplaceInfoBar(
+ InfoBarDelegate* old_delegate,
+ scoped_ptr<InfoBarDelegate> new_delegate) {
if (!infobars_enabled_)
- return AddInfoBar(new_delegate); // Deletes the delegate.
+ return AddInfoBar(new_delegate.Pass()); // Deletes the delegate.
InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(),
old_delegate));
DCHECK(i != infobars_.end());
- i = infobars_.insert(i, new_delegate) + 1;
+ InfoBarDelegate* new_delegate_ptr = new_delegate.release();
+ i = infobars_.insert(i, new_delegate_ptr);
+ InfoBarReplacedDetails replaced_details(old_delegate, new_delegate_ptr);
// Remove the old delegate before notifying, so that if any observers call
// back to AddInfoBar() or similar, we don't dupe-check against this delegate.
- infobars_.erase(i);
+ infobars_.erase(++i);
old_delegate->clear_owner();
- InfoBarReplacedDetails replaced_details(old_delegate, new_delegate);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
content::Source<InfoBarService>(this),
content::Details<InfoBarReplacedDetails>(&replaced_details));
- return true;
+ return new_delegate_ptr;
}
size_t InfoBarTabHelper::GetInfoBarCount() const {
@@ -169,30 +170,13 @@
}
void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() {
- // At most one infobar and do not supersede the stronger running content bar.
- for (size_t i = 0; i < infobars_.size(); ++i) {
- if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate())
- return;
- }
- AddInfoBar(new InsecureContentInfoBarDelegate(this,
- InsecureContentInfoBarDelegate::DISPLAY));
+ InsecureContentInfoBarDelegate::Create(
+ this, InsecureContentInfoBarDelegate::DISPLAY);
}
void InfoBarTabHelper::OnDidBlockRunningInsecureContent() {
- // At most one infobar superseding any weaker displaying content bar.
- for (size_t i = 0; i < infobars_.size(); ++i) {
- InsecureContentInfoBarDelegate* delegate =
- GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate();
- if (delegate) {
- if (delegate->type() != InsecureContentInfoBarDelegate::RUN) {
- ReplaceInfoBar(delegate, new InsecureContentInfoBarDelegate(
- this, InsecureContentInfoBarDelegate::RUN));
- }
- return;
- }
- }
- AddInfoBar(new InsecureContentInfoBarDelegate(this,
- InsecureContentInfoBarDelegate::RUN));
+ InsecureContentInfoBarDelegate::Create(this,
+ InsecureContentInfoBarDelegate::RUN);
}
void InfoBarTabHelper::RenderViewGone(base::TerminationStatus status) {
« no previous file with comments | « chrome/browser/infobars/infobar_tab_helper.h ('k') | chrome/browser/infobars/insecure_content_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698