diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-19 15:05:24 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-19 15:05:24 +0000 |
commit | 992e2915cebcd5cffecef766167015e45175cfa4 (patch) | |
tree | ba8f1c69416c0ee74cc603b6720f8edbaad92fa2 /chrome/browser | |
parent | 261ab7c41385753f006f8cb95ab2ab642fd2ed7a (diff) | |
download | chromium_src-992e2915cebcd5cffecef766167015e45175cfa4.zip chromium_src-992e2915cebcd5cffecef766167015e45175cfa4.tar.gz chromium_src-992e2915cebcd5cffecef766167015e45175cfa4.tar.bz2 |
Remove old popup blocker.
This also removes the --disable-better-popup-blocking command line flag.
The BlockedContentTabHelper is now exclusively used by instant.
I moved the remaining browser tests to the new popup blocking
infrastructure.
BUG=none
R=bauerb@chromium.org
Review URL: https://chromiumcodereview.appspot.com/22854020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
11 files changed, 196 insertions, 495 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index e50df30..97d2761 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -2003,11 +2003,6 @@ bool ChromeContentBrowserClient::CanCreateWindow( } #if !defined(OS_ANDROID) - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking)) { - return true; - } - if (is_guest) return true; diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc index b1a2b08..380ba1c 100644 --- a/chrome/browser/extensions/app_process_apitest.cc +++ b/chrome/browser/extensions/app_process_apitest.cc @@ -10,7 +10,6 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/process_map.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -660,24 +659,16 @@ IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) { browser(), GetTestBaseURL("app_process").Resolve("path3/container.html")); WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); - BlockedContentTabHelper* blocked_content_tab_helper = - BlockedContentTabHelper::FromWebContents(tab); PopupBlockerTabHelper* popup_blocker_tab_helper = PopupBlockerTabHelper::FromWebContents(tab); - if (!blocked_content_tab_helper->GetBlockedContentsCount() && - (!popup_blocker_tab_helper || - !popup_blocker_tab_helper->GetBlockedPopupsCount())) { + if (!popup_blocker_tab_helper->GetBlockedPopupsCount()) { content::WindowedNotificationObserver observer( chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, content::NotificationService::AllSources()); observer.Wait(); } - EXPECT_EQ(1u, - blocked_content_tab_helper->GetBlockedContentsCount() + - (popup_blocker_tab_helper - ? popup_blocker_tab_helper->GetBlockedPopupsCount() - : 0)); + EXPECT_EQ(1u, popup_blocker_tab_helper->GetBlockedPopupsCount()); } // Tests that if an extension launches an app via chrome.tabs.create with an URL diff --git a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc index f10c5d5..bb45102 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc +++ b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.cc @@ -42,18 +42,8 @@ void BlockedContentTabHelper::DidNavigateMainFrame( // for this tab, unless this is an in-page navigation. if (!details.is_in_page) { // Close blocked popups. - if (blocked_contents_->GetBlockedContentsCount()) { + if (blocked_contents_->GetBlockedContentsCount()) blocked_contents_->Clear(); - PopupNotificationVisibilityChanged(false); - } - } -} - -void BlockedContentTabHelper::PopupNotificationVisibilityChanged( - bool visible) { - if (!web_contents()->IsBeingDestroyed()) { - TabSpecificContentSettings::FromWebContents(web_contents())-> - SetPopupsBlocked(visible); } } @@ -84,69 +74,7 @@ void BlockedContentTabHelper::AddWebContents(content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { - if (!blocked_contents_->GetBlockedContentsCount()) - PopupNotificationVisibilityChanged(true); SendNotification(new_contents, true); blocked_contents_->AddWebContents( new_contents, disposition, initial_pos, user_gesture); } - -void BlockedContentTabHelper::AddPopup(content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) { - // A page can't spawn popups (or do anything else, either) until its load - // commits, so when we reach here, the popup was spawned by the - // NavigationController's last committed entry, not the active entry. For - // example, if a page opens a popup in an onunload() handler, then the active - // entry is the page to be loaded as we navigate away from the unloading - // page. For this reason, we can't use GetURL() to get the opener URL, - // because it returns the active entry. - NavigationEntry* entry = - web_contents()->GetController().GetLastCommittedEntry(); - GURL creator = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); - Profile* profile = - Profile::FromBrowserContext(web_contents()->GetBrowserContext()); - - if (creator.is_valid() && - profile->GetHostContentSettingsMap()->GetContentSetting( - creator, creator, CONTENT_SETTINGS_TYPE_POPUPS, std::string()) == - CONTENT_SETTING_ALLOW) { - content::WebContentsDelegate* delegate = web_contents()->GetDelegate(); - if (delegate) { - delegate->AddNewContents(web_contents(), - new_contents, - disposition, - initial_pos, - true, // user_gesture - NULL); - } - } else { - // Call blocked_contents_->AddWebContents with user_gesture == true - // so that the contents will not get blocked again. - SendNotification(new_contents, true); - blocked_contents_->AddWebContents(new_contents, - disposition, - initial_pos, - true); // user_gesture - TabSpecificContentSettings::FromWebContents(web_contents())-> - OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS, std::string()); - } -} - -void BlockedContentTabHelper::LaunchForContents( - content::WebContents* web_contents) { - SendNotification(web_contents, false); - blocked_contents_->LaunchForContents(web_contents); - if (!blocked_contents_->GetBlockedContentsCount()) - PopupNotificationVisibilityChanged(false); -} - -size_t BlockedContentTabHelper::GetBlockedContentsCount() const { - return blocked_contents_->GetBlockedContentsCount(); -} - -void BlockedContentTabHelper::GetBlockedContents( - std::vector<content::WebContents*>* blocked_contents) const { - blocked_contents_->GetBlockedContents(blocked_contents); -} diff --git a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h index 9807347..f3f624d 100644 --- a/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h +++ b/chrome/browser/ui/blocked_content/blocked_content_tab_helper.h @@ -15,7 +15,8 @@ class BlockedContentContainer; class BlockedContentTabHelperDelegate; -// Per-tab class to manage blocked popups. +// Collects WebContents objects spawned from the observed WebContents and +// optionally adds them to the tab strip later on. class BlockedContentTabHelper : public content::WebContentsObserver, public content::WebContentsUserData<BlockedContentTabHelper> { @@ -39,22 +40,6 @@ class BlockedContentTabHelper const gfx::Rect& initial_pos, bool user_gesture); - // Adds the incoming |new_contents| to the |blocked_contents_| container. - void AddPopup(content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture); - - // Shows the blocked WebContents |web_contents|. - void LaunchForContents(content::WebContents* web_contents); - - // Returns the number of blocked contents. - size_t GetBlockedContentsCount() const; - - // Returns the blocked WebContentses. |blocked_contents| must be non-NULL. - void GetBlockedContents( - std::vector<content::WebContents*>* blocked_contents) const; - // content::WebContentsObserver overrides: virtual void DidNavigateMainFrame( const content::LoadCommittedDetails& details, @@ -64,9 +49,6 @@ class BlockedContentTabHelper explicit BlockedContentTabHelper(content::WebContents* web_contents); friend class content::WebContentsUserData<BlockedContentTabHelper>; - // Called when the blocked popup notification is shown or hidden. - void PopupNotificationVisibilityChanged(bool visible); - // Called to notify any observers that |contents| is entering or leaving // the blocked state. void SendNotification(content::WebContents* contents, bool blocked_state); diff --git a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc index ca8e8a2..293cca3 100644 --- a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc +++ b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc @@ -14,7 +14,6 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -74,51 +73,52 @@ class CountRenderViewHosts : public content::NotificationObserver { class PopupBlockerBrowserTest : public InProcessBrowserTest { public: PopupBlockerBrowserTest() {} + virtual ~PopupBlockerBrowserTest() {} - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - InProcessBrowserTest::SetUpCommandLine(command_line); - command_line->AppendSwitch(switches::kDisableBetterPopupBlocking); - } - - // Returns a url that shows one popup. - GURL GetTestURL() { - return ui_test_utils::GetTestUrl( - base::FilePath(kTestDir), - base::FilePath(FILE_PATH_LITERAL("popup-blocked-to-post-blank.html"))); - } - - std::vector<WebContents*> GetBlockedContents(Browser* browser) { + int GetBlockedContentsCount() { // Do a round trip to the renderer first to flush any in-flight IPCs to // create a to-be-blocked window. - WebContents* tab = browser->tab_strip_model()->GetActiveWebContents(); + WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); CHECK(content::ExecuteScript(tab, std::string())); - BlockedContentTabHelper* blocked_content_tab_helper = - BlockedContentTabHelper::FromWebContents(tab); - std::vector<WebContents*> blocked_contents; - blocked_content_tab_helper->GetBlockedContents(&blocked_contents); - return blocked_contents; + PopupBlockerTabHelper* popup_blocker_helper = + PopupBlockerTabHelper::FromWebContents(tab); + return popup_blocker_helper->GetBlockedPopupsCount(); } - void NavigateAndCheckPopupShown(Browser* browser, const GURL& url) { + void NavigateAndCheckPopupShown(const GURL& url) { content::WindowedNotificationObserver observer( chrome::NOTIFICATION_TAB_ADDED, content::NotificationService::AllSources()); - ui_test_utils::NavigateToURL(browser, url); + ui_test_utils::NavigateToURL(browser(), url); observer.Wait(); - ASSERT_EQ(2u, chrome::GetBrowserCount(browser->profile(), - browser->host_desktop_type())); + ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), + browser()->host_desktop_type())); - std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); - ASSERT_TRUE(blocked_contents.empty()); + ASSERT_EQ(0, GetBlockedContentsCount()); } - void BasicTest(Browser* browser, const GURL& url) { + // Navigates to the test indicated by |test_name| using |browser| which is + // expected to try to open a popup. Verifies that the popup was blocked and + // then opens the blocked popup. Once the popup stopped loading, verifies + // that the title of the page is "PASS" if |check_title| is true. + // + // If |expect_new_browser| is true, the popup is expected to open a new + // window, or a background tab if it is false. + // + // Returns the WebContents of the launched popup. + WebContents* RunCheckTest(Browser* browser, + const base::FilePath& test_name, + bool expect_new_browser, + bool check_title) { + GURL url(ui_test_utils::GetTestUrl(base::FilePath(kTestDir), test_name)); + + CountRenderViewHosts counter; + ui_test_utils::NavigateToURL(browser, url); - // If the popup blocker blocked the blank post, there should be only one - // tab in only one browser window and the URL of current tab must be equal - // to the original URL. + // Since the popup blocker blocked the window.open, there should be only one + // tab. EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile(), browser->host_desktop_type())); EXPECT_EQ(1, browser->tab_strip_model()->count()); @@ -126,50 +126,128 @@ class PopupBlockerBrowserTest : public InProcessBrowserTest { browser->tab_strip_model()->GetActiveWebContents(); EXPECT_EQ(url, web_contents->GetURL()); - std::vector<WebContents*> blocked_contents = GetBlockedContents(browser); - ASSERT_EQ(1u, blocked_contents.size()); + // And no new RVH created. + EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); content::WindowedNotificationObserver observer( chrome::NOTIFICATION_TAB_ADDED, content::NotificationService::AllSources()); + ui_test_utils::BrowserAddedObserver browser_observer; - BlockedContentTabHelper* blocked_content_tab_helper = - BlockedContentTabHelper::FromWebContents(web_contents); - blocked_content_tab_helper->LaunchForContents(blocked_contents[0]); + // Launch the blocked popup. + PopupBlockerTabHelper* popup_blocker_helper = + PopupBlockerTabHelper::FromWebContents(web_contents); + if (!popup_blocker_helper->GetBlockedPopupsCount()) { + content::WindowedNotificationObserver observer( + chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, + content::NotificationService::AllSources()); + observer.Wait(); + } + EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); + std::map<int32, GURL> blocked_requests = + popup_blocker_helper->GetBlockedPopupRequests(); + std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); + popup_blocker_helper->ShowBlockedPopup(iter->first); observer.Wait(); + Browser* new_browser; + if (expect_new_browser) { + new_browser = browser_observer.WaitForSingleNewBrowser(); + web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); + } else { + new_browser = browser; + EXPECT_EQ(2, browser->tab_strip_model()->count()); + web_contents = browser->tab_strip_model()->GetWebContentsAt(1); + } + + if (check_title) { + // Check that the check passed. + base::string16 expected_title(base::ASCIIToUTF16("PASS")); + content::TitleWatcher title_watcher(web_contents, expected_title); + EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); + } + + return web_contents; } + + private: + DISALLOW_COPY_AND_ASSIGN(PopupBlockerBrowserTest); }; -IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupBlockedPostBlank) { - BasicTest(browser(), GetTestURL()); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, + BlockWebContentsCreation) { +#if defined(OS_WIN) && defined(USE_ASH) + // Disable this test in Metro+Ash for now (http://crbug.com/262796). + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) + return; +#endif + + RunCheckTest( + browser(), + base::FilePath(FILE_PATH_LITERAL("popup-blocked-to-post-blank.html")), + true, + false); } IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, - PopupBlockedPostBlankIncognito) { - BasicTest(CreateIncognitoBrowser(), GetTestURL()); + BlockWebContentsCreationIncognito) { +#if defined(OS_WIN) && defined(USE_ASH) + // Disable this test in Metro+Ash for now (http://crbug.com/262796). + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) + return; +#endif + + RunCheckTest( + CreateIncognitoBrowser(), + base::FilePath(FILE_PATH_LITERAL("popup-blocked-to-post-blank.html")), + true, + false); } IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupBlockedFakeClickOnAnchor) { - GURL url(ui_test_utils::GetTestUrl( - base::FilePath(kTestDir), - base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor.html")))); - BasicTest(browser(), url); +#if defined(OS_WIN) && defined(USE_ASH) + // Disable this test in Metro+Ash for now (http://crbug.com/262796). + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) + return; +#endif + + RunCheckTest( + browser(), + base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor.html")), + false, + false); +} + +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, + PopupBlockedFakeClickOnAnchorNoTarget) { +#if defined(OS_WIN) && defined(USE_ASH) + // Disable this test in Metro+Ash for now (http://crbug.com/262796). + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) + return; +#endif + + RunCheckTest( + browser(), + base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor2.html")), + false, + false); } IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, MultiplePopups) { - GURL url(ui_test_utils::GetTestUrl(base::FilePath( - kTestDir), base::FilePath(FILE_PATH_LITERAL("popup-many.html")))); + GURL url(ui_test_utils::GetTestUrl( + base::FilePath(kTestDir), + base::FilePath(FILE_PATH_LITERAL("popup-many.html")))); ui_test_utils::NavigateToURL(browser(), url); - std::vector<WebContents*> blocked_contents = GetBlockedContents(browser()); - ASSERT_EQ(2u, blocked_contents.size()); + ASSERT_EQ(2, GetBlockedContentsCount()); } // Verify that popups are launched on browser back button. IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, AllowPopupThroughContentSetting) { - GURL url(GetTestURL()); + GURL url(ui_test_utils::GetTestUrl( + base::FilePath(kTestDir), + base::FilePath(FILE_PATH_LITERAL("popup-blocked-to-post-blank.html")))); browser()->profile()->GetHostContentSettingsMap() ->SetContentSetting(ContentSettingsPattern::FromURL(url), ContentSettingsPattern::Wildcard(), @@ -177,10 +255,11 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, std::string(), CONTENT_SETTING_ALLOW); - NavigateAndCheckPopupShown(browser(), url); + NavigateAndCheckPopupShown(url); } -IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupsLaunchWhenTabIsClosed) { +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, + PopupsLaunchWhenTabIsClosed) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kDisablePopupBlocking); GURL url = ui_test_utils::GetTestUrl( @@ -188,7 +267,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, PopupsLaunchWhenTabIsClosed) { base::FilePath(FILE_PATH_LITERAL("popup-on-unload.html"))); ui_test_utils::NavigateToURL(browser(), url); - NavigateAndCheckPopupShown(browser(), GURL(content::kAboutBlankURL)); + NavigateAndCheckPopupShown(GURL(content::kAboutBlankURL)); } // Verify that when you unblock popup, the popup shows in history and omnibox. @@ -196,8 +275,10 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, UnblockedPopupShowsInHistoryAndOmnibox) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kDisablePopupBlocking); - GURL url(GetTestURL()); - NavigateAndCheckPopupShown(browser(), url); + GURL url(ui_test_utils::GetTestUrl( + base::FilePath(kTestDir), + base::FilePath(FILE_PATH_LITERAL("popup-blocked-to-post-blank.html")))); + NavigateAndCheckPopupShown(url); std::string search_string = "data:text/html,<title>Popup Success!</title>you should not see this " @@ -219,281 +300,71 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, EXPECT_EQ(ASCIIToUTF16(search_string), model->CurrentMatch(NULL).contents); } -class BetterPopupBlockerBrowserTest : public PopupBlockerBrowserTest { - public: - BetterPopupBlockerBrowserTest() {} - virtual ~BetterPopupBlockerBrowserTest() {} - - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - InProcessBrowserTest::SetUpCommandLine(command_line); - } - - // Navigates to the test indicated by |test_name| which is expected to try to - // open a popup. Verifies that the popup was blocked and then opens the - // blocked popup. Once the popup stopped loading, verifies that the title of - // the page is "PASS". - // - // If |expect_new_browser| is true, the popup is expected to open a new - // window, or a background tab if it is false. - void RunCheckTest(const base::FilePath& test_name, bool expect_new_browser) { - GURL url(ui_test_utils::GetTestUrl(base::FilePath(kTestDir), test_name)); - - CountRenderViewHosts counter; - - ui_test_utils::NavigateToURL(browser(), url); - - // Since the popup blocker blocked the window.open, there should be only one - // tab. - EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), - browser()->host_desktop_type())); - EXPECT_EQ(1, browser()->tab_strip_model()->count()); - WebContents* web_contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(url, web_contents->GetURL()); - - // And no new RVH created. - EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TAB_ADDED, - content::NotificationService::AllSources()); - ui_test_utils::BrowserAddedObserver browser_observer; - - // Launch the blocked popup. - PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); - EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); - std::map<int32, GURL> blocked_requests = - popup_blocker_helper->GetBlockedPopupRequests(); - std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); - popup_blocker_helper->ShowBlockedPopup(iter->first); - - observer.Wait(); - Browser* new_browser; - if (expect_new_browser) { - new_browser = browser_observer.WaitForSingleNewBrowser(); - web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); - } else { - new_browser = browser(); - EXPECT_EQ(2, browser()->tab_strip_model()->count()); - web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); - } - - // Check that the check passed. - base::string16 expected_title(base::ASCIIToUTF16("PASS")); - content::TitleWatcher title_watcher(web_contents, expected_title); - EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); - } - - private: - DISALLOW_COPY_AND_ASSIGN(BetterPopupBlockerBrowserTest); -}; - -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, - BlockWebContentsCreation) { -#if defined(OS_WIN) && defined(USE_ASH) - // Disable this test in Metro+Ash for now (http://crbug.com/262796). - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) - return; -#endif - - CountRenderViewHosts counter; - - ui_test_utils::NavigateToURL(browser(), GetTestURL()); - - // Wait until the request actually has hit the popup blocker. The - // NavigateToURL call above returns as soon as the main tab stopped loading - // which can happen before the popup request was processed. - WebContents* web_contents = - browser()->tab_strip_model()->GetActiveWebContents(); - PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); - if (!popup_blocker_helper->GetBlockedPopupsCount()) { - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, - content::NotificationService::AllSources()); - observer.Wait(); - } - - // If the popup blocker blocked the blank post, there should be only one tab. - EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), - browser()->host_desktop_type())); - EXPECT_EQ(1, browser()->tab_strip_model()->count()); - EXPECT_EQ(GetTestURL(), web_contents->GetURL()); - - // And no new RVH created. - EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TAB_ADDED, - content::NotificationService::AllSources()); - - // Launch the blocked popup. - EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); - std::map<int32, GURL> blocked_requests = - popup_blocker_helper->GetBlockedPopupRequests(); - std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); - popup_blocker_helper->ShowBlockedPopup(iter->first); - - observer.Wait(); -} - -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, - PopupBlockedFakeClickOnAnchorNoTarget) { -#if defined(OS_WIN) && defined(USE_ASH) - // Disable this test in Metro+Ash for now (http://crbug.com/262796). - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) - return; -#endif - - GURL url(ui_test_utils::GetTestUrl( - base::FilePath(kTestDir), - base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor2.html")))); - - CountRenderViewHosts counter; - - ui_test_utils::NavigateToURL(browser(), url); - - // If the popup blocker blocked the blank post, there should be only one tab. - EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), - browser()->host_desktop_type())); - EXPECT_EQ(1, browser()->tab_strip_model()->count()); - WebContents* web_contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(url, web_contents->GetURL()); - - // And no new RVH created. - EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TAB_ADDED, - content::NotificationService::AllSources()); - - // Launch the blocked popup. - PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); - EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); - std::map<int32, GURL> blocked_requests = - popup_blocker_helper->GetBlockedPopupRequests(); - std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); - popup_blocker_helper->ShowBlockedPopup(iter->first); - - observer.Wait(); -} - -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeatures) { - GURL url(ui_test_utils::GetTestUrl( - base::FilePath(kTestDir), - base::FilePath(FILE_PATH_LITERAL("popup-window-open.html")))); - - CountRenderViewHosts counter; - - ui_test_utils::NavigateToURL(browser(), url); - - // If the popup blocker blocked the blank post, there should be only one tab. - EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), - browser()->host_desktop_type())); - EXPECT_EQ(1, browser()->tab_strip_model()->count()); - WebContents* web_contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(url, web_contents->GetURL()); - - // And no new RVH created. - EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TAB_ADDED, - content::NotificationService::AllSources()); - ui_test_utils::BrowserAddedObserver browser_observer; - - // Launch the blocked popup. - PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); - EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); - std::map<int32, GURL> blocked_requests = - popup_blocker_helper->GetBlockedPopupRequests(); - std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); - popup_blocker_helper->ShowBlockedPopup(iter->first); - - observer.Wait(); - Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WindowFeatures) { + WebContents* popup = + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-window-open.html")), + true, + false); // Check that the new popup has (roughly) the requested size. - web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); - gfx::Size window_size = web_contents->GetView()->GetContainerSize(); + gfx::Size window_size = popup->GetView()->GetContainerSize(); EXPECT_TRUE(349 <= window_size.width() && window_size.width() <= 351); EXPECT_TRUE(249 <= window_size.height() && window_size.height() <= 251); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, CorrectReferrer) { - RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-referrer.html")), true); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CorrectReferrer) { + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-referrer.html")), + true, + true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WindowFeaturesBarProps) { - RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html")), +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WindowFeaturesBarProps) { + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-windowfeatures.html")), + true, true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, SessionStorage) { - RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-sessionstorage.html")), +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, SessionStorage) { + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-sessionstorage.html")), + true, true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, Opener) { - RunCheckTest(base::FilePath(FILE_PATH_LITERAL("popup-opener.html")), true); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-opener.html")), + true, + true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, OpenerSuppressed) { - RunCheckTest( - base::FilePath(FILE_PATH_LITERAL("popup-openersuppressed.html")), false); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) { + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-openersuppressed.html")), + false, + true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, ShiftClick) { +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { RunCheckTest( + browser(), base::FilePath(FILE_PATH_LITERAL("popup-fake-click-on-anchor3.html")), + true, true); } -IN_PROC_BROWSER_TEST_F(BetterPopupBlockerBrowserTest, WebUI) { - GURL url(ui_test_utils::GetTestUrl( - base::FilePath(kTestDir), - base::FilePath(FILE_PATH_LITERAL("popup-webui.html")))); - - CountRenderViewHosts counter; - - ui_test_utils::NavigateToURL(browser(), url); - - // If the popup blocker blocked the blank post, there should be only one tab. - EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), - browser()->host_desktop_type())); - EXPECT_EQ(1, browser()->tab_strip_model()->count()); - WebContents* web_contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(url, web_contents->GetURL()); - - // And no new RVH created. - EXPECT_EQ(0, counter.GetRenderViewHostCreatedCount()); - - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TAB_ADDED, - content::NotificationService::AllSources()); - ui_test_utils::BrowserAddedObserver browser_observer; - - // Launch the blocked popup. - PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); - EXPECT_EQ(1u, popup_blocker_helper->GetBlockedPopupsCount()); - std::map<int32, GURL> blocked_requests = - popup_blocker_helper->GetBlockedPopupRequests(); - std::map<int32, GURL>::const_iterator iter = blocked_requests.begin(); - popup_blocker_helper->ShowBlockedPopup(iter->first); - - observer.Wait(); - Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); +IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WebUI) { + WebContents* popup = + RunCheckTest(browser(), + base::FilePath(FILE_PATH_LITERAL("popup-webui.html")), + true, + false); // Check that the new popup displays about:blank. - web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(GURL(content::kAboutBlankURL), web_contents->GetURL()); + EXPECT_EQ(GURL(content::kAboutBlankURL), popup->GetURL()); } } // namespace diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 30df6ec..bc4d0c2 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1308,10 +1308,7 @@ WebContents* Browser::OpenURLFromTab(WebContents* source, if (source) popup_blocker_helper = PopupBlockerTabHelper::FromWebContents(source); - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking) && - popup_blocker_helper) { - + if (popup_blocker_helper) { if ((params.disposition == NEW_POPUP || params.disposition == NEW_FOREGROUND_TAB || params.disposition == NEW_BACKGROUND_TAB || diff --git a/chrome/browser/ui/browser_tab_contents.cc b/chrome/browser/ui/browser_tab_contents.cc index 6680210..56b4433 100644 --- a/chrome/browser/ui/browser_tab_contents.cc +++ b/chrome/browser/ui/browser_tab_contents.cc @@ -139,10 +139,7 @@ void BrowserTabContents::AttachTabHelpers(WebContents* web_contents) { web_contents, PasswordManagerDelegateImpl::FromWebContents(web_contents)); PDFTabHelper::CreateForWebContents(web_contents); PluginObserver::CreateForWebContents(web_contents); - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking)) { - PopupBlockerTabHelper::CreateForWebContents(web_contents); - } + PopupBlockerTabHelper::CreateForWebContents(web_contents); PrefsTabHelper::CreateForWebContents(web_contents); prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager( web_contents, PasswordManager::FromWebContents(web_contents)); diff --git a/chrome/browser/ui/browser_tabstrip.cc b/chrome/browser/ui/browser_tabstrip.cc index e5572b5..52da4ad 100644 --- a/chrome/browser/ui/browser_tabstrip.cc +++ b/chrome/browser/ui/browser_tabstrip.cc @@ -72,22 +72,6 @@ void AddWebContents(Browser* browser, return; } - // Handle blocking of popups. - if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB || - disposition == NEW_BACKGROUND_TAB) && !user_gesture && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisablePopupBlocking) && - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking)) { - // Unrequested popups from normal pages are constrained unless they're in - // the white list. The popup owner will handle checking this. - source_blocked_content->AddPopup( - new_contents, disposition, initial_pos, user_gesture); - if (was_blocked) - *was_blocked = true; - return; - } - new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); } 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 5ce1c0a..b011ff1 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc @@ -546,53 +546,29 @@ ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( void ContentSettingPopupBubbleModel::SetPopups() { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking)) { - std::map<int32, GURL> blocked_popups = - PopupBlockerTabHelper::FromWebContents(web_contents()) - ->GetBlockedPopupRequests(); - for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin(); - iter != blocked_popups.end(); - ++iter) { - std::string title(iter->second.spec()); - // The popup may not have a valid URL. - if (title.empty()) - title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); - PopupItem popup_item( - ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_DEFAULT_FAVICON), - title, - iter->first); - add_popup(popup_item); - } - return; - } - std::vector<WebContents*> blocked_contents; - BlockedContentTabHelper::FromWebContents(web_contents())-> - GetBlockedContents(&blocked_contents); - for (std::vector<WebContents*>::const_iterator - i = blocked_contents.begin(); i != blocked_contents.end(); ++i) { - std::string title(UTF16ToUTF8((*i)->GetTitle())); - // The popup may not have committed a load yet, in which case it won't - // have a URL or title. + std::map<int32, GURL> blocked_popups = + PopupBlockerTabHelper::FromWebContents(web_contents()) + ->GetBlockedPopupRequests(); + for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin(); + iter != blocked_popups.end(); + ++iter) { + std::string title(iter->second.spec()); + // The popup may not have a valid URL. if (title.empty()) title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); PopupItem popup_item( - FaviconTabHelper::FromWebContents(*i)->GetFavicon(), title, *i); + ui::ResourceBundle::GetSharedInstance().GetImageNamed( + IDR_DEFAULT_FAVICON), + title, + iter->first); add_popup(popup_item); } } void ContentSettingPopupBubbleModel::OnPopupClicked(int index) { if (web_contents()) { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableBetterPopupBlocking)) { - PopupBlockerTabHelper::FromWebContents(web_contents())-> - ShowBlockedPopup(bubble_content().popup_items[index].popup_id); - } else { - BlockedContentTabHelper::FromWebContents(web_contents())-> - LaunchForContents(bubble_content().popup_items[index].web_contents); - } + PopupBlockerTabHelper::FromWebContents(web_contents())-> + ShowBlockedPopup(bubble_content().popup_items[index].popup_id); } } diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.h b/chrome/browser/ui/content_settings/content_setting_bubble_model.h index 89c7bef..bc88e96 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.h +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.h @@ -34,19 +34,11 @@ class ContentSettingBubbleModel : public content::NotificationObserver { typedef ContentSettingBubbleModelDelegate Delegate; struct PopupItem { - PopupItem(const gfx::Image& image, - const std::string& title, - content::WebContents* web_contents) - : image(image), - title(title), - web_contents(web_contents), - popup_id(-1) {} PopupItem(const gfx::Image& image, const std::string& title, int32 popup_id) - : image(image), title(title), web_contents(NULL), popup_id(popup_id) {} + : image(image), title(title), popup_id(popup_id) {} gfx::Image image; std::string title; - content::WebContents* web_contents; int32 popup_id; }; typedef std::vector<PopupItem> PopupItems; diff --git a/chrome/browser/ui/search/instant_loader.cc b/chrome/browser/ui/search/instant_loader.cc index 949cf60..fbdba21 100644 --- a/chrome/browser/ui/search/instant_loader.cc +++ b/chrome/browser/ui/search/instant_loader.cc @@ -94,8 +94,6 @@ void InstantLoader::SetContents(scoped_ptr<content::WebContents> new_contents) { BlockedContentTabHelper::FromWebContents(contents())-> SetAllContentsBlocked(true); TabSpecificContentSettings::CreateForWebContents(contents()); - TabSpecificContentSettings::FromWebContents(contents())-> - SetPopupsBlocked(true); // Bookmarks (Users can bookmark the Instant NTP. This ensures the bookmarked // state is correctly set when the contents are swapped into a tab.) @@ -132,16 +130,6 @@ scoped_ptr<content::WebContents> InstantLoader::ReleaseContents() { BlockedContentTabHelper::FromWebContents(contents())-> SetAllContentsBlocked(false); - TabSpecificContentSettings::FromWebContents(contents())-> - SetPopupsBlocked(false); -#if !defined(OS_ANDROID) - PopupBlockerTabHelper* popup_helper = - PopupBlockerTabHelper::FromWebContents(contents()); - if (popup_helper) { - TabSpecificContentSettings::FromWebContents(contents()) - ->SetPopupsBlocked(!!popup_helper->GetBlockedPopupsCount()); - } -#endif CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |