cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [4/8] git commit: Bug fixes. Include cordova_plugins. Fixed ResourceLoader.ensureDir.
Date Tue, 30 Apr 2013 15:04:00 GMT
Bug fixes. Include cordova_plugins. Fixed ResourceLoader.ensureDir.


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

Branch: refs/heads/master
Commit: bc673ba67d785f65b07e8ccd5c01111e0e5b2d8e
Parents: ee3be7c
Author: Shravan Narayan <shravanrn@google.com>
Authored: Fri Apr 26 14:33:49 2013 -0400
Committer: Shravan Narayan <shravanrn@google.com>
Committed: Fri Apr 26 14:38:08 2013 -0400

----------------------------------------------------------------------
 .../src/ios/CordovaAppHarnessRedirect.m            |   23 +++---
 www/cdvh_files/www/cordova_plugins.json            |    1 +
 www/js/AppsService.js                              |    8 +-
 www/js/CdvhPackageHandler.js                       |   29 +++++---
 www/js/ResourcesLoader.js                          |   63 ++++++++++-----
 5 files changed, 79 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/bc673ba6/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
----------------------------------------------------------------------
diff --git a/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m b/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
index 0b0eb1c..0753855 100644
--- a/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
+++ b/plugins/CordovaAppHarnessRedirect/src/ios/CordovaAppHarnessRedirect.m
@@ -26,6 +26,9 @@
 - (void)issueNotFoundResponse;
 @end
 
+NSString* const cdvAppHarnessURLScheme = @"cdv-app-harness";
+NSString* const cdvAppHarnessDirectURLPrefix = @"cdv-app-harness:///direct";
+NSString* const cdvAppHarnessRedirectURLPrefix = @"cdv-app-harness:///redirect";
 static NSString* pathPrefix;
 static UIWebView* uiwebview;
 
