Bug 1502802 - Implement PostMessageOptions for Client and ServiceWorker, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 29 Oct 2018 16:26:30 +0100
changeset 443383 bc4333f4fabb3a0dfdfd6475fbef339a4dee9039
parent 443382 815f3200c6ce8c09b5f25991996618f8b8a09427
child 443384 c0cf2301443d9c7adda82829aa2b7ace041983f4
push id34955
push userrgurzau@mozilla.com
push dateMon, 29 Oct 2018 22:01:36 +0000
treeherdermozilla-central@4c7772c170a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1502802
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1502802 - Implement PostMessageOptions for Client and ServiceWorker, r=smaug
dom/clients/api/Client.cpp
dom/clients/api/Client.h
dom/serviceworkers/ServiceWorker.cpp
dom/serviceworkers/ServiceWorker.h
dom/webidl/Client.webidl
dom/webidl/ServiceWorker.webidl
testing/web-platform/meta/service-workers/service-worker/postmessage.https.html.ini
--- a/dom/clients/api/Client.cpp
+++ b/dom/clients/api/Client.cpp
@@ -7,16 +7,17 @@
 #include "Client.h"
 
 #include "ClientDOMUtil.h"
 #include "mozilla/dom/ClientHandle.h"
 #include "mozilla/dom/ClientIPCTypes.h"
 #include "mozilla/dom/ClientManager.h"
 #include "mozilla/dom/ClientState.h"
 #include "mozilla/dom/DOMMozPromiseRequestHolder.h"
+#include "mozilla/dom/MessagePortBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerScope.h"
 #include "nsIGlobalObject.h"
 
 namespace mozilla {
 namespace dom {
 
@@ -137,16 +138,24 @@ Client::PostMessage(JSContext* aCx, JS::
   if (aRv.Failed()) {
     return;
   }
 
   EnsureHandle();
   mHandle->PostMessage(data, workerPrivate->GetServiceWorkerDescriptor());
 }
 
+void
+Client::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+                    const PostMessageOptions& aOptions,
+                    ErrorResult& aRv)
+{
+  PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
 VisibilityState
 Client::GetVisibilityState() const
 {
   return mData->state().get_IPCClientWindowState().visibilityState();
 }
 
 bool
 Client::Focused() const
--- a/dom/clients/api/Client.h
+++ b/dom/clients/api/Client.h
@@ -17,16 +17,17 @@ class nsIGlobalObject;
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class ClientHandle;
 class ClientInfoAndState;
+struct PostMessageOptions;
 class Promise;
 
 template <typename t> class Sequence;
 
 class Client final : public nsISupports
                    , public nsWrapperCache
 {
   nsCOMPtr<nsIGlobalObject> mGlobal;
@@ -84,16 +85,21 @@ public:
   already_AddRefed<Promise>
   Navigate(const nsAString& aURL, ErrorResult& aRv);
 
   void
   PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
               const Sequence<JSObject*>& aTransferrable,
               ErrorResult& aRv);
 
+  void
+  PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+              const PostMessageOptions& aOptions,
+              ErrorResult& aRv);
+
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(mozilla::dom::Client)
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // _mozilla_dom_Client_h
--- a/dom/serviceworkers/ServiceWorker.cpp
+++ b/dom/serviceworkers/ServiceWorker.cpp
@@ -13,16 +13,17 @@
 #include "ServiceWorkerImpl.h"
 #include "ServiceWorkerManager.h"
 #include "ServiceWorkerPrivate.h"
 #include "ServiceWorkerRegistration.h"
 #include "ServiceWorkerUtils.h"
 
 #include "mozilla/dom/ClientIPCTypes.h"
 #include "mozilla/dom/ClientState.h"
+#include "mozilla/dom/MessagePortBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/StaticPrefs.h"
 
 #ifdef XP_WIN
 #undef PostMessage
 #endif
@@ -225,16 +226,23 @@ ServiceWorker::PostMessage(JSContext* aC
   data->Write(aCx, aMessage, transferable, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   mInner->PostMessage(std::move(data), clientInfo.ref(), clientState.ref());
 }
 
+void
+ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
+                           const PostMessageOptions& aOptions,
+                           ErrorResult& aRv)
+{
+  PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
 
 const ServiceWorkerDescriptor&
 ServiceWorker::Descriptor() const
 {
   return mDescriptor;
 }
 
 void
--- a/dom/serviceworkers/ServiceWorker.h
+++ b/dom/serviceworkers/ServiceWorker.h
@@ -16,16 +16,17 @@
 #undef PostMessage
 #endif
 
 class nsIGlobalObject;
 
 namespace mozilla {
 namespace dom {
 
+struct PostMessageOptions;
 class ServiceWorkerCloneData;
 
 #define NS_DOM_SERVICEWORKER_IID \
   {0xd42e0611, 0x3647, 0x4319, {0xae, 0x05, 0x19, 0x89, 0x59, 0xba, 0x99, 0x5e}}
 
 bool
 ServiceWorkerVisible(JSContext* aCx, JSObject* aObj);
 
@@ -94,16 +95,20 @@ public:
 
   void
   GetScriptURL(nsString& aURL) const;
 
   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);
+
   const ServiceWorkerDescriptor&
   Descriptor() const;
 
   void
   DisconnectFromOwner() override;
 
 private:
   ServiceWorker(nsIGlobalObject* aWindow,
--- a/dom/webidl/Client.webidl
+++ b/dom/webidl/Client.webidl
@@ -18,17 +18,19 @@ interface Client {
 
   readonly attribute ClientType type;
   readonly attribute DOMString id;
 
   // Implement reserved in bug 1264177
   // 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]
 interface WindowClient : Client {
   [BinaryName="GetVisibilityState"]
   readonly attribute VisibilityState visibilityState;
   readonly attribute boolean focused;
 
--- a/dom/webidl/ServiceWorker.webidl
+++ b/dom/webidl/ServiceWorker.webidl
@@ -15,17 +15,19 @@
  Exposed=(Window,Worker)]
 interface ServiceWorker : EventTarget {
   readonly attribute USVString scriptURL;
   readonly attribute ServiceWorkerState state;
 
   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;
 
 enum ServiceWorkerState {
   // https://github.com/w3c/ServiceWorker/issues/1162
   "parsed",
 
deleted file mode 100644
--- a/testing/web-platform/meta/service-workers/service-worker/postmessage.https.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[postmessage.https.html]
-  [postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client]
-    expected: FAIL
-