Bug 1205237 - Part 2: add PresentationNetworkHelper; r=schien
authorLiang-Heng Chen <xeonchen@mozilla.com>
Sun, 18 Oct 2015 23:06:00 +0200
changeset 302337 6558cc9ebe66b27dbfa8c0db8927e0f92e05f090
parent 302336 1c72eaef7f82f391f1f2448508794a2bef951d62
child 302338 099ca9784468abf17b28816dcff2408f70e5bb75
push id5392
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:08:23 +0000
treeherdermozilla-beta@16ce8562a975 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien
bugs1205237
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 1205237 - Part 2: add PresentationNetworkHelper; r=schien
dom/presentation/PresentationNetworkHelper.js
dom/presentation/PresentationNetworkHelper.manifest
dom/presentation/interfaces/moz.build
dom/presentation/interfaces/nsIPresentationNetworkHelper.idl
dom/presentation/moz.build
mobile/android/installer/package-manifest.in
new file mode 100644
--- /dev/null
+++ b/dom/presentation/PresentationNetworkHelper.js
@@ -0,0 +1,28 @@
+// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
+/* 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, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Messaging.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const NETWORKHELPER_CID = Components.ID("{5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d}");
+
+function PresentationNetworkHelper() {}
+
+PresentationNetworkHelper.prototype = {
+  classID: NETWORKHELPER_CID,
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationNetworkHelper]),
+
+  getWifiIPAddress: function(aListener) {
+    Messaging.sendRequestForResult({type: "Wifi:GetIPAddress"})
+             .then(result => aListener.onGetWifiIPAddress(result),
+                   err => aListener.onError(err));
+  }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PresentationNetworkHelper]);
new file mode 100644
--- /dev/null
+++ b/dom/presentation/PresentationNetworkHelper.manifest
@@ -0,0 +1,3 @@
+# PresentationNetworkHelper.js
+component {5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d} PresentationNetworkHelper.js
+contract @mozilla.org/presentation-device/networkHelper;1 {5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d}
--- a/dom/presentation/interfaces/moz.build
+++ b/dom/presentation/interfaces/moz.build
@@ -13,10 +13,15 @@ XPIDL_SOURCES += [
     'nsIPresentationListener.idl',
     'nsIPresentationRequestUIGlue.idl',
     'nsIPresentationService.idl',
     'nsIPresentationSessionRequest.idl',
     'nsIPresentationSessionTransport.idl',
     'nsITCPPresentationServer.idl',
 ]
 
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    XPIDL_SOURCES += [
+        'nsIPresentationNetworkHelper.idl',
+    ]
+
 XPIDL_MODULE = 'dom_presentation'
 
new file mode 100644
--- /dev/null
+++ b/dom/presentation/interfaces/nsIPresentationNetworkHelper.idl
@@ -0,0 +1,36 @@
+/* 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/. */
+
+#include "nsISupports.idl"
+
+%{C++
+#define PRESENTATION_NETWORK_HELPER_CONTRACTID \
+  "@mozilla.org/presentation-device/networkHelper;1"
+%}
+
+[scriptable, uuid(0a7e134f-ff80-4e73-91e6-12b3134fe568)]
+interface nsIPresentationNetworkHelperListener : nsISupports
+{
+  /**
+   * Called when error occurs.
+   * @param aReason error message.
+   */
+  void onError(in AUTF8String aReason);
+
+  /**
+   * Called when get Wi-Fi IP address.
+   * @param aIPAddress the IP address of Wi-Fi interface.
+   */
+  void onGetWifiIPAddress(in AUTF8String aIPAddress);
+};
+
+[scriptable, uuid(650dc16b-3d9c-49a6-9037-1d6f2d18c90c)]
+interface nsIPresentationNetworkHelper : nsISupports
+{
+  /**
+   * Get IP address of Wi-Fi interface.
+   * @param aListener the callback interface.
+   */
+  void getWifiIPAddress(in nsIPresentationNetworkHelperListener aListener);
+};
--- a/dom/presentation/moz.build
+++ b/dom/presentation/moz.build
@@ -42,16 +42,22 @@ UNIFIED_SOURCES += [
     'PresentationSessionTransport.cpp',
 ]
 
 EXTRA_COMPONENTS += [
     'PresentationDeviceInfoManager.js',
     'PresentationDeviceInfoManager.manifest',
 ]
 
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    EXTRA_COMPONENTS += [
+        'PresentationNetworkHelper.js',
+        'PresentationNetworkHelper.manifest',
+    ]
+
 EXTRA_JS_MODULES += [
     'PresentationDeviceInfoManager.jsm',
 ]
 
 IPDL_SOURCES += [
     'ipc/PPresentation.ipdl',
     'ipc/PPresentationRequest.ipdl'
 ]
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -459,16 +459,18 @@
 
 @BINPATH@/components/Downloads.manifest
 @BINPATH@/components/DownloadLegacy.js
 
 @BINPATH@/components/PresentationDeviceInfoManager.manifest
 @BINPATH@/components/PresentationDeviceInfoManager.js
 @BINPATH@/components/BuiltinProviders.manifest
 @BINPATH@/components/TCPPresentationServer.js
+@BINPATH@/components/PresentationNetworkHelper.js
+@BINPATH@/components/PresentationNetworkHelper.manifest
 
 @BINPATH@/components/PACGenerator.js
 @BINPATH@/components/PACGenerator.manifest
 
 ; Modules
 @BINPATH@/modules/*
 
 #ifdef MOZ_SAFE_BROWSING