Index: chrome/browser/infobars/infobar_manager.cc |
diff --git a/chrome/browser/infobars/infobar_service.cc b/chrome/browser/infobars/infobar_manager.cc |
similarity index 42% |
copy from chrome/browser/infobars/infobar_service.cc |
copy to chrome/browser/infobars/infobar_manager.cc |
index b3bcaa09d2b633c57c52ee890f22547f0f04f56a..859d59d954126c3e7386ec18fe97d6f3461bf730 100644 |
--- a/chrome/browser/infobars/infobar_service.cc |
+++ b/chrome/browser/infobars/infobar_manager.cc |
@@ -2,23 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/infobars/infobar_manager.h" |
#include "base/command_line.h" |
-#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/infobars/infobar.h" |
#include "chrome/browser/infobars/infobar_delegate.h" |
-#include "chrome/browser/infobars/insecure_content_infobar_delegate.h" |
#include "chrome/common/chrome_switches.h" |
-#include "chrome/common/render_messages.h" |
-#include "content/public/browser/navigation_controller.h" |
-#include "content/public/browser/notification_service.h" |
-#include "content/public/browser/web_contents.h" |
+InfoBarManager::InfoBarManager() : infobars_enabled_(true) { |
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars)) |
+ infobars_enabled_ = false; |
+} |
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); |
+InfoBarManager::~InfoBarManager() { |
+ // Destroy all remaining InfoBars. It's important to not animate here so that |
+ // we guarantee that we'll delete all delegates before we do anything else. |
+ RemoveAllInfoBars(false); |
+} |
-InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) { |
+InfoBar* InfoBarManager::AddInfoBar(scoped_ptr<InfoBar> infobar, int entry_id) { |
DCHECK(infobar); |
if (!infobars_enabled_) |
return NULL; |
@@ -33,100 +35,64 @@ InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) { |
InfoBar* infobar_ptr = infobar.release(); |
infobars_.push_back(infobar_ptr); |
+ infobar_ptr->StoreActiveEntryUniqueID(entry_id); |
infobar_ptr->SetOwner(this); |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
- content::Source<InfoBarService>(this), |
- content::Details<InfoBar::AddedDetails>(infobar_ptr)); |
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar_ptr)); |
+ |
return infobar_ptr; |
} |
-void InfoBarService::RemoveInfoBar(InfoBar* infobar) { |
+void InfoBarManager::RemoveInfoBar(InfoBar* infobar) { |
RemoveInfoBarInternal(infobar, true); |
} |
-InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar, |
- scoped_ptr<InfoBar> new_infobar) { |
+InfoBar* InfoBarManager::ReplaceInfoBar(InfoBar* old_infobar, |
+ scoped_ptr<InfoBar> new_infobar, |
+ int entry_id) { |
DCHECK(old_infobar); |
if (!infobars_enabled_) |
- return AddInfoBar(new_infobar.Pass()); // Deletes the infobar. |
+ return AddInfoBar(new_infobar.Pass(), entry_id); // Deletes the infobar. |
DCHECK(new_infobar); |
- InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), |
- old_infobar)); |
+ InfoBars::iterator i( |
+ std::find(infobars_.begin(), infobars_.end(), old_infobar)); |
DCHECK(i != infobars_.end()); |
InfoBar* new_infobar_ptr = new_infobar.release(); |
i = infobars_.insert(i, new_infobar_ptr); |
new_infobar_ptr->SetOwner(this); |
- InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar_ptr); |
// Remove the old infobar before notifying, so that if any observers call back |
// to AddInfoBar() or similar, we don't dupe-check against this infobar. |
infobars_.erase(++i); |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
- content::Source<InfoBarService>(this), |
- content::Details<InfoBar::ReplacedDetails>(&replaced_details)); |
+ FOR_EACH_OBSERVER(Observer, |
+ observer_list_, |
+ OnInfoBarReplaced(old_infobar, new_infobar_ptr)); |
old_infobar->CloseSoon(); |
return new_infobar_ptr; |
} |
-InfoBarService::InfoBarService(content::WebContents* web_contents) |
- : content::WebContentsObserver(web_contents), |
- infobars_enabled_(true) { |
- DCHECK(web_contents); |
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars)) |
- infobars_enabled_ = false; |
-} |
- |
-InfoBarService::~InfoBarService() { |
- // Destroy all remaining InfoBars. It's important to not animate here so that |
- // we guarantee that we'll delete all delegates before we do anything else. |
- RemoveAllInfoBars(false); |
-} |
- |
-void InfoBarService::RenderProcessGone(base::TerminationStatus status) { |
- RemoveAllInfoBars(true); |
+void InfoBarManager::CleanUp() { |
+ for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) |
+ (*i)->delegate()->CleanUp(); |
} |
-void InfoBarService::NavigationEntryCommitted( |
- const content::LoadCommittedDetails& load_details) { |
+void InfoBarManager::OnNavigation( |
+ const InfoBarDelegate::NavigationDetails& details) { |
// NOTE: It is not safe to change the following code to count upwards or |
// use iterators, as the RemoveInfoBar() call synchronously modifies our |
// delegate list. |
for (size_t i = infobars_.size(); i > 0; --i) { |
InfoBar* infobar = infobars_[i - 1]; |
- if (infobar->delegate()->ShouldExpire(load_details)) |
+ if (infobar->delegate()->ShouldExpire(details)) |
RemoveInfoBar(infobar); |
} |
} |
-void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { |
- // The WebContents is going away; be aggressively paranoid and delete |
- // ourselves lest other parts of the system attempt to add infobars or use |
- // us otherwise during the destruction. |
- web_contents->RemoveUserData(UserDataKey()); |
- // That was the equivalent of "delete this". This object is now destroyed; |
- // returning from this function is the only safe thing to do. |
-} |
- |
-bool InfoBarService::OnMessageReceived(const IPC::Message& message) { |
- bool handled = true; |
- IPC_BEGIN_MESSAGE_MAP(InfoBarService, message) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, |
- OnDidBlockDisplayingInsecureContent) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, |
- OnDidBlockRunningInsecureContent) |
- IPC_MESSAGE_UNHANDLED(handled = false) |
- IPC_END_MESSAGE_MAP() |
- return handled; |
-} |
- |
-void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { |
+void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { |
DCHECK(infobar); |
if (!infobars_enabled_) { |
DCHECK(infobars_.empty()); |
@@ -142,26 +108,12 @@ void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { |
// This notification must happen before the call to CloseSoon() below, since |
// observers may want to access |infobar| and that call can delete it. |
- InfoBar::RemovedDetails removed_details(infobar, animate); |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
- content::Source<InfoBarService>(this), |
- content::Details<InfoBar::RemovedDetails>(&removed_details)); |
- |
+ FOR_EACH_OBSERVER( |
+ Observer, observer_list_, OnInfoBarRemoved(infobar, animate)); |
Peter Kasting
2014/03/18 18:29:17
Tiny nit: I slightly prefer:
FOR_EACH_OBSERVER(
|
infobar->CloseSoon(); |
} |
-void InfoBarService::RemoveAllInfoBars(bool animate) { |
+void InfoBarManager::RemoveAllInfoBars(bool animate) { |
while (!infobars_.empty()) |
RemoveInfoBarInternal(infobars_.back(), animate); |
} |
- |
-void InfoBarService::OnDidBlockDisplayingInsecureContent() { |
- InsecureContentInfoBarDelegate::Create( |
- this, InsecureContentInfoBarDelegate::DISPLAY); |
-} |
- |
-void InfoBarService::OnDidBlockRunningInsecureContent() { |
- InsecureContentInfoBarDelegate::Create(this, |
- InsecureContentInfoBarDelegate::RUN); |
-} |