Skip to content

Commit d98725e

Browse files
committed
Add a URL constructor that takes a String
https://bugs.webkit.org/show_bug.cgi?id=237068 Reviewed by Darin Adler. Source/JavaScriptCore: Adopt the new `URL(const String&)` constructor. * API/JSAPIGlobalObject.mm: (JSC::computeValidImportSpecifier): Source/WebCore: Adopt the new `URL(const String&)` constructor. * Modules/webauthn/AuthenticatorCoordinator.cpp: (WebCore::AuthenticatorCoordinatorInternal::processAppIdExtension): * Modules/websockets/WebSocket.cpp: (WebCore::WebSocket::connect): * bindings/js/ScriptModuleLoader.cpp: (WebCore::resolveModuleSpecifier): (WebCore::ScriptModuleLoader::fetch): (WebCore::ScriptModuleLoader::moduleURL): (WebCore::ScriptModuleLoader::responseURLFromRequestURL): (WebCore::ScriptModuleLoader::importModule): * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneDeserializer::readFile): (WebCore::CloneDeserializer::readTerminal): * contentextensions/ContentExtensionActions.cpp: (WebCore::ContentExtensions::RedirectAction::parse): (WebCore::ContentExtensions::RedirectAction::applyToRequest): * dom/Document.cpp: (WebCore::Document::referrer): * html/URLInputType.cpp: (WebCore::URLInputType::typeMismatchFor const): * loader/DocumentLoader.cpp: (WebCore::microsoftTeamsRedirectURL): * loader/PrivateClickMeasurement.cpp: (WebCore::PrivateClickMeasurement::parseAttributionRequestQuery): * loader/appcache/ApplicationCacheStorage.cpp: (WebCore::ApplicationCacheStorage::deleteCacheForOrigin): * loader/archive/cf/LegacyWebArchive.cpp: (WebCore::LegacyWebArchive::createResource): * loader/archive/mhtml/MHTMLParser.cpp: (WebCore::MHTMLParser::parseNextPart): * page/DOMWindow.cpp: (WebCore::DOMWindow::open): * page/Quirks.cpp: (WebCore::isBBCDomain): (WebCore::Quirks::triggerOptionalStorageAccessQuirk const): * page/SecurityOrigin.cpp: (WebCore::SecurityOrigin::createFromString): (WebCore::SecurityOrigin::create): * page/SecurityOriginData.cpp: (WebCore::SecurityOriginData::toURL const): * page/SecurityPolicy.cpp: (WebCore::SecurityPolicy::generateReferrerHeader): * page/csp/ContentSecurityPolicy.cpp: (WebCore::ContentSecurityPolicy::reportViolation const): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache): (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::setPlaybinURL): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (webKitWebSrcMakeRequest): * platform/gtk/SelectionData.cpp: (WebCore::SelectionData::setURIList): * platform/network/ResourceRequestBase.cpp: (WebCore::ResourceRequestBase::setHTTPReferrer): * platform/network/cf/ResourceErrorCF.cpp: (WebCore::ResourceError::platformLazyInit): * platform/network/cf/SocketStreamHandleImplCFNet.cpp: (WebCore::SocketStreamHandleImpl::SocketStreamHandleImpl): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::didReceiveHeader): * platform/network/mac/ResourceErrorMac.mm: (WebCore::ResourceError::platformLazyInit): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::writeString): * testing/Internals.cpp: (WebCore::Internals::sendH2Ping): Source/WTF: Add a URL constructor that takes a String to simplify our code base a bit. * wtf/URL.cpp: (WTF::URL::truncatedForUseAsBase const): (WTF::URL::fakeURLWithRelativePart): (WTF::URL::fileURLWithFileSystemPath): * wtf/URL.h: (WTF::URL::URL): (WTF::URL::decode): Canonical link: https://commits.webkit.org/247668@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290350 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ed8601a commit d98725e

37 files changed

Lines changed: 183 additions & 64 deletions

