diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 18:56:21 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 18:56:21 +0000 |
commit | 7e2041201c0de2336b80f5afb9e7bebeda6be68e (patch) | |
tree | bfda35d9f7b84ec7347baa35b18551bfae967967 /chrome/browser/geolocation | |
parent | fed17d435c43ab7ef492664196ec4535b3a48af5 (diff) | |
download | chromium_src-7e2041201c0de2336b80f5afb9e7bebeda6be68e.zip chromium_src-7e2041201c0de2336b80f5afb9e7bebeda6be68e.tar.gz chromium_src-7e2041201c0de2336b80f5afb9e7bebeda6be68e.tar.bz2 |
Move infobar handling to a tab helper, part 1.
Revert revert of r99187.
This reverts r99198.
BUG=94741
TEST=no visible change
Review URL: http://codereview.chromium.org/7810002
TBR=avi@chromium.org
Review URL: http://codereview.chromium.org/7827017
Review URL: http://codereview.chromium.org/7826014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
3 files changed, 70 insertions, 64 deletions
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc index d41be1c..fc7af06 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc @@ -13,6 +13,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" @@ -465,7 +466,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)); - wrapper->AddInfoBar(i->infobar_delegate); + wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate); } break; } @@ -489,7 +490,7 @@ GeolocationInfoBarQueueController::PendingInfoBarRequests::iterator // asynchronously. TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - wrapper->RemoveInfoBar(i->infobar_delegate); + wrapper->infobar_tab_helper()->RemoveInfoBar(i->infobar_delegate); return ++i; } diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 3109341..22836ed 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/infobar.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -101,6 +102,9 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id(); } int bridge_id() const { return 42; } // Not relevant at this level. + InfoBarTabHelper* infobar_tab_helper() { + return contents_wrapper()->infobar_tab_helper(); + } void CheckPermissionMessageSent(int bridge_id, bool allowed); void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); @@ -211,14 +215,14 @@ void GeolocationPermissionContextTests::TearDown() { TEST_F(GeolocationPermissionContextTests, SinglePermission) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); infobar_0->Cancel(); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); @@ -242,16 +246,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->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. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -260,16 +264,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id(), true); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); closed_delegate_tracker_.Clear(); infobar_0->InfoBarClosed(); // Now we should have a new infobar for the second frame. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -278,11 +282,11 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { infobar_1->Cancel(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); CheckPermissionMessageSent(bridge_id() + 1, false); - contents_wrapper()->RemoveInfoBar(infobar_1); + infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ALLOW, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -318,16 +322,16 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->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); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -339,10 +343,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); closed_delegate_tracker_.Clear(); infobar_0->InfoBarClosed(); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -351,11 +355,11 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { infobar_1->Accept(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id() + 1, true); - contents_wrapper()->RemoveInfoBar(infobar_1); + infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ASK, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -376,10 +380,10 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) { GURL invalid_embedder; GURL requesting_frame("about:blank"); NavigateAndCommit(invalid_embedder); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), false); } @@ -390,34 +394,34 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { AddNewTab(url_b); AddNewTab(url_a); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); - EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); + EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); - ASSERT_EQ(1U, extra_tabs_[1]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* removed_infobar = - extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]-> + infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); // Accept the first tab. - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); infobar_0->Accept(); CheckPermissionMessageSent(bridge_id(), true); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); + EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); CheckPermissionMessageSentForTab(1, bridge_id(), true); EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); closed_delegate_tracker_.Clear(); @@ -425,11 +429,11 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { removed_infobar->InfoBarClosed(); // But the other tab should still have the info bar... - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); infobar_1->Cancel(); - extra_tabs_[0]->RemoveInfoBar(infobar_1); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); @@ -443,34 +447,34 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { NavigateAndCommit(url_a); AddNewTab(url_a); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); - EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); + EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); ConfirmInfoBarDelegate* removed_infobar = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); // Accept the second tab. - ConfirmInfoBarDelegate* infobar_0 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); infobar_0->Accept(); CheckPermissionMessageSentForTab(0, bridge_id(), true); - extra_tabs_[0]->RemoveInfoBar(infobar_0); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), true); EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); closed_delegate_tracker_.Clear(); @@ -478,15 +482,15 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { removed_infobar->InfoBarClosed(); // And we should have the queued infobar displayed now. - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); // Accept the second infobar. - ConfirmInfoBarDelegate* infobar_1 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); infobar_1->Accept(); CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); - extra_tabs_[0]->RemoveInfoBar(infobar_1); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); @@ -514,16 +518,16 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { std::string())); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->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. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); // Delete the tab contents. diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index 43d89bd..c80f49c 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/geolocation/geolocation_settings_state.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/infobar.h" @@ -331,7 +332,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { observer.Wait(); } - tab_contents_wrapper->RemoveInfoBar(infobar_); + tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(infobar_); LOG(WARNING) << "infobar response set"; infobar_ = NULL; EXPECT_GT(settings_state.state_map().size(), state_map_size); @@ -576,12 +577,12 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, iframe_xpath_ = L"//iframe[@id='iframe_1']"; AddGeolocationWatch(true); - size_t num_infobars_before_cancel = - current_browser_->GetSelectedTabContentsWrapper()->infobar_count(); + InfoBarTabHelper* infobar_helper = current_browser_-> + GetSelectedTabContentsWrapper()->infobar_tab_helper(); + size_t num_infobars_before_cancel = infobar_helper->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_->GetSelectedTabContentsWrapper()->infobar_count(); + size_t num_infobars_after_cancel = infobar_helper->infobar_count(); EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); } |