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";
|
2012-08-23 11:56:36 -07:00
|
|
|
|
2012-07-20 08:41:30 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2012-08-23 11:56:36 -07:00
|
|
|
|
2012-07-20 08:41:30 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-07-05 10:43:02 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsISyncMessageSender");
|
2012-07-20 08:41:30 -07:00
|
|
|
|
|
|
|
function debug(aMsg) {
|
|
|
|
//dump("-- ActivityWrapper.js " + Date.now() + " : " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-23 11:56:36 -07:00
|
|
|
* nsISystemMessagesWrapper implementation. Will return a
|
2012-07-20 08:41:30 -07:00
|
|
|
* nsIDOMMozActivityRequestHandler
|
|
|
|
*/
|
|
|
|
function ActivityWrapper() {
|
|
|
|
debug("ActivityWrapper");
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivityWrapper.prototype = {
|
2012-08-24 21:07:58 -07:00
|
|
|
wrapMessage: function wrapMessage(aMessage, aWindow) {
|
2012-07-20 08:41:30 -07:00
|
|
|
debug("Wrapping " + JSON.stringify(aMessage));
|
2014-02-06 11:55:20 -08:00
|
|
|
|
|
|
|
// This message is useful to communicate that the activity message has been
|
|
|
|
// properly received by the app. If the app will be killed, the
|
|
|
|
// ActivitiesService will be able to fire an error and complete the
|
|
|
|
// Activity workflow.
|
|
|
|
cpmm.sendAsyncMessage("Activity:Ready", { id: aMessage.id });
|
|
|
|
|
2014-03-22 06:52:21 -07:00
|
|
|
let handler = new aWindow.ActivityRequestHandler(aMessage.id, aMessage.payload);
|
2012-07-20 08:41:30 -07:00
|
|
|
|
2013-07-05 10:43:02 -07:00
|
|
|
// When the activity window is closed, fire an error to notify the activity
|
|
|
|
// caller of the situation.
|
|
|
|
// We don't need to check whether the activity itself already sent
|
|
|
|
// back something since ActivitiesService.jsm takes care of that.
|
|
|
|
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let innerWindowID = util.currentInnerWindowID;
|
|
|
|
|
|
|
|
let observer = {
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
|
2013-10-21 11:16:00 -07:00
|
|
|
switch (aTopic) {
|
|
|
|
case 'inner-window-destroyed':
|
|
|
|
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
|
|
if (wId == innerWindowID) {
|
|
|
|
debug("Closing activity window " + innerWindowID);
|
|
|
|
Services.obs.removeObserver(observer, "inner-window-destroyed");
|
|
|
|
cpmm.sendAsyncMessage("Activity:PostError",
|
|
|
|
{ id: aMessage.id,
|
|
|
|
error: "ActivityCanceled"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'activity-error':
|
|
|
|
case 'activity-success':
|
|
|
|
if (aData !== aMessage.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Services.obs.removeObserver(observer, "activity-error");
|
|
|
|
Services.obs.removeObserver(observer, "activity-success");
|
|
|
|
let docshell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation);
|
|
|
|
Services.obs.notifyObservers(docshell, "activity-done", aTopic);
|
|
|
|
break;
|
2013-07-05 10:43:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:16:00 -07:00
|
|
|
Services.obs.addObserver(observer, "activity-error", false);
|
|
|
|
Services.obs.addObserver(observer, "activity-success", false);
|
2013-07-05 10:43:02 -07:00
|
|
|
Services.obs.addObserver(observer, "inner-window-destroyed", false);
|
2012-07-20 08:41:30 -07:00
|
|
|
return handler;
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{5430d6f9-32d6-4924-ba39-6b6d1b093cd6}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivityWrapper]);
|
2012-07-20 08:41:30 -07:00
|
|
|
|