Bug 1550364 part 6. Stop using [array] in nsIUDPSocketInternal. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 May 2019 06:55:07 +0000
changeset 532110 91754861e8d845ea6d84ae52b4ebad339fd89d96
parent 532109 1456c2b5efb899d210fb91f2ebedfcad7c094bea
child 532111 3315610792f4b94ab15a102fa8119efec42f9a2e
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)
reviewersbaku
bugs1550364
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 1550364 part 6. Stop using [array] in nsIUDPSocketInternal. r=baku Differential Revision: https://phabricator.services.mozilla.com/D30449
dom/network/UDPSocket.cpp
dom/network/UDPSocket.h
dom/network/UDPSocketChild.cpp
dom/network/interfaces/nsIUDPSocketChild.idl
media/mtransport/nr_socket_prsock.cpp
media/mtransport/nr_socket_prsock.h
--- a/dom/network/UDPSocket.cpp
+++ b/dom/network/UDPSocket.cpp
@@ -557,47 +557,44 @@ nsresult UDPSocket::Init(const nsString&
 
   nsCOMPtr<nsIRunnable> runnable = new OpenSocketRunnable(this);
 
   return NS_DispatchToMainThread(runnable);
 }
 
 void UDPSocket::HandleReceivedData(const nsACString& aRemoteAddress,
                                    const uint16_t& aRemotePort,
-                                   const uint8_t* aData,
-                                   const uint32_t& aDataLength) {
+                                   const nsTArray<uint8_t>& aData) {
   if (mReadyState != SocketReadyState::Open) {
     return;
   }
 
   if (NS_FAILED(CheckCurrentGlobalCorrectness())) {
     return;
   }
 
-  if (NS_FAILED(DispatchReceivedData(aRemoteAddress, aRemotePort, aData,
-                                     aDataLength))) {
+  if (NS_FAILED(DispatchReceivedData(aRemoteAddress, aRemotePort, aData))) {
     CloseWithReason(NS_ERROR_TYPE_ERR);
   }
 }
 
 nsresult UDPSocket::DispatchReceivedData(const nsACString& aRemoteAddress,
                                          const uint16_t& aRemotePort,
-                                         const uint8_t* aData,
-                                         const uint32_t& aDataLength) {
+                                         const nsTArray<uint8_t>& aData) {
   AutoJSAPI jsapi;
 
   if (NS_WARN_IF(!jsapi.Init(GetOwner()))) {
     return NS_ERROR_FAILURE;
   }
 
   JSContext* cx = jsapi.cx();
 
   // Copy packet data to ArrayBuffer
-  JS::Rooted<JSObject*> arrayBuf(cx,
-                                 ArrayBuffer::Create(cx, aDataLength, aData));
+  JS::Rooted<JSObject*> arrayBuf(
+      cx, ArrayBuffer::Create(cx, aData.Length(), aData.Elements()));
 
   if (NS_WARN_IF(!arrayBuf)) {
     return NS_ERROR_FAILURE;
   }
 
   JS::Rooted<JS::Value> jsData(cx, JS::ObjectValue(*arrayBuf));
 
   // Create DOM event
@@ -641,18 +638,17 @@ UDPSocket::OnPacketReceived(nsIUDPSocket
     return NS_OK;
   }
 
   uint16_t remotePort;
   if (NS_WARN_IF(NS_FAILED(addr->GetPort(&remotePort)))) {
     return NS_OK;
   }
 
-  HandleReceivedData(remoteAddress, remotePort, buffer.Elements(),
-                     buffer.Length());
+  HandleReceivedData(remoteAddress, remotePort, buffer);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 UDPSocket::OnStopListening(nsIUDPSocket* aSocket, nsresult aStatus) {
   // nsIUDPSocketListener callbacks should be invoked on main thread.
   MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
 
@@ -669,19 +665,19 @@ UDPSocket::CallListenerError(const nsACS
                              uint32_t aLineNumber) {
   CloseWithReason(NS_ERROR_DOM_NETWORK_ERR);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 UDPSocket::CallListenerReceivedData(const nsACString& aRemoteAddress,
-                                    uint16_t aRemotePort, const uint8_t* aData,
-                                    uint32_t aDataLength) {
-  HandleReceivedData(aRemoteAddress, aRemotePort, aData, aDataLength);
+                                    uint16_t aRemotePort,
+                                    const nsTArray<uint8_t>& aData) {
+  HandleReceivedData(aRemoteAddress, aRemotePort, aData);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 UDPSocket::CallListenerOpened() {
   if (mReadyState != SocketReadyState::Opening) {
     return NS_OK;
--- a/dom/network/UDPSocket.h
+++ b/dom/network/UDPSocket.h
@@ -124,23 +124,22 @@ class UDPSocket final : public DOMEventT
 
   nsresult InitLocal(const nsAString& aLocalAddress,
                      const uint16_t& aLocalPort);
 
   nsresult InitRemote(const nsAString& aLocalAddress,
                       const uint16_t& aLocalPort);
 
   void HandleReceivedData(const nsACString& aRemoteAddress,
-                          const uint16_t& aRemotePort, const uint8_t* aData,
-                          const uint32_t& aDataLength);
+                          const uint16_t& aRemotePort,
+                          const nsTArray<uint8_t>& aData);
 
   nsresult DispatchReceivedData(const nsACString& aRemoteAddress,
                                 const uint16_t& aRemotePort,
-                                const uint8_t* aData,
-                                const uint32_t& aDataLength);
+                                const nsTArray<uint8_t>& aData);
 
   void CloseWithReason(nsresult aReason);
 
   nsresult DoPendingMcastCommand();
 
   nsString mLocalAddress;
   Nullable<uint16_t> mLocalPort;
   nsCString mRemoteAddress;
--- a/dom/network/UDPSocketChild.cpp
+++ b/dom/network/UDPSocketChild.cpp
@@ -213,19 +213,18 @@ mozilla::ipc::IPCResult UDPSocketChild::
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult UDPSocketChild::RecvCallbackReceivedData(
     const UDPAddressInfo& aAddressInfo, InfallibleTArray<uint8_t>&& aData) {
   UDPSOCKET_LOG(("%s: %s:%u length %zu", __FUNCTION__,
                  aAddressInfo.addr().get(), aAddressInfo.port(),
                  aData.Length()));
-  nsresult rv = mSocket->CallListenerReceivedData(
-      aAddressInfo.addr(), aAddressInfo.port(), aData.Elements(),
-      aData.Length());
+  nsresult rv = mSocket->CallListenerReceivedData(aAddressInfo.addr(),
+                                                  aAddressInfo.port(), aData);
   mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult UDPSocketChild::RecvCallbackError(
     const nsCString& aMessage, const nsCString& aFilename,
     const uint32_t& aLineNumber) {
--- a/dom/network/interfaces/nsIUDPSocketChild.idl
+++ b/dom/network/interfaces/nsIUDPSocketChild.idl
@@ -8,24 +8,23 @@
 interface nsIUDPSocketInternal;
 interface nsIInputStream;
 interface nsIPrincipal;
 interface nsIEventTarget;
 
 /*
  * Internal interface for callback from chrome process
  */
-[scriptable, uuid(613dd3ad-598b-4da9-ad63-bbda50c20098)]
+[scriptable, builtinclass, uuid(613dd3ad-598b-4da9-ad63-bbda50c20098)]
 interface nsIUDPSocketInternal : nsISupports
 {
   // callback while socket is opened. localPort and localAddress is ready until this time.
   void callListenerOpened();
   // callback while socket is connected.
   void callListenerConnected();
   // callback while socket is closed.
   void callListenerClosed();
   // callback while incoming packet is received.
   void callListenerReceivedData(in AUTF8String host, in unsigned short port,
-                                [const, array, size_is(dataLength)] in uint8_t data,
-                                in unsigned long dataLength);
+                                in Array<uint8_t> data);
   // callback while any error happened.
   void callListenerError(in AUTF8String message, in AUTF8String filename, in uint32_t lineNumber);
 };
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -1055,19 +1055,18 @@ NrUdpSocketIpcProxy::~NrUdpSocketIpcProx
 NS_IMETHODIMP NrUdpSocketIpcProxy::CallListenerError(const nsACString& message,
                                                      const nsACString& filename,
                                                      uint32_t line_number) {
   return socket_->CallListenerError(message, filename, line_number);
 }
 
 // callback while receiving UDP packet
 NS_IMETHODIMP NrUdpSocketIpcProxy::CallListenerReceivedData(
-    const nsACString& host, uint16_t port, const uint8_t* data,
-    uint32_t data_length) {
-  return socket_->CallListenerReceivedData(host, port, data, data_length);
+    const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
+  return socket_->CallListenerReceivedData(host, port, data);
 }
 
 // callback while UDP socket is opened
 NS_IMETHODIMP NrUdpSocketIpcProxy::CallListenerOpened() {
   return socket_->CallListenerOpened();
 }
 
 // callback while UDP socket is connected
@@ -1114,20 +1113,18 @@ NS_IMETHODIMP NrUdpSocketIpc::CallListen
   ReentrantMonitorAutoEnter mon(monitor_);
   err_ = true;
   monitor_.NotifyAll();
 
   return NS_OK;
 }
 
 // callback while receiving UDP packet
-NS_IMETHODIMP NrUdpSocketIpc::CallListenerReceivedData(const nsACString& host,
-                                                       uint16_t port,
-                                                       const uint8_t* data,
-                                                       uint32_t data_length) {
+NS_IMETHODIMP NrUdpSocketIpc::CallListenerReceivedData(
+    const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
   ASSERT_ON_THREAD(io_thread_);
 
   PRNetAddr addr;
   memset(&addr, 0, sizeof(addr));
 
   {
     ReentrantMonitorAutoEnter mon(monitor_);
 
@@ -1142,17 +1139,17 @@ NS_IMETHODIMP NrUdpSocketIpc::CallListen
         PR_SetNetAddr(PR_IpAddrNull, addr.raw.family, port, &addr)) {
       err_ = true;
       MOZ_ASSERT(false, "Failed to set port in PRNetAddr");
       return NS_OK;
     }
   }
 
   nsAutoPtr<MediaPacket> buf(new MediaPacket);
-  buf->Copy(data, data_length);
+  buf->Copy(data.Elements(), data.Length());
   RefPtr<nr_udp_message> msg(new nr_udp_message(addr, buf));
 
   RUN_ON_THREAD(sts_thread_,
                 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
                                       &NrUdpSocketIpc::recv_callback_s, msg),
                 NS_DISPATCH_NORMAL);
   return NS_OK;
 }
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -241,18 +241,17 @@ class NrSocketIpc : public NrSocketBase 
 class NrUdpSocketIpc : public NrSocketIpc {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrUdpSocketIpc, override)
 
   NS_IMETHODIMP CallListenerError(const nsACString& message,
                                   const nsACString& filename,
                                   uint32_t line_number);
   NS_IMETHODIMP CallListenerReceivedData(const nsACString& host, uint16_t port,
-                                         const uint8_t* data,
-                                         uint32_t data_length);
+                                         const nsTArray<uint8_t>& data);
   NS_IMETHODIMP CallListenerOpened();
   NS_IMETHODIMP CallListenerConnected();
   NS_IMETHODIMP CallListenerClosed();
 
   NrUdpSocketIpc();
 
   // Implementations of the NrSocketBase APIs
   virtual int create(nr_transport_addr* addr) override;