Permalink
Browse files

Bug 812198 - Add support for preinstalled packaged apps r=vingtetun

  • Loading branch information...
fabricedesre committed Dec 8, 2012
1 parent eef8ac4 commit c94c8a6a0927260e9825933383f73d8f21f5e497
View
@@ -91,8 +91,13 @@ function ensureFolderExists(file) {
}
function getJSON(file) {
- let content = getFileContent(file);
- return JSON.parse(content);
+ try {
+ let content = getFileContent(file);
+ return JSON.parse(content);
+ } catch(e) {
+ dump('Invalid JSON file : ' + file.path + '\n');
+ throw e;
+ }
}
function makeWebappsObject(dirs) {
@@ -103,28 +108,30 @@ function makeWebappsObject(dirs) {
let directories = getSubDirectories(directoryName);
directories.forEach(function readManifests(dir) {
let manifestFile = getFile(GAIA_DIR, directoryName, dir, "manifest.webapp");
+ let updateFile = getFile(GAIA_DIR, directoryName, dir, "update.webapp");
// Ignore directories without manifest
- if (!manifestFile.exists())
+ if (!manifestFile.exists() && !updateFile.exists()) {
return;
+ }
+
+ let manifest = manifestFile.exists() ? manifestFile : updateFile;
let domain = dir + "." + GAIA_DOMAIN;
let webapp = {
- manifest: getJSON(manifestFile),
- manifestFile: manifestFile,
+ manifest: getJSON(manifest),
+ manifestFile: manifest,
url: GAIA_SCHEME + domain + (GAIA_PORT ? GAIA_PORT : ''),
domain: domain,
sourceDirectoryFile: manifestFile.parent,
sourceDirectoryName: dir,
sourceAppDirectoryName: directoryName
};
- // External webapps have an `origin` file
- let origin = webapp.sourceDirectoryFile.clone();
- origin.append('origin');
- if (origin.exists()) {
- let url = getFileContent(origin);
- // Strip any leading/ending spaces
- webapp.origin = url.replace(/^\s+|\s+$/, '');
+ // External webapps have a `metadata.json` file
+ let metaData = webapp.sourceDirectoryFile.clone();
+ metaData.append('metadata.json');
+ if (metaData.exists()) {
+ webapp.metaData = getJSON(metaData);
}
fun(webapp);
View
@@ -69,46 +69,76 @@ Gaia.externalWebapps.forEach(function (webapp) {
if (BUILD_APP_NAME != '*' && webapp.sourceDirectoryName != BUILD_APP_NAME)
return;
+ if (!webapp.metaData) {
+ return;
+ }
+
// Compute webapp folder name in profile
let webappTargetDirName = webapp.sourceDirectoryName;
// Copy webapp's manifest to the profile
let webappTargetDir = webappsTargetDir.clone();
webappTargetDir.append(webappTargetDirName);
- webapp.manifestFile.copyTo(webappTargetDir, 'manifest.webapp');
-
- let origin = webapp.sourceDirectoryFile.clone();
- origin.append('origin');
- let url = webapp.origin;
- if (!origin)
- throw new Error('External webapp `' + webapp.domain + '` doesn\'t have an' +
- '`origin` file.');
+ let origin;
+ let installOrigin;
+ let manifestURL;
+
+ let removable = false;
+
+ // In case of packaged app, just copy `application.zip` and `update.webapp`
+ let appPackage = webapp.sourceDirectoryFile.clone();
+ appPackage.append('application.zip');
+ if (appPackage.exists()) {
+ let updateManifest = webapp.sourceDirectoryFile.clone();
+ updateManifest.append('update.webapp');
+ if (!updateManifest.exists()) {
+ throw new Error('External packaged webapp `' + webapp.domain + ' is ' +
+ 'missing an `update.webapp` file. This JSON file ' +
+ 'contains a `package_path` attribute specifying where ' +
+ 'to download the application zip package from the origin ' +
+ 'specified in `metadata.json` file.');
+ }
+ appPackage.copyTo(webappTargetDir, 'application.zip');
+ updateManifest.copyTo(webappTargetDir, 'update.webapp');
+ removable = true;
+ origin = webapp.metaData.origin;
+ installOrigin = webapp.metaData.installOrigin;
+ manifestURL = webapp.metaData.manifestURL;
+ } else {
+ webapp.manifestFile.copyTo(webappTargetDir, 'manifest.webapp');
+ origin = webapp.metaData.origin;
+ installOrigin = webapp.metaData.origin;
+ manifestURL = webapp.metaData.origin + 'manifest.webapp';
+
+ // This is an hosted app. Check if there is an offline cache.
+ let srcCacheFolder = webapp.sourceDirectoryFile.clone();
+ srcCacheFolder.append('cache');
+ if (srcCacheFolder.exists()) {
+ let cacheManifest = srcCacheFolder.clone();
+ cacheManifest.append('manifest.appcache');
+ if (!cacheManifest.exists())
+ throw new Error('External webapp `' + webapp.domain + '` has a cache ' +
+ 'directory without `manifest.appcache` file.');
+
+ // Copy recursively the whole cache folder to webapp folder
+ let targetCacheFolder = webappTargetDir.clone();
+ targetCacheFolder.append('cache');
+ copyRec(srcCacheFolder, targetCacheFolder);
+ }
+ }
// Add webapp's entry to the webapps global manifest
manifests[webappTargetDirName] = {
- origin: url,
- installOrigin: url,
+ origin: origin,
+ installOrigin: installOrigin,
receipt: null,
installTime: 132333986000,
- manifestURL: url + 'manifest.webapp',
+ manifestURL: manifestURL,
+ removable: removable,
localId: id++
};
- let srcCacheFolder = webapp.sourceDirectoryFile.clone();
- srcCacheFolder.append("cache");
- if (srcCacheFolder.exists()) {
- let cacheManifest = srcCacheFolder.clone();
- cacheManifest.append("manifest.appcache");
- if (!cacheManifest.exists())
- throw new Error('External webapp `' + webapp.domain + '` has a cache ' +
- 'directory without `manifest.appcache` file.');
-
- // Copy recursively the whole cache folder to webapp folder
- let targetCacheFolder = webappTargetDir.clone();
- targetCacheFolder.append("cache");
- copyRec(srcCacheFolder, targetCacheFolder);
- }
});
// Write webapps global manifest
@@ -0,0 +1,3 @@
+{
+ "origin": "http://m.here.net/"
+}
@@ -1 +0,0 @@
-http://m.here.net/
@@ -0,0 +1,3 @@
+{
+ "origin" : "https://marketplace-dev.allizom.org/telefonica/"
+}
@@ -1 +0,0 @@
-https://marketplace-dev.allizom.org/telefonica/
@@ -0,0 +1,3 @@
+{
+ "origin" : "https://marketplace.allizom.org/telefonica/"
+}
@@ -1 +0,0 @@
-https://marketplace.allizom.org/telefonica/
@@ -0,0 +1,3 @@
+{
+ "origin": "https://marketplace.firefox.com/telefonica/"
+}
@@ -1 +0,0 @@
-https://marketplace.firefox.com/telefonica/

0 comments on commit c94c8a6

Please sign in to comment.