Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix launching of Chrome apps.
  • Loading branch information
bshepherdson committed Jan 6, 2014
1 parent cc307cc commit 062ce6a0e564cbd0169d09ae2dd65b3aa04f1efc
Showing 2 changed files with 16 additions and 8 deletions.
@@ -164,17 +164,17 @@ + (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)request {

- (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 @@ - (void)issueTopLevelRedirect:(NSURL*)url origURL:(NSURL*)origURL {
- (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 @@ - (void)startLoading {

// 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];
}
}

@@ -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.

0 comments on commit 062ce6a

Please sign in to comment.