blob: 37a04e7c6131c2636861279877aba9f4d64fd6a7 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/navigation_throttle.h"
class PolicyBlacklistService;
class PrefService;
namespace content {
class BrowserContext;
class NavigationHandle;
} // namespace content
// PolicyBlacklistNavigationThrottle provides a simple way to block a navigation
// based on the URLBlacklistManager and Safe Search API. If the URL is
// blacklisted or whitelisted, the throttle will immediately block or allow the
// navigation. Otherwise, the URL will be checked against the Safe Search API if
// the SafeSitesFilterBehavior policy is enabled. This final check may be
// asynchronous if the result hasn't been cached yet.
class PolicyBlacklistNavigationThrottle : public content::NavigationThrottle {
content::NavigationHandle* navigation_handle,
content::BrowserContext* context);
~PolicyBlacklistNavigationThrottle() override;
// NavigationThrottle overrides.
ThrottleCheckResult WillStartRequest() override;
ThrottleCheckResult WillRedirectRequest() override;
const char* GetNameForLogging() override;
// Callback from PolicyBlacklistService.
void CheckSafeSearchCallback(bool is_safe);
PolicyBlacklistService* blacklist_service_;
PrefService* prefs_;
// Whether the request was deferred in order to check the Safe Search API.
bool deferred_ = false;
// Whether the Safe Search API callback determined the in-progress navigation
// should be canceled.
bool should_cancel_ = false;
base::WeakPtrFactory<PolicyBlacklistNavigationThrottle> weak_ptr_factory_;