#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "url/url_util.h"
#include <stddef.h>
#include <string.h>
#include <atomic>
#include <ostream>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "url/url_canon_internal.h"
#include "url/url_constants.h"
#include "url/url_features.h"
#include "url/url_file.h"
#include "url/url_parse_internal.h"
#include "url/url_util_internal.h"
namespace url {
namespace {
struct SchemeWithType { … };
struct SchemeWithHandler { … };
struct SchemeRegistry { … };
bool scheme_registries_locked = …;
static std::atomic<bool> g_scheme_registries_used{ … };
SchemeRegistry* GetSchemeRegistryWithoutLocking() { … }
const SchemeRegistry& GetSchemeRegistry() { … }
enum WhitespaceRemovalPolicy { … };
template<typename CHAR>
inline bool DoCompareSchemeComponent(const CHAR* spec,
const Component& component,
const char* compare_to) { … }
template<typename CHAR>
bool DoIsInSchemes(const CHAR* spec,
const Component& scheme,
SchemeType* type,
const std::vector<SchemeWithType>& schemes) { … }
template<typename CHAR>
bool DoIsStandard(const CHAR* spec, const Component& scheme, SchemeType* type) { … }
template <typename CHAR>
bool DoIsOpaqueNonSpecial(const CHAR* spec, const Component& scheme) { … }
template<typename CHAR>
bool DoFindAndCompareScheme(const CHAR* str,
int str_len,
const char* compare,
Component* found_scheme) { … }
template <typename CHAR>
bool DoCanonicalize(const CHAR* spec,
int spec_len,
bool trim_path_end,
WhitespaceRemovalPolicy whitespace_policy,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
template<typename CHAR>
bool DoResolveRelative(const char* base_spec,
int base_spec_len,
const Parsed& base_parsed,
const CHAR* in_relative,
int in_relative_length,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
template<typename CHAR>
bool DoReplaceComponents(const char* spec,
int spec_len,
const Parsed& parsed,
const Replacements<CHAR>& replacements,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
void DoSchemeModificationPreamble() { … }
void DoAddSchemeWithHandler(const char* new_scheme,
const char* handler,
std::vector<SchemeWithHandler>* schemes) { … }
void DoAddScheme(const char* new_scheme, std::vector<std::string>* schemes) { … }
void DoAddSchemeWithType(const char* new_scheme,
SchemeType type,
std::vector<SchemeWithType>* schemes) { … }
}
void ClearSchemesForTests() { … }
class ScopedSchemeRegistryInternal { … };
ScopedSchemeRegistryForTests::ScopedSchemeRegistryForTests()
: … { … }
ScopedSchemeRegistryForTests::~ScopedSchemeRegistryForTests() = default;
void EnableNonStandardSchemesForAndroidWebView() { … }
bool AllowNonStandardSchemesForAndroidWebView() { … }
void AddStandardScheme(const char* new_scheme, SchemeType type) { … }
std::vector<std::string> GetStandardSchemes() { … }
void AddReferrerScheme(const char* new_scheme, SchemeType type) { … }
void AddSecureScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetSecureSchemes() { … }
void AddLocalScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetLocalSchemes() { … }
void AddNoAccessScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetNoAccessSchemes() { … }
void AddCorsEnabledScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetCorsEnabledSchemes() { … }
void AddWebStorageScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetWebStorageSchemes() { … }
void AddCSPBypassingScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetCSPBypassingSchemes() { … }
void AddEmptyDocumentScheme(const char* new_scheme) { … }
const std::vector<std::string>& GetEmptyDocumentSchemes() { … }
void AddPredefinedHandlerScheme(const char* new_scheme, const char* handler) { … }
std::vector<std::pair<std::string, std::string>> GetPredefinedHandlerSchemes() { … }
void LockSchemeRegistries() { … }
bool IsStandard(const char* spec, const Component& scheme) { … }
bool IsStandardScheme(std::string_view scheme) { … }
bool GetStandardSchemeType(const char* spec,
const Component& scheme,
SchemeType* type) { … }
bool GetStandardSchemeType(const char16_t* spec,
const Component& scheme,
SchemeType* type) { … }
bool IsStandard(const char16_t* spec, const Component& scheme) { … }
bool IsReferrerScheme(const char* spec, const Component& scheme) { … }
bool FindAndCompareScheme(const char* str,
int str_len,
const char* compare,
Component* found_scheme) { … }
bool FindAndCompareScheme(const char16_t* str,
int str_len,
const char* compare,
Component* found_scheme) { … }
bool DomainIs(std::string_view canonical_host,
std::string_view canonical_domain) { … }
bool HostIsIPAddress(std::string_view host) { … }
bool Canonicalize(const char* spec,
int spec_len,
bool trim_path_end,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
bool Canonicalize(const char16_t* spec,
int spec_len,
bool trim_path_end,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
bool ResolveRelative(const char* base_spec,
int base_spec_len,
const Parsed& base_parsed,
const char* relative,
int relative_length,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
bool ResolveRelative(const char* base_spec,
int base_spec_len,
const Parsed& base_parsed,
const char16_t* relative,
int relative_length,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) { … }
bool ReplaceComponents(const char* spec,
int spec_len,
const Parsed& parsed,
const Replacements<char>& replacements,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
bool ReplaceComponents(const char* spec,
int spec_len,
const Parsed& parsed,
const Replacements<char16_t>& replacements,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* out_parsed) { … }
void DecodeURLEscapeSequences(std::string_view input,
DecodeURLMode mode,
CanonOutputW* output) { … }
void EncodeURIComponent(std::string_view input, CanonOutput* output) { … }
bool IsURIComponentChar(char c) { … }
bool CompareSchemeComponent(const char* spec,
const Component& component,
const char* compare_to) { … }
bool CompareSchemeComponent(const char16_t* spec,
const Component& component,
const char* compare_to) { … }
bool HasInvalidURLEscapeSequences(std::string_view input) { … }
bool IsAndroidWebViewHackEnabledScheme(std::string_view scheme) { … }
}