Bug 1200132 - Use adderss to create socketTransport, r=schien, junior
authorKershaw Chang <kechang@mozilla.com>
Wed, 21 Oct 2015 02:54:00 +0200
changeset 303944 dd0747ee0782de1427d4d30db3ff695857a5dd5f
parent 303943 b26934635fa1ee30a89e3cb437019ca1a365026a
child 303945 302c448ac9388093afc0a235cf4b3c4fbced102b
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien, junior
bugs1200132
milestone44.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 1200132 - Use adderss to create socketTransport, r=schien, junior
dom/presentation/interfaces/nsITCPPresentationServer.idl
dom/presentation/provider/MulticastDNSDeviceProvider.cpp
dom/presentation/provider/MulticastDNSDeviceProvider.h
dom/presentation/provider/TCPPresentationServer.js
dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
dom/presentation/tests/xpcshell/test_tcp_control_channel.js
--- a/dom/presentation/interfaces/nsITCPPresentationServer.idl
+++ b/dom/presentation/interfaces/nsITCPPresentationServer.idl
@@ -9,21 +9,21 @@ interface nsIPresentationControlChannel;
 %{C++
 #define TCP_PRESENTATION_SERVER_CONTACT_ID \
   "@mozilla.org/presentation-device/tcp-presentation-server;1"
 %}
 
 /*
  * The device information required for establishing TCP control channel.
  */
-[scriptable, uuid(7fce55c0-2470-4a41-a3b9-c35fbe55f206)]
+[scriptable, uuid(296fd171-e4d0-4de0-99ff-ad8ed52ddef3)]
 interface nsITCPDeviceInfo: nsISupports
 {
   readonly attribute AUTF8String id;
-  readonly attribute AUTF8String host;
+  readonly attribute AUTF8String address;
   readonly attribute uint16_t port;
 };
 
 [scriptable, uuid(fbb890a9-9e95-47d1-a425-86fd95881d81)]
 interface nsITCPPresentationServerListener: nsISupports
 {
   /**
    * Callback while the server socket stops listening.
--- a/dom/presentation/provider/MulticastDNSDeviceProvider.cpp
+++ b/dom/presentation/provider/MulticastDNSDeviceProvider.cpp
@@ -48,47 +48,47 @@ namespace {
 
 class TCPDeviceInfo final : public nsITCPDeviceInfo
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITCPDEVICEINFO
 
   explicit TCPDeviceInfo(const nsACString& aId,
-                         const nsACString& aHost,
+                         const nsACString& aAddress,
                          const uint16_t aPort)
     : mId(aId)
-    , mHost(aHost)
+    , mAddress(aAddress)
     , mPort(aPort)
   {
   }
 
 private:
   virtual ~TCPDeviceInfo() {}
 
   nsCString mId;
-  nsCString mHost;
+  nsCString mAddress;
   uint16_t mPort;
 };
 
 NS_IMPL_ISUPPORTS(TCPDeviceInfo,
                   nsITCPDeviceInfo)
 
 // nsITCPDeviceInfo
 NS_IMETHODIMP
 TCPDeviceInfo::GetId(nsACString& aId)
 {
   aId = mId;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-TCPDeviceInfo::GetHost(nsACString& aHost)
+TCPDeviceInfo::GetAddress(nsACString& aAddress)
 {
-  aHost = mHost;
+  aAddress = mAddress;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TCPDeviceInfo::GetPort(uint16_t* aPort)
 {
   *aPort = mPort;
   return NS_OK;
@@ -314,35 +314,36 @@ MulticastDNSDeviceProvider::RequestSessi
                                            const nsAString& aUrl,
                                            const nsAString& aPresentationId,
                                            nsIPresentationControlChannel** aRetVal)
 {
   MOZ_ASSERT(aDevice);
   MOZ_ASSERT(mPresentationServer);
 
   RefPtr<TCPDeviceInfo> deviceInfo = new TCPDeviceInfo(aDevice->Id(),
-                                                       aDevice->Host(),
+                                                       aDevice->Address(),
                                                        aDevice->Port());
 
   return mPresentationServer->RequestSession(deviceInfo, aUrl, aPresentationId, aRetVal);
 }
 
 nsresult
-MulticastDNSDeviceProvider::AddDevice(const nsACString& aServiceName,
+MulticastDNSDeviceProvider::AddDevice(const nsACString& aId,
+                                      const nsACString& aServiceName,
                                       const nsACString& aServiceType,
-                                      const nsACString& aHost,
+                                      const nsACString& aAddress,
                                       const uint16_t aPort)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mPresentationServer);
 
-  RefPtr<Device> device = new Device(aHost, /* ID */
+  RefPtr<Device> device = new Device(aId, /* ID */
                                      aServiceName,
                                      aServiceType,
-                                     aHost,
+                                     aAddress,
                                      aPort,
                                      DeviceState::eActive,
                                      this);
 
   nsCOMPtr<nsIPresentationDeviceListener> listener;
   if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
     unused << listener->AddDevice(device);
   }
@@ -351,28 +352,28 @@ MulticastDNSDeviceProvider::AddDevice(co
 
   return NS_OK;
 }
 
 nsresult
 MulticastDNSDeviceProvider::UpdateDevice(const uint32_t aIndex,
                                          const nsACString& aServiceName,
                                          const nsACString& aServiceType,
-                                         const nsACString& aHost,
+                                         const nsACString& aAddress,
                                          const uint16_t aPort)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mPresentationServer);
 
   if (NS_WARN_IF(aIndex >= mDevices.Length())) {
     return NS_ERROR_INVALID_ARG;
   }
 
   RefPtr<Device> device = mDevices[aIndex];
-  device->Update(aServiceName, aServiceType, aHost, aPort);
+  device->Update(aServiceName, aServiceType, aAddress, aPort);
   device->ChangeState(DeviceState::eActive);
 
   nsCOMPtr<nsIPresentationDeviceListener> listener;
   if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
     unused << listener->UpdateDevice(device);
   }
 
   return NS_OK;
@@ -420,29 +421,29 @@ MulticastDNSDeviceProvider::FindDeviceBy
     return false;
   }
 
   aIndex = index;
   return true;
 }
 
 bool
-MulticastDNSDeviceProvider::FindDeviceByHost(const nsACString& aHost,
-                                             uint32_t& aIndex)
+MulticastDNSDeviceProvider::FindDeviceByAddress(const nsACString& aAddress,
+                                                uint32_t& aIndex)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<Device> device = new Device(/* aId = */ EmptyCString(),
                                      /* aName = */ EmptyCString(),
                                      /* aType = */ EmptyCString(),
-                                     aHost,
+                                     aAddress,
                                      /* aPort = */ 0,
                                      /* aState = */ DeviceState::eUnknown,
                                      /* aProvider = */ nullptr);
-  size_t index = mDevices.IndexOf(device, 0, DeviceHostComparator());
+  size_t index = mDevices.IndexOf(device, 0, DeviceAddressComparator());
 
   if (index == mDevices.NoIndex) {
     return false;
   }
 
   aIndex = index;
   return true;
 }
@@ -770,37 +771,43 @@ MulticastDNSDeviceProvider::OnServiceRes
 
   LOG_I("OnServiceResolved: %s", serviceName.get());
 
   nsAutoCString host;
   if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetHost(host)))) {
     return rv;
   }
 
