OLD | NEW |
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 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 DOMUI* dom_ui = GetDOMUIForCurrentState(); | 948 DOMUI* dom_ui = GetDOMUIForCurrentState(); |
949 if (dom_ui) | 949 if (dom_ui) |
950 return dom_ui->focus_location_bar_by_default(); | 950 return dom_ui->focus_location_bar_by_default(); |
951 NavigationEntry* entry = controller_.GetActiveEntry(); | 951 NavigationEntry* entry = controller_.GetActiveEntry(); |
952 if (entry && entry->url() == GURL(chrome::kAboutBlankURL)) | 952 if (entry && entry->url() == GURL(chrome::kAboutBlankURL)) |
953 return true; | 953 return true; |
954 return false; | 954 return false; |
955 } | 955 } |
956 | 956 |
957 void TabContents::AddInfoBar(InfoBarDelegate* delegate) { | 957 void TabContents::AddInfoBar(InfoBarDelegate* delegate) { |
| 958 if (delegate_ && !delegate_->infobars_enabled()) { |
| 959 delegate->InfoBarClosed(); |
| 960 return; |
| 961 } |
| 962 |
958 // Look through the existing InfoBarDelegates we have for a match. If we've | 963 // Look through the existing InfoBarDelegates we have for a match. If we've |
959 // already got one that matches, then we don't add the new one. | 964 // already got one that matches, then we don't add the new one. |
960 for (int i = 0; i < infobar_delegate_count(); ++i) { | 965 for (int i = 0; i < infobar_delegate_count(); ++i) { |
961 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { | 966 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { |
962 // Tell the new infobar to close so that it can clean itself up. | 967 // Tell the new infobar to close so that it can clean itself up. |
963 delegate->InfoBarClosed(); | 968 delegate->InfoBarClosed(); |
964 return; | 969 return; |
965 } | 970 } |
966 } | 971 } |
967 | 972 |
968 infobar_delegates_.push_back(delegate); | 973 infobar_delegates_.push_back(delegate); |
969 NotificationService::current()->Notify( | 974 NotificationService::current()->Notify( |
970 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, | 975 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, |
971 Source<TabContents>(this), | 976 Source<TabContents>(this), |
972 Details<InfoBarDelegate>(delegate)); | 977 Details<InfoBarDelegate>(delegate)); |
973 | 978 |
974 // Add ourselves as an observer for navigations the first time a delegate is | 979 // Add ourselves as an observer for navigations the first time a delegate is |
975 // added. We use this notification to expire InfoBars that need to expire on | 980 // added. We use this notification to expire InfoBars that need to expire on |
976 // page transitions. | 981 // page transitions. |
977 if (infobar_delegates_.size() == 1) { | 982 if (infobar_delegates_.size() == 1) { |
978 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 983 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
979 Source<NavigationController>(&controller_)); | 984 Source<NavigationController>(&controller_)); |
980 } | 985 } |
981 } | 986 } |
982 | 987 |
983 void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { | 988 void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { |
| 989 if (delegate_ && !delegate_->infobars_enabled()) { |
| 990 return; |
| 991 } |
| 992 |
984 std::vector<InfoBarDelegate*>::iterator it = | 993 std::vector<InfoBarDelegate*>::iterator it = |
985 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); | 994 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
986 if (it != infobar_delegates_.end()) { | 995 if (it != infobar_delegates_.end()) { |
987 InfoBarDelegate* delegate = *it; | 996 InfoBarDelegate* delegate = *it; |
988 NotificationService::current()->Notify( | 997 NotificationService::current()->Notify( |
989 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 998 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
990 Source<TabContents>(this), | 999 Source<TabContents>(this), |
991 Details<InfoBarDelegate>(delegate)); | 1000 Details<InfoBarDelegate>(delegate)); |
992 infobar_delegates_.erase(it); | 1001 infobar_delegates_.erase(it); |
993 | 1002 |
994 // Remove ourselves as an observer if we are tracking no more InfoBars. | 1003 // Remove ourselves as an observer if we are tracking no more InfoBars. |
995 if (infobar_delegates_.empty()) { | 1004 if (infobar_delegates_.empty()) { |
996 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, | 1005 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
997 Source<NavigationController>(&controller_)); | 1006 Source<NavigationController>(&controller_)); |
998 } | 1007 } |
999 } | 1008 } |
1000 } | 1009 } |
1001 | 1010 |
1002 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, | 1011 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
1003 InfoBarDelegate* new_delegate) { | 1012 InfoBarDelegate* new_delegate) { |
| 1013 if (delegate_ && !delegate_->infobars_enabled()) { |
| 1014 new_delegate->InfoBarClosed(); |
| 1015 return; |
| 1016 } |
| 1017 |
1004 std::vector<InfoBarDelegate*>::iterator it = | 1018 std::vector<InfoBarDelegate*>::iterator it = |
1005 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); | 1019 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
1006 DCHECK(it != infobar_delegates_.end()); | 1020 DCHECK(it != infobar_delegates_.end()); |
1007 | 1021 |
1008 // Notify the container about the change of plans. | 1022 // Notify the container about the change of plans. |
1009 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( | 1023 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( |
1010 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( | 1024 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( |
1011 old_delegate, new_delegate)); | 1025 old_delegate, new_delegate)); |
1012 NotificationService::current()->Notify( | 1026 NotificationService::current()->Notify( |
1013 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | 1027 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
(...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2911 } | 2925 } |
2912 | 2926 |
2913 void TabContents::set_encoding(const std::string& encoding) { | 2927 void TabContents::set_encoding(const std::string& encoding) { |
2914 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2928 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
2915 } | 2929 } |
2916 | 2930 |
2917 void TabContents::SetAppIcon(const SkBitmap& app_icon) { | 2931 void TabContents::SetAppIcon(const SkBitmap& app_icon) { |
2918 app_icon_ = app_icon; | 2932 app_icon_ = app_icon; |
2919 NotifyNavigationStateChanged(INVALIDATE_TITLE); | 2933 NotifyNavigationStateChanged(INVALIDATE_TITLE); |
2920 } | 2934 } |
OLD | NEW |