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 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");
|
|
|
|
|
2014-04-07 06:59:48 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
|
|
|
"resource://gre/modules/SystemAppProxy.jsm");
|
|
|
|
|
2012-07-20 08:41:30 -07:00
|
|
|
function ActivitiesDialog() {
|
|
|
|
this._id = 0;
|
|
|
|
|
|
|
|
this.activities = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivitiesDialog.prototype = {
|
|
|
|
run: function ap_run() {
|
|
|
|
let id = "activity-choice" + this._id++;
|
|
|
|
let activity = this.activities.shift();
|
|
|
|
|
|
|
|
let choices = [];
|
|
|
|
activity.list.forEach(function(item) {
|
2013-01-07 06:48:56 -08:00
|
|
|
choices.push({ manifest: item.manifest, icon: item.icon });
|
2012-07-20 08:41:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Keep up the frond-end of an activity choice. The messages contains
|
|
|
|
// a list of {names, icons} for applications able to handle this particular
|
|
|
|
// activity. The front-end should display a UI to pick one.
|
2012-08-19 12:00:19 -07:00
|
|
|
let detail = {
|
2012-07-20 08:41:30 -07:00
|
|
|
type: "activity-choice",
|
|
|
|
id: id,
|
|
|
|
name: activity.name,
|
|
|
|
choices: choices
|
2012-08-19 12:00:19 -07:00
|
|
|
};
|
2012-07-20 08:41:30 -07:00
|
|
|
|
|
|
|
// Listen the resulting choice from the front-end. If there is no choice,
|
|
|
|
// let's return -1, which means the user has cancelled the dialog.
|
2014-04-07 06:59:48 -07:00
|
|
|
SystemAppProxy.addEventListener("mozContentEvent", function act_getChoice(evt) {
|
2012-07-20 08:41:30 -07:00
|
|
|
if (evt.detail.id != id)
|
|
|
|
return;
|
|
|
|
|
2014-04-07 06:59:48 -07:00
|
|
|
SystemAppProxy.removeEventListener("mozContentEvent", act_getChoice);
|
2013-09-05 09:45:16 -07:00
|
|
|
activity.callback.handleEvent(evt.detail.value !== undefined
|
|
|
|
? evt.detail.value
|
|
|
|
: -1);
|
2012-07-20 08:41:30 -07:00
|
|
|
});
|
|
|
|
|
2014-04-07 06:59:48 -07:00
|
|
|
SystemAppProxy.dispatchEvent(detail);
|
2012-07-20 08:41:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
chooseActivity: function ap_chooseActivity(aName, aActivities, aCallback) {
|
|
|
|
this.activities.push({
|
|
|
|
name: aName,
|
|
|
|
list: aActivities,
|
|
|
|
callback: aCallback
|
|
|
|
});
|
|
|
|
Services.tm.currentThread.dispatch(this, Ci.nsIEventTarget.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{70a83123-7467-4389-a309-3e81c74ad002}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIActivityUIGlue, Ci.nsIRunnable])
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivitiesDialog]);
|
2012-07-20 08:41:30 -07:00
|
|
|
|