Diff
Modified: trunk/Source/WebCore/ChangeLog (260723 => 260724)
--- trunk/Source/WebCore/ChangeLog 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/ChangeLog 2020-04-26 14:53:33 UTC (rev 260724)
@@ -1,3 +1,48 @@
+2020-04-26 Darin Adler <[email protected]>
+
+ Remove unnecessary inlining and templates for URL decomposition DOM functions
+ https://bugs.webkit.org/show_bug.cgi?id=211025
+
+ Reviewed by Alex Christensen.
+
+ * Headers.cmake: Renamed URLUtils.h to URLDecomposition.h.
+ * Modules/cache/DOMCacheStorage.cpp: Updated include and using namespace.
+ * Sources.txt: Added URLDecomposition.cpp.
+ * WebCore.xcodeproj/project.pbxproj: Added URLDecomposition.cpp and
+ renamed URLUtils.h to URLDecomposition.h.
+
+ * html/DOMURL.h: Removed the WEBCORE_EXPORT on this class. Added final.
+ Derive from URLDecomposition instead of URLUtils. Changed return type of
+ href to const&. Moved toJSON here from URLUtils. Added overrides of the
+ fullURL and setFullURL functions for URLDecomposition.
+
+ * html/DOMURL.idl: Removed ImplementationLacksVTable.
+
+ * html/HTMLAnchorElement.cpp:
+ (WebCore::HTMLAnchorElement::HTMLAnchorElement): Moved initialization of
+ boolean data members to the class definition.
+
+ * html/HTMLAnchorElement.h: Derive from URLDecomposition instead of
+ URLUtils. Added overrides of the fullURL and setFullURL functions for
+ URLDecomposition. Initialize data members here in the class definition.
+
+ * html/HTMLMediaElement.cpp: Removed unnecessary include of DOMURL.h.
+
+ * html/URLDecomposition.cpp: Added. Contains most of the code from
+ the URLUtils class template, which no longer needs to be in a header.
+
+ * html/URLDecomposition.h: Renamed URLUtils.h to this. It's now an
+ abstract base class rather than a class template using the curiously
+ recurring template pattern.
+
+ * html/URLSearchParams.h: Forward-declare DOMURL rather than including
+ the DOMURL.h header.
+
+ * html/URLUtils.h: Removed. Renamed to URLDecompostion.h.
+
+ * page/DOMWindow.cpp: Removed unneeded include of DOMURL.h.
+ * testing/Internals.cpp: Added include of DOMURL.h.
+
2020-04-26 Cathie Chen <[email protected]>
fast/scrolling/scroll-behavior-invalidate-if-disabled.html is a flaky failure
Modified: trunk/Source/WebCore/Headers.cmake (260723 => 260724)
--- trunk/Source/WebCore/Headers.cmake 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/Headers.cmake 2020-04-26 14:53:33 UTC (rev 260724)
@@ -650,8 +650,8 @@
html/StepRange.h
html/TimeRanges.h
html/TypeAhead.h
+ html/URLDecomposition.h
html/URLRegistry.h
- html/URLUtils.h
html/ValidityState.h
html/VoidCallback.h
Modified: trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp (260723 => 260724)
--- trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -32,9 +32,9 @@
#include "JSDOMCache.h"
#include "JSFetchResponse.h"
#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
namespace WebCore {
-using namespace WebCore::DOMCacheEngine;
DOMCacheStorage::DOMCacheStorage(ScriptExecutionContext& context, Ref<CacheStorageConnection>&& connection)
: ActiveDOMObject(&context)
Modified: trunk/Source/WebCore/Sources.txt (260723 => 260724)
--- trunk/Source/WebCore/Sources.txt 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/Sources.txt 2020-04-26 14:53:33 UTC (rev 260724)
@@ -1276,6 +1276,7 @@
html/TimeInputType.cpp
html/TimeRanges.cpp
html/TypeAhead.cpp
+html/URLDecomposition.cpp
html/URLInputType.cpp
html/URLSearchParams.cpp
html/ValidationMessage.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (260723 => 260724)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-04-26 14:53:33 UTC (rev 260724)
@@ -2713,7 +2713,7 @@
93D196331D6CAB8200FC7E47 /* Exception.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D196321D6CAB8200FC7E47 /* Exception.h */; settings = {ATTRIBUTES = (Private, ); }; };
93D4379F1D57B15300AB85EA /* JSExecState.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F934D831189F1EE00508D5D /* JSExecState.h */; settings = {ATTRIBUTES = (Private, ); }; };
93D437A01D57B19A00AB85EA /* CustomElementReactionQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B56C9A81C89312800C456DF /* CustomElementReactionQueue.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 93D437A21D57B3FE00AB85EA /* URLUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 656B9DCA189DE10000BB842C /* URLUtils.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 93D437A21D57B3FE00AB85EA /* URLDecomposition.h in Headers */ = {isa = PBXBuildFile; fileRef = 656B9DCA189DE10000BB842C /* URLDecomposition.h */; settings = {ATTRIBUTES = (Private, ); }; };
93D437A31D57B7E200AB85EA /* JSMediaListCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FE716D9F204003A4E6D /* JSMediaListCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
93D9D53C0DA27E180077216C /* RangeBoundaryPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
93E241FF0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E241FE0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9256,7 +9256,7 @@
656581E909D1508D000E61D7 /* SVGNames.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SVGNames.h; path = DerivedSources/WebCore/SVGNames.h; sourceTree = BUILT_PRODUCTS_DIR; };
656581EA09D1508D000E61D7 /* XLinkNames.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = XLinkNames.cpp; path = DerivedSources/WebCore/XLinkNames.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
656581EB09D1508D000E61D7 /* XLinkNames.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = XLinkNames.h; path = DerivedSources/WebCore/XLinkNames.h; sourceTree = BUILT_PRODUCTS_DIR; };
- 656B9DCA189DE10000BB842C /* URLUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = URLUtils.h; sourceTree = "<group>"; };
+ 656B9DCA189DE10000BB842C /* URLDecomposition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = URLDecomposition.h; sourceTree = "<group>"; };
656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LoaderNSURLExtras.h; sourceTree = "<group>"; };
656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = LoaderNSURLExtras.mm; sourceTree = "<group>"; };
656D371E0ADBA5DE00A4554D /* DocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentLoader.h; sourceTree = "<group>"; };
@@ -10941,6 +10941,7 @@
93E2425E0B2B509500C732A1 /* HTMLFrameOwnerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLFrameOwnerElement.cpp; sourceTree = "<group>"; };
93E2A304123E9DC0009FE12A /* HTMLParserIdioms.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLParserIdioms.cpp; sourceTree = "<group>"; };
93E2A305123E9DC0009FE12A /* HTMLParserIdioms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLParserIdioms.h; sourceTree = "<group>"; };
+ 93E5B25424536B1E005C52D0 /* URLDecomposition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLDecomposition.cpp; sourceTree = "<group>"; };
93EB355E09E37FD600F43799 /* MouseEventWithHitTestResults.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseEventWithHitTestResults.cpp; sourceTree = "<group>"; };
93EEC1E509C2877700C515D1 /* Attr.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Attr.idl; sourceTree = "<group>"; };
93EEC1E609C2877700C515D1 /* CharacterData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CharacterData.idl; sourceTree = "<group>"; };
@@ -22519,6 +22520,8 @@
E446139F0CD6331000FADA75 /* TimeRanges.idl */,
C375D7FB16639519006184AB /* TypeAhead.cpp */,
C375D7FC16639519006184AB /* TypeAhead.h */,
+ 93E5B25424536B1E005C52D0 /* URLDecomposition.cpp */,
+ 656B9DCA189DE10000BB842C /* URLDecomposition.h */,
F55B3DA91251F12D003EF269 /* URLInputType.cpp */,
F55B3DAA1251F12D003EF269 /* URLInputType.h */,
CDEE393817974274001D7580 /* URLRegistry.h */,
@@ -22525,7 +22528,6 @@
5C5381B01D87D45700E2EBE6 /* URLSearchParams.cpp */,
5C5381B11D87D45700E2EBE6 /* URLSearchParams.h */,
5C5381AF1D8793E000E2EBE6 /* URLSearchParams.idl */,
- 656B9DCA189DE10000BB842C /* URLUtils.h */,
F5A154251279534D00D0B0C0 /* ValidationMessage.cpp */,
F5A154261279534D00D0B0C0 /* ValidationMessage.h */,
15C7708A100D3C6A005BA267 /* ValidityState.h */,
@@ -33353,10 +33355,10 @@
E4AFCFA50DAF29A300F5F55C /* UnitBezier.h in Headers */,
D086FE9809D53AAB005BC74D /* UnlinkCommand.h in Headers */,
FD1762E0176686D900D836A8 /* UpSampler.h in Headers */,
+ 93D437A21D57B3FE00AB85EA /* URLDecomposition.h in Headers */,
267726051A5DF6F2003C24DD /* URLFilterParser.h in Headers */,
F55B3DDE1251F12D003EF269 /* URLInputType.h in Headers */,
7CC289DF1AA0FE5D009A9CE3 /* URLRegistry.h in Headers */,
- 93D437A21D57B3FE00AB85EA /* URLUtils.h in Headers */,
A72763BF16689BFB002FCACB /* UserActionElementSet.h in Headers */,
868160D618766A130021E79D /* UserActivity.h in Headers */,
A3AF9D8620326861006CAD06 /* UserAgent.h in Headers */,
Modified: trunk/Source/WebCore/html/DOMURL.h (260723 => 260724)
--- trunk/Source/WebCore/html/DOMURL.h 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/DOMURL.h 2020-04-26 14:53:33 UTC (rev 260724)
@@ -27,8 +27,8 @@
#pragma once
#include "ExceptionOr.h"
+#include "URLDecomposition.h"
#include <wtf/URL.h>
-#include "URLUtils.h"
namespace WebCore {
@@ -37,7 +37,7 @@
class URLRegistrable;
class URLSearchParams;
-class WEBCORE_EXPORT DOMURL : public RefCounted<DOMURL>, public URLUtils<DOMURL> {
+class DOMURL final : public RefCounted<DOMURL>, public URLDecomposition {
public:
static ExceptionOr<Ref<DOMURL>> create(const String& url, const String& base);
static ExceptionOr<Ref<DOMURL>> create(const String& url, const DOMURL& base);
@@ -44,12 +44,14 @@
static ExceptionOr<Ref<DOMURL>> create(const String& url);
~DOMURL();
- URL href() const { return m_url; }
- ExceptionOr<void> setHref(const String& url);
+ const URL& href() const { return m_url; }
+ ExceptionOr<void> setHref(const String&);
void setQuery(const String&);
URLSearchParams& searchParams();
+ const String& toJSON() const { return m_url.string(); }
+
static String createObjectURL(ScriptExecutionContext&, Blob&);
static void revokeObjectURL(ScriptExecutionContext&, const String&);
@@ -58,6 +60,9 @@
private:
DOMURL(URL&& completeURL, URL&& baseURL);
+ URL fullURL() const final { return m_url; }
+ void setFullURL(const URL& fullURL) final { setHref(fullURL.string()); }
+
URL m_baseURL;
URL m_url;
RefPtr<URLSearchParams> m_searchParams;
Modified: trunk/Source/WebCore/html/DOMURL.idl (260723 => 260724)
--- trunk/Source/WebCore/html/DOMURL.idl 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/DOMURL.idl 2020-04-26 14:53:33 UTC (rev 260724)
@@ -32,7 +32,6 @@
ConstructorMayThrowException,
ExportMacro=WEBCORE_EXPORT,
Exposed=(Window,Worker),
- ImplementationLacksVTable,
InterfaceName=URL,
JSGenerateToJSObject,
JSGenerateToNativeObject,
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (260723 => 260724)
--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -65,8 +65,6 @@
HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document)
- , m_hasRootEditableElementForSelectionOnMouseDown(false)
- , m_wasShiftKeyDownOnMouseDown(false)
{
}
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.h (260723 => 260724)
--- trunk/Source/WebCore/html/HTMLAnchorElement.h 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.h 2020-04-26 14:53:33 UTC (rev 260724)
@@ -26,7 +26,7 @@
#include "HTMLElement.h"
#include "HTMLNames.h"
#include "SharedStringHash.h"
-#include "URLUtils.h"
+#include "URLDecomposition.h"
#include <wtf/OptionSet.h>
namespace WebCore {
@@ -41,7 +41,7 @@
Opener = 1 << 2,
};
-class HTMLAnchorElement : public HTMLElement, public URLUtils<HTMLAnchorElement> {
+class HTMLAnchorElement : public HTMLElement, public URLDecomposition {
WTF_MAKE_ISO_ALLOCATED(HTMLAnchorElement);
public:
static Ref<HTMLAnchorElement> create(Document&);
@@ -116,8 +116,11 @@
void setRootEditableElementForSelectionOnMouseDown(Element*);
void clearRootEditableElementForSelectionOnMouseDown();
- bool m_hasRootEditableElementForSelectionOnMouseDown;
- bool m_wasShiftKeyDownOnMouseDown;
+ URL fullURL() const final { return href(); }
+ void setFullURL(const URL& fullURL) final { setHref(fullURL.string()); }
+
+ bool m_hasRootEditableElementForSelectionOnMouseDown { false };
+ bool m_wasShiftKeyDownOnMouseDown { false };
OptionSet<Relation> m_linkRelations;
// This is computed only once and must not be affected by subsequent URL changes.
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (260723 => 260724)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -149,7 +149,6 @@
#endif
#if ENABLE(MEDIA_STREAM)
-#include "DOMURL.h"
#include "MediaStream.h"
#endif
Added: trunk/Source/WebCore/html/URLDecomposition.cpp (0 => 260724)
--- trunk/Source/WebCore/html/URLDecomposition.cpp (rev 0)
+++ trunk/Source/WebCore/html/URLDecomposition.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2014-2020 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 AND ITS CONTRIBUTORS "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 OR ITS 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.
+ */
+
+#include "config.h"
+#include "URLDecomposition.h"
+
+#include "SecurityOrigin.h"
+
+namespace WebCore {
+
+String URLDecomposition::origin() const
+{
+ return SecurityOrigin::create(fullURL())->toString();
+}
+
+String URLDecomposition::protocol() const
+{
+ auto fullURL = this->fullURL();
+ if (WTF::protocolIsJavaScript(fullURL.string()))
+ return "_javascript_:"_s;
+ return makeString(fullURL.protocol(), ':');
+}
+
+void URLDecomposition::setProtocol(StringView value)
+{
+ URL copy = fullURL();
+ copy.setProtocol(value);
+ setFullURL(copy);
+}
+
+String URLDecomposition::username() const
+{
+ return fullURL().encodedUser().toString();
+}
+
+void URLDecomposition::setUsername(StringView user)
+{
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL())
+ return;
+ fullURL.setUser(user);
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::password() const
+{
+ return fullURL().encodedPassword().toString();
+}
+
+void URLDecomposition::setPassword(StringView password)
+{
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL())
+ return;
+ fullURL.setPassword(password);
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::host() const
+{
+ return fullURL().hostAndPort();
+}
+
+static unsigned countASCIIDigits(StringView string)
+{
+ unsigned length = string.length();
+ for (unsigned count = 0; count < length; ++count) {
+ if (!isASCIIDigit(string[count]))
+ return count;
+ }
+ return length;
+}
+
+void URLDecomposition::setHost(StringView value)
+{
+ if (value.isEmpty())
+ return;
+
+ size_t separator = value.find(':');
+ if (!separator)
+ return;
+
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL() || !fullURL.canSetHostOrPort())
+ return;
+
+ if (separator == notFound)
+ fullURL.setHostAndPort(value);
+ else {
+ unsigned portLength = countASCIIDigits(value.substring(separator + 1));
+ if (!portLength) {
+ // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
+ // specifically goes against RFC 3986 (p3.2) and
+ // requires setting the port to "0" if it is set to empty string.
+ // FIXME: This seems like something that has since been changed and this rule and code may be obsolete.
+ fullURL.setHostAndPort(makeString(value.substring(0, separator + 1), '0'));
+ } else {
+ auto portNumber = parseUInt16(value.substring(separator + 1, portLength));
+ if (portNumber && WTF::isDefaultPortForProtocol(*portNumber, fullURL.protocol()))
+ fullURL.setHostAndPort(value.substring(0, separator));
+ else
+ fullURL.setHostAndPort(value.substring(0, separator + 1 + portLength));
+ }
+ }
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::hostname() const
+{
+ return fullURL().host().toString();
+}
+
+static StringView removeAllLeadingSolidusCharacters(StringView string)
+{
+ unsigned i;
+ unsigned length = string.length();
+ for (i = 0; i < length; ++i) {
+ if (string[i] != '/')
+ break;
+ }
+ return string.substring(i);
+}
+
+void URLDecomposition::setHostname(StringView value)
+{
+ auto host = removeAllLeadingSolidusCharacters(value);
+ if (host.isEmpty())
+ return;
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL() || !fullURL.canSetHostOrPort())
+ return;
+ fullURL.setHost(host);
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::port() const
+{
+ auto port = fullURL().port();
+ if (!port)
+ return emptyString();
+ return String::number(*port);
+}
+
+// Outer optional is whether we could parse at all. Inner optional is "no port specified".
+static Optional<Optional<uint16_t>> parsePort(StringView string, StringView protocol)
+{
+ auto digitsOnly = string.left(countASCIIDigits(string));
+ if (digitsOnly.isEmpty())
+ return Optional<uint16_t> { WTF::nullopt };
+ auto port = parseUInt16(digitsOnly);
+ if (!port)
+ return WTF::nullopt;
+ if (WTF::isDefaultPortForProtocol(*port, protocol))
+ return Optional<uint16_t> { WTF::nullopt };
+ return { { *port } };
+}
+
+void URLDecomposition::setPort(StringView value)
+{
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL() || fullURL.protocolIs("file") || !fullURL.canSetHostOrPort())
+ return;
+ auto port = parsePort(value, fullURL.protocol());
+ if (!port)
+ return;
+ fullURL.setPort(*port);
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::pathname() const
+{
+ return fullURL().path().toString();
+}
+
+void URLDecomposition::setPathname(StringView value)
+{
+ auto fullURL = this->fullURL();
+ if (fullURL.cannotBeABaseURL() || !fullURL.canSetPathname())
+ return;
+ if (value.startsWith('/'))
+ fullURL.setPath(value);
+ else
+ fullURL.setPath(makeString('/', value));
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::search() const
+{
+ auto fullURL = this->fullURL();
+ return fullURL.query().isEmpty() ? emptyString() : fullURL.queryWithLeadingQuestionMark().toString();
+}
+
+void URLDecomposition::setSearch(const String& value)
+{
+ auto fullURL = this->fullURL();
+ if (value.isEmpty()) {
+ // If the given value is the empty string, set url's query to null.
+ fullURL.setQuery({ });
+ } else {
+ String newSearch = value.startsWith('?') ? value.substring(1) : value;
+ // Make sure that '#' in the query does not leak to the hash.
+ fullURL.setQuery(newSearch.replaceWithLiteral('#', "%23"));
+ }
+ setFullURL(fullURL);
+}
+
+String URLDecomposition::hash() const
+{
+ // FIXME: Why convert this string to an atom here instead of just a string? Intentionally to save memory? An error?
+ auto fullURL = this->fullURL();
+ return fullURL.fragmentIdentifier().isEmpty() ? emptyAtom() : fullURL.fragmentIdentifierWithLeadingNumberSign().toAtomString();
+}
+
+void URLDecomposition::setHash(StringView value)
+{
+ auto fullURL = this->fullURL();
+ auto newFragment = value.startsWith('#') ? StringView(value).substring(1) : StringView(value);
+ if (newFragment.isEmpty())
+ fullURL.removeFragmentIdentifier();
+ else
+ fullURL.setFragmentIdentifier(newFragment);
+ setFullURL(fullURL);
+}
+
+}
Copied: trunk/Source/WebCore/html/URLDecomposition.h (from rev 260723, trunk/Source/WebCore/html/DOMURL.h) (0 => 260724)
--- trunk/Source/WebCore/html/URLDecomposition.h (rev 0)
+++ trunk/Source/WebCore/html/URLDecomposition.h 2020-04-26 14:53:33 UTC (rev 260724)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2014-2020 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 AND ITS CONTRIBUTORS "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 OR ITS 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.
+ */
+
+#pragma once
+
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+class URLDecomposition {
+public:
+ String origin() const;
+
+ WEBCORE_EXPORT String protocol() const;
+ void setProtocol(StringView);
+
+ String username() const;
+ void setUsername(StringView);
+
+ String password() const;
+ void setPassword(StringView);
+
+ WEBCORE_EXPORT String host() const;
+ void setHost(StringView);
+
+ WEBCORE_EXPORT String hostname() const;
+ void setHostname(StringView);
+
+ WEBCORE_EXPORT String port() const;
+ void setPort(StringView);
+
+ WEBCORE_EXPORT String pathname() const;
+ void setPathname(StringView);
+
+ WEBCORE_EXPORT String search() const;
+ void setSearch(const String&);
+
+ WEBCORE_EXPORT String hash() const;
+ void setHash(StringView);
+
+protected:
+ virtual ~URLDecomposition() = default;
+
+private:
+ virtual URL fullURL() const = 0;
+ virtual void setFullURL(const URL&) = 0;
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/html/URLSearchParams.h (260723 => 260724)
--- trunk/Source/WebCore/html/URLSearchParams.h 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/URLSearchParams.h 2020-04-26 14:53:33 UTC (rev 260724)
@@ -24,7 +24,6 @@
#pragma once
-#include "DOMURL.h"
#include <wtf/Variant.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -31,6 +30,8 @@
namespace WebCore {
+class DOMURL;
+
class URLSearchParams : public RefCounted<URLSearchParams> {
public:
static ExceptionOr<Ref<URLSearchParams>> create(Variant<Vector<Vector<String>>, Vector<WTF::KeyValuePair<String, String>>, String>&&);
Deleted: trunk/Source/WebCore/html/URLUtils.h (260723 => 260724)
--- trunk/Source/WebCore/html/URLUtils.h 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/html/URLUtils.h 2020-04-26 14:53:33 UTC (rev 260724)
@@ -1,296 +0,0 @@
-/*
- * Copyright (C) 2014-2020 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 AND ITS CONTRIBUTORS "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 OR ITS 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.
- */
-
-#pragma once
-
-#include "SecurityOrigin.h"
-
-namespace WebCore {
-
-// FIXME: Rename this to URLDecompositionFunctions.
-template<typename T> class URLUtils {
-public:
- URL href() const { return static_cast<const T*>(this)->href(); }
- void setHref(const String& url) { static_cast<T*>(this)->setHref(url); }
-
- String toString() const;
- String toJSON() const;
-
- String origin() const;
-
- String protocol() const;
- void setProtocol(StringView);
-
- String username() const;
- void setUsername(StringView);
-
- String password() const;
- void setPassword(StringView);
-
- String host() const;
- void setHost(StringView);
-
- String hostname() const;
- void setHostname(StringView);
-
- String port() const;
- void setPort(StringView);
-
- String pathname() const;
- void setPathname(StringView);
-
- String search() const;
- void setSearch(const String&);
-
- String hash() const;
- void setHash(StringView);
-};
-
-template<typename T> String URLUtils<T>::toString() const
-{
- return href().string();
-}
-
-template<typename T> String URLUtils<T>::toJSON() const
-{
- return href().string();
-}
-
-template<typename T> String URLUtils<T>::origin() const
-{
- return SecurityOrigin::create(href())->toString();
-}
-
-template<typename T> String URLUtils<T>::protocol() const
-{
- if (WTF::protocolIsJavaScript(href()))
- return "_javascript_:"_s;
- return makeString(href().protocol(), ':');
-}
-
-template<typename T> void URLUtils<T>::setProtocol(StringView value)
-{
- URL url = ""
- url.setProtocol(value);
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::username() const
-{
- return href().encodedUser().toString();
-}
-
-template<typename T> void URLUtils<T>::setUsername(StringView user)
-{
- URL url = ""
- if (url.cannotBeABaseURL())
- return;
- url.setUser(user);
- setHref(url);
-}
-
-template<typename T> String URLUtils<T>::password() const
-{
- return href().encodedPassword().toString();
-}
-
-template<typename T> void URLUtils<T>::setPassword(StringView password)
-{
- URL url = ""
- if (url.cannotBeABaseURL())
- return;
- url.setPassword(password);
- setHref(url);
-}
-
-template<typename T> String URLUtils<T>::host() const
-{
- return href().hostAndPort();
-}
-
-inline unsigned countASCIIDigits(StringView string)
-{
- unsigned length = string.length();
- for (unsigned count = 0; count < length; ++count) {
- if (!isASCIIDigit(string[count]))
- return count;
- }
- return length;
-}
-
-template<typename T> void URLUtils<T>::setHost(StringView value)
-{
- if (value.isEmpty())
- return;
- URL url = ""
- if (url.cannotBeABaseURL())
- return;
- if (!url.canSetHostOrPort())
- return;
-
- size_t separator = value.find(':');
- if (!separator)
- return;
-
- if (separator == notFound)
- url.setHostAndPort(value);
- else {
- unsigned portLength = countASCIIDigits(value.substring(separator + 1));
- if (!portLength) {
- // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
- // specifically goes against RFC 3986 (p3.2) and
- // requires setting the port to "0" if it is set to empty string.
- // FIXME: This seems like something that has since been changed and this rule and code may be obsolete.
- url.setHostAndPort(makeString(value.substring(0, separator + 1), '0'));
- } else {
- auto portNumber = parseUInt16(value.substring(separator + 1, portLength));
- if (portNumber && WTF::isDefaultPortForProtocol(*portNumber, url.protocol()))
- url.setHostAndPort(value.substring(0, separator));
- else
- url.setHostAndPort(value.substring(0, separator + 1 + portLength));
- }
- }
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::hostname() const
-{
- return href().host().toString();
-}
-
-inline StringView removeAllLeadingSolidusCharacters(StringView string)
-{
- unsigned i;
- unsigned length = string.length();
- for (i = 0; i < length; ++i) {
- if (string[i] != '/')
- break;
- }
- return string.substring(i);
-}
-
-template<typename T> void URLUtils<T>::setHostname(StringView value)
-{
- auto host = removeAllLeadingSolidusCharacters(value);
- if (host.isEmpty())
- return;
-
- URL url = ""
- if (url.cannotBeABaseURL())
- return;
- if (!url.canSetHostOrPort())
- return;
-
- url.setHost(host);
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::port() const
-{
- if (href().port())
- return String::number(href().port().value());
-
- return emptyString();
-}
-
-template<typename T> void URLUtils<T>::setPort(StringView value)
-{
- URL url = ""
- if (url.cannotBeABaseURL() || url.protocolIs("file") || !url.canSetHostOrPort())
- return;
-
- auto digitsOnly = value.left(countASCIIDigits(value));
- Optional<uint16_t> port;
- if (!digitsOnly.isEmpty()) {
- port = parseUInt16(digitsOnly);
- if (!port)
- return;
- if (WTF::isDefaultPortForProtocol(*port, url.protocol()))
- port = WTF::nullopt;
- }
- url.setPort(port);
-
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::pathname() const
-{
- return href().path().toString();
-}
-
-template<typename T> void URLUtils<T>::setPathname(StringView value)
-{
- URL url = ""
- if (url.cannotBeABaseURL())
- return;
- if (!url.canSetPathname())
- return;
-
- if (value.startsWith('/'))
- url.setPath(value);
- else
- url.setPath(makeString('/', value));
-
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::search() const
-{
- return href().query().isEmpty() ? emptyString() : href().queryWithLeadingQuestionMark().toString();
-}
-
-template<typename T> void URLUtils<T>::setSearch(const String& value)
-{
- URL url = ""
- if (value.isEmpty()) {
- // If the given value is the empty string, set url's query to null.
- url.setQuery({ });
- } else {
- String newSearch = value.startsWith('?') ? value.substring(1) : value;
- // Make sure that '#' in the query does not leak to the hash.
- url.setQuery(newSearch.replaceWithLiteral('#', "%23"));
- }
-
- setHref(url.string());
-}
-
-template<typename T> String URLUtils<T>::hash() const
-{
- // FIXME: Why convert this string to an atom here instead of just a string? Intentionally to save memory? An error?
- return href().fragmentIdentifier().isEmpty() ? emptyAtom() : href().fragmentIdentifierWithLeadingNumberSign().toAtomString();
-}
-
-template<typename T> void URLUtils<T>::setHash(StringView value)
-{
- URL url = ""
- auto newFragment = value.startsWith('#') ? StringView(value).substring(1) : StringView(value);
- if (newFragment.isEmpty())
- url.removeFragmentIdentifier();
- else
- url.setFragmentIdentifier(newFragment);
- setHref(url.string());
-}
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (260723 => 260724)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -45,7 +45,6 @@
#include "DOMStringList.h"
#include "DOMTimer.h"
#include "DOMTokenList.h"
-#include "DOMURL.h"
#include "DeviceMotionController.h"
#include "DeviceMotionData.h"
#include "DeviceMotionEvent.h"
Modified: trunk/Source/WebCore/testing/Internals.cpp (260723 => 260724)
--- trunk/Source/WebCore/testing/Internals.cpp 2020-04-26 07:37:24 UTC (rev 260723)
+++ trunk/Source/WebCore/testing/Internals.cpp 2020-04-26 14:53:33 UTC (rev 260724)
@@ -58,6 +58,7 @@
#include "DOMRect.h"
#include "DOMRectList.h"
#include "DOMStringList.h"
+#include "DOMURL.h"
#include "DOMWindow.h"
#include "DeprecatedGlobalSettings.h"
#include "DiagnosticLoggingClient.h"