Set a sensible user agent string for the HTTP requests that Sparkle makes (checking...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jun 2009 00:03:43 +0000 (00:03 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Jun 2009 00:03:43 +0000 (00:03 +0000)
Reviewed by Sam Weinig.

* WebKitLauncher/WebKitNightlyEnablerSparkle.m:
(userAgentStringForSparkle):
(initializeSparkle):

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

WebKitTools/ChangeLog
WebKitTools/WebKitLauncher/WebKitNightlyEnablerSparkle.m

index c79f6c8..b1ff302 100644 (file)
@@ -2,6 +2,16 @@
 
         Reviewed by Sam Weinig.
 
+        Set a sensible user agent string for the HTTP requests that Sparkle makes (checking for and downloading updates).
+
+        * WebKitLauncher/WebKitNightlyEnablerSparkle.m:
+        (userAgentStringForSparkle):
+        (initializeSparkle):
+
+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.
 
index e42f498..3927131 100644 (file)
@@ -122,6 +122,17 @@ static void setMethodImplementation(Method m, IMP imp)
 
 #endif
 
+static NSString *userAgentStringForSparkle()
+{
+    NSBundle *safariBundle = [NSBundle mainBundle];
+    NSString *safariVersion = [[safariBundle localizedInfoDictionary] valueForKey:@"CFBundleShortVersionString"];
+    NSString *safariBuild = [[[safariBundle infoDictionary] valueForKey:(NSString *)kCFBundleVersionKey] substringFromIndex:1];
+    NSString *webKitRevision = [[webKitLauncherBundle() infoDictionary] valueForKey:(NSString *)kCFBundleVersionKey];
+    NSString *applicationName = [NSString stringWithFormat:@"Version/%@ Safari/%@ WebKitRevision/%@", safariVersion, safariBuild, webKitRevision];
+    Class WebView = objc_lookUpClass("WebView");
+    return objc_msgSend(WebView, @selector(_standardUserAgentWithApplicationName:), applicationName);
+}
+
 void initializeSparkle()
 {
     // Override some Sparkle behaviour
@@ -135,6 +146,7 @@ void initializeSparkle()
     setMethodImplementation(methodToPatch, (IMP)updateAlertInitForAlertPanel);
 
     SUUpdater *updater = [SUUpdater updaterForBundle:webKitLauncherBundle()];
+    [updater setUserAgentString:userAgentStringForSparkle()];
 
     // Find the first separator on the Safari menu…
     NSMenu *applicationSubmenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];