2012-02-28 22:01:48 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-07-03 18:00:53 +00:00
|
|
|
"use strict";
|
2012-02-28 22:01:48 +00:00
|
|
|
|
2013-06-27 08:25:40 +00:00
|
|
|
let DEBUG = false;
|
|
|
|
|
|
|
|
function updateDebug(aResult) {
|
|
|
|
DEBUG = !!aResult;
|
|
|
|
}
|
|
|
|
|
2012-08-22 21:34:57 +00:00
|
|
|
function debug(s) { dump("-*- ContactManager: " + s + "\n"); }
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-03-07 21:45:24 +00:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
|
|
|
|
2012-04-02 23:39:57 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(Services, "DOMRequest", function() {
|
2012-03-07 21:45:24 +00:00
|
|
|
return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
|
|
|
|
});
|
|
|
|
|
2013-04-17 11:51:51 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "pm",
|
|
|
|
"@mozilla.org/permissionmanager;1",
|
|
|
|
"nsIPermissionManager");
|
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsIMessageSender");
|
2012-02-28 22:01:48 +00:00
|
|
|
|
2013-06-27 08:25:40 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
|
|
|
|
"@mozilla.org/settingsService;1",
|
|
|
|
"nsISettingsService");
|
|
|
|
|
2013-03-27 22:24:15 +00:00
|
|
|
const CONTACTS_SENDMORE_MINIMUM = 5;
|
|
|
|
|
2013-04-05 19:22:00 +00:00
|
|
|
function stringOrBust(aObj) {
|
|
|
|
if (typeof aObj != "string") {
|
|
|
|
if (DEBUG) debug("Field is not a string and was ignored.");
|
|
|
|
return undefined;
|
|
|
|
} else {
|
|
|
|
return aObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sanitizeStringArray(aArray) {
|
|
|
|
if (!Array.isArray(aArray)) {
|
|
|
|
aArray = [aArray];
|
|
|
|
}
|
|
|
|
return aArray.map(stringOrBust).filter(function(el) { return el != undefined; });
|
|
|
|
}
|
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
const nsIClassInfo = Ci.nsIClassInfo;
|
2013-06-14 17:15:57 +00:00
|
|
|
const CONTACTPROPERTIES_CID = Components.ID("{35ad8a4e-9486-44b6-883d-550f14635e49}");
|
2013-04-10 23:09:10 +00:00
|
|
|
const nsIContactProperties = Ci.nsIContactProperties;
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
// ContactProperties is not directly instantiated. It is used as interface.
|
|
|
|
|
2012-08-22 21:34:57 +00:00
|
|
|
function ContactProperties(aProp) { if (DEBUG) debug("ContactProperties Constructor"); }
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
ContactProperties.prototype = {
|
|
|
|
|
|
|
|
classID : CONTACTPROPERTIES_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTPROPERTIES_CID,
|
|
|
|
contractID:"@mozilla.org/contactProperties;1",
|
|
|
|
classDescription: "ContactProperties",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactProperties],
|
2012-02-28 22:01:48 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIContactProperties])
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//ContactAddress
|
|
|
|
|
|
|
|
const CONTACTADDRESS_CONTRACTID = "@mozilla.org/contactAddress;1";
|
2013-04-27 15:28:53 +00:00
|
|
|
const CONTACTADDRESS_CID = Components.ID("{9cbfa81c-bcab-4ca9-b0d2-f4318f295e33}");
|
2013-04-10 23:09:10 +00:00
|
|
|
const nsIContactAddress = Components.interfaces.nsIContactAddress;
|
2012-02-28 22:01:48 +00:00
|
|
|
|
2013-04-27 15:28:53 +00:00
|
|
|
function ContactAddress(aType, aStreetAddress, aLocality, aRegion, aPostalCode, aCountryName, aPref) {
|
2013-04-05 19:22:00 +00:00
|
|
|
this.type = sanitizeStringArray(aType);
|
|
|
|
this.streetAddress = stringOrBust(aStreetAddress);
|
|
|
|
this.locality = stringOrBust(aLocality);
|
|
|
|
this.region = stringOrBust(aRegion);
|
|
|
|
this.postalCode = stringOrBust(aPostalCode);
|
|
|
|
this.countryName = stringOrBust(aCountryName);
|
2013-04-27 15:28:53 +00:00
|
|
|
this.pref = aPref;
|
2012-02-28 22:01:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ContactAddress.prototype = {
|
2012-08-22 17:56:25 +00:00
|
|
|
__exposedProps__: {
|
|
|
|
type: 'rw',
|
|
|
|
streetAddress: 'rw',
|
|
|
|
locality: 'rw',
|
|
|
|
region: 'rw',
|
|
|
|
postalCode: 'rw',
|
2013-06-13 22:43:30 +00:00
|
|
|
countryName: 'rw',
|
|
|
|
pref: 'rw'
|
2012-08-22 17:56:25 +00:00
|
|
|
},
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
classID : CONTACTADDRESS_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTADDRESS_CID,
|
|
|
|
contractID: CONTACTADDRESS_CONTRACTID,
|
|
|
|
classDescription: "ContactAddress",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactAddress],
|
2012-02-28 22:01:48 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIContactAddress])
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
//ContactField
|
2012-07-03 18:00:53 +00:00
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
const CONTACTFIELD_CONTRACTID = "@mozilla.org/contactField;1";
|
2013-04-27 15:28:53 +00:00
|
|
|
const CONTACTFIELD_CID = Components.ID("{ad19a543-69e4-44f0-adfa-37c011556bc1}");
|
2013-04-10 23:09:10 +00:00
|
|
|
const nsIContactField = Components.interfaces.nsIContactField;
|
2012-07-03 18:00:53 +00:00
|
|
|
|
2013-04-27 15:28:53 +00:00
|
|
|
function ContactField(aType, aValue, aPref) {
|
2013-04-05 19:22:00 +00:00
|
|
|
this.type = sanitizeStringArray(aType);
|
|
|
|
this.value = stringOrBust(aValue);
|
2013-04-27 15:28:53 +00:00
|
|
|
this.pref = aPref;
|
2012-07-03 18:00:53 +00:00
|
|
|
};
|
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
ContactField.prototype = {
|
2012-08-22 17:56:25 +00:00
|
|
|
__exposedProps__: {
|
|
|
|
type: 'rw',
|
2013-06-13 22:43:30 +00:00
|
|
|
value: 'rw',
|
|
|
|
pref: 'rw'
|
2012-08-22 17:56:25 +00:00
|
|
|
},
|
2012-07-03 18:00:53 +00:00
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
classID : CONTACTFIELD_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTFIELD_CID,
|
|
|
|
contractID: CONTACTFIELD_CONTRACTID,
|
|
|
|
classDescription: "ContactField",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactField],
|
2012-07-03 18:00:53 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIContactField])
|
2012-07-03 18:00:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
//ContactTelField
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
const CONTACTTELFIELD_CONTRACTID = "@mozilla.org/contactTelField;1";
|
2013-04-10 23:09:10 +00:00
|
|
|
const CONTACTTELFIELD_CID = Components.ID("{4d42c5a9-ea5d-4102-80c3-40cc986367ca}");
|
|
|
|
const nsIContactTelField = Components.interfaces.nsIContactTelField;
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2013-04-27 15:28:53 +00:00
|
|
|
function ContactTelField(aType, aValue, aCarrier, aPref) {
|
2013-04-05 19:22:00 +00:00
|
|
|
this.type = sanitizeStringArray(aType);
|
|
|
|
this.value = stringOrBust(aValue);
|
|
|
|
this.carrier = stringOrBust(aCarrier);
|
2013-04-27 15:28:53 +00:00
|
|
|
this.pref = aPref;
|
2012-05-11 04:51:48 +00:00
|
|
|
};
|
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
ContactTelField.prototype = {
|
2012-08-22 17:56:25 +00:00
|
|
|
__exposedProps__: {
|
|
|
|
type: 'rw',
|
|
|
|
value: 'rw',
|
2013-06-13 22:43:30 +00:00
|
|
|
carrier: 'rw',
|
|
|
|
pref: 'rw'
|
2012-08-22 17:56:25 +00:00
|
|
|
},
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2012-08-15 23:42:08 +00:00
|
|
|
classID : CONTACTTELFIELD_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTTELFIELD_CID,
|
|
|
|
contractID: CONTACTTELFIELD_CONTRACTID,
|
|
|
|
classDescription: "ContactTelField",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactTelField],
|
2012-05-11 04:51:48 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIContactTelField])
|
2012-05-11 04:51:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 12:05:51 +00:00
|
|
|
//ContactFindSortOptions
|
|
|
|
|
|
|
|
const CONTACTFINDSORTOPTIONS_CONTRACTID = "@mozilla.org/contactFindSortOptions;1"
|
2013-04-10 23:09:10 +00:00
|
|
|
const CONTACTFINDSORTOPTIONS_CID = Components.ID("{0a5b1fab-70da-46dd-b902-619904d920c2}");
|
|
|
|
const nsIContactFindSortOptions = Ci.nsIContactFindSortOptions;
|
2013-02-03 12:05:51 +00:00
|
|
|
|
|
|
|
function ContactFindSortOptions () { }
|
|
|
|
|
|
|
|
ContactFindSortOptions.prototype = {
|
|
|
|
classID: CONTACTFINDSORTOPTIONS_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: CONTACTFINDSORTOPTIONS_CID,
|
|
|
|
contractID: CONTACTFINDSORTOPTIONS_CONTRACTID,
|
|
|
|
classDescription: "ContactFindSortOptions",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactFindSortOptions],
|
2013-02-03 12:05:51 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([nsIContactFindSortOptions])
|
2013-02-03 12:05:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
//ContactFindOptions
|
|
|
|
|
|
|
|
const CONTACTFINDOPTIONS_CONTRACTID = "@mozilla.org/contactFindOptions;1";
|
2013-04-10 23:09:10 +00:00
|
|
|
const CONTACTFINDOPTIONS_CID = Components.ID("{28ce07d0-45d9-4b7a-8843-521df4edd8bc}");
|
|
|
|
const nsIContactFindOptions = Components.interfaces.nsIContactFindOptions;
|
2012-02-28 22:01:48 +00:00
|
|
|
|
2012-04-02 23:39:57 +00:00
|
|
|
function ContactFindOptions() { };
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
ContactFindOptions.prototype = {
|
|
|
|
|
|
|
|
classID : CONTACTFINDOPTIONS_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTFINDOPTIONS_CID,
|
|
|
|
contractID: CONTACTFINDOPTIONS_CONTRACTID,
|
|
|
|
classDescription: "ContactFindOptions",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIContactFindSortOptions,
|
|
|
|
nsIContactFindOptions],
|
2012-02-28 22:01:48 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
2013-02-03 12:05:51 +00:00
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIContactFindSortOptions,
|
|
|
|
nsIContactFindOptions])
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Contact
|
|
|
|
|
|
|
|
const CONTACT_CONTRACTID = "@mozilla.org/contact;1";
|
2013-04-10 23:09:10 +00:00
|
|
|
const CONTACT_CID = Components.ID("{72a5ee28-81d8-4af8-90b3-ae935396cc66}");
|
2012-02-28 22:01:48 +00:00
|
|
|
const nsIDOMContact = Components.interfaces.nsIDOMContact;
|
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
function checkBlobArray(aBlob) {
|
|
|
|
if (Array.isArray(aBlob)) {
|
|
|
|
for (let i = 0; i < aBlob.length; i++) {
|
|
|
|
if (typeof aBlob != 'object') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!(aBlob[i] instanceof Components.interfaces.nsIDOMBlob)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aBlob;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVanillaObj(aObj) {
|
|
|
|
return Object.prototype.toString.call(aObj) == "[object Object]";
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateArrayField(data, createCb) {
|
|
|
|
if (data) {
|
|
|
|
data = Array.isArray(data) ? data : [data];
|
|
|
|
let filtered = [];
|
|
|
|
for (let obj of data) {
|
|
|
|
if (obj && isVanillaObj(obj)) {
|
|
|
|
filtered.push(createCb(obj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-02-01 20:44:55 +00:00
|
|
|
function Contact() { };
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
Contact.prototype = {
|
2012-08-22 17:56:25 +00:00
|
|
|
__exposedProps__: {
|
2012-09-13 04:02:30 +00:00
|
|
|
id: 'rw',
|
|
|
|
updated: 'rw',
|
|
|
|
published: 'rw',
|
2012-08-22 17:56:25 +00:00
|
|
|
name: 'rw',
|
|
|
|
honorificPrefix: 'rw',
|
|
|
|
givenName: 'rw',
|
|
|
|
additionalName: 'rw',
|
|
|
|
familyName: 'rw',
|
|
|
|
honorificSuffix: 'rw',
|
|
|
|
nickname: 'rw',
|
|
|
|
email: 'rw',
|
|
|
|
photo: 'rw',
|
|
|
|
url: 'rw',
|
|
|
|
category: 'rw',
|
|
|
|
adr: 'rw',
|
|
|
|
tel: 'rw',
|
|
|
|
org: 'rw',
|
|
|
|
jobTitle: 'rw',
|
|
|
|
bday: 'rw',
|
|
|
|
note: 'rw',
|
|
|
|
impp: 'rw',
|
|
|
|
anniversary: 'rw',
|
|
|
|
sex: 'rw',
|
2013-06-14 17:15:57 +00:00
|
|
|
genderIdentity: 'rw',
|
|
|
|
key: 'rw',
|
2012-08-22 17:56:25 +00:00
|
|
|
},
|
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
set name(aName) {
|
|
|
|
this._name = sanitizeStringArray(aName);
|
|
|
|
},
|
2013-04-05 19:22:00 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get name() {
|
|
|
|
return this._name;
|
|
|
|
},
|
2013-04-05 19:22:00 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
set honorificPrefix(aHonorificPrefix) {
|
|
|
|
this._honorificPrefix = sanitizeStringArray(aHonorificPrefix);
|
|
|
|
},
|
2012-07-03 18:00:53 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get honorificPrefix() {
|
|
|
|
return this._honorificPrefix;
|
|
|
|
},
|
|
|
|
|
|
|
|
set givenName(aGivenName) {
|
|
|
|
this._givenName = sanitizeStringArray(aGivenName);
|
|
|
|
},
|
|
|
|
|
|
|
|
get givenName() {
|
|
|
|
return this._givenName;
|
|
|
|
},
|
|
|
|
|
|
|
|
set additionalName(aAdditionalName) {
|
|
|
|
this._additionalName = sanitizeStringArray(aAdditionalName);
|
|
|
|
},
|
|
|
|
|
|
|
|
get additionalName() {
|
|
|
|
return this._additionalName;
|
|
|
|
},
|
|
|
|
|
|
|
|
set familyName(aFamilyName) {
|
|
|
|
this._familyName = sanitizeStringArray(aFamilyName);
|
|
|
|
},
|
|
|
|
|
|
|
|
get familyName() {
|
|
|
|
return this._familyName;
|
|
|
|
},
|
|
|
|
|
|
|
|
set honorificSuffix(aHonorificSuffix) {
|
|
|
|
this._honorificSuffix = sanitizeStringArray(aHonorificSuffix);
|
|
|
|
},
|
|
|
|
|
|
|
|
get honorificSuffix() {
|
|
|
|
return this._honorificSuffix;
|
|
|
|
},
|
|
|
|
|
|
|
|
set nickname(aNickname) {
|
|
|
|
this._nickname = sanitizeStringArray(aNickname);
|
|
|
|
},
|
|
|
|
|
|
|
|
get nickname() {
|
|
|
|
return this._nickname;
|
|
|
|
},
|
|
|
|
|
|
|
|
set photo(aPhoto) {
|
|
|
|
this._photo = checkBlobArray(aPhoto);
|
|
|
|
},
|
|
|
|
|
|
|
|
get photo() {
|
|
|
|
return this._photo;
|
|
|
|
},
|
|
|
|
|
|
|
|
set category(aCategory) {
|
|
|
|
this._category = sanitizeStringArray(aCategory);
|
|
|
|
},
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return this._category;
|
|
|
|
},
|
|
|
|
|
|
|
|
set email(aEmail) {
|
|
|
|
this._email = validateArrayField(aEmail, function(email) {
|
|
|
|
return new ContactField(email.type, email.value, email.pref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
get email() {
|
|
|
|
return this._email;
|
|
|
|
},
|
|
|
|
|
|
|
|
set adr(aAdr) {
|
|
|
|
this._adr = validateArrayField(aAdr, function(adr) {
|
|
|
|
return new ContactAddress(adr.type, adr.streetAddress, adr.locality,
|
|
|
|
adr.region, adr.postalCode, adr.countryName,
|
|
|
|
adr.pref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
get adr() {
|
|
|
|
return this._adr;
|
|
|
|
},
|
|
|
|
|
|
|
|
set tel(aTel) {
|
|
|
|
this._tel = validateArrayField(aTel, function(tel) {
|
|
|
|
return new ContactTelField(tel.type, tel.value, tel.carrier, tel.pref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
get tel() {
|
|
|
|
return this._tel;
|
|
|
|
},
|
|
|
|
|
|
|
|
set impp(aImpp) {
|
|
|
|
this._impp = validateArrayField(aImpp, function(impp) {
|
|
|
|
return new ContactField(impp.type, impp.value, impp.pref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
get impp() {
|
|
|
|
return this._impp;
|
|
|
|
},
|
|
|
|
|
|
|
|
set url(aUrl) {
|
|
|
|
this._url = validateArrayField(aUrl, function(url) {
|
|
|
|
return new ContactField(url.type, url.value, url.pref);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
get url() {
|
|
|
|
return this._url;
|
|
|
|
},
|
|
|
|
|
|
|
|
set org(aOrg) {
|
|
|
|
this._org = sanitizeStringArray(aOrg);
|
|
|
|
},
|
|
|
|
|
|
|
|
get org() {
|
|
|
|
return this._org;
|
|
|
|
},
|
|
|
|
|
|
|
|
set jobTitle(aJobTitle) {
|
|
|
|
this._jobTitle = sanitizeStringArray(aJobTitle);
|
|
|
|
},
|
|
|
|
|
|
|
|
get jobTitle() {
|
|
|
|
return this._jobTitle;
|
|
|
|
},
|
|
|
|
|
|
|
|
set note(aNote) {
|
|
|
|
this._note = sanitizeStringArray(aNote);
|
|
|
|
},
|
|
|
|
|
|
|
|
get note() {
|
|
|
|
return this._note;
|
|
|
|
},
|
|
|
|
|
|
|
|
set bday(aBday) {
|
2013-06-13 22:43:30 +00:00
|
|
|
if (aBday && aBday.constructor.name === "Date") {
|
2013-06-12 20:48:20 +00:00
|
|
|
this._bday = aBday;
|
|
|
|
} else if (typeof aBday === "string" || typeof aBday === "number") {
|
2013-06-04 01:50:31 +00:00
|
|
|
this._bday = new Date(aBday);
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
2013-06-04 01:50:31 +00:00
|
|
|
},
|
2012-02-28 22:01:48 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get bday() {
|
|
|
|
return this._bday;
|
|
|
|
},
|
|
|
|
|
|
|
|
set anniversary(aAnniversary) {
|
2013-06-13 22:43:30 +00:00
|
|
|
if (aAnniversary && aAnniversary.constructor.name === "Date") {
|
2013-06-12 20:48:20 +00:00
|
|
|
this._anniversary = aAnniversary;
|
|
|
|
} else if (typeof aAnniversary === "string" || typeof aAnniversary === "number") {
|
2013-06-04 01:50:31 +00:00
|
|
|
this._anniversary = new Date(aAnniversary);
|
2012-05-11 04:51:48 +00:00
|
|
|
}
|
2013-06-04 01:50:31 +00:00
|
|
|
},
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get anniversary() {
|
|
|
|
return this._anniversary;
|
|
|
|
},
|
|
|
|
|
|
|
|
set sex(aSex) {
|
|
|
|
if (aSex !== "undefined") {
|
|
|
|
this._sex = aSex;
|
2012-08-15 23:42:08 +00:00
|
|
|
} else {
|
2013-06-04 01:50:31 +00:00
|
|
|
this._sex = null;
|
2012-08-15 23:42:08 +00:00
|
|
|
}
|
2013-06-04 01:50:31 +00:00
|
|
|
},
|
2012-08-15 23:42:08 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get sex() {
|
|
|
|
return this._sex;
|
|
|
|
},
|
|
|
|
|
|
|
|
set genderIdentity(aGenderIdentity) {
|
|
|
|
if (aGenderIdentity !== "undefined") {
|
|
|
|
this._genderIdentity = aGenderIdentity;
|
2012-08-15 23:42:08 +00:00
|
|
|
} else {
|
2013-06-04 01:50:31 +00:00
|
|
|
this._genderIdentity = null;
|
2012-08-15 23:42:08 +00:00
|
|
|
}
|
2013-06-04 01:50:31 +00:00
|
|
|
},
|
2012-08-15 23:42:08 +00:00
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
get genderIdentity() {
|
|
|
|
return this._genderIdentity;
|
|
|
|
},
|
|
|
|
|
2013-06-14 17:15:57 +00:00
|
|
|
set key(aKey) {
|
|
|
|
this._key = sanitizeStringArray(aKey);
|
|
|
|
},
|
|
|
|
|
|
|
|
get key() {
|
|
|
|
return this._key;
|
|
|
|
},
|
|
|
|
|
2013-06-04 01:50:31 +00:00
|
|
|
init: function init(aProp) {
|
|
|
|
this.name = aProp.name;
|
|
|
|
this.honorificPrefix = aProp.honorificPrefix;
|
|
|
|
this.givenName = aProp.givenName;
|
|
|
|
this.additionalName = aProp.additionalName;
|
|
|
|
this.familyName = aProp.familyName;
|
|
|
|
this.honorificSuffix = aProp.honorificSuffix;
|
|
|
|
this.nickname = aProp.nickname;
|
|
|
|
this.email = aProp.email;
|
|
|
|
this.photo = aProp.photo;
|
|
|
|
this.url = aProp.url;
|
|
|
|
this.category = aProp.category;
|
|
|
|
this.adr = aProp.adr;
|
|
|
|
this.tel = aProp.tel;
|
|
|
|
this.org = aProp.org;
|
|
|
|
this.jobTitle = aProp.jobTitle;
|
|
|
|
this.bday = aProp.bday;
|
|
|
|
this.note = aProp.note;
|
|
|
|
this.impp = aProp.impp;
|
|
|
|
this.anniversary = aProp.anniversary;
|
|
|
|
this.sex = aProp.sex;
|
|
|
|
this.genderIdentity = aProp.genderIdentity;
|
2013-06-14 17:15:57 +00:00
|
|
|
this.key = aProp.key;
|
2012-02-28 22:01:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get published () {
|
|
|
|
return this._published;
|
|
|
|
},
|
|
|
|
|
|
|
|
set published(aPublished) {
|
|
|
|
this._published = aPublished;
|
|
|
|
},
|
|
|
|
|
|
|
|
get updated () {
|
|
|
|
return this._updated;
|
|
|
|
},
|
2012-05-11 04:51:48 +00:00
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
set updated(aUpdated) {
|
|
|
|
this._updated = aUpdated;
|
|
|
|
},
|
|
|
|
|
|
|
|
classID : CONTACT_CID,
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACT_CID,
|
|
|
|
contractID: CONTACT_CONTRACTID,
|
|
|
|
classDescription: "Contact",
|
2013-04-10 23:09:10 +00:00
|
|
|
interfaces: [nsIDOMContact, nsIContactProperties],
|
2012-02-28 22:01:48 +00:00
|
|
|
flags: nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
2013-04-10 23:09:10 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIDOMContact, nsIContactProperties])
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContactManager
|
|
|
|
|
|
|
|
const CONTACTMANAGER_CONTRACTID = "@mozilla.org/contactManager;1";
|
2013-06-04 03:45:10 +00:00
|
|
|
const CONTACTMANAGER_CID = Components.ID("{8beb3a66-d70a-4111-b216-b8e995ad3aff}");
|
2012-02-28 22:01:48 +00:00
|
|
|
const nsIDOMContactManager = Components.interfaces.nsIDOMContactManager;
|
|
|
|
|
|
|
|
function ContactManager()
|
|
|
|
{
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("Constructor");
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ContactManager.prototype = {
|
2012-03-07 21:45:24 +00:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2012-05-08 18:42:41 +00:00
|
|
|
_oncontactchange: null,
|
|
|
|
|
|
|
|
set oncontactchange(aCallback) {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("set oncontactchange");
|
2012-08-09 18:34:57 +00:00
|
|
|
let allowCallback = function() {
|
2013-02-01 20:44:55 +00:00
|
|
|
if (!this._oncontactchange) {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:RegisterForMessages");
|
|
|
|
}
|
2012-05-08 18:42:41 +00:00
|
|
|
this._oncontactchange = aCallback;
|
2012-08-09 18:34:57 +00:00
|
|
|
}.bind(this);
|
|
|
|
let cancelCallback = function() {
|
2012-05-08 18:42:41 +00:00
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
2012-08-09 18:34:57 +00:00
|
|
|
}
|
|
|
|
this.askPermission("listen", null, allowCallback, cancelCallback);
|
2012-05-08 18:42:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get oncontactchange() {
|
|
|
|
return this._oncontactchange;
|
|
|
|
},
|
2012-02-28 22:01:48 +00:00
|
|
|
|
|
|
|
_setMetaData: function(aNewContact, aRecord) {
|
|
|
|
aNewContact.id = aRecord.id;
|
|
|
|
aNewContact.published = aRecord.published;
|
|
|
|
aNewContact.updated = aRecord.updated;
|
|
|
|
},
|
|
|
|
|
2013-02-03 12:05:51 +00:00
|
|
|
_convertContact: function CM_convertContact(aContact) {
|
|
|
|
let newContact = new Contact();
|
|
|
|
newContact.init(aContact.properties);
|
|
|
|
this._setMetaData(newContact, aContact);
|
|
|
|
return newContact;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertContacts: function(aContacts) {
|
|
|
|
let contacts = [];
|
2012-02-28 22:01:48 +00:00
|
|
|
for (let i in aContacts) {
|
2013-02-03 12:05:51 +00:00
|
|
|
contacts.push(this._convertContact(aContacts[i]));
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
return contacts;
|
|
|
|
},
|
|
|
|
|
2013-02-25 03:53:55 +00:00
|
|
|
_fireSuccessOrDone: function(aCursor, aResult) {
|
|
|
|
if (aResult == null) {
|
|
|
|
Services.DOMRequest.fireDone(aCursor);
|
|
|
|
} else {
|
|
|
|
Services.DOMRequest.fireSuccess(aCursor, aResult);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-23 11:41:41 +00:00
|
|
|
_pushArray: function(aArr1, aArr2) {
|
|
|
|
aArr1.push.apply(aArr1, aArr2);
|
|
|
|
},
|
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
receiveMessage: function(aMessage) {
|
2013-02-03 12:05:51 +00:00
|
|
|
if (DEBUG) debug("receiveMessage: " + aMessage.name);
|
2012-02-28 22:01:48 +00:00
|
|
|
let msg = aMessage.json;
|
|
|
|
let contacts = msg.contacts;
|
|
|
|
|
2012-08-31 13:54:48 +00:00
|
|
|
let req;
|
2012-02-28 22:01:48 +00:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Contacts:Find:Return:OK":
|
2012-08-31 13:54:48 +00:00
|
|
|
req = this.getRequest(msg.requestID);
|
2012-02-28 22:01:48 +00:00
|
|
|
if (req) {
|
2013-02-03 12:05:51 +00:00
|
|
|
let result = this._convertContacts(contacts);
|
2012-05-08 18:42:41 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req.request, result);
|
2012-02-28 22:01:48 +00:00
|
|
|
} else {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("no request stored!" + msg.requestID);
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-02-03 12:05:51 +00:00
|
|
|
case "Contacts:GetAll:Next":
|
2013-04-18 17:44:38 +00:00
|
|
|
let data = this.getRequest(msg.cursorId);
|
|
|
|
if (!data) {
|
|
|
|
break;
|
|
|
|
}
|
2013-02-23 11:41:41 +00:00
|
|
|
let result = contacts ? this._convertContacts(contacts) : [null];
|
2013-02-25 03:53:55 +00:00
|
|
|
if (data.waitingForNext) {
|
|
|
|
if (DEBUG) debug("cursor waiting for contact, sending");
|
|
|
|
data.waitingForNext = false;
|
2013-02-23 11:41:41 +00:00
|
|
|
let contact = result.shift();
|
|
|
|
this._pushArray(data.cachedContacts, result);
|
2013-03-16 03:40:03 +00:00
|
|
|
this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
|
2013-05-03 16:15:55 +00:00
|
|
|
if (!contact) {
|
|
|
|
this.removeRequest(msg.cursorId);
|
|
|
|
}
|
2013-02-03 12:05:51 +00:00
|
|
|
} else {
|
2013-02-25 03:53:55 +00:00
|
|
|
if (DEBUG) debug("cursor not waiting, saving");
|
2013-02-23 11:41:41 +00:00
|
|
|
this._pushArray(data.cachedContacts, result);
|
2013-02-03 12:05:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-02-28 22:01:48 +00:00
|
|
|
case "Contact:Save:Return:OK":
|
|
|
|
case "Contacts:Clear:Return:OK":
|
|
|
|
case "Contact:Remove:Return:OK":
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
if (req)
|
2012-05-08 18:42:41 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req.request, null);
|
2012-02-28 22:01:48 +00:00
|
|
|
break;
|
|
|
|
case "Contacts:Find:Return:KO":
|
|
|
|
case "Contact:Save:Return:KO":
|
|
|
|
case "Contact:Remove:Return:KO":
|
|
|
|
case "Contacts:Clear:Return:KO":
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
if (req)
|
2012-05-08 18:42:41 +00:00
|
|
|
Services.DOMRequest.fireError(req.request, msg.errorMsg);
|
2012-02-28 22:01:48 +00:00
|
|
|
break;
|
2012-08-09 18:34:57 +00:00
|
|
|
case "PermissionPromptHelper:AskPermission:OK":
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("id: " + msg.requestID);
|
2012-08-09 18:34:57 +00:00
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
if (!req) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
req.allow();
|
|
|
|
} else {
|
|
|
|
req.cancel();
|
|
|
|
}
|
|
|
|
break;
|
2013-02-01 20:44:55 +00:00
|
|
|
case "Contact:Changed":
|
|
|
|
// Fire oncontactchange event
|
|
|
|
if (DEBUG) debug("Contacts:ContactChanged: " + msg.contactID + ", " + msg.reason);
|
|
|
|
if (this._oncontactchange) {
|
|
|
|
let event = new this._window.MozContactChangeEvent("contactchanged", {
|
|
|
|
contactID: msg.contactID,
|
|
|
|
reason: msg.reason
|
|
|
|
});
|
|
|
|
this._oncontactchange.handleEvent(event);
|
|
|
|
}
|
|
|
|
break;
|
2013-04-25 17:15:47 +00:00
|
|
|
case "Contacts:Revision":
|
|
|
|
if (DEBUG) debug("new revision: " + msg.revision);
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
if (req) {
|
|
|
|
Services.DOMRequest.fireSuccess(req, msg.revision);
|
|
|
|
}
|
|
|
|
break;
|
2013-06-04 03:45:10 +00:00
|
|
|
case "Contacts:Count":
|
|
|
|
if (DEBUG) debug("count: " + msg.count);
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
if (req) {
|
|
|
|
Services.DOMRequest.fireSuccess(req, msg.count);
|
|
|
|
}
|
|
|
|
break;
|
2013-02-01 20:44:55 +00:00
|
|
|
default:
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
|
|
|
this.removeRequest(msg.requestID);
|
|
|
|
},
|
|
|
|
|
2012-10-13 18:57:59 +00:00
|
|
|
askPermission: function (aAccess, aRequest, aAllowCallback, aCancelCallback) {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("askPermission for contacts");
|
2012-11-01 00:26:05 +00:00
|
|
|
let access;
|
|
|
|
switch(aAccess) {
|
|
|
|
case "create":
|
|
|
|
access = "create";
|
|
|
|
break;
|
|
|
|
case "update":
|
|
|
|
case "remove":
|
|
|
|
access = "write";
|
|
|
|
break;
|
|
|
|
case "find":
|
|
|
|
case "listen":
|
2013-04-25 17:15:47 +00:00
|
|
|
case "revision":
|
2013-06-04 03:45:10 +00:00
|
|
|
case "count":
|
2012-11-01 00:26:05 +00:00
|
|
|
access = "read";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
access = "unknown";
|
|
|
|
}
|
2013-02-03 12:05:51 +00:00
|
|
|
|
2013-04-17 11:51:51 +00:00
|
|
|
// Shortcut for ALLOW_ACTION so we avoid a parent roundtrip
|
|
|
|
let type = "contacts-" + access;
|
|
|
|
let permValue =
|
|
|
|
pm.testExactPermissionFromPrincipal(this._window.document.nodePrincipal, type);
|
|
|
|
if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
aAllowCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-09 18:34:57 +00:00
|
|
|
let requestID = this.getRequestId({
|
2012-10-13 18:57:59 +00:00
|
|
|
request: aRequest,
|
2012-08-09 18:34:57 +00:00
|
|
|
allow: function() {
|
|
|
|
aAllowCallback();
|
|
|
|
}.bind(this),
|
|
|
|
cancel : function() {
|
|
|
|
if (aCancelCallback) {
|
|
|
|
aCancelCallback()
|
2012-10-13 18:57:59 +00:00
|
|
|
} else if (aRequest) {
|
|
|
|
Services.DOMRequest.fireError(aRequest, "Not Allowed");
|
2012-08-09 18:34:57 +00:00
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
|
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
cpmm.sendAsyncMessage("PermissionPromptHelper:AskPermission", {
|
|
|
|
type: "contacts",
|
2012-11-01 00:26:05 +00:00
|
|
|
access: access,
|
2012-08-09 18:34:57 +00:00
|
|
|
requestID: requestID,
|
|
|
|
origin: principal.origin,
|
|
|
|
appID: principal.appId,
|
|
|
|
browserFlag: principal.isInBrowserElement
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function save(aContact) {
|
2012-02-28 22:01:48 +00:00
|
|
|
let request;
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("save: " + JSON.stringify(aContact) + " :" + aContact.id);
|
2012-08-09 18:34:57 +00:00
|
|
|
let newContact = {};
|
|
|
|
newContact.properties = {
|
|
|
|
name: [],
|
|
|
|
honorificPrefix: [],
|
|
|
|
givenName: [],
|
|
|
|
additionalName: [],
|
|
|
|
familyName: [],
|
|
|
|
honorificSuffix: [],
|
|
|
|
nickname: [],
|
|
|
|
email: [],
|
|
|
|
photo: [],
|
|
|
|
url: [],
|
|
|
|
category: [],
|
|
|
|
adr: [],
|
|
|
|
tel: [],
|
|
|
|
org: [],
|
|
|
|
jobTitle: [],
|
|
|
|
bday: null,
|
|
|
|
note: [],
|
|
|
|
impp: [],
|
|
|
|
anniversary: null,
|
|
|
|
sex: null,
|
2013-06-14 17:15:57 +00:00
|
|
|
genderIdentity: null,
|
|
|
|
key: [],
|
2012-08-09 18:34:57 +00:00
|
|
|
};
|
|
|
|
for (let field in newContact.properties) {
|
|
|
|
newContact.properties[field] = aContact[field];
|
|
|
|
}
|
|
|
|
|
|
|
|
let reason;
|
|
|
|
if (aContact.id == "undefined") {
|
|
|
|
// for example {25c00f01-90e5-c545-b4d4-21E2ddbab9e0} becomes
|
|
|
|
// 25c00f0190e5c545b4d421E2ddbab9e0
|
|
|
|
aContact.id = this._getRandomId().replace('-', '', 'g').replace('{', '').replace('}', '');
|
|
|
|
reason = "create";
|
2012-02-28 22:01:48 +00:00
|
|
|
} else {
|
2012-08-09 18:34:57 +00:00
|
|
|
reason = "update";
|
2012-02-28 22:01:48 +00:00
|
|
|
}
|
2012-08-09 18:34:57 +00:00
|
|
|
|
|
|
|
this._setMetaData(newContact, aContact);
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("send: " + JSON.stringify(newContact));
|
2012-08-09 18:34:57 +00:00
|
|
|
request = this.createRequest();
|
2012-11-01 00:26:05 +00:00
|
|
|
let options = { contact: newContact, reason: reason };
|
2012-08-09 18:34:57 +00:00
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contact:Save", {requestID: this.getRequestId({request: request, reason: reason}), options: options});
|
|
|
|
}.bind(this)
|
|
|
|
this.askPermission(reason, request, allowCallback);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
find: function(aOptions) {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("find! " + JSON.stringify(aOptions));
|
2013-02-03 12:05:51 +00:00
|
|
|
let request = this.createRequest();
|
2012-08-09 18:34:57 +00:00
|
|
|
let options = { findOptions: aOptions };
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:Find", {requestID: this.getRequestId({request: request, reason: "find"}), options: options});
|
|
|
|
}.bind(this)
|
|
|
|
this.askPermission("find", request, allowCallback);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2013-02-03 12:05:51 +00:00
|
|
|
createCursor: function CM_createCursor(aRequest) {
|
2013-02-25 03:53:55 +00:00
|
|
|
let data = {
|
|
|
|
cursor: Services.DOMRequest.createCursor(this._window, function() {
|
|
|
|
this.handleContinue(id);
|
|
|
|
}.bind(this)),
|
|
|
|
cachedContacts: [],
|
|
|
|
waitingForNext: true,
|
|
|
|
};
|
2013-04-18 17:44:38 +00:00
|
|
|
let id = this.getRequestId(data);
|
2013-02-03 12:05:51 +00:00
|
|
|
if (DEBUG) debug("saved cursor id: " + id);
|
2013-02-25 03:53:55 +00:00
|
|
|
return [id, data.cursor];
|
2013-02-03 12:05:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getAll: function CM_getAll(aOptions) {
|
|
|
|
if (DEBUG) debug("getAll: " + JSON.stringify(aOptions));
|
|
|
|
let [cursorId, cursor] = this.createCursor();
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:GetAll", {
|
|
|
|
cursorId: cursorId, findOptions: aOptions});
|
|
|
|
}.bind(this);
|
|
|
|
this.askPermission("find", cursor, allowCallback);
|
|
|
|
return cursor;
|
|
|
|
},
|
|
|
|
|
2013-03-16 03:40:03 +00:00
|
|
|
nextTick: function nextTick(aCallback) {
|
|
|
|
Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
2013-02-03 12:05:51 +00:00
|
|
|
handleContinue: function CM_handleContinue(aCursorId) {
|
|
|
|
if (DEBUG) debug("handleContinue: " + aCursorId);
|
2013-04-18 17:44:38 +00:00
|
|
|
let data = this.getRequest(aCursorId);
|
2013-02-25 03:53:55 +00:00
|
|
|
if (data.cachedContacts.length > 0) {
|
|
|
|
if (DEBUG) debug("contact in cache");
|
2013-02-23 11:41:41 +00:00
|
|
|
let contact = data.cachedContacts.shift();
|
2013-03-16 03:40:03 +00:00
|
|
|
this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
|
2013-05-03 16:15:55 +00:00
|
|
|
if (!contact) {
|
|
|
|
this.removeRequest(aCursorId);
|
|
|
|
} else if (data.cachedContacts.length === CONTACTS_SENDMORE_MINIMUM) {
|
2013-03-27 22:24:15 +00:00
|
|
|
cpmm.sendAsyncMessage("Contacts:GetAll:SendNow", { cursorId: aCursorId });
|
|
|
|
}
|
2013-02-25 03:53:55 +00:00
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("waiting for contact");
|
|
|
|
data.waitingForNext = true;
|
|
|
|
}
|
2013-02-03 12:05:51 +00:00
|
|
|
},
|
|
|
|
|
2012-08-09 18:34:57 +00:00
|
|
|
remove: function removeContact(aRecord) {
|
|
|
|
let request;
|
|
|
|
request = this.createRequest();
|
|
|
|
let options = { id: aRecord.id };
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options});
|
|
|
|
}.bind(this)
|
|
|
|
this.askPermission("remove", request, allowCallback);
|
|
|
|
return request;
|
2012-02-28 22:01:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clear: function() {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("clear");
|
2012-02-28 22:01:48 +00:00
|
|
|
let request;
|
2012-08-09 18:34:57 +00:00
|
|
|
request = this.createRequest();
|
|
|
|
let options = {};
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:Clear", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options});
|
|
|
|
}.bind(this)
|
|
|
|
this.askPermission("remove", request, allowCallback);
|
|
|
|
return request;
|
2012-02-28 22:01:48 +00:00
|
|
|
},
|
|
|
|
|
2013-04-25 17:15:47 +00:00
|
|
|
getRevision: function() {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:GetRevision", {
|
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
});
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
let cancelCallback = function() {
|
|
|
|
Services.DOMRequest.fireError(request);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.askPermission("revision", request, allowCallback, cancelCallback);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2013-06-04 03:45:10 +00:00
|
|
|
getCount: function() {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
|
|
|
let allowCallback = function() {
|
|
|
|
cpmm.sendAsyncMessage("Contacts:GetCount", {
|
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
});
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
let cancelCallback = function() {
|
|
|
|
Services.DOMRequest.fireError(request);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.askPermission("count", request, allowCallback, cancelCallback);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
init: function(aWindow) {
|
2012-03-07 21:45:24 +00:00
|
|
|
this.initHelper(aWindow, ["Contacts:Find:Return:OK", "Contacts:Find:Return:KO",
|
2012-05-11 04:51:48 +00:00
|
|
|
"Contacts:Clear:Return:OK", "Contacts:Clear:Return:KO",
|
|
|
|
"Contact:Save:Return:OK", "Contact:Save:Return:KO",
|
2012-08-09 18:34:57 +00:00
|
|
|
"Contact:Remove:Return:OK", "Contact:Remove:Return:KO",
|
2013-02-01 20:44:55 +00:00
|
|
|
"Contact:Changed",
|
2013-02-03 12:05:51 +00:00
|
|
|
"PermissionPromptHelper:AskPermission:OK",
|
2013-06-04 03:45:10 +00:00
|
|
|
"Contacts:GetAll:Next", "Contacts:Revision",
|
|
|
|
"Contacts:Count"]);
|
2013-06-27 08:25:40 +00:00
|
|
|
|
|
|
|
let lock = gSettingsService.createLock();
|
|
|
|
lock.get("dom.mozContacts.debugging.enabled", {
|
|
|
|
handle: function(aName, aResult) {
|
|
|
|
updateDebug(aResult);
|
|
|
|
},
|
|
|
|
handleError: function(aErrorMessage) {
|
|
|
|
if (DEBUG) debug("Error reading dom.mozContacts.debugging.enabled setting: " + aErrorMessage);
|
|
|
|
}
|
|
|
|
});
|
2012-02-28 22:01:48 +00:00
|
|
|
},
|
|
|
|
|
2012-05-08 18:42:41 +00:00
|
|
|
// Called from DOMRequestIpcHelper
|
|
|
|
uninit: function uninit() {
|
2012-08-22 21:34:57 +00:00
|
|
|
if (DEBUG) debug("uninit call");
|
2012-05-08 18:42:41 +00:00
|
|
|
if (this._oncontactchange)
|
|
|
|
this._oncontactchange = null;
|
|
|
|
},
|
|
|
|
|
2012-02-28 22:01:48 +00:00
|
|
|
classID : CONTACTMANAGER_CID,
|
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsIDOMContactManager, Ci.nsIDOMGlobalPropertyInitializer]),
|
|
|
|
|
|
|
|
classInfo : XPCOMUtils.generateCI({classID: CONTACTMANAGER_CID,
|
|
|
|
contractID: CONTACTMANAGER_CONTRACTID,
|
|
|
|
classDescription: "ContactManager",
|
|
|
|
interfaces: [nsIDOMContactManager],
|
|
|
|
flags: nsIClassInfo.DOM_OBJECT})
|
|
|
|
}
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
|
2013-02-03 12:05:51 +00:00
|
|
|
[Contact, ContactManager, ContactProperties, ContactAddress, ContactField, ContactTelField, ContactFindSortOptions, ContactFindOptions])
|