1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 //dump('DEBUG RequestSyncScheduler: ' + s + '\n');
11 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
13 Cu.import('resource://gre/modules/DOMRequestHelper.jsm');
14 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
16 XPCOMUtils.defineLazyServiceGetter(this, 'cpmm',
17 '@mozilla.org/childprocessmessagemanager;1',
20 function RequestSyncScheduler() {
24 RequestSyncScheduler.prototype = {
25 __proto__: DOMRequestIpcHelper.prototype,
27 classDescription: 'RequestSyncScheduler XPCOM Component',
28 classID: Components.ID('{8ee5ab74-15c4-478f-9d32-67627b9f0f1a}'),
29 contractID: '@mozilla.org/dom/request-sync-scheduler;1',
30 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
32 Ci.nsIDOMGlobalPropertyInitializer]),
34 _messages: [ 'RequestSync:Register:Return',
35 'RequestSync:Unregister:Return',
36 'RequestSync:Registrations:Return',
37 'RequestSync:Registration:Return' ],
39 init: function(aWindow) {
42 // DOMRequestIpcHelper.initHelper sets this._window
43 this.initDOMRequestHelper(aWindow, this._messages);
46 register: function(aTask, aParams) {
48 return this.sendMessage('RequestSync:Register',
49 { task: aTask, params: aParams });
52 unregister: function(aTask) {
54 return this.sendMessage('RequestSync:Unregister',
58 registrations: function() {
59 debug('registrations');
60 return this.sendMessage('RequestSync:Registrations', {});
63 registration: function(aTask) {
64 debug('registration');
65 return this.sendMessage('RequestSync:Registration',
69 sendMessage: function(aMsg, aObj) {
71 return this.createPromise(function(aResolve, aReject) {
73 self.getPromiseResolverId({ resolve: aResolve, reject: aReject });
74 cpmm.sendAsyncMessage(aMsg, aObj, null,
75 self._window.document.nodePrincipal);
79 receiveMessage: function(aMessage) {
80 debug('receiveMessage');
82 let req = this.getPromiseResolver(aMessage.data.requestID);
87 if ('error' in aMessage.data) {
88 req.reject(Cu.cloneInto(aMessage.data.error, this._window));
92 if ('results' in aMessage.data) {
93 req.resolve(Cu.cloneInto(aMessage.data.results, this._window));
101 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RequestSyncScheduler]);