You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/06/25 20:58:01 UTC

[3/9] git commit: Remove redundant and unused duplicate file, and improve Chrome loading

Remove redundant and unused duplicate file, and improve Chrome loading

It now draws on the same Chrome app bootstrap files as exist in the app
harness itself. This ensures that the Javascript always matches the
native side.


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/e80bb1dc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/e80bb1dc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/e80bb1dc

Branch: refs/heads/master
Commit: e80bb1dcb813eb04f0f4177a7ecdd634fdfc84d4
Parents: a7a877b
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 14 09:55:42 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Thu Jun 20 10:43:42 2013 -0400

----------------------------------------------------------------------
 www/cdvah_js/CrxPackageHandler.js | 69 ++++++++++++++++++++++++++++++++++
 www/js/CrxPackageHandler.js       | 54 --------------------------
 2 files changed, 69 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/e80bb1dc/www/cdvah_js/CrxPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/CrxPackageHandler.js b/www/cdvah_js/CrxPackageHandler.js
new file mode 100644
index 0000000..8019d5d
--- /dev/null
+++ b/www/cdvah_js/CrxPackageHandler.js
@@ -0,0 +1,69 @@
+(function(){
+    "use strict";
+    /* global myApp */
+    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 ************/
+            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(){
+                    // Read cordova_plugins.json and use it to copy the plugin Javascript files.
+                    return ResourcesLoader.xhrGet("app-bundle:///cordova_plugins.json");
+                })
+                .then(function(xhr) {
+                    return JSON.parse(xhr.responseText.trim());
+                })
+                .then(function(plugins){
+                    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.json", platformWWWDirectory + "cordova_plugins.json"),
+                        copyFile("app-bundle:///chromeapp.html", platformWWWDirectory + "chromeapp.html"),
+                        copyFile("app-bundle:///chromeappstyles.css", platformWWWDirectory + "chromeappstyles.css"),
+                        copyFile("app-bundle:///chromebgpage.html", platformWWWDirectory + "chromebgpage.html")
+                    ];
+
+                    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/e80bb1dc/www/js/CrxPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/js/CrxPackageHandler.js b/www/js/CrxPackageHandler.js
deleted file mode 100644
index 2627fd7..0000000
--- a/www/js/CrxPackageHandler.js
+++ /dev/null
@@ -1,54 +0,0 @@
-(function(){
-    "use strict";
-    /* global myApp */
-    myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
-
-        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 (fileName, outputDirectory){
-                return ResourcesLoader.ensureDirectoryExists(outputDirectory + "/www")
-                .then(function(){
-                    return ResourcesLoader.extractZipFile(fileName, outputDirectory + "/www");
-                })
-                .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")
-                    ]);
-                });
-            }
-        });
-
-    }]);
-})();
\ No newline at end of file