#include "components/supervised_user/core/browser/supervised_user_url_filter.h"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/task/thread_pool.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/supervised_user/core/browser/kids_chrome_management_url_checker_client.h"
#include "components/supervised_user/core/browser/supervised_user_capabilities.h"
#include "components/supervised_user/core/browser/supervised_user_preferences.h"
#include "components/supervised_user/core/browser/supervised_user_utils.h"
#include "components/supervised_user/core/common/supervised_user_constants.h"
#include "components/url_matcher/url_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "url/gurl.h"
#include "url/url_constants.h"
EXCLUDE_PRIVATE_REGISTRIES;
EXCLUDE_UNKNOWN_REGISTRIES;
GetCanonicalHostRegistryLength;
namespace supervised_user {
supervised_user::FilteringBehavior GetBehaviorFromSafeSearchClassification(
safe_search_api::Classification classification) { … }
bool IsSameDomain(const GURL& url1, const GURL& url2) { … }
bool IsNonStandardUrlScheme(const GURL& effective_url) { … }
bool IsAlwaysAllowedHost(const GURL& effective_url) { … }
bool IsAlwaysAllowedUrlPrefix(const GURL& effective_url) { … }
bool IsPlayStoreTermsOfServiceUrl(const GURL& effective_url) { … }
namespace {
const char kManagedSiteListConflictHistogramName[] = …;
const char kManagedSiteListSubdomainConflictTypeHistogramName[] = …;
constexpr char kWebFilterTypeHistogramName[] = …;
constexpr char kManagedSiteListHistogramName[] = …;
constexpr char kApprovedSitesCountHistogramName[] = …;
constexpr char kBlockedSitesCountHistogramName[] = …;
constexpr std::string_view kHttpProtocol = …;
constexpr std::string_view kHttpsProtocol = …;
constexpr std::string_view kWwwSubdomain = …;
std::string TrimHttpOrHttpsProtocol(const std::string& pattern) { … }
std::string TrimWwwSubdomain(const std::string& pattern) { … }
bool HostHasTrivialSubdomainConflict(const std::string& pattern,
const std::set<std::string> host_list) { … }
FilteringSubdomainConflictType;
std::optional<FilteringSubdomainConflictType> AddConflict(
std::optional<FilteringSubdomainConflictType> current_conflict,
bool is_trivial_subdomain_conflict) { … }
}
SupervisedUserURLFilter::SupervisedUserURLFilter(
PrefService& user_prefs,
std::unique_ptr<Delegate> delegate)
: … { … }
SupervisedUserURLFilter::~SupervisedUserURLFilter() { … }
const char* SupervisedUserURLFilter::GetWebFilterTypeHistogramNameForTest() { … }
const char* SupervisedUserURLFilter::GetManagedSiteListHistogramNameForTest() { … }
const char*
SupervisedUserURLFilter::GetApprovedSitesCountHistogramNameForTest() { … }
const char*
SupervisedUserURLFilter::GetBlockedSitesCountHistogramNameForTest() { … }
const char*
SupervisedUserURLFilter::GetManagedSiteListConflictHistogramNameForTest() { … }
const char*
SupervisedUserURLFilter::GetManagedSiteListConflictTypeHistogramNameForTest() { … }
supervised_user::FilteringBehavior SupervisedUserURLFilter::BehaviorFromInt(
int behavior_value) { … }
bool SupervisedUserURLFilter::HostMatchesPattern(
const std::string& canonical_host,
const std::string& pattern) { … }
SupervisedUserFilterTopLevelResult
SupervisedUserURLFilter::GetHistogramValueForTopLevelFilteringBehavior(
FilteringBehavior behavior,
FilteringBehaviorReason reason,
bool is_filtering_behavior_known) { … }
int SupervisedUserURLFilter::GetHistogramValueForFilteringBehavior(
FilteringBehavior behavior,
FilteringBehaviorReason reason,
bool is_filtering_behavior_known) { … }
void SupervisedUserURLFilter::RecordFilterResultEvent(
FilteringBehavior behavior,
FilteringBehaviorReason reason,
bool is_filtering_behavior_known,
ui::PageTransition transition_type) { … }
supervised_user::FilteringBehavior
SupervisedUserURLFilter::GetFilteringBehaviorForURL(const GURL& url) { … }
bool SupervisedUserURLFilter::IsExemptedFromGuardianApproval(
const GURL& effective_url) { … }
bool SupervisedUserURLFilter::GetManualFilteringBehaviorForURL(
const GURL& url,
FilteringBehavior* behavior) { … }
supervised_user::FilteringBehavior
SupervisedUserURLFilter::GetFilteringBehaviorForURL(
const GURL& url,
supervised_user::FilteringBehaviorReason* reason) { … }
supervised_user::FilteringBehavior
SupervisedUserURLFilter::GetManualFilteringBehaviorForURL(const GURL& url) { … }
bool SupervisedUserURLFilter::GetFilteringBehaviorForURLWithAsyncChecks(
const GURL& url,
FilteringBehaviorCallback callback,
bool skip_manual_parent_filter) { … }
bool SupervisedUserURLFilter::GetFilteringBehaviorForSubFrameURLWithAsyncChecks(
const GURL& url,
const GURL& main_frame_url,
FilteringBehaviorCallback callback) { … }
void SupervisedUserURLFilter::SetDefaultFilteringBehavior(
FilteringBehavior behavior) { … }
supervised_user::FilteringBehavior
SupervisedUserURLFilter::GetDefaultFilteringBehavior() const { … }
void SupervisedUserURLFilter::SetManualHosts(
std::map<std::string, bool> host_map) { … }
bool SupervisedUserURLFilter::IsManualHostsEmpty() const { … }
void SupervisedUserURLFilter::SetManualURLs(std::map<GURL, bool> url_map) { … }
void SupervisedUserURLFilter::Clear() { … }
void SupervisedUserURLFilter::AddObserver(Observer* observer) { … }
void SupervisedUserURLFilter::RemoveObserver(Observer* observer) { … }
WebFilterType SupervisedUserURLFilter::GetWebFilterType() const { … }
bool SupervisedUserURLFilter::EmitURLFilterMetrics() const { … }
void SupervisedUserURLFilter::ReportWebFilterTypeMetrics() const { … }
void SupervisedUserURLFilter::ReportManagedSiteListMetrics() const { … }
void SupervisedUserURLFilter::SetFilterInitialized(bool is_filter_initialized) { … }
bool SupervisedUserURLFilter::RunAsyncChecker(
const GURL& url,
FilteringBehaviorCallback callback) const { … }
void SupervisedUserURLFilter::SetURLCheckerClient(
std::unique_ptr<safe_search_api::URLCheckerClient> url_checker_client) { … }
bool SupervisedUserURLFilter::IsHostInBlocklist(const std::string& host) const { … }
void SupervisedUserURLFilter::CheckCallback(
FilteringBehaviorCallback callback,
const GURL& url,
safe_search_api::Classification classification,
bool uncertain) const { … }
}