+  nsAutoCString address;
+  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetAddress(address)))) {
+    return rv;
+  }
+
   uint16_t port;
   if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetPort(&port)))) {
     return rv;
   }
 
   nsAutoCString serviceType;
   if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceType(serviceType)))) {
     return rv;
   }
 
   uint32_t index;
   if (FindDeviceById(host, index)) {
     return UpdateDevice(index,
                         serviceName,
                         serviceType,
-                        host,
+                        address,
                         port);
   } else {
-    return AddDevice(serviceName,
+    return AddDevice(host,
+                     serviceName,
                      serviceType,
-                     host,
+                     address,
                      port);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MulticastDNSDeviceProvider::OnResolveFailed(nsIDNSServiceInfo* aServiceInfo,
@@ -833,38 +840,38 @@ MulticastDNSDeviceProvider::OnClose(nsre
 NS_IMETHODIMP
 MulticastDNSDeviceProvider::OnSessionRequest(nsITCPDeviceInfo* aDeviceInfo,
                                              const nsAString& aUrl,
                                              const nsAString& aPresentationId,
                                              nsIPresentationControlChannel* aControlChannel)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsAutoCString host;
-  unused << aDeviceInfo->GetHost(host);
+  nsAutoCString address;
+  unused << aDeviceInfo->GetAddress(address);
 
-  LOG_I("OnSessionRequest: %s", host.get());
+  LOG_I("OnSessionRequest: %s", address.get());
 
   RefPtr<Device> device;
   uint32_t index;
-  if (FindDeviceByHost(host, index)) {
+  if (FindDeviceByAddress(address, index)) {
     device = mDevices[index];
   } else {
     // create a one-time device object for non-discoverable controller
     // this device will not be listed in available device list and cannot
     // be used for requesting session.
     nsAutoCString id;
     unused << aDeviceInfo->GetId(id);
     uint16_t port;
     unused << aDeviceInfo->GetPort(&port);
 
     device = new Device(id,
                         /* aName = */ id,
                         /* aType = */ EmptyCString(),
-                        host,
+                        address,
                         port,
                         DeviceState::eActive,
                         /* aProvider = */ nullptr);
   }
 
   nsCOMPtr<nsIPresentationDeviceListener> listener;
   if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
     unused << listener->OnSessionRequest(device, aUrl, aPresentationId,
--- a/dom/presentation/provider/MulticastDNSDeviceProvider.h
+++ b/dom/presentation/provider/MulticastDNSDeviceProvider.h
@@ -57,38 +57,38 @@ private:
   {
   public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIPRESENTATIONDEVICE
 
     explicit Device(const nsACString& aId,
                     const nsACString& aName,
                     const nsACString& aType,
-                    const nsACString& aHost,
+                    const nsACString& aAddress,
                     const uint16_t aPort,
                     DeviceState aState,
                     MulticastDNSDeviceProvider* aProvider)
       : mId(aId)
       , mName(aName)
       , mType(aType)
-      , mHost(aHost)
+      , mAddress(aAddress)
       , mPort(aPort)
       , mState(aState)
       , mProvider(aProvider)
     {
     }
 
     const nsCString& Id() const
     {
       return mId;
     }
 
-    const nsCString& Host() const
+    const nsCString& Address() const
     {
-      return mHost;
+      return mAddress;
     }
 
     const uint16_t Port() const
     {
       return mPort;
     }
 
     const DeviceState State() const
@@ -98,74 +98,75 @@ private:
 
     void ChangeState(DeviceState aState)
     {
       mState = aState;
     }
 
     void Update(const nsACString& aName,
                 const nsACString& aType,
-                const nsACString& aHost,
+                const nsACString& aAddress,
                 const uint16_t aPort)
     {
       mName = aName;
       mType = aType;
-      mHost = aHost;
+      mAddress = aAddress;
       mPort = aPort;
     }
 
   private:
     virtual ~Device() = default;
 
     nsCString mId;
     nsCString mName;
     nsCString mType;
-    nsCString mHost;
+    nsCString mAddress;
     uint16_t mPort;
     DeviceState mState;
     MulticastDNSDeviceProvider* mProvider;
   };
 
   struct DeviceIdComparator {
     bool Equals(const RefPtr<Device>& aA, const RefPtr<Device>& aB) const {
       return aA->Id() == aB->Id();
     }
   };
 
-  struct DeviceHostComparator {
+  struct DeviceAddressComparator {
     bool Equals(const RefPtr<Device>& aA, const RefPtr<Device>& aB) const {
-      return aA->Host() == aB->Host();
+      return aA->Address() == aB->Address();
     }
   };
 
   virtual ~MulticastDNSDeviceProvider();
   nsresult RegisterService();
   nsresult UnregisterService(nsresult aReason);
   nsresult StopDiscovery(nsresult aReason);
   nsresult RequestSession(Device* aDevice,
                           const nsAString& aUrl,
                           const nsAString& aPresentationId,
                           nsIPresentationControlChannel** aRetVal);
 
   // device manipulation
-  nsresult AddDevice(const nsACString& aServiceName,
+  nsresult AddDevice(const nsACString& aId,
+                     const nsACString& aServiceName,
                      const nsACString& aServiceType,
-                     const nsACString& aHost,
+                     const nsACString& aAddress,
                      const uint16_t aPort);
   nsresult UpdateDevice(const uint32_t aIndex,
                         const nsACString& aServiceName,
                         const nsACString& aServiceType,
-                        const nsACString& aHost,
+                        const nsACString& aAddress,
                         const uint16_t aPort);
   nsresult RemoveDevice(const uint32_t aIndex);
   bool FindDeviceById(const nsACString& aId,
                       uint32_t& aIndex);
 
-  bool FindDeviceByHost(const nsACString& aHost,
-                        uint32_t& aIndex);
+  bool FindDeviceByAddress(const nsACString& aAddress,
+                           uint32_t& aIndex);
 
   void MarkAllDevicesUnknown();
   void ClearUnknownDevices();
   void ClearDevices();
 
   // preferences
   nsresult OnDiscoveryChanged(bool aEnabled);
   nsresult OnDiscoveryTimeoutChanged(uint32_t aTimeoutMs);
--- a/dom/presentation/provider/TCPPresentationServer.js
+++ b/dom/presentation/provider/TCPPresentationServer.js
@@ -9,18 +9,18 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 
 const DEBUG = Services.prefs.getBoolPref("dom.presentation.tcp_server.debug");
 function log(aMsg) {
   dump("-*- TCPPresentationServer.js: " + aMsg + "\n");
 }
 
-function TCPDeviceInfo(aHost, aPort, aId) {
-  this.host = aHost;
+function TCPDeviceInfo(aAddress, aPort, aId) {
+  this.address = aAddress;
   this.port = aPort;
   this.id = aId;
 }
 
 function TCPPresentationServer() {
   this._id = null;
   this._port = 0;
   this._serverSocket = null;
@@ -120,17 +120,17 @@ TCPPresentationServer.prototype = {
 
     let sts = Cc["@mozilla.org/network/socket-transport-service;1"]
                 .getService(Ci.nsISocketTransportService)
 
     let socketTransport;
     try {
       socketTransport = sts.createTransport(null,
                                             0,
-                                            aDeviceInfo.host,
+                                            aDeviceInfo.address,
                                             aDeviceInfo.port,
                                             null);
     } catch (e) {
       DEBUG && log("TCPPresentationServer - createTransport throws: " + e);
       // Pop the exception to |TCPDevice.establishControlChannel|
       throw Cr.NS_ERROR_FAILURE;
     }
     return new TCPControlChannel(this,
@@ -155,17 +155,17 @@ TCPPresentationServer.prototype = {
                                  "receiver",
                                  null // url
                                  );
   },
 
   // Triggered by TCPControlChannel
   onSessionRequest: function(aDeviceInfo, aUrl, aPresentationId, aControlChannel) {
     DEBUG && log("TCPPresentationServer - onSessionRequest: "
-                 + aDeviceInfo.host + ":" + aDeviceInfo.port);
+                 + aDeviceInfo.address + ":" + aDeviceInfo.port);
     this.listener.onSessionRequest(aDeviceInfo,
                                    aUrl,
                                    aPresentationId,
                                    aControlChannel);
     this.releaseControlChannel(aControlChannel);
   },
 
   // nsIServerSocketListener (Triggered by nsIServerSocket.init)
--- a/dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
+++ b/dom/presentation/tests/xpcshell/test_multicast_dns_device_provider.js
@@ -114,16 +114,24 @@ MockDNSServiceInfo.prototype = {
   set host(aHost) {
     this._host = aHost;
   },
 
   get host() {
     return this._host;
   },
 
+  set address(aAddress) {
+    this._address = aAddress;
+  },
+
+  get address() {
+    return this._address;
+  },
+
   set port(aPort) {
     this._port = aPort;
   },
 
   get port() {
     return this._port;
   },
 
@@ -182,16 +190,17 @@ TestPresentationDeviceListener.prototype
     return size;
   }
 };
 
 function createDevice(host, port, serviceName, serviceType, domainName, attributes) {
   let device = new MockDNSServiceInfo();
   device.host = host || "";
   device.port = port || 0;
+  device.address = host || "";
   device.serviceName = serviceName || "";
   device.serviceType = serviceType || "";
   device.domainName = domainName || "";
   device.attributes = attributes || null;
   return device;
 }
 
 function registerService() {
@@ -427,17 +436,17 @@ function handleSessionRequest() {
     },
   };
 
   provider.listener = listener;
 
   let controlChannel = listener.device.establishControlChannel(testUrl, testPresentationId);
 
   Assert.equal(mockServerObj.request.deviceInfo.id, mockDevice.host);
-  Assert.equal(mockServerObj.request.deviceInfo.host, mockDevice.host);
+  Assert.equal(mockServerObj.request.deviceInfo.address, mockDevice.host);
   Assert.equal(mockServerObj.request.deviceInfo.port, mockDevice.port);
   Assert.equal(mockServerObj.request.url, testUrl);
   Assert.equal(mockServerObj.request.presentationId, testPresentationId);
 
   provider.listener = null;
 
   run_next_test();
 }
@@ -500,17 +509,17 @@ function handleOnSessionRequest() {
     }
   };
 
   provider.listener = listener;
 
   const deviceInfo = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsITCPDeviceInfo]),
     id: mockDevice.host,
-    host: mockDevice.host,
+    address: mockDevice.host,
     port: 54321,
   };
 
   const testUrl = "http://example.com";
   const testPresentationId = "test-presentation-id";
   const testControlChannel = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationControlChannel]),
   };
@@ -569,17 +578,17 @@ function handleOnSessionRequestFromUnkno
     }
   };
 
   provider.listener = listener;
 
   const deviceInfo = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsITCPDeviceInfo]),
     id: "unknown-device.local",
