2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebPageProxy.h"
30 #include <WebCore/Language.h>
31 #include <WebCore/WebCoreInstanceHandle.h>
32 #include <wtf/StdLibExtras.h>
33 #include <wtf/text/StringConcatenate.h>
35 using namespace WebCore;
39 static String windowsVersion()
42 OSVERSIONINFO versionInfo = { 0 };
43 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
44 ::GetVersionEx(&versionInfo);
46 if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
47 if (versionInfo.dwMajorVersion == 4) {
48 if (versionInfo.dwMinorVersion == 0)
49 osVersion = "Windows 95";
50 else if (versionInfo.dwMinorVersion == 10)
51 osVersion = "Windows 98";
52 else if (versionInfo.dwMinorVersion == 90)
53 osVersion = "Windows 98; Win 9x 4.90";
55 } else if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
56 osVersion = makeString("Windows NT ", String::number(versionInfo.dwMajorVersion), '.', String::number(versionInfo.dwMinorVersion));
58 if (!osVersion.length())
59 osVersion = makeString("Windows ", String::number(versionInfo.dwMajorVersion), '.', String::number(versionInfo.dwMinorVersion));
63 static String userVisibleWebKitVersionString()
65 String versionStr = "420+";
68 struct LANGANDCODEPAGE {
74 ::GetModuleFileName(instanceHandle(), path, WTF_ARRAY_LENGTH(path));
76 DWORD versionSize = ::GetFileVersionInfoSize(path, &handle);
79 data = fastMalloc(versionSize);
82 if (!::GetFileVersionInfo(path, 0, versionSize, data))
85 if (!::VerQueryValue(data, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate))
88 _stprintf_s(key, WTF_ARRAY_LENGTH(key), TEXT("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
89 LPCTSTR productVersion;
90 UINT productVersionLength;
91 if (!::VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&productVersion, &productVersionLength))
93 versionStr = String(productVersion, productVersionLength - 1);
101 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
103 DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersion()));
104 DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));
106 // FIXME: We should upate the user agent if the default language changes.
107 String language = defaultLanguage();
109 if (applicationNameForUserAgent.isEmpty())
110 return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)");
111 return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) ", applicationNameForUserAgent);
114 } // namespace WebKit