diff options
61 files changed, 497 insertions, 427 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 5c2aaef..0511aa4 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -7,9 +7,9 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" @@ -165,5 +165,6 @@ void AlternateNavURLFetcher::ShowInfobarIfPossible() { infobar_contents_ = controller_->tab_contents(); StoreActiveEntryUniqueID(infobar_contents_); - infobar_contents_->AddInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(infobar_contents_)-> + AddInfoBar(this); } diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index 4158454..9770ce0 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -457,8 +457,9 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillAfterTranslate) { // Get translation bar. render_view_host()->OnMessageReceived(ViewHostMsg_TranslateLanguageDetermined( 0, "ja", true)); - TranslateInfoBarDelegate* infobar = browser()->GetSelectedTabContents()-> - GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); + TranslateInfoBarDelegate* infobar = + browser()->GetSelectedTabContentsWrapper()-> + GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); ASSERT_TRUE(infobar != NULL); EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 9ccc797..5004503 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -36,7 +36,6 @@ #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "content/common/notification_source.h" #include "content/common/notification_type.h" @@ -223,8 +222,9 @@ bool FormIsHTTPS(FormStructure* form) { } // namespace -AutofillManager::AutofillManager(TabContents* tab_contents) - : TabContentsObserver(tab_contents), +AutofillManager::AutofillManager(TabContentsWrapper* tab_contents) + : TabContentsObserver(tab_contents->tab_contents()), + tab_contents_wrapper_(tab_contents), personal_data_(NULL), download_manager_(tab_contents->profile()), disable_download_manager_requests_(false), @@ -299,9 +299,7 @@ bool AutofillManager::OnMessageReceived(const IPC::Message& message) { void AutofillManager::OnFormSubmitted(const FormData& form) { // Let AutoComplete know as well. - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); - wrapper->autocomplete_history_manager()->OnFormSubmitted(form); + tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); if (!IsAutofillEnabled()) return; @@ -435,10 +433,9 @@ void AutofillManager::OnQueryFormFieldAutofill( // Add the results from AutoComplete. They come back asynchronously, so we // hand off what we generated and they will send the results back to the // renderer. - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); - wrapper->autocomplete_history_manager()->OnGetAutocompleteSuggestions( - query_id, field.name, field.value, values, labels, icons, unique_ids); + tab_contents_wrapper_->autocomplete_history_manager()-> + OnGetAutocompleteSuggestions( + query_id, field.name, field.value, values, labels, icons, unique_ids); } void AutofillManager::OnFillAutofillFormData(int query_id, @@ -649,7 +646,7 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { // it. scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); if (imported_credit_card && tab_contents()) { - tab_contents()->AddInfoBar( + tab_contents_wrapper_->AddInfoBar( new AutofillCCInfoBarDelegate(tab_contents(), scoped_credit_card.release(), personal_data_, @@ -684,9 +681,10 @@ void AutofillManager::Reset() { has_logged_address_suggestions_count_ = false; } -AutofillManager::AutofillManager(TabContents* tab_contents, +AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, PersonalDataManager* personal_data) - : TabContentsObserver(tab_contents), + : TabContentsObserver(tab_contents->tab_contents()), + tab_contents_wrapper_(tab_contents), personal_data_(personal_data), download_manager_(NULL), disable_download_manager_requests_(true), diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index f9e69b9..ae62a90 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -30,7 +30,7 @@ class CreditCard; class PersonalDataManager; class PrefService; class RenderViewHost; -class TabContents; +class TabContentsWrapper; struct ViewHostMsg_FrameNavigate_Params; @@ -48,7 +48,7 @@ struct FormField; class AutofillManager : public TabContentsObserver, public AutofillDownloadManager::Observer { public: - explicit AutofillManager(TabContents* tab_contents); + explicit AutofillManager(TabContentsWrapper* tab_contents); virtual ~AutofillManager(); // Registers our browser prefs. @@ -91,7 +91,7 @@ class AutofillManager : public TabContentsObserver, // (where applicable). typedef std::pair<std::string, size_t> GUIDPair; - AutofillManager(TabContents* tab_contents, + AutofillManager(TabContentsWrapper* tab_contents, PersonalDataManager* personal_data); void set_personal_data_manager(PersonalDataManager* personal_data) { @@ -196,6 +196,9 @@ class AutofillManager : public TabContentsObserver, // |submitted_form|. void DeterminePossibleFieldTypesForUpload(FormStructure* submitted_form); + // The owning TabContentsWrapper. + TabContentsWrapper* tab_contents_wrapper_; + // The personal data manager, used to save and load personal data to/from the // web database. This is overridden by the AutofillManagerTest. // Weak reference. diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index e1b9521..35ae16e 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -408,7 +408,7 @@ void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id, class TestAutofillManager : public AutofillManager { public: - TestAutofillManager(TabContents* tab_contents, + TestAutofillManager(TabContentsWrapper* tab_contents, TestPersonalDataManager* personal_manager) : AutofillManager(tab_contents, personal_manager), autofill_enabled_(true) { @@ -483,7 +483,7 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness { virtual void SetUp() { TabContentsWrapperTestHarness::SetUp(); test_personal_data_ = new TestPersonalDataManager(); - autofill_manager_.reset(new TestAutofillManager(contents(), + autofill_manager_.reset(new TestAutofillManager(contents_wrapper(), test_personal_data_.get())); } diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc index 286a65a..c84d063 100644 --- a/chrome/browser/autofill/autofill_metrics_unittest.cc +++ b/chrome/browser/autofill/autofill_metrics_unittest.cc @@ -117,7 +117,7 @@ class TestPersonalDataManager : public PersonalDataManager { class TestAutofillManager : public AutofillManager { public: - TestAutofillManager(TabContents* tab_contents, + TestAutofillManager(TabContentsWrapper* tab_contents, TestPersonalDataManager* personal_manager) : AutofillManager(tab_contents, personal_manager), autofill_enabled_(true) { @@ -193,7 +193,7 @@ class AutofillMetricsTest : public TabContentsWrapperTestHarness { virtual void SetUp() { TabContentsWrapperTestHarness::SetUp(); test_personal_data_ = new TestPersonalDataManager(); - autofill_manager_.reset(new TestAutofillManager(contents(), + autofill_manager_.reset(new TestAutofillManager(contents_wrapper(), test_personal_data_.get())); } diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index bb78b91..d40a437 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1385,7 +1385,9 @@ void InfoBarCountObserver::Observe(NotificationType type, } void InfoBarCountObserver::CheckCount() { - if (tab_contents_->infobar_count() != target_count_) + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); + if (wrapper->infobar_count() != target_count_) return; if (automation_) { diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 5073718..11b9063 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1880,8 +1880,12 @@ void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) { *count = static_cast<size_t>(-1); // -1 means error. if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); - if (nav_controller) - *count = nav_controller->tab_contents()->infobar_count(); + if (nav_controller) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents( + nav_controller->tab_contents()); + *count = wrapper->infobar_count(); + } } } @@ -1894,14 +1898,18 @@ void TestingAutomationProvider::ClickInfoBarAccept( if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); if (nav_controller) { - if (info_bar_index < nav_controller->tab_contents()->infobar_count()) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents( + nav_controller->tab_contents()); + if (info_bar_index < wrapper->infobar_count()) { if (wait_for_navigation) { new NavigationNotificationObserver(nav_controller, this, reply_message, 1, false, false); } InfoBarDelegate* delegate = - nav_controller->tab_contents()->GetInfoBarDelegateAt( - info_bar_index); + TabContentsWrapper::GetCurrentWrapperForContents( + nav_controller->tab_contents())->GetInfoBarDelegateAt( + info_bar_index); if (delegate->AsConfirmInfoBarDelegate()) delegate->AsConfirmInfoBarDelegate()->Accept(); success = true; @@ -2465,9 +2473,11 @@ void TestingAutomationProvider::SetWindowDimensions( ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { // Each infobar may have different properties depending on the type. ListValue* infobars = new ListValue; - for (size_t i = 0; i < tc->infobar_count(); ++i) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tc); + for (size_t i = 0; i < wrapper->infobar_count(); ++i) { DictionaryValue* infobar_item = new DictionaryValue; - InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(i); + InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); if (infobar->AsConfirmInfoBarDelegate()) { // Also covers ThemeInstalledInfoBarDelegate. infobar_item->SetString("type", "confirm_infobar"); @@ -2531,7 +2541,8 @@ void TestingAutomationProvider::PerformActionOnInfobar( reply.SendError("Invalid or missing args"); return; } - TabContents* tab_contents = browser->GetTabContentsAt(tab_index); + TabContentsWrapper* tab_contents = + browser->GetTabContentsWrapperAt(tab_index); if (!tab_contents) { reply.SendError(StringPrintf("No such tab at index %d", tab_index)); return; @@ -3702,8 +3713,10 @@ TabContentsWrapper* GetTabContentsWrapperFromDict(const Browser* browser, // Get the TranslateInfoBarDelegate from TabContents. TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( TabContents* tab_contents) { - for (size_t i = 0; i < tab_contents->infobar_count(); i++) { - InfoBarDelegate* infobar = tab_contents->GetInfoBarDelegateAt(i); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + for (size_t i = 0; i < wrapper->infobar_count(); i++) { + InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); if (infobar->AsTranslateInfoBarDelegate()) return infobar->AsTranslateInfoBarDelegate(); } @@ -3905,7 +3918,7 @@ void TestingAutomationProvider::SelectTranslateOption( // This is the function called when an infobar is dismissed or when the // user clicks the 'Nope' translate button. translate_bar->TranslationDeclined(); - tab_contents->RemoveInfoBar(translate_bar); + tab_contents_wrapper->RemoveInfoBar(translate_bar); reply.SendSuccess(NULL); } else { reply.SendError("Invalid string found for option."); diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc index 579c172..3abe80c 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -7,6 +7,7 @@ #include "base/stl_util-inl.h" #include "chrome/browser/download/download_request_infobar_delegate.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" @@ -71,7 +72,9 @@ void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( NotifyCallbacks(DownloadRequestLimiter::delegate_->ShouldAllowDownload()); } else { infobar_ = new DownloadRequestInfoBarDelegate(tab, this); - tab->AddInfoBar(infobar_); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + wrapper->AddInfoBar(infobar_); } } diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index d423427..94cbde5 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/extensions/extension_resource.h" #include "content/browser/tab_contents/tab_contents.h" @@ -79,7 +80,7 @@ void ExtensionDisabledDialogDelegate::InstallUIAbort() { class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate, public NotificationObserver { public: - ExtensionDisabledInfobarDelegate(TabContents* tab_contents, + ExtensionDisabledInfobarDelegate(TabContentsWrapper* tab_contents, ExtensionService* service, const Extension* extension); @@ -98,16 +99,16 @@ class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate, const NotificationDetails& details) OVERRIDE; NotificationRegistrar registrar_; - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; ExtensionService* service_; const Extension* extension_; }; ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate( - TabContents* tab_contents, + TabContentsWrapper* tab_contents, ExtensionService* service, const Extension* extension) - : ConfirmInfoBarDelegate(tab_contents), + : ConfirmInfoBarDelegate(tab_contents->tab_contents()), tab_contents_(tab_contents), service_(service), extension_(extension) { @@ -173,7 +174,7 @@ void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, if (!browser) return; - TabContents* tab_contents = browser->GetSelectedTabContents(); + TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); if (!tab_contents) return; diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc index 336f287..c9fdca2 100644 --- a/chrome/browser/extensions/extension_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_infobar_delegate.cc @@ -8,8 +8,8 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "content/common/notification_type.h" @@ -71,18 +71,20 @@ ExtensionInfoBarDelegate* void ExtensionInfoBarDelegate::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); switch (type.value) { case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: { const ExtensionHost* result = Details<ExtensionHost>(details).ptr(); if (extension_host_.get() == result) - tab_contents_->RemoveInfoBar(this); + wrapper->RemoveInfoBar(this); break; } case NotificationType::EXTENSION_UNLOADED: { const Extension* extension = Details<UnloadedExtensionInfo>(details)->extension; if (extension_ == extension) - tab_contents_->RemoveInfoBar(this); + wrapper->RemoveInfoBar(this); break; } default: { diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc index e775331d..2597c74 100644 --- a/chrome/browser/extensions/extension_infobar_module.cc +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -52,7 +52,7 @@ bool ShowInfoBarFunction::RunImpl() { return false; } - tab_contents->tab_contents()->AddInfoBar( + tab_contents->AddInfoBar( new ExtensionInfoBarDelegate(browser, tab_contents->tab_contents(), GetExtension(), url)); diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index a735efd..783ccdc 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -23,12 +23,12 @@ #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/url_constants.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -230,7 +230,7 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, if (!browser) return; - TabContents* tab_contents = browser->GetSelectedTabContents(); + TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); if (!tab_contents) return; @@ -253,7 +253,8 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, // Then either replace that old one or add a new one. InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( - tab_contents, new_theme, previous_theme_id, previous_using_native_theme); + tab_contents->tab_contents(), new_theme, previous_theme_id, + previous_using_native_theme); if (old_delegate) tab_contents->ReplaceInfoBar(old_delegate, new_delegate); diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index 721685d..ee04530 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/test/ui_test_utils.h" #include "content/browser/tab_contents/tab_contents.h" @@ -21,14 +22,14 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { // Checks that a theme info bar is currently visible and issues an undo to // revert to the previous theme. void VerifyThemeInfoBarAndUndoInstall() { - TabContents* tab_contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(tab_contents); - ASSERT_EQ(1U, tab_contents->infobar_count()); + TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); + ASSERT_TRUE(tab); + ASSERT_EQ(1U, tab->infobar_count()); ConfirmInfoBarDelegate* delegate = - tab_contents->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Cancel(); - ASSERT_EQ(0U, tab_contents->infobar_count()); + ASSERT_EQ(0U, tab->infobar_count()); } const Extension* GetTheme() const { diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc index 3f01810..07bfccc 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc @@ -11,8 +11,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" @@ -105,7 +105,8 @@ void ThemeInstalledInfoBarDelegate::Observe( // with, close this info bar since it is no longer relevant. if (theme_id_ != theme_service_->GetThemeID()) { if (tab_contents_ && !tab_contents_->is_being_destroyed()) { - tab_contents_->RemoveInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + RemoveInfoBar(this); // The infobar is gone so there is no reason for this delegate to keep // a pointer to the TabContents (the TabContents has deleted its // reference to this delegate and a new delegate will be created if diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 56ac022..86e227d 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -99,7 +99,6 @@ ExternalTabContainer::ExternalTabContainer( handle_top_level_requests_(false), external_method_factory_(this), pending_(false), - infobars_enabled_(true), focus_manager_(NULL), external_tab_view_(NULL), unload_reply_message_(NULL), @@ -133,7 +132,6 @@ bool ExternalTabContainer::Init(Profile* profile, load_requests_via_automation_ = load_requests_via_automation; handle_top_level_requests_ = handle_top_level_requests; - infobars_enabled_ = infobars_enabled; route_all_top_level_navigations_ = route_all_top_level_navigations; set_window_style(WS_POPUP | WS_CLIPCHILDREN); @@ -160,6 +158,9 @@ bool ExternalTabContainer::Init(Profile* profile, tab_contents_.reset(new TabContentsWrapper(new_contents)); } + if (!infobars_enabled) + tab_contents_->set_infobars_enabled(false); + tab_contents_->tab_contents()->set_delegate(this); tab_contents_->tab_contents()-> @@ -468,10 +469,6 @@ void ExternalTabContainer::TabContentsCreated(TabContents* new_contents) { RegisterRenderViewHostForAutomation(rvh, true); } -bool ExternalTabContainer::infobars_enabled() { - return infobars_enabled_; -} - void ExternalTabContainer::ActivateContents(TabContents* contents) { } @@ -1076,7 +1073,7 @@ void ExternalTabContainer::SetupExternalTabView() { external_tab_view_ = new views::View(); InfoBarContainerView* info_bar_container = new InfoBarContainerView(this); - info_bar_container->ChangeTabContents(tab_contents()); + info_bar_container->ChangeTabContents(tab_contents_.get()); views::GridLayout* layout = new views::GridLayout(external_tab_view_); // Give this column an identifier of 0. diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h index 4a3ac39..a2f7088 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -211,8 +211,6 @@ class ExternalTabContainer : public TabContentsDelegate, virtual void TabContentsCreated(TabContents* new_contents); - virtual bool infobars_enabled(); - void RunUnloadHandlers(IPC::Message* reply_message); protected: @@ -321,9 +319,6 @@ class ExternalTabContainer : public TabContentsDelegate, // from the host. bool pending_; - // Set to true if the ExternalTabContainer if infobars should be enabled. - bool infobars_enabled_; - views::FocusManager* focus_manager_; views::View* external_tab_view_; diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index b730d83..9113372 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -307,7 +307,6 @@ class GeolocationBrowserTest : public InProcessBrowserTest { } void SetInfobarResponse(const GURL& requesting_url, bool allowed) { - TabContents* tab_contents = current_browser_->GetSelectedTabContents(); TabContentsWrapper* tab_contents_wrapper = current_browser_->GetSelectedTabContentsWrapper(); TabSpecificContentSettings* content_settings = @@ -322,7 +321,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { else infobar_->AsConfirmInfoBarDelegate()->Cancel(); WaitForNavigation(); - tab_contents->RemoveInfoBar(infobar_); + tab_contents_wrapper->RemoveInfoBar(infobar_); LOG(WARNING) << "infobar response set"; infobar_ = NULL; EXPECT_GT(settings_state.state_map().size(), state_map_size); @@ -556,11 +555,11 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, AddGeolocationWatch(true); size_t num_infobars_before_cancel = - current_browser_->GetSelectedTabContents()->infobar_count(); + current_browser_->GetSelectedTabContentsWrapper()->infobar_count(); // Change the iframe, and ensure the infobar is gone. IFrameLoader change_iframe_1(current_browser_, 1, current_url_); size_t num_infobars_after_cancel = - current_browser_->GetSelectedTabContents()->infobar_count(); + current_browser_->GetSelectedTabContentsWrapper()->infobar_count(); EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); } diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc index 6bb651f..54ed24d 100644 --- a/chrome/browser/geolocation/geolocation_permission_context.cc +++ b/chrome/browser/geolocation/geolocation_permission_context.cc @@ -17,13 +17,13 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" #include "content/browser/geolocation/geolocation_provider.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/geolocation_messages.h" #include "content/common/notification_registrar.h" #include "content/common/notification_source.h" @@ -440,10 +440,13 @@ void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, int render_view_id) { TabContents* tab_contents = tab_util::GetTabContentsByID(render_process_id, render_view_id); + TabContentsWrapper* wrapper = NULL; + if (tab_contents) + wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); i != pending_infobar_requests_.end(); ) { if (i->IsForTab(render_process_id, render_view_id)) { - if (!tab_contents) { + if (!wrapper) { i = pending_infobar_requests_.erase(i); continue; } @@ -459,7 +462,7 @@ void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, tab_contents, this, render_process_id, render_view_id, i->bridge_id, i->requesting_frame, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); - tab_contents->AddInfoBar(i->infobar_delegate); + wrapper->AddInfoBar(i->infobar_delegate); } break; } @@ -481,7 +484,9 @@ GeolocationInfoBarQueueController::PendingInfoBarRequests::iterator // TabContents will destroy the InfoBar, which will remove from our vector // asynchronously. - tab_contents->RemoveInfoBar(i->infobar_delegate); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + wrapper->RemoveInfoBar(i->infobar_delegate); return ++i; } diff --git a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc index dbfd59c..ab73d24 100644 --- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc @@ -19,6 +19,8 @@ #include "content/browser/tab_contents/test_tab_contents.h" #include "content/common/geolocation_messages.h" #include "content/common/notification_details.h" +#include "content/common/notification_registrar.h" +#include "content/common/notification_source.h" #include "content/common/notification_type.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,24 +31,29 @@ namespace { // TestTabContents short-circuits TAB_CONTENTS_INFOBAR_REMOVED to call // InfoBarClosed() directly. We need to observe it and call InfoBarClosed() // later. -class TestTabContentsWithPendingInfoBar : public TestTabContents { +class TestTabContentsWithPendingInfoBar : public TabContentsWrapper { public: TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance); virtual ~TestTabContentsWithPendingInfoBar(); - // TestTabContents: + // TabContentsWrapper: virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); InfoBarDelegate* removed_infobar_delegate_; + NotificationRegistrar registrar_; }; TestTabContentsWithPendingInfoBar::TestTabContentsWithPendingInfoBar( Profile* profile, SiteInstance* instance) - : TestTabContents(profile, instance), + : TabContentsWrapper( + new TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL)), removed_infobar_delegate_(NULL) { + Source<TabContents> source(tab_contents()); + registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, + source); } TestTabContentsWithPendingInfoBar::~TestTabContentsWithPendingInfoBar() { @@ -59,7 +66,7 @@ void TestTabContentsWithPendingInfoBar::Observe( if (type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) removed_infobar_delegate_ = Details<InfoBarDelegate>(details).ptr(); else - TestTabContents::Observe(type, source, details); + TabContentsWrapper::Observe(type, source, details); } } // namespace @@ -152,8 +159,8 @@ void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { TestTabContentsWithPendingInfoBar* new_tab = new TestTabContentsWithPendingInfoBar(profile(), NULL); new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED); - static_cast<TestRenderViewHost*>(new_tab->render_manager()->current_host())-> - SendNavigate(extra_tabs_.size() + 1, url); + static_cast<TestRenderViewHost*>(new_tab->tab_contents()->render_manager()-> + current_host())->SendNavigate(extra_tabs_.size() + 1, url); extra_tabs_.push_back(new_tab); } @@ -180,7 +187,7 @@ void GeolocationPermissionContextTests::SetUp() { SiteInstance* site_instance = contents()->GetSiteInstance(); tab_contents_with_pending_infobar_ = new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance); - SetContents(tab_contents_with_pending_infobar_); + SetContentsWrapper(tab_contents_with_pending_infobar_); geolocation_permission_context_ = new GeolocationPermissionContext(profile()); } @@ -196,10 +203,10 @@ void GeolocationPermissionContextTests::TearDown() { TEST_F(GeolocationPermissionContextTests, SinglePermission) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); } TEST_F(GeolocationPermissionContextTests, QueuedPermission) { @@ -213,16 +220,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { requesting_frame_1, requesting_frame_0)); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); // Ensure only one infobar is created. - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); ConfirmInfoBarDelegate* infobar_0 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -231,15 +238,15 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id(), true); - contents()->RemoveInfoBar(infobar_0); + contents_wrapper()->RemoveInfoBar(infobar_0); EXPECT_EQ(infobar_0, tab_contents_with_pending_infobar_->removed_infobar_delegate_); infobar_0->InfoBarClosed(); // Now we should have a new infobar for the second frame. - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); ConfirmInfoBarDelegate* infobar_1 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -248,11 +255,11 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { infobar_1->Cancel(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); CheckPermissionMessageSent(bridge_id() + 1, false); - contents()->RemoveInfoBar(infobar_1); + contents_wrapper()->RemoveInfoBar(infobar_1); EXPECT_EQ(infobar_1, tab_contents_with_pending_infobar_->removed_infobar_delegate_); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ALLOW, profile()->GetGeolocationContentSettingsMap()->GetContentSetting( @@ -273,16 +280,16 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { requesting_frame_1, requesting_frame_0)); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); ConfirmInfoBarDelegate* infobar_0 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -293,10 +300,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { EXPECT_EQ(infobar_0, tab_contents_with_pending_infobar_->removed_infobar_delegate_); infobar_0->InfoBarClosed(); - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); ConfirmInfoBarDelegate* infobar_1 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -305,11 +312,11 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { infobar_1->Accept(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id() + 1, true); - contents()->RemoveInfoBar(infobar_1); + contents_wrapper()->RemoveInfoBar(infobar_1); EXPECT_EQ(infobar_1, tab_contents_with_pending_infobar_->removed_infobar_delegate_); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ASK, profile()->GetGeolocationContentSettingsMap()->GetContentSetting( @@ -323,10 +330,10 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) { GURL invalid_embedder; GURL requesting_frame("about:blank"); NavigateAndCommit(invalid_embedder); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), false); } @@ -337,10 +344,10 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { AddNewTab(url_b); AddNewTab(url_a); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); @@ -355,11 +362,11 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { // Accept the first tab. ConfirmInfoBarDelegate* infobar_0 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); infobar_0->Accept(); CheckPermissionMessageSent(bridge_id(), true); - contents()->RemoveInfoBar(infobar_0); + contents_wrapper()->RemoveInfoBar(infobar_0); EXPECT_EQ(infobar_0, tab_contents_with_pending_infobar_->removed_infobar_delegate_); infobar_0->InfoBarClosed(); @@ -380,10 +387,10 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { NavigateAndCommit(url_a); AddNewTab(url_a); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); @@ -394,7 +401,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); ConfirmInfoBarDelegate* removed_infobar = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); // Accept the second tab. ConfirmInfoBarDelegate* infobar_0 = @@ -407,7 +414,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { extra_tabs_[0]->removed_infobar_delegate_); infobar_0->InfoBarClosed(); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), true); // Destroy the infobar that has just been removed. removed_infobar->InfoBarClosed(); @@ -442,16 +449,16 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { requesting_frame_1, requesting_frame_0)); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); // Ensure only one infobar is created. - EXPECT_EQ(1U, contents()->infobar_count()); + EXPECT_EQ(1U, contents_wrapper()->infobar_count()); ConfirmInfoBarDelegate* infobar_0 = - contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index a851f9e..b50d34c 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -13,10 +13,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/search_engines/template_url.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" #include "grit/generated_resources.h" #include "net/base/load_flags.h" @@ -31,7 +31,9 @@ InfoBarDelegate* CreateInfobar(TabContents* tab_contents, const GURL& new_google_url) { InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents, google_url_tracker, new_google_url); - tab_contents->AddInfoBar(infobar); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + wrapper->AddInfoBar(infobar); return infobar; } diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 0d2711f..6241808 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -20,6 +20,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_child_process_host.h" @@ -27,7 +28,6 @@ #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/common/desktop_notification_messages.h" #include "content/common/notification_service.h" @@ -508,6 +508,9 @@ void DesktopNotificationService::RequestPermission( if (!tab) return; + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + // If |origin| hasn't been seen before and the default content setting for // notifications is "ask", show an infobar. // The cache can only answer queries on the IO thread once it's initialized, @@ -515,9 +518,10 @@ void DesktopNotificationService::RequestPermission( ContentSetting setting = GetContentSetting(origin); if (setting == CONTENT_SETTING_ASK) { // Show an info bar requesting permission. - tab->AddInfoBar(new NotificationPermissionInfoBarDelegate( - tab, origin, DisplayNameForOrigin(origin), process_id, - route_id, callback_context)); + wrapper->AddInfoBar( + new NotificationPermissionInfoBarDelegate( + tab, origin, DisplayNameForOrigin(origin), process_id, + route_id, callback_context)); } else { // Notify renderer immediately. RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc index 42f7de1..375db47 100644 --- a/chrome/browser/omnibox_search_hint.cc +++ b/chrome/browser/omnibox_search_hint.cc @@ -21,9 +21,9 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "content/common/notification_type.h" @@ -81,7 +81,7 @@ class HintInfoBar : public ConfirmInfoBarDelegate { }; HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint) - : ConfirmInfoBarDelegate(omnibox_hint->tab()), + : ConfirmInfoBarDelegate(omnibox_hint->tab()->tab_contents()), omnibox_hint_(omnibox_hint), action_taken_(false), should_expire_(false), @@ -144,7 +144,7 @@ bool HintInfoBar::Accept() { // OmniboxSearchHint ---------------------------------------------------------- -OmniboxSearchHint::OmniboxSearchHint(TabContents* tab) : tab_(tab) { +OmniboxSearchHint::OmniboxSearchHint(TabContentsWrapper* tab) : tab_(tab) { NavigationController* controller = &(tab->controller()); notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, diff --git a/chrome/browser/omnibox_search_hint.h b/chrome/browser/omnibox_search_hint.h index 2f27ea1..ac90c0c 100644 --- a/chrome/browser/omnibox_search_hint.h +++ b/chrome/browser/omnibox_search_hint.h @@ -13,7 +13,7 @@ #include "content/common/notification_registrar.h" class Profile; -class TabContents; +class TabContentsWrapper; // This class is responsible for showing an info-bar that tells the user she // can type her search query directly in the omnibox. @@ -22,7 +22,7 @@ class TabContents; // info-bar. class OmniboxSearchHint : public NotificationObserver { public: - explicit OmniboxSearchHint(TabContents* tab); + explicit OmniboxSearchHint(TabContentsWrapper* tab); ~OmniboxSearchHint(); // NotificationObserver method: @@ -34,7 +34,7 @@ class OmniboxSearchHint : public NotificationObserver { // queries can be typed directly in there. void ShowEnteringQuery(); - TabContents* tab() { return tab_; } + TabContentsWrapper* tab() { return tab_; } // Disables the hint infobar permanently, so that it does not show ever again. void DisableHint(); @@ -49,7 +49,7 @@ class OmniboxSearchHint : public NotificationObserver { NotificationRegistrar notification_registrar_; // The tab we are associated with. - TabContents* tab_; + TabContentsWrapper* tab_; // A map containing the URLs of the search engine for which we want to // trigger the hint. diff --git a/chrome/browser/password_manager_delegate_impl.cc b/chrome/browser/password_manager_delegate_impl.cc index 1a518ba..b873b2e 100644 --- a/chrome/browser/password_manager_delegate_impl.cc +++ b/chrome/browser/password_manager_delegate_impl.cc @@ -9,9 +9,9 @@ #include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/autofill_messages.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" @@ -115,8 +115,8 @@ void PasswordManagerDelegateImpl::FillPasswordForm( void PasswordManagerDelegateImpl::AddSavePasswordInfoBar( PasswordFormManager* form_to_save) { - tab_contents_->AddInfoBar( - new SavePasswordInfoBarDelegate(tab_contents_, form_to_save)); + tab_contents_->AddInfoBar(new SavePasswordInfoBarDelegate( + tab_contents_->tab_contents(), form_to_save)); } Profile* PasswordManagerDelegateImpl::GetProfileForPasswordManager() { diff --git a/chrome/browser/password_manager_delegate_impl.h b/chrome/browser/password_manager_delegate_impl.h index d7a0650..82e58f3fe 100644 --- a/chrome/browser/password_manager_delegate_impl.h +++ b/chrome/browser/password_manager_delegate_impl.h @@ -8,11 +8,11 @@ #include "base/basictypes.h" #include "chrome/browser/password_manager/password_manager_delegate.h" -class TabContents; +class TabContentsWrapper; class PasswordManagerDelegateImpl : public PasswordManagerDelegate { public: - explicit PasswordManagerDelegateImpl(TabContents* contents) + explicit PasswordManagerDelegateImpl(TabContentsWrapper* contents) : tab_contents_(contents) { } // PasswordManagerDelegate implementation. @@ -22,7 +22,7 @@ class PasswordManagerDelegateImpl : public PasswordManagerDelegate { virtual Profile* GetProfileForPasswordManager(); virtual bool DidLastPageLoadEncounterSSLErrors(); private: - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; DISALLOW_COPY_AND_ASSIGN(PasswordManagerDelegateImpl); }; diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc index 3fd20fb..2f28c74 100644 --- a/chrome/browser/pdf_unsupported_feature.cc +++ b/chrome/browser/pdf_unsupported_feature.cc @@ -11,13 +11,13 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/chrome_interstitial_page.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_content_client.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/pref_names.h" #include "content/browser/plugin_service.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/user_metrics.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" @@ -125,14 +125,14 @@ void OpenReaderUpdateURL(TabContents* tab) { } // Opens the PDF using Adobe Reader. -void OpenUsingReader(TabContents* tab, +void OpenUsingReader(TabContentsWrapper* tab, const WebPluginInfo& reader_plugin, InfoBarDelegate* old_delegate, InfoBarDelegate* new_delegate) { PluginService::OverriddenPlugin plugin; - plugin.render_process_id = tab->GetRenderProcessHost()->id(); + plugin.render_process_id = tab->render_view_host()->process()->id(); plugin.render_view_id = tab->render_view_host()->routing_id(); - plugin.url = tab->GetURL(); + plugin.url = tab->tab_contents()->GetURL(); plugin.plugin = reader_plugin; // The plugin is disabled, so enable it to get around the renderer check. // Also give it a new version so that the renderer doesn't show the blocked @@ -158,9 +158,11 @@ void OpenUsingReader(TabContents* tab, class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { public: PDFUnsupportedFeatureInterstitial( - TabContents* tab, + TabContentsWrapper* tab, const WebPluginInfo& reader_webplugininfo) - : ChromeInterstitialPage(tab, false, tab->GetURL()), + : ChromeInterstitialPage( + tab->tab_contents(), false, tab->tab_contents()->GetURL()), + tab_contents_(tab), reader_webplugininfo_(reader_webplugininfo) { UserMetrics::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); } @@ -210,7 +212,7 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { } else if (command == "2") { UserMetrics::RecordAction( UserMetricsAction("PDF_ReaderInterstitialIgnore")); - OpenUsingReader(tab(), reader_webplugininfo_, NULL, NULL); + OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL); } else { NOTREACHED(); } @@ -218,6 +220,7 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { } private: + TabContentsWrapper* tab_contents_; WebPluginInfo reader_webplugininfo_; DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); @@ -229,7 +232,7 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { public: // |reader_group| is NULL if Adobe Reader isn't installed. - PDFUnsupportedFeatureInfoBarDelegate(TabContents* tab_contents, + PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, PluginGroup* reader_group); virtual ~PDFUnsupportedFeatureInfoBarDelegate(); @@ -245,7 +248,7 @@ class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { bool OnYes(); void OnNo(); - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; bool reader_installed_; bool reader_vulnerable_; WebPluginInfo reader_webplugininfo_; @@ -254,9 +257,9 @@ class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { }; PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( - TabContents* tab_contents, + TabContentsWrapper* tab_contents, PluginGroup* reader_group) - : ConfirmInfoBarDelegate(tab_contents), + : ConfirmInfoBarDelegate(tab_contents->tab_contents()), tab_contents_(tab_contents), reader_installed_(!!reader_group), reader_vulnerable_(false) { @@ -317,7 +320,7 @@ string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const { bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { if (!reader_installed_) { UserMetrics::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK")); - OpenReaderUpdateURL(tab_contents_); + OpenReaderUpdateURL(tab_contents_->tab_contents()); return true; } @@ -334,7 +337,7 @@ bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { if (tab_contents_->profile()->GetPrefs()->GetBoolean( prefs::kPluginsShowSetReaderDefaultInfobar)) { InfoBarDelegate* bar = - new PDFEnableAdobeReaderInfoBarDelegate(tab_contents_); + new PDFEnableAdobeReaderInfoBarDelegate(tab_contents_->tab_contents()); OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar); return false; } @@ -350,7 +353,7 @@ void PDFUnsupportedFeatureInfoBarDelegate::OnNo() { } // namespace -void PDFHasUnsupportedFeature(TabContents* tab) { +void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { #if !defined(OS_WIN) // Only works for Windows for now. For Mac, we'll have to launch the file // externally since Adobe Reader doesn't work inside Chrome. diff --git a/chrome/browser/pdf_unsupported_feature.h b/chrome/browser/pdf_unsupported_feature.h index e6e4f64..f3ab921 100644 --- a/chrome/browser/pdf_unsupported_feature.h +++ b/chrome/browser/pdf_unsupported_feature.h @@ -8,12 +8,12 @@ #include "base/basictypes.h" -class TabContents; +class TabContentsWrapper; // Call this when a tab encounters a PDF that has features which our internal // viewer doesn't support. Will take care of puting up an infobar to inform the // user and launch Reader if they choose. If Reader is out of date, it will put // up an interstitial. -void PDFHasUnsupportedFeature(TabContents* tab); +void PDFHasUnsupportedFeature(TabContentsWrapper* tab); #endif // CHROME_BROWSER_PDF_UNSUPPORTED_FEATURE_H_ diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index dabdac1..da09dc6 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -11,10 +11,10 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/user_metrics.h" #include "content/common/view_messages.h" #include "grit/generated_resources.h" @@ -303,17 +303,19 @@ void PluginObserver::OnMissingPluginStatus(int status) { // TODO(PORT): pull in when plug-ins work #if defined(OS_WIN) if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) { - tab_contents()->AddInfoBar( - new PluginInstallerInfoBarDelegate(tab_contents())); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents())-> + AddInfoBar(new PluginInstallerInfoBarDelegate(tab_contents())); return; } DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD, status); - for (size_t i = 0; i < tab_contents()->infobar_count(); ++i) { - InfoBarDelegate* delegate = tab_contents()->GetInfoBarDelegateAt(i); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); + for (size_t i = 0; i < wrapper->infobar_count(); ++i) { + InfoBarDelegate* delegate = wrapper->GetInfoBarDelegateAt(i); if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) { - tab_contents()->RemoveInfoBar(delegate); + wrapper->RemoveInfoBar(delegate); return; } } @@ -339,16 +341,18 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { } gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( IDR_INFOBAR_PLUGIN_CRASHED); - tab_contents()->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), - icon, - l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), - true)); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents())->AddInfoBar( + new SimpleAlertInfoBarDelegate(tab_contents(), + icon, + l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), + true)); } void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url) { - tab_contents()->AddInfoBar(update_url.is_empty() ? - static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( - tab_contents(), name)) : - new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents())->AddInfoBar( + update_url.is_empty() ? + static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( + tab_contents(), name)) : + new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); } diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc index b1ae045..a0bd215 100644 --- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc +++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc @@ -13,7 +13,7 @@ #include "chrome/browser/ssl_client_certificate_selector.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" -#include "content/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "grit/generated_resources.h" @@ -137,10 +137,12 @@ TabContentsSSLHelper::SSLAddCertData::~SSLAddCertData() { void TabContentsSSLHelper::SSLAddCertData::ShowInfoBar( InfoBarDelegate* delegate) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); if (infobar_delegate_) - tab_contents_->ReplaceInfoBar(infobar_delegate_, delegate); + wrapper->ReplaceInfoBar(infobar_delegate_, delegate); else - tab_contents_->AddInfoBar(delegate); + wrapper->AddInfoBar(delegate); infobar_delegate_ = delegate; } diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc index 5f9455e..537efb8 100644 --- a/chrome/browser/task_manager/task_manager_browsertest.cc +++ b/chrome/browser/task_manager/task_manager_browsertest.cc @@ -21,10 +21,10 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/page_transition_types.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" @@ -396,7 +396,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, // Reload the extension using the "crashed extension" infobar while the task // manager is still visible. Make sure we don't crash and the extension // gets reloaded and noticed in the task manager. - TabContents* current_tab = browser()->GetSelectedTabContents(); + TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); ASSERT_EQ(1U, current_tab->infobar_count()); ConfirmInfoBarDelegate* delegate = current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc index 5537e83..3c39bce 100644 --- a/chrome/browser/translate/translate_infobar_delegate.cc +++ b/chrome/browser/translate/translate_infobar_delegate.cc @@ -14,7 +14,6 @@ #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_constants.h" -#include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" #include "ui/base/l10n/l10n_util.h" @@ -111,7 +110,8 @@ void TranslateInfoBarDelegate::Translate() { void TranslateInfoBarDelegate::RevertTranslation() { TranslateManager::GetInstance()->RevertTranslation(tab_contents_); - tab_contents_->RemoveInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + RemoveInfoBar(this); } void TranslateInfoBarDelegate::ReportLanguageDetectionError() { @@ -145,7 +145,8 @@ void TranslateInfoBarDelegate::ToggleLanguageBlacklist() { prefs_.RemoveLanguageFromBlacklist(original_lang); } else { prefs_.BlacklistLanguage(original_lang); - tab_contents_->RemoveInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + RemoveInfoBar(this); } } @@ -163,7 +164,8 @@ void TranslateInfoBarDelegate::ToggleSiteBlacklist() { prefs_.RemoveSiteFromBlacklist(host); } else { prefs_.BlacklistSite(host); - tab_contents_->RemoveInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + RemoveInfoBar(this); } } @@ -193,7 +195,8 @@ void TranslateInfoBarDelegate::NeverTranslatePageLanguage() { std::string original_lang = GetOriginalLanguageCode(); DCHECK(!prefs_.IsLanguageBlacklisted(original_lang)); prefs_.BlacklistLanguage(original_lang); - tab_contents_->RemoveInfoBar(this); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + RemoveInfoBar(this); } string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc index 98e7f20..2ccba27 100644 --- a/chrome/browser/translate/translate_manager.cc +++ b/chrome/browser/translate/translate_manager.cc @@ -418,8 +418,9 @@ void TranslateManager::InitiateTranslation(TabContents* tab, return; } - TranslateTabHelper* helper = TabContentsWrapper::GetCurrentWrapperForContents( - tab)->translate_tab_helper(); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + TranslateTabHelper* helper = wrapper->translate_tab_helper(); std::string auto_translate_to = helper->language_state().AutoTranslateTo(); if (!auto_translate_to.empty()) { // This page was navigated through a click from a translated page. @@ -428,7 +429,7 @@ void TranslateManager::InitiateTranslation(TabContents* tab, } // Prompts the user if he/she wants the page translated. - tab->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( + wrapper->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, page_lang, target_lang)); } @@ -642,11 +643,13 @@ void TranslateManager::ShowInfoBar(TabContents* tab, TranslateInfoBarDelegate* infobar) { TranslateInfoBarDelegate* old_infobar = GetTranslateInfoBarDelegate(tab); infobar->UpdateBackgroundAnimation(old_infobar); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); if (old_infobar) { // There already is a translate infobar, simply replace it. - tab->ReplaceInfoBar(old_infobar, infobar); + wrapper->ReplaceInfoBar(old_infobar, infobar); } else { - tab->AddInfoBar(infobar); + wrapper->AddInfoBar(infobar); } } @@ -660,9 +663,11 @@ std::string TranslateManager::GetTargetLanguage() { // static TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( TabContents* tab) { - for (size_t i = 0; i < tab->infobar_count(); ++i) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + for (size_t i = 0; i < wrapper->infobar_count(); ++i) { TranslateInfoBarDelegate* delegate = - tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); + wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); if (delegate) return delegate; } diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index a5103f3..797b2c6 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/translate/translate_manager.h" #include "chrome/browser/translate/translate_prefs.h" #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/net/test_url_fetcher_factory.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -84,9 +85,9 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, // Returns the translate infobar if there is 1 infobar and it is a translate // infobar. TranslateInfoBarDelegate* GetTranslateInfoBar() { - return (contents()->infobar_count() == 1) ? - contents()->GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate() : - NULL; + return (contents_wrapper()->infobar_count() == 1) ? + contents_wrapper()->GetInfoBarDelegateAt(0)-> + AsTranslateInfoBarDelegate() : NULL; } // If there is 1 infobar and it is a translate infobar, closes it and returns @@ -96,7 +97,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, if (!infobar) return false; infobar->InfoBarDismissed(); // Simulates closing the infobar. - contents()->RemoveInfoBar(infobar); + contents_wrapper()->RemoveInfoBar(infobar); return true; } @@ -129,7 +130,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, if (!infobar) return false; infobar->TranslationDeclined(); - contents()->RemoveInfoBar(infobar); + contents_wrapper()->RemoveInfoBar(infobar); return true; } @@ -545,18 +546,18 @@ TEST_F(TranslateManagerTest, MultipleOnPageContents) { // Simulate clicking 'Nope' (don't translate). EXPECT_TRUE(DenyTranslation()); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Send a new PageContents, we should not show an infobar. SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); // Do the same steps but simulate closing the infobar this time. SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); EXPECT_TRUE(CloseTranslateInfoBar()); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, contents()->infobar_count()); + EXPECT_EQ(0U, contents_wrapper()->infobar_count()); } // Test that reloading the page brings back the infobar. diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index a9619cf..bdc2949 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -113,7 +113,6 @@ #include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/user_metrics.h" #include "content/common/content_restriction.h" @@ -3404,10 +3403,11 @@ void Browser::ContentRestrictionsChanged(TabContents* source) { } void Browser::WorkerCrashed() { - TabContents* tab_contents = GetSelectedTabContents(); + TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); if (!tab_contents) return; - tab_contents->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents, NULL, + tab_contents->AddInfoBar(new SimpleAlertInfoBarDelegate( + tab_contents->tab_contents(), NULL, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true)); } diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index 9ae505f..ba68646 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -62,7 +62,6 @@ #include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" #include "content/common/result_codes.h" #include "grit/chromium_strings.h" @@ -253,10 +252,10 @@ void NotifyNotDefaultBrowserTask::Run() { // Don't show the info-bar if there are already info-bars showing. // In ChromeBot tests, there might be a race. This line appears to get // called during shutdown and |tab| can be NULL. - TabContents* tab = browser->GetSelectedTabContents(); + TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); if (!tab || tab->infobar_count() > 0) return; - tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab)); + tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab->tab_contents())); } @@ -1024,14 +1023,14 @@ void BrowserInit::LaunchWithProfile::AddInfoBarsIfNecessary(Browser* browser) { if (!browser || !profile_ || browser->tab_count() == 0) return; - TabContents* tab_contents = browser->GetSelectedTabContents(); + TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); AddCrashedInfoBarIfNecessary(tab_contents); AddBadFlagsInfoBarIfNecessary(tab_contents); AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary(tab_contents); } void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( - TabContents* tab) { + TabContentsWrapper* tab) { // Assume that if the user is launching incognito they were previously // running incognito so that we have nothing to restore from. if (!profile_->DidLastSessionExitCleanly() && @@ -1039,12 +1038,12 @@ void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( // The last session didn't exit cleanly. Show an infobar to the user // so that they can restore if they want. The delegate deletes itself when // it is closed. - tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab)); + tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab->tab_contents())); } } void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( - TabContents* tab) { + TabContentsWrapper* tab) { // Unsupported flags for which to display a warning that "stability and // security will suffer". static const char* kBadFlags[] = { @@ -1068,7 +1067,7 @@ void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( } if (bad_flag) { - tab->AddInfoBar(new SimpleAlertInfoBarDelegate(tab, NULL, + tab->AddInfoBar(new SimpleAlertInfoBarDelegate(tab->tab_contents(), NULL, l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE, UTF8ToUTF16(std::string("--") + bad_flag)), false)); @@ -1127,11 +1126,12 @@ const char DNSCertProvenanceCheckingInfoBar::kLearnMoreURL[] = "http://dev.chromium.org/dnscertprovenancechecking"; void BrowserInit::LaunchWithProfile:: - AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary(TabContents* tab) { + AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary( + TabContentsWrapper* tab) { if (!command_line_.HasSwitch(switches::kEnableDNSCertProvenanceChecking)) return; - tab->AddInfoBar(new DNSCertProvenanceCheckingInfoBar(tab)); + tab->AddInfoBar(new DNSCertProvenanceCheckingInfoBar(tab->tab_contents())); } void BrowserInit::LaunchWithProfile::AddStartupURLs( diff --git a/chrome/browser/ui/browser_init.h b/chrome/browser/ui/browser_init.h index c00ab09..0b97956 100644 --- a/chrome/browser/ui/browser_init.h +++ b/chrome/browser/ui/browser_init.h @@ -18,7 +18,7 @@ class Browser; class CommandLine; class GURL; class Profile; -class TabContents; +class TabContentsWrapper; // class containing helpers for BrowserMain to spin up a new instance and // initialize the profile. @@ -175,16 +175,16 @@ class BrowserInit { // If the last session didn't exit cleanly and tab is a web contents tab, // an infobar is added allowing the user to restore the last session. - void AddCrashedInfoBarIfNecessary(TabContents* tab); + void AddCrashedInfoBarIfNecessary(TabContentsWrapper* tab); // If we have been started with unsupported flags like --single-process, // politely nag the user about it. - void AddBadFlagsInfoBarIfNecessary(TabContents* tab); + void AddBadFlagsInfoBarIfNecessary(TabContentsWrapper* tab); // If DNS based certificate checking has been enabled then we show a // warning infobar. void AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary( - TabContents* tab); + TabContentsWrapper* tab); // Adds additional startup URLs to the specified vector. void AddStartupURLs(std::vector<GURL>* startup_urls) const; diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index cd1c88a..873b1f5 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -1495,7 +1495,10 @@ enum { // applicable)? [self updateBookmarkBarVisibilityWithAnimation:NO]; - [infoBarContainerController_ changeTabContents:contents]; + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(contents); + // Without the .get(), xcode fails. + [infoBarContainerController_.get() changeTabContents:wrapper]; // Update devTools and sidebar contents after size for all views is set. [sidebarController_ ensureContentsVisible]; @@ -1526,7 +1529,9 @@ enum { } - (void)onTabDetachedWithContents:(TabContents*)contents { - [infoBarContainerController_ tabDetachedWithContents:contents]; + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(contents); + [infoBarContainerController_ tabDetachedWithContents:wrapper]; } - (void)userChangedTheme { diff --git a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm index 43854cb..2d6e4dc 100644 --- a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm +++ b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm @@ -215,8 +215,8 @@ void CollectedCookiesMac::OnSheetDidEnd(NSWindow* sheet) { - (void)windowWillClose:(NSNotification*)notif { if (contentSettingsChanged_) { - tabContents_->AddInfoBar( - new CollectedCookiesInfoBarDelegate(tabContents_)); + TabContentsWrapper::GetCurrentWrapperForContents(tabContents_)-> + AddInfoBar(new CollectedCookiesInfoBarDelegate(tabContents_)); } [allowedOutlineView_ setDelegate:nil]; [blockedOutlineView_ setDelegate:nil]; diff --git a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm index 67fbbd7..c68f7d7 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm @@ -29,8 +29,8 @@ static void ShowGenericExtensionInstalledInfoBar( if (!browser) return; - TabContents* tab_contents = browser->GetSelectedTabContents(); - if (!tab_contents) + TabContentsWrapper* wrapper = browser->GetSelectedTabContentsWrapper(); + if (!wrapper) return; string16 extension_name = UTF8ToUTF16(new_extension->name()); @@ -40,9 +40,9 @@ static void ShowGenericExtensionInstalledInfoBar( extension_name) + UTF8ToUTF16(" ") + l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO_MAC); - InfoBarDelegate* delegate = new SimpleAlertInfoBarDelegate(tab_contents, - new gfx::Image(new SkBitmap(icon)), msg, true); - tab_contents->AddInfoBar(delegate); + InfoBarDelegate* delegate = new SimpleAlertInfoBarDelegate( + wrapper->tab_contents(), new gfx::Image(new SkBitmap(icon)), msg, true); + wrapper->AddInfoBar(delegate); } namespace browser { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.h b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.h index b153bd6..a559dd6 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.h @@ -16,7 +16,7 @@ @class InfoBarController; class InfoBarDelegate; class InfoBarNotificationObserver; -class TabContents; +class TabContentsWrapper; class TabStripModel; // Protocol for basic container methods, as needed by an InfoBarController. @@ -48,7 +48,7 @@ const CGFloat kBaseHeight = 36.0; id<ViewResizer> resizeDelegate_; // weak // The TabContents we are currently showing infobars for. - TabContents* currentTabContents_; // weak + TabContentsWrapper* currentTabContents_; // weak // Holds the InfoBarControllers currently owned by this container. scoped_nsobject<NSMutableArray> infobarControllers_; @@ -88,12 +88,12 @@ const CGFloat kBaseHeight = 36.0; // infobars, removes them first and deregisters for any // notifications. |contents| can be NULL, in which case no infobars // are shown and no notifications are registered for. -- (void)changeTabContents:(TabContents*)contents; +- (void)changeTabContents:(TabContentsWrapper*)contents; // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents. // Forwarded by BWC. Removes all infobars and deregisters for any notifications // if |contents| is the current tab contents. -- (void)tabDetachedWithContents:(TabContents*)contents; +- (void)tabDetachedWithContents:(TabContentsWrapper*)contents; // Returns the number of active infobars. This is // |infobarControllers_ - closingInfoBars_|. diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm index 64b71c4..509b9b7 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm @@ -10,7 +10,7 @@ #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" #import "chrome/browser/ui/cocoa/view_id_util.h" -#include "content/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "skia/ext/skia_utils_mac.h" @@ -120,7 +120,7 @@ class InfoBarNotificationObserver : public NotificationObserver { [self positionInfoBarsAndRedraw]; } -- (void)changeTabContents:(TabContents*)contents { +- (void)changeTabContents:(TabContentsWrapper*)contents { registrar_.RemoveAll(); [self removeAllInfoBars]; @@ -131,7 +131,7 @@ class InfoBarNotificationObserver : public NotificationObserver { animate:NO]; } - Source<TabContents> source(currentTabContents_); + Source<TabContents> source(currentTabContents_->tab_contents()); registrar_.Add(infoBarObserver_.get(), NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); registrar_.Add(infoBarObserver_.get(), @@ -143,7 +143,7 @@ class InfoBarNotificationObserver : public NotificationObserver { [self positionInfoBarsAndRedraw]; } -- (void)tabDetachedWithContents:(TabContents*)contents { +- (void)tabDetachedWithContents:(TabContentsWrapper*)contents { if (currentTabContents_ == contents) [self changeTabContents:NULL]; } diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm index 265d122..d9cd41c 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar.mm @@ -18,10 +18,10 @@ #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/tab_contents.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -186,13 +186,13 @@ bool KeystonePromotionInfoBarDelegate::Cancel() { [[KeystoneGlue defaultKeystoneGlue] needsPromotion]) { Browser* browser = BrowserList::GetLastActive(); if (browser) { - TabContents* tabContents = browser->GetSelectedTabContents(); + TabContentsWrapper* wrapper = browser->GetSelectedTabContentsWrapper(); // Only show if no other info bars are showing, because that's how the // default browser info bar works. - if (tabContents && tabContents->infobar_count() == 0) { - tabContents->AddInfoBar( - new KeystonePromotionInfoBarDelegate(tabContents)); + if (wrapper && wrapper->infobar_count() == 0) { + wrapper->AddInfoBar(new KeystonePromotionInfoBarDelegate( + wrapper->tab_contents())); } } } diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc index 98890a7..9e51050 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc @@ -332,7 +332,7 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { virtual ~ContentSettingCookiesBubbleModel() { if (settings_changed()) { - tab_contents()->tab_contents()->AddInfoBar( + tab_contents()->AddInfoBar( new CollectedCookiesInfoBarDelegate(tab_contents()->tab_contents())); } } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 0e1d842..fca910d 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -1181,7 +1181,7 @@ void BrowserWindowGtk::TabSelectedAt(TabContentsWrapper* old_contents, // Update various elements that are interested in knowing the current // TabContents. - infobar_container_->ChangeTabContents(new_contents->tab_contents()); + infobar_container_->ChangeTabContents(new_contents); contents_container_->SetTab(new_contents); UpdateDevToolsForContents(new_contents->tab_contents()); diff --git a/chrome/browser/ui/gtk/collected_cookies_gtk.cc b/chrome/browser/ui/gtk/collected_cookies_gtk.cc index fb2222c..38d993c 100644 --- a/chrome/browser/ui/gtk/collected_cookies_gtk.cc +++ b/chrome/browser/ui/gtk/collected_cookies_gtk.cc @@ -14,7 +14,6 @@ #include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_source.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -430,7 +429,7 @@ void CollectedCookiesGtk::Observe(NotificationType type, void CollectedCookiesGtk::OnClose(GtkWidget* close_button) { if (status_changed_) { - tab_contents_->AddInfoBar( + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)->AddInfoBar( new CollectedCookiesInfoBarDelegate(tab_contents_)); } window_->CloseConstrainedWindow(); diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc index dc9ceab..57b1f71 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc @@ -16,7 +16,7 @@ #include "chrome/browser/ui/gtk/gtk_theme_service.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" -#include "content/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "third_party/skia/include/core/SkPaint.h" @@ -86,7 +86,7 @@ InfoBarContainerGtk::~InfoBarContainerGtk() { container_.Destroy(); } -void InfoBarContainerGtk::ChangeTabContents(TabContents* contents) { +void InfoBarContainerGtk::ChangeTabContents(TabContentsWrapper* contents) { if (tab_contents_) registrar_.RemoveAll(); @@ -96,7 +96,7 @@ void InfoBarContainerGtk::ChangeTabContents(TabContents* contents) { tab_contents_ = contents; if (tab_contents_) { UpdateInfoBars(); - Source<TabContents> source(tab_contents_); + Source<TabContents> source(tab_contents_->tab_contents()); registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.h b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.h index 5d6ee67..d4a728d 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.h +++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.h @@ -14,7 +14,7 @@ class InfoBar; class InfoBarDelegate; class Profile; -class TabContents; +class TabContentsWrapper; typedef struct _GtkWidget GtkWidget; @@ -29,7 +29,7 @@ class InfoBarContainerGtk : public NotificationObserver { // Changes the TabContents for which this container is showing InfoBars. Can // be NULL, in which case we will simply detach ourselves from the old tab // contents. - void ChangeTabContents(TabContents* contents); + void ChangeTabContents(TabContentsWrapper* contents); // Remove the specified InfoBarDelegate from the selected TabContents. This // will notify us back and cause us to close the View. This is called from @@ -74,7 +74,7 @@ class InfoBarContainerGtk : public NotificationObserver { Profile* profile_; // The TabContents for which we are currently showing InfoBars. - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; // VBox that holds the info bars. OwnedWidgetGtk container_; diff --git a/chrome/browser/ui/shell_dialogs.cc b/chrome/browser/ui/shell_dialogs.cc index 3e9593c..5b9d391 100644 --- a/chrome/browser/ui/shell_dialogs.cc +++ b/chrome/browser/ui/shell_dialogs.cc @@ -8,8 +8,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/pref_names.h" -#include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -51,7 +51,9 @@ void SelectFileDialog::SelectFile(Type type, if (!CanOpenSelectFileDialog()) { // Show the InfoBar saying that file-selection dialogs are disabled. if (source_contents) { - source_contents->AddInfoBar(new SimpleAlertInfoBarDelegate( + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(source_contents); + wrapper->AddInfoBar(new SimpleAlertInfoBarDelegate( source_contents, NULL, l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index e8787c8..f81d1c5 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -28,6 +28,7 @@ #include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/safe_browsing/client_side_detection_host.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/translate/translate_tab_helper.h" @@ -58,6 +59,7 @@ static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > TabContentsWrapper::TabContentsWrapper(TabContents* contents) : TabContentsObserver(contents), delegate_(NULL), + infobars_enabled_(true), tab_contents_(contents) { DCHECK(contents); DCHECK(!GetCurrentWrapperForContents(contents)); @@ -67,7 +69,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) // Create the tab helpers. autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); - autofill_manager_.reset(new AutofillManager(contents)); + autofill_manager_.reset(new AutofillManager(this)); automation_tab_helper_.reset(new AutomationTabHelper(contents)); blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); @@ -75,7 +77,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) extension_tab_helper_.reset(new ExtensionTabHelper(this)); favicon_tab_helper_.reset(new FaviconTabHelper(contents)); find_tab_helper_.reset(new FindTabHelper(contents)); - password_manager_delegate_.reset(new PasswordManagerDelegateImpl(contents)); + password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); password_manager_.reset( new PasswordManager(contents, password_manager_delegate_.get())); safebrowsing_detection_host_.reset( @@ -100,10 +102,20 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) // Set-up the showing of the omnibox search infobar if applicable. if (OmniboxSearchHint::IsEnabled(contents->profile())) - omnibox_search_hint_.reset(new OmniboxSearchHint(contents)); + omnibox_search_hint_.reset(new OmniboxSearchHint(this)); } TabContentsWrapper::~TabContentsWrapper() { + // Notify any lasting InfobarDelegates that have not yet been removed that + // whatever infobar they were handling in this TabContents has closed, + // because the TabContents is going away entirely. + // This must happen after the TAB_CONTENTS_DESTROYED notification as the + // notification may trigger infobars calls that access their delegate. (and + // some implementations of InfoBarDelegate do delete themselves on + // InfoBarClosed()). + for (size_t i = 0; i < infobar_count(); ++i) + infobar_delegates_[i]->InfoBarClosed(); + infobar_delegates_.clear(); } PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { @@ -270,7 +282,13 @@ TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( } //////////////////////////////////////////////////////////////////////////////// -// TabContentsWrapper, TabContentsObserver implementation: +// TabContentsWrapper implementation: + +void TabContentsWrapper::RenderViewGone() { + // Remove all infobars. + while (!infobar_delegates_.empty()) + RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); +} bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { bool handled = true; @@ -288,6 +306,123 @@ bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { return handled; } +void TabContentsWrapper::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::NAV_ENTRY_COMMITTED: { + DCHECK(&tab_contents_->controller() == + Source<NavigationController>(source).ptr()); + + NavigationController::LoadCommittedDetails& committed_details = + *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); + + // Only hide InfoBars when the user has done something that makes the main + // frame load. We don't want various automatic or subframe navigations + // making it disappear. + if (!committed_details.is_user_initiated_main_frame_load()) + return; + + // NOTE: It is not safe to change the following code to count upwards or + // use iterators, as the RemoveInfoBar() call synchronously modifies our + // delegate list. + for (size_t i = infobar_delegates_.size(); i > 0; --i) { + InfoBarDelegate* delegate = infobar_delegates_[i - 1]; + if (delegate->ShouldExpire(committed_details)) + RemoveInfoBar(delegate); + } + + break; + } + default: + NOTREACHED(); + } +} + +void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { + if (!infobars_enabled_) { + delegate->InfoBarClosed(); + return; + } + + // Look through the existing InfoBarDelegates we have for a match. If we've + // already got one that matches, then we don't add the new one. + for (size_t i = 0; i < infobar_delegates_.size(); ++i) { + if (infobar_delegates_[i]->EqualsDelegate(delegate)) { + // Tell the new infobar to close so that it can clean itself up. + delegate->InfoBarClosed(); + return; + } + } + + infobar_delegates_.push_back(delegate); + NotificationService::current()->Notify( + NotificationType::TAB_CONTENTS_INFOBAR_ADDED, + Source<TabContents>(tab_contents_.get()), + Details<InfoBarDelegate>(delegate)); + + // Add ourselves as an observer for navigations the first time a delegate is + // added. We use this notification to expire InfoBars that need to expire on + // page transitions. + if (infobar_delegates_.size() == 1) { + registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents_->controller())); + } +} + +void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { + if (!infobars_enabled_) + return; + + std::vector<InfoBarDelegate*>::iterator it = + find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); + if (it != infobar_delegates_.end()) { + InfoBarDelegate* delegate = *it; + NotificationService::current()->Notify( + NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, + Source<TabContents>(tab_contents_.get()), + Details<InfoBarDelegate>(delegate)); + + infobar_delegates_.erase(it); + // Remove ourselves as an observer if we are tracking no more InfoBars. + if (infobar_delegates_.empty()) { + registrar_.Remove( + this, NotificationType::NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents_->controller())); + } + } +} + +void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, + InfoBarDelegate* new_delegate) { + if (!infobars_enabled_) { + new_delegate->InfoBarClosed(); + return; + } + + std::vector<InfoBarDelegate*>::iterator it = + find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); + DCHECK(it != infobar_delegates_.end()); + + // Notify the container about the change of plans. + scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( + new std::pair<InfoBarDelegate*, InfoBarDelegate*>( + old_delegate, new_delegate)); + NotificationService::current()->Notify( + NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, + Source<TabContents>(tab_contents_.get()), + Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); + + // Remove the old one. + infobar_delegates_.erase(it); + + // Add the new one. + DCHECK(find(infobar_delegates_.begin(), + infobar_delegates_.end(), new_delegate) == + infobar_delegates_.end()); + infobar_delegates_.push_back(new_delegate); +} + //////////////////////////////////////////////////////////////////////////////// // Internal helpers @@ -315,7 +450,7 @@ void TabContentsWrapper::OnPageContents(const GURL& url, } void TabContentsWrapper::OnJSOutOfMemory() { - tab_contents()->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), + AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); } @@ -330,11 +465,11 @@ void TabContentsWrapper::OnRegisterProtocolHandler(const std::string& protocol, ProtocolHandler::CreateProtocolHandler(protocol, url, title); if (!handler.IsEmpty() && registry->CanSchemeBeOverridden(handler.protocol())) { - tab_contents()->AddInfoBar(registry->IsRegistered(handler) ? - static_cast<InfoBarDelegate*>(new SimpleAlertInfoBarDelegate( - tab_contents(), NULL, l10n_util::GetStringFUTF16( - IDS_REGISTER_PROTOCOL_HANDLER_ALREADY_REGISTERED, - handler.title(), UTF8ToUTF16(handler.protocol())), true)) : + AddInfoBar(registry->IsRegistered(handler) ? + static_cast<InfoBarDelegate*>(new SimpleAlertInfoBarDelegate( + tab_contents(), NULL, l10n_util::GetStringFUTF16( + IDS_REGISTER_PROTOCOL_HANDLER_ALREADY_REGISTERED, + handler.title(), UTF8ToUTF16(handler.protocol())), true)) : new RegisterProtocolHandlerInfoBarDelegate(tab_contents(), registry, handler)); } @@ -360,5 +495,5 @@ void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { } void TabContentsWrapper::OnPDFHasUnsupportedFeature() { - PDFHasUnsupportedFeature(tab_contents()); + PDFHasUnsupportedFeature(this); } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 8e91f35..aead86c 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include <vector> #include "base/basictypes.h" #include "base/compiler_specific.h" @@ -14,6 +15,7 @@ #include "chrome/browser/printing/print_view_manager.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/common/notification_registrar.h" namespace prerender { class PrerenderObserver; @@ -35,6 +37,7 @@ class ExtensionWebNavigationTabObserver; class FaviconTabHelper; class FileSelectObserver; class FindTabHelper; +class InfoBarDelegate; class NavigationController; class OmniboxSearchHint; class PasswordManager; @@ -55,7 +58,8 @@ class ClientSideDetectionHost; // TODO(pinkerton): Eventually, this class will become TabContents as far as // the browser front-end is concerned, and the current TabContents will be // renamed to something like WebPage or WebView (ben's suggestions). -class TabContentsWrapper : public TabContentsObserver { +class TabContentsWrapper : public TabContentsObserver, + public NotificationObserver { public: // Takes ownership of |contents|, which must be heap-allocated (as it lives // in a scoped_ptr) and can not be NULL. @@ -161,8 +165,34 @@ class TabContentsWrapper : public TabContentsObserver { // Overrides ----------------------------------------------------------------- // TabContentsObserver overrides: + virtual void RenderViewGone() OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + // NotificationObserver overrides: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) OVERRIDE; + + // Infobars ------------------------------------------------------------------ + + // Adds an InfoBar for the specified |delegate|. + void AddInfoBar(InfoBarDelegate* delegate); + + // Removes the InfoBar for the specified |delegate|. + void RemoveInfoBar(InfoBarDelegate* delegate); + + // Replaces one infobar with another, without any animation in between. + void ReplaceInfoBar(InfoBarDelegate* old_delegate, + InfoBarDelegate* new_delegate); + + // Enumeration and access functions. + size_t infobar_count() const { return infobar_delegates_.size(); } + void set_infobars_enabled(bool value) { infobars_enabled_ = value; } + // WARNING: This does not sanity-check |index|! + InfoBarDelegate* GetInfoBarDelegateAt(size_t index) { + return infobar_delegates_[index]; + } + private: // Internal helpers ---------------------------------------------------------- @@ -185,6 +215,12 @@ class TabContentsWrapper : public TabContentsObserver { // Delegate for notifying our owner about stuff. Not owned by us. TabContentsWrapperDelegate* delegate_; + // Delegates for InfoBars associated with this TabContentsWrapper. + std::vector<InfoBarDelegate*> infobar_delegates_; + bool infobars_enabled_; + + NotificationRegistrar registrar_; + // Data for current page ----------------------------------------------------- // Shows an info-bar to users when they search from a known search engine and diff --git a/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.cc index 8ae1173..0a06b8f 100644 --- a/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.cc @@ -27,6 +27,11 @@ void TabContentsWrapperTestHarness::SetContents(TestTabContents* contents) { contents_wrapper_.reset(new TabContentsWrapper(contents)); } +void TabContentsWrapperTestHarness::SetContentsWrapper( + TabContentsWrapper* contents) { + contents_wrapper_.reset(contents); +} + void TabContentsWrapperTestHarness::SetUp() { SetContents(CreateTestTabContents()); } diff --git a/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h index 7dc578c..89725b2 100644 --- a/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h @@ -20,6 +20,7 @@ class TabContentsWrapperTestHarness : public RenderViewHostTestHarness { TabContentsWrapper* contents_wrapper(); void SetContents(TestTabContents* contents); + void SetContentsWrapper(TabContentsWrapper* contents); protected: // testing::Test diff --git a/chrome/browser/ui/views/collected_cookies_win.cc b/chrome/browser/ui/views/collected_cookies_win.cc index 92474fa..390c257 100644 --- a/chrome/browser/ui/views/collected_cookies_win.cc +++ b/chrome/browser/ui/views/collected_cookies_win.cc @@ -11,7 +11,6 @@ #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/cookie_info_view.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "grit/generated_resources.h" @@ -379,7 +378,7 @@ void CollectedCookiesWin::DeleteDelegate() { bool CollectedCookiesWin::Cancel() { if (status_changed_) { - tab_contents_->AddInfoBar( + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)->AddInfoBar( new CollectedCookiesInfoBarDelegate(tab_contents_)); } diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 1f6dee6..4b199f7 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -2528,7 +2528,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents, // avoid an unnecessary resize and re-layout of a TabContents. if (change_tab_contents) contents_container_->ChangeTabContents(NULL); - infobar_container_->ChangeTabContents(new_contents->tab_contents()); + infobar_container_->ChangeTabContents(new_contents); UpdateUIForContents(new_contents); if (change_tab_contents) contents_container_->ChangeTabContents(new_contents->tab_contents()); diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc index ea0955e..4fe550c 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.cc +++ b/chrome/browser/ui/views/infobars/infobar_container.cc @@ -5,8 +5,8 @@ #include "chrome/browser/ui/views/infobars/infobar_container.h" #include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/infobars/infobar.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "ui/base/animation/slide_animation.h" @@ -25,7 +25,7 @@ InfoBarContainer::~InfoBarContainer() { DCHECK(infobars_.empty()); } -void InfoBarContainer::ChangeTabContents(TabContents* contents) { +void InfoBarContainer::ChangeTabContents(TabContentsWrapper* contents) { registrar_.RemoveAll(); while (!infobars_.empty()) { @@ -41,7 +41,7 @@ void InfoBarContainer::ChangeTabContents(TabContents* contents) { tab_contents_ = contents; if (tab_contents_) { - Source<TabContents> tc_source(tab_contents_); + Source<TabContents> tc_source(tab_contents_->tab_contents()); registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, tc_source); registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, @@ -49,7 +49,7 @@ void InfoBarContainer::ChangeTabContents(TabContents* contents) { registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, tc_source); - for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { + for (size_t i = 0; i < contents->infobar_count(); ++i) { // As when we removed the infobars above, we prevent callbacks to // OnInfoBarAnimated() for each infobar. AddInfoBar(tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(), false, diff --git a/chrome/browser/ui/views/infobars/infobar_container.h b/chrome/browser/ui/views/infobars/infobar_container.h index 293f811..312140c 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.h +++ b/chrome/browser/ui/views/infobars/infobar_container.h @@ -16,6 +16,7 @@ class InfoBar; class InfoBarDelegate; class TabContents; +class TabContentsWrapper; // InfoBarContainer is a cross-platform base class to handle the visibility- // related aspects of InfoBars. While InfoBars own themselves, the @@ -49,7 +50,7 @@ class InfoBarContainer : public NotificationObserver { // Changes the TabContents for which this container is showing infobars. This // will remove all current infobars from the container, add the infobars from // |contents|, and show them all. |contents| may be NULL. - void ChangeTabContents(TabContents* contents); + void ChangeTabContents(TabContentsWrapper* contents); // Returns the amount by which to overlap the toolbar above, and, when // |total_height| is non-NULL, set it to the height of the InfoBarContainer @@ -123,7 +124,7 @@ class InfoBarContainer : public NotificationObserver { NotificationRegistrar registrar_; Delegate* delegate_; - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; InfoBars infobars_; // Calculated in SetMaxTopArrowHeight(). diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index bf511cf..6e60971 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -30,7 +30,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/web_cache_manager.h" #include "chrome/browser/renderer_preferences_util.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -299,19 +298,6 @@ TabContents::~TabContents() { Source<TabContents>(this), NotificationService::NoDetails()); - // Notify any lasting InfobarDelegates that have not yet been removed that - // whatever infobar they were handling in this TabContents has closed, - // because the TabContents is going away entirely. - // This must happen after the TAB_CONTENTS_DESTROYED notification as the - // notification may trigger infobars calls that access their delegate. (and - // some implementations of InfoBarDelegate do delete themselves on - // InfoBarClosed()). - for (size_t i = 0; i < infobar_count(); ++i) { - InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); - delegate->InfoBarClosed(); - } - infobar_delegates_.clear(); - // TODO(brettw) this should be moved to the view. #if defined(OS_WIN) // If we still have a window handle, destroy it. GetNativeView can return @@ -744,89 +730,6 @@ void TabContents::SetFocusToLocationBar(bool select_all) { delegate()->SetFocusToLocationBar(select_all); } -void TabContents::AddInfoBar(InfoBarDelegate* delegate) { - if (delegate_ && !delegate_->infobars_enabled()) { - delegate->InfoBarClosed(); - return; - } - - // Look through the existing InfoBarDelegates we have for a match. If we've - // already got one that matches, then we don't add the new one. - for (size_t i = 0; i < infobar_count(); ++i) { - if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { - // Tell the new infobar to close so that it can clean itself up. - delegate->InfoBarClosed(); - return; - } - } - - infobar_delegates_.push_back(delegate); - NotificationService::current()->Notify( - NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this), - Details<InfoBarDelegate>(delegate)); - - // Add ourselves as an observer for navigations the first time a delegate is - // added. We use this notification to expire InfoBars that need to expire on - // page transitions. - if (infobar_delegates_.size() == 1) { - registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, - Source<NavigationController>(&controller_)); - } -} - -void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { - if (delegate_ && !delegate_->infobars_enabled()) { - return; - } - - std::vector<InfoBarDelegate*>::iterator it = - find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); - if (it != infobar_delegates_.end()) { - InfoBarDelegate* delegate = *it; - NotificationService::current()->Notify( - NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, - Source<TabContents>(this), - Details<InfoBarDelegate>(delegate)); - - infobar_delegates_.erase(it); - // Remove ourselves as an observer if we are tracking no more InfoBars. - if (infobar_delegates_.empty()) { - registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, - Source<NavigationController>(&controller_)); - } - } -} - -void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate) { - if (delegate_ && !delegate_->infobars_enabled()) { - new_delegate->InfoBarClosed(); - return; - } - - std::vector<InfoBarDelegate*>::iterator it = - find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); - DCHECK(it != infobar_delegates_.end()); - - // Notify the container about the change of plans. - scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( - new std::pair<InfoBarDelegate*, InfoBarDelegate*>( - old_delegate, new_delegate)); - NotificationService::current()->Notify( - NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, - Source<TabContents>(this), - Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); - - // Remove the old one. - infobar_delegates_.erase(it); - - // Add the new one. - DCHECK(find(infobar_delegates_.begin(), - infobar_delegates_.end(), new_delegate) == - infobar_delegates_.end()); - infobar_delegates_.push_back(new_delegate); -} - bool TabContents::ShouldShowBookmarkBar() { if (showing_interstitial_page()) return false; @@ -1205,24 +1108,6 @@ void TabContents::SetIsLoading(bool is_loading, det); } -void TabContents::ExpireInfoBars( - const NavigationController::LoadCommittedDetails& details) { - // Only hide InfoBars when the user has done something that makes the main - // frame load. We don't want various automatic or subframe navigations making - // it disappear. - if (!details.is_user_initiated_main_frame_load()) - return; - - // NOTE: It is not safe to change the following code to count upwards or use - // iterators, as the RemoveInfoBar() call synchronously modifies our delegate - // list. - for (size_t i = infobar_count(); i > 0; --i) { - InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); - if (delegate->ShouldExpire(details)) - RemoveInfoBar(delegate); - } -} - WebUI* TabContents::GetWebUIForCurrentState() { // When there is a pending navigation entry, we want to use the pending WebUI // that goes along with it to control the basic flags. For example, we want to @@ -1584,10 +1469,6 @@ void TabContents::RenderViewGone(RenderViewHost* rvh, NotifyDisconnected(); SetIsCrashed(status, error_code); - // Remove all infobars. - while (!infobar_delegates_.empty()) - RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); - // Tell the view that we've crashed so it can prepare the sad tab page. // Only do this if we're not in browser shutdown, so that TabContents // objects that are not in a browser (e.g., HTML dialogs) and thus are @@ -2146,15 +2027,6 @@ void TabContents::Observe(NotificationType type, view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); break; - case NotificationType::NAV_ENTRY_COMMITTED: { - DCHECK(&controller_ == Source<NavigationController>(source).ptr()); - - NavigationController::LoadCommittedDetails& committed_details = - *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); - ExpireInfoBars(committed_details); - break; - } - #if defined(OS_LINUX) case NotificationType::BROWSER_THEME_CHANGED: { renderer_preferences_util::UpdateFromSystemSettings( diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index c3e5544..56980fb 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -9,7 +9,6 @@ #include <deque> #include <map> #include <string> -#include <vector> #include "base/basictypes.h" #include "base/gtest_prod_util.h" @@ -47,7 +46,6 @@ class HistoryAddPageArgs; class WebUI; class DownloadItem; class Extension; -class InfoBarDelegate; class LoadNotificationDetails; class PluginObserver; class Profile; @@ -365,25 +363,6 @@ class TabContents : public PageNavigator, // Creates a view and sets the size for the specified RVH. virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh); - // Infobars ------------------------------------------------------------------ - - // Adds an InfoBar for the specified |delegate|. - void AddInfoBar(InfoBarDelegate* delegate); - - // Removes the InfoBar for the specified |delegate|. - void RemoveInfoBar(InfoBarDelegate* delegate); - - // Replaces one infobar with another, without any animation in between. - void ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate); - - // Enumeration and access functions. - size_t infobar_count() const { return infobar_delegates_.size(); } - // WARNING: This does not sanity-check |index|! - InfoBarDelegate* GetInfoBarDelegateAt(size_t index) { - return infobar_delegates_[index]; - } - // Toolbars and such --------------------------------------------------------- // Returns true if a Bookmark Bar should be shown for this tab. @@ -636,12 +615,6 @@ class TabContents : public PageNavigator, ConstrainedWindowList child_windows_; - // Expires InfoBars that need to be expired, according to the state carried - // in |details|, in response to a new NavigationEntry being committed (the - // user navigated to another page). - void ExpireInfoBars( - const NavigationController::LoadCommittedDetails& details); - // Navigation helpers -------------------------------------------------------- // // These functions are helpers for Navigate() and DidNavigate(). @@ -903,11 +876,6 @@ class TabContents : public PageNavigator, // True if this is a secure page which displayed insecure content. bool displayed_insecure_content_; - // Data for shelves and stuff ------------------------------------------------ - - // Delegates for InfoBars associated with this TabContents. - std::vector<InfoBarDelegate*> infobar_delegates_; - // Data for misc internal state ---------------------------------------------- // See capturing_contents() above. diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 9eb58df..7c9d9e7 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -180,10 +180,6 @@ gfx::NativeWindow TabContentsDelegate::GetFrameNativeWindow() { void TabContentsDelegate::TabContentsCreated(TabContents* new_contents) { } -bool TabContentsDelegate::infobars_enabled() { - return true; -} - bool TabContentsDelegate::ShouldEnablePreferredSizeNotifications() { return false; } diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index c0c0b61..4be48d4 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -265,9 +265,6 @@ class TabContentsDelegate { // typically happens when popups are created. virtual void TabContentsCreated(TabContents* new_contents); - // Returns whether infobars are enabled. Overrideable by child classes. - virtual bool infobars_enabled(); - // Whether the renderer should report its preferred size when it changes by // calling UpdatePreferredSize(). // Note that this is set when the RenderViewHost is created and cannot be |