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

Side by Side Diff: chrome/browser/tab_contents/infobar_container.cc

Issue 7006010: Change InfoBar-related notifications to be sourced from a TabContentsWrapper, not a TabContents. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this. 5 #if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this.
6 6
7 #include "chrome/browser/tab_contents/infobar_container.h" 7 #include "chrome/browser/tab_contents/infobar_container.h"
8 8
9 #include "chrome/browser/tab_contents/infobar.h" 9 #include "chrome/browser/tab_contents/infobar.h"
10 #include "chrome/browser/tab_contents/infobar_delegate.h" 10 #include "chrome/browser/tab_contents/infobar_delegate.h"
(...skipping 25 matching lines...) Expand all
36 // animating, OnInfoBarStateChanged() won't get called; we'll manually 36 // animating, OnInfoBarStateChanged() won't get called; we'll manually
37 // trigger this once for the whole set of changes below. This also prevents 37 // trigger this once for the whole set of changes below. This also prevents
38 // InfoBar::MaybeDelete() from calling RemoveInfoBar() a second time if the 38 // InfoBar::MaybeDelete() from calling RemoveInfoBar() a second time if the
39 // infobar happens to be at zero height (dunno if this can actually happen). 39 // infobar happens to be at zero height (dunno if this can actually happen).
40 infobar->set_container(NULL); 40 infobar->set_container(NULL);
41 RemoveInfoBar(infobar); 41 RemoveInfoBar(infobar);
42 } 42 }
43 43
44 tab_contents_ = contents; 44 tab_contents_ = contents;
45 if (tab_contents_) { 45 if (tab_contents_) {
46 Source<TabContents> tc_source(tab_contents_->tab_contents()); 46 Source<TabContentsWrapper> tc_source(tab_contents_);
47 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 47 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
48 tc_source); 48 tc_source);
49 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 49 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
50 tc_source); 50 tc_source);
51 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, 51 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
52 tc_source); 52 tc_source);
53 53
54 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { 54 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
55 // As when we removed the infobars above, we prevent callbacks to 55 // As when we removed the infobars above, we prevent callbacks to
56 // OnInfoBarAnimated() for each infobar. 56 // OnInfoBarAnimated() for each infobar.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // and at worst disastrous to call that. 116 // and at worst disastrous to call that.
117 delegate_ = NULL; 117 delegate_ = NULL;
118 ChangeTabContents(NULL); 118 ChangeTabContents(NULL);
119 } 119 }
120 120
121 void InfoBarContainer::Observe(NotificationType type, 121 void InfoBarContainer::Observe(NotificationType type,
122 const NotificationSource& source, 122 const NotificationSource& source,
123 const NotificationDetails& details) { 123 const NotificationDetails& details) {
124 switch (type.value) { 124 switch (type.value) {
125 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: 125 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED:
126 AddInfoBar( 126 AddInfoBar(Details<InfoBar>(details).ptr(), true, WANT_CALLBACK);
127 Details<InfoBarDelegate>(details)->CreateInfoBar(tab_contents_), true,
128 WANT_CALLBACK);
129 break; 127 break;
130 128
131 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: 129 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: {
132 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); 130 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails;
133 break; 131 RemoveDetails* remove_details = Details<RemoveDetails>(details).ptr();
134 132 RemoveInfoBar(remove_details->first, remove_details->second);
135 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: {
136 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarPair;
137 InfoBarPair* infobar_pair = Details<InfoBarPair>(details).ptr();
138 RemoveInfoBar(infobar_pair->first, false);
139 AddInfoBar(infobar_pair->second->CreateInfoBar(tab_contents_), false,
140 WANT_CALLBACK);
141 break; 133 break;
142 } 134 }
143 135
136 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: {
137 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails;
138 ReplaceDetails* replace_details = Details<ReplaceDetails>(details).ptr();
139 RemoveInfoBar(replace_details->first, false);
140 AddInfoBar(replace_details->second, false, WANT_CALLBACK);
141 break;
142 }
143
144 default: 144 default:
145 NOTREACHED(); 145 NOTREACHED();
146 break; 146 break;
147 } 147 }
148 } 148 }
149 149
150 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, 150 void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate,
151 bool use_animation) { 151 bool use_animation) {
152 // Search for the infobar associated with |delegate|. We cannot search for 152 // Search for the infobar associated with |delegate|. We cannot search for
153 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its 153 // |delegate| in |tab_contents_|, because an InfoBar remains alive until its
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return InfoBar::kDefaultArrowTargetHeight; 196 return InfoBar::kDefaultArrowTargetHeight;
197 // When the first infobar is animating closed, we animate the second infobar's 197 // When the first infobar is animating closed, we animate the second infobar's
198 // arrow target height from the default to the top target height. Note that 198 // arrow target height from the default to the top target height. Note that
199 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. 199 // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
200 return top_arrow_target_height_ + static_cast<int>( 200 return top_arrow_target_height_ + static_cast<int>(
201 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 201 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
202 first_infobar_animation->GetCurrentValue()); 202 first_infobar_animation->GetCurrentValue());
203 } 203 }
204 204
205 #endif // TOOLKIT_VIEWS 205 #endif // TOOLKIT_VIEWS
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/infobar.h ('k') | chrome/browser/tab_contents/tab_contents_ssl_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698