Bug 1158029 - Part 2: mDNS XPCOM module using NsdManager. r=mcmanus
authorLiang-Heng Chen <xeonchen@mozilla.com>
Thu, 16 Jul 2015 02:43:00 -0400
changeset 253228 8e092ec5fbbdfbe8cb745ff1ef8a8896378fdbfd
parent 253227 7c4170003ac85eaf2ede125ba60ae1e1809f5f5a
child 253229 67b2c40bbaef3ddc62fcdcaed454253a82a8f93b
push id29063
push userttaubert@mozilla.com
push dateFri, 17 Jul 2015 08:16:37 +0000
treeherdermozilla-central@15155971639c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1158029
milestone42.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 1158029 - Part 2: mDNS XPCOM module using NsdManager. r=mcmanus
dom/presentation/provider/PresentationDeviceProviderModule.cpp
mobile/android/installer/package-manifest.in
netwerk/dns/mdns/libmdns/moz.build
netwerk/dns/mdns/libmdns/nsDNSServiceDiscovery.js
netwerk/dns/mdns/libmdns/nsDNSServiceDiscovery.manifest
--- a/dom/presentation/provider/PresentationDeviceProviderModule.cpp
+++ b/dom/presentation/provider/PresentationDeviceProviderModule.cpp
@@ -23,18 +23,18 @@ static const mozilla::Module::CIDEntry k
 };
 
 static const mozilla::Module::ContractIDEntry kPresentationDeviceProviderContracts[] = {
   { MULTICAST_DNS_PROVIDER_CONTRACT_ID, &kMULTICAST_DNS_PROVIDER_CID },
   { nullptr }
 };
 
 static const mozilla::Module::CategoryEntry kPresentationDeviceProviderCategories[] = {
-#if 0 // defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 16
-  { PRESENTATION_DEVICE_PROVIDER_CATEGORY, "MulticastDNSDeviceProvider", MULTICAST_DNS_PROVIDER_CONTRACT_ID},
+#if defined(MOZ_WIDGET_ANDROID) // || (defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 16)
+  { PRESENTATION_DEVICE_PROVIDER_CATEGORY, "MulticastDNSDeviceProvider", MULTICAST_DNS_PROVIDER_CONTRACT_ID },
 #endif
   { nullptr }
 };
 
 static const mozilla::Module kPresentationDeviceProviderModule = {
   mozilla::Module::kVersion,
   kPresentationDeviceProviderCIDs,
   kPresentationDeviceProviderContracts,
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -316,16 +316,18 @@
 @BINPATH@/components/PermissionPromptService.js
 @BINPATH@/components/PermissionPromptService.manifest
 @BINPATH@/components/fuelApplication.manifest
 @BINPATH@/components/fuelApplication.js
 @BINPATH@/components/WebContentConverter.js
 @BINPATH@/components/BrowserComponents.manifest
 @BINPATH@/components/nsBrowserContentHandler.js
 @BINPATH@/components/nsBrowserGlue.js
+@BINPATH@/components/nsDNSServiceDiscovery.manifest
+@BINPATH@/components/nsDNSServiceDiscovery.js
 @BINPATH@/components/nsSetDefaultBrowser.manifest
 @BINPATH@/components/nsSetDefaultBrowser.js
 @BINPATH@/components/toolkitsearch.manifest
 @BINPATH@/components/nsSearchService.js
 @BINPATH@/components/nsSearchSuggestions.js
 @BINPATH@/components/passwordmgr.manifest
 @BINPATH@/components/nsLoginInfo.js
 @BINPATH@/components/nsLoginManager.js
--- a/netwerk/dns/mdns/libmdns/moz.build
+++ b/netwerk/dns/mdns/libmdns/moz.build
@@ -1,16 +1,21 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    EXTRA_COMPONENTS += [
+        'nsDNSServiceDiscovery.js',
+        'nsDNSServiceDiscovery.manifest',
+    ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['ANDROID_VERSION'] >= '16':
+elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['ANDROID_VERSION'] >= '16':
     UNIFIED_SOURCES += [
         'MDNSResponderOperator.cpp',
         'MDNSResponderReply.cpp',
         'nsDNSServiceDiscovery.cpp',
     ]
 
     CXXFLAGS += [
         '-I%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
new file mode 100644
--- /dev/null
+++ b/netwerk/dns/mdns/libmdns/nsDNSServiceDiscovery.js
@@ -0,0 +1,123 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/MulticastDNS.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const DNSSERVICEDISCOVERY_CID = Components.ID("{f9346d98-f27a-4e89-b744-493843416480}");
+const DNSSERVICEDISCOVERY_CONTRACT_ID = "@mozilla.org/toolkit/components/mdnsresponder/dns-sd;1";
+const DNSSERVICEINFO_CONTRACT_ID = "@mozilla.org/toolkit/components/mdnsresponder/dns-info;1";
+
+function log(aMsg) {
+  dump("-*- nsDNSServiceDiscovery.js : " + aMsg + "\n");
+}
+
+// Helper class to transform return objects to correct type.
+function ListenerWrapper(aListener) {
+  this.listener = aListener;
+}
+
+ListenerWrapper.prototype = {
+  // Helper function for transforming an Object into nsIDNSServiceInfo.
+  makeServiceInfo: function (aServiceInfo) {
+    let serviceInfo = Cc[DNSSERVICEINFO_CONTRACT_ID].createInstance(Ci.nsIDNSServiceInfo);
+
+    for (let name of ['host', 'port', 'serviceName', 'serviceType']) {
+      try {
+        serviceInfo[name] = aServiceInfo[name];
+      } catch (e) {
+        // ignore exceptions
+      }
+    }
+
+    return serviceInfo;
+  },
+
+  /* transparent types */
+  onDiscoveryStarted: function(aServiceType) {
+    this.listener.onDiscoveryStarted(aServiceType);
+  },
+  onDiscoveryStopped: function(aServiceType) {
+    this.listener.onDiscoveryStopped(aServiceType);
+  },
+  onStartDiscoveryFailed: function(aServiceType, aErrorCode) {
+    this.listener.onStartDiscoveryFailed(aServiceType);
+  },
+  onStopDiscoveryFailed: function(aServiceType, aErrorCode) {
+    this.listener.onStopDiscoveryFailed(aServiceType);
+  },
+
+  /* transform types */
+  onServiceFound: function(aServiceInfo) {
+    this.listener.onServiceFound(this.makeServiceInfo(aServiceInfo));
+  },
+  onServiceLost: function(aServiceInfo) {
+    this.listener.onServiceLost(this.makeServiceInfo(aServiceInfo));
+  },
+  onServiceRegistered: function(aServiceInfo) {
+    this.listener.onServiceRegistered(this.makeServiceInfo(aServiceInfo));
+  },
+  onServiceUnregistered: function(aServiceInfo) {
+    this.listener.onServiceUnregistered(this.makeServiceInfo(aServiceInfo));
+  },
+  onServiceResolved: function(aServiceInfo) {
+    this.listener.onServiceResolved(this.makeServiceInfo(aServiceInfo));
+  },
+
+  onRegistrationFailed: function(aServiceInfo, aErrorCode) {
+    this.listener.onRegistrationFailed(this.makeServiceInfo(aServiceInfo), aErrorCode);
+  },
+  onUnregistrationFailed: function(aServiceInfo, aErrorCode) {
+    this.listener.onUnregistrationFailed(this.makeServiceInfo(aServiceInfo), aErrorCode);
+  },
+  onResolveFailed: function(aServiceInfo, aErrorCode) {
+    this.listener.onResolveFailed(this.makeServiceInfo(aServiceInfo), aErrorCode);
+  }
+};
+
+function nsDNSServiceDiscovery() {
+  log("nsDNSServiceDiscovery");
+  this.mdns = new MulticastDNS();
+}
+
+nsDNSServiceDiscovery.prototype = {
+  classID: DNSSERVICEDISCOVERY_CID,
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIDNSServiceDiscovery]),
+
+  startDiscovery: function(aServiceType, aListener) {
+    log("startDiscovery");
+    let listener = new ListenerWrapper(aListener);
+    this.mdns.startDiscovery(aServiceType, listener);
+
+    return {
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable]),
+      cancel: (function() {
+        this.mdns.stopDiscovery(aServiceType, listener);
+      }).bind(this)
+    };
+  },
+
+  registerService: function(aServiceInfo, aListener) {
+    log("registerService");
+    let listener = new ListenerWrapper(aListener);
+    this.mdns.registerService(aServiceInfo, listener);
+
+    return {
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable]),
+      cancel: (function() {
+        this.mdns.unregisterService(aServiceInfo, listener);
+      }).bind(this)
+    };
+  },
+
+  resolveService: function(aServiceInfo, aListener) {
+    log("resolveService");
+    this.mdns.resolveService(aServiceInfo, new ListenerWrapper(aListener));
+  }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDNSServiceDiscovery]);
new file mode 100644
--- /dev/null
+++ b/netwerk/dns/mdns/libmdns/nsDNSServiceDiscovery.manifest
@@ -0,0 +1,3 @@
+# nsDNSServiceDiscovery.js
+component {f9346d98-f27a-4e89-b744-493843416480} nsDNSServiceDiscovery.js
+contract @mozilla.org/toolkit/components/mdnsresponder/dns-sd;1 {f9346d98-f27a-4e89-b744-493843416480}