diff -Nrup mozilla/dom/base/nsGlobalWindow.cpp mozilla-OK/dom/base/nsGlobalWindow.cpp
--- mozilla/dom/base/nsGlobalWindow.cpp 2023-12-08 22:51:43.106195433 +0300
+++ mozilla-OK/dom/base/nsGlobalWindow.cpp 2023-12-08 22:57:52.810002423 +0300
@@ -9218,6 +9218,25 @@ nsGlobalWindow::PostMessageMoz(JSContext
aSubjectPrincipal, aRv);
}
+void
+nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const WindowPostMessageOptions& aOptions,
+ nsIPrincipal& aSubjectPrincipal,
+ ErrorResult& aRv)
+{
+ JS::Rooted<JS::Value> transferArray(aCx, JS::UndefinedValue());
+
+ aRv = nsContentUtils::CreateJSValueFromSequenceOfObject(aCx,
+ aOptions.mTransfer,
+ &transferArray);
+ if (NS_WARN_IF(aRv.Failed())) {
+ return;
+ }
+
+ PostMessageMoz(aCx, aMessage, aOptions.mTargetOrigin, transferArray,
+ aSubjectPrincipal, aRv);
+}
+
class nsCloseEvent : public Runnable {
RefPtr<nsGlobalWindow> mWindow;
diff -Nrup mozilla/dom/base/nsGlobalWindow.h mozilla-OK/dom/base/nsGlobalWindow.h
--- mozilla/dom/base/nsGlobalWindow.h 2023-11-07 00:01:21.000000000 +0300
+++ mozilla-OK/dom/base/nsGlobalWindow.h 2023-12-08 22:57:52.812002411 +0300
@@ -143,6 +143,7 @@ class WakeLock;
#if defined(MOZ_WIDGET_ANDROID)
class WindowOrientationObserver;
#endif
+struct WindowPostMessageOptions;
class Worklet;
namespace cache {
class CacheStorage;
@@ -1001,6 +1002,10 @@ public:
const mozilla::dom::Sequence<JSObject*>& aTransfer,
nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& aError);
+ 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 -Nrup mozilla/dom/messagechannel/MessagePort.cpp mozilla-OK/dom/messagechannel/MessagePort.cpp
--- mozilla/dom/messagechannel/MessagePort.cpp 2023-11-28 23:05:19.000000000 +0300
+++ mozilla-OK/dom/messagechannel/MessagePort.cpp 2023-12-08 22:57:52.812002411 +0300
@@ -463,6 +463,14 @@ MessagePort::PostMessage(JSContext* aCx,
}
void
+MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
+void
MessagePort::Start()
{
if (mMessageQueueEnabled) {
diff -Nrup mozilla/dom/messagechannel/MessagePort.h mozilla-OK/dom/messagechannel/MessagePort.h
--- mozilla/dom/messagechannel/MessagePort.h 2022-01-25 01:04:16.000000000 +0300
+++ mozilla-OK/dom/messagechannel/MessagePort.h 2023-12-08 22:57:52.813002406 +0300
@@ -24,6 +24,7 @@ namespace dom {
class ClonedMessageData;
class MessagePortChild;
class MessagePortIdentifier;
+struct PostMessageOptions;
class PostMessageRunnable;
class SharedMessagePortMessage;
@@ -63,6 +64,11 @@ public:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
+ void
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv);
+
void Start();
void Close();
diff -Nrup mozilla/dom/webidl/Client.webidl mozilla-OK/dom/webidl/Client.webidl
--- mozilla/dom/webidl/Client.webidl 2020-02-18 02:37:50.000000000 +0300
+++ mozilla-OK/dom/webidl/Client.webidl 2023-12-08 22:57:52.813002406 +0300
@@ -22,7 +22,9 @@ interface Client {
// readonly attribute boolean reserved;
[Throws]
- void postMessage(any message, optional sequence<object> transfer = []);
+ void postMessage(any message, sequence<object> transfer);
+ [Throws]
+ void postMessage(any message, optional PostMessageOptions aOptions);
};
[Exposed=ServiceWorker]
diff -Nrup mozilla/dom/webidl/DedicatedWorkerGlobalScope.webidl mozilla-OK/dom/webidl/DedicatedWorkerGlobalScope.webidl
--- mozilla/dom/webidl/DedicatedWorkerGlobalScope.webidl 2020-12-22 14:42:29.000000000 +0300
+++ mozilla-OK/dom/webidl/DedicatedWorkerGlobalScope.webidl 2023-12-08 22:57:52.813002406 +0300
@@ -19,7 +19,9 @@ interface DedicatedWorkerGlobalScope : W
readonly attribute DOMString name;
[Throws]
- void postMessage(any message, optional sequence<object> transfer = []);
+ void postMessage(any message, sequence<object> transfer);
+ [Throws]
+ void postMessage(any message, optional PostMessageOptions options);
void close();
diff -Nrup mozilla/dom/webidl/MessagePort.webidl mozilla-OK/dom/webidl/MessagePort.webidl
--- mozilla/dom/webidl/MessagePort.webidl 2020-12-22 14:42:29.000000000 +0300
+++ mozilla-OK/dom/webidl/MessagePort.webidl 2023-12-08 22:57:52.814002400 +0300
@@ -10,7 +10,9 @@
[Exposed=(Window,Worker,System)]
interface MessagePort : EventTarget {
[Throws]
- void postMessage(any message, optional sequence<object> transferable = []);
+ void postMessage(any message, sequence<object> transferable);
+ [Throws]
+ void postMessage(any message, optional PostMessageOptions options);
void start();
void close();
@@ -20,3 +22,7 @@ interface MessagePort : EventTarget {
attribute EventHandler onmessageerror;
};
// MessagePort implements Transferable;
+
+dictionary PostMessageOptions {
+ sequence<object> transfer = [];
+};
diff -Nrup mozilla/dom/webidl/ServiceWorker.webidl mozilla-OK/dom/webidl/ServiceWorker.webidl
--- mozilla/dom/webidl/ServiceWorker.webidl 2022-04-13 21:14:22.000000000 +0300
+++ mozilla-OK/dom/webidl/ServiceWorker.webidl 2023-12-08 22:57:52.814002400 +0300
@@ -20,7 +20,9 @@ interface ServiceWorker : EventTarget {
attribute EventHandler onstatechange;
[Throws]
- void postMessage(any message, optional sequence<object> transferable = []);
+ void postMessage(any message, sequence<object> transferable);
+ [Throws]
+ void postMessage(any message, optional PostMessageOptions options);
};
ServiceWorker implements AbstractWorker;
diff -Nrup mozilla/dom/webidl/Window.webidl mozilla-OK/dom/webidl/Window.webidl
--- mozilla/dom/webidl/Window.webidl 2023-11-07 00:01:22.000000000 +0300
+++ mozilla-OK/dom/webidl/Window.webidl 2023-12-08 22:57:52.814002400 +0300
@@ -83,6 +83,8 @@ interface XULControllers;
[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
};
@@ -504,3 +506,7 @@ partial interface Window {
[Throws, Func="IsChromeOrXBL"]
readonly attribute IntlUtils intlUtils;
};
+
+dictionary WindowPostMessageOptions : PostMessageOptions {
+ USVString targetOrigin = "/";
+};
diff -Nrup mozilla/dom/webidl/Worker.webidl mozilla-OK/dom/webidl/Worker.webidl
--- mozilla/dom/webidl/Worker.webidl 2020-12-22 14:42:29.000000000 +0300
+++ mozilla-OK/dom/webidl/Worker.webidl 2023-12-08 22:57:52.815002394 +0300
@@ -19,7 +19,9 @@ interface Worker : EventTarget {
void terminate();
[Throws]
- void postMessage(any message, optional sequence<object> transfer = []);
+ void postMessage(any message, sequence<object> transfer);
+ [Throws]
+ void postMessage(any message, optional PostMessageOptions aOptions);
attribute EventHandler onmessage;
attribute EventHandler onmessageerror;
diff -Nrup mozilla/dom/workers/ServiceWorker.cpp mozilla-OK/dom/workers/ServiceWorker.cpp
--- mozilla/dom/workers/ServiceWorker.cpp 2022-04-13 21:14:22.000000000 +0300
+++ mozilla-OK/dom/workers/ServiceWorker.cpp 2023-12-08 22:57:52.815002394 +0300
@@ -14,6 +14,7 @@
#include "WorkerPrivate.h"
#include "mozilla/Preferences.h"
+#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
@@ -104,6 +105,14 @@ ServiceWorker::PostMessage(JSContext* aC
aRv = workerPrivate->SendMessageEvent(aCx, aMessage, aTransferable, Move(clientInfo));
}
+void
+ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
} // namespace workers
} // namespace dom
} // namespace mozilla
diff -Nrup mozilla/dom/workers/ServiceWorker.h mozilla-OK/dom/workers/ServiceWorker.h
--- mozilla/dom/workers/ServiceWorker.h 2020-02-18 02:37:50.000000000 +0300
+++ mozilla-OK/dom/workers/ServiceWorker.h 2023-12-08 22:57:52.816002388 +0300
@@ -16,6 +16,8 @@ class nsPIDOMWindowInner;
namespace mozilla {
namespace dom {
+struct PostMessageOptions;
+
namespace workers {
class ServiceWorkerInfo;
@@ -66,6 +68,10 @@ public:
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
+ void
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions, ErrorResult& aRv);
+
private:
// This class can only be created from ServiceWorkerInfo::GetOrCreateInstance().
ServiceWorker(nsPIDOMWindowInner* aWindow, ServiceWorkerInfo* aInfo);
diff -Nrup mozilla/dom/workers/ServiceWorkerClient.cpp mozilla-OK/dom/workers/ServiceWorkerClient.cpp
--- mozilla/dom/workers/ServiceWorkerClient.cpp 2020-02-18 02:37:50.000000000 +0300
+++ mozilla-OK/dom/workers/ServiceWorkerClient.cpp 2023-12-08 22:57:52.816002388 +0300
@@ -8,6 +8,7 @@
#include "ServiceWorkerClient.h"
#include "ServiceWorkerContainer.h"
+#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/MessageEvent.h"
#include "mozilla/dom/Navigator.h"
#include "nsGlobalWindow.h"
@@ -284,3 +285,11 @@ ServiceWorkerClient::PostMessage(JSConte
}
}
+void
+ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
diff -Nrup mozilla/dom/workers/ServiceWorkerClient.h mozilla-OK/dom/workers/ServiceWorkerClient.h
--- mozilla/dom/workers/ServiceWorkerClient.h 2020-02-18 02:37:50.000000000 +0300
+++ mozilla-OK/dom/workers/ServiceWorkerClient.h 2023-12-08 22:57:52.816002388 +0300
@@ -18,6 +18,9 @@ class nsIDocument;
namespace mozilla {
namespace dom {
+
+struct PostMessageOptions;
+
namespace workers {
class ServiceWorkerClient;
@@ -103,6 +106,10 @@ public:
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
+ void
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions, ErrorResult& aRv);
+
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
diff -Nrup mozilla/dom/workers/WorkerPrivate.cpp mozilla-OK/dom/workers/WorkerPrivate.cpp
--- mozilla/dom/workers/WorkerPrivate.cpp 2023-11-07 00:01:22.000000000 +0300
+++ mozilla-OK/dom/workers/WorkerPrivate.cpp 2023-12-08 22:57:52.818002376 +0300
@@ -3494,6 +3494,16 @@ WorkerPrivateParent<Derived>::PostMessag
template <class Derived>
void
+WorkerPrivateParent<Derived>::PostMessage(
+ JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessageInternal(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
+template <class Derived>
+void
WorkerPrivateParent<Derived>::UpdateContextOptions(
const JS::ContextOptions& aContextOptions)
{
diff -Nrup mozilla/dom/workers/WorkerPrivate.h mozilla-OK/dom/workers/WorkerPrivate.h
--- mozilla/dom/workers/WorkerPrivate.h 2022-11-02 23:12:10.000000000 +0300
+++ mozilla-OK/dom/workers/WorkerPrivate.h 2023-12-08 22:57:52.819002370 +0300
@@ -70,6 +70,7 @@ class PromiseNativeHandler;
class StructuredCloneHolder;
class WorkerDebuggerGlobalScope;
class WorkerGlobalScope;
+struct PostMessageOptions;
struct WorkerOptions;
} // namespace dom
namespace ipc {
@@ -402,6 +403,11 @@ public:
ErrorResult& aRv);
void
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv);
+
+ void
UpdateContextOptions(const JS::ContextOptions& aContextOptions);
void
diff -Nrup mozilla/dom/workers/WorkerScope.cpp mozilla-OK/dom/workers/WorkerScope.cpp
--- mozilla/dom/workers/WorkerScope.cpp 2023-11-07 00:01:22.000000000 +0300
+++ mozilla-OK/dom/workers/WorkerScope.cpp 2023-12-08 22:57:52.819002370 +0300
@@ -567,6 +567,16 @@ DedicatedWorkerGlobalScope::PostMessage(
}
void
+DedicatedWorkerGlobalScope::PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv)
+{
+ mWorkerPrivate->AssertIsOnWorkerThread();
+ mWorkerPrivate->PostMessageToParent(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
+void
DedicatedWorkerGlobalScope::Close(JSContext* aCx)
{
mWorkerPrivate->AssertIsOnWorkerThread();
diff -Nrup mozilla/dom/workers/WorkerScope.h mozilla-OK/dom/workers/WorkerScope.h
--- mozilla/dom/workers/WorkerScope.h 2023-11-07 00:01:22.000000000 +0300
+++ mozilla-OK/dom/workers/WorkerScope.h 2023-12-08 22:57:52.820002364 +0300
@@ -25,6 +25,7 @@ class Function;
class IDBFactory;
enum class ImageBitmapFormat : uint8_t;
class Performance;
+struct PostMessageOptions;
class Promise;
class RequestOrUSVString;
class ServiceWorkerRegistration;
@@ -248,6 +249,11 @@ public:
ErrorResult& aRv);
void
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+ const PostMessageOptions& aOptions,
+ ErrorResult& aRv);
+
+ void
Close(JSContext* aCx);
IMPL_EVENT_HANDLER(message)