Skip to content

Commit

Permalink
Share more code between local and remote postMessage
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=254773

Reviewed by Chris Dumez.

Share the shape all the way down to the IDL.

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/page/DOMWindow.cpp:
(WebCore::DOMWindow::createTargetOriginForPostMessage):
* Source/WebCore/page/DOMWindow.h:
(WebCore::DOMWindow::identifier const):
* Source/WebCore/page/DOMWindow.idl: Copied from Source/WebCore/page/DOMWindow.h.
* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::postMessage):
* Source/WebCore/page/LocalDOMWindow.h:
(WebCore::WindowPostMessageOptions::WindowPostMessageOptions): Deleted.
* Source/WebCore/page/LocalDOMWindow.idl:
* Source/WebCore/page/RemoteDOMWindow.cpp:
(WebCore::RemoteDOMWindow::postMessage):
* Source/WebCore/page/RemoteDOMWindow.h:
* Source/WebCore/page/RemoteDOMWindow.idl:
* Source/WebCore/page/WindowPostMessageOptions.h: Copied from Source/WebCore/page/DOMWindow.h.
(WebCore::WindowPostMessageOptions::WindowPostMessageOptions):
* Source/WebCore/page/WindowPostMessageOptions.idl: Copied from Source/WebCore/page/DOMWindow.h.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/262437@main
  • Loading branch information
achristensen07 committed Mar 31, 2023
1 parent e25587a commit 3d36d22
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 83 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources-output.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources.make
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4338,6 +4338,7 @@ JSWebXRWebGLLayer.cpp
JSWheelEvent.cpp
JSWindowEventHandlers.cpp
JSWindowEventHandlers+Gamepad.cpp
JSWindowPostMessageOptions.cpp
JSWindowOrWorkerGlobalScope.cpp
JSWorker.cpp
JSWorkerGlobalScope.cpp
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -19147,6 +19148,9 @@
FABE72F31059C1EB00D999DD /* mathtags.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathtags.in; sourceTree = "<group>"; };
FABE72FB1059C21100D999DD /* MathMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElementFactory.cpp; sourceTree = "<group>"; };
FABE72FC1059C21100D999DD /* MathMLNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLNames.cpp; sourceTree = "<group>"; };
FAEF5F5F29D6241C000AD8EC /* WindowPostMessageOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WindowPostMessageOptions.h; sourceTree = "<group>"; };
FAEF5F6029D626D1000AD8EC /* WindowPostMessageOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WindowPostMessageOptions.idl; sourceTree = "<group>"; };
FAEF5F6229D62D15000AD8EC /* DOMWindow.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMWindow.idl; sourceTree = "<group>"; };
FB273E7E2086E6A300A54E87 /* SVGGeometryElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGGeometryElement.cpp; sourceTree = "<group>"; };
FB273E7F2086E6A300A54E87 /* SVGGeometryElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGGeometryElement.h; sourceTree = "<group>"; };
FB273E802086E6A300A54E87 /* SVGGeometryElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGGeometryElement.idl; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
11 changes: 4 additions & 7 deletions Source/WebCore/page/DOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ DOMWindow::~DOMWindow()
allWindows().remove(identifier());
}

std::optional<ExceptionOr<RefPtr<SecurityOrigin>>> DOMWindow::createTargetOriginForPostMessage(const String& targetOrigin, RefPtr<Document>& sourceDocument)
ExceptionOr<RefPtr<SecurityOrigin>> DOMWindow::createTargetOriginForPostMessage(const String& targetOrigin, Document& sourceDocument)
{
RefPtr<SecurityOrigin> 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;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/page/DOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class DOMWindow : public RefCounted<DOMWindow>, public EventTarget {
static HashMap<GlobalWindowIdentifier, DOMWindow*>& allWindows();

const GlobalWindowIdentifier& identifier() const { return m_identifier; }
std::optional<ExceptionOr<RefPtr<SecurityOrigin>>> createTargetOriginForPostMessage(const String&, RefPtr<Document>&);
virtual Frame* frame() const = 0;

virtual bool isLocalDOMWindow() const = 0;
Expand All @@ -56,6 +55,8 @@ class DOMWindow : public RefCounted<DOMWindow>, public EventTarget {
protected:
explicit DOMWindow(GlobalWindowIdentifier&&);

ExceptionOr<RefPtr<SecurityOrigin>> createTargetOriginForPostMessage(const String&, Document&);

EventTargetInterface eventTargetInterface() const final { return LocalDOMWindowEventTargetInterfaceType; }
void refEventTarget() final { ref(); }
void derefEventTarget() final { deref(); }
Expand Down
29 changes: 29 additions & 0 deletions Source/WebCore/page/DOMWindow.idl
Original file line number Diff line number Diff line change
@@ -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<object> transfer = []);
[CallWith=CurrentGlobalObject&IncumbentWindow, DoNotCheckSecurity] undefined postMessage(any message, optional WindowPostMessageOptions options);
};
17 changes: 4 additions & 13 deletions Source/WebCore/page/LocalDOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,18 +954,9 @@ ExceptionOr<void> 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<ExceptionOr<RefPtr<SecurityOrigin>>> targetSecurityOrigin = createTargetOriginForPostMessage(options.targetOrigin, sourceDocument);
if (!targetSecurityOrigin)
return { };

if (targetSecurityOrigin->hasException())
return targetSecurityOrigin->releaseException();

RefPtr<SecurityOrigin> target;
if (targetSecurityOrigin->returnValue())
target = targetSecurityOrigin->releaseReturnValue();
auto targetSecurityOrigin = createTargetOriginForPostMessage(options.targetOrigin, *sourceDocument);
if (targetSecurityOrigin.hasException())
return targetSecurityOrigin.releaseException();

Vector<RefPtr<MessagePort>> ports;
auto messageData = SerializedScriptValue::create(lexicalGlobalObject, messageValue, WTFMove(options.transfer), ports, SerializationForStorage::No, SerializationContext::WindowPostMessage);
Expand All @@ -979,7 +970,7 @@ ExceptionOr<void> LocalDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobal
// Schedule the message.
RefPtr<WindowProxy> 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 { };
}

Expand Down
12 changes: 1 addition & 11 deletions Source/WebCore/page/LocalDOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <JavaScriptCore/HandleTypes.h>
#include <JavaScriptCore/Strong.h>
#include <wtf/FixedVector.h>
Expand Down Expand Up @@ -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<JSC::Strong<JSC::JSObject>>&& transfer)
: StructuredSerializeOptions(WTFMove(transfer))
, targetOrigin(WTFMove(targetOrigin))
{ }

String targetOrigin { "/"_s };
};

class LocalDOMWindow final
: public DOMWindow
, public ContextDestructionObserver
Expand Down
11 changes: 1 addition & 10 deletions Source/WebCore/page/LocalDOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> 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();
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions Source/WebCore/page/RemoteDOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,22 @@ WindowProxy* RemoteDOMWindow::parent() const
return &m_frame->windowProxy();
}

ExceptionOr<void> RemoteDOMWindow::postMessage(JSC::JSGlobalObject& lexicalGlobalObject, LocalDOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
ExceptionOr<void> 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<ExceptionOr<RefPtr<SecurityOrigin>>> 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<SecurityOriginData> target;
if (targetSecurityOrigin->returnValue())
target = targetSecurityOrigin->releaseReturnValue()->data();
if (auto origin = targetSecurityOrigin.releaseReturnValue())
target = origin->data();

Vector<RefPtr<MessagePort>> 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();

Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/page/RemoteDOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "DOMWindow.h"
#include "RemoteFrame.h"
#include "WindowPostMessageOptions.h"
#include <JavaScriptCore/Strong.h>
#include <wtf/IsoMalloc.h>
#include <wtf/TypeCasts.h>
Expand Down Expand Up @@ -68,7 +69,11 @@ class RemoteDOMWindow final : public DOMWindow {
WindowProxy* top() const;
WindowProxy* opener() const;
WindowProxy* parent() const;
ExceptionOr<void> postMessage(JSC::JSGlobalObject&, LocalDOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&);
ExceptionOr<void> postMessage(JSC::JSGlobalObject&, LocalDOMWindow& incumbentWindow, JSC::JSValue message, WindowPostMessageOptions&&);
ExceptionOr<void> postMessage(JSC::JSGlobalObject& globalObject, LocalDOMWindow& incumbentWindow, JSC::JSValue message, String&& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
{
return postMessage(globalObject, incumbentWindow, message, WindowPostMessageOptions { WTFMove(targetOrigin), WTFMove(transfer) });
}

private:
WEBCORE_EXPORT RemoteDOMWindow(RemoteFrame&, GlobalWindowIdentifier&&);
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/page/RemoteDOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> transfer = []);
};

RemoteDOMWindow includes DOMWindow;

0 comments on commit 3d36d22

Please sign in to comment.