chromium/extensions/common/url_pattern.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "extensions/common/url_pattern.h"

#include <stddef.h>

#include <ostream>
#include <string_view>

#include "base/containers/contains.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "url/gurl.h"
#include "url/url_util.h"

const char URLPattern::kAllUrlsPattern[] =;

namespace {

// TODO(aa): What about more obscure schemes like javascript: ?
// Note: keep this array in sync with kValidSchemeMasks.
const char* const kValidSchemes[] =;

const int kValidSchemeMasks[] =;

static_assert;

const char kParseSuccess[] =;
const char kParseErrorMissingSchemeSeparator[] =;
const char kParseErrorInvalidScheme[] =;
const char kParseErrorWrongSchemeType[] =;
const char kParseErrorEmptyHost[] =;
const char kParseErrorInvalidHostWildcard[] =;
const char kParseErrorEmptyPath[] =;
const char kParseErrorInvalidPort[] =;
const char kParseErrorInvalidHost[] =;

// Message explaining each URLPattern::ParseResult.
const char* const kParseResultMessages[] =;

static_assert;

const char kPathSeparator[] =;

bool IsStandardScheme(std::string_view scheme) {}

bool IsValidPortForScheme(std::string_view scheme, std::string_view port) {}

// Returns |path| with the trailing wildcard stripped if one existed.
//
// The functions that rely on this (OverlapsWith and Contains) are only
// called for the patterns inside URLPatternSet. In those cases, we know that
// the path will have only a single wildcard at the end. This makes figuring
// out overlap much easier. It seems like there is probably a computer-sciency
// way to solve the general case, but we don't need that yet.
std::string_view StripTrailingWildcard(std::string_view path) {}

// Removes trailing dot from |host_piece| if any.
std::string_view CanonicalizeHostForMatching(std::string_view host_piece) {}

}  // namespace

// static
bool URLPattern::IsValidSchemeForExtensions(std::string_view scheme) {}

// static
int URLPattern::GetValidSchemeMaskForExtensions() {}

URLPattern::URLPattern()
    :{}

URLPattern::URLPattern(int valid_schemes)
    :{}

URLPattern::URLPattern(int valid_schemes, std::string_view pattern)
    // Strict error checking is used, because this constructor is only
    // appropriate when we know |pattern| is valid.
    :{}

URLPattern::URLPattern(const URLPattern& other) = default;

URLPattern::URLPattern(URLPattern&& other) = default;

URLPattern::~URLPattern() = default;

URLPattern& URLPattern::operator=(const URLPattern& other) = default;

URLPattern& URLPattern::operator=(URLPattern&& other) = default;

bool URLPattern::operator<(const URLPattern& other) const {}

bool URLPattern::operator>(const URLPattern& other) const {}

bool URLPattern::operator==(const URLPattern& other) const {}

std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern) {}

URLPattern::ParseResult URLPattern::Parse(std::string_view pattern) {}

void URLPattern::SetValidSchemes(int valid_schemes) {}

void URLPattern::SetHost(std::string_view host) {}

void URLPattern::SetMatchAllURLs(bool val) {}

void URLPattern::SetMatchSubdomains(bool val) {}

bool URLPattern::SetScheme(std::string_view scheme) {}

bool URLPattern::IsValidScheme(std::string_view scheme) const {}

void URLPattern::SetPath(std::string_view path) {}

bool URLPattern::SetPort(std::string_view port) {}

bool URLPattern::MatchesURL(const GURL& test) const {}

bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {}

bool URLPattern::MatchesScheme(std::string_view test) const {}

bool URLPattern::MatchesHost(std::string_view host) const {}

bool URLPattern::MatchesHost(const GURL& test) const {}

bool URLPattern::MatchesEffectiveTld(
    net::registry_controlled_domains::PrivateRegistryFilter private_filter,
    net::registry_controlled_domains::UnknownRegistryFilter unknown_filter)
    const {}

bool URLPattern::MatchesSingleOrigin() const {}

bool URLPattern::MatchesPath(std::string_view test) const {}

const std::string& URLPattern::GetAsString() const {}

bool URLPattern::OverlapsWith(const URLPattern& other) const {}

bool URLPattern::Contains(const URLPattern& other) const {}

std::optional<URLPattern> URLPattern::CreateIntersection(
    const URLPattern& other) const {}

bool URLPattern::MatchesAnyScheme(
    const std::vector<std::string>& schemes) const {}

bool URLPattern::MatchesAllSchemes(
    const std::vector<std::string>& schemes) const {}

bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const {}

bool URLPattern::MatchesPortPattern(std::string_view port) const {}

std::vector<std::string> URLPattern::GetExplicitSchemes() const {}

std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const {}

// static
const char* URLPattern::GetParseResultString(
    URLPattern::ParseResult parse_result) {}