diff options
| author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
| commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
| tree | e367e64a75991c554930278175d403c072de6bb8 /Tools/WebKitLauncher/WebKitLauncherURLProtocol.m | |
| parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
| download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz | |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Tools/WebKitLauncher/WebKitLauncherURLProtocol.m')
| -rw-r--r-- | Tools/WebKitLauncher/WebKitLauncherURLProtocol.m | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Tools/WebKitLauncher/WebKitLauncherURLProtocol.m b/Tools/WebKitLauncher/WebKitLauncherURLProtocol.m index 9e5685774..f1a945fd1 100644 --- a/Tools/WebKitLauncher/WebKitLauncherURLProtocol.m +++ b/Tools/WebKitLauncher/WebKitLauncherURLProtocol.m @@ -31,6 +31,10 @@ #import <Sparkle/Sparkle.h> #endif +@interface NSObject (WKBrowsingContextControllerMethods) ++ (void)registerSchemeForCustomProtocol:(NSString *)scheme; +@end + @interface WebKitLauncherURLProtocol (ImplementationDetails) -(void)handleIsWebKitLauncherAvailableJS; -(void)handleCheckForUpdates; @@ -41,6 +45,7 @@ +(void)load { + [NSClassFromString(@"WKBrowsingContextController") registerSchemeForCustomProtocol:@"x-webkit-launcher"]; [NSURLProtocol registerClass:self]; } @@ -53,6 +58,9 @@ if (!mainDocumentURL) return NO; + if ([[mainDocumentURL scheme] isEqualToString:@"file"]) + return YES; + NSString *mainDocumentHost = [mainDocumentURL host]; if (![mainDocumentHost isEqualToString:@"webkit.org"] && ![mainDocumentHost hasSuffix:@".webkit.org"]) return NO; @@ -73,6 +81,10 @@ [self handleIsWebKitLauncherAvailableJS]; return; } + if ([resourceSpecifier isEqualToString:@"webkit-version-information.js"]) { + [self handleWebKitVersionInformation]; + return; + } #if ENABLE_SPARKLE if ([resourceSpecifier isEqualToString:@"check-for-updates"]) { [self handleCheckForUpdates]; @@ -98,6 +110,26 @@ [client URLProtocolDidFinishLoading:self]; } +-(void)handleWebKitVersionInformation +{ + id client = [self client]; + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/javascript" expectedContentLength:0 textEncodingName:@"utf-8"]; + [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed]; + [response release]; + + NSBundle *bundle = webKitLauncherBundle(); + int revision = [[[bundle infoDictionary] valueForKey:(NSString *)kCFBundleVersionKey] intValue]; + NSString *branch = [NSString stringWithContentsOfURL:[bundle URLForResource:@"BRANCH" withExtension:nil] encoding:NSUTF8StringEncoding error:0]; + branch = [branch stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (!branch) + branch = @"trunk"; + + NSString *script = [NSString stringWithFormat:@"var webKitRevision = %d; var webKitBranch = \"%@\";", revision, branch]; + NSData *data = [script dataUsingEncoding:NSUTF8StringEncoding]; + [client URLProtocol:self didLoadData:data]; + [client URLProtocolDidFinishLoading:self]; +} + #if ENABLE_SPARKLE -(void)handleCheckForUpdates { @@ -115,7 +147,7 @@ -(void)resourceNotFound { id client = [self client]; - NSDictionary *infoDictionary = [NSDictionary dictionaryWithObject:NSErrorFailingURLStringKey forKey:[[self request] URL]]; + NSDictionary *infoDictionary = [NSDictionary dictionaryWithObject:NSURLErrorFailingURLStringErrorKey forKey:[[self request] URL]]; NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:infoDictionary]; [client URLProtocol:self didFailWithError:error]; } |
