Bug 862351 - Don't enqueue messages sent to a different inner window. r=gwagner
authorReuben Morais <reuben.morais@gmail.com>
Thu, 18 Apr 2013 19:44:38 +0200
changeset 129192 d1847d734c77f27ff11050b940f1d349a91f45c8
parent 129191 b390e72c5a543b600f8613650b0ceb0bfe747d96
child 129234 f8d27fe5d7c04b396b6798255b35aa384401e04c
push idunknown
push userunknown
push dateunknown
reviewersgwagner
bugs862351
milestone23.0a1
Bug 862351 - Don't enqueue messages sent to a different inner window. r=gwagner
dom/contacts/ContactManager.js
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -383,18 +383,16 @@ function ContactManager()
 {
   if (DEBUG) debug("Constructor");
 }
 
 ContactManager.prototype = {
   __proto__: DOMRequestIpcHelper.prototype,
   _oncontactchange: null,
 
-  _cursorData: {},
-
   set oncontactchange(aCallback) {
     if (DEBUG) debug("set oncontactchange");
     let allowCallback = function() {
       if (!this._oncontactchange) {
         cpmm.sendAsyncMessage("Contacts:RegisterForMessages");
       }
       this._oncontactchange = aCallback;
     }.bind(this);
@@ -453,17 +451,20 @@ ContactManager.prototype = {
         if (req) {
           let result = this._convertContacts(contacts);
           Services.DOMRequest.fireSuccess(req.request, result);
         } else {
           if (DEBUG) debug("no request stored!" + msg.requestID);
         }
         break;
       case "Contacts:GetAll:Next":
-        let data = this._cursorData[msg.cursorId];
+        let data = this.getRequest(msg.cursorId);
+        if (!data) {
+          break;
+        }
         let result = contacts ? this._convertContacts(contacts) : [null];
         if (data.waitingForNext) {
           if (DEBUG) debug("cursor waiting for contact, sending");
           data.waitingForNext = false;
           let contact = result.shift();
           this._pushArray(data.cachedContacts, result);
           this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
         } else {
@@ -659,26 +660,25 @@ ContactManager.prototype = {
     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;
   },
 
   createCursor: function CM_createCursor(aRequest) {
-    let id = this._getRandomId();
     let data = {
       cursor: Services.DOMRequest.createCursor(this._window, function() {
         this.handleContinue(id);
       }.bind(this)),
       cachedContacts: [],
       waitingForNext: true,
     };
+    let id = this.getRequestId(data);
     if (DEBUG) debug("saved cursor id: " + id);
-    this._cursorData[id] = data;
     return [id, data.cursor];
   },
 
   getAll: function CM_getAll(aOptions) {
     if (DEBUG) debug("getAll: " + JSON.stringify(aOptions));
     let [cursorId, cursor] = this.createCursor();
     let allowCallback = function() {
       cpmm.sendAsyncMessage("Contacts:GetAll", {
@@ -689,17 +689,17 @@ ContactManager.prototype = {
   },
 
   nextTick: function nextTick(aCallback) {
     Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
   },
 
   handleContinue: function CM_handleContinue(aCursorId) {
     if (DEBUG) debug("handleContinue: " + aCursorId);
-    let data = this._cursorData[aCursorId];
+    let data = this.getRequest(aCursorId);
     if (data.cachedContacts.length > 0) {
       if (DEBUG) debug("contact in cache");
       let contact = data.cachedContacts.shift();
       this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
       if (data.cachedContacts.length < CONTACTS_SENDMORE_MINIMUM) {
         cpmm.sendAsyncMessage("Contacts:GetAll:SendNow", { cursorId: aCursorId });
       }
     } else {