Bug 822712 - Port to b2g18. r=nsm, a=blocking-b2g:leo+
authorDoug Turner <dougt@dougt.org>
Sat, 30 Mar 2013 10:22:53 -0700
changeset 118883 f9f11b8cbf8af012f9c69407fc2130aa37ea1032
parent 118882 029540d0efeec8cb876781dc0f62620c40230074
child 118884 6fa132a4b57757b28e47c354c6239b0fece2038e
push id604
push userdougt@mozilla.com
push dateSat, 30 Mar 2013 19:43:41 +0000
reviewersnsm, blocking-b2g
bugs822712
milestone18.0
Bug 822712 - Port to b2g18. r=nsm, a=blocking-b2g:leo+
dom/push/src/Push.js
dom/push/src/PushService.js
--- a/dom/push/src/Push.js
+++ b/dom/push/src/Push.js
@@ -1,16 +1,16 @@
 /* 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/. */
 
 "use strict";
 
 function debug(s) {
-  // dump("-*- Push.js: " + s + "\n");
+//    dump("-*- Push.js: " + s + "\n");
 }
 
 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");
@@ -42,23 +42,27 @@ Push.prototype = {
     let principal = aWindow.document.nodePrincipal;
 
     this._pageURL = principal.URI;
 
     let appsService = Cc["@mozilla.org/AppsService;1"]
                         .getService(Ci.nsIAppsService);
     this._app = appsService.getAppByLocalId(principal.appId);
     this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
-    if (!this._manifestURL)
+    if (!this._manifestURL) {
+      debug("No manifestURL");
       return null;
+    }
 
     let perm = Services.perms.testExactPermissionFromPrincipal(principal,
                                                                "push");
-    if (perm != Ci.nsIPermissionManager.ALLOW_ACTION)
+    if (perm != Ci.nsIPermissionManager.ALLOW_ACTION) {
+      debug("No Permission");
       return null;
+    }
 
     this.initHelper(aWindow, []);
 
     this.initMessageListener([
       "PushService:Register:OK",
       "PushService:Register:KO",
       "PushService:Unregister:OK",
       "PushService:Unregister:KO",
--- a/dom/push/src/PushService.js
+++ b/dom/push/src/PushService.js
@@ -1,30 +1,28 @@
 /* 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/. */
 
 "use strict";
 
 function debug(s) {
-  // dump("-*- PushService.js: " + s + "\n");
+//    dump("-*- PushService.js: " + s + "\n");
 }
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
-Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/services-common/preferences.js");
-Cu.import("resource://gre/modules/services-common/utils.js");
-Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
+Cu.import("resource://gre/modules/commonjs/promise/core.js");
 
 const kPUSHDB_DB_NAME = "push";
 const kPUSHDB_DB_VERSION = 1; // Change this if the IndexedDB format changes
 const kPUSHDB_STORE_NAME = "push";
 const kCONFLICT_RETRY_ATTEMPTS = 3; // If channelID registration says 409, how
                                     // many times to retry with a new channelID
 
 const kERROR_CHID_CONFLICT = 409;   // Error code sent by push server if this
@@ -753,17 +751,24 @@ PushService.prototype = {
       // again.  Discard the message itself, let the timeout notify error to
       // the app.
       debug("This should never happen!");
       this._shutdownWS();
     }
 
     this._ws.sendMsg(JSON.stringify(data));
     // Process the next one as soon as possible.
-    setTimeout(this._processNextRequestInQueue.bind(this), 0);
+    this.nextTick(this._processNextRequestInQueue.bind(this));
+  },
+
+  nextTick: function(aCallback, thisObj) {
+    if (thisObj) {
+      aCallback = aCallback.bind(thisObj);
+    }
+    Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
   },
 
   _receivedUpdate: function(aChannelID, aLatestVersion) {
     debug("Updating: " + aChannelID + " -> " + aLatestVersion);
 
     var compareRecordVersionAndNotify = function(aPushRecord) {
       debug("compareRecordVersionAndNotify()");
       if (!aPushRecord) {