Commit b4927e75 authored by Doug Turner's avatar Doug Turner Committed by Commit Bot

URLBlacklist policy not working in incognito mode.

It seems BrowserContextKeyedServiceFactory returns a null context if in
incognito mode. This CL adds an overload to return a context when the
policy blacklist is being requested from an incognito context.

Bug: 821653
Change-Id: Iac2fab5c52bfb79fcee08d8e3ba9b05f4bef6c8b
Reviewed-on: https://chromium-review.googlesource.com/961383
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543108}
parent a71178f2
...@@ -2604,6 +2604,53 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { ...@@ -2604,6 +2604,53 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) {
CheckCanOpenURL(browser(), kURLS[4]); CheckCanOpenURL(browser(), kURLS[4]);
} }
IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistIncognito) {
// Checks that URLs can be blacklisted, and that exceptions can be made to
// the blacklist.
Browser* incognito_browser =
OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
ASSERT_TRUE(embedded_test_server()->Start());
const std::string kURLS[] = {
embedded_test_server()->GetURL("aaa.com", "/empty.html").spec(),
embedded_test_server()->GetURL("bbb.com", "/empty.html").spec(),
embedded_test_server()->GetURL("sub.bbb.com", "/empty.html").spec(),
embedded_test_server()->GetURL("bbb.com", "/policy/blank.html").spec(),
embedded_test_server()->GetURL("bbb.com.", "/policy/blank.html").spec(),
};
// Verify that "bbb.com" opens before applying the blacklist.
CheckCanOpenURL(incognito_browser, kURLS[1]);
// Set a blacklist.
base::ListValue blacklist;
blacklist.AppendString("bbb.com");
PolicyMap policies;
policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
UpdateProviderPolicy(policies);
FlushBlacklistPolicy();
// All bbb.com URLs are blocked, and "aaa.com" is still unblocked.
CheckCanOpenURL(incognito_browser, kURLS[0]);
for (size_t i = 1; i < arraysize(kURLS); ++i)
CheckURLIsBlocked(incognito_browser, kURLS[i]);
// Whitelist some sites of bbb.com.
base::ListValue whitelist;
whitelist.AppendString("sub.bbb.com");
whitelist.AppendString("bbb.com/policy");
policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr);
UpdateProviderPolicy(policies);
FlushBlacklistPolicy();
CheckURLIsBlocked(incognito_browser, kURLS[1]);
CheckCanOpenURL(incognito_browser, kURLS[2]);
CheckCanOpenURL(incognito_browser, kURLS[3]);
CheckCanOpenURL(incognito_browser, kURLS[4]);
}
IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistAndWhitelist) { IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistAndWhitelist) {
// Regression test for http://crbug.com/755256. Blacklisting * and // Regression test for http://crbug.com/755256. Blacklisting * and
// whitelisting an origin should work. // whitelisting an origin should work.
......
...@@ -56,6 +56,13 @@ KeyedService* PolicyBlacklistFactory::BuildServiceInstanceFor( ...@@ -56,6 +56,13 @@ KeyedService* PolicyBlacklistFactory::BuildServiceInstanceFor(
return new PolicyBlacklistService(std::move(url_blacklist_manager)); return new PolicyBlacklistService(std::move(url_blacklist_manager));
} }
content::BrowserContext* PolicyBlacklistFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// TODO(crbug.com/701326): This DCHECK should be moved to GetContextToUse().
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return context;
}
PolicyBlacklistNavigationThrottle::PolicyBlacklistNavigationThrottle( PolicyBlacklistNavigationThrottle::PolicyBlacklistNavigationThrottle(
content::NavigationHandle* navigation_handle, content::NavigationHandle* navigation_handle,
content::BrowserContext* context) content::BrowserContext* context)
......
...@@ -52,6 +52,10 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory { ...@@ -52,6 +52,10 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory {
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
// Finds which browser context (if any) to use.
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
policy::URLBlacklistManager::OverrideBlacklistCallback override_blacklist_; policy::URLBlacklistManager::OverrideBlacklistCallback override_blacklist_;
DISALLOW_COPY_AND_ASSIGN(PolicyBlacklistFactory); DISALLOW_COPY_AND_ASSIGN(PolicyBlacklistFactory);
......
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