Commit 6d6838d4 authored by Charles Harrison's avatar Charles Harrison Committed by Commit Bot

[tab-under] Add pref to turn feature off

A followup will hook this pref with a new enterprise policy to turn the
feature off.

Bug: 823700
Change-Id: I06096460a372941ba06f3bf3e9cc63b9084f82cd
Reviewed-on: https://chromium-review.googlesource.com/970729Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544375}
parent f630ab7b
......@@ -55,6 +55,7 @@
#include "chrome/browser/task_manager/task_manager_interface.h"
#include "chrome/browser/tracing/chrome_tracing_delegate.h"
#include "chrome/browser/ui/blocked_content/safe_browsing_triggered_popup_blocker.h"
#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
#include "chrome/browser/ui/browser_ui_prefs.h"
#include "chrome/browser/ui/navigation_correction_tab_observer.h"
#include "chrome/browser/ui/network_profile_bubble.h"
......@@ -525,6 +526,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
SessionStartupPref::RegisterProfilePrefs(registry);
signin::RegisterAccountConsistencyProfilePrefs(registry);
syncer::SyncPrefs::RegisterProfilePrefs(registry);
TabUnderNavigationThrottle::RegisterProfilePrefs(registry);
TemplateURLPrepopulateData::RegisterProfilePrefs(registry);
translate::TranslatePrefs::RegisterProfilePrefs(registry);
UINetworkQualityEstimatorService::RegisterProfilePrefs(registry);
......
......@@ -23,12 +23,15 @@
#include "chrome/browser/ui/blocked_content/list_item_position.h"
#include "chrome/browser/ui/blocked_content/popup_tracker.h"
#include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/content/source_url_recorder.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/ukm/ukm_source.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_utils.h"
......@@ -729,3 +732,20 @@ TEST_F(BlockTabUnderTest, SiteEngagementNoThreshold_Blocks) {
auto samples = histogram_tester()->GetAllSamples(kEngagementScore);
EXPECT_LT(0, samples[0].min);
}
TEST_F(BlockTabUnderTest, ControlledByPrefs) {
// Turn feature off via prefs.
PrefService* prefs =
user_prefs::UserPrefs::Get(web_contents()->GetBrowserContext());
prefs->SetBoolean(prefs::kTabUnderProtection, false);
EXPECT_TRUE(NavigateAndCommitWithoutGesture(GURL("https://first.test/")));
SimulatePopup();
EXPECT_TRUE(NavigateAndCommitWithoutGesture(GURL("https://example.test1/")));
ExpectUIShown(false);
// Turn feature back on.
prefs->SetBoolean(prefs::kTabUnderProtection, true);
EXPECT_FALSE(NavigateAndCommitWithoutGesture(GURL("https://example.test2/")));
ExpectUIShown(true);
}
......@@ -22,6 +22,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/list_item_position.h"
#include "chrome/browser/ui/blocked_content/popup_opener_tab_helper.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
......@@ -105,6 +109,13 @@ void LogTabUnderAttempt(content::NavigationHandle* handle,
const base::Feature TabUnderNavigationThrottle::kBlockTabUnders{
"BlockTabUnders", base::FEATURE_DISABLED_BY_DEFAULT};
// static
void TabUnderNavigationThrottle::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(prefs::kTabUnderProtection,
true /* default_value */);
}
// static
std::unique_ptr<content::NavigationThrottle>
TabUnderNavigationThrottle::MaybeCreate(content::NavigationHandle* handle) {
......@@ -124,7 +135,10 @@ TabUnderNavigationThrottle::TabUnderNavigationThrottle(
0 /* default_value */)),
off_the_record_(
handle->GetWebContents()->GetBrowserContext()->IsOffTheRecord()),
block_(base::FeatureList::IsEnabled(kBlockTabUnders)),
block_(base::FeatureList::IsEnabled(kBlockTabUnders) &&
user_prefs::UserPrefs::Get(
handle->GetWebContents()->GetBrowserContext())
->GetBoolean(prefs::kTabUnderProtection)),
has_opened_popup_since_last_user_gesture_at_start_(
HasOpenedPopupSinceLastUserGesture()) {}
......
......@@ -17,6 +17,10 @@ namespace content {
class NavigationHandle;
}
namespace user_prefs {
class PrefRegistrySyncable;
};
constexpr char kBlockTabUnderFormatMessage[] =
"Chrome stopped this site from navigating to %s, see "
"https://www.chromestatus.com/feature/5675755719622656 for more details.";
......@@ -61,6 +65,8 @@ class TabUnderNavigationThrottle : public content::NavigationThrottle {
kCount
};
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static std::unique_ptr<content::NavigationThrottle> MaybeCreate(
content::NavigationHandle* handle);
......
......@@ -116,6 +116,10 @@ const char kSiteEngagementLastUpdateTime[] = "profile.last_engagement_time";
// 5: open the New Tab Page on startup.
const char kRestoreOnStartup[] = "session.restore_on_startup";
// A boolean pref to indicate whether or not Chrome should be performing
// tab-under protection (i.e. blocking navigations it detects as tab-unders).
const char kTabUnderProtection[] = "tab_under_protection";
// The URLs to restore on startup or when the home button is pressed. The URLs
// are only restored on startup if kRestoreOnStartup is 4.
const char kURLsToRestoreOnStartup[] = "session.startup_urls";
......
......@@ -55,6 +55,7 @@ extern const char kSupervisedUserSecondCustodianProfileImageURL[];
extern const char kSupervisedUserSecondCustodianProfileURL[];
extern const char kSupervisedUserSharedSettings[];
extern const char kSupervisedUserWhitelists[];
extern const char kTabUnderProtection[];
extern const char kURLsToRestoreOnStartup[];
#if BUILDFLAG(ENABLE_RLZ)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment