diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-04-07 16:02:34 +0800 |
---|---|---|
committer | FranklinDM <mrmineshafter17@gmail.com> | 2023-04-07 23:41:56 +0800 |
commit | 6d2e5850cec46d5d3b4c8865e22262a499379cf7 (patch) | |
tree | 8d9598a8a7e5ea86bd23696c1909c93846c699a7 /dom | |
parent | b3a6a8f27410fe1a66c0ee90213870b888a6f874 (diff) | |
download | uxp-6d2e5850cec46d5d3b4c8865e22262a499379cf7.tar.gz |
Issue #2197 - Part 2d: Implement PostMessageOptions for Window
Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1502802
Diffstat (limited to 'dom')
-rw-r--r-- | dom/base/nsGlobalWindow.cpp | 11 | ||||
-rw-r--r-- | dom/base/nsGlobalWindow.h | 6 | ||||
-rw-r--r-- | dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml | 7 | ||||
-rw-r--r-- | dom/webidl/Window.webidl | 6 |
4 files changed, 23 insertions, 7 deletions
diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index ec33d0aef0..f4c1119a83 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8898,6 +8898,17 @@ nsGlobalWindow::PostMessageMoz(JSContext* aCx, aSubjectPrincipal, aRv); } +void +nsGlobalWindow::PostMessageMoz(JSContext* aCx, + JS::Handle<JS::Value> aMessage, + const WindowPostMessageOptions& aOptions, + nsIPrincipal& aSubjectPrincipal, + ErrorResult& aRv) +{ + PostMessageMoz(aCx, aMessage, aOptions.mTargetOrigin, aOptions.mTransfer, + aSubjectPrincipal, aRv); +} + class nsCloseEvent : public Runnable { RefPtr<nsGlobalWindow> mWindow; diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 8c961e2014..9a97a5e92a 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -135,6 +135,7 @@ class TabGroup; class Timeout; class U2F; class WakeLock; +struct WindowPostMessageOptions; class Worklet; namespace cache { class CacheStorage; @@ -936,6 +937,11 @@ public: const mozilla::dom::Sequence<JSObject*>& aTransfer, nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aRv); + void PostMessageMoz(JSContext* aCx, + JS::Handle<JS::Value> aMessage, + const mozilla::dom::WindowPostMessageOptions& aOptions, + nsIPrincipal& aSubjectPrincipal, + mozilla::ErrorResult& aError); int32_t SetTimeout(JSContext* aCx, mozilla::dom::Function& aFunction, int32_t aTimeout, const mozilla::dom::Sequence<JS::Value>& aArguments, diff --git a/dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml b/dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml index f6a9198968..e48bee136d 100644 --- a/dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml +++ b/dom/tests/mochitest/whatwg/test_postMessage_origin.xhtml @@ -383,13 +383,6 @@ var tests = hasWrongReturnOriginBug: true }, - // 55 - { - args: ["NOT-RECEIVED", undefined], - source: "sameDomain", - name: "SyntaxError", - code: DOMException.SYNTAX_ERR - }, ]; function allTests(callback) diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 73d5843a16..59cc9689c2 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -80,6 +80,8 @@ interface nsIDOMCrypto; [Throws, CrossOriginCallable, NeedsSubjectPrincipal] void postMessage(any message, DOMString targetOrigin, optional sequence<object> transfer = []); + [Throws, CrossOriginCallable, NeedsSubjectPrincipal] + void postMessage(any message, optional WindowPostMessageOptions options); // also has obsolete members }; @@ -485,3 +487,7 @@ callback IdleRequestCallback = void (IdleDeadline deadline); partial interface Window { [ChromeOnly] readonly attribute boolean isSecureContextIfOpenerIgnored; }; + +dictionary WindowPostMessageOptions : StructuredSerializeOptions { + USVString targetOrigin = "/"; +}; |