Bug 988469 - MSISDN verification API for privileged apps. Part 1: DOM API. r=sicking

This commit is contained in:
Fernando Jiménez 2014-06-07 19:30:18 +02:00
parent d6a8183dac
commit f421522b73
10 changed files with 190 additions and 3 deletions

View File

@ -829,6 +829,10 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
@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

View File

@ -43,6 +43,9 @@
#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"
@ -1584,6 +1587,30 @@ Navigator::GetMozTelephony(ErrorResult& 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*
@ -1647,7 +1674,6 @@ Navigator::GetMozIccManager(ErrorResult& aRv)
return mIccManager;
}
#endif // MOZ_B2G_RIL
#ifdef MOZ_GAMEPAD

View File

@ -215,12 +215,15 @@ public:
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

View File

@ -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'

View File

@ -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);
};

7
dom/mobileid/moz.build Normal file
View File

@ -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']

View File

@ -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]);

View File

@ -0,0 +1,2 @@
component {6ec1806c-d61f-4724-9495-68c26d46dc53} MobileIdentity.js
contract @mozilla.org/mobileidentity-service;1 {6ec1806c-d61f-4724-9495-68c26d46dc53}

View File

@ -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',
]

View File

@ -113,7 +113,10 @@ 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']