From abf42c46c10abd25f438a1bc864495fede5fc76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Mon, 28 Nov 2011 12:13:11 -0800 Subject: [PATCH] Bug 697383 - implement navigator.mozApps - Part 0 : Remove old implementation [r=mfinkle] --- mobile/xul/installer/package-manifest.in | 3 - toolkit/Makefile.in | 1 - toolkit/mozapps/webapps/Makefile.in | 57 ---- toolkit/mozapps/webapps/OpenWebapps.idl | 118 -------- toolkit/mozapps/webapps/OpenWebapps.js | 296 ------------------- toolkit/mozapps/webapps/OpenWebapps.jsm | 260 ---------------- toolkit/mozapps/webapps/OpenWebapps.manifest | 8 - 7 files changed, 743 deletions(-) delete mode 100644 toolkit/mozapps/webapps/Makefile.in delete mode 100644 toolkit/mozapps/webapps/OpenWebapps.idl delete mode 100644 toolkit/mozapps/webapps/OpenWebapps.js delete mode 100644 toolkit/mozapps/webapps/OpenWebapps.jsm delete mode 100644 toolkit/mozapps/webapps/OpenWebapps.manifest diff --git a/mobile/xul/installer/package-manifest.in b/mobile/xul/installer/package-manifest.in index b7b45aba7a11..e284387564e0 100644 --- a/mobile/xul/installer/package-manifest.in +++ b/mobile/xul/installer/package-manifest.in @@ -277,7 +277,6 @@ @BINPATH@/components/xuldoc.xpt @BINPATH@/components/xultmpl.xpt @BINPATH@/components/zipwriter.xpt -@BINPATH@/components/openwebapps.xpt ; JavaScript components @BINPATH@/components/ConsoleAPI.manifest @@ -331,7 +330,6 @@ @BINPATH@/components/amContentHandler.js @BINPATH@/components/amWebInstallListener.js @BINPATH@/components/nsBlocklistService.js -@BINPATH@/components/OpenWebapps.manifest #ifdef MOZ_UPDATER @BINPATH@/components/nsUpdateService.manifest @@ -607,7 +605,6 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@ @BINPATH@/components/PromptService.js @BINPATH@/components/SessionStore.js @BINPATH@/components/Sidebar.js -@BINPATH@/components/OpenWebapps.js #ifdef MOZ_SAFE_BROWSING @BINPATH@/components/SafeBrowsing.js #endif diff --git a/toolkit/Makefile.in b/toolkit/Makefile.in index 442c73a0d2a4..8ba03f2a46c0 100644 --- a/toolkit/Makefile.in +++ b/toolkit/Makefile.in @@ -56,7 +56,6 @@ PARALLEL_DIRS = \ mozapps/plugins \ mozapps/shared \ mozapps/update \ - mozapps/webapps \ obsolete \ profile \ themes \ diff --git a/toolkit/mozapps/webapps/Makefile.in b/toolkit/mozapps/webapps/Makefile.in deleted file mode 100644 index 51cdd1790821..000000000000 --- a/toolkit/mozapps/webapps/Makefile.in +++ /dev/null @@ -1,57 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is the Open Web Apps. -# -# The Initial Developer of the Original Code is Ben Goodger. -# Portions created by the Initial Developer are Copyright (C) 2004 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Fabrice Desré -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = openwebapps - -XPIDLSRCS = OpenWebapps.idl - -EXTRA_COMPONENTS += \ - OpenWebapps.js \ - OpenWebapps.manifest \ - $(NULL) - -EXTRA_JS_MODULES = \ - OpenWebapps.jsm \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/toolkit/mozapps/webapps/OpenWebapps.idl b/toolkit/mozapps/webapps/OpenWebapps.idl deleted file mode 100644 index 1823f58878d1..000000000000 --- a/toolkit/mozapps/webapps/OpenWebapps.idl +++ /dev/null @@ -1,118 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Open Web Apps. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation - * Portions created by the Initial Developer are Copyright (C) 2011 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Fabrice Desré - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// IDL for https://developer.mozilla.org/en/OpenWebApps/The_JavaScript_API - -#include "nsISupports.idl" - -[scriptable, uuid(3b937eb5-679b-41e9-aefa-543849fa61dd)] -interface nsIOpenWebappsApplication : nsISupports { - attribute jsval manifest; - attribute DOMString origin; - attribute jsval install_data; - attribute DOMString install_origin; - attribute unsigned long install_time; -}; - -[scriptable, function, uuid(fa3ac1bb-ad7d-44d7-8585-9ecdf3782d65)] -interface nsIOpenWebappsSuccessInstalled : nsISupports { - void handle(in nsIOpenWebappsApplication application); -}; - -[scriptable, function, uuid(a8a83f45-4cbe-4806-b867-017554e30bd4)] -interface nsIOpenWebappsSuccessList : nsISupports { - void handle([array, size_is(count)] in nsIOpenWebappsApplication apps, - in unsigned long count); -}; - -[scriptable, function, uuid(75e44e3f-ccda-4497-af68-8abd3f5e1d7b)] -interface nsIOpenWebappsError : nsISupports { - attribute DOMString code; - attribute DOMString message; -}; - -[scriptable, function, uuid(8b29495e-a5e4-4e76-9af8-0f6fe97b8959)] -interface nsIOpenWebappsErrorCB : nsISupports { - void handle(in nsIOpenWebappsError error); -}; - -[scriptable, function, uuid(b86669ab-6a36-4ceb-a4bf-a980dd496144)] -interface nsIOpenWebappsSuccessEmpty : nsISupports { - void handle(); -}; - -[scriptable, function, uuid(a458afcf-eee9-42fb-bd90-75d5e41c0d9e)] -interface nsIOpenWebappsChangeCallback : nsISupports { - // what is either "add" when new apps are added to the repository, or - // "remove" when they are deleted. - void update(in DOMString what, [array, size_is(count)] in nsIOpenWebappsApplication apps, - in unsigned long count); -}; - -[scriptable, uuid(f3ec76a6-abca-4d90-b8c9-e221033068ef)] -interface nsIOpenWebappsMgmt : nsISupports { - void launch(in DOMString origin, - [optional] in nsIOpenWebappsSuccessEmpty onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - void list(in nsIOpenWebappsSuccessList onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - void uninstall(in DOMString origin, - in nsIOpenWebappsSuccessEmpty onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - long watchUpdates(in nsIOpenWebappsChangeCallback callback); - - void clearWatch(in long watchId); -}; - -[scriptable, uuid(cecd9de7-ea4e-45fd-8a01-a5861d9109ab)] -interface nsIOpenWebapps : nsISupports { - void install(in DOMString manifestURI, - [optional] in jsval install_data, - [optional] in nsIOpenWebappsSuccessEmpty onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - void amInstalled(in nsIOpenWebappsSuccessInstalled onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - void getInstalledBy(in nsIOpenWebappsSuccessList onsuccess, - [optional] in nsIOpenWebappsErrorCB onerror); - - readonly attribute nsIOpenWebappsMgmt mgmt; -}; diff --git a/toolkit/mozapps/webapps/OpenWebapps.js b/toolkit/mozapps/webapps/OpenWebapps.js deleted file mode 100644 index 8a2a06b7ec82..000000000000 --- a/toolkit/mozapps/webapps/OpenWebapps.js +++ /dev/null @@ -1,296 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Open Web Apps. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2011 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Fabrice Desré - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; -const Cr = Components.results; - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -function OpenWebapps() { - this.messages = ["OpenWebapps:InstallDone", "OpenWebapps:InstallAborted", "OpenWebapps:GetInstalledBy:Return", - "OpenWebapps:AmInstalled:Return", "OpenWebapps:MgmtLaunch:Return", "OpenWebapps:MgmtList:Return", - "OpenWebapps:MgmtUninstall:Return"]; - - this.mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender); - - this.messages.forEach((function(msgName) { - this.mm.addMessageListener(msgName, this); - }).bind(this)); - - this._callbacks = []; - this._window = null; - this._watchId = 0; -} - -OpenWebapps.prototype = { - - /** from https://developer.mozilla.org/en/OpenWebApps/The_Manifest - * only the name property is mandatory - */ - checkManifest: function(aManifest) { - return ("name" in aManifest); - }, - - getCallbackId: function(aCallback) { - let id = "id" + this._getRandomId(); - this._callbacks[id] = aCallback; - return id; - }, - - getCallback: function(aId) { - return this._callbacks[aId]; - }, - - removeCallback: function(aId) { - if (this._callbacks[aId]) - delete this._callbacks[aId]; - }, - - _getRandomId: function() { - return Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString(); - }, - - _convertAppsArray: function(aApps) { - let apps = new Array(); - for (let i = 0; i < aApps.length; i++) { - let app = aApps[i]; - let xapp = Cc["@mozilla.org/openwebapps/application;1"].createInstance(Ci.nsIOpenWebappsApplication); - xapp.origin = app.origin; - xapp.manifest = app.manifest; - xapp.install_data = app.install_data; - xapp.install_origin = app.install_origin; - xapp.install_time = app.install_time; - apps.push(xapp); - } - return apps; - }, - - receiveMessage: function(aMessage) { - let msg = aMessage.json; - let callbacks = this.getCallback(msg.callbackID); - - // if we have no such callback and this is not a broadcast message, bail out - if (!callbacks && aMessage.name != "OpenWebapps:InstallDone" - && aMessage.name != "OpenWebapps:MgmtUninstall:Return") - return; - - switch(aMessage.name) { - case "OpenWebapps:InstallAborted" : - if (callbacks.error) - callbacks.error.handle({ code: "denied", message: "User denied installation" }); - break; - case "OpenWebapps:InstallDone" : - if (callbacks && callbacks.success) - callbacks.success.handle(); - this._onInstalled([msg.app]); - break; - case "OpenWebapps:GetInstalledBy:Return": - if (callbacks && callbacks.success) { - let apps = this._convertAppsArray(msg.apps); - callbacks.success.handle(apps, apps.length); - } - break; - case "OpenWebapps:AmInstalled:Return": - if (callbacks.success) - callbacks.success.handle(msg.installed ? msg.app : null); - break; - case "OpenWebapps:MgmtLaunch:Return": - if (msg.ok && callbacks && callbacks.success) - callbacks.success.handle(); - else if (!msg.ok && callbacks.error) - callbacks.error.handle({ code: "noSuchApp", message: "Unable to launch application"}); - break; - case "OpenWebapps:MgmtList:Return": - if (msg.ok && callbacks && callbacks.success) { - let apps = this._convertAppsArray(msg.apps); - callbacks.success.handle(apps, apps.length); - } - else if (!msg.ok && callbacks && callbacks.error) { - callbacks.error.handle({ code: "noAppList", message: "Unable to get application list"}); - } - break; - case "OpenWebapps:MgmtUninstall:Return": - if (msg.ok) { - if (callbacks && callbacks.success) - callbacks.success.handle(); - this._onUninstalled([msg.app]); - } - else if (!msg.ok && callbacks.error) - callbacks.error.handle({ code: "noSuchApp", message: "Unable to uninstall application"}); - break; - } - this.removeCallback(msg.callbackID); - }, - - // nsIOpenWebapps implementation - - install: function(aURL, aInstallData, aSuccess, aError) { - let self = this; - - let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); - xhr.open("GET", aURL, true); - - xhr.addEventListener("load", function() { - if (xhr.status == 200) { - try { - let manifest = JSON.parse(xhr.responseText); - if (!self.checkManifest(manifest)) { - if (aError) - aError.handle({ code: "invalidManifest", message: "Invalid manifest" }); - } else { - self.mm.sendAsyncMessage("OpenWebapps:Install", { storeURI: self._window.location.href, manifestURI: aURL, manifest: xhr.responseText, - installData: aInstallData, callbackID: self.getCallbackId({ success: aSuccess, error: aError }) }); - } - } catch(e) { - if (aError) - aError.handle({ code: "manifestParseError", message: "Unable to parse the manifest" }); - } - } - else if (aError) { - aError.handle({ code: "networkError", message: "Unable to retrieve manifest" }); - } - }, false); - - xhr.addEventListener("error", function() { - if (aError) - aError.handle({ code: "networkError", message: "Unable to retrieve manifest" }); - }, false); - - xhr.send(null); - }, - - amInstalled: function(aSuccess, aError) { - this.mm.sendAsyncMessage("OpenWebapps:AmInstalled", { appURI: this._window.location.href, callbackID: this.getCallbackId({ success: aSuccess, error: aError }) }); - }, - - getInstalledBy: function(aSuccess, aError) { - this.mm.sendAsyncMessage("OpenWebapps:GetInstalledBy", { storeURI: this._window.location.href, callbackID: this.getCallbackId({ success: aSuccess, error: aError }) }); - }, - - // nsIOpenWebappsMgmt implementation - launch: function(aOrigin, aSuccess, aError) { - this.mm.sendAsyncMessage("OpenWebapps:MgmtLaunch", { origin: aOrigin, callbackID: this.getCallbackId({ success: aSuccess, error: aError }) }); - }, - - list: function(aSuccess, aError) { - this.mm.sendAsyncMessage("OpenWebapps:MgmtList", { from: this._window.location.href, callbackID: this.getCallbackId({ success: aSuccess, error: aError }) }); - }, - - uninstall: function(aOrigin, aSuccess, aError) { - this.mm.sendAsyncMessage("OpenWebapps:MgmtUninstall", { from: this._window.location.href, origin: aOrigin, callbackID: this.getCallbackId({ success: aSuccess, error: aError }) }); - }, - - _onRepoChange: function(aWhat, aApps) { - for (let prop in this._callbacks) { - if (this._callbacks[prop].isWatch) { - let apps = this._convertAppsArray(aApps); - this._callbacks[prop].callback.update(aWhat, apps, apps.length); - } - } - }, - - _onInstalled: function(aApps) { - this._onRepoChange("add", aApps); - }, - - _onUninstalled: function(aApps) { - this._onRepoChange("remove", aApps); - }, - - watchUpdates: function(aCallback) { - this._watchId++; - this._callbacks["_watch" + this._getRandomId()] = { isWatch: true, callback: aCallback }; - return this._watchId; - }, - - clearWatch: function(aWatchId) { - this.removeCallback("_watch" + aWatchId); - }, - - handleEvent: function(aEvent) { - if (aEvent.type == "unload") { - // remove all callbacks so we don't call anything on a cleared scope - this._callbacks = []; - } - }, - - // nsIDOMGlobalPropertyInitializer implementation - init: function(aWindow) { - this._window = aWindow; - this._window.addEventListener("unload", this, false); - }, - - get mgmt() { - return this.QueryInterface(Ci.nsIOpenWebappsMgmt); - }, - - classID: Components.ID("{d8fd4d63-27ea-47b9-a931-481214bb8b5b}"), - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIOpenWebapps, Ci.nsIOpenWebappsMgmt, Ci.nsIDOMGlobalPropertyInitializer]), - - classInfo: XPCOMUtils.generateCI({classID: Components.ID("{d8fd4d63-27ea-47b9-a931-481214bb8b5b}"), - contractID: "@mozilla.org/openwebapps;1", - interfaces: [Ci.nsIOpenWebapps], - flags: Ci.nsIClassInfo.DOM_OBJECT, - classDescription: "OpenWebapps"}) -} - -function OpenWebappsApplication() { -} - -OpenWebappsApplication.prototype = { - origin: null, - manifest: null, - install_data: null, - install_origin: null, - install_time: 0, - - classID: Components.ID("{34456347-0792-45a4-8eb1-7b5f94f2d700}"), - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIOpenWebappsApplication]), - - classInfo: XPCOMUtils.generateCI({classID: Components.ID("{34456347-0792-45a4-8eb1-7b5f94f2d700}"), - contractID: "@mozilla.org/openwebapps/application;1", - interfaces: [Ci.nsIOpenWebappsApplication], - flags: Ci.nsIClassInfo.DOM_OBJECT, - classDescription: "OpenWebapps Application"}) -} - -const NSGetFactory = XPCOMUtils.generateNSGetFactory([OpenWebapps, OpenWebappsApplication]); - diff --git a/toolkit/mozapps/webapps/OpenWebapps.jsm b/toolkit/mozapps/webapps/OpenWebapps.jsm deleted file mode 100644 index 4e1c64eed8a8..000000000000 --- a/toolkit/mozapps/webapps/OpenWebapps.jsm +++ /dev/null @@ -1,260 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Mobile Browser. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2011 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Fabrice Desré - * Mark Finkle - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const Cu = Components.utils; -const Cc = Components.classes; -const Ci = Components.interfaces; - -let EXPORTED_SYMBOLS = ["OpenWebapps"]; - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -XPCOMUtils.defineLazyGetter(this, "NetUtil", function() { - Cu.import("resource://gre/modules/NetUtil.jsm"); - return NetUtil; -}); - -let OpenWebapps = { - appsDir: null, - appsFile: null, - webapps: { }, - - init: function() { - let file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile); - file.append("webapps"); - if (!file.exists() || !file.isDirectory()) { - file.create(Ci.nsIFile.DIRECTORY_TYPE, 0700); - } - this.appsDir = file; - this.appsFile = file.clone(); - this.appsFile.append("webapps.json"); - if (!this.appsFile.exists()) - return; - - try { - let channel = NetUtil.newChannel(this.appsFile); - channel.contentType = "application/json"; - let self = this; - NetUtil.asyncFetch(channel, function(aStream, aResult) { - if (!Components.isSuccessCode(aResult)) { - Cu.reportError("OpenWebappsSupport: Could not read from json file " + this.appsFile.path); - return; - } - - // Read json file into a string - let data = null; - try { - self.webapps = JSON.parse(NetUtil.readInputStreamToString(aStream, aStream.available()) || ""); - aStream.close(); - } catch (ex) { - Cu.reportError("OpenWebsappsStore: Could not parse JSON: " + ex); - } - }); - } catch (ex) { - Cu.reportError("OpenWebappsSupport: Could not read from " + aFile.path + " : " + ex); - } - }, - - _writeFile: function ss_writeFile(aFile, aData) { - // Initialize the file output stream. - let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); - ostream.init(aFile, 0x02 | 0x08 | 0x20, 0600, ostream.DEFER_OPEN); - - // Obtain a converter to convert our data to a UTF-8 encoded input stream. - let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); - converter.charset = "UTF-8"; - - // Asynchronously copy the data to the file. - let istream = converter.convertToInputStream(aData); - NetUtil.asyncCopy(istream, ostream, function(rc) { - // nothing to do - }); - }, - - install: function(aApplication) { - let id = this._appId(aApplication.appURI); - - // install an application again is considered as an update - if (id) { - let dir = this.appsDir.clone(); - dir.append(id); - try { - dir.remove(true); - } catch(e) { - } - } - else { - let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); - id = uuidGenerator.generateUUID().toString(); - } - - let dir = this.appsDir.clone(); - dir.append(id); - dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700); - - let manFile = dir.clone(); - manFile.append("manifest.json"); - this._writeFile(manFile, JSON.stringify(aApplication.manifest)); - - this.webapps[id] = { - title: aApplication.title, - storeURI: aApplication.storeURI, - appURI: aApplication.appURI, - installData: aApplication.installData, - installTime: (new Date()).getTime() - }; - this._writeFile(this.appsFile, JSON.stringify(this.webapps)); - - // now save the icon as icon.png in the app directory - let iconURI = aApplication.iconURI ? aApplication.iconURI : "chrome://browser/skin/images/homescreen-default-hdpi.png"; - let iconFile = dir.clone(); - iconFile.append("icon.png"); - let uri = Services.io.newURI(iconURI, null, null); - let persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist); - persist.persistFlags = persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES | persist.PERSIST_FLAGS_BYPASS_CACHE; - persist.saveURI(uri, null, null, null, "", iconFile); - }, - - _appId: function(aURI) { - for (let id in this.webapps) { - if (this.webapps[id].appURI == aURI) - return id; - } - return null; - }, - - _readManifest: function(aId) { - let file = this.appsDir.clone(); - file.append(aId); - file.append("manifest.json"); - let data = ""; - let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream); - var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream); - fstream.init(file, -1, 0, 0); - cstream.init(fstream, "UTF-8", 0, 0); - let (str = {}) { - let read = 0; - do { - read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value - data += str.value; - } while (read != 0); - } - cstream.close(); // this closes fstream - try { - return JSON.parse(data); - } catch(e) { - return null; - } - }, - - amInstalled: function(aURI) { - for (let id in this.webapps) { - let app = this.webapps[id]; - if (app.appURI == aURI) { - return { origin: app.appURI, - install_origin: app.storeURI, - install_data: app.installData, - install_time: app.installTime, - manifest: this._readManifest(id) }; - } - } - return null; - }, - - getInstalledBy: function(aStoreURI) { - let res = []; - for (let id in this.webapps) { - let app = this.webapps[id]; - if (app.storeURI == aStoreURI) - res.push({ origin: app.appURI, - install_origin: app.storeURI, - install_data: app.installData, - install_time: app.installTime, - manifest: this._readManifest(id) }); - } - return res; - }, - - mgmtList: function() { - let res = new Array(); - for (let id in this.webapps) { - let app = this.webapps[id]; - res.push({ origin: app.appURI, - install_origin: app.storeURI, - install_data: app.installData, - install_time: app.installTime, - manifest: this._readManifest(id) }); - } - return res; - }, - - mgmtLaunch: function(aOrigin) { - for (let id in this.webapps) { - let app = this.webapps[id]; - app.manifest = this._readManifest(id); - if (app.appURI == aOrigin) { - let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); - let uri = Services.io.newURI(aOrigin + (app.manifest.launch_path ? app.manifest.launch_path : ""), null, null); - browserWin.browserDOMWindow.openURI(uri, null, browserWin.OPEN_APPTAB, Ci.nsIBrowserDOMWindow.OPEN_NEW); - return true; - } - } - return false; - }, - - mgmtUninstall: function(aOrigin) { - for (let id in this.webapps) { - let app = this.webapps[id]; - if (app.appURI == aOrigin) { - delete this.webapps[id]; - this._writeFile(this.appsFile, JSON.stringify(this.webapps)); - let dir = this.appsDir.clone(); - dir.append(id); - try { - dir.remove(true); - } catch (e) { - } - return true; - } - } - return false; - } -}; - -OpenWebapps.init(); - diff --git a/toolkit/mozapps/webapps/OpenWebapps.manifest b/toolkit/mozapps/webapps/OpenWebapps.manifest deleted file mode 100644 index ce3a11d79054..000000000000 --- a/toolkit/mozapps/webapps/OpenWebapps.manifest +++ /dev/null @@ -1,8 +0,0 @@ -# OpenWebapps.js -component {d8fd4d63-27ea-47b9-a931-481214bb8b5b} OpenWebapps.js -contract @mozilla.org/openwebapps;1 {d8fd4d63-27ea-47b9-a931-481214bb8b5b} -category JavaScript-navigator-property mozApps @mozilla.org/openwebapps;1 - -component {34456347-0792-45a4-8eb1-7b5f94f2d700} OpenWebapps.js -contract @mozilla.org/openwebapps/application;1 {34456347-0792-45a4-8eb1-7b5f94f2d700} -