diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 176fbfa02433..d86d3ede4c36 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -1249,6 +1249,7 @@ set(WebCore_NON_SVG_IDL_FILES page/BarProp.idl page/Crypto.idl page/DOMSelection.idl + page/DOMWindow.idl page/EventSource.idl page/History.idl page/IntersectionObserver.idl @@ -1319,6 +1320,7 @@ set(WebCore_NON_SVG_IDL_FILES page/WindowOrWorkerGlobalScope+Crypto.idl page/WindowOrWorkerGlobalScope+Performance.idl page/WindowOrWorkerGlobalScope.idl + page/WindowPostMessageOptions.idl page/WindowSessionStorage.idl page/WorkerNavigator.idl diff --git a/Source/WebCore/DerivedSources-input.xcfilelist b/Source/WebCore/DerivedSources-input.xcfilelist index c6277be12deb..c61487d466ec 100644 --- a/Source/WebCore/DerivedSources-input.xcfilelist +++ b/Source/WebCore/DerivedSources-input.xcfilelist @@ -1481,6 +1481,7 @@ $(PROJECT_DIR)/mathml/mathtags.in $(PROJECT_DIR)/page/BarProp.idl $(PROJECT_DIR)/page/Crypto.idl $(PROJECT_DIR)/page/DOMSelection.idl +$(PROJECT_DIR)/page/DOMWindow.idl $(PROJECT_DIR)/page/DOMWindow+CSSOM.idl $(PROJECT_DIR)/page/DOMWindow+CSSOMView.idl $(PROJECT_DIR)/page/DOMWindow+Compat.idl @@ -1567,6 +1568,7 @@ $(PROJECT_DIR)/page/WindowLocalStorage.idl $(PROJECT_DIR)/page/WindowOrWorkerGlobalScope+Crypto.idl $(PROJECT_DIR)/page/WindowOrWorkerGlobalScope+Performance.idl $(PROJECT_DIR)/page/WindowOrWorkerGlobalScope.idl +$(PROJECT_DIR)/page/WindowPostMessageOptions.idl $(PROJECT_DIR)/page/WindowSessionStorage.idl $(PROJECT_DIR)/page/WorkerNavigator.idl $(PROJECT_DIR)/page/csp/CSPViolationReportBody.idl diff --git a/Source/WebCore/DerivedSources-output.xcfilelist b/Source/WebCore/DerivedSources-output.xcfilelist index e8b74d23b0a7..c7884ea1f251 100644 --- a/Source/WebCore/DerivedSources-output.xcfilelist +++ b/Source/WebCore/DerivedSources-output.xcfilelist @@ -3085,6 +3085,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowOrWorkerGlobalScope+Perform $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowOrWorkerGlobalScope+Performance.h $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowOrWorkerGlobalScope.cpp $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowOrWorkerGlobalScope.h +$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowPostMessageOptions.cpp +$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowPostMessageOptions.h $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowSessionStorage.cpp $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWindowSessionStorage.h $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWorker.cpp diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make index a08f7ea089dc..6dfda4b18b6b 100644 --- a/Source/WebCore/DerivedSources.make +++ b/Source/WebCore/DerivedSources.make @@ -1308,6 +1308,7 @@ JS_BINDING_IDLS := \ $(WebCore)/page/BarProp.idl \ $(WebCore)/page/Crypto.idl \ $(WebCore)/page/DOMSelection.idl \ + $(WebCore)/page/DOMWindow.idl \ $(WebCore)/page/EventSource.idl \ $(WebCore)/page/History.idl \ $(WebCore)/page/IntersectionObserver.idl \ @@ -1382,6 +1383,7 @@ JS_BINDING_IDLS := \ $(WebCore)/page/WindowOrWorkerGlobalScope+Crypto.idl \ $(WebCore)/page/WindowOrWorkerGlobalScope+Performance.idl \ $(WebCore)/page/WindowOrWorkerGlobalScope.idl \ + $(WebCore)/page/WindowPostMessageOptions.idl \ $(WebCore)/page/WindowSessionStorage.idl \ $(WebCore)/page/WorkerNavigator.idl \ $(WebCore)/page/csp/CSPViolationReportBody.idl \ diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake index 9181a7a25253..e71d484f9a9b 100644 --- a/Source/WebCore/Headers.cmake +++ b/Source/WebCore/Headers.cmake @@ -1369,6 +1369,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS page/WheelEventTestMonitor.h page/WindowFeatures.h page/WindowOrWorkerGlobalScope.h + page/WindowPostMessageOptions.h page/WorkerClient.h page/csp/CSPViolationReportBody.h diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index 10be3c023132..e9367361d12c 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -4338,6 +4338,7 @@ JSWebXRWebGLLayer.cpp JSWheelEvent.cpp JSWindowEventHandlers.cpp JSWindowEventHandlers+Gamepad.cpp +JSWindowPostMessageOptions.cpp JSWindowOrWorkerGlobalScope.cpp JSWorker.cpp JSWorkerGlobalScope.cpp diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index 065194d21e43..789e0932849a 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -5946,6 +5946,7 @@ FABE72F71059C1EB00D999DD /* MathMLPresentationElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72F01059C1EB00D999DD /* MathMLPresentationElement.h */; }; FABE72F91059C1EB00D999DD /* MathMLMathElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72F21059C1EB00D999DD /* MathMLMathElement.h */; }; FABE72FE1059C21100D999DD /* MathMLNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FABE72FC1059C21100D999DD /* MathMLNames.cpp */; }; + FAEF5F6129D62710000AD8EC /* WindowPostMessageOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = FAEF5F5F29D6241C000AD8EC /* WindowPostMessageOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; FB273E822086E6C700A54E87 /* SVGGeometryElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FB273E7F2086E6A300A54E87 /* SVGGeometryElement.h */; }; FB273E852086E74D00A54E87 /* JSSVGGeometryElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FB273E842086E73E00A54E87 /* JSSVGGeometryElement.h */; }; FB2C15C3165D649D0039C9F8 /* CachedSVGDocumentReference.h in Headers */ = {isa = PBXBuildFile; fileRef = FB2C15C2165D64900039C9F8 /* CachedSVGDocumentReference.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -19147,6 +19148,9 @@ FABE72F31059C1EB00D999DD /* mathtags.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathtags.in; sourceTree = ""; }; FABE72FB1059C21100D999DD /* MathMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElementFactory.cpp; sourceTree = ""; }; FABE72FC1059C21100D999DD /* MathMLNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLNames.cpp; sourceTree = ""; }; + FAEF5F5F29D6241C000AD8EC /* WindowPostMessageOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WindowPostMessageOptions.h; sourceTree = ""; }; + FAEF5F6029D626D1000AD8EC /* WindowPostMessageOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WindowPostMessageOptions.idl; sourceTree = ""; }; + FAEF5F6229D62D15000AD8EC /* DOMWindow.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMWindow.idl; sourceTree = ""; }; FB273E7E2086E6A300A54E87 /* SVGGeometryElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGGeometryElement.cpp; sourceTree = ""; }; FB273E7F2086E6A300A54E87 /* SVGGeometryElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGGeometryElement.h; sourceTree = ""; }; FB273E802086E6A300A54E87 /* SVGGeometryElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGGeometryElement.idl; sourceTree = ""; }; @@ -25663,6 +25667,7 @@ 188604B20F2E654A000B6443 /* DOMTimer.h */, 46B95193207D632F00A7D2DD /* DOMWindow.cpp */, 46B9518A207D632800A7D2DD /* DOMWindow.h */, + FAEF5F6229D62D15000AD8EC /* DOMWindow.idl */, 517FBA17151AA71B00B57959 /* DOMWindowExtension.cpp */, 517FBA18151AA71B00B57959 /* DOMWindowExtension.h */, A718760D0B2A120100A16ECE /* DragActions.h */, @@ -25994,6 +25999,8 @@ 460C745626DD699D00427D3E /* WindowOrWorkerGlobalScope.cpp */, 460C745826DD699D00427D3E /* WindowOrWorkerGlobalScope.h */, 9371080D1DB754550060744E /* WindowOrWorkerGlobalScope.idl */, + FAEF5F5F29D6241C000AD8EC /* WindowPostMessageOptions.h */, + FAEF5F6029D626D1000AD8EC /* WindowPostMessageOptions.idl */, 7C67712C2527D7C900FDEF00 /* WindowSessionStorage.idl */, A7A3D55028939156008D683D /* WorkerClient.h */, E1271A130EEEC80400F61213 /* WorkerNavigator.cpp */, @@ -40587,6 +40594,7 @@ 460C745926DD69BB00427D3E /* WindowOrWorkerGlobalScope.h in Headers */, 41D129CE1F3D0EF600D15E47 /* WindowOrWorkerGlobalScopeCaches.h in Headers */, 5185FCB41BB4C4E80012898F /* WindowOrWorkerGlobalScopeIndexedDatabase.h in Headers */, + FAEF5F6129D62710000AD8EC /* WindowPostMessageOptions.h in Headers */, 463521AD2081092A00C28922 /* WindowProxy.h in Headers */, E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */, 501BAAA913950E2C00F7ACEB /* WindRule.h in Headers */, diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp index 2b4a36639600..29ead9f344f8 100644 --- a/Source/WebCore/page/DOMWindow.cpp +++ b/Source/WebCore/page/DOMWindow.cpp @@ -54,21 +54,18 @@ DOMWindow::~DOMWindow() allWindows().remove(identifier()); } -std::optional>> DOMWindow::createTargetOriginForPostMessage(const String& targetOrigin, RefPtr& sourceDocument) +ExceptionOr> DOMWindow::createTargetOriginForPostMessage(const String& targetOrigin, Document& sourceDocument) { RefPtr targetSecurityOrigin; - if (targetOrigin == "/"_s) { - if (!sourceDocument) - return std::nullopt; - targetSecurityOrigin = &sourceDocument->securityOrigin(); - } else if (targetOrigin != "*"_s) { + if (targetOrigin == "/"_s) + targetSecurityOrigin = &sourceDocument.securityOrigin(); + else if (targetOrigin != "*"_s) { targetSecurityOrigin = &SecurityOrigin::createFromString(targetOrigin).leakRef(); // It doesn't make sense target a postMessage at an opaque origin // because there's no way to represent an opaque origin in a string. if (targetSecurityOrigin->isOpaque()) return Exception { SyntaxError }; } - return targetSecurityOrigin; } diff --git a/Source/WebCore/page/DOMWindow.h b/Source/WebCore/page/DOMWindow.h index 34c483ad0e89..5f22b4ba3824 100644 --- a/Source/WebCore/page/DOMWindow.h +++ b/Source/WebCore/page/DOMWindow.h @@ -44,7 +44,6 @@ class DOMWindow : public RefCounted, public EventTarget { static HashMap& allWindows(); const GlobalWindowIdentifier& identifier() const { return m_identifier; } - std::optional>> createTargetOriginForPostMessage(const String&, RefPtr&); virtual Frame* frame() const = 0; virtual bool isLocalDOMWindow() const = 0; @@ -56,6 +55,8 @@ class DOMWindow : public RefCounted, public EventTarget { protected: explicit DOMWindow(GlobalWindowIdentifier&&); + ExceptionOr> createTargetOriginForPostMessage(const String&, Document&); + EventTargetInterface eventTargetInterface() const final { return LocalDOMWindowEventTargetInterfaceType; } void refEventTarget() final { ref(); } void derefEventTarget() final { deref(); } diff --git a/Source/WebCore/page/DOMWindow.idl b/Source/WebCore/page/DOMWindow.idl new file mode 100644 index 000000000000..f6006f4b987a --- /dev/null +++ b/Source/WebCore/page/DOMWindow.idl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 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 INC. 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 INC. 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. + */ + +interface mixin DOMWindow { + [CallWith=CurrentGlobalObject&IncumbentWindow, DoNotCheckSecurity] undefined postMessage(any message, USVString targetOrigin, optional sequence transfer = []); + [CallWith=CurrentGlobalObject&IncumbentWindow, DoNotCheckSecurity] undefined postMessage(any message, optional WindowPostMessageOptions options); +}; diff --git a/Source/WebCore/page/LocalDOMWindow.cpp b/Source/WebCore/page/LocalDOMWindow.cpp index 60e0e6f4ed6b..35ea67c3201c 100644 --- a/Source/WebCore/page/LocalDOMWindow.cpp +++ b/Source/WebCore/page/LocalDOMWindow.cpp @@ -954,18 +954,9 @@ ExceptionOr LocalDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobal if (!sourceDocument) return { }; - // Compute the target origin. We need to do this synchronously in order - // to generate the SyntaxError exception correctly. - std::optional>> targetSecurityOrigin = createTargetOriginForPostMessage(options.targetOrigin, sourceDocument); - if (!targetSecurityOrigin) - return { }; - - if (targetSecurityOrigin->hasException()) - return targetSecurityOrigin->releaseException(); - - RefPtr target; - if (targetSecurityOrigin->returnValue()) - target = targetSecurityOrigin->releaseReturnValue(); + auto targetSecurityOrigin = createTargetOriginForPostMessage(options.targetOrigin, *sourceDocument); + if (targetSecurityOrigin.hasException()) + return targetSecurityOrigin.releaseException(); Vector> ports; auto messageData = SerializedScriptValue::create(lexicalGlobalObject, messageValue, WTFMove(options.transfer), ports, SerializationForStorage::No, SerializationContext::WindowPostMessage); @@ -979,7 +970,7 @@ ExceptionOr LocalDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobal // Schedule the message. RefPtr incumbentWindowProxy = incumbentWindow.frame() ? &incumbentWindow.frame()->windowProxy() : nullptr; MessageWithMessagePorts message { messageData.releaseReturnValue(), disentangledPorts.releaseReturnValue() }; - processPostMessage(lexicalGlobalObject, WTFMove(sourceDocument), message, WTFMove(incumbentWindowProxy), WTFMove(target)); + processPostMessage(lexicalGlobalObject, WTFMove(sourceDocument), message, WTFMove(incumbentWindowProxy), targetSecurityOrigin.releaseReturnValue()); return { }; } diff --git a/Source/WebCore/page/LocalDOMWindow.h b/Source/WebCore/page/LocalDOMWindow.h index d942b70e1f66..3f11a0695127 100644 --- a/Source/WebCore/page/LocalDOMWindow.h +++ b/Source/WebCore/page/LocalDOMWindow.h @@ -35,9 +35,9 @@ #include "ReducedResolutionSeconds.h" #include "ScrollToOptions.h" #include "ScrollTypes.h" -#include "StructuredSerializeOptions.h" #include "Supplementable.h" #include "WindowOrWorkerGlobalScope.h" +#include "WindowPostMessageOptions.h" #include #include #include @@ -102,16 +102,6 @@ struct WindowFeatures; enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList }; enum class IncludeTargetOrigin : bool { No, Yes }; -struct WindowPostMessageOptions : public StructuredSerializeOptions { - WindowPostMessageOptions() = default; - WindowPostMessageOptions(String&& targetOrigin, Vector>&& transfer) - : StructuredSerializeOptions(WTFMove(transfer)) - , targetOrigin(WTFMove(targetOrigin)) - { } - - String targetOrigin { "/"_s }; -}; - class LocalDOMWindow final : public DOMWindow , public ContextDestructionObserver diff --git a/Source/WebCore/page/LocalDOMWindow.idl b/Source/WebCore/page/LocalDOMWindow.idl index 61640c672fe8..3019487a22e6 100644 --- a/Source/WebCore/page/LocalDOMWindow.idl +++ b/Source/WebCore/page/LocalDOMWindow.idl @@ -87,10 +87,6 @@ DOMString? prompt(optional DOMString message = "", optional DOMString defaultValue = ""); undefined print(); - [CallWith=CurrentGlobalObject&IncumbentWindow, DoNotCheckSecurity] undefined postMessage(any message, USVString targetOrigin, optional sequence transfer = []); - [CallWith=CurrentGlobalObject&IncumbentWindow, DoNotCheckSecurity] undefined postMessage(any message, optional WindowPostMessageOptions options); - - // Obsolete: Still part of the HTML specification (https://html.spec.whatwg.org/#Window-partial). undefined captureEvents(); undefined releaseEvents(); @@ -126,14 +122,9 @@ [EnabledForWorld=shadowRootIsAlwaysOpen] Element? matchingElementInFlatTree(Node scope, DOMString selectors); }; -[ - ImplementedAs=WindowPostMessageOptions -] dictionary WindowPostMessageOptions : StructuredSerializeOptions { - USVString targetOrigin = "/"; -}; - LocalDOMWindow includes AnimationFrameProvider; LocalDOMWindow includes GlobalEventHandlers; +LocalDOMWindow includes DOMWindow; LocalDOMWindow includes WindowEventHandlers; LocalDOMWindow includes WindowOrWorkerGlobalScope; LocalDOMWindow includes WindowLocalStorage; diff --git a/Source/WebCore/page/RemoteDOMWindow.cpp b/Source/WebCore/page/RemoteDOMWindow.cpp index 0a489290f560..5fb3f1421d46 100644 --- a/Source/WebCore/page/RemoteDOMWindow.cpp +++ b/Source/WebCore/page/RemoteDOMWindow.cpp @@ -114,23 +114,22 @@ WindowProxy* RemoteDOMWindow::parent() const return &m_frame->windowProxy(); } -ExceptionOr RemoteDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObject, LocalDOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector>&& transfer) +ExceptionOr RemoteDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObject, LocalDOMWindow& incumbentWindow, JSC::JSValue message, WindowPostMessageOptions&& options) { RefPtr sourceDocument = incumbentWindow.document(); - // Compute the target origin. We need to do this synchronously in order - // to generate the SyntaxError exception correctly. - std::optional>> targetSecurityOrigin = createTargetOriginForPostMessage(targetOrigin, sourceDocument); - if (!targetSecurityOrigin) + if (!sourceDocument) return { }; - if (targetSecurityOrigin->hasException()) - return targetSecurityOrigin->releaseException(); + + auto targetSecurityOrigin = createTargetOriginForPostMessage(options.targetOrigin, *sourceDocument); + if (targetSecurityOrigin.hasException()) + return targetSecurityOrigin.releaseException(); std::optional target; - if (targetSecurityOrigin->returnValue()) - target = targetSecurityOrigin->releaseReturnValue()->data(); + if (auto origin = targetSecurityOrigin.releaseReturnValue()) + target = origin->data(); Vector> ports; - auto messageData = SerializedScriptValue::create(lexicalGlobalObject, message, WTFMove(transfer), ports, SerializationForStorage::No, SerializationContext::WindowPostMessage); + auto messageData = SerializedScriptValue::create(lexicalGlobalObject, message, WTFMove(options.transfer), ports, SerializationForStorage::No, SerializationContext::WindowPostMessage); if (messageData.hasException()) return messageData.releaseException(); diff --git a/Source/WebCore/page/RemoteDOMWindow.h b/Source/WebCore/page/RemoteDOMWindow.h index f032ac1739c8..087fe9e33cf4 100644 --- a/Source/WebCore/page/RemoteDOMWindow.h +++ b/Source/WebCore/page/RemoteDOMWindow.h @@ -27,6 +27,7 @@ #include "DOMWindow.h" #include "RemoteFrame.h" +#include "WindowPostMessageOptions.h" #include #include #include @@ -68,7 +69,11 @@ class RemoteDOMWindow final : public DOMWindow { WindowProxy* top() const; WindowProxy* opener() const; WindowProxy* parent() const; - ExceptionOr postMessage(JSC::JSGlobalObject&, LocalDOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector>&&); + ExceptionOr postMessage(JSC::JSGlobalObject&, LocalDOMWindow& incumbentWindow, JSC::JSValue message, WindowPostMessageOptions&&); + ExceptionOr postMessage(JSC::JSGlobalObject& globalObject, LocalDOMWindow& incumbentWindow, JSC::JSValue message, String&& targetOrigin, Vector>&& transfer) + { + return postMessage(globalObject, incumbentWindow, message, WindowPostMessageOptions { WTFMove(targetOrigin), WTFMove(transfer) }); + } private: WEBCORE_EXPORT RemoteDOMWindow(RemoteFrame&, GlobalWindowIdentifier&&); diff --git a/Source/WebCore/page/RemoteDOMWindow.idl b/Source/WebCore/page/RemoteDOMWindow.idl index 5b860895107d..f7a594a54d1d 100644 --- a/Source/WebCore/page/RemoteDOMWindow.idl +++ b/Source/WebCore/page/RemoteDOMWindow.idl @@ -53,5 +53,6 @@ [LegacyUnforgeable] readonly attribute WindowProxy? top; readonly attribute WindowProxy? opener; [Replaceable] readonly attribute WindowProxy? parent; - [CallWith=CurrentGlobalObject&IncumbentWindow] undefined postMessage(any message, USVString targetOrigin, optional sequence transfer = []); }; + +RemoteDOMWindow includes DOMWindow; diff --git a/Source/WebCore/page/WindowPostMessageOptions.h b/Source/WebCore/page/WindowPostMessageOptions.h new file mode 100644 index 000000000000..baad8b931042 --- /dev/null +++ b/Source/WebCore/page/WindowPostMessageOptions.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 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 INC. 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 INC. 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 "StructuredSerializeOptions.h" + +namespace WebCore { + +struct WindowPostMessageOptions : public StructuredSerializeOptions { + WindowPostMessageOptions() = default; + WindowPostMessageOptions(String&& targetOrigin, Vector>&& transfer) + : StructuredSerializeOptions(WTFMove(transfer)) + , targetOrigin(WTFMove(targetOrigin)) + { } + + String targetOrigin { "/"_s }; +}; + +} diff --git a/Source/WebCore/page/WindowPostMessageOptions.idl b/Source/WebCore/page/WindowPostMessageOptions.idl new file mode 100644 index 000000000000..64f2d7cf7ded --- /dev/null +++ b/Source/WebCore/page/WindowPostMessageOptions.idl @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 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 INC. 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 INC. 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. + */ + +dictionary WindowPostMessageOptions : StructuredSerializeOptions { + USVString targetOrigin = "/"; +}; diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm index bb749848a369..28f333f391a3 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm @@ -62,7 +62,7 @@ static void enableSiteIsolation(WKWebViewConfiguration *configuration) auto webkitHTML = ""_s; @@ -172,20 +172,9 @@ HTTPServer server(HTTPServer::UseCoroutines::Yes, [&](Connection connection) -> ""_s; bool finishedLoading { false }; - HTTPServer server(HTTPServer::UseCoroutines::Yes, [&](Connection connection) -> Task { - while (1) { - auto request = co_await connection.awaitableReceiveHTTPRequest(); - auto path = HTTPServer::parsePath(request); - if (path == "/example"_s) { - co_await connection.awaitableSend(HTTPResponse(exampleHTML).serialize()); - continue; - } - if (path == "/webkit"_s) { - co_await connection.awaitableSend(HTTPResponse(webkitHTML).serialize()); - continue; - } - EXPECT_FALSE(true); - } + HTTPServer server({ + { "/example"_s, { exampleHTML } }, + { "/webkit"_s, { webkitHTML } } }, HTTPServer::Protocol::HttpsProxy); auto navigationDelegate = adoptNS([TestNavigationDelegate new]); [navigationDelegate allowAnyTLSCertificate]; @@ -321,21 +310,12 @@ HTTPServer server(HTTPServer::UseCoroutines::Yes, [&](Connection connection) -> ""_s; bool finishedLoading { false }; - HTTPServer server(HTTPServer::UseCoroutines::Yes, [&](Connection connection) -> Task { - while (1) { - auto request = co_await connection.awaitableReceiveHTTPRequest(); - auto path = HTTPServer::parsePath(request); - if (path == "/example"_s) { - co_await connection.awaitableSend(HTTPResponse(exampleHTML).serialize()); - continue; - } - if (path == "/webkit"_s) { - co_await connection.awaitableSend(HTTPResponse(webkitHTML).serialize()); - continue; - } - EXPECT_FALSE(true); - } + + HTTPServer server({ + { "/example"_s, { exampleHTML } }, + { "/webkit"_s, { webkitHTML } } }, HTTPServer::Protocol::HttpsProxy); + auto navigationDelegate = adoptNS([TestNavigationDelegate new]); [navigationDelegate allowAnyTLSCertificate]; navigationDelegate.get().didFinishNavigation = makeBlockPtr([&](WKWebView *, WKNavigation *navigation) {