mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 832936 - Implement mozContacts.getCount. r=gwagner sr=sicking
This commit is contained in:
parent
3111f31203
commit
c2a53b4f53
@ -513,7 +513,7 @@ Contact.prototype = {
|
||||
// ContactManager
|
||||
|
||||
const CONTACTMANAGER_CONTRACTID = "@mozilla.org/contactManager;1";
|
||||
const CONTACTMANAGER_CID = Components.ID("{7bfb6481-f946-4254-afc5-d7fe9f5c45a3}");
|
||||
const CONTACTMANAGER_CID = Components.ID("{8beb3a66-d70a-4111-b216-b8e995ad3aff}");
|
||||
const nsIDOMContactManager = Components.interfaces.nsIDOMContactManager;
|
||||
|
||||
function ContactManager()
|
||||
@ -658,6 +658,13 @@ ContactManager.prototype = {
|
||||
Services.DOMRequest.fireSuccess(req, msg.revision);
|
||||
}
|
||||
break;
|
||||
case "Contacts:Count":
|
||||
if (DEBUG) debug("count: " + msg.count);
|
||||
req = this.getRequest(msg.requestID);
|
||||
if (req) {
|
||||
Services.DOMRequest.fireSuccess(req, msg.count);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
||||
}
|
||||
@ -678,6 +685,7 @@ ContactManager.prototype = {
|
||||
case "find":
|
||||
case "listen":
|
||||
case "revision":
|
||||
case "count":
|
||||
access = "read";
|
||||
break;
|
||||
default:
|
||||
@ -867,6 +875,23 @@ ContactManager.prototype = {
|
||||
return request;
|
||||
},
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
init: function(aWindow) {
|
||||
this.initHelper(aWindow, ["Contacts:Find:Return:OK", "Contacts:Find:Return:KO",
|
||||
"Contacts:Clear:Return:OK", "Contacts:Clear:Return:KO",
|
||||
@ -874,8 +899,8 @@ ContactManager.prototype = {
|
||||
"Contact:Remove:Return:OK", "Contact:Remove:Return:KO",
|
||||
"Contact:Changed",
|
||||
"PermissionPromptHelper:AskPermission:OK",
|
||||
"Contacts:GetAll:Next",
|
||||
"Contacts:Revision"]);
|
||||
"Contacts:GetAll:Next", "Contacts:Revision",
|
||||
"Contacts:Count"]);
|
||||
},
|
||||
|
||||
// Called from DOMRequestIpcHelper
|
||||
|
@ -20,6 +20,6 @@ component {72a5ee28-81d8-4af8-90b3-ae935396cc66} ContactManager.js
|
||||
contract @mozilla.org/contact;1 {72a5ee28-81d8-4af8-90b3-ae935396cc66}
|
||||
category JavaScript-global-constructor mozContact @mozilla.org/contact;1
|
||||
|
||||
component {7bfb6481-f946-4254-afc5-d7fe9f5c45a3} ContactManager.js
|
||||
contract @mozilla.org/contactManager;1 {7bfb6481-f946-4254-afc5-d7fe9f5c45a3}
|
||||
component {8beb3a66-d70a-4111-b216-b8e995ad3aff} ContactManager.js
|
||||
contract @mozilla.org/contactManager;1 {8beb3a66-d70a-4111-b216-b8e995ad3aff}
|
||||
category JavaScript-navigator-property mozContacts @mozilla.org/contactManager;1
|
||||
|
@ -727,7 +727,16 @@ ContactDB.prototype = {
|
||||
this.newTxn("readonly", REVISION_STORE, function (txn, store) {
|
||||
store.get(REVISION_KEY).onsuccess = function (e) {
|
||||
aSuccessCb(e.target.result);
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
getCount: function CDB_getCount(aSuccessCb) {
|
||||
if (DEBUG) debug("getCount");
|
||||
this.newTxn("readonly", STORE_NAME, function (txn, store) {
|
||||
store.count().onsuccess = function (e) {
|
||||
aSuccessCb(e.target.result);
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -29,7 +29,8 @@ let ContactService = {
|
||||
this._messages = ["Contacts:Find", "Contacts:GetAll", "Contacts:GetAll:SendNow",
|
||||
"Contacts:Clear", "Contact:Save",
|
||||
"Contact:Remove", "Contacts:RegisterForMessages",
|
||||
"child-process-shutdown", "Contacts:GetRevision"];
|
||||
"child-process-shutdown", "Contacts:GetRevision",
|
||||
"Contacts:GetCount"];
|
||||
this._children = [];
|
||||
this._cursors = {};
|
||||
this._messages.forEach(function(msgName) {
|
||||
@ -184,6 +185,19 @@ let ContactService = {
|
||||
}
|
||||
);
|
||||
break;
|
||||
case "Contacts:GetCount":
|
||||
if (!this.assertPermission(aMessage, "contacts-read")) {
|
||||
return null;
|
||||
}
|
||||
this._db.getCount(
|
||||
function(count) {
|
||||
mm.sendAsyncMessage("Contacts:Count", {
|
||||
requestID: msg.requestID,
|
||||
count: count
|
||||
});
|
||||
}
|
||||
);
|
||||
break;
|
||||
case "Contacts:RegisterForMessages":
|
||||
if (!aMessage.target.assertPermission("contacts-read")) {
|
||||
return null;
|
||||
|
@ -241,6 +241,15 @@ function checkRevision(revision, msg, then) {
|
||||
revReq.onerror = onFailure;
|
||||
}
|
||||
|
||||
function checkCount(count, msg, then) {
|
||||
var request = navigator.mozContacts.getCount();
|
||||
request.onsuccess = function(e) {
|
||||
is(e.target.result, count, msg);
|
||||
then();
|
||||
};
|
||||
request.onerror = onFailure;
|
||||
}
|
||||
|
||||
var mozContacts = window.navigator.mozContacts;
|
||||
ok(mozContacts, "mozContacts exists");
|
||||
ok("mozContact" in window, "mozContact exists");
|
||||
@ -257,7 +266,9 @@ var steps = [
|
||||
req = mozContacts.clear();
|
||||
req.onsuccess = function () {
|
||||
ok(true, "Deleted the database");
|
||||
checkRevision(1, "Revision was incremented on clear", next);
|
||||
checkCount(0, "No contacts after clear", function() {
|
||||
checkRevision(1, "Revision was incremented on clear", next);
|
||||
});
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
});
|
||||
@ -279,7 +290,9 @@ var steps = [
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
sample_id1 = createResult1.id;
|
||||
checkRevision(2, "Revision was incremented on save", next);
|
||||
checkCount(1, "1 contact after adding empty contact", function() {
|
||||
checkRevision(2, "Revision was incremented on save", next);
|
||||
});
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
@ -990,7 +1003,7 @@ var steps = [
|
||||
req.onsuccess = function () {
|
||||
ok(createResult1.id, "The contact now has an ID.");
|
||||
ok(createResult1.name == properties1.name, "Same Name");
|
||||
next();
|
||||
checkCount(20, "20 contacts in DB", next);
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ interface nsIDOMContact : nsIContactProperties
|
||||
void init(in nsIContactProperties properties); // Workaround BUG 723206
|
||||
};
|
||||
|
||||
[scriptable, uuid(e01ebfe7-e972-4e01-b04b-1d162dc74983)]
|
||||
[scriptable, uuid(8beb3a66-d70a-4111-b216-b8e995ad3aff)]
|
||||
interface nsIDOMContactManager : nsISupports
|
||||
{
|
||||
nsIDOMDOMRequest find(in nsIContactFindOptions options);
|
||||
@ -36,4 +36,6 @@ interface nsIDOMContactManager : nsISupports
|
||||
attribute nsIDOMEventListener oncontactchange;
|
||||
|
||||
nsIDOMDOMRequest getRevision();
|
||||
|
||||
nsIDOMDOMRequest getCount();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user