Bug 1011084 - Implement navigator.mozId with WebIDL; r=bholley r=spenrose, sr=jst

This commit is contained in:
Jed Parsons 2014-05-30 17:06:18 -07:00
Родитель db7404cb44
Коммит b397ed9680
4 изменённых файлов: 122 добавлений и 100 удалений

Просмотреть файл

@ -1,7 +1,6 @@
# nsDOMIdentity.js
component {210853d9-2c97-4669-9761-b1ab9cbf57ef} nsDOMIdentity.js
contract @mozilla.org/dom/identity;1 {210853d9-2c97-4669-9761-b1ab9cbf57ef}
category JavaScript-navigator-property mozId @mozilla.org/dom/identity;1
contract @mozilla.org/identity/manager;1 {210853d9-2c97-4669-9761-b1ab9cbf57ef}
# nsIDService.js (initialization on startup)
component {4e0a0e98-b1d3-4745-a1eb-f815199dd06b} nsIDService.js

Просмотреть файл

@ -46,29 +46,10 @@ const ERRORS = {
"The request() method may only be invoked when handling user input",
};
function nsDOMIdentity(aIdentityInternal) {
this._identityInternal = aIdentityInternal;
function nsDOMIdentity() {
}
nsDOMIdentity.prototype = {
__exposedProps__: {
// Relying Party (RP)
watch: 'r',
request: 'r',
logout: 'r',
get: 'r',
getVerifiedEmail: 'r',
// Provisioning
beginProvisioning: 'r',
genKeyPair: 'r',
registerCertificate: 'r',
raiseProvisioningFailure: 'r',
// Authentication
beginAuthentication: 'r',
completeAuthentication: 'r',
raiseAuthenticationFailure: 'r'
},
// require native events unless syntheticEventsOk is set
get nativeEventsRequired() {
@ -148,7 +129,7 @@ nsDOMIdentity.prototype = {
// broken client to be able to call watch() any more. It's broken.
return;
}
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:RP:Watch",
message,
null,
@ -224,7 +205,7 @@ nsDOMIdentity.prototype = {
}
this._rpCalls++;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:RP:Request",
message,
null,
@ -249,7 +230,7 @@ nsDOMIdentity.prototype = {
return;
}
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:RP:Logout",
message,
null,
@ -337,7 +318,7 @@ nsDOMIdentity.prototype = {
}
this._beginProvisioningCallback = aCallback;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:BeginProvisioning",
this.DOMIdentityMessage(),
null,
@ -358,7 +339,7 @@ nsDOMIdentity.prototype = {
}
this._genKeyPairCallback = aCallback;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:GenKeyPair",
this.DOMIdentityMessage(),
null,
@ -378,7 +359,7 @@ nsDOMIdentity.prototype = {
let message = this.DOMIdentityMessage();
message.cert = aCertificate;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:RegisterCertificate",
message,
null,
@ -398,7 +379,7 @@ nsDOMIdentity.prototype = {
let message = this.DOMIdentityMessage();
message.reason = aReason;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:ProvisioningFailure",
message,
null,
@ -423,7 +404,7 @@ nsDOMIdentity.prototype = {
}
this._beginAuthenticationCallback = aCallback;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:BeginAuthentication",
this.DOMIdentityMessage(),
null,
@ -440,7 +421,7 @@ nsDOMIdentity.prototype = {
}
this._authenticationEnded = true;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:CompleteAuthentication",
this.DOMIdentityMessage(),
null,
@ -458,7 +439,7 @@ nsDOMIdentity.prototype = {
let message = this.DOMIdentityMessage();
message.reason = aReason;
this._identityInternal._mm.sendAsyncMessage(
this._mm.sendAsyncMessage(
"Identity:IDP:AuthenticationFailure",
message,
null,
@ -466,26 +447,6 @@ nsDOMIdentity.prototype = {
);
},
// Private.
_init: function nsDOMIdentity__init(aWindow) {
this._initializeState();
// Store window and origin URI.
this._window = aWindow;
this._origin = aWindow.document.nodePrincipal.origin;
this._appStatus = aWindow.document.nodePrincipal.appStatus;
this._appId = aWindow.document.nodePrincipal.appId;
// Setup identifiers for current window.
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
// We need to inherit the id from the internalIdentity service.
// See comments below in that service's init.
this._id = this._identityInternal._id;
},
/**
* Called during init and shutdown.
*/
@ -503,12 +464,18 @@ nsDOMIdentity.prototype = {
this._beginAuthenticationCallback = null;
},
_receiveMessage: function nsDOMIdentity_receiveMessage(aMessage) {
// nsIMessageListener
receiveMessage: function nsDOMIdentity_receiveMessage(aMessage) {
let msg = aMessage.json;
// Is this message intended for this window?
if (msg.id != this._id) {
return;
}
switch (aMessage.name) {
case "Identity:ResetState":
if (!this._identityInternal._debug) {
if (!this._debug) {
return;
}
this._initializeState();
@ -586,10 +553,6 @@ nsDOMIdentity.prototype = {
}
},
_log: function nsDOMIdentity__log(msg) {
this._identityInternal._log(msg);
},
_callGenKeyPairCallback: function nsDOMIdentity__callGenKeyPairCallback(message) {
// create a pubkey object that works
let chrome_pubkey = JSON.parse(message.publicKey);
@ -676,35 +639,10 @@ nsDOMIdentity.prototype = {
return message;
},
uninit: function DOMIdentity_uninit() {
this._log("nsDOMIdentity uninit() " + this._id);
this._identityInternal._mm.sendAsyncMessage(
"Identity:RP:Unwatch",
{ id: this._id },
null,
this._window.document.nodePrincipal
);
}
};
/**
* Internal functions that shouldn't be exposed to content.
*/
function nsDOMIdentityInternal() {
}
nsDOMIdentityInternal.prototype = {
// nsIMessageListener
receiveMessage: function nsDOMIdentityInternal_receiveMessage(aMessage) {
let msg = aMessage.json;
// Is this message intended for this window?
if (msg.id != this._id) {
return;
}
this._identity._receiveMessage(aMessage);
},
/**
* Internal methods that are not exposed to content.
* See dom/webidl/Identity.webidl for the public interface.
*/
// nsIObserver
observe: function nsDOMIdentityInternal_observe(aSubject, aTopic, aData) {
let window = aSubject.QueryInterface(Ci.nsIDOMWindow);
@ -712,11 +650,10 @@ nsDOMIdentityInternal.prototype = {
return;
}
this._identity.uninit();
this.uninit();
Services.obs.removeObserver(this, "dom-window-destroyed");
this._identity._initializeState();
this._identity = null;
this._initializeState();
// TODO: Also send message to DOMIdentity notifiying window is no longer valid
// ie. in the case that the user closes the auth. window and we need to know.
@ -732,7 +669,8 @@ nsDOMIdentityInternal.prototype = {
this._mm = null;
},
// nsIDOMGlobalPropertyInitializer
// Because we implement nsIDOMGlobalPropertyInitializer, our init() method
// is invoked with content window as its single argument.
init: function nsDOMIdentityInternal_init(aWindow) {
if (Services.prefs.getPrefType(PREF_ENABLED) != Ci.nsIPrefBranch.PREF_BOOL
|| !Services.prefs.getBoolPref(PREF_ENABLED)) {
@ -743,6 +681,7 @@ nsDOMIdentityInternal.prototype = {
Services.prefs.getPrefType(PREF_DEBUG) == Ci.nsIPrefBranch.PREF_BOOL
&& Services.prefs.getBoolPref(PREF_DEBUG);
// Setup identifiers for current window.
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
@ -756,8 +695,13 @@ nsDOMIdentityInternal.prototype = {
// nsDOMIdentity needs to know our _id, so this goes after
// its creation.
this._identity = new nsDOMIdentity(this);
this._identity._init(aWindow);
this._initializeState();
// Store window and origin URI.
this._window = aWindow;
this._origin = aWindow.document.nodePrincipal.origin;
this._appStatus = aWindow.document.nodePrincipal.appStatus;
this._appId = aWindow.document.nodePrincipal.appId;
this._log("init was called from " + aWindow.document.location);
@ -781,10 +725,16 @@ nsDOMIdentityInternal.prototype = {
// Setup observers so we can remove message listeners.
Services.obs.addObserver(this, "dom-window-destroyed", false);
return this._identity;
},
uninit: function DOMIdentity_uninit() {
this._log("nsDOMIdentity uninit() " + this._id);
this._mm.sendAsyncMessage(
"Identity:RP:Unwatch",
{ id: this._id }
);
},
// Private.
_log: function nsDOMIdentityInternal__log(msg) {
if (!this._debug) {
@ -796,9 +746,11 @@ nsDOMIdentityInternal.prototype = {
// Component setup.
classID: Components.ID("{210853d9-2c97-4669-9761-b1ab9cbf57ef}"),
QueryInterface: XPCOMUtils.generateQI(
[Ci.nsIDOMGlobalPropertyInitializer, Ci.nsIMessageListener]
),
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIMessageListener,
Ci.nsIObserver,
Ci.nsIDOMGlobalPropertyInitializer
]),
classInfo: XPCOMUtils.generateCI({
classID: Components.ID("{210853d9-2c97-4669-9761-b1ab9cbf57ef}"),
@ -840,4 +792,4 @@ function assertCorrectCallbacks(aOptions) {
}
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDOMIdentityInternal]);
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDOMIdentity]);

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
callback IdentityOnReadyCallback = void();
callback IdentityOnLoginCallback = void(DOMString identityAssertion);
callback IdentityOnLogoutCallback = void();
callback IdentityOnCancelCallback = void(DOMString? error);
callback IdentityOnErrorCallback = void(DOMString error);
dictionary IdentityWatchOptions {
// Required callback
IdentityOnLoginCallback onlogin;
// Optional parameters
DOMString wantIssuer;
DOMString loggedInUser;
// Optional callbacks
IdentityOnReadyCallback onready;
IdentityOnLogoutCallback onlogout;
IdentityOnErrorCallback onerror;
// Certified apps can specify this
DOMString audience;
};
dictionary IdentityRequestOptions {
// Optional parameters
long refreshAuthentication;
DOMString termsOfService;
DOMString privacyPolicy;
DOMString backgroundColor;
DOMString siteLogo;
DOMString siteName;
DOMString returnTo;
IdentityOnCancelCallback oncancel;
// Certified apps can specify this
DOMString origin;
};
dictionary IdentityGetOptions {
DOMString privacyPolicy;
DOMString termsOfService;
DOMString privacyURL;
DOMString tosURL;
DOMString siteName;
DOMString siteLogo;
};
[JSImplementation="@mozilla.org/identity/manager;1",
NoInterfaceObject,
NavigatorProperty="mozId",
Pref="dom.identity.enabled"]
interface IdentityManager {
void watch(optional IdentityWatchOptions options);
void request(optional IdentityRequestOptions options);
void logout();
[Pref="dom.identity.exposeLegacyGetAPI"]
void get(IdentityOnLoginCallback callback, optional IdentityGetOptions options);
[Pref="dom.identity.exposeLegacyGetVerifiedEmailAPI"]
void getVerifiedEmail(IdentityOnLoginCallback callback);
};

Просмотреть файл

@ -232,6 +232,7 @@ WEBIDL_FILES = [
'IDBRequest.webidl',
'IDBTransaction.webidl',
'IDBVersionChangeEvent.webidl',
'Identity.webidl',
'ImageCapture.webidl',
'ImageData.webidl',
'ImageDocument.webidl',