2012-07-20 19:41:30 +04: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-23 05:20:09 +04:00
|
|
|
|
2012-07-20 19:41:30 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-10-21 22:16:00 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-07-20 19:41:30 +04:00
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsISyncMessageSender");
|
2012-07-20 19:41:30 +04: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 17:52:21 +04:00
|
|
|
// system message callback. The newly created wrapper then create an
|
|
|
|
// ActivityRequestHandler object.
|
2012-07-20 19:41:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ActivityRequestHandler.prototype = {
|
2014-03-22 17:52:21 +04:00
|
|
|
init: function arh_init(aWindow) {
|
|
|
|
this._window = aWindow;
|
|
|
|
},
|
|
|
|
|
2015-11-09 17:33:00 +03:00
|
|
|
__init: function arh___init(aId, aOptions, aReturnValue) {
|
2014-03-22 17:52:21 +04:00
|
|
|
this._id = aId;
|
|
|
|
this._options = aOptions;
|
2015-11-09 17:33:00 +03:00
|
|
|
this._returnValue = aReturnValue;
|
2014-03-22 17:52:21 +04:00
|
|
|
},
|
2012-08-23 05:20:09 +04:00
|
|
|
|
2012-07-20 19:41:30 +04:00
|
|
|
get source() {
|
2014-03-22 17:54:40 +04: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 17:52:21 +04:00
|
|
|
return Cu.cloneInto(this._options, this._window);
|
2012-07-20 19:41:30 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
postResult: function arh_postResult(aResult) {
|
2015-11-09 17:33:00 +03:00
|
|
|
if (this._returnValue) {
|
|
|
|
cpmm.sendAsyncMessage("Activity:PostResult", {
|
|
|
|
"id": this._id,
|
|
|
|
"result": aResult
|
|
|
|
});
|
|
|
|
Services.obs.notifyObservers(null, "activity-success", this._id);
|
|
|
|
} else {
|
|
|
|
Cu.reportError("postResult() can't be called when 'returnValue': 'true' isn't declared in manifest.webapp");
|
|
|
|
throw new Error("postResult() can't be called when 'returnValue': 'true' isn't declared in manifest.webapp");
|
|
|
|
}
|
2012-07-20 19:41:30 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
postError: function arh_postError(aError) {
|
|
|
|
cpmm.sendAsyncMessage("Activity:PostError", {
|
|
|
|
"id": this._id,
|
|
|
|
"error": aError
|
|
|
|
});
|
2013-10-21 22:16:00 +04:00
|
|
|
Services.obs.notifyObservers(null, "activity-error", this._id);
|
2012-07-20 19:41:30 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{9326952a-dbe3-4d81-a51f-d9c160d96d6b}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
2014-03-22 17:52:21 +04:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer
|
|
|
|
])
|
2012-07-20 19:41:30 +04:00
|
|
|
}
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityRequestHandler]);
|