具体的なコードを見てみる(2)
• Chromeプロセスで動いているContactsServiceが 'Contacts:Find'メッセージを
受信すると
receiveMessage: function(aMessage) {
if (DEBUG) debug("receiveMessage " + aMessage.name);
let mm = aMessage.target;
let msg = aMessage.data;
let cursorList;
switch (aMessage.name) {
case "Contacts:Find":
具体的なコードを見てみる(1)
• パーミッションチェック
• チェックがallowならsendAsyncMessageで'Contacts:GetAll' メッセージを投げる
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;
},
15.
具体的なコードを見てみる(2)
• Parentプロセスで動いているContactsServiceが 'Contacts:GetAll'メッセージを
受信すると
receiveMessage: function(aMessage) {
if (DEBUG) debug("receiveMessage " + aMessage.name);
let mm = aMessage.target;
let msg = aMessage.data;
let cursorList;
switch (aMessage.name) {
(snip)
case "Contacts:GetAll":
16.
具体的なコードを見てみる(3)
• ContactDBを検索
• ContactDBのカーソルが回るたびにChildプロセスに'Contacts:GetALl:Next' メッ
セージを送信する
this._db.getAll(
function(aContacts) {
try {
mm.sendAsyncMessage("Contacts:GetAll:Next",
{cursorId: msg.cursorId, contacts: aContacts});
if (aContacts === null) {
let cursorList = this._cursors.get(mm);
let index = cursorList.indexOf(msg.cursorId);
cursorList.splice(index, 1);
}
} catch (e) {
if (DEBUG) debug("Child is dead, DB should stop sending contacts");
throw e;
}
}.bind(this),