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

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

Issue 211273007: Split InfoBarService core code into InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + comments Created 6 years, 9 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
« no previous file with comments | « chrome/browser/infobars/infobar_manager.h ('k') | chrome/browser/infobars/infobar_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47%
copy from chrome/browser/infobars/infobar_service.cc
copy to chrome/browser/infobars/infobar_manager.cc
index a97d3a569d60dd7cafc750651f45132765b7451f..be57b98dee0b5cf43d844f467edba6b84786f67f 100644
--- a/chrome/browser/infobars/infobar_service.cc
+++ b/chrome/browser/infobars/infobar_manager.cc
@@ -1,24 +1,15 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// 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"
-
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService);
-
-InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) {
+InfoBar* InfoBarManager::AddInfoBar(scoped_ptr<InfoBar> infobar) {
DCHECK(infobar);
if (!infobars_enabled_)
return NULL;
@@ -36,20 +27,20 @@ InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) {
infobar_ptr->SetOwner(this);
FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar_ptr));
- // TODO(droger): Remove the notifications and use observers instead.
- // See http://crbug.com/354380
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
- content::Source<InfoBarService>(this),
- content::Details<InfoBar::AddedDetails>(infobar_ptr));
+
return infobar_ptr;
}
-void InfoBarService::RemoveInfoBar(InfoBar* infobar) {
+void InfoBarManager::RemoveInfoBar(InfoBar* infobar) {
RemoveInfoBarInternal(infobar, true);
}
-InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar,
+void InfoBarManager::RemoveAllInfoBars(bool animate) {
+ while (!infobars_.empty())
+ RemoveInfoBarInternal(infobars_.back(), animate);
+}
+
+InfoBar* InfoBarManager::ReplaceInfoBar(InfoBar* old_infobar,
scoped_ptr<InfoBar> new_infobar) {
DCHECK(old_infobar);
if (!infobars_enabled_)
@@ -63,7 +54,6 @@ InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar,
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.
@@ -72,45 +62,35 @@ InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar,
FOR_EACH_OBSERVER(Observer,
observer_list_,
OnInfoBarReplaced(old_infobar, new_infobar_ptr));
- // TODO(droger): Remove the notifications and use observers instead.
- // See http://crbug.com/354380
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
- content::Source<InfoBarService>(this),
- content::Details<InfoBar::ReplacedDetails>(&replaced_details));
old_infobar->CloseSoon();
return new_infobar_ptr;
}
-void InfoBarService::AddObserver(Observer* obs) {
+void InfoBarManager::AddObserver(Observer* obs) {
observer_list_.AddObserver(obs);
}
-void InfoBarService::RemoveObserver(Observer* obs) {
+void InfoBarManager::RemoveObserver(Observer* obs) {
observer_list_.RemoveObserver(obs);
}
-InfoBarService::InfoBarService(content::WebContents* web_contents)
- : content::WebContentsObserver(web_contents),
- infobars_enabled_(true) {
+InfoBarManager::InfoBarManager(content::WebContents* web_contents)
+ : infobars_enabled_(true),
+ web_contents_(web_contents) {
DCHECK(web_contents);
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars))
infobars_enabled_ = false;
}
-InfoBarService::~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);
- FOR_EACH_OBSERVER(Observer, observer_list_, OnServiceShuttingDown(this));
+ FOR_EACH_OBSERVER(Observer, observer_list_, OnManagerShuttingDown(this));
}
-void InfoBarService::RenderProcessGone(base::TerminationStatus status) {
- RemoveAllInfoBars(true);
-}
-
-void InfoBarService::NavigationEntryCommitted(
+void InfoBarManager::OnNavigation(
const content::LoadCommittedDetails& load_details) {
// NOTE: It is not safe to change the following code to count upwards or
// use iterators, as the RemoveInfoBar() call synchronously modifies our
@@ -122,28 +102,9 @@ void InfoBarService::NavigationEntryCommitted(
}
}
-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 InfoBarManager::OnWebContentsDestroyed() { web_contents_ = NULL; }
-void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
+void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
DCHECK(infobar);
if (!infobars_enabled_) {
DCHECK(infobars_.empty());
@@ -161,28 +122,6 @@ void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
// observers may want to access |infobar| and that call can delete it.
FOR_EACH_OBSERVER(Observer, observer_list_,
OnInfoBarRemoved(infobar, animate));
- // TODO(droger): Remove the notifications and use observers instead.
- // See http://crbug.com/354380
- 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));
infobar->CloseSoon();
}
-
-void InfoBarService::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);
-}
« no previous file with comments | « chrome/browser/infobars/infobar_manager.h ('k') | chrome/browser/infobars/infobar_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698