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/. */
7 const Cc = Components.classes;
8 const Ci = Components.interfaces;
9 const Cu = Components.utils;
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 Cu.import("resource://gre/modules/Services.jsm");
14 XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
15 "resource://gre/modules/SystemAppProxy.jsm");
17 function ActivitiesDialog() {
23 ActivitiesDialog.prototype = {
24 run: function ap_run() {
25 let id = "activity-choice" + this._id++;
26 let activity = this.activities.shift();
29 activity.list.forEach(function(item) {
30 choices.push({ manifest: item.manifest, icon: item.icon });
34 // Keep up the frond-end of an activity choice. The messages contains
35 // a list of {names, icons} for applications able to handle this particular
36 // activity. The front-end should display a UI to pick one.
38 type: "activity-choice",
45 detail.activityType = activity.type;
48 // Listen the resulting choice from the front-end. If there is no choice,
49 // let's return -1, which means the user has cancelled the dialog.
50 SystemAppProxy.addEventListener("mozContentEvent", function act_getChoice(evt) {
51 if (evt.detail.id != id)
54 SystemAppProxy.removeEventListener("mozContentEvent", act_getChoice);
55 activity.callback.handleEvent(Ci.nsIActivityUIGlueCallback.WEBAPPS_ACTIVITY,
56 evt.detail.value !== undefined
61 SystemAppProxy.dispatchEvent(detail);
64 chooseActivity: function ap_chooseActivity(aOptions, aActivities, aCallback) {
65 // B2G does not have an alternate activity system, make no choice and return.
66 if (aActivities.length === 0) {
67 aCallback.handleEvent(Ci.nsIActivityUIGlueCallback.WEBAPPS_ACTIVITY, -1);
77 if (aOptions.data && aOptions.data.type) {
78 activity.type = aOptions.data.type;
81 this.activities.push(activity);
82 Services.tm.currentThread.dispatch(this, Ci.nsIEventTarget.DISPATCH_NORMAL);
85 classID: Components.ID("{3a54788b-48cc-4ab4-93d6-0d6a8ef74f8e}"),
87 QueryInterface: XPCOMUtils.generateQI([Ci.nsIActivityUIGlue, Ci.nsIRunnable])
90 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ActivitiesDialog]);