-    host: "unknown-device.local",
+    address: "unknown-device.local",
     port: 12345,
   };
 
   const testUrl = "http://example.com";
   const testPresentationId = "test-presentation-id";
   const testControlChannel = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationControlChannel]),
   };
--- a/dom/presentation/tests/xpcshell/test_tcp_control_channel.js
+++ b/dom/presentation/tests/xpcshell/test_tcp_control_channel.js
@@ -67,17 +67,17 @@ function testPresentationServer() {
                                    'presenterControlChannelClose']);
   let controllerControlChannel;
 
   tps.listener = {
 
     onSessionRequest: function(deviceInfo, url, presentationId, controlChannel) {
       controllerControlChannel = controlChannel;
       Assert.equal(deviceInfo.id, tps.id, 'expected device id');
-      Assert.equal(deviceInfo.host, '127.0.0.1', 'expected device host');
+      Assert.equal(deviceInfo.address, '127.0.0.1', 'expected device address');
       Assert.equal(url, 'http://example.com', 'expected url');
       Assert.equal(presentationId, 'testPresentationId', 'expected presentation id');
 
       controllerControlChannel.listener = {
         status: 'created',
         onOffer: function(aOffer) {
           Assert.equal(this.status, 'opened', '1. controllerControlChannel: get offer, send answer');
           this.status = 'onOffer';
@@ -112,17 +112,17 @@ function testPresentationServer() {
       };
     },
 
     QueryInterface: XPCOMUtils.generateQI([Ci.nsITCPPresentationServerListener]),
   };
 
   let presenterDeviceInfo = {
     id: 'presentatorID',
-    host: '127.0.0.1',
+    address: '127.0.0.1',
     port: PRESENTER_CONTROL_CHANNEL_PORT,
     QueryInterface: XPCOMUtils.generateQI([Ci.nsITCPDeviceInfo]),
   };
 
   let presenterControlChannel = tps.requestSession(presenterDeviceInfo,
                                                    'http://example.com',
                                                    'testPresentationId');