Add a hook to the WebKit launcher application to allow a link on the nightly build...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 21 Jun 2009 22:03:23 +0000 (22:03 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 21 Jun 2009 22:03:23 +0000 (22:03 +0000)
trigger an update via the built-in software update mechanism.

Reviewed by Sam Weinig.

* WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj:
* WebKitLauncher/WebKitLauncherURLProtocol.h: Added.
* WebKitLauncher/WebKitLauncherURLProtocol.m: Added.
(+[WebKitLauncherURLProtocol load]):
(+[WebKitLauncherURLProtocol canInitWithRequest:]): Only allow use of the x-webkit-launcher scheme from .webkit.org subdomains.
(+[WebKitLauncherURLProtocol canonicalRequestForRequest:]):
(-[WebKitLauncherURLProtocol startLoading]):
(-[WebKitLauncherURLProtocol stopLoading]):
(-[WebKitLauncherURLProtocol handleIsWebKitLauncherAvailableJS]): Return a brief JavaScript snippet that can be used to programatically
determine whether the x-webkit-launcher is available and working.
(-[WebKitLauncherURLProtocol handleCheckForUpdates]): Trigger a software update on the main thread.
(-[WebKitLauncherURLProtocol resourceNotFound]): Fail with a generic "File does not exist" error.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@44920 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj
WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.h [new file with mode: 0644]
WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.m [new file with mode: 0644]

index e02a796..c79f6c8 100644 (file)
@@ -1,3 +1,23 @@
+2009-06-21  Mark Rowe  <mrowe@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Add a hook to the WebKit launcher application to allow a link on the nightly build start page to
+        trigger an update via the built-in software update mechanism.
+
+        * WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj:
+        * WebKitLauncher/WebKitLauncherURLProtocol.h: Added.
+        * WebKitLauncher/WebKitLauncherURLProtocol.m: Added.
+        (+[WebKitLauncherURLProtocol load]):
+        (+[WebKitLauncherURLProtocol canInitWithRequest:]): Only allow use of the x-webkit-launcher scheme from .webkit.org subdomains.
+        (+[WebKitLauncherURLProtocol canonicalRequestForRequest:]):
+        (-[WebKitLauncherURLProtocol startLoading]):
+        (-[WebKitLauncherURLProtocol stopLoading]):
+        (-[WebKitLauncherURLProtocol handleIsWebKitLauncherAvailableJS]): Return a brief JavaScript snippet that can be used to programatically
+        determine whether the x-webkit-launcher is available and working.
+        (-[WebKitLauncherURLProtocol handleCheckForUpdates]): Trigger a software update on the main thread.
+        (-[WebKitLauncherURLProtocol resourceNotFound]): Fail with a generic "File does not exist" error.
+
 2009-06-20  Jan Michael Alonzo  <jmalonzo@webkit.org>
 
         Reviewed by Gustavo Noronha and Xan Lopez.
index ac832c6..0f920e1 100644 (file)
@@ -21,6 +21,8 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+               5D1067640FE63758002A2868 /* WebKitLauncherURLProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D1067620FE63758002A2868 /* WebKitLauncherURLProtocol.h */; };
+               5D1067650FE63758002A2868 /* WebKitLauncherURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D1067630FE63758002A2868 /* WebKitLauncherURLProtocol.m */; };
                5D41141C0A50A9DE00C84CF0 /* VERSION in Resources */ = {isa = PBXBuildFile; fileRef = 5D41141B0A50A9DE00C84CF0 /* VERSION */; };
                5D4DF982097F89FB0083D5E5 /* start.html in Resources */ = {isa = PBXBuildFile; fileRef = 5D4DF981097F89FB0083D5E5 /* start.html */; };
                5D650F3609DB8B370075E9A8 /* WebKitNightlyEnabler.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D650F3509DB8B370075E9A8 /* WebKitNightlyEnabler.m */; };
