mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 14:44:26 +00:00
Bug 988469 - MSISDN verification API for privileged apps. Part 3: B2G UI Glue. r=vingtetun
This commit is contained in:
parent
3a335772ca
commit
898ba77586
@ -95,3 +95,6 @@ contract @mozilla.org/commandlinehandler/general-startup;1?type=b2goop {e30b0e13
|
||||
category command-line-handler m-b2goop @mozilla.org/commandlinehandler/general-startup;1?type=b2goop
|
||||
#endif
|
||||
|
||||
# MobileIdentityUIGlue.js
|
||||
component {83dbe26a-81f3-4a75-9541-3d0b7ca496b5} MobileIdentityUIGlue.js
|
||||
contract @mozilla.org/services/mobileid-ui-glue;1 {83dbe26a-81f3-4a75-9541-3d0b7ca496b5}
|
||||
|
68
b2g/components/ContentRequestHelper.jsm
Normal file
68
b2g/components/ContentRequestHelper.jsm
Normal file
@ -0,0 +1,68 @@
|
||||
/* 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";
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["ContentRequestHelper"];
|
||||
|
||||
const { interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
||||
"@mozilla.org/uuid-generator;1",
|
||||
"nsIUUIDGenerator");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
||||
"resource://gre/modules/SystemAppProxy.jsm");
|
||||
|
||||
function debug(msg) {
|
||||
// dump("ContentRequestHelper ** " + msg + "\n");
|
||||
}
|
||||
|
||||
this.ContentRequestHelper = function() {
|
||||
}
|
||||
|
||||
ContentRequestHelper.prototype = {
|
||||
|
||||
contentRequest: function(aContentEventName, aChromeEventName,
|
||||
aInternalEventName, aData) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let id = uuidgen.generateUUID().toString();
|
||||
|
||||
SystemAppProxy.addEventListener(aContentEventName,
|
||||
function onContentEvent(result) {
|
||||
SystemAppProxy.removeEventListener(aContentEventName,
|
||||
onContentEvent);
|
||||
let msg = result.detail;
|
||||
if (!msg || !msg.id || msg.id != id) {
|
||||
deferred.reject("InternalErrorWrongContentEvent " +
|
||||
JSON.stringify(msg));
|
||||
SystemAppProxy.removeEventListener(aContentEventName,
|
||||
onContentEvent);
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Got content event " + JSON.stringify(msg));
|
||||
|
||||
if (msg.error) {
|
||||
deferred.reject(msg.error);
|
||||
} else {
|
||||
deferred.resolve(msg.result);
|
||||
}
|
||||
});
|
||||
|
||||
let detail = {
|
||||
eventName: aInternalEventName,
|
||||
id: id,
|
||||
data: aData
|
||||
};
|
||||
debug("Send chrome event " + JSON.stringify(detail));
|
||||
SystemAppProxy._sendCustomEvent(aChromeEventName, detail);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
};
|
@ -6,66 +6,26 @@
|
||||
|
||||
const { interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/FxAccountsCommon.js");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
||||
"@mozilla.org/uuid-generator;1",
|
||||
"nsIUUIDGenerator");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
||||
"resource://gre/modules/SystemAppProxy.jsm");
|
||||
Cu.import("resource://gre/modules/ContentRequestHelper.jsm");
|
||||
|
||||
function FxAccountsUIGlue() {
|
||||
}
|
||||
|
||||
FxAccountsUIGlue.prototype = {
|
||||
|
||||
_contentRequest: function(aEventName, aData) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let id = uuidgen.generateUUID().toString();
|
||||
|
||||
SystemAppProxy.addEventListener("mozFxAccountsRPContentEvent",
|
||||
function onContentEvent(result) {
|
||||
let msg = result.detail;
|
||||
if (!msg || !msg.id || msg.id != id) {
|
||||
deferred.reject("InternalErrorWrongContentEvent");
|
||||
SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
|
||||
onContentEvent);
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("UIGlue got content event " + JSON.stringify(msg));
|
||||
|
||||
if (msg.error) {
|
||||
deferred.reject(msg);
|
||||
} else {
|
||||
deferred.resolve(msg.result);
|
||||
}
|
||||
SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
|
||||
onContentEvent);
|
||||
});
|
||||
|
||||
let detail = {
|
||||
eventName: aEventName,
|
||||
id: id,
|
||||
data: aData
|
||||
};
|
||||
log.debug("Send chrome event " + JSON.stringify(detail));
|
||||
SystemAppProxy._sendCustomEvent("mozFxAccountsUnsolChromeEvent", detail);
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
__proto__: ContentRequestHelper.prototype,
|
||||
|
||||
signInFlow: function() {
|
||||
return this._contentRequest("openFlow");
|
||||
return this.contentRequest("mozFxAccountsRPContentEvent",
|
||||
"mozFxAccountsUnsolChromeEvent",
|
||||
"openFlow");
|
||||
},
|
||||
|
||||
refreshAuthentication: function(aEmail) {
|
||||
return this._contentRequest("refreshAuthentication", {
|
||||
return this.contentRequest("mozFxAccountsRPContentEvent",
|
||||
"mozFxAccountsUnsolChromeEvent",
|
||||
"refreshAuthentication", {
|
||||
email: aEmail
|
||||
});
|
||||
},
|
||||
|
161
b2g/components/MobileIdentityUIGlue.js
Normal file
161
b2g/components/MobileIdentityUIGlue.js
Normal file
@ -0,0 +1,161 @@
|
||||
/* 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 { interfaces: Ci, utils: Cu, classes: Cc } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/ContentRequestHelper.jsm");
|
||||
Cu.import("resource://gre/modules/MobileIdentityCommon.jsm");
|
||||
Cu.import("resource://gre/modules/MobileIdentityUIGlueCommon.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
||||
"@mozilla.org/uuid-generator;1",
|
||||
"nsIUUIDGenerator");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
||||
"resource://gre/modules/SystemAppProxy.jsm");
|
||||
|
||||
const CHROME_EVENT = "mozMobileIdChromeEvent";
|
||||
const CONTENT_EVENT = "mozMobileIdContentEvent";
|
||||
const UNSOLICITED_CONTENT_EVENT = "mozMobileIdUnsolContentEvent";
|
||||
|
||||
function MobileIdentityUIGlue() {
|
||||
SystemAppProxy.addEventListener(UNSOLICITED_CONTENT_EVENT, this);
|
||||
}
|
||||
|
||||
MobileIdentityUIGlue.prototype = {
|
||||
|
||||
__proto__: ContentRequestHelper.prototype,
|
||||
|
||||
_sendChromeEvent: function(aEventName, aData) {
|
||||
SystemAppProxy._sendCustomEvent(CHROME_EVENT, {
|
||||
eventName: aEventName,
|
||||
id: uuidgen.generateUUID().toString(),
|
||||
data: aData
|
||||
});
|
||||
},
|
||||
|
||||
_oncancel: null,
|
||||
|
||||
get oncancel() {
|
||||
return this._oncancel;
|
||||
},
|
||||
|
||||
set oncancel(aCallback) {
|
||||
this._oncancel = aCallback;
|
||||
},
|
||||
|
||||
_onresendcode: null,
|
||||
|
||||
get onresendcode() {
|
||||
return this._onresendcode;
|
||||
},
|
||||
|
||||
set onresendcode(aCallback) {
|
||||
this._onresendcode = aCallback;
|
||||
},
|
||||
|
||||
startFlow: function(aManifestURL, aIccInfo) {
|
||||
let phoneNumberInfo;
|
||||
if (aIccInfo) {
|
||||
phoneNumberInfo = [];
|
||||
for (var i = 0; i < aIccInfo.length; i++) {
|
||||
let iccInfo = aIccInfo[i];
|
||||
phoneNumberInfo.push({
|
||||
primary: iccInfo.primary,
|
||||
msisdn: iccInfo.msisdn,
|
||||
operator: iccInfo.operator,
|
||||
external: iccInfo.external,
|
||||
serviceId: iccInfo.serviceId,
|
||||
mcc: iccInfo.mcc
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this.contentRequest(CONTENT_EVENT,
|
||||
CHROME_EVENT,
|
||||
"onpermissionrequest",
|
||||
{ phoneNumberInfo: phoneNumberInfo || [],
|
||||
manifestURL: aManifestURL })
|
||||
.then(
|
||||
(result) => {
|
||||
if (!result || !result.phoneNumber && !result.serviceId) {
|
||||
return Promise.reject(ERROR_INVALID_PROMPT_RESULT);
|
||||
}
|
||||
|
||||
let promptResult = new MobileIdentityUIGluePromptResult(
|
||||
result.phoneNumber || null,
|
||||
result.prefix || null,
|
||||
result.mcc || null,
|
||||
result.serviceId || null
|
||||
);
|
||||
return promptResult;
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
verificationCodePrompt: function(aRetriesLeft, aTimeout, aTimeLeft) {
|
||||
return this.contentRequest(CONTENT_EVENT,
|
||||
CHROME_EVENT,
|
||||
"onverificationcode",
|
||||
{ retriesLeft: aRetriesLeft,
|
||||
verificationTimeout: aTimeout,
|
||||
verificationTimeoutLeft: aTimeLeft })
|
||||
.then(
|
||||
(result) => {
|
||||
if (!result || !result.verificationCode) {
|
||||
return Promise.reject(ERROR_INVALID_VERIFICATION_CODE);
|
||||
}
|
||||
|
||||
return result.verificationCode;
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
error: function(aError) {
|
||||
log.error("UI error " + aError);
|
||||
this._sendChromeEvent("onerror", {
|
||||
error: aError
|
||||
});
|
||||
},
|
||||
|
||||
verify: function() {
|
||||
this._sendChromeEvent("verify");
|
||||
},
|
||||
|
||||
verified: function(aVerifiedPhoneNumber) {
|
||||
this._sendChromeEvent("onverified", {
|
||||
verifiedPhoneNumber: aVerifiedPhoneNumber
|
||||
});
|
||||
},
|
||||
|
||||
handleEvent: function(aEvent) {
|
||||
let msg = aEvent.detail;
|
||||
if (!msg) {
|
||||
log.warning("Got invalid event");
|
||||
return;
|
||||
}
|
||||
log.debug("Got content event ${}", msg);
|
||||
|
||||
switch(msg.eventName) {
|
||||
case 'cancel':
|
||||
this.oncancel();
|
||||
break;
|
||||
case 'resendcode':
|
||||
this.onresendcode();
|
||||
break;
|
||||
default:
|
||||
log.warning("Invalid event name");
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
classID: Components.ID("{83dbe26a-81f3-4a75-9541-3d0b7ca496b5}"),
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileIdentityUIGlue])
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MobileIdentityUIGlue]);
|
@ -15,6 +15,7 @@ EXTRA_COMPONENTS += [
|
||||
'HelperAppDialog.js',
|
||||
'InterAppCommUIGlue.js',
|
||||
'MailtoProtocolHandler.js',
|
||||
'MobileIdentityUIGlue.js',
|
||||
'PaymentGlue.js',
|
||||
'ProcessGlobal.js',
|
||||
'SmsProtocolHandler.js',
|
||||
@ -43,6 +44,7 @@ if CONFIG['MOZ_UPDATER']:
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
'AlertsHelper.jsm',
|
||||
'ContentRequestHelper.jsm',
|
||||
'ErrorPage.jsm',
|
||||
'SignInToWebsite.jsm',
|
||||
'SystemAppProxy.jsm',
|
||||
|
@ -831,6 +831,7 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
|
||||
|
||||
@BINPATH@/components/MobileIdentity.manifest
|
||||
@BINPATH@/components/MobileIdentity.js
|
||||
@BINPATH@/components/MobileIdentityUIGlue.js
|
||||
@BINPATH@/components/dom_mobileidentity.xpt
|
||||
|
||||
#ifdef MOZ_WEBSPEECH
|
||||
|
Loading…
x
Reference in New Issue
Block a user