Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D01D410FDC for ; Mon, 6 Jan 2014 20:25:41 +0000 (UTC) Received: (qmail 53035 invoked by uid 500); 6 Jan 2014 20:25:41 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 52905 invoked by uid 500); 6 Jan 2014 20:25:41 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 52727 invoked by uid 99); 6 Jan 2014 20:25:41 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jan 2014 20:25:41 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 388AB882C88; Mon, 6 Jan 2014 20:25:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: braden@apache.org To: commits@cordova.apache.org Date: Mon, 06 Jan 2014 20:25:45 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [05/13] git commit: Installing and launching from CRX files, all working! Installing and launching from CRX files, all working! Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/33d8fe23 Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/33d8fe23 Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/33d8fe23 Branch: refs/heads/master Commit: 33d8fe23dc2cd55beecdf58783e607916c8f490e Parents: 062ce6a Author: Braden Shepherdson Authored: Wed Nov 27 14:53:44 2013 -0800 Committer: Braden Shepherdson Committed: Mon Jan 6 15:24:12 2014 -0500 ---------------------------------------------------------------------- www/cdvah/crx_files/config.android.xml | 2 +- www/cdvah/crx_files/config.ios.xml | 1 - www/cdvah/index.html | 1 + www/cdvah/js/CrxInstaller.js | 55 +++++++++++++++++++++++++ www/cdvah/js/CrxPackageHandler.js | 64 ----------------------------- www/cdvah/js/Installer.js | 19 +++++++-- www/cdvah/js/ResourcesLoader.js | 2 +- www/cdvah/views/add.html | 7 ++-- 8 files changed, 78 insertions(+), 73 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/crx_files/config.android.xml ---------------------------------------------------------------------- diff --git a/www/cdvah/crx_files/config.android.xml b/www/cdvah/crx_files/config.android.xml index b0e4507..24126a4 100644 --- a/www/cdvah/crx_files/config.android.xml +++ b/www/cdvah/crx_files/config.android.xml @@ -92,7 +92,7 @@ - + http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/crx_files/config.ios.xml ---------------------------------------------------------------------- diff --git a/www/cdvah/crx_files/config.ios.xml b/www/cdvah/crx_files/config.ios.xml index 9254738..c6d446b 100644 --- a/www/cdvah/crx_files/config.ios.xml +++ b/www/cdvah/crx_files/config.ios.xml @@ -88,7 +88,6 @@ - http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/index.html ---------------------------------------------------------------------- diff --git a/www/cdvah/index.html b/www/cdvah/index.html index 7d77fac..5a816b2 100644 --- a/www/cdvah/index.html +++ b/www/cdvah/index.html @@ -9,6 +9,7 @@ + http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/js/CrxInstaller.js ---------------------------------------------------------------------- diff --git a/www/cdvah/js/CrxInstaller.js b/www/cdvah/js/CrxInstaller.js new file mode 100644 index 0000000..c9f08aa --- /dev/null +++ b/www/cdvah/js/CrxInstaller.js @@ -0,0 +1,55 @@ +(function(){ + 'use strict'; + /* global myApp */ + myApp.run(['$q', 'Installer', 'AppsService', 'ResourcesLoader', function($q, Installer, AppsService, ResourcesLoader){ + + var platformId = cordova.require('cordova/platform').id; + + function CrxInstaller(url, appId) { + Installer.call(this, url, appId); + } + + CrxInstaller.prototype = Object.create(Installer.prototype); + + CrxInstaller.prototype.type = 'crx'; + + CrxInstaller.prototype._doUpdateApp = function(installPath) { + var platformConfig = location.pathname.replace(/\/[^\/]*$/, '/crx_files/config.' + platformId + '.xml'); + var targetConfig = installPath + '/config.xml'; + var xhr; + var self = this; + + var baseName = self.url.match(/\/([^\/]*)$/)[1]; + var crxFile = installPath.replace(/\/$/, '') + '/' + baseName; + + return ResourcesLoader.downloadFromUrl(this.url, crxFile).then(function(destination) { + return ResourcesLoader.extractZipFile(crxFile, installPath); + }).then(function() { + // Copy in the config..xml file from the harness. + return ResourcesLoader.xhrGet(platformConfig); + }).then(function(_xhr){ + xhr = _xhr; + return ResourcesLoader.ensureDirectoryExists(targetConfig); + }).then(function() { + return ResourcesLoader.writeFileContents(targetConfig, xhr.responseText); + }); + }; + + AppsService.registerInstallerFactory({ + type: 'crx', + createFromUrl: function(url) { + // Clean up the URL. + if (!/^https?:/.test(url)) { + url = 'http://' + url; + } + + // TODO: Fix the missing appId, somehow. + return $q.when(new CrxInstaller(url, 'New Chrome App')); + }, + + createFromJson: function(url, appId) { + return new CrxInstaller(url, appId); + } + }); + }]); +})(); http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/js/CrxPackageHandler.js ---------------------------------------------------------------------- diff --git a/www/cdvah/js/CrxPackageHandler.js b/www/cdvah/js/CrxPackageHandler.js deleted file mode 100644 index a860d57..0000000 --- a/www/cdvah/js/CrxPackageHandler.js +++ /dev/null @@ -1,64 +0,0 @@ -(function(){ - 'use strict'; - /* global myApp */ - myApp.run(['$q', 'AppsService', 'ResourcesLoader', 'ContextMenuInjectScript', function($q, AppsService, ResourcesLoader, ContextMenuInjectScript){ - - var platformId = cordova.require('cordova/platform').id; - - function copyFile(startUrl, targetLocation){ - /************ Begin Work around for File system bug ************/ - if(targetLocation.indexOf('file://') === 0) { - targetLocation = targetLocation.substring('file://'.length); - } - /************ End Work around for File system bug **************/ - return ResourcesLoader.xhrGet(startUrl) - .then(function(xhr){ - return ResourcesLoader.ensureDirectoryExists(targetLocation) - .then(function(){ - return ResourcesLoader.writeFileContents(targetLocation, xhr.responseText); - }); - }); - } - - AppsService.registerPackageHandler('crx', { - extractPackageToDirectory : function (appName, fileName, outputDirectory){ - console.log('extracting the crx'); - var dataToAppend = ContextMenuInjectScript.getInjectString(appName); - var platformDirectory = outputDirectory + '/' + platformId + '/'; - var platformWWWDirectory = platformDirectory + 'www/'; - var cordovaFile = platformWWWDirectory + 'cordova.js'; - - // We need to - // 1) Copy over the files required to convert a crx to a normal web app - // 2) Modify the cordova.js file - return ResourcesLoader.extractZipFile(fileName, platformWWWDirectory) - .then(function(){ - var plugins = cordova.require('cordova/plugin_list'); - if (!plugins) { - throw new Error('Error loading cordova_plugins.json'); - } - - var copies = [ - copyFile('app-bundle:///cordova.js', cordovaFile), - copyFile('app-bundle:///crx_files/config.' + platformId + '.xml', platformDirectory + 'config.xml'), - copyFile('app-bundle:///cordova_plugins.js', platformWWWDirectory + 'cordova_plugins.js'), - copyFile('app-bundle:///chromeapp.html', platformWWWDirectory + 'chromeapp.html'), - copyFile('app-bundle:///chromeappstyles.css', platformWWWDirectory + 'chromeappstyles.css'), - copyFile('app-bundle:///chromebgpage.html', platformWWWDirectory + 'chromebgpage.html'), - copyFile('app-bundle:///cdvah_js/ContextMenu.js', platformWWWDirectory + 'ContextMenu.js') - ]; - - for(var i = 0; i < plugins.length; i++) { - console.log('copying ' + plugins[i].file); - copies.push(copyFile('app-bundle:///' + plugins[i].file, platformWWWDirectory + plugins[i].file)); - } - - return $q.all(copies); - }) - .then(function(){ - return ResourcesLoader.appendFileContents(cordovaFile, dataToAppend); - }); - } - }); - }]); -})(); http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/js/Installer.js ---------------------------------------------------------------------- diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js index 7c2c2da..18d1093 100644 --- a/www/cdvah/js/Installer.js +++ b/www/cdvah/js/Installer.js @@ -67,7 +67,12 @@ self.installPath = installPath; self.lastUpdated = new Date(); self.updatingStatus = null; - return getAppPlugins(installPath + '/www/cordova_plugins.js'); + if (self.type === 'crx') { + // No cordova_plugins.js to read for .crx-based apps. + return $q.when({}); + } else { + return getAppPlugins(installPath + '/www/cordova_plugins.js'); + } }, null, function(status) { self.updatingStatus = Math.round(status * 100); }).then(function(metadata) { @@ -91,6 +96,8 @@ } var configLocation = installPath + '/config.xml'; + var type = this.type; + return getAppStartPageFromConfig(configLocation) .then(function(rawStartLocation) { var urlutil = cordova.require('cordova/urlutil'); @@ -115,11 +122,17 @@ UrlRemap.aliasUri('/cordova\\.js.*', '.+', harnessDir + '/cordova.js', false /* redirect */); UrlRemap.aliasUri('/cordova_plugins\\.js.*', '.+', harnessDir + '/cordova_plugins.js', false /* redirect */); if (startLocation.indexOf('chrome-extension://') === 0) { - var pluginsUrl = 'chrome-extension://[^\/]+/plugins/'; + var pluginsUrl = 'chrome-extension://[^/]+/plugins/'; UrlRemap.aliasUri('^' + pluginsUrl, '^' + pluginsUrl, harnessDir + '/plugins/', false /* redirect */); + + var bootstrapUrl = 'chrome-extension://[^/]+/chrome(?:app\\.html|bgpage\\.html|appstyles\\.css)'; + UrlRemap.aliasUri('^' + bootstrapUrl, '^chrome-extension://[^/]+/', harnessDir + '/', false /* redirect */); + var chromeExtensionUrl = 'chrome-extension://[^\/]+/(?!!gap_exec)'; // Add the extra mapping for chrome-extension://aaaa... to point to the install location. - UrlRemap.aliasUri('^' + chromeExtensionUrl, '^' + chromeExtensionUrl, installUrl + '/www/', false /* redirect */); + // We want the /www/ for Cordova apps, and no /www/ for CRX apps. + var installSubdir = type == 'crx' ? '/' : '/www/'; + UrlRemap.aliasUri('^' + chromeExtensionUrl, '^' + chromeExtensionUrl, installUrl + installSubdir, false /* redirect */); } else { var pluginsUrl = startLocation.replace(/\/www\/.*/, '/www/plugins/'); UrlRemap.aliasUri('^' + pluginsUrl, '^' + pluginsUrl, harnessDir + '/plugins/', false /* redirect */); http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/js/ResourcesLoader.js ---------------------------------------------------------------------- diff --git a/www/cdvah/js/ResourcesLoader.js b/www/cdvah/js/ResourcesLoader.js index 982d2b5..e6faecf 100644 --- a/www/cdvah/js/ResourcesLoader.js +++ b/www/cdvah/js/ResourcesLoader.js @@ -172,7 +172,7 @@ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { - if(xhr.status === 200) { + if(xhr.status === 200 || xhr.status === 0) { deferred.resolve(xhr); } else { deferred.reject(new Error('XHR return status: ' + xhr.status + ' for url: ' + url)); http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/33d8fe23/www/cdvah/views/add.html ---------------------------------------------------------------------- diff --git a/www/cdvah/views/add.html b/www/cdvah/views/add.html index 94bb581..1818ccd 100644 --- a/www/cdvah/views/add.html +++ b/www/cdvah/views/add.html @@ -1,8 +1,9 @@ -
+
@@ -17,14 +18,14 @@
-
+

- +