Bug 988469 - MSISDN verification API for privileged apps. Part 1: DOM API. r=sicking
authorFernando Jiménez <ferjmoreno@gmail.com>
Sat, 07 Jun 2014 19:30:18 +0200
changeset 187463 52bbad182cb31cdfe920c9de6973853967dc0b69
parent 187462 ffa3043bd8eb8de33ece9feb845c0dba6e6ce9c0
child 187464 fe1432e7b89554319c974ebe09ae528f3169b57a
push id44608
push userryanvm@gmail.com
push dateMon, 09 Jun 2014 02:12:46 +0000
treeherdermozilla-inbound@9305a8ec77fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs988469
milestone32.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 988469 - MSISDN verification API for privileged apps. Part 1: DOM API. r=sicking
b2g/installer/package-manifest.in
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/mobileid/interfaces/moz.build
dom/mobileid/interfaces/nsIMobileIdentityService.idl
dom/mobileid/moz.build
dom/mobileid/src/MobileIdentity.js
dom/mobileid/src/MobileIdentity.manifest
dom/mobileid/src/moz.build
dom/moz.build
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -824,16 +824,20 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DL
 @BINPATH@/components/FxAccountsUIGlue.js
 @BINPATH@/components/services_fxaccounts.xpt
 #endif
 
 @BINPATH@/components/DataStore.manifest
 @BINPATH@/components/DataStoreImpl.js
 @BINPATH@/components/dom_datastore.xpt
 
+@BINPATH@/components/MobileIdentity.manifest
+@BINPATH@/components/MobileIdentity.js
+@BINPATH@/components/dom_mobileidentity.xpt
+
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
 #ifdef XP_MACOSX
 @BINPATH@/@DLL_PREFIX@plugin_child_interpose@DLL_SUFFIX@
 #endif
 
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -38,16 +38,19 @@
 #include "mozilla/dom/Telephony.h"
 #include "mozilla/Hal.h"
 #include "nsISiteSpecificUserAgent.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/StaticPtr.h"
 #include "Connection.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "nsGlobalWindow.h"
+#ifdef MOZ_B2G
+#include "nsIMobileIdentityService.h"
+#endif
 #ifdef MOZ_B2G_RIL
 #include "mozilla/dom/IccManager.h"
 #include "mozilla/dom/CellBroadcast.h"
 #include "mozilla/dom/MobileConnectionArray.h"
 #include "mozilla/dom/Voicemail.h"
 #endif
 #include "nsIIdleObserver.h"
 #include "nsIPermissionManager.h"
@@ -1579,16 +1582,40 @@ Navigator::GetMozTelephony(ErrorResult& 
       return nullptr;
     }
     mTelephony = Telephony::Create(mWindow, aRv);
   }
 
   return mTelephony;
 }
 