@@ -39,7 +42,7 @@ static UIWebView* uiwebview;
     uiwebview = theWebView;
     if (self) {
         [NSURLProtocol registerClass:[AppHarnessURLProtocol class]];
-        pathPrefix = [[NSBundle mainBundle] pathForResource:@"chromeapp.html" ofType:@""
inDirectory:@"www"];
+        pathPrefix = [[NSBundle mainBundle] pathForResource:@"cordova.js" ofType:@"" inDirectory:@"www"];
         NSRange range = [pathPrefix rangeOfString:@"/www/"];
         //trim trailing slash after www
         range.length--;
@@ -60,9 +63,9 @@ static UIWebView* uiwebview;
     NSURL* url = [request URL];
     NSString* schemeString = [url scheme];
 
-    if([schemeString isEqualToString:@"cdv-app-harness"]){
+    if([schemeString isEqualToString:cdvAppHarnessURLScheme]){
         NSString* urlString = [url absoluteString];
-        return [urlString hasPrefix:@"cdv-app-harness:///redirect"] || [urlString hasPrefix:@"cdv-app-harness:///direct"];
+        return [urlString hasPrefix:cdvAppHarnessRedirectURLPrefix] || [urlString hasPrefix:cdvAppHarnessDirectURLPrefix];
     }
     return NO;
 }
@@ -108,7 +111,7 @@ static UIWebView* uiwebview;
     if([uiwebview isLoading]) {
         [uiwebview stopLoading];
     }
-    NSString *newUrlString = [NSString stringWithFormat:@"file://%@%@", pathPrefix, file];
+    NSString *newUrlString = [NSString stringWithFormat:@"file://%@%@", [pathPrefix stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
file];
     NSURL *newUrl = [NSURL URLWithString:newUrlString];
     NSURLRequest *request = [NSURLRequest requestWithURL:newUrl];
     [uiwebview loadRequest:request];
@@ -120,18 +123,16 @@ static UIWebView* uiwebview;
     NSString* schemeString = [url scheme];
     BOOL issuedResponse = NO;
 
-    if([schemeString isEqualToString:@"cdv-app-harness"]){
+    if([schemeString isEqualToString:cdvAppHarnessURLScheme]){
         NSString* urlString = [url absoluteString];
-        NSString* redirectPrefix = @"cdv-app-harness:///redirect";
-        NSString* directPrefix = @"cdv-app-harness:///direct";
         
-        if([urlString hasPrefix:redirectPrefix]){
+        if([urlString hasPrefix:cdvAppHarnessRedirectURLPrefix]){
             issuedResponse = YES;
-            NSString* path = [urlString substringFromIndex:redirectPrefix.length];
+            NSString* path = [urlString substringFromIndex:cdvAppHarnessRedirectURLPrefix.length];
             [self issueRedirectResponseForFile:path];
-        } else if([urlString hasPrefix:directPrefix]){
+        } else if([urlString hasPrefix:cdvAppHarnessDirectURLPrefix]){
             issuedResponse = YES;
-            NSString* path = [urlString substringFromIndex:directPrefix.length];
+            NSString* path = [urlString substringFromIndex:cdvAppHarnessDirectURLPrefix.length];
             [self issueNSURLResponseForFile:path];
         }
     }

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/bc673ba6/www/cdvh_files/www/cordova_plugins.json
----------------------------------------------------------------------
diff --git a/www/cdvh_files/www/cordova_plugins.json b/www/cdvh_files/www/cordova_plugins.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/www/cdvh_files/www/cordova_plugins.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/bc673ba6/www/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/js/AppsService.js b/www/js/AppsService.js
index ef9b2b1..3683d46 100644
--- a/www/js/AppsService.js
+++ b/www/js/AppsService.js
@@ -10,10 +10,7 @@
         function grabExtensionFromUrl(url) {
             var lastSegment = url.split("#")[0].split("?")[0].split("/").pop();
             var dotLocation = lastSegment.lastIndexOf(".");
-            var extension = "";
-            if(dotLocation !== -1) {
-                extension = lastSegment.substring(dotLocation + 1);
-            }
+            var extension = (dotLocation !== -1)? lastSegment.substring(dotLocation + 1)
: "";
             return extension;
         }
 
@@ -55,6 +52,9 @@
         }
 
         function getAppStartPageFromAppLocation(appLocation) {
+            if(appLocation.indexOf("file://") === 0){
+                appLocation = appLocation.substring("file://".length);
+            }
             appLocation += (appLocation.substring(appLocation.length - 1) === "/") ? "" :
"/";
             var configFile = appLocation + "config." + platformId + ".xml";
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/bc673ba6/www/js/CdvhPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/js/CdvhPackageHandler.js b/www/js/CdvhPackageHandler.js
index e991d63..c5205e6 100644
--- a/www/js/CdvhPackageHandler.js
+++ b/www/js/CdvhPackageHandler.js
@@ -3,20 +3,29 @@
     /* 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("cdvh", {
             extractPackageToDirectory : function (fileName, outputDirectory){
                 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);
+                    return Q.all([
+                        copyFile("cdv-app-harness:///direct/cordova.js", outputDirectory
+ "/www/cordova.js"),
+                        copyFile("cdv-app-harness:///direct/cdvh_files/www/cordova_plugins.json",
outputDirectory + "/www/cordova_plugins.json")
+                    ]);
                 });
             }
         });

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/bc673ba6/www/js/ResourcesLoader.js
----------------------------------------------------------------------
diff --git a/www/js/ResourcesLoader.js b/www/js/ResourcesLoader.js
index 07c2bcc..c26e465 100644
--- a/www/js/ResourcesLoader.js
+++ b/www/js/ResourcesLoader.js
@@ -65,11 +65,9 @@
             return str && str.replace(/^\s+|\s+$/g, "");
         }
 
-        function makeRelativeToRoot(path) {
-            if(path && (path.charAt(0) === "/")) {
-                path = path.substring(1);
-            } else if(path && path.substring(0, 8) === "file:///") {
-                path = path.substring(8);
+        function fixFilePath(path) {
+            if(path && path.indexOf("file://") === 0) {
+                path = path.substring("file://".length);
             }
             return path;
         }
@@ -144,27 +142,52 @@
             return path;
         }
 
+        function getPathSegments(path){
+            //truncate leading and trailing slashes
+            if(path.charAt(0) === "/"){
+                path = path.substring(1);
+            }
+            if(path.charAt(path.length - 1) === "/"){
+                path = path.substring(0, path.length - 1);
+            }
+            var segments = path.split("/");
+            return segments;
+        }
+
+        function ensureSingleDirectoryExists(directory){
+            var deferred = Q.defer();
+
+            var gotDirEntry = function(dirEntry) {
+                deferred.resolve(dirEntry.fullPath);
+            };
+
+            var failedToGetDirEntry = function(error) {
+                var str = "There was an error checking the directory: " + directory + " "
+ JSON.stringify(error);
+                deferred.reject(new Error(str));
+            };
+
+            fs.root.getDirectory(directory, {create: true, exclusive: false}, gotDirEntry,
failedToGetDirEntry);
+            return deferred.promise;
+        }
+
         return {
             // returns a promise with a full path to the dir
             ensureDirectoryExists : function(directory) {
                 return initialiseFileSystem()
                 .then(function(){
-                    var deferred = Q.defer();
-
                     directory = truncateToDirectoryPath(directory);
-                    directory = makeRelativeToRoot(directory);
-
-                    var gotDirEntry = function(dirEntry) {
-                        deferred.resolve(dirEntry.fullPath);
-                    };
-
-                    var failedToGetDirEntry = function(error) {
-                        var str = "There was an error checking the directory: " + directory
+ " " + JSON.stringify(error);
-                        deferred.reject(new Error(str));
-                    };
-
-                    fs.root.getDirectory(directory, {create: true, exclusive: false}, gotDirEntry,
failedToGetDirEntry);
-                    return deferred.promise;
+                    directory = fixFilePath(directory);
+                    var segments = getPathSegments(directory);
+                    var currentDir = directory.charAt(0) === "/"? "/" : "";
+                    var promiseArr = [];
+                    while(segments.length !== 0) {
+                        currentDir +=  segments.shift() + "/";
+                        promiseArr.push(ensureSingleDirectoryExists(currentDir));
+                    }
+                    return Q.all(promiseArr);
+                })
+                .then(function(paths){
+                    return paths[paths.length - 1];
                 });
             },
 


Mime
View raw message