Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ScopedURL in Document #8255

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
page/RemoteFrame.h
page/RemoteFrameClient.h
page/RenderingUpdateScheduler.h
page/ScopedURL.h
page/ScreenOrientationLockType.h
page/ScreenOrientationType.h
page/ScrollBehavior.h
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#if ENABLE(MEDIA_SOURCE)

#include "MediaSource.h"
#include "ScopedURL.h"
#include "ScriptExecutionContext.h"
#include <wtf/MainThread.h>
#include <wtf/NeverDestroyed.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ void MediaSourceRegistry::registerURL(const ScriptExecutionContext& context, con
m_mediaSources.add(urlString, std::pair { RefPtr { &source }, context.identifier() });
}

void MediaSourceRegistry::unregisterURL(const URL& url)
void MediaSourceRegistry::unregisterURL(const ScopedURL& url)
{
// MediaSource objects are not exposed to workers.
if (!isMainThread())
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/mediasource/MediaSourceRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
namespace WebCore {

class MediaSource;
class ScopedURL;

class MediaSourceRegistry final : public URLRegistry {
friend class NeverDestroyed<MediaSourceRegistry>;
Expand All @@ -49,7 +50,7 @@ class MediaSourceRegistry final : public URLRegistry {

// Registers a blob URL referring to the specified media source.
void registerURL(const ScriptExecutionContext&, const URL&, URLRegistrable&) final;
void unregisterURL(const URL&) final;
void unregisterURL(const ScopedURL&) final;
void unregisterURLsForContext(const ScriptExecutionContext&) final;
URLRegistrable* lookup(const String&) const final;

Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/Modules/websockets/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "MessageEvent.h"
#include "MixedContentChecker.h"
#include "ResourceLoadObserver.h"
#include "ScopedURL.h"
#include "ScriptController.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
Expand Down Expand Up @@ -226,7 +227,7 @@ void WebSocket::failAsynchronously()
ExceptionOr<void> WebSocket::connect(const String& url, const Vector<String>& protocols)
{
LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data());
m_url = URL { url };
m_url = ScopedURL { url };

ASSERT(scriptExecutionContext());
auto& context = *scriptExecutionContext();
Expand Down Expand Up @@ -478,7 +479,7 @@ RefPtr<ThreadableWebSocketChannel> WebSocket::channel() const
return m_channel;
}

const URL& WebSocket::url() const
const ScopedURL& WebSocket::url() const
{
return m_url;
}
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/Modules/websockets/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ArrayBufferView;
namespace WebCore {

class Blob;
class ScopedURL;
class ThreadableWebSocketChannel;

class WebSocket final : public RefCounted<WebSocket>, public EventTarget, public ActiveDOMObject, private WebSocketChannelClient {
Expand Down Expand Up @@ -81,7 +82,7 @@ class WebSocket final : public RefCounted<WebSocket>, public EventTarget, public

RefPtr<ThreadableWebSocketChannel> channel() const;

const URL& url() const;
const ScopedURL& url() const;
State readyState() const;
unsigned bufferedAmount() const;

Expand Down Expand Up @@ -131,7 +132,7 @@ class WebSocket final : public RefCounted<WebSocket>, public EventTarget, public
RefPtr<ThreadableWebSocketChannel> m_channel;

State m_state { CONNECTING };
URL m_url;
ScopedURL m_url;
unsigned m_bufferedAmount { 0 };
unsigned m_bufferedAmountAfterClose { 0 };
BinaryType m_binaryType { BinaryType::Blob };
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,7 @@
D0EDA775143E303C0028E383 /* CachedRawResource.h in Headers */ = {isa = PBXBuildFile; fileRef = D0EDA773143E303C0028E383 /* CachedRawResource.h */; settings = {ATTRIBUTES = (Private, ); }; };
D0FF2A5E11F8C45A007E74E0 /* PingLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = D0FF2A5C11F8C45A007E74E0 /* PingLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
D2BB5C65290985E40065457D /* NetworkConnectionIntegrity.h in Headers */ = {isa = PBXBuildFile; fileRef = D2BB5C64290985E40065457D /* NetworkConnectionIntegrity.h */; settings = {ATTRIBUTES = (Private, ); }; };
D2EBD7C3294694CE006FDFCB /* ScopedURL.h in Headers */ = {isa = PBXBuildFile; fileRef = D2EBD7C22946949D006FDFCB /* ScopedURL.h */; settings = {ATTRIBUTES = (Private, ); }; };
D302754A12A5FE84004BD828 /* RenderDetailsMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = D302754612A5FE84004BD828 /* RenderDetailsMarker.h */; };
D359D78A129CA2710006E5D2 /* HTMLDetailsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = D359D787129CA2710006E5D2 /* HTMLDetailsElement.h */; };
D359D8BF129CA55C0006E5D2 /* JSHTMLDetailsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = D359D8BD129CA55C0006E5D2 /* JSHTMLDetailsElement.h */; };
Expand Down Expand Up @@ -17152,6 +17153,7 @@
D0FF2A5C11F8C45A007E74E0 /* PingLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PingLoader.h; sourceTree = "<group>"; };
D2BB5C64290985E40065457D /* NetworkConnectionIntegrity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkConnectionIntegrity.h; sourceTree = "<group>"; };
D2CDB5ED638F43AF86F07AA2 /* JSErrorEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorEventCustom.cpp; sourceTree = "<group>"; };
D2EBD7C22946949D006FDFCB /* ScopedURL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScopedURL.h; sourceTree = "<group>"; };
D302754512A5FE84004BD828 /* RenderDetailsMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderDetailsMarker.cpp; sourceTree = "<group>"; };
D302754612A5FE84004BD828 /* RenderDetailsMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderDetailsMarker.h; sourceTree = "<group>"; };
D359D786129CA2710006E5D2 /* HTMLDetailsElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLDetailsElement.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -25325,6 +25327,7 @@
ADBAD6ED1BCDD95000381325 /* ResourceUsageOverlay.h */,
A5071E831C56D079009951BE /* ResourceUsageThread.cpp */,
A5071E841C56D079009951BE /* ResourceUsageThread.h */,
D2EBD7C22946949D006FDFCB /* ScopedURL.h */,
BCEC01BA0C274DAC009F4EC9 /* Screen.cpp */,
BCEC01BB0C274DAC009F4EC9 /* Screen.h */,
BCEC01BC0C274DAC009F4EC9 /* Screen.idl */,
Expand Down Expand Up @@ -38641,6 +38644,7 @@
5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */,
9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */,
7B7311FB25C092B7003B2796 /* ScopedHighPerformanceGPURequest.h in Headers */,
D2EBD7C3294694CE006FDFCB /* ScopedURL.h in Headers */,
BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
070BED98273F415D00583926 /* ScreenCaptureKitCaptureSource.h in Headers */,
073955BB27AB277F009A08D2 /* ScreenCaptureKitSharingSessionManager.h in Headers */,
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
#include "SVGUseElement.h"
#include "SWClientConnection.h"
#include "ScopedEventQueue.h"
#include "ScopedURL.h"
#include "ScriptController.h"
#include "ScriptDisallowedScope.h"
#include "ScriptModuleLoader.h"
Expand Down Expand Up @@ -3521,9 +3522,9 @@ void Document::logExceptionToConsole(const String& errorMessage, const String& s
addMessage(MessageSource::JS, MessageLevel::Error, errorMessage, sourceURL, lineNumber, columnNumber, WTFMove(callStack));
}

void Document::setURL(const URL& url)
void Document::setURL(const ScopedURL& url)
{
URL newURL = url.isEmpty() ? aboutBlankURL() : url;
auto newURL = url.isEmpty() ? ScopedURL { aboutBlankURL() } : url;
if (newURL == m_url)
return;

Expand Down Expand Up @@ -6608,7 +6609,7 @@ bool Document::isContextThread() const
}

// https://w3c.github.io/webappsec-secure-contexts/#is-url-trustworthy
static bool isURLPotentiallyTrustworthy(const URL& url)
static bool isURLPotentiallyTrustworthy(const ScopedURL& url)
{
if (url.protocolIsAbout())
return url.isAboutBlank() || url.isAboutSrcDoc();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/dom/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ class Document

bool wellFormed() const { return m_wellFormed; }

const URL& url() const final { return m_url; }
void setURL(const URL&);
const ScopedURL& url() const final { return m_url; }
void setURL(const ScopedURL&);
WEBCORE_EXPORT const URL& urlForBindings() const;

URL adjustedURL() const;
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/dom/SecurityContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ContentSecurityPolicy.h"
#include "HTMLParserIdioms.h"
#include "PolicyContainer.h"
#include "ScopedURL.h"
#include "SecurityOrigin.h"
#include "SecurityOriginPolicy.h"
#include <wtf/text/StringBuilder.h>
Expand Down Expand Up @@ -59,15 +60,15 @@ void SecurityContext::setContentSecurityPolicy(std::unique_ptr<ContentSecurityPo
m_contentSecurityPolicy = WTFMove(contentSecurityPolicy);
}

bool SecurityContext::isSecureTransitionTo(const URL& url) const
bool SecurityContext::isSecureTransitionTo(const ScopedURL& url) const
{
// If we haven't initialized our security origin by now, this is probably
// a new window created via the API (i.e., that lacks an origin and lacks
// a place to inherit the origin from).
if (!haveInitializedSecurityOrigin())
return true;

return securityOriginPolicy()->origin().isSameOriginDomain(SecurityOrigin::create(url).get());
return securityOrigin()->isSameOriginDomain(SecurityOrigin::create(url).get());
}

void SecurityContext::enforceSandboxFlags(SandboxFlags mask, SandboxFlagsSource source)
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/dom/SecurityContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace WebCore {
class SecurityOrigin;
class SecurityOriginPolicy;
class ContentSecurityPolicy;
class ScopedURL;
struct CrossOriginOpenerPolicy;
struct PolicyContainer;
enum class ReferrerPolicy : uint8_t;
Expand Down Expand Up @@ -74,7 +75,7 @@ class SecurityContext {
SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
ContentSecurityPolicy* contentSecurityPolicy() { return m_contentSecurityPolicy.get(); }

bool isSecureTransitionTo(const URL&) const;
bool isSecureTransitionTo(const ScopedURL&) const;

enum class SandboxFlagsSource : bool { CSP, Other };
void enforceSandboxFlags(SandboxFlags, SandboxFlagsSource = SandboxFlagsSource::Other);
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/fileapi/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "PolicyContainer.h"
#include "ReadableStream.h"
#include "ReadableStreamSource.h"
#include "ScopedURL.h"
#include "ScriptExecutionContext.h"
#include "SharedBuffer.h"
#include "ThreadableBlobRegistry.h"
Expand All @@ -58,7 +59,7 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(Blob);
class BlobURLRegistry final : public URLRegistry {
public:
void registerURL(const ScriptExecutionContext&, const URL&, URLRegistrable&) final;
void unregisterURL(const URL&) final;
void unregisterURL(const ScopedURL&) final;
void unregisterURLsForContext(const ScriptExecutionContext&) final;

static URLRegistry& registry();
Expand All @@ -77,7 +78,7 @@ void BlobURLRegistry::registerURL(const ScriptExecutionContext& context, const U
ThreadableBlobRegistry::registerBlobURL(context.securityOrigin(), context.policyContainer(), publicURL, static_cast<Blob&>(blob).url());
}

void BlobURLRegistry::unregisterURL(const URL& url)
void BlobURLRegistry::unregisterURL(const ScopedURL& url)
{
bool isURLRegistered = false;
{
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/fileapi/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Blob;
class BlobLoader;
class DeferredPromise;
class ReadableStream;
class ScopedURL;
class ScriptExecutionContext;
class FragmentedSharedBuffer;
class WebCoreOpaqueRoot;
Expand Down Expand Up @@ -95,7 +96,7 @@ class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Bl

virtual ~Blob();

URL url() const { return m_internalURL; }
ScopedURL url() const { return m_internalURL; }
const String& type() const { return m_type; }

WEBCORE_EXPORT unsigned long long size() const;
Expand Down Expand Up @@ -154,7 +155,7 @@ class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Bl
// This is an internal URL referring to the blob data associated with this object. It serves
// as an identifier for this blob. The internal URL is never used to source the blob's content
// into an HTML or for FileRead'ing, public blob URLs must be used for those purposes.
URL m_internalURL;
ScopedURL m_internalURL;

HashSet<std::unique_ptr<BlobLoader>> m_blobLoaders;
};
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/fileapi/BlobLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ExceptionCode.h"
#include "FileReaderLoader.h"
#include "FileReaderLoaderClient.h"
#include "ScopedURL.h"
#include "SharedBuffer.h"
#include <JavaScriptCore/ArrayBuffer.h>
#include <wtf/CompletionHandler.h>
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/fileapi/BlobURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "BlobURL.h"
#include "Document.h"
#include "ScopedURL.h"
#include "SecurityOrigin.h"
#include "ThreadableBlobRegistry.h"

Expand Down Expand Up @@ -66,7 +67,7 @@ static const Document* blobOwner(const SecurityOrigin& blobOrigin)
return nullptr;
}

URL BlobURL::getOriginURL(const URL& url)
URL BlobURL::getOriginURL(const ScopedURL& url)
{
ASSERT(url.protocolIs(kBlobProtocol));

Expand All @@ -77,7 +78,7 @@ URL BlobURL::getOriginURL(const URL& url)
return SecurityOrigin::extractInnerURL(url);
}

bool BlobURL::isSecureBlobURL(const URL& url)
bool BlobURL::isSecureBlobURL(const ScopedURL& url)
{
ASSERT(url.protocolIs(kBlobProtocol));

Expand All @@ -86,7 +87,7 @@ bool BlobURL::isSecureBlobURL(const URL& url)
if (auto* document = blobOwner(*origin))
return document->isSecureContext();
}
return SecurityOrigin::isSecure(url);
return false;
}

URL BlobURL::createBlobURL(StringView originString)
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/fileapi/BlobURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

namespace WebCore {

class ScopedURL;
class SecurityOrigin;

// Blob URLs are of the form
Expand All @@ -50,8 +51,8 @@ class BlobURL {
static URL createPublicURL(SecurityOrigin*);
static URL createInternalURL();

static URL getOriginURL(const URL&);
static bool isSecureBlobURL(const URL&);
static URL getOriginURL(const ScopedURL&);
static bool isSecureBlobURL(const ScopedURL&);

private:
static URL createBlobURL(StringView originString);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/fileapi/FileReaderLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blo
start(scriptExecutionContext, blob.url());
}

void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, const URL& blobURL)
void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, const ScopedURL& blobURL)
{
ASSERT(scriptExecutionContext);

Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/fileapi/FileReaderLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "BlobResourceHandle.h"
#include "ExceptionCode.h"
#include "ScopedURL.h"
#include "ThreadableLoaderClient.h"
#include <pal/text/TextEncoding.h>
#include <wtf/Forward.h>
Expand Down Expand Up @@ -67,7 +68,7 @@ class FileReaderLoader : public ThreadableLoaderClient {
~FileReaderLoader();

WEBCORE_EXPORT void start(ScriptExecutionContext*, Blob&);
void start(ScriptExecutionContext*, const URL&);
void start(ScriptExecutionContext*, const ScopedURL&);
WEBCORE_EXPORT void cancel();

// ThreadableLoaderClient
Expand Down Expand Up @@ -104,7 +105,7 @@ class FileReaderLoader : public ThreadableLoaderClient {
PAL::TextEncoding m_encoding;
String m_dataType;

URL m_urlForReading;
ScopedURL m_urlForReading;
RefPtr<ThreadableLoader> m_loader;

RefPtr<JSC::ArrayBuffer> m_rawData;
Expand Down