chromium/third_party/blink/renderer/platform/weborigin/kurl.cc

/*
 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

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

#include "third_party/blink/renderer/platform/weborigin/kurl.h"

#include <algorithm>
#include <string_view>

#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "third_party/blink/renderer/platform/weborigin/known_ports.h"
#include "third_party/blink/renderer/platform/weborigin/scheme_registry.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/string_statics.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
#include "url/gurl.h"
#include "url/url_constants.h"
#include "url/url_features.h"
#include "url/url_util.h"
#ifndef NDEBUG
#include <stdio.h>
#endif

namespace blink {

#if DCHECK_IS_ON()
static void AssertProtocolIsGood(const StringView protocol) {}
#endif

// Note: You must ensure that |spec| is a valid canonicalized URL before calling
// this function.
static const char* AsURLChar8Subtle(const String& spec) {}

// Returns the characters for the given string, or a pointer to a static empty
// string if the input string is null. This will always ensure we have a non-
// null character pointer since ReplaceComponents has special meaning for null.
static const char* CharactersOrEmpty(const StringUTF8Adaptor& string) {}

static bool IsSchemeFirstChar(char c) {}

static bool IsSchemeChar(char c) {}

static bool IsUnicodeEncoding(const WTF::TextEncoding* encoding) {}

namespace {

class KURLCharsetConverter final : public url::CharsetConverter {};

}  // namespace

bool IsValidProtocol(const String& protocol) {}

KURL KURL::UrlStrippedForUseAsReferrer() const {}

String KURL::StrippedForUseAsReferrer() const {}

String KURL::StrippedForUseAsHref() const {}

bool KURL::IsLocalFile() const {}

bool ProtocolIsJavaScript(const String& url) {}

const KURL& BlankURL() {}

const KURL& SrcdocURL() {}

bool KURL::IsAboutURL(const char* allowed_path) const {}

bool KURL::IsAboutBlankURL() const {}

bool KURL::IsAboutSrcdocURL() const {}

const KURL& NullURL() {}

String KURL::ElidedString() const {}

KURL::KURL()
    :{}

// Initializes with a string representing an absolute URL. No encoding
// information is specified. This generally happens when a KURL is converted
// to a string and then converted back. In this case, the URL is already
// canonical and in proper escaped form so needs no encoding. We treat it as
// UTF-8 just in case.
KURL::KURL(const String& url) {}

// Initializes with a GURL. This is used to covert from a GURL to a KURL.
KURL::KURL(const GURL& gurl) {}

// Constructs a new URL given a base URL and a possibly relative input URL.
// This assumes UTF-8 encoding.
KURL::KURL(const KURL& base, const String& relative) {}

// Constructs a new URL given a base URL and a possibly relative input URL.
// Any query portion of the relative URL will be encoded in the given encoding.
KURL::KURL(const KURL& base,
           const String& relative,
           const WTF::TextEncoding& encoding) {}

KURL::KURL(const AtomicString& canonical_string,
           const url::Parsed& parsed,
           bool is_valid)
    :{}

KURL::KURL(const KURL& other)
    :{}

KURL::~KURL() = default;

KURL& KURL::operator=(const KURL& other) {}

bool KURL::IsNull() const {}

bool KURL::IsEmpty() const {}

bool KURL::IsValid() const {}

bool KURL::HasPort() const {}

bool KURL::ProtocolIsJavaScript() const {}

bool KURL::ProtocolIsInHTTPFamily() const {}

bool KURL::HasIDNA2008DeviationCharacter() const {}

bool KURL::HasPath() const {}

String KURL::LastPathComponent() const {}

String KURL::Protocol() const {}

String KURL::Host() const {}

StringView KURL::HostView() const {}

uint16_t KURL::Port() const {}

// TODO(csharrison): Migrate pass() and user() to return a StringView. Most
// consumers just need to know if the string is empty.

String KURL::Pass() const {}

String KURL::User() const {}

String KURL::FragmentIdentifier() const {}

bool KURL::HasFragmentIdentifier() const {}

String KURL::BaseAsString() const {}

String KURL::Query() const {}

String KURL::GetPath() const {}

namespace {

bool IsASCIITabOrNewline(UChar ch) {}

// See https://url.spec.whatwg.org/#concept-basic-url-parser:
// 3. Remove all ASCII tab or newline from |input|.
//
// Matches url::RemoveURLWhitespace.
String RemoveURLWhitespace(const String& input) {}

}  // namespace

bool KURL::SetProtocol(const String& protocol) {}

namespace {

String ParsePortFromStringPosition(const String& value, unsigned port_start) {}

// Align with https://url.spec.whatwg.org/#host-state step 3, and also with the
// IsAuthorityTerminator() function in //url/third_party/mozilla/url_parse.cc.
bool IsEndOfHost(UChar ch) {}

bool IsEndOfHostSpecial(UChar ch) {}

wtf_size_t FindHostEnd(const String& host, bool is_special) {}

}  // namespace

void KURL::SetHost(const String& input) {}

void KURL::SetHostAndPort(const String& input) {}

void KURL::RemovePort() {}

void KURL::SetPort(const String& input) {}

void KURL::SetPort(uint16_t port) {}

void KURL::SetUser(const String& user) {}

void KURL::SetPass(const String& pass) {}

void KURL::SetFragmentIdentifier(const String& input) {}

void KURL::RemoveFragmentIdentifier() {}

void KURL::SetQuery(const String& input) {}

void KURL::SetPath(const String& input) {}

String DecodeURLEscapeSequences(const String& string, DecodeURLMode mode) {}

String EncodeWithURLEscapeSequences(const String& not_encoded_string) {}

bool HasInvalidURLEscapeSequences(const String& string) {}

bool KURL::CanSetHostOrPort() const {}

bool KURL::CanSetPathname() const {}

bool KURL::CanRemoveHost() const {}

bool KURL::IsHierarchical() const {}

bool KURL::IsStandard() const {}

bool EqualIgnoringFragmentIdentifier(const KURL& a, const KURL& b) {}

unsigned KURL::HostStart() const {}

unsigned KURL::HostEnd() const {}

unsigned KURL::PathStart() const {}

unsigned KURL::PathEnd() const {}

unsigned KURL::PathAfterLastSlash() const {}

bool ProtocolIs(const String& url, const char* protocol) {}

void KURL::Init(const KURL& base,
                const String& relative,
                const WTF::TextEncoding* query_encoding) {}

void KURL::InitInnerURL() {}

void KURL::InitProtocolMetadata() {}

void KURL::AssertStringSpecIsASCII() {}

bool KURL::ProtocolIs(const StringView protocol) const {}

StringView KURL::StringViewForInvalidComponent() const {}

StringView KURL::ComponentStringView(const url::Component& component) const {}

String KURL::ComponentString(const url::Component& component) const {}

template <typename CHAR>
void KURL::ReplaceComponents(const url::Replacements<CHAR>& replacements,
                             bool preserve_validity) {}

void KURL::WriteIntoTrace(perfetto::TracedValue context) const {}

operator GURL()
bool operator==(const KURL& a, const KURL& b) {}

bool operator==(const KURL& a, const String& b) {}

bool operator==(const String& a, const KURL& b) {}

bool operator!=(const KURL& a, const KURL& b) {}

bool operator!=(const KURL& a, const String& b) {}

bool operator!=(const String& a, const KURL& b) {}

std::ostream& operator<<(std::ostream& os, const KURL& url) {}

}  // namespace blink