#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/url_formatter/url_formatter.h"
#include <algorithm>
#include <ostream>
#include <string_view>
#include <utility>
#include <vector>
#include "base/lazy_instance.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_offset_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_local_storage.h"
#include "build/build_config.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/icu/source/common/unicode/uidna.h"
#include "third_party/icu/source/common/unicode/utypes.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_constants.h"
#include "url/url_util.h"
namespace url_formatter {
namespace {
const char kWww[] = …;
constexpr size_t kWwwLength = …;
const char kMobilePrefix[] = …;
constexpr size_t kMobilePrefixLength = …;
IDNConversionResult IDNToUnicodeWithAdjustments(
std::string_view host,
base::OffsetAdjuster::Adjustments* adjustments);
struct ComponentResult { … };
ComponentResult IDNToUnicodeOneComponent(
std::u16string_view comp,
std::string_view top_level_domain,
std::u16string_view top_level_domain_unicode,
bool ignore_spoof_check_results,
std::u16string* out);
class AppendComponentTransform { … };
class HostComponentTransform : public AppendComponentTransform { … };
class NonHostComponentTransform : public AppendComponentTransform { … };
void AppendFormattedComponent(const std::string& spec,
const url::Component& original_component,
const AppendComponentTransform& transform,
std::u16string* output,
url::Component* output_component,
base::OffsetAdjuster::Adjustments* adjustments) { … }
void AdjustComponent(int delta, url::Component* component) { … }
void AdjustAllComponentsButScheme(int delta, url::Parsed* parsed) { … }
std::u16string FormatViewSourceUrl(
const GURL& url,
FormatUrlTypes format_types,
base::UnescapeRule::Type unescape_rules,
url::Parsed* new_parsed,
size_t* prefix_end,
base::OffsetAdjuster::Adjustments* adjustments) { … }
base::LazyInstance<IDNSpoofChecker>::Leaky g_idn_spoof_checker = …;
void GetTopLevelDomain(std::string_view host,
std::string_view* top_level_domain,
std::u16string* top_level_domain_unicode) { … }
IDNConversionResult IDNToUnicodeWithAdjustmentsImpl(
std::string_view host,
base::OffsetAdjuster::Adjustments* adjustments,
bool ignore_spoof_check_results) { … }
IDNConversionResult IDNToUnicodeWithAdjustments(
std::string_view host,
base::OffsetAdjuster::Adjustments* adjustments) { … }
IDNConversionResult UnsafeIDNToUnicodeWithAdjustments(
std::string_view host,
base::OffsetAdjuster::Adjustments* adjustments) { … }
IDNSpoofChecker::Result SpoofCheckIDNComponent(
std::u16string_view label,
std::string_view top_level_domain,
std::u16string_view top_level_domain_unicode) { … }
struct UIDNAWrapper { … };
base::LazyInstance<UIDNAWrapper>::Leaky g_uidna = …;
ComponentResult IDNToUnicodeOneComponent(
std::u16string_view comp,
std::string_view top_level_domain,
std::u16string_view top_level_domain_unicode,
bool ignore_spoof_check_results,
std::u16string* out) { … }
bool HasTwoViewSourceSchemes(std::string_view spec) { … }
}
const FormatUrlType kFormatUrlOmitNothing = …;
const FormatUrlType kFormatUrlOmitUsernamePassword = …;
const FormatUrlType kFormatUrlOmitHTTP = …;
const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = …;
const FormatUrlType kFormatUrlOmitHTTPS = …;
const FormatUrlType kFormatUrlOmitTrivialSubdomains = …;
const FormatUrlType kFormatUrlTrimAfterHost = …;
const FormatUrlType kFormatUrlOmitFileScheme = …;
const FormatUrlType kFormatUrlOmitMailToScheme = …;
const FormatUrlType kFormatUrlOmitMobilePrefix = …;
const FormatUrlType kFormatUrlOmitDefaults = …;
std::u16string FormatUrl(const GURL& url,
FormatUrlTypes format_types,
base::UnescapeRule::Type unescape_rules,
url::Parsed* new_parsed,
size_t* prefix_end,
size_t* offset_for_adjustment) { … }
std::u16string FormatUrlWithOffsets(
const GURL& url,
FormatUrlTypes format_types,
base::UnescapeRule::Type unescape_rules,
url::Parsed* new_parsed,
size_t* prefix_end,
std::vector<size_t>* offsets_for_adjustment) { … }
std::u16string FormatUrlWithAdjustments(
const GURL& url,
FormatUrlTypes format_types,
base::UnescapeRule::Type unescape_rules,
url::Parsed* new_parsed,
size_t* prefix_end,
base::OffsetAdjuster::Adjustments* adjustments) { … }
bool CanStripTrailingSlash(const GURL& url) { … }
void AppendFormattedHost(const GURL& url, std::u16string* output) { … }
IDNConversionResult UnsafeIDNToUnicodeWithDetails(std::string_view host) { … }
std::u16string IDNToUnicode(std::string_view host) { … }
std::string StripWWW(const std::string& text) { … }
void StripWWWFromHostComponent(const std::string& url, url::Component* host) { … }
std::string StripMobilePrefix(const std::string& text) { … }
Skeletons GetSkeletons(const std::u16string& host) { … }
TopDomainEntry LookupSkeletonInTopDomains(const std::string& skeleton,
const SkeletonType type) { … }
std::u16string MaybeRemoveDiacritics(const std::u16string& host) { … }
IDNA2008DeviationCharacter GetDeviationCharacter(std::u16string_view hostname) { … }
}