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 2014/01/06 21:25:47 UTC

[07/13] git commit: Fix launching of Chrome apps.

Fix launching of Chrome apps.


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

Branch: refs/heads/master
Commit: 062ce6a0e564cbd0169d09ae2dd65b3aa04f1efc
Parents: cc307cc
Author: Braden Shepherdson <br...@gmail.com>
Authored: Mon Nov 25 14:55:24 2013 -0800
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Mon Jan 6 15:24:12 2014 -0500

----------------------------------------------------------------------
 UrlRemap/src/ios/UrlRemap.m | 12 ++++++------
 www/cdvah/js/Installer.js   | 12 ++++++++++--
 2 files changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/062ce6a0/UrlRemap/src/ios/UrlRemap.m
----------------------------------------------------------------------
diff --git a/UrlRemap/src/ios/UrlRemap.m b/UrlRemap/src/ios/UrlRemap.m
index dfc8e7d..995a898 100644
--- a/UrlRemap/src/ios/UrlRemap.m
+++ b/UrlRemap/src/ios/UrlRemap.m
@@ -164,17 +164,17 @@ static NSMutableArray* gRerouteParams = nil;
 
 - (void)issueNotFoundResponse {
     NSURL* url = [[self request] URL];
-    NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url statusCode:404 HTTPVersion:@"HTTP/1.1" headerFields:@{}];
+    NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url statusCode:404 HTTPVersion:@"HTTP/1.1" headerFields:@{ @"Access-Control-Allow-Origin": @"*" }];
     [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
     [[self client] URLProtocolDidFinishLoading:self];
 }
 
-- (void)issueNSURLResponseForUrl:(NSURL*)url {
+- (void)issueNSURLResponseForUrl:(NSURL*)url origUrl:(NSURL*)origUrl {
     if ([[url scheme] isEqualToString:@"file"]) {
         NSString* path = [url path];
         FILE* fp = fopen([path UTF8String], "r");
         if (fp) {
-            NSURLResponse *response = [[NSURLResponse alloc] initWithURL:url MIMEType:@"text/html" expectedContentLength:-1 textEncodingName:@"utf8"];//[[NSHTTPURLResponse alloc] initWithURL:url statusCode:200 HTTPVersion:@"HTTP/1.1" headerFields:@{}];
+            NSURLResponse *response = [[NSURLResponse alloc] initWithURL:origUrl MIMEType:@"text/html" expectedContentLength:-1 textEncodingName:@"utf8"];
             [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
 
             char* buf = malloc(32768);
@@ -212,7 +212,7 @@ static NSMutableArray* gRerouteParams = nil;
 - (void)startLoading {
     NSURLRequest* request = [self request];
     NSString* urlString = [[request URL] absoluteString];
-    
+
     RouteParams* params = [UrlRemapURLProtocol getChosenParams:urlString forInjection:NO];
     NSRange wholeStringRange = NSMakeRange(0, [urlString length]);
     NSString* newUrlString = [params->_replaceRegex stringByReplacingMatchesInString:urlString options:0 range:wholeStringRange withTemplate:params->_replacer];
@@ -222,13 +222,13 @@ static NSMutableArray* gRerouteParams = nil;
     
     // iOS 6+ just gives "Frame load interrupted" when you try and feed it data via a URLProtocol.
     // http://stackoverflow.com/questions/12058203/using-a-custom-nsurlprotocol-on-ios-for-file-urls-causes-frame-load-interrup/19432303
+    NSURL* pageUrl = params->_redirectToReplacedUrl ? newUrl : [request URL];
     if (isTopLevelNavigation) {
-        NSURL* pageUrl = params->_redirectToReplacedUrl ? newUrl : [request URL];
         [self issueTopLevelRedirect:newUrl origURL:pageUrl];
     } else if(params->_redirectToReplacedUrl) {
         [self issueRedirectResponseForUrl:newUrl];
     } else {
-        [self issueNSURLResponseForUrl:newUrl];
+        [self issueNSURLResponseForUrl:newUrl origUrl:pageUrl];
     }
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/062ce6a0/www/cdvah/js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js
index 5cd4a42..7c2c2da 100644
--- a/www/cdvah/js/Installer.js
+++ b/www/cdvah/js/Installer.js
@@ -114,8 +114,16 @@
                 // Override cordova.js, cordova_plugins.js, and www/plugins to point at bundled plugins.
                 UrlRemap.aliasUri('/cordova\\.js.*', '.+', harnessDir + '/cordova.js', false /* redirect */);
                 UrlRemap.aliasUri('/cordova_plugins\\.js.*', '.+', harnessDir + '/cordova_plugins.js', false /* redirect */);
-                var pluginsUrl = startLocation.replace(/\/www\/.*/, '/www/plugins/');
-                UrlRemap.aliasUri('^' + pluginsUrl, '^' + pluginsUrl, harnessDir + '/plugins/', false /* redirect */);
+                if (startLocation.indexOf('chrome-extension://') === 0) {
+                    var pluginsUrl = 'chrome-extension://[^\/]+/plugins/';
+                    UrlRemap.aliasUri('^' + pluginsUrl, '^' + pluginsUrl, harnessDir + '/plugins/', 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 */);
+                } else {
+                    var pluginsUrl = startLocation.replace(/\/www\/.*/, '/www/plugins/');
+                    UrlRemap.aliasUri('^' + pluginsUrl, '^' + pluginsUrl, harnessDir + '/plugins/', false /* redirect */);
+                }
                 // Make any references to www/ point to the app's install location.
                 UrlRemap.aliasUri('^' + harnessDir, '^' + harnessDir, installUrl + '/www', false /* redirect */);
                 // Set-up app-harness: scheme to point at the harness.