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/04/30 17:03:59 UTC

[3/8] git commit: Copy cordova.js instead of rerouting

Copy cordova.js instead of rerouting

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

Branch: refs/heads/master
Commit: ee3be7c895021ae2afe19eef039cb3cff4115510
Parents: 911968c
Author: Shravan Narayan <sh...@google.com>
Authored: Thu Apr 25 20:14:22 2013 -0400
Committer: Shravan Narayan <sh...@google.com>
Committed: Thu Apr 25 20:14:22 2013 -0400

----------------------------------------------------------------------
 plugins/CordovaAppHarnessRedirect/plugin.xml       |    1 -
 .../src/android/CordovaAppHarnessRedirect.java     |   11 +----
 .../src/ios/CordovaAppHarnessRedirect.m            |   14 +-----
 www/js/AppsService.js                              |    6 ++-
 www/js/CdvhPackageHandler.js                       |   37 ++++++--------
 www/js/ResourcesLoader.js                          |   39 +++++++++++++++
 6 files changed, 61 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/plugins/CordovaAppHarnessRedirect/plugin.xml
----------------------------------------------------------------------
diff --git a/plugins/CordovaAppHarnessRedirect/plugin.xml b/plugins/CordovaAppHarnessRedirect/plugin.xml
index 2deef66..a751464 100644
--- a/plugins/CordovaAppHarnessRedirect/plugin.xml
+++ b/plugins/CordovaAppHarnessRedirect/plugin.xml
@@ -14,7 +14,6 @@
 
     <config-file target="res/xml/config.xml" parent="/cordova/plugins">
       <plugin name="CordovaAppHarnessRedirect" value="org.apache.cordova.cordovaappharness.CordovaAppHarnessRedirect">
-        <url-filter value="file://" />
         <url-filter value="cdv-app-harness://" />
       </plugin>
     </config-file>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/plugins/CordovaAppHarnessRedirect/src/android/CordovaAppHarnessRedirect.java
