Issue #2197 - Part 2d: Implement PostMessageOptions for Window

Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1502802
This commit is contained in:
FranklinDM 2023-04-07 16:02:34 +08:00 committed by roytam1
commit 4174037d8a
4 changed files with 23 additions and 7 deletions

View file

@ -8904,6 +8904,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;

View file

@ -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,

View file

@ -383,13 +383,6 @@ var tests =
hasWrongReturnOriginBug: true
},
// 55
{
args: ["NOT-RECEIVED", undefined],
source: "sameDomain",
name: "SyntaxError",
code: DOMException.SYNTAX_ERR
},
];
function allTests(callback)

View file

@ -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 = "/";
};