Bug 1542170 - Expose http channel Id to WebSocketEvent listeners, r=valentin
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 03 May 2019 17:25:44 +0000
changeset 531343 87fbdfa81895208c7dbf3a0f174450a9978fe9bd
parent 531342 24a453261a2ea10668ba55a06dfb45ee029e6011
child 531344 216940ec115da17b4efad13094aad06b3efdbde3
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1542170
milestone68.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 1542170 - Expose http channel Id to WebSocketEvent listeners, r=valentin Differential Revision: https://phabricator.services.mozilla.com/D28865
dom/websocket/WebSocket.cpp
dom/websocket/tests/test_websocket_frame.html
netwerk/protocol/websocket/PWebSocketEventListener.ipdl
netwerk/protocol/websocket/WebSocketEventListenerChild.cpp
netwerk/protocol/websocket/WebSocketEventListenerChild.h
netwerk/protocol/websocket/WebSocketEventListenerParent.cpp
netwerk/protocol/websocket/WebSocketEventService.cpp
netwerk/protocol/websocket/WebSocketEventService.h
netwerk/protocol/websocket/nsIWebSocketEventService.idl
--- a/dom/websocket/WebSocket.cpp
+++ b/dom/websocket/WebSocket.cpp
@@ -711,17 +711,18 @@ WebSocketImpl::OnStart(nsISupports* aCon
   rv = mChannel->GetExtensions(mWebSocket->mEstablishedExtensions);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   UpdateURI();
 
   mWebSocket->SetReadyState(WebSocket::OPEN);
 
   mService->WebSocketOpened(
       mChannel->Serial(), mInnerWindowID, mWebSocket->mEffectiveURL,
-      mWebSocket->mEstablishedProtocol, mWebSocket->mEstablishedExtensions);
+      mWebSocket->mEstablishedProtocol, mWebSocket->mEstablishedExtensions,
+      mChannel->HttpChannelId());
 
   // Let's keep the object alive because the webSocket can be CCed in the
   // onopen callback.
   RefPtr<WebSocket> webSocket = mWebSocket;
 
   // Call 'onopen'
   rv = webSocket->CreateAndDispatchSimpleEvent(OPEN_EVENT_STRING);
   if (NS_FAILED(rv)) {
--- a/dom/websocket/tests/test_websocket_frame.html
+++ b/dom/websocket/tests/test_websocket_frame.html
@@ -40,22 +40,23 @@ var listener = {
     info("WebSocketCreated");
 
     is(aURI, URI, "URI matches");
     is(aProtocols, "frame", "Protocol matches");
 
     webSocketCreatedCounter++;
   },
 
-  webSocketOpened: function(aWebSocketSerialID, aEffectiveURI, aProtocols, aExtensions) {
+  webSocketOpened: function(aWebSocketSerialID, aEffectiveURI, aProtocols, aExtensions, httpChannelId) {
     info("WebSocketOpened");
 
     is(aEffectiveURI, URI, "EffectiveURI matches");
     is(aProtocols, "frame", "Protocol matches");
     is(aExtensions, "permessage-deflate", "No extensions");
+    ok(httpChannelId > 0, "Channel ID received");
 
     webSocketOpenedCounter++;
   },
 
   webSocketMessageAvailable: function(aWebSocketSerialID, aData, aMessageType) {
     info("WebSocketMessageAvailable");
 
     if (tests.length) {
--- a/netwerk/protocol/websocket/PWebSocketEventListener.ipdl
+++ b/netwerk/protocol/websocket/PWebSocketEventListener.ipdl
@@ -19,17 +19,18 @@ async protocol PWebSocketEventListener
 child:
   async WebSocketCreated(uint32_t awebSocketSerialID,
                          nsString aURI,
                          nsCString aProtocols);
 
   async WebSocketOpened(uint32_t awebSocketSerialID,
                         nsString aEffectiveURI,
                         nsCString aProtocols,
-                        nsCString aExtensions);
+                        nsCString aExtensions,
+                        uint64_t aHttpChannelId);
 
   async WebSocketMessageAvailable(uint32_t awebSocketSerialID,
                                   nsCString aData,
                                   uint16_t aMessageType);
 
   async WebSocketClosed(uint32_t awebSocketSerialID,
                         bool aWasClean,
                         uint16_t aCode,
--- a/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketEventListenerChild.cpp
@@ -31,21 +31,22 @@ mozilla::ipc::IPCResult WebSocketEventLi
                                aProtocols, target);
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult WebSocketEventListenerChild::RecvWebSocketOpened(
     const uint32_t& aWebSocketSerialID, const nsString& aEffectiveURI,
-    const nsCString& aProtocols, const nsCString& aExtensions) {
+    const nsCString& aProtocols, const nsCString& aExtensions,
+    const uint64_t& aHttpChannelId) {
   if (mService) {
     nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
     mService->WebSocketOpened(aWebSocketSerialID, mInnerWindowID, aEffectiveURI,
-                              aProtocols, aExtensions, target);
+                              aProtocols, aExtensions, aHttpChannelId, target);
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 WebSocketEventListenerChild::RecvWebSocketMessageAvailable(
     const uint32_t& aWebSocketSerialID, const nsCString& aData,
--- a/netwerk/protocol/websocket/WebSocketEventListenerChild.h
+++ b/netwerk/protocol/websocket/WebSocketEventListenerChild.h
@@ -24,17 +24,18 @@ class WebSocketEventListenerChild final 
                                        nsIEventTarget* aTarget);
 
   mozilla::ipc::IPCResult RecvWebSocketCreated(
       const uint32_t& aWebSocketSerialID, const nsString& aURI,
       const nsCString& aProtocols);
 
   mozilla::ipc::IPCResult RecvWebSocketOpened(
       const uint32_t& aWebSocketSerialID, const nsString& aEffectiveURI,
-      const nsCString& aProtocols, const nsCString& aExtensions);
+      const nsCString& aProtocols, const nsCString& aExtensions,
+      const uint64_t& aHttpChannelId);
 
   mozilla::ipc::IPCResult RecvWebSocketMessageAvailable(
       const uint32_t& aWebSocketSerialID, const nsCString& aData,
       const uint16_t& aMessageType);
 
   mozilla::ipc::IPCResult RecvWebSocketClosed(
       const uint32_t& aWebSocketSerialID, const bool& aWasClean,
       const uint16_t& aCode, const nsString& aReason);
--- a/netwerk/protocol/websocket/WebSocketEventListenerParent.cpp
+++ b/netwerk/protocol/websocket/WebSocketEventListenerParent.cpp
@@ -60,19 +60,21 @@ WebSocketEventListenerParent::WebSocketC
                                  nsCString(aProtocols));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebSocketEventListenerParent::WebSocketOpened(uint32_t aWebSocketSerialID,
                                               const nsAString& aEffectiveURI,
                                               const nsACString& aProtocols,
-                                              const nsACString& aExtensions) {
+                                              const nsACString& aExtensions,
+                                              uint64_t aHttpChannelId) {
   Unused << SendWebSocketOpened(aWebSocketSerialID, nsString(aEffectiveURI),
-                                nsCString(aProtocols), nsCString(aExtensions));
+                                nsCString(aProtocols), nsCString(aExtensions),
+                                aHttpChannelId);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebSocketEventListenerParent::WebSocketClosed(uint32_t aWebSocketSerialID,
                                               bool aWasClean, uint16_t aCode,
                                               const nsAString& aReason) {
   Unused << SendWebSocketClosed(aWebSocketSerialID, aWasClean, aCode,
--- a/netwerk/protocol/websocket/WebSocketEventService.cpp
+++ b/netwerk/protocol/websocket/WebSocketEventService.cpp
@@ -107,32 +107,36 @@ class WebSocketCreatedRunnable final : p
   const nsCString mProtocols;
 };
 
 class WebSocketOpenedRunnable final : public WebSocketBaseRunnable {
  public:
   WebSocketOpenedRunnable(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID,
                           const nsAString& aEffectiveURI,
                           const nsACString& aProtocols,
-                          const nsACString& aExtensions)
+                          const nsACString& aExtensions,
+                          uint64_t aHttpChannelId)
       : WebSocketBaseRunnable(aWebSocketSerialID, aInnerWindowID),
         mEffectiveURI(aEffectiveURI),
         mProtocols(aProtocols),
-        mExtensions(aExtensions) {}
+        mExtensions(aExtensions),
+        mHttpChannelId(aHttpChannelId) {}
 
  private:
   virtual void DoWork(nsIWebSocketEventListener* aListener) override {
-    DebugOnly<nsresult> rv = aListener->WebSocketOpened(
-        mWebSocketSerialID, mEffectiveURI, mProtocols, mExtensions);
+    DebugOnly<nsresult> rv =
+        aListener->WebSocketOpened(mWebSocketSerialID, mEffectiveURI,
+                                   mProtocols, mExtensions, mHttpChannelId);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "WebSocketOpened failed");
   }
 
   const nsString mEffectiveURI;
   const nsCString mProtocols;
   const nsCString mExtensions;
+  uint64_t mHttpChannelId;
 };
 
 class WebSocketMessageAvailableRunnable final : public WebSocketBaseRunnable {
  public:
   WebSocketMessageAvailableRunnable(uint32_t aWebSocketSerialID,
                                     uint64_t aInnerWindowID,
                                     const nsACString& aData,
                                     uint16_t aMessageType)
@@ -233,25 +237,26 @@ void WebSocketEventService::WebSocketCre
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
 }
 
 void WebSocketEventService::WebSocketOpened(uint32_t aWebSocketSerialID,
                                             uint64_t aInnerWindowID,
                                             const nsAString& aEffectiveURI,
                                             const nsACString& aProtocols,
                                             const nsACString& aExtensions,
+                                            uint64_t aHttpChannelId,
                                             nsIEventTarget* aTarget) {
   // Let's continue only if we have some listeners.
   if (!HasListeners()) {
     return;
   }
 
-  RefPtr<WebSocketOpenedRunnable> runnable =
-      new WebSocketOpenedRunnable(aWebSocketSerialID, aInnerWindowID,
-                                  aEffectiveURI, aProtocols, aExtensions);
+  RefPtr<WebSocketOpenedRunnable> runnable = new WebSocketOpenedRunnable(
+      aWebSocketSerialID, aInnerWindowID, aEffectiveURI, aProtocols,
+      aExtensions, aHttpChannelId);
   DebugOnly<nsresult> rv = aTarget
                                ? aTarget->Dispatch(runnable, NS_DISPATCH_NORMAL)
                                : NS_DispatchToMainThread(runnable);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
 }
 
 void WebSocketEventService::WebSocketMessageAvailable(
     uint32_t aWebSocketSerialID, uint64_t aInnerWindowID,
--- a/netwerk/protocol/websocket/WebSocketEventService.h
+++ b/netwerk/protocol/websocket/WebSocketEventService.h
@@ -38,17 +38,17 @@ class WebSocketEventService final : publ
 
   void WebSocketCreated(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID,
                         const nsAString& aURI, const nsACString& aProtocols,
                         nsIEventTarget* aTarget = nullptr);
 
   void WebSocketOpened(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID,
                        const nsAString& aEffectiveURI,
                        const nsACString& aProtocols,
-                       const nsACString& aExtensions,
+                       const nsACString& aExtensions, uint64_t aHttpChannelId,
                        nsIEventTarget* aTarget = nullptr);
 
   void WebSocketMessageAvailable(uint32_t aWebSocketSerialID,
                                  uint64_t aInnerWindowID,
                                  const nsACString& aData, uint16_t aMessageType,
                                  nsIEventTarget* aTarget = nullptr);
 
   void WebSocketClosed(uint32_t aWebSocketSerialID, uint64_t aInnerWindowID,
--- a/netwerk/protocol/websocket/nsIWebSocketEventService.idl
+++ b/netwerk/protocol/websocket/nsIWebSocketEventService.idl
@@ -41,17 +41,18 @@ interface nsIWebSocketEventListener : ns
 {
   [must_use] void webSocketCreated(in unsigned long aWebSocketSerialID,
                                    in AString aURI,
                                    in ACString aProtocols);
 
   [must_use] void webSocketOpened(in unsigned long aWebSocketSerialID,
                                   in AString aEffectiveURI,
                                   in ACString aProtocols,
-                                  in ACString aExtensions);
+                                  in ACString aExtensions,
+                                  in uint64_t aHttpChannelId);
 
   const unsigned short TYPE_STRING      = 0x0;
   const unsigned short TYPE_BLOB        = 0x1;
   const unsigned short TYPE_ARRAYBUFFER = 0x2;
 
   [must_use] void webSocketMessageAvailable(in unsigned long aWebSocketSerialID,
                                             in ACString aMessage,
                                             in unsigned short aType);