Set a sensible user agent string for the HTTP requests that Sparkle makes (checking for and downloading updates).

Reviewed by Sam Weinig.

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44925 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/WebKitLauncher/WebKitNightlyEnablerSparkle.m b/WebKitTools/WebKitLauncher/WebKitNightlyEnablerSparkle.m
index e42f498..3927131 100644
--- a/WebKitTools/WebKitLauncher/WebKitNightlyEnablerSparkle.m
+++ b/WebKitTools/WebKitLauncher/WebKitNightlyEnablerSparkle.m
@@ -122,6 +122,17 @@
 
 #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 @@
     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];