Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Features/owa free activities #159

Merged
merged 10 commits into from

2 participants

@mixedpuppy
Owner

activities addon without hooks into openwebapps. once the api work is done, we can reimplement that support

@mhammond mhammond commented on the diff
addons/activities/lib/services.js
@@ -485,6 +525,8 @@ function serviceInvocationHandler(win)
this._popups = []; // save references to popups we've created already
let observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
+ observerService.addObserver(this, "activity-handler-registered", false);
+ observerService.addObserver(this, "activity-handler-unregistered", false);
observerService.addObserver(this, "openwebapp-installed", false);
@mhammond Owner

shouldn't these openwebapp observers die?

@mixedpuppy Owner

we may still need them to install/remove apps that provide a share service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mixedpuppy mixedpuppy merged commit c33d32a into develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  Makefile
@@ -31,7 +31,7 @@ activities := $(TOPSRCDIR)/addons/activities
ifeq ($(TARGET),activities)
pkgdir := $(activities)
- cfx_args := --pkgdir=$(pkgdir) $(binary) $(profile) --package-path=$(oauthorizer) --package-path=$(openwebapps) --binary-args="-console -purgecaches $(BINARYARGS)"
+ cfx_args := --pkgdir=$(pkgdir) $(binary) $(profile) --package-path=$(oauthorizer) --binary-args="-console -purgecaches $(BINARYARGS)"
else
pkgdir := $(openwebapps)
cfx_args := --pkgdir=$(pkgdir) $(binary) $(profile) --binary-args="-console -purgecaches $(BINARYARGS)"
View
90 addons/activities/lib/main.js
@@ -51,7 +51,7 @@ MozActivitiesAPI.prototype = {
startActivity: function(activity, successCB, errorCB) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let recentWindow = wm.getMostRecentWindow("navigator:browser");
- recentWindow.serviceInvocationHandler.invoke(aWindow, activity, successCB, errorCB);
+ recentWindow.serviceInvocationHandler.invoke(activity, successCB, errorCB);
},
__exposedProps__: {
startActivity: "r"
@@ -68,64 +68,42 @@ let MozActivitiesAPIFactory = {
//----- navigator.mozActivities api implementation
-function ActivitiesLoader() {
- console.log("ActivitiesLoader init");
- Services.obs.addObserver(this, "openwebapps-mediator-load", true);
- Services.obs.addObserver(this, "openwebapps-mediator-init", true);
-}
-ActivitiesLoader.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
- observe: function(subject, topic, data) {
- console.log("ActivitiesLoader observed "+topic);
- switch (topic) {
- case "openwebapps-mediator-load":
- console.log("initialize window.serviceInvocationHandler");
- let doc = subject.document.documentElement;
- if (doc.getAttribute("windowtype") == "navigator:browser") {
- console.log("attache the serviceInvocationHandler");
- try {
- let serviceInvocationHandler = require("services").serviceInvocationHandler;
- subject.serviceInvocationHandler = new serviceInvocationHandler(subject);
- } catch(e) {
- console.log("error "+e);
- }
- }
- break;
- case "openwebapps-mediator-init":
- console.log("initialize webActivities APIs");
- // register our navigator api's that will be globally attached
- Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(
- MozActivitiesAPIClassID, "MozActivitiesAPI", MozActivitiesAPIContract, MozActivitiesAPIFactory
- );
- Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).
- addCategoryEntry("JavaScript-navigator-property", "mozActivities",
- MozActivitiesAPIContract,
- false, true);
-
- unloaders.push(function() {
- Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(
- MozActivitiesAPIClassID, MozActivitiesAPIFactory
- );
- Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).
- deleteCategoryEntry("JavaScript-navigator-property", "mozActivities", false);
- });
- }
- },
- removeObservers: function() {
- Services.obs.removeObserver(this, "openwebapps-mediator-load");
- Services.obs.removeObserver(this, "openwebapps-mediator-init");
+exports.main = function(options, callbacks) {
+ console.log("web activities addon starting")
+
+
+ /* We use winWatcher to create an instance per window (current and future) */
+ let iter = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getEnumerator("navigator:browser");
+ while (iter.hasMoreElements()) {
+ let aWindow = iter.getNext().QueryInterface(Ci.nsIDOMWindow);
+ let serviceInvocationHandler = require("services").serviceInvocationHandler;
+ aWindow.serviceInvocationHandler = new serviceInvocationHandler(aWindow);
}
-}
-var loader = new ActivitiesLoader();
-unloaders.push(function () {
- loader.removeObservers();
- loader = null;
-});
+ function winWatcher(subject, topic) {
+ if (topic != "domwindowopened") return;
+ let serviceInvocationHandler = require("services").serviceInvocationHandler;
+ subject.serviceInvocationHandler = new serviceInvocationHandler(subject);
+ }
+ Services.ww.registerNotification(winWatcher);
+ unloaders.push(function() Services.ww.unregisterNotification(winWatcher));
+
+ // register our navigator api's that will be globally attached
+ Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(
+ MozActivitiesAPIClassID, "MozActivitiesAPI", MozActivitiesAPIContract, MozActivitiesAPIFactory
+ );
+ Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).
+ addCategoryEntry("JavaScript-navigator-property", "mozActivities",
+ MozActivitiesAPIContract,
+ false, true);
-exports.main = function(options, callbacks) {
- console.log("web activities addon starting")
- let owa = require("openwebapps/main");
+ unloaders.push(function() {
+ Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(
+ MozActivitiesAPIClassID, MozActivitiesAPIFactory
+ );
+ Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).
+ deleteCategoryEntry("JavaScript-navigator-property", "mozActivities", false);
+ });
}
exports.onUnload = function(reason) {
View
56 addons/activities/lib/services.js
@@ -40,7 +40,6 @@
* ***** END LICENSE BLOCK ***** */
const {Cu, Ci, Cc} = require("chrome");
-var {FFRepoImplService} = require("openwebapps/api");
let {OAuthConsumer} = require("oauthorizer/oauthconsumer");
let tmp = {}
Cu.import("resource://gre/modules/Services.jsm", tmp);
@@ -167,7 +166,7 @@ MediatorPanel.prototype = {
});
worker.port.on("owa.service.register.handler", function (activity) {
//dump("register.handler "+JSON.stringify(activity)+"\n");
- //dump("register.handler "+frame.origin+":"+activity.action+":"+activity.message+"\n");
+ //console.log("register.handler "+frame.origin+":"+activity.action+":"+activity.message);
if (!mediator.handlers[frame.origin])
mediator.handlers[frame.origin] = {};
if (!mediator.handlers[frame.origin][activity.action])
@@ -223,7 +222,7 @@ MediatorPanel.prototype = {
onOWAReady: function(msg) {
this._panelWindow = null;
- FFRepoImplService.findServices(this.methodName, function(serviceList) {
+ activityRegistry.get(this.methodName, function(serviceList) {
this.tabData.activity.data = this.updateargs(this.tabData.activity.data);
this.panel.port.emit("owa.mediation.setup", {
activity: this.tabData.activity,
@@ -468,6 +467,47 @@ MediatorPanel.prototype = {
}
}
+var activityRegistry = {
+ _activitiesList: {},
+ registerActivityHandler: function(activity, url, title, data) {
+ this.unregisterActivityHandler(activity, url);
+ if (!this._activitiesList[activity]) this._activitiesList[activity] = [];
+ this._activitiesList[activity].push({
+ url: url,
+ service: activity,
+ title: title,
+ app: data
+ });
+ Services.obs.notifyObservers(null, 'activity-handler-registered', activity);
+ },
+ unregisterActivityHandler: function(activity, url) {
+ let activities = this._activitiesList[activity];
+ if (!activities)
+ return;
+ for (var i=0; i < activities.length; i++) {
+ if (activities[i].url == url) {
+ activities.splice(i, 1);
+ Services.obs.notifyObservers(null, 'activity-handler-unregistered', activity);
+ return;
+ }
+ }
+ },
+ get: function(activityName, cb) {
+ let activities = this._activitiesList[activityName] ? [].concat(this._activitiesList[activityName]) : [];
+ try {
+ // the owa api will need to be xpcom or something, we cannot import
+ // addon-sdk files from an external addon
+ //var {FFRepoImplService} = require("openwebapps/api");
+ //FFRepoImplService.findServices(activityName, function(serviceList) {
+ // // make a combo list of our internal activities and installed apps
+ // activities = activities.concat(serviceList);
+ // cb(activities);
+ //});
+ } catch (e) {
+ }
+ cb(activities);
+ }
+}
/**
* serviceInvocationHandler
@@ -485,6 +525,8 @@ function serviceInvocationHandler(win)
this._popups = []; // save references to popups we've created already
let observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
+ observerService.addObserver(this, "activity-handler-registered", false);
+ observerService.addObserver(this, "activity-handler-unregistered", false);
observerService.addObserver(this, "openwebapp-installed", false);
@mhammond Owner

shouldn't these openwebapp observers die?

@mixedpuppy Owner

we may still need them to install/remove apps that provide a share service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
observerService.addObserver(this, "openwebapp-uninstalled", false);
observerService.addObserver(this, "net:clear-active-logins", false);
@@ -539,6 +581,13 @@ serviceInvocationHandler.prototype = {
* reset our mediators if an app is installed or uninstalled
*/
observe: function(subject, topic, data) {
+ if (topic === "activity-handler-registered" ||
+ topic === "activity-handler-unregistered") {
+ for each (let popupCheck in this._popups) {
+ if (popupCheck.methodName == data)
+ popupCheck.reconfigure();
+ }
+ } else
if (topic === "openwebapp-installed" ||
topic === "openwebapp-uninstalled" ||
topic === "net:clear-active-logins")
@@ -618,3 +667,4 @@ serviceInvocationHandler.prototype = {
exports.serviceInvocationHandler = serviceInvocationHandler;
exports.MediatorPanel = MediatorPanel;
+exports.activityRegistry = activityRegistry;
View
2  addons/activities/package.json
@@ -6,6 +6,6 @@
"fullName": "Web Activities for Firefox",
"id": "webactivities@mozillalabs.com",
"description": "Adds Web Activities to Firefox.",
- "dependencies": ["api-utils", "addon-kit", "openwebapps", "oauthorizer"],
+ "dependencies": ["api-utils", "addon-kit", "oauthorizer"],
"main": "./main.js"
}
View
69 addons/activities/test/helpers.js
@@ -2,24 +2,13 @@ const {Cc, Ci, Cm, Cu, components} = require("chrome");
exports.getServiceInvocationHandler = function() {
- require("openwebapps/main"); // for the side effect of injecting window.apps.
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
let window = wm.getMostRecentWindow("navigator:browser");
return window.serviceInvocationHandler;
}
-// Return the "openwebapps" object.
-exports.getOWA = function() {
- require("openwebapps/main"); // for the side effect of injecting window.apps.
- let repo = require("api").FFRepoImplService;
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
- .getService(Ci.nsIWindowMediator);
- let window = wm.getMostRecentWindow("navigator:browser");
- return window.apps;
-}
-
-function getTestAppOptions(appRelPath) {
+function getTestAppOptions(activityName, appRelPath) {
// first find the URL of the app.
let lastSlash = module.uri.lastIndexOf("/");
let manifest = module.uri.substr(0, lastSlash+1) + appRelPath;
@@ -28,58 +17,30 @@ function getTestAppOptions(appRelPath) {
return {
url: manifest,
origin: origin,
- skipPostInstallDashboard: true // don't want the app panel to appear.
+ launch_url: origin,
+ manifest: {
+ name: activityName
+ }
};
};
// Ensure one of our test apps is installed and ready to go.
-exports.installTestApp = function(test, appPath, callback, errback) {
- let repo = exports.getOWA()._repo;
- let options = getTestAppOptions(appPath);
- options.onerror = function(errob) {
- if (errback) {
- errback(errob);
- } else {
- // no errback so they expect success!
- test.fail("failed to install the test app: " + errob.code + "/" + errob.message);
- test.done();
- }
- };
- options.onsuccess = function() {
- callback(options);
- };
- repo.install('http://localhost:8420',
- options,
- undefined); // the window is only used if a prompt is shown.
+exports.installTestApp = function(activityName, appPath) {
+ let { activityRegistry } = require("activities/services");
+ let options = getTestAppOptions(activityName, appPath);
+ activityRegistry.registerActivityHandler(activityName, options.url, activityName,
+ options);
+ return options;
};
// Uninstall our test app - by default (ie, with no errback passed), errors
// are "fatal".
-exports.uninstallTestApp = function(test, appPath, callback, errback) {
- let repo = exports.getOWA()._repo;
- let options = getTestAppOptions(appPath);
-
- repo.uninstall(options.origin,
- function() { // success CB
- callback();
- },
- function(errob) { //errback
- if (errback) {
- errback(errob);
- } else {
- test.fail("failed to uninstall test app: " + errob.code + "/" + errob.message);
- test.done();
- }
- }
- );
+exports.uninstallTestApp = function(activityName, appPath) {
+ let { activityRegistry } = require("activities/services");
+ let options = getTestAppOptions(activityName, appPath);
+ activityRegistry.unregisterActivityHandler(activityName, options.url);
};
-// Ensure the test app is not installed.
-exports.ensureNoTestApp = function(test, appPath, callback) {
- exports.uninstallTestApp(test, appPath,
- function() {callback()}, function() {callback()});
-}
-
var call_counter = 0;
exports.invokeService = function(mediatorPanel, activity, cb, cberr) {
let worker = mediatorPanel.handlers[activity.origin][activity.action][activity.message];
View
33 addons/activities/test/test-services.js
@@ -1,4 +1,3 @@
-const FFRepoImpl = require("openwebapps/api").FFRepoImplService;
const {getServiceInvocationHandler, installTestApp, invokeService} = require("./helpers");
const {Cc, Ci, Cm, Cu, components} = require("chrome");
const tabs = require("tabs");
@@ -8,7 +7,8 @@ require("activities/main").main();
exports.test_invoke = function(test) {
test.waitUntilDone();
- installTestApp(test, "apps/basic/basic.webapp", function(options) {
+ let options = installTestApp("test.basic", "apps/basic/basic.html");
+
// we don't yet have a "mediator" concept we can use, so we call some
// internal methods to set things up bypassing the builtin mediator ui.
let activity = {action:"test.basic",
@@ -34,7 +34,6 @@ exports.test_invoke = function(test) {
});
});
mediator.show();
- });
};
@@ -43,7 +42,8 @@ exports.test_invoke_twice = function(test) {
test.waitUntilDone();
let services = getServiceInvocationHandler();
let seenTab1Callback = false;
- installTestApp(test, "apps/basic/basic.webapp", function(options) {
+ let options = installTestApp("test.basic", "apps/basic/basic.html");
+
tabs.open({
url: "about:blank",
onOpen: function(tab1) {
@@ -103,14 +103,14 @@ exports.test_invoke_twice = function(test) {
});
}
});
- });
}
exports.test_panel_auto_hides_on_tab_switch = function(test) {
test.waitUntilDone();
let services = getServiceInvocationHandler();
let seenTab1Callback = false;
- installTestApp(test, "apps/basic/basic.webapp", function(options) {
+ let options = installTestApp("test.basic", "apps/basic/basic.html");
+
tabs.open({
url: "about:blank",
onOpen: function(tab1) {
@@ -122,8 +122,7 @@ exports.test_panel_auto_hides_on_tab_switch = function(test) {
message: "echoArgs",
data: {hello: "world"}};
let mediator = services.get(activity);
- mediator.show();
- mediator.panel.port.once("owa.mediation.ready", function() {
+ mediator.panel.once("show", function() {
test.waitUntil(function() {return mediator.panel.isShowing}
).then(function() {
// mediator is showing - create a new tab and make sure it goes away.
@@ -161,18 +160,19 @@ exports.test_panel_auto_hides_on_tab_switch = function(test) {
}
});
});
- })
+ });
+ mediator.show();
})
}
})
- });
}
exports.test_panel_auto_hides_on_tab_close = function(test) {
test.waitUntilDone();
let services = getServiceInvocationHandler();
let seenTab1Callback = false;
- installTestApp(test, "apps/basic/basic.webapp", function(options) {
+ let options = installTestApp("test.basic", "apps/basic/basic.html");
+
tabs.open({
url: "about:blank",
onOpen: function(tab) {
@@ -183,8 +183,7 @@ exports.test_panel_auto_hides_on_tab_close = function(test) {
message: "echoArgs",
data: {hello: "world"}};
let mediator = services.get(activity);
- mediator.show();
- mediator.panel.port.once("owa.mediation.ready", function() {
+ mediator.panel.once("show", function() {
test.waitUntil(function() {return mediator.panel.isShowing}
).then(function() {
// mediator is showing - close the tab and make sure it goes away.
@@ -195,17 +194,18 @@ exports.test_panel_auto_hides_on_tab_close = function(test) {
test.done();
});
});
- })
+ });
+ mediator.show();
})
}
})
- });
}
// A helper for the error tests.
function testError(test, activity, errchecker) {
test.waitUntilDone();
- installTestApp(test, "apps/basic/basic.webapp", function(options) {
+ let options = installTestApp("test.basic", "apps/basic/basic.html");
+
// we don't yet have a "mediator" concept we can use, so we call some
// internal methods to set things up bypassing the builtin mediator ui.
activity.origin = options.origin;
@@ -229,7 +229,6 @@ function testError(test, activity, errchecker) {
});
});
mediator.show();
- });
}
exports.test_invoke_error = function(test) {
Something went wrong with that request. Please try again.