/* * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple 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 COMPUTER, 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. */ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_KURL_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_KURL_H_ #include <iosfwd> #include <memory> #include "third_party/abseil-cpp/absl/base/attributes.h" #include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/cross_thread_copier.h" #include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon.h" #include "url/url_util.h" // KURL stands for the URL parser in KDE's HTML Widget (KHTML). The name hasn't // changed since Blink forked WebKit, which in turn forked KHTML. // // KURL is Blink's URL class and is the analog to GURL in other Chromium // code. KURL and GURL both share the same underlying URL parser, whose code is // located in //url, but KURL is backed by Blink specific WTF::Strings. This // means that KURLs are usually cheap to copy due to WTF::Strings being // internally ref-counted. However, please don't copy KURLs if you can use a // const ref, since the size of the parsed structure and related metadata is // non-trivial. // // KURL also has a few other optimizations, including: // - Fast comparisons since the string spec is stored as an AtomicString. // - Cached bit for whether the KURL is http/https // - Internal reference to the URL protocol (scheme) to avoid String allocation // for the callers that require it. Common protocols like http and https are // stored as shared static strings. namespace WTF { class TextEncoding; } class GURL; namespace blink { class PLATFORM_EXPORT KURL { … }; PLATFORM_EXPORT bool operator==(const KURL&, const KURL&); PLATFORM_EXPORT bool operator==(const KURL&, const String&); PLATFORM_EXPORT bool operator==(const String&, const KURL&); PLATFORM_EXPORT bool operator!=(const KURL&, const KURL&); PLATFORM_EXPORT bool operator!=(const KURL&, const String&); PLATFORM_EXPORT bool operator!=(const String&, const KURL&); // Pretty printer for gtest and base/logging.*. It prepends and appends // double-quotes, and escapes characters other than ASCII printables. PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const KURL&); PLATFORM_EXPORT bool EqualIgnoringFragmentIdentifier(const KURL&, const KURL&); PLATFORM_EXPORT const KURL& BlankURL(); PLATFORM_EXPORT const KURL& SrcdocURL(); PLATFORM_EXPORT const KURL& NullURL(); // Functions to do URL operations on strings. // These are operations that aren't faster on a parsed URL. // These are also different from the KURL functions in that they don't require // the string to be a valid and parsable URL. This is especially important // because valid javascript URLs are not necessarily considered valid by KURL. PLATFORM_EXPORT bool ProtocolIs(const String& url, const char* protocol); PLATFORM_EXPORT bool ProtocolIsJavaScript(const String& url); PLATFORM_EXPORT bool IsValidProtocol(const String&); DecodeURLMode; // Unescapes the given string using URL escaping rules. // // DANGER: If the URL has "%00" in it, the resulting string will have embedded // null characters! // // This function is also used to decode javascript: URLs and as a general // purpose unescaping function. // // Caution: Specifying kUTF8OrIsomorphic to the second argument doesn't conform // to specifications in many cases. PLATFORM_EXPORT String DecodeURLEscapeSequences(const String&, DecodeURLMode mode); PLATFORM_EXPORT String EncodeWithURLEscapeSequences(const String&); // Checks an arbitrary string for invalid escape sequences. // // A valid percent-encoding is '%' followed by exactly two hex-digits. This // function returns true if an occurrence of '%' is found and followed by // anything other than two hex-digits. PLATFORM_EXPORT bool HasInvalidURLEscapeSequences(const String&); } // namespace blink namespace WTF { // Defined in kurl_hash.h. template <> struct HashTraits<blink::KURL>; template <> struct CrossThreadCopier<blink::KURL> : public CrossThreadCopierPassThrough<blink::KURL> { … }; } // namespace WTF #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WEBORIGIN_KURL_H_