| OLD | NEW |
| 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/ui/tab_contents/tab_contents_wrapper.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "chrome/browser/autocomplete_history_manager.h" | 9 #include "chrome/browser/autocomplete_history_manager.h" |
| 10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 renderer_preferences_util::UpdateFromSystemSettings( | 171 renderer_preferences_util::UpdateFromSystemSettings( |
| 172 tab_contents()->GetMutableRendererPrefs(), profile()); | 172 tab_contents()->GetMutableRendererPrefs(), profile()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TabContentsWrapper::~TabContentsWrapper() { | 175 TabContentsWrapper::~TabContentsWrapper() { |
| 176 in_destructor_ = true; | 176 in_destructor_ = true; |
| 177 | 177 |
| 178 // Destroy all remaining InfoBars. It's important to not animate here so that | 178 // Destroy all remaining InfoBars. It's important to not animate here so that |
| 179 // we guarantee that we'll delete all delegates before we do anything else. | 179 // we guarantee that we'll delete all delegates before we do anything else. |
| 180 // |
| 181 // TODO(pkasting): If there is no InfoBarContainer, this leaks all the |
| 182 // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on |
| 183 // Infobars. |
| 180 RemoveAllInfoBars(false); | 184 RemoveAllInfoBars(false); |
| 181 } | 185 } |
| 182 | 186 |
| 183 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { | 187 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { |
| 184 return g_tab_contents_wrapper_property_accessor.Pointer(); | 188 return g_tab_contents_wrapper_property_accessor.Pointer(); |
| 185 } | 189 } |
| 186 | 190 |
| 187 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { | 191 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { |
| 188 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, | 192 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, |
| 189 true, | 193 true, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 358 } |
| 355 | 359 |
| 356 //////////////////////////////////////////////////////////////////////////////// | 360 //////////////////////////////////////////////////////////////////////////////// |
| 357 // TabContentsWrapper implementation: | 361 // TabContentsWrapper implementation: |
| 358 | 362 |
| 359 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { | 363 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { |
| 360 UpdateAlternateErrorPageURL(render_view_host); | 364 UpdateAlternateErrorPageURL(render_view_host); |
| 361 } | 365 } |
| 362 | 366 |
| 363 void TabContentsWrapper::RenderViewGone() { | 367 void TabContentsWrapper::RenderViewGone() { |
| 364 // Remove all infobars. | |
| 365 RemoveAllInfoBars(true); | 368 RemoveAllInfoBars(true); |
| 366 | 369 |
| 367 // Tell the view that we've crashed so it can prepare the sad tab page. | 370 // Tell the view that we've crashed so it can prepare the sad tab page. |
| 368 // Only do this if we're not in browser shutdown, so that TabContents | 371 // Only do this if we're not in browser shutdown, so that TabContents |
| 369 // objects that are not in a browser (e.g., HTML dialogs) and thus are | 372 // objects that are not in a browser (e.g., HTML dialogs) and thus are |
| 370 // visible do not flash a sad tab page. | 373 // visible do not flash a sad tab page. |
| 371 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) { | 374 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) { |
| 372 tab_contents()->view()->OnTabCrashed( | 375 tab_contents()->view()->OnTabCrashed( |
| 373 tab_contents()->crashed_status(), tab_contents()->crashed_error_code()); | 376 tab_contents()->crashed_status(), tab_contents()->crashed_error_code()); |
| 374 } | 377 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 465 } |
| 463 | 466 |
| 464 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { | 467 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { |
| 465 if (!infobars_enabled_) { | 468 if (!infobars_enabled_) { |
| 466 delegate->InfoBarClosed(); | 469 delegate->InfoBarClosed(); |
| 467 return; | 470 return; |
| 468 } | 471 } |
| 469 | 472 |
| 470 for (size_t i = 0; i < infobars_.size(); ++i) { | 473 for (size_t i = 0; i < infobars_.size(); ++i) { |
| 471 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { | 474 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { |
| 472 // Tell the new infobar to close so that it can clean itself up. | |
| 473 delegate->InfoBarClosed(); | 475 delegate->InfoBarClosed(); |
| 474 return; | 476 return; |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 | 479 |
| 478 infobars_.push_back(delegate); | 480 infobars_.push_back(delegate); |
| 479 NotificationService::current()->Notify( | 481 NotificationService::current()->Notify( |
| 480 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, | 482 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, |
| 481 Source<TabContentsWrapper>(this), Details<InfoBarDelegate>(delegate)); | 483 Source<TabContentsWrapper>(this), Details<InfoBarDelegate>(delegate)); |
| 482 | 484 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; | 646 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; |
| 645 RemoveDetails remove_details(infobar, animate); | 647 RemoveDetails remove_details(infobar, animate); |
| 646 NotificationService::current()->Notify( | 648 NotificationService::current()->Notify( |
| 647 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 649 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 648 Source<TabContentsWrapper>(this), | 650 Source<TabContentsWrapper>(this), |
| 649 Details<RemoveDetails>(&remove_details)); | 651 Details<RemoveDetails>(&remove_details)); |
| 650 | 652 |
| 651 infobars_.erase(infobars_.begin() + i); | 653 infobars_.erase(infobars_.begin() + i); |
| 652 // Remove ourselves as an observer if we are tracking no more InfoBars. | 654 // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 653 if (infobars_.empty()) { | 655 if (infobars_.empty()) { |
| 654 registrar_.Remove( | 656 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 655 this, NotificationType::NAV_ENTRY_COMMITTED, | |
| 656 Source<NavigationController>(&tab_contents_->controller())); | 657 Source<NavigationController>(&tab_contents_->controller())); |
| 657 } | 658 } |
| 658 } | 659 } |
| 659 | 660 |
| 660 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { | 661 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { |
| 661 while (!infobars_.empty()) | 662 while (!infobars_.empty()) |
| 662 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | 663 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); |
| 663 } | 664 } |
| OLD | NEW |