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

Side by Side Diff: chrome/browser/infobars/infobar_tab_helper.cc

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 #include "chrome/browser/infobars/infobar_tab_helper.h" 5 #include "chrome/browser/infobars/infobar_tab_helper.h"
6 6
7 #include "chrome/browser/infobars/infobar.h" 7 #include "chrome/browser/infobars/infobar.h"
8 #include "chrome/browser/infobars/infobar_delegate.h" 8 #include "chrome/browser/infobars/infobar_delegate.h"
9 #include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h" 9 #include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
12 #include "content/common/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
14 14
15 InfoBarTabHelper::InfoBarTabHelper(TabContents* tab_contents) 15 InfoBarTabHelper::InfoBarTabHelper(TabContents* tab_contents)
16 : TabContentsObserver(tab_contents), 16 : TabContentsObserver(tab_contents),
17 infobars_enabled_(true) { 17 infobars_enabled_(true) {
18 DCHECK(tab_contents); 18 DCHECK(tab_contents);
19 } 19 }
20 20
21 InfoBarTabHelper::~InfoBarTabHelper() { 21 InfoBarTabHelper::~InfoBarTabHelper() {
22 // Destroy all remaining InfoBars. It's important to not animate here so that 22 // Destroy all remaining InfoBars. It's important to not animate here so that
(...skipping 14 matching lines...) Expand all
37 for (size_t i = 0; i < infobars_.size(); ++i) { 37 for (size_t i = 0; i < infobars_.size(); ++i) {
38 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { 38 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
39 delegate->InfoBarClosed(); 39 delegate->InfoBarClosed();
40 return; 40 return;
41 } 41 }
42 } 42 }
43 43
44 // TODO(pkasting): Consider removing InfoBarTabHelper arg from delegate 44 // TODO(pkasting): Consider removing InfoBarTabHelper arg from delegate
45 // constructors and instead using a setter from here. 45 // constructors and instead using a setter from here.
46 infobars_.push_back(delegate); 46 infobars_.push_back(delegate);
47 NotificationService::current()->Notify( 47 content::NotificationService::current()->Notify(
48 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 48 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
49 content::Source<InfoBarTabHelper>(this), 49 content::Source<InfoBarTabHelper>(this),
50 content::Details<InfoBarAddedDetails>(delegate)); 50 content::Details<InfoBarAddedDetails>(delegate));
51 51
52 // Add ourselves as an observer for navigations the first time a delegate is 52 // Add ourselves as an observer for navigations the first time a delegate is
53 // added. We use this notification to expire InfoBars that need to expire on 53 // added. We use this notification to expire InfoBars that need to expire on
54 // page transitions. 54 // page transitions.
55 if (infobars_.size() == 1) { 55 if (infobars_.size() == 1) {
56 registrar_.Add( 56 registrar_.Add(
57 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 57 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
(...skipping 16 matching lines...) Expand all
74 for (i = 0; i < infobars_.size(); ++i) { 74 for (i = 0; i < infobars_.size(); ++i) {
75 if (GetInfoBarDelegateAt(i) == old_delegate) 75 if (GetInfoBarDelegateAt(i) == old_delegate)
76 break; 76 break;
77 } 77 }
78 DCHECK_LT(i, infobars_.size()); 78 DCHECK_LT(i, infobars_.size());
79 79
80 infobars_.insert(infobars_.begin() + i, new_delegate); 80 infobars_.insert(infobars_.begin() + i, new_delegate);
81 81
82 old_delegate->clear_owner(); 82 old_delegate->clear_owner();
83 InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); 83 InfoBarReplacedDetails replaced_details(old_delegate, new_delegate);
84 NotificationService::current()->Notify( 84 content::NotificationService::current()->Notify(
85 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, 85 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
86 content::Source<InfoBarTabHelper>(this), 86 content::Source<InfoBarTabHelper>(this),
87 content::Details<InfoBarReplacedDetails>(&replaced_details)); 87 content::Details<InfoBarReplacedDetails>(&replaced_details));
88 88
89 infobars_.erase(infobars_.begin() + i + 1); 89 infobars_.erase(infobars_.begin() + i + 1);
90 } 90 }
91 91
92 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { 92 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) {
93 return infobars_[index]; 93 return infobars_[index];
94 } 94 }
95 95
96 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, 96 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate,
97 bool animate) { 97 bool animate) {
98 if (!infobars_enabled_) { 98 if (!infobars_enabled_) {
99 DCHECK(infobars_.empty()); 99 DCHECK(infobars_.empty());
100 return; 100 return;
101 } 101 }
102 102
103 size_t i; 103 size_t i;
104 for (i = 0; i < infobars_.size(); ++i) { 104 for (i = 0; i < infobars_.size(); ++i) {
105 if (GetInfoBarDelegateAt(i) == delegate) 105 if (GetInfoBarDelegateAt(i) == delegate)
106 break; 106 break;
107 } 107 }
108 DCHECK_LT(i, infobars_.size()); 108 DCHECK_LT(i, infobars_.size());
109 InfoBarDelegate* infobar = infobars_[i]; 109 InfoBarDelegate* infobar = infobars_[i];
110 110
111 infobar->clear_owner(); 111 infobar->clear_owner();
112 InfoBarRemovedDetails removed_details(infobar, animate); 112 InfoBarRemovedDetails removed_details(infobar, animate);
113 NotificationService::current()->Notify( 113 content::NotificationService::current()->Notify(
114 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 114 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
115 content::Source<InfoBarTabHelper>(this), 115 content::Source<InfoBarTabHelper>(this),
116 content::Details<InfoBarRemovedDetails>(&removed_details)); 116 content::Details<InfoBarRemovedDetails>(&removed_details));
117 117
118 infobars_.erase(infobars_.begin() + i); 118 infobars_.erase(infobars_.begin() + i);
119 // Remove ourselves as an observer if we are tracking no more InfoBars. 119 // Remove ourselves as an observer if we are tracking no more InfoBars.
120 if (infobars_.empty()) { 120 if (infobars_.empty()) {
121 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 121 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
122 content::Source<NavigationController>(&tab_contents()->controller())); 122 content::Source<NavigationController>(&tab_contents()->controller()));
123 } 123 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (delegate->ShouldExpire(committed_details)) 190 if (delegate->ShouldExpire(committed_details))
191 RemoveInfoBar(delegate); 191 RemoveInfoBar(delegate);
192 } 192 }
193 193
194 break; 194 break;
195 } 195 }
196 default: 196 default:
197 NOTREACHED(); 197 NOTREACHED();
198 } 198 }
199 } 199 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/profile_writer.cc ('k') | chrome/browser/instant/instant_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698