‎Source/JavaScriptCore/API/JSAPIGlobalObject.mm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
static Expected<URL, String> computeValidImportSpecifier(const URL& base, const String& specifier)
8484
{
85-
URL absoluteURL(URL(), specifier);
85+
URL absoluteURL(specifier);
8686
if (absoluteURL.isValid())
8787
return absoluteURL;
8888

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2022-02-22 Chris Dumez <cdumez@apple.com>
2+
3+
Add a URL constructor that takes a String
4+
https://bugs.webkit.org/show_bug.cgi?id=237068
5+
6+
Reviewed by Darin Adler.
7+
8+
Adopt the new `URL(const String&)` constructor.
9+
10+
* API/JSAPIGlobalObject.mm:
11+
(JSC::computeValidImportSpecifier):
12+
113
2022-02-22 Alexander Kanavin <alex@linutronix.de>
214

315
When building introspection files, add CMAKE_C_FLAGS to the compiler flags.

‎Source/WTF/ChangeLog‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2022-02-22 Chris Dumez <cdumez@apple.com>
2+
3+
Add a URL constructor that takes a String
4+
https://bugs.webkit.org/show_bug.cgi?id=237068
5+
6+
Reviewed by Darin Adler.
7+
8+
Add a URL constructor that takes a String to simplify our code base a bit.
9+
10+
* wtf/URL.cpp:
11+
(WTF::URL::truncatedForUseAsBase const):
12+
(WTF::URL::fakeURLWithRelativePart):
13+
(WTF::URL::fileURLWithFileSystemPath):
14+
* wtf/URL.h:
15+
(WTF::URL::URL):
16+
(WTF::URL::decode):
17+
118
2022-02-22 Chris Dumez <cdumez@apple.com>
219

320
Drop StringHasher::hashMemory() and use the modern Hasher instead

‎Source/WTF/wtf/URL.cpp‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ void URL::invalidate()
6464

6565
URL::URL(const URL& base, const String& relative, const URLTextEncoding* encoding)
6666
{
67-
*this = URLParser(relative, base, encoding).result();
67+
*this = URLParser(String { relative }, base, encoding).result();
68+
}
69+
70+
URL::URL(String&& absoluteURL, const URLTextEncoding* encoding)
71+
{
72+
*this = URLParser(WTFMove(absoluteURL), URL(), encoding).result();
6873
}
6974

7075
static bool shouldTrimFromURL(UChar character)
@@ -235,7 +240,7 @@ StringView URL::fragmentIdentifier() const
235240

236241
URL URL::truncatedForUseAsBase() const
237242
{
238-
return URL(URL(), m_string.left(m_pathAfterLastSlash));
243+
return URL(m_string.left(m_pathAfterLastSlash));
239244
}
240245

241246
#if !USE(CF)
@@ -571,9 +576,9 @@ static String percentEncodeCharacters(const StringType& input, bool(*shouldEncod
571576
return input;
572577
}
573578

574-
void URL::parse(const String& string)
579+
void URL::parse(String&& string)
575580
{
576-
*this = URLParser(string).result();
581+
*this = URLParser(WTFMove(string)).result();
577582
}
578583

579584
void URL::remove(unsigned start, unsigned length)
@@ -583,9 +588,9 @@ void URL::remove(unsigned start, unsigned length)
583588
ASSERT(start < m_string.length());
584589
ASSERT(length <= m_string.length() - start);
585590

586-
auto stringAfterRemoval = WTFMove(m_string);
591+
auto stringAfterRemoval = std::exchange(m_string, { });
587592
stringAfterRemoval.remove(start, length);
588-
parse(stringAfterRemoval);
593+
parse(WTFMove(stringAfterRemoval));
589594
}
590595

591596
void URL::setUser(StringView newUser)
@@ -1054,12 +1059,12 @@ String URL::stringCenterEllipsizedToLength(unsigned length) const
10541059

10551060
URL URL::fakeURLWithRelativePart(StringView relativePart)
10561061
{
1057-
return URL(URL(), makeString("webkit-fake-url://", createVersion4UUIDString(), '/', relativePart));
1062+
return URL(makeString("webkit-fake-url://", createVersion4UUIDString(), '/', relativePart));
10581063
}
10591064

10601065
URL URL::fileURLWithFileSystemPath(StringView path)
10611066
{
1062-
return URL(URL(), makeString(
1067+
return URL(makeString(
10631068
"file://",
10641069
path.startsWith('/') ? "" : "/",
10651070
escapePathWithoutCopying(path)

‎Source/WTF/wtf/URL.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class URL {
6565
// null or empty, in which case the relative URL will be interpreted as absolute.
6666
WTF_EXPORT_PRIVATE URL(const URL& base, const String& relative, const URLTextEncoding* = nullptr);
6767

68+
// Parses the input string as an absolute URL. If you need to parse a relative URL, call the constructor above
69+
// taking a base URL and a relative URL string.
70+
WTF_EXPORT_PRIVATE explicit URL(String&& absoluteURL, const URLTextEncoding* = nullptr);
71+
explicit URL(const String& absoluteURL, const URLTextEncoding* encoding = nullptr)
72+
: URL(String { absoluteURL }, encoding)
73+
{
74+
}
75+
6876
WTF_EXPORT_PRIVATE static URL fakeURLWithRelativePart(StringView);
6977
WTF_EXPORT_PRIVATE static URL fileURLWithFileSystemPath(StringView);
7078

@@ -209,7 +217,7 @@ class URL {
209217
unsigned hostStart() const;
210218
unsigned credentialsEnd() const;
211219
void remove(unsigned start, unsigned length);
212-
void parse(const String&);
220+
void parse(String&&);
213221

214222
friend WTF_EXPORT_PRIVATE bool protocolHostAndPortAreEqual(const URL&, const URL&);
215223

@@ -313,7 +321,7 @@ template<typename Decoder> std::optional<URL> URL::decode(Decoder& decoder)
313321
decoder >> string;
314322
if (!string)
315323
return std::nullopt;
316-
return URL(URL(), WTFMove(*string));
324+
return URL(WTFMove(*string));
317325
}
318326

319327
inline bool operator==(const URL& a, const URL& b)

‎Source/WTF/wtf/URLParser.cpp‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,34 +1059,34 @@ ALWAYS_INLINE size_t URLParser::currentPosition(const CodePointIterator<Characte
10591059
return iterator.codeUnitsSince(reinterpret_cast<const CharacterType*>(m_inputBegin));
10601060
}
10611061

1062-
URLParser::URLParser(const String& input, const URL& base, const URLTextEncoding* nonUTF8QueryEncoding)
1063-
: m_inputString(input)
1062+
URLParser::URLParser(String&& input, const URL& base, const URLTextEncoding* nonUTF8QueryEncoding)
1063+
: m_inputString(WTFMove(input))
10641064
{
1065-
if (input.isNull()) {
1065+
if (m_inputString.isNull()) {
10661066
if (base.isValid() && !base.m_cannotBeABaseURL) {
10671067
m_url = base;
10681068
m_url.removeFragmentIdentifier();
10691069
}
10701070
return;
10711071
}
10721072

1073-
if (input.is8Bit()) {
1074-
m_inputBegin = input.characters8();
1075-
parse(input.characters8(), input.length(), base, nonUTF8QueryEncoding);
1073+
if (m_inputString.is8Bit()) {
1074+
m_inputBegin = m_inputString.characters8();
1075+
parse(m_inputString.characters8(), m_inputString.length(), base, nonUTF8QueryEncoding);
10761076
} else {
1077-
m_inputBegin = input.characters16();
1078-
parse(input.characters16(), input.length(), base, nonUTF8QueryEncoding);
1077+
m_inputBegin = m_inputString.characters16();
1078+
parse(m_inputString.characters16(), m_inputString.length(), base, nonUTF8QueryEncoding);
10791079
}
10801080

10811081
ASSERT(!m_url.m_isValid
1082-
|| m_didSeeSyntaxViolation == (m_url.string() != input)
1083-
|| (input.isAllSpecialCharacters<isC0ControlOrSpace>() && m_url.m_string == base.m_string.left(base.m_queryEnd))
1082+
|| m_didSeeSyntaxViolation == (m_url.string() != m_inputString)
1083+
|| (m_inputString.isAllSpecialCharacters<isC0ControlOrSpace>() && m_url.m_string == base.m_string.left(base.m_queryEnd))
10841084
|| (base.isValid() && base.protocolIs("file")));
10851085
ASSERT(internalValuesConsistent(m_url));
10861086
#if ASSERT_ENABLED
10871087
if (!m_didSeeSyntaxViolation) {
10881088
// Force a syntax violation at the beginning to make sure we get the same result.
1089-
URLParser parser(makeString(" ", input), base, nonUTF8QueryEncoding);
1089+
URLParser parser(makeString(" ", m_inputString), base, nonUTF8QueryEncoding);
10901090
URL parsed = parser.result();
10911091
if (parsed.isValid())
10921092
ASSERT(allValuesEqual(parser.result(), m_url));

‎Source/WTF/wtf/URLParser.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class URLParser {
6969
static std::optional<uint16_t> defaultPortForProtocol(StringView);
7070

7171
private:
72-
URLParser(const String&, const URL& = { }, const URLTextEncoding* = nullptr);
72+
URLParser(String&&, const URL& = { }, const URLTextEncoding* = nullptr);
7373
URL result() { return m_url; }
7474

7575
friend class URL;

‎Source/WebCore/ChangeLog‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,80 @@
1+
2022-02-22 Chris Dumez <cdumez@apple.com>
2+
3+
Add a URL constructor that takes a String
4+
https://bugs.webkit.org/show_bug.cgi?id=237068
5+
6+
Reviewed by Darin Adler.
7+
8+
Adopt the new `URL(const String&)` constructor.
9+
10+
* Modules/webauthn/AuthenticatorCoordinator.cpp:
11+
(WebCore::AuthenticatorCoordinatorInternal::processAppIdExtension):
12+
* Modules/websockets/WebSocket.cpp:
13+
(WebCore::WebSocket::connect):
14+
* bindings/js/ScriptModuleLoader.cpp:
15+
(WebCore::resolveModuleSpecifier):
16+
(WebCore::ScriptModuleLoader::fetch):
17+
(WebCore::ScriptModuleLoader::moduleURL):
18+
(WebCore::ScriptModuleLoader::responseURLFromRequestURL):
19+
(WebCore::ScriptModuleLoader::importModule):
20+
* bindings/js/SerializedScriptValue.cpp:
21+
(WebCore::CloneDeserializer::readFile):
22+
(WebCore::CloneDeserializer::readTerminal):
23+
* contentextensions/ContentExtensionActions.cpp:
24+
(WebCore::ContentExtensions::RedirectAction::parse):
25+
(WebCore::ContentExtensions::RedirectAction::applyToRequest):
26+
* dom/Document.cpp:
27+
(WebCore::Document::referrer):
28+
* html/URLInputType.cpp:
29+
(WebCore::URLInputType::typeMismatchFor const):
30+
* loader/DocumentLoader.cpp:
31+
(WebCore::microsoftTeamsRedirectURL):
32+
* loader/PrivateClickMeasurement.cpp:
33+
(WebCore::PrivateClickMeasurement::parseAttributionRequestQuery):
34+
* loader/appcache/ApplicationCacheStorage.cpp:
35+
(WebCore::ApplicationCacheStorage::deleteCacheForOrigin):
36+
* loader/archive/cf/LegacyWebArchive.cpp:
37+
(WebCore::LegacyWebArchive::createResource):
38+
* loader/archive/mhtml/MHTMLParser.cpp:
39+
(WebCore::MHTMLParser::parseNextPart):
40+
* page/DOMWindow.cpp:
41+
(WebCore::DOMWindow::open):
42+
* page/Quirks.cpp:
43+
(WebCore::isBBCDomain):
44+
(WebCore::Quirks::triggerOptionalStorageAccessQuirk const):
45+
* page/SecurityOrigin.cpp:
46+
(WebCore::SecurityOrigin::createFromString):
47+
(WebCore::SecurityOrigin::create):
48+
* page/SecurityOriginData.cpp:
49+
(WebCore::SecurityOriginData::toURL const):
50+
* page/SecurityPolicy.cpp:
51+
(WebCore::SecurityPolicy::generateReferrerHeader):
52+
* page/csp/ContentSecurityPolicy.cpp:
53+
(WebCore::ContentSecurityPolicy::reportViolation const):
54+
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
55+
(WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
56+
(WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
57+
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
58+
(WebCore::MediaPlayerPrivateGStreamer::setPlaybinURL):
59+
* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
60+
(webKitWebSrcMakeRequest):
61+
* platform/gtk/SelectionData.cpp:
62+
(WebCore::SelectionData::setURIList):
63+
* platform/network/ResourceRequestBase.cpp:
64+
(WebCore::ResourceRequestBase::setHTTPReferrer):
65+
* platform/network/cf/ResourceErrorCF.cpp:
66+
(WebCore::ResourceError::platformLazyInit):
67+
* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
68+
(WebCore::SocketStreamHandleImpl::SocketStreamHandleImpl):
69+
* platform/network/curl/CurlRequest.cpp:
70+
(WebCore::CurlRequest::didReceiveHeader):
71+
* platform/network/mac/ResourceErrorMac.mm:
72+
(WebCore::ResourceError::platformLazyInit):
73+
* platform/win/PasteboardWin.cpp:
74+
(WebCore::Pasteboard::writeString):
75+
* testing/Internals.cpp:
76+
(WebCore::Internals::sendH2Ping):
77+
178
2022-02-22 Chris Dumez <cdumez@apple.com>
279

380
Drop StringHasher::hashMemory() and use the modern Hasher instead

‎Source/WebCore/Modules/webauthn/AuthenticatorCoordinator.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static String processAppIdExtension(const SecurityOrigin& facetId, const String&
7878
return facetId.toString();
7979

8080
// Step 3. Relax the comparison to same site.
81-
URL appIdURL(URL(), appId);
81+
URL appIdURL { appId };
8282
if (!appIdURL.isValid() || facetId.protocol() != appIdURL.protocol() || (RegistrableDomain(appIdURL) != RegistrableDomain::uncheckedCreateFromHost(facetId.host()) && !needsAppIdQuirks(facetId.host(), appId)))
8383
return String();
8484
return appId;

‎Source/WebCore/Modules/websockets/WebSocket.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void WebSocket::failAsynchronously()
223223
ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& protocols)
224224
{
225225
LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data());
226-
m_url = URL(URL(), url);
226+
m_url = URL { url };
227227

228228
ASSERT(scriptExecutionContext());
229229
auto& context = *scriptExecutionContext();

0 commit comments

Comments
 (0)