----------------------------------------------------------------------
diff --git a/plugins/CordovaAppHarnessRedirect/src/android/CordovaAppHarnessRedirect.java b/plugins/CordovaAppHarnessRedirect/src/android/CordovaAppHarnessRedirect.java
index ed2d7b5..fbb68d0 100644
--- a/plugins/CordovaAppHarnessRedirect/src/android/CordovaAppHarnessRedirect.java
+++ b/plugins/CordovaAppHarnessRedirect/src/android/CordovaAppHarnessRedirect.java
@@ -30,9 +30,6 @@ import android.webkit.WebResourceResponse;
 
 public class CordovaAppHarnessRedirect extends CordovaPlugin {
 
-    // Ensure we we redirect any file:///*/cordova.js uri's to the the cordova.js located in the assets
-    // Ensure we redirect any file:///*/__cordovaappharness_contextMenu_{menu_choice} uri's to the correct locations
-
     // Returns an empty response, so that an error of unknown url is not displayed.
     // Used when we are loading a new url immediately
     private WebResourceResponse getEmptyWebResourceResponse()
@@ -63,13 +60,7 @@ public class CordovaAppHarnessRedirect extends CordovaPlugin {
         Uri uri = Uri.parse(url);
         String scheme = uri.getScheme();
 
-        // we need reroute any requests to cordova.js from an app from the disk to the modified cordova.js in the bundle
-        if("file".equals(scheme)) {
-            String fileName = uri.getLastPathSegment();
-            if("cordova.js".equals(fileName)) {
-                return getWebResourceResponseForFile("/cordova.js");
-            }
-        } else if("cdv-app-harness".equals(scheme)) {
+        if("cdv-app-harness".equals(scheme)) {
             String redirectPrefix = "cdv-app-harness:///redirect";
             String directPrefix = "cdv-app-harness:///direct";
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
----------------------------------------------------------------------
diff --git a/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m b/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
index ca2649b..0b0eb1c 100644
--- a/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
+++ b/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
@@ -60,12 +60,6 @@ static UIWebView* uiwebview;
     NSURL* url = [request URL];
     NSString* schemeString = [url scheme];
 
-    // we need reroute any requests to cordova.js from an app from the disk to the modified cordova.js in the bundle
-    if([schemeString isEqualToString:@"file"]) {
-        NSString* fileName = [url lastPathComponent];
-        return [fileName isEqualToString:@"cordova.js"];
-    }
-
     if([schemeString isEqualToString:@"cdv-app-harness"]){
         NSString* urlString = [url absoluteString];
         return [urlString hasPrefix:@"cdv-app-harness:///redirect"] || [urlString hasPrefix:@"cdv-app-harness:///direct"];
@@ -126,13 +120,7 @@ static UIWebView* uiwebview;
     NSString* schemeString = [url scheme];
     BOOL issuedResponse = NO;
 
-    if([schemeString isEqualToString:@"file"]) {
-        NSString* fileName = [url lastPathComponent];
-        if([fileName isEqualToString:@"cordova.js"]) {
-            issuedResponse = YES;
-            [self issueNSURLResponseForFile:@"/cordova.js"];
-        }
-    } else if([schemeString isEqualToString:@"cdv-app-harness"]){
+    if([schemeString isEqualToString:@"cdv-app-harness"]){
         NSString* urlString = [url absoluteString];
         NSString* redirectPrefix = @"cdv-app-harness:///redirect";
         NSString* directPrefix = @"cdv-app-harness:///direct";

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/www/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/js/AppsService.js b/www/js/AppsService.js
index 6c6ecd1..ef9b2b1 100644
--- a/www/js/AppsService.js
+++ b/www/js/AppsService.js
@@ -115,8 +115,10 @@
                     return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + appName);
                 })
                 .then(function(appLocation) {
-                    var startLocation = getAppStartPageFromAppLocation(appLocation);
-                    document.location = startLocation;
+                    return getAppStartPageFromAppLocation(appLocation);
+                })
+                .then(function(startLocation) {
+                    window.location = startLocation;
                 });
             },
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/www/js/CdvhPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/js/CdvhPackageHandler.js b/www/js/CdvhPackageHandler.js
index 152280d..e991d63 100644
--- a/www/js/CdvhPackageHandler.js
+++ b/www/js/CdvhPackageHandler.js
@@ -1,30 +1,25 @@
 (function(){
     "use strict";
     /* global myApp */
-    myApp.run(["AppsService", function(AppsService){
+    myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
+
         AppsService.registerPackageHandler("cdvh", {
             extractPackageToDirectory : function (fileName, outputDirectory){
-                var deferred = Q.defer();
-
-                //will throw an exception if the zip plugin is not loaded
-                try {
-                    var onZipDone = function(returnCode) {
-                        if(returnCode !== 0) {
-                            deferred.reject(new Error("Something went wrong during the unzipping of: " + fileName));
-                        } else {
-                            deferred.resolve();
-                        }
-                    };
-
-                    /* global zip */
-                    zip.unzip(fileName, outputDirectory, onZipDone);
-                } catch(e) {
-                    deferred.reject(e);
-                } finally {
-                    return deferred.promise;
-                }
+                return ResourcesLoader.extractZipFile(fileName, outputDirectory)
+                .then(function(){
+                    return ResourcesLoader.xhrGet("cdv-app-harness:///direct/cordova.js");
+                })
+                .then(function(xhr){
+                    var cordovaJSPath = outputDirectory + "/www/cordova.js";
+                    /************ Begin Work around for File system bug ************/
+                    if(cordovaJSPath.indexOf("file://") === 0) {
+                        cordovaJSPath = cordovaJSPath.substring("file://".length);
+                    }
+                    /************ End Work around for File system bug **************/
+                    return ResourcesLoader.writeFileContents(cordovaJSPath, xhr.responseText);
+                });
             }
         });
-    }]);
 
+    }]);
 })();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ee3be7c8/www/js/ResourcesLoader.js
----------------------------------------------------------------------
diff --git a/www/js/ResourcesLoader.js b/www/js/ResourcesLoader.js
index 118a975..07c2bcc 100644
--- a/www/js/ResourcesLoader.js
+++ b/www/js/ResourcesLoader.js
@@ -307,6 +307,45 @@
                     dirEntry.removeRecursively(deferred.resolve, failedToDeleteDirectory);
                     return deferred.promise;
                 });
+            },
+
+            extractZipFile : function(fileName, outputDirectory){
+                var deferred = Q.defer();
+
+                //will throw an exception if the zip plugin is not loaded
+                try {
+                    var onZipDone = function(returnCode) {
+                        if(returnCode !== 0) {
+                            deferred.reject(new Error("Something went wrong during the unzipping of: " + fileName));
+                        } else {
+                            deferred.resolve();
+                        }
+                    };
+
+                    /* global zip */
+                    zip.unzip(fileName, outputDirectory, onZipDone);
+                } catch(e) {
+                    deferred.reject(e);
+                } finally {
+                    return deferred.promise;
+                }
+            },
+
+            xhrGet : function(url) {
+                var deferred = Q.defer();
+                var xhr = new XMLHttpRequest();
+                xhr.onreadystatechange = function() {
+                    if (xhr.readyState === 4) {
+                        if(xhr.status === 200) {
+                            deferred.resolve(xhr);
+                        } else {
+                            deferred.reject("XHR return status: " + xhr.statusText);
+                        }
+                    }
+                };
+                xhr.open("GET", url, true);
+                xhr.send();
+                return deferred.promise;
             }
         };
     }]);