@@ -61,6 +63,8 @@
 /* Begin PBXFileReference section */
                1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
                29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+               5D1067620FE63758002A2868 /* WebKitLauncherURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitLauncherURLProtocol.h; sourceTree = "<group>"; };
+               5D1067630FE63758002A2868 /* WebKitLauncherURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebKitLauncherURLProtocol.m; sourceTree = "<group>"; };
                5D41141B0A50A9DE00C84CF0 /* VERSION */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = VERSION; sourceTree = "<group>"; };
                5D4DF981097F89FB0083D5E5 /* start.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html; path = start.html; sourceTree = "<group>"; };
                5D650F3409DB8B280075E9A8 /* WebKitNightlyEnabler.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebKitNightlyEnabler.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                29B97315FDCFA39411CA2CEA /* Source */ = {
                        isa = PBXGroup;
                        children = (
+                               5D1067620FE63758002A2868 /* WebKitLauncherURLProtocol.h */,
+                               5D1067630FE63758002A2868 /* WebKitLauncherURLProtocol.m */,
                                5DA88F790FC813EB00AB2F62 /* WebKitNightlyEnabler.h */,
                                5D650F3509DB8B370075E9A8 /* WebKitNightlyEnabler.m */,
                                5DA88F6B0FC8136000AB2F62 /* WebKitNightlyEnablerSparkle.h */,
                        files = (
                                5DA88F6D0FC8136000AB2F62 /* WebKitNightlyEnablerSparkle.h in Headers */,
                                5DA88F7A0FC813EB00AB2F62 /* WebKitNightlyEnabler.h in Headers */,
+                               5D1067640FE63758002A2868 /* WebKitLauncherURLProtocol.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        files = (
                                5D650F3609DB8B370075E9A8 /* WebKitNightlyEnabler.m in Sources */,
                                5DA88F6E0FC8136000AB2F62 /* WebKitNightlyEnablerSparkle.m in Sources */,
+                               5D1067650FE63758002A2868 /* WebKitLauncherURLProtocol.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.h b/WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.h
new file mode 100644 (file)
index 0000000..9159f5d
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface WebKitLauncherURLProtocol : NSURLProtocol
+{
+
+}
+
+@end
diff --git a/WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.m b/WebKitTools/WebKitLauncher/WebKitLauncherURLProtocol.m
new file mode 100644 (file)
index 0000000..9e56857
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import "WebKitLauncherURLProtocol.h"
+#import "WebKitNightlyEnabler.h"
+
+#if ENABLE_SPARKLE
+#import <AppKit/AppKit.h>
+#import <Sparkle/Sparkle.h>
+#endif
+
+@interface WebKitLauncherURLProtocol (ImplementationDetails)
+-(void)handleIsWebKitLauncherAvailableJS;
+-(void)handleCheckForUpdates;
+-(void)resourceNotFound;
+@end
+
+@implementation WebKitLauncherURLProtocol
+
++(void)load
+{
+    [NSURLProtocol registerClass:self];
+}
+
++(BOOL)canInitWithRequest:(NSURLRequest *)request
+{
+    if (![[[request URL] scheme] isEqualToString:@"x-webkit-launcher"])
+        return NO;
+
+    NSURL *mainDocumentURL = [request mainDocumentURL];
+    if (!mainDocumentURL)
+        return NO;
+
+    NSString *mainDocumentHost = [mainDocumentURL host];
+    if (![mainDocumentHost isEqualToString:@"webkit.org"] && ![mainDocumentHost hasSuffix:@".webkit.org"])
+        return NO;
+
+    return YES;
+}
+
++(NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
+{
+    return request;
+}
+
+-(void)startLoading
+{
+    NSURLRequest *request = [self request];
+    NSString *resourceSpecifier = [[request URL] resourceSpecifier];
+    if ([resourceSpecifier isEqualToString:@"is-x-webkit-launcher-available.js"]) {
+        [self handleIsWebKitLauncherAvailableJS];
+        return;
+    }
+#if ENABLE_SPARKLE
+    if ([resourceSpecifier isEqualToString:@"check-for-updates"]) {
+        [self handleCheckForUpdates];
+        return;
+    }
+#endif
+    [self resourceNotFound];
+}
+
+-(void)stopLoading
+{
+}
+
+-(void)handleIsWebKitLauncherAvailableJS
+{
+    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];
+
+    NSData *data = [@"var isWebKitLauncherAvailable = true;" dataUsingEncoding:NSUTF8StringEncoding];
+    [client URLProtocol:self didLoadData:data];
+    [client URLProtocolDidFinishLoading:self];
+}
+
+#if ENABLE_SPARKLE
+-(void)handleCheckForUpdates
+{
+    id client = [self client];
+    NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/plain" expectedContentLength:0 textEncodingName:@"utf-8"];
+    [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+    [response release];
+
+    SUUpdater *updater = [SUUpdater updaterForBundle:webKitLauncherBundle()];
+    [updater performSelectorOnMainThread:@selector(checkForUpdates:) withObject:self waitUntilDone:NO];
+    [client URLProtocolDidFinishLoading:self];
+}
+#endif
+
+-(void)resourceNotFound
+{
+    id client = [self client];
+    NSDictionary *infoDictionary = [NSDictionary dictionaryWithObject:NSErrorFailingURLStringKey forKey:[[self request] URL]];
+    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:infoDictionary];
+    [client URLProtocol:self didFailWithError:error];
+}
+
+@end