+#ifdef MOZ_B2G
+already_AddRefed<Promise>
+Navigator::GetMobileIdAssertion(ErrorResult& aRv)
+{
+  if (!mWindow || !mWindow->GetDocShell()) {
+    aRv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIMobileIdentityService> service =
+    do_GetService("@mozilla.org/mobileidentity-service;1");
+  if (!service) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsCOMPtr<nsISupports> promise;
+  aRv = service->GetMobileIdAssertion(mWindow, getter_AddRefs(promise));
+
+  nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
+  return p.forget();
+}
+#endif // MOZ_B2G
+
 #ifdef MOZ_B2G_RIL
 
 MobileConnectionArray*
 Navigator::GetMozMobileConnections(ErrorResult& aRv)
 {
   if (!mMobileConnections) {
     if (!mWindow) {
       aRv.Throw(NS_ERROR_UNEXPECTED);
@@ -1642,17 +1669,16 @@ Navigator::GetMozIccManager(ErrorResult&
     }
     NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
 
     mIccManager = new IccManager(mWindow);
   }
 
   return mIccManager;
 }
-
 #endif // MOZ_B2G_RIL
 
 #ifdef MOZ_GAMEPAD
 void
 Navigator::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads,
                        ErrorResult& aRv)
 {
   if (!mWindow) {
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -210,22 +210,25 @@ public:
   nsIDOMMozMobileMessageManager* GetMozMobileMessage();
   Telephony* GetMozTelephony(ErrorResult& aRv);
   network::Connection* GetConnection(ErrorResult& aRv);
   nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
   void MozSetMessageHandler(const nsAString& aType,
                             systemMessageCallback* aCallback,
                             ErrorResult& aRv);
   bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv);
+#ifdef MOZ_B2G
+  already_AddRefed<Promise> GetMobileIdAssertion(ErrorResult& aRv);
+#endif
 #ifdef MOZ_B2G_RIL
   MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
   CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv);
   Voicemail* GetMozVoicemail(ErrorResult& aRv);
   IccManager* GetMozIccManager(ErrorResult& aRv);
-#endif // MOZ_B2G_RIL
+#endif // MOZ_B2G_RILi
 #ifdef MOZ_GAMEPAD
   void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
 #endif // MOZ_GAMEPAD
 #ifdef MOZ_B2G_FM
   FMRadio* GetMozFMRadio(ErrorResult& aRv);
 #endif
 #ifdef MOZ_B2G_BT
   bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/interfaces/moz.build
@@ -0,0 +1,11 @@
+# -*- 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/.
+
+XPIDL_SOURCES += [
+    'nsIMobileIdentityService.idl',
+]
+
+XPIDL_MODULE = 'dom_mobileidentity'
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/interfaces/nsIMobileIdentityService.idl
@@ -0,0 +1,13 @@
+/* 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"
+
+interface nsIDOMWindow;
+
+[scriptable, uuid(376d3a43-a7f2-4ac0-b196-d83acb3a68cc)]
+interface nsIMobileIdentityService : nsISupports
+{
+  nsISupports getMobileIdAssertion(in nsIDOMWindow window);
+};
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/moz.build
@@ -0,0 +1,7 @@
+# -*- 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/.
+
+PARALLEL_DIRS += ['interfaces', 'src']
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/src/MobileIdentity.js
@@ -0,0 +1,108 @@
+/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* 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/DOMRequestHelper.jsm");
+Cu.import("resource://gre/modules/MobileIdentityCommon.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const MOBILEIDSERVICE_CID =
+  Components.ID("{6ec1806c-d61f-4724-9495-68c26d46dc53}");
+
+const IPC_MSG_NAMES = ["MobileId:GetAssertion:Return:OK",
+                       "MobileId:GetAssertion:Return:KO"];
+
+XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
+                                   "@mozilla.org/childprocessmessagemanager;1",
+                                   "nsIMessageSender");
+
+function MobileIdentityService() {
+}
+
+MobileIdentityService.prototype = {
+  __proto__: DOMRequestIpcHelper.prototype,
+
+  // TODO: this should be handled by DOMRequestIpcHelper. Bug 1020582
+  _windows: {},
+
+  getMobileIdAssertion: function(aWindow) {
+    log.debug("getMobileIdAssertion");
+
+    if (!this.init) {
+      this.initDOMRequestHelper(aWindow, IPC_MSG_NAMES);
+      this.init = true;
+    }
+
+    return new aWindow.Promise(
+      (resolve, reject) => {
+        let promiseId = this.getPromiseResolverId({
+          resolve: resolve,
+          reject: reject
+        });
+
+        this._windows[promiseId] = aWindow;
+
+        cpmm.sendAsyncMessage("MobileId:GetAssertion", {
+          promiseId: promiseId
+        }, null, aWindow.document.nodePrincipal);
+      }
+    );
+  },
+
+  receiveMessage: function(aMessage) {
+    let name = aMessage.name;
+    let msg = aMessage.json;
+
+    log.debug("Received message " + name + ": " + JSON.stringify(msg));
+
+    let promiseId = msg.promiseId || msg.requestID;
+    let promise = this.takePromiseResolver(promiseId);
+    if (!promise) {
+      log.error("Promise not found");
+      return;
+    }
+
+    let _window = this._windows[promiseId];
+    delete this._windows[promiseId];
+    if (!_window) {
+      log.error("No window object found");
+      return;
+    }
+
+    switch (name) {
+      case "MobileId:GetAssertion:Return:OK":
+        if (!msg.result) {
+          promise.reject(new _window.DOMError(ERROR_INTERNAL_UNEXPECTED));
+        }
+
+        // Return the assertion
+        promise.resolve(msg.result);
+        break;
+      case "MobileId:GetAssertion:Return:KO":
+        promise.reject(new _window.DOMError(msg.error || ERROR_UNKNOWN));
+        break;
+    }
+  },
+
+  classID: MOBILEIDSERVICE_CID,
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileIdentityService,
+                                         Ci.nsISupportsWeakReference,
+                                         Ci.nsIObserver]),
+
+  classInfo: XPCOMUtils.generateCI({
+    classID: MOBILEIDSERVICE_CID,
+    contractID: "@mozilla.org/mobileidentity-service;1",
+    interfaces: [Ci.nsIMobileIdentityService],
+    flags: Ci.nsIClassInfo.SINGLETON
+  })
+
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MobileIdentityService]);
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/src/MobileIdentity.manifest
@@ -0,0 +1,2 @@
+component {6ec1806c-d61f-4724-9495-68c26d46dc53} MobileIdentity.js
+contract @mozilla.org/mobileidentity-service;1 {6ec1806c-d61f-4724-9495-68c26d46dc53}
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/src/moz.build
@@ -0,0 +1,10 @@
+# -*- 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/.
+
+EXTRA_COMPONENTS += [
+    'MobileIdentity.js',
+    'MobileIdentity.manifest',
+]
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -108,17 +108,20 @@ if CONFIG['MOZ_PAY']:
 
 if CONFIG['MOZ_GAMEPAD']:
     PARALLEL_DIRS += ['gamepad']
 
 if CONFIG['MOZ_NFC']:
     PARALLEL_DIRS += ['nfc']
 
 if CONFIG['MOZ_B2G']:
-    PARALLEL_DIRS += ['downloads']
+    PARALLEL_DIRS += [
+        'downloads',
+        'mobileid'
+    ]
 
 if CONFIG['MOZ_B2G_BT_API_V2']:
     PARALLEL_DIRS += ['bluetooth2']
 else:
     PARALLEL_DIRS += ['bluetooth']
 
 TEST_DIRS += [
     'tests',