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 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
8 // For GdkScreen | 8 // For GdkScreen |
9 #include <gdk/gdk.h> | 9 #include <gdk/gdk.h> |
10 #endif // defined(OS_CHROMEOS) | 10 #endif // defined(OS_CHROMEOS) |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 } | 1099 } |
1100 | 1100 |
1101 std::vector<InfoBarDelegate*>::iterator it = | 1101 std::vector<InfoBarDelegate*>::iterator it = |
1102 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); | 1102 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
1103 if (it != infobar_delegates_.end()) { | 1103 if (it != infobar_delegates_.end()) { |
1104 InfoBarDelegate* delegate = *it; | 1104 InfoBarDelegate* delegate = *it; |
1105 NotificationService::current()->Notify( | 1105 NotificationService::current()->Notify( |
1106 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 1106 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
1107 Source<TabContents>(this), | 1107 Source<TabContents>(this), |
1108 Details<InfoBarDelegate>(delegate)); | 1108 Details<InfoBarDelegate>(delegate)); |
1109 infobar_delegates_.erase(it); | |
1110 | 1109 |
1111 // Remove ourselves as an observer if we are tracking no more InfoBars. | 1110 // Just to be safe, make sure the delegate was not removed by an observer. |
1112 if (infobar_delegates_.empty()) { | 1111 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
1113 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, | 1112 if (it != infobar_delegates_.end()) { |
1114 Source<NavigationController>(&controller_)); | 1113 infobar_delegates_.erase(it); |
| 1114 // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 1115 if (infobar_delegates_.empty()) { |
| 1116 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 1117 Source<NavigationController>(&controller_)); |
| 1118 } |
| 1119 } else { |
| 1120 // If you hit this NOTREACHED, please comment in bug |
| 1121 // http://crbug.com/50428 how you got there. |
| 1122 NOTREACHED(); |
1115 } | 1123 } |
1116 } | 1124 } |
1117 } | 1125 } |
1118 | 1126 |
1119 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, | 1127 void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
1120 InfoBarDelegate* new_delegate) { | 1128 InfoBarDelegate* new_delegate) { |
1121 if (delegate_ && !delegate_->infobars_enabled()) { | 1129 if (delegate_ && !delegate_->infobars_enabled()) { |
1122 new_delegate->InfoBarClosed(); | 1130 new_delegate->InfoBarClosed(); |
1123 return; | 1131 return; |
1124 } | 1132 } |
1125 | 1133 |
1126 std::vector<InfoBarDelegate*>::iterator it = | 1134 std::vector<InfoBarDelegate*>::iterator it = |
1127 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); | 1135 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
1128 DCHECK(it != infobar_delegates_.end()); | 1136 DCHECK(it != infobar_delegates_.end()); |
1129 | 1137 |
1130 // Notify the container about the change of plans. | 1138 // Notify the container about the change of plans. |
1131 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( | 1139 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( |
1132 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( | 1140 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( |
1133 old_delegate, new_delegate)); | 1141 old_delegate, new_delegate)); |
1134 NotificationService::current()->Notify( | 1142 NotificationService::current()->Notify( |
1135 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | 1143 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
1136 Source<TabContents>(this), | 1144 Source<TabContents>(this), |
1137 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); | 1145 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); |
1138 | 1146 |
1139 // Remove the old one. | 1147 // Just to be safe, make sure the delegate was not removed by an observer. |
1140 infobar_delegates_.erase(it); | 1148 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
| 1149 if (it != infobar_delegates_.end()) { |
| 1150 // Remove the old one. |
| 1151 infobar_delegates_.erase(it); |
| 1152 } else { |
| 1153 // If you hit this NOTREACHED, please comment in bug |
| 1154 // http://crbug.com/50428 how you got there. |
| 1155 NOTREACHED(); |
| 1156 } |
1141 | 1157 |
1142 // Add the new one. | 1158 // Add the new one. |
| 1159 DCHECK(find(infobar_delegates_.begin(), |
| 1160 infobar_delegates_.end(), new_delegate) == |
| 1161 infobar_delegates_.end()); |
1143 infobar_delegates_.push_back(new_delegate); | 1162 infobar_delegates_.push_back(new_delegate); |
1144 } | 1163 } |
1145 | 1164 |
1146 bool TabContents::ShouldShowBookmarkBar() { | 1165 bool TabContents::ShouldShowBookmarkBar() { |
1147 if (showing_interstitial_page()) | 1166 if (showing_interstitial_page()) |
1148 return false; | 1167 return false; |
1149 | 1168 |
1150 // See GetDOMUIForCurrentState() comment for more info. This case is very | 1169 // See GetDOMUIForCurrentState() comment for more info. This case is very |
1151 // similar, but for non-first loads, we want to use the committed entry. This | 1170 // similar, but for non-first loads, we want to use the committed entry. This |
1152 // is so the bookmarks bar disappears at the same time the page does. | 1171 // is so the bookmarks bar disappears at the same time the page does. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 void TabContents::ExpireInfoBars( | 1514 void TabContents::ExpireInfoBars( |
1496 const NavigationController::LoadCommittedDetails& details) { | 1515 const NavigationController::LoadCommittedDetails& details) { |
1497 // Only hide InfoBars when the user has done something that makes the main | 1516 // Only hide InfoBars when the user has done something that makes the main |
1498 // frame load. We don't want various automatic or subframe navigations making | 1517 // frame load. We don't want various automatic or subframe navigations making |
1499 // it disappear. | 1518 // it disappear. |
1500 if (!details.is_user_initiated_main_frame_load()) | 1519 if (!details.is_user_initiated_main_frame_load()) |
1501 return; | 1520 return; |
1502 | 1521 |
1503 for (int i = infobar_delegate_count() - 1; i >= 0; --i) { | 1522 for (int i = infobar_delegate_count() - 1; i >= 0; --i) { |
1504 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); | 1523 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); |
| 1524 if (!delegate) { |
| 1525 // If you hit this NOTREACHED, please comment in bug |
| 1526 // http://crbug.com/50428 how you got there. |
| 1527 NOTREACHED(); |
| 1528 continue; |
| 1529 } |
| 1530 |
1505 if (delegate->ShouldExpire(details)) | 1531 if (delegate->ShouldExpire(details)) |
1506 RemoveInfoBar(delegate); | 1532 RemoveInfoBar(delegate); |
1507 } | 1533 } |
1508 } | 1534 } |
1509 | 1535 |
1510 DOMUI* TabContents::GetDOMUIForCurrentState() { | 1536 DOMUI* TabContents::GetDOMUIForCurrentState() { |
1511 // When there is a pending navigation entry, we want to use the pending DOMUI | 1537 // When there is a pending navigation entry, we want to use the pending DOMUI |
1512 // that goes along with it to control the basic flags. For example, we want to | 1538 // that goes along with it to control the basic flags. For example, we want to |
1513 // show the pending URL in the URL bar, so we want the display_url flag to | 1539 // show the pending URL in the URL bar, so we want the display_url flag to |
1514 // be from the pending entry. | 1540 // be from the pending entry. |
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3300 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save)); | 3326 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save)); |
3301 } | 3327 } |
3302 | 3328 |
3303 Profile* TabContents::GetProfileForPasswordManager() { | 3329 Profile* TabContents::GetProfileForPasswordManager() { |
3304 return profile(); | 3330 return profile(); |
3305 } | 3331 } |
3306 | 3332 |
3307 bool TabContents::DidLastPageLoadEncounterSSLErrors() { | 3333 bool TabContents::DidLastPageLoadEncounterSSLErrors() { |
3308 return controller().ssl_manager()->ProcessedSSLErrorFromRequest(); | 3334 return controller().ssl_manager()->ProcessedSSLErrorFromRequest(); |
3309 } | 3335 } |
OLD | NEW |