Skip to content

Commit

Permalink
URLBlacklist policy not working in incognito mode.
Browse files Browse the repository at this point in the history
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: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543108}
  • Loading branch information
dougt authored and Commit Bot committed Mar 14, 2018
1 parent a71178f commit b4927e7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
47 changes: 47 additions & 0 deletions chrome/browser/policy/policy_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,53 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) {
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) {
// Regression test for http://crbug.com/755256. Blacklisting * and
// whitelisting an origin should work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ KeyedService* PolicyBlacklistFactory::BuildServiceInstanceFor(
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(
content::NavigationHandle* navigation_handle,
content::BrowserContext* context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory {
KeyedService* BuildServiceInstanceFor(
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_;

DISALLOW_COPY_AND_ASSIGN(PolicyBlacklistFactory);
Expand Down

0 comments on commit b4927e7

Please sign in to comment.