chromium/components/supervised_user/core/browser/supervised_user_url_filter.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// UMA histogram FamilyUser.ManagedSiteList.Conflict
// Reports conflict when the user tries to access a url that has a match in
// both of the allow list and the block list.
const char kManagedSiteListConflictHistogramName[] =;

// UMA histogram FamilyUser.ManagedSiteList.SubdomainConflictType
// Reports a conflict when the user tries to access a url that has a match in
// both of the allow list and the block list and the two conflicting entries
// differs only in the "www" subdomain.
const char kManagedSiteListSubdomainConflictTypeHistogramName[] =;

// UMA histogram FamilyUser.WebFilterType
// Reports WebFilterType which indicates web filter behaviour are used for
// current Family Link user.
constexpr char kWebFilterTypeHistogramName[] =;

// UMA histogram FamilyUser.ManualSiteListType
// Reports ManualSiteListType which indicates approved list and blocked list
// usage for current Family Link user.
constexpr char kManagedSiteListHistogramName[] =;

// UMA histogram FamilyUser.ManagedSiteListCount.Approved
// Reports the number of approved urls and domains for current Family Link user.
constexpr char kApprovedSitesCountHistogramName[] =;

// UMA histogram FamilyUser.ManagedSiteListCount.Blocked
// Reports the number of blocked urls and domains for current Family Link user.
constexpr char kBlockedSitesCountHistogramName[] =;

constexpr std::string_view kHttpProtocol =;
constexpr std::string_view kHttpsProtocol =;
constexpr std::string_view kWwwSubdomain =;

// Trims the given `pattern` if it starts with 'https://' or 'http://'.
std::string TrimHttpOrHttpsProtocol(const std::string& pattern) {}

// Trims 'www' subdomain if it is present on the given pattern.
std::string TrimWwwSubdomain(const std::string& pattern) {}

// For a given host `pattern` and, checks if there is another pattern in
// the given `host_list` which differs only in the trivial
// "www"-subdomain.
// Note: This method applies transformations to the given pattern
// opposite to those from `SupervisedUserURLFilter::HostMatchesPattern`
// (e.g. protocol/subdomain stripping). The pattern manipulations should
// be kept in sync between the two methods.
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) {}

}  // namespace

SupervisedUserURLFilter::SupervisedUserURLFilter(
    PrefService& user_prefs,
    std::unique_ptr<Delegate> delegate)
    :{}

SupervisedUserURLFilter::~SupervisedUserURLFilter() {}

// static
const char* SupervisedUserURLFilter::GetWebFilterTypeHistogramNameForTest() {}

// static
const char* SupervisedUserURLFilter::GetManagedSiteListHistogramNameForTest() {}

// static
const char*
SupervisedUserURLFilter::GetApprovedSitesCountHistogramNameForTest() {}

// static
const char*
SupervisedUserURLFilter::GetBlockedSitesCountHistogramNameForTest() {}

// static
const char*
SupervisedUserURLFilter::GetManagedSiteListConflictHistogramNameForTest() {}

// static
const char*
SupervisedUserURLFilter::GetManagedSiteListConflictTypeHistogramNameForTest() {}

// static
supervised_user::FilteringBehavior SupervisedUserURLFilter::BehaviorFromInt(
    int behavior_value) {}

// static
// Note: The transformations applied to pattern (e.g. protocol/subdomain
// stripping) should be kept in sync with those in the method
// `HostHasSubdomainConflict`.
bool SupervisedUserURLFilter::HostMatchesPattern(
    const std::string& canonical_host,
    const std::string& pattern) {}

SupervisedUserFilterTopLevelResult
SupervisedUserURLFilter::GetHistogramValueForTopLevelFilteringBehavior(
    FilteringBehavior behavior,
    FilteringBehaviorReason reason,
    bool is_filtering_behavior_known) {}

// static
int SupervisedUserURLFilter::GetHistogramValueForFilteringBehavior(
    FilteringBehavior behavior,
    FilteringBehaviorReason reason,
    bool is_filtering_behavior_known) {}

// static
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) {}

// There may be conflicting patterns, say, "allow *.google.com" and "block
// www.google.*". To break the tie, we prefer blocklists over allowlists.
// If there are no applicable manual overrides, we return INVALID.
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 {}

}  // namespace supervised_user