summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/info_bar_view.cc
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 22:10:17 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 22:10:17 +0000
commitecd9d87092866d04c00b5695ac56f0a026a6a2c8 (patch)
tree8af05cf2b9c524db3d40a7007ed5ec137a820d12 /chrome/browser/views/info_bar_view.cc
parent7ea9cbb1f61ea1b6990011d076bc09c05b9e72e8 (diff)
downloadchromium_src-ecd9d87092866d04c00b5695ac56f0a026a6a2c8.zip
chromium_src-ecd9d87092866d04c00b5695ac56f0a026a6a2c8.tar.gz
chromium_src-ecd9d87092866d04c00b5695ac56f0a026a6a2c8.tar.bz2
Make a step on refactoring navigation. The eventual plan is to have the NavigationController create and commit the new NavigationEntries (currently WebContents does a bunch of the details of this which is hard to understand and not easily testable).
This tries to consolidate the logic that I want to move to the NavigationController without actually moving it there yet. I removed all of the "PreCommit" functions in WebContents, since when the NavigationController does all of the committing, there won't be a phase where the NavigationEntry exists but isn't committed. Most of the logic could be moved to the PostCommit functions without any problem, which is an indication that the current design was busted anyway. I had to precompute some data and pass it to the *PostCommit function to work around some of the components that required old data. I had to change InfoBars around since it relied on having both the committed and uncommitted entries, but I think the new design is much better anyway. BUG=1343593,1343146 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1506 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/info_bar_view.cc')
-rw-r--r--chrome/browser/views/info_bar_view.cc96
1 files changed, 58 insertions, 38 deletions
diff --git a/chrome/browser/views/info_bar_view.cc b/chrome/browser/views/info_bar_view.cc
index c10dfa9..56c2ecc 100644
--- a/chrome/browser/views/info_bar_view.cc
+++ b/chrome/browser/views/info_bar_view.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/views/info_bar_view.h"
#include "base/logging.h"
+#include "chrome/browser/navigation_controller.h"
#include "chrome/browser/navigation_entry.h"
#include "chrome/browser/tab_contents_delegate.h"
#include "chrome/browser/web_contents.h"
@@ -31,9 +32,16 @@ static const int kSeparatorHeight = 1;
InfoBarView::InfoBarView(WebContents* web_contents)
: web_contents_(web_contents) {
Init();
+ NotificationService::current()->AddObserver(
+ this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(web_contents_->controller()));
}
-InfoBarView::~InfoBarView() {}
+InfoBarView::~InfoBarView() {
+ NotificationService::current()->RemoveObserver(
+ this, NOTIFY_NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(web_contents_->controller()));
+}
void InfoBarView::AppendInfoBarItem(ChromeViews::View* view, bool auto_expire) {
// AddChildView adds an entry to expire_map_ for view.
@@ -107,43 +115,6 @@ void InfoBarView::ChildAnimationEnded() {
web_contents_->ToolbarSizeChanged(false);
}
-void InfoBarView::DidNavigate(NavigationEntry* entry) {
- // Determine the views to remove first.
- std::vector<ChromeViews::View*> to_remove;
- NavigationEntry* pending_entry =
- web_contents_->controller()->GetPendingEntry();
- const int active_id = pending_entry ? pending_entry->unique_id() :
- entry->unique_id();
- for (std::map<View*,int>::iterator i = expire_map_.begin();
- i != expire_map_.end(); ++i) {
- if ((pending_entry &&
- pending_entry->transition_type() == PageTransition::RELOAD) ||
- i->second != active_id)
- to_remove.push_back(i->first);
- }
-
- if (to_remove.empty())
- return;
-
- // Remove the views.
- for (std::vector<ChromeViews::View*>::iterator i = to_remove.begin();
- i != to_remove.end(); ++i) {
- // RemoveChildView takes care of removing from expire_map for us.
- RemoveChildView(*i);
-
- // We own the child and we're removing it, need to delete it.
- delete *i;
- }
-
- if (GetChildViewCount() == 0) {
- // All our views have been removed, no need to stay visible.
- web_contents_->SetInfoBarVisible(false);
- } else if (web_contents_) {
- // This triggers a layout.
- web_contents_->ToolbarSizeChanged(false);
- }
-}
-
void InfoBarView::ViewHierarchyChanged(bool is_add, View *parent,
View *child) {
if (parent == this && child->GetParent() == this) {
@@ -220,3 +191,52 @@ void InfoBarView::PaintSeparator(ChromeCanvas* canvas,
GetWidth(),
kSeparatorHeight);
}
+
+void InfoBarView::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& in_details) {
+ // We should get only commit notifications from our controller.
+ DCHECK(type == NOTIFY_NAV_ENTRY_COMMITTED);
+ DCHECK(web_contents_->controller() ==
+ Source<NavigationController>(source).ptr());
+
+ NavigationController::LoadCommittedDetails& details =
+ *(Details<NavigationController::LoadCommittedDetails>(in_details).ptr());
+
+ // Only hide infobars when the user has done something that makes the main
+ // frame load. We don't want various automatic or subframe navigations making
+ // it disappear.
+ if (!details.is_user_initiated_main_frame_load())
+ return;
+
+ // Determine the views to remove first.
+ std::vector<ChromeViews::View*> to_remove;
+ for (std::map<View*,int>::iterator i = expire_map_.begin();
+ i != expire_map_.end(); ++i) {
+ if (PageTransition::StripQualifier(details.entry->transition_type()) ==
+ PageTransition::RELOAD ||
+ i->second != details.entry->unique_id())
+ to_remove.push_back(i->first);
+ }
+
+ if (to_remove.empty())
+ return;
+
+ // Remove the views.
+ for (std::vector<ChromeViews::View*>::iterator i = to_remove.begin();
+ i != to_remove.end(); ++i) {
+ // RemoveChildView takes care of removing from expire_map for us.
+ RemoveChildView(*i);
+
+ // We own the child and we're removing it, need to delete it.
+ delete *i;
+ }
+
+ if (GetChildViewCount() == 0) {
+ // All our views have been removed, no need to stay visible.
+ web_contents_->SetInfoBarVisible(false);
+ } else if (web_contents_) {
+ // This triggers a layout.
+ web_contents_->ToolbarSizeChanged(false);
+ }
+}