Skip to content

Commit d6a7ceb

Browse files
authored
added overload for postmessage to accept objects (#275)
* added overload for postmessage to accept objects
1 parent 7a3869a commit d6a7ceb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/DSharp.Web/Html/Window.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Window.cs
1+
// Window.cs
22
// Script#/Libraries/Web
33
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
44
//
@@ -475,6 +475,8 @@ public static DBFactory IndexedDB {
475475
public static void PostMessage(string message, string targetOrigin) {
476476
}
477477

478+
public static extern void PostMessage(object message, string targetOrigin);
479+
478480
/// <summary>
479481
/// Delegate that indicates the ability of the browser
480482
/// to show a modal dialog.

src/DSharp.Web/Html/WindowInstance.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// WindowInstance.cs
1+
// WindowInstance.cs
22
// Script#/Libraries/Web
33
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
44
//
@@ -206,5 +206,12 @@ public void ScrollTo(int x, int y) {
206206

207207
public void PostMessage(string message, string targetOrigin) {
208208
}
209+
210+
/// <summary>
211+
/// The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
212+
/// </summary>
213+
/// <param name="message">Data to be sent to the other window. The data is serialized using the structured clone algorithm. This means you can pass a broad variety of data objects safely to the destination window without having to serialize them yourself</param>
214+
/// <param name="targetOrigin">Specifies what the origin of targetWindow must be for the event to be dispatched, either as the literal string "*" (indicating no preference) or as a URI. If at the time the event is scheduled to be dispatched the scheme, hostname, or port of targetWindow's document does not match that provided in targetOrigin, the event will not be dispatched; only if all three match will the event be dispatched. This mechanism provides control over where messages are sent; for example, if postMessage() was used to transmit a password, it would be absolutely critical that this argument be a URI whose origin is the same as the intended receiver of the message containing the password, to prevent interception of the password by a malicious third party. <b>Always provide a specific targetOrigin, not *, if you know where the other window's document should be located. Failing to provide a specific target discloses the data you send to any interested malicious site</b></param>
215+
public extern void PostMessage(object message, string targetOrigin);
209216
}
210217
}

0 commit comments

Comments
 (0)