2012-07-20 08:41:30 -07:00
|
|
|
/* 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";
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2012-08-22 18:20:09 -07:00
|
|
|
|
2012-07-20 08:41:30 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-10-21 11:16:00 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-07-20 08:41:30 -07:00
|
|
|
|
2012-08-27 07:13:02 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsISyncMessageSender");
|
2012-07-20 08:41:30 -07:00
|
|
|
|
|
|
|
function debug(aMsg) {
|
|
|
|
//dump("-- ActivityRequestHandler.js " + Date.now() + " : " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsIDOMMozActivityRequestHandler implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function ActivityRequestHandler() {
|
|
|
|
debug("ActivityRequestHandler");
|
|
|
|
|
|
|
|
// When a system message of type 'activity' is emitted, it forces the
|
|
|
|
// creation of an ActivityWrapper which in turns replace the default
|
2014-03-22 06:52:21 -07:00
|
|
|
// system message callback. The newly created wrapper then create an
|
|
|
|
// ActivityRequestHandler object.
|
2012-07-20 08:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ActivityRequestHandler.prototype = {
|
2014-03-22 06:52:21 -07:00
|
|
|
init: function arh_init(aWindow) {
|
|
|
|
this._window = aWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
__init: function arh___init(aId, aOptions) {
|
|
|
|
this._id = aId;
|
|
|
|
this._options = aOptions;
|
|
|
|
},
|
2012-08-22 18:20:09 -07:00
|
|
|
|
2012-07-20 08:41:30 -07:00
|
|
|
get source() {
|
2014-03-22 06:54:40 -07:00
|
|
|
// We need to clone this object because the this._options.data has
|
|
|
|
// the type any in WebIDL which will cause the binding layer to pass
|
|
|
|
// the value which is a COW unmodified to content.
|
2014-03-22 06:52:21 -07:00
|
|
|
return Cu.cloneInto(this._options, this._window);
|
2012-07-20 08:41:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
postResult: function arh_postResult(aResult) {
|
|
|
|
cpmm.sendAsyncMessage("Activity:PostResult", {
|
|
|
|
"id": this._id,
|
|
|
|
"result": aResult
|
|
|
|
});
|
2013-10-21 11:16:00 -07:00
|
|
|
Services.obs.notifyObservers(null, "activity-success", this._id);
|
2012-07-20 08:41:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
postError: function arh_postError(aError) {
|
|
|
|
cpmm.sendAsyncMessage("Activity:PostError", {
|
|
|
|
"id": this._id,
|
|
|
|
"error": aError
|
|
|
|
});
|
2013-10-21 11:16:00 -07:00
|
|
|
Services.obs.notifyObservers(null, "activity-error", this._id);
|
2012-07-20 08:41:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{9326952a-dbe3-4d81-a51f-d9c160d96d6b}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
2014-03-22 06:52:21 -07:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer
|
|
|
|
])
|
2012-07-20 08:41:30 -07:00
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityRequestHandler]);
|