You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/05/23 22:03:46 UTC
[23/30] git commit: Support chrome webstore links. Updated to support
new app dir structure.
Support chrome webstore links. Updated to support new app dir structure.
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/9f0d462b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/9f0d462b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/9f0d462b
Branch: refs/heads/master
Commit: 9f0d462b4b1fd9137765fe8d85e076146daf4abc
Parents: 4d4e0b4
Author: Shravan Narayan <sh...@google.com>
Authored: Sun May 12 01:12:14 2013 -0400
Committer: Braden Shepherdson <br...@google.com>
Committed: Thu May 16 15:29:29 2013 -0400
----------------------------------------------------------------------
www/cdvah_index.html | 1 +
www/cdvah_js/CrxDownloader.js | 31 ++++++++++++++++
www/cdvah_js/CrxPackageHandler.js | 60 ++++++++++++++++++--------------
3 files changed, 66 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/9f0d462b/www/cdvah_index.html
----------------------------------------------------------------------
diff --git a/www/cdvah_index.html b/www/cdvah_index.html
index 3eaede1..77bbd2b 100644
--- a/www/cdvah_index.html
+++ b/www/cdvah_index.html
@@ -13,6 +13,7 @@
<script type="text/javascript" src="cdvah_js/AppsService.js"></script>
<script type="text/javascript" src="cdvah_js/AppBundleAlias.js"></script>
<script type="text/javascript" src="cdvah_js/KnownExtensionDownloader.js"></script>
+ <script type="text/javascript" src="cdvah_js/CrxDownloader.js"></script>
<script type="text/javascript" src="cdvah_js/CdvhPackageHandler.js"></script>
<script type="text/javascript" src="cdvah_js/CrxPackageHandler.js"></script>
<script type="text/javascript" src="cdvah_js/ListCtrl.js"></script>
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/9f0d462b/www/cdvah_js/CrxDownloader.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/CrxDownloader.js b/www/cdvah_js/CrxDownloader.js
new file mode 100644
index 0000000..0388a08
--- /dev/null
+++ b/www/cdvah_js/CrxDownloader.js
@@ -0,0 +1,31 @@
+(function(){
+ "use strict";
+ /* global myApp */
+ myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
+
+ function isChromeWebStoreUri(pattern){
+ var regexUri = /^https:\/\/chrome.google.com\/webstore\/detail\/.*?\/[a-z]{32}((\?|#|\/).*)?$/;
+ var ret = (pattern.search(regexUri) !== -1);
+ return ret;
+ }
+
+ AppsService.registerPatternDownloader({
+ canHandleSourcePattern : isChromeWebStoreUri,
+
+ downloadFromPattern : function (appName, pattern, tempDirectory) {
+ var fileName = tempDirectory + appName + ".crx";
+ var chromeAppIdRegex = /^https:\/\/chrome\.google\.com\/webstore\/detail\/.*?\/([a-z]{32})/;
+ // Two results expected.
+ // 1 - the entire match of the regex
+ // 2 - the match of the capture group i.e. the app id
+ var matches = pattern.match(chromeAppIdRegex);
+ if(!matches || matches.length !== 2){
+ throw new Error("Invalid url for chrome web store");
+ }
+ var sourceUrl = "https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D" + matches[1] + "%26uc";
+ return ResourcesLoader.downloadFromUrl(sourceUrl, fileName);
+ }
+ }, 500 /* assign a priority */);
+
+ }]);
+})();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/9f0d462b/www/cdvah_js/CrxPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/CrxPackageHandler.js b/www/cdvah_js/CrxPackageHandler.js
index 2627fd7..e4b4e7b 100644
--- a/www/cdvah_js/CrxPackageHandler.js
+++ b/www/cdvah_js/CrxPackageHandler.js
@@ -1,7 +1,9 @@
(function(){
"use strict";
/* global myApp */
- myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
+ myApp.run(["AppsService", "ResourcesLoader", "ContextMenuInjectScript", function(AppsService, ResourcesLoader, ContextMenuInjectScript){
+
+ var platformId = cordova.require("cordova/platform").id;
function copyFile(startUrl, targetLocation){
/************ Begin Work around for File system bug ************/
@@ -19,36 +21,42 @@
}
AppsService.registerPackageHandler("crx", {
- extractPackageToDirectory : function (fileName, outputDirectory){
- return ResourcesLoader.ensureDirectoryExists(outputDirectory + "/www")
- .then(function(){
- return ResourcesLoader.extractZipFile(fileName, outputDirectory + "/www");
- })
+ extractPackageToDirectory : function (appName, fileName, outputDirectory){
+ 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(){
return Q.all([
- copyFile("cdv-app-harness:///direct/cordova.js", outputDirectory + "/www/cordova.js"),
- copyFile("cdv-app-harness:///direct/crx_files/config.android.xml", outputDirectory + "/config.android.xml"),
- copyFile("cdv-app-harness:///direct/crx_files/config.ios.xml", outputDirectory + "/config.ios.xml"),
- copyFile("cdv-app-harness:///direct/crx_files/www/cordova_plugins.json", outputDirectory + "/www/cordova_plugins.json"),
- copyFile("cdv-app-harness:///direct/crx_files/www/chromeapp.html", outputDirectory + "/www/chromeapp.html"),
- copyFile("cdv-app-harness:///direct/crx_files/www/chromeappstyles.css", outputDirectory + "/www/chromeappstyles.css"),
- copyFile("cdv-app-harness:///direct/crx_files/www/chromebgpage.html", outputDirectory + "/www/chromebgpage.html"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/app/runtime.js", outputDirectory + "/www/plugins/chrome/api/app/runtime.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/app/window.js", outputDirectory + "/www/plugins/chrome/api/app/window.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/bootstrap.js", outputDirectory + "/www/plugins/chrome/api/bootstrap.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/helpers/stubs.js", outputDirectory + "/www/plugins/chrome/api/helpers/stubs.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/mobile.js", outputDirectory + "/www/plugins/chrome/api/mobile.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome/api/runtime.js", outputDirectory + "/www/plugins/chrome/api/runtime.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.common/events.js", outputDirectory + "/www/plugins/chrome.common/events.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.fileSystem/fileSystem.js", outputDirectory + "/www/plugins/chrome.fileSystem/fileSystem.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.i18n/i18n.js", outputDirectory + "/www/plugins/chrome.i18n/i18n.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.identity/identity.js", outputDirectory + "/www/plugins/chrome.identity/identity.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.socket/socket.js", outputDirectory + "/www/plugins/chrome.socket/socket.js"),
- copyFile("cdv-app-harness:///direct/crx_files/www/plugins/chrome.storage/storage.js", outputDirectory + "/www/plugins/chrome.storage/storage.js")
+ copyFile("app-bundle:///cordova.js", cordovaFile),
+ copyFile("app-bundle:///crx_files/config." + platformId + ".xml", platformDirectory + "config.xml"),
+ copyFile("app-bundle:///crx_files/www/cordova_plugins.json", platformWWWDirectory + "cordova_plugins.json"),
+ copyFile("app-bundle:///crx_files/www/chromeapp.html", platformWWWDirectory + "chromeapp.html"),
+ copyFile("app-bundle:///crx_files/www/chromeappstyles.css", platformWWWDirectory + "chromeappstyles.css"),
+ copyFile("app-bundle:///crx_files/www/chromebgpage.html", platformWWWDirectory + "chromebgpage.html"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/app/runtime.js", platformWWWDirectory + "plugins/chrome/api/app/runtime.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/app/window.js", platformWWWDirectory + "plugins/chrome/api/app/window.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/bootstrap.js", platformWWWDirectory + "plugins/chrome/api/bootstrap.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/helpers/stubs.js", platformWWWDirectory + "plugins/chrome/api/helpers/stubs.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/mobile.js", platformWWWDirectory + "plugins/chrome/api/mobile.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome/api/runtime.js", platformWWWDirectory + "plugins/chrome/api/runtime.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.common/events.js", platformWWWDirectory + "plugins/chrome.common/events.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.fileSystem/fileSystem.js", platformWWWDirectory + "plugins/chrome.fileSystem/fileSystem.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.i18n/i18n.js", platformWWWDirectory + "plugins/chrome.i18n/i18n.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.identity/identity.js", platformWWWDirectory + "plugins/chrome.identity/identity.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.socket/socket.js", platformWWWDirectory + "plugins/chrome.socket/socket.js"),
+ copyFile("app-bundle:///crx_files/www/plugins/chrome.storage/storage.js", platformWWWDirectory + "plugins/chrome.storage/storage.js")
]);
+ })
+ .then(function(){
+ return ResourcesLoader.appendFileContents(cordovaFile, dataToAppend);
});
}
});
-
}]);
})();
\ No newline at end of file