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

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

Issue 1205001: Revert 42366 - Allow TabContentsDelegate classes to specify whether InfoBars ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/tab_contents/tab_contents.h" 5 #include "chrome/browser/tab_contents/tab_contents.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/text_elider.h" 9 #include "app/text_elider.h"
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 DOMUI* dom_ui = GetDOMUIForCurrentState(); 944 DOMUI* dom_ui = GetDOMUIForCurrentState();
945 if (dom_ui) 945 if (dom_ui)
946 return dom_ui->focus_location_bar_by_default(); 946 return dom_ui->focus_location_bar_by_default();
947 NavigationEntry* entry = controller_.GetActiveEntry(); 947 NavigationEntry* entry = controller_.GetActiveEntry();
948 if (entry && entry->url() == GURL(chrome::kAboutBlankURL)) 948 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
949 return true; 949 return true;
950 return false; 950 return false;
951 } 951 }
952 952
953 void TabContents::AddInfoBar(InfoBarDelegate* delegate) { 953 void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
954 if (delegate_ && !delegate_->infobars_enabled()) {
955 delegate->InfoBarClosed();
956 return;
957 }
958
959 // Look through the existing InfoBarDelegates we have for a match. If we've 954 // Look through the existing InfoBarDelegates we have for a match. If we've
960 // already got one that matches, then we don't add the new one. 955 // already got one that matches, then we don't add the new one.
961 for (int i = 0; i < infobar_delegate_count(); ++i) { 956 for (int i = 0; i < infobar_delegate_count(); ++i) {
962 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { 957 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
963 // Tell the new infobar to close so that it can clean itself up. 958 // Tell the new infobar to close so that it can clean itself up.
964 delegate->InfoBarClosed(); 959 delegate->InfoBarClosed();
965 return; 960 return;
966 } 961 }
967 } 962 }
968 963
969 infobar_delegates_.push_back(delegate); 964 infobar_delegates_.push_back(delegate);
970 NotificationService::current()->Notify( 965 NotificationService::current()->Notify(
971 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 966 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
972 Source<TabContents>(this), 967 Source<TabContents>(this),
973 Details<InfoBarDelegate>(delegate)); 968 Details<InfoBarDelegate>(delegate));
974 969
975 // Add ourselves as an observer for navigations the first time a delegate is 970 // Add ourselves as an observer for navigations the first time a delegate is
976 // added. We use this notification to expire InfoBars that need to expire on 971 // added. We use this notification to expire InfoBars that need to expire on
977 // page transitions. 972 // page transitions.
978 if (infobar_delegates_.size() == 1) { 973 if (infobar_delegates_.size() == 1) {
979 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 974 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
980 Source<NavigationController>(&controller_)); 975 Source<NavigationController>(&controller_));
981 } 976 }
982 } 977 }
983 978
984 void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { 979 void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
985 if (delegate_ && !delegate_->infobars_enabled()) {
986 return;
987 }
988
989 std::vector<InfoBarDelegate*>::iterator it = 980 std::vector<InfoBarDelegate*>::iterator it =
990 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); 981 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
991 if (it != infobar_delegates_.end()) { 982 if (it != infobar_delegates_.end()) {
992 InfoBarDelegate* delegate = *it; 983 InfoBarDelegate* delegate = *it;
993 NotificationService::current()->Notify( 984 NotificationService::current()->Notify(
994 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 985 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
995 Source<TabContents>(this), 986 Source<TabContents>(this),
996 Details<InfoBarDelegate>(delegate)); 987 Details<InfoBarDelegate>(delegate));
997 infobar_delegates_.erase(it); 988 infobar_delegates_.erase(it);
998 989
999 // Remove ourselves as an observer if we are tracking no more InfoBars. 990 // Remove ourselves as an observer if we are tracking no more InfoBars.
1000 if (infobar_delegates_.empty()) { 991 if (infobar_delegates_.empty()) {
1001 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, 992 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1002 Source<NavigationController>(&controller_)); 993 Source<NavigationController>(&controller_));
1003 } 994 }
1004 } 995 }
1005 } 996 }
1006 997
1007 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, 998 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1008 InfoBarDelegate* new_delegate) { 999 InfoBarDelegate* new_delegate) {
1009 if (delegate_ && !delegate_->infobars_enabled()) {
1010 new_delegate->InfoBarClosed();
1011 return;
1012 }
1013
1014 std::vector<InfoBarDelegate*>::iterator it = 1000 std::vector<InfoBarDelegate*>::iterator it =
1015 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); 1001 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1016 DCHECK(it != infobar_delegates_.end()); 1002 DCHECK(it != infobar_delegates_.end());
1017 1003
1018 // Notify the container about the change of plans. 1004 // Notify the container about the change of plans.
1019 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( 1005 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1020 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( 1006 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1021 old_delegate, new_delegate)); 1007 old_delegate, new_delegate));
1022 NotificationService::current()->Notify( 1008 NotificationService::current()->Notify(
1023 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, 1009 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 } 2888 }
2903 2889
2904 void TabContents::set_encoding(const std::string& encoding) { 2890 void TabContents::set_encoding(const std::string& encoding) {
2905 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); 2891 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2906 } 2892 }
2907 2893
2908 void TabContents::SetAppIcon(const SkBitmap& app_icon) { 2894 void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2909 app_icon_ = app_icon; 2895 app_icon_ = app_icon;
2910 NotifyNavigationStateChanged(INVALIDATE_TITLE); 2896 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2911 } 2897 }
OLDNEW
« no previous file with comments | « chrome/browser/external_tab_container.cc ('k') | chrome/browser/tab_contents/tab_contents_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698