[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da
weinig at apple.com
weinig at apple.com
Wed Dec 22 18:35:16 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 5604768ce4696711c0d0a4a635d8471b570c68ab
Author: weinig at apple.com <weinig at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Dec 14 05:49:20 2010 +0000
WebKit2: Need to be able to set the application name for the user agent for a WKPage
https://bugs.webkit.org/show_bug.cgi?id=51011
Reviewed by Anders Carlsson.
Fixes:
WebKit2: Need to be able to set the application name for the user agent for a WKPage
<rdar://problem/8564532>
WebKit2: Need to be able to get the computed user agent for a WKPage
<rdar://problem/8637285>
Moves user agent computation to the UIProcess and just passes it to the WebProcess
when it has changed.
* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
Add a user agent to the creation parameters.
* UIProcess/API/C/WKPage.cpp:
(WKPageCopyUserAgent):
(WKPageCopyApplicationNameForUserAgent):
(WKPageSetApplicationNameForUserAgent):
(WKPageSetCustomUserAgent):
* UIProcess/API/C/WKPage.h:
Add new API to set the application name and access the computed user agent.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::setUserAgent):
(WebKit::WebPageProxy::setApplicationNameForUserAgent):
(WebKit::WebPageProxy::setCustomUserAgent):
(WebKit::WebPageProxy::processDidCrash):
(WebKit::WebPageProxy::creationParameters):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::userAgent):
(WebKit::WebPageProxy::applicationNameForUserAgent):
* UIProcess/mac/WebPageProxyMac.mm: Added.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::setUserAgent):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::userAgent):
* WebProcess/WebPage/WebPage.messages.in:
Pipe through user agent.
(WebKit::callGestalt):
(WebKit::macOSXVersionString):
(WebKit::userVisibleWebKitVersionString):
(WebKit::WebPageProxy::standardUserAgent):
* UIProcess/win/WebPageProxyWin.cpp: Added.
(WebKit::windowsVersion):
(WebKit::userVisibleWebKitVersionString):
(WebKit::WebPageProxy::standardUserAgent):
Port standardUserAgent computation from WebKit1.
* UIProcess/qt/WebPageProxyQt.cpp: Added.
(WebKit::WebPageProxy::standardUserAgent):
Stub out the user agent so there is no change in behavior.
* WebKit2.pro:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:
Add new file.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74000 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index b1d71f0..385ebbe 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,72 @@
+2010-12-13 Sam Weinig <sam at webkit.org>
+
+ Reviewed by Anders Carlsson.
+
+ WebKit2: Need to be able to set the application name for the user agent for a WKPage
+ https://bugs.webkit.org/show_bug.cgi?id=51011
+
+ Fixes:
+ WebKit2: Need to be able to set the application name for the user agent for a WKPage
+ <rdar://problem/8564532>
+ WebKit2: Need to be able to get the computed user agent for a WKPage
+ <rdar://problem/8637285>
+
+ Moves user agent computation to the UIProcess and just passes it to the WebProcess
+ when it has changed.
+
+ * Shared/WebPageCreationParameters.cpp:
+ (WebKit::WebPageCreationParameters::encode):
+ (WebKit::WebPageCreationParameters::decode):
+ * Shared/WebPageCreationParameters.h:
+ Add a user agent to the creation parameters.
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageCopyUserAgent):
+ (WKPageCopyApplicationNameForUserAgent):
+ (WKPageSetApplicationNameForUserAgent):
+ (WKPageSetCustomUserAgent):
+ * UIProcess/API/C/WKPage.h:
+ Add new API to set the application name and access the computed user agent.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::WebPageProxy):
+ (WebKit::WebPageProxy::close):
+ (WebKit::WebPageProxy::setUserAgent):
+ (WebKit::WebPageProxy::setApplicationNameForUserAgent):
+ (WebKit::WebPageProxy::setCustomUserAgent):
+ (WebKit::WebPageProxy::processDidCrash):
+ (WebKit::WebPageProxy::creationParameters):
+ * UIProcess/WebPageProxy.h:
+ (WebKit::WebPageProxy::userAgent):
+ (WebKit::WebPageProxy::applicationNameForUserAgent):
+ * UIProcess/mac/WebPageProxyMac.mm: Added.
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::WebPage):
+ (WebKit::WebPage::setUserAgent):
+ * WebProcess/WebPage/WebPage.h:
+ (WebKit::WebPage::userAgent):
+ * WebProcess/WebPage/WebPage.messages.in:
+ Pipe through user agent.
+
+ (WebKit::callGestalt):
+ (WebKit::macOSXVersionString):
+ (WebKit::userVisibleWebKitVersionString):
+ (WebKit::WebPageProxy::standardUserAgent):
+ * UIProcess/win/WebPageProxyWin.cpp: Added.
+ (WebKit::windowsVersion):
+ (WebKit::userVisibleWebKitVersionString):
+ (WebKit::WebPageProxy::standardUserAgent):
+ Port standardUserAgent computation from WebKit1.
+
+ * UIProcess/qt/WebPageProxyQt.cpp: Added.
+ (WebKit::WebPageProxy::standardUserAgent):
+ Stub out the user agent so there is no change in behavior.
+
+ * WebKit2.pro:
+ * WebKit2.xcodeproj/project.pbxproj:
+ * win/WebKit2.vcproj:
+ Add new file.
+
2010-12-13 Brady Eidson <beidson at apple.com>
Reviewed by Jon Honeycutt (and Brian Weinstein in heart).
diff --git a/WebKit2/Shared/WebPageCreationParameters.cpp b/WebKit2/Shared/WebPageCreationParameters.cpp
index 14addfa..d11098a 100644
--- a/WebKit2/Shared/WebPageCreationParameters.cpp
+++ b/WebKit2/Shared/WebPageCreationParameters.cpp
@@ -37,6 +37,7 @@ void WebPageCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) const
encoder->encode(pageGroupData);
encoder->encode(drawsBackground);
encoder->encode(drawsTransparentBackground);
+ encoder->encode(userAgent);
#if PLATFORM(WIN)
encoder->encode(reinterpret_cast<uint64_t>(nativeWindow));
@@ -57,6 +58,8 @@ bool WebPageCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, WebPag
return false;
if (!decoder->decode(parameters.drawsTransparentBackground))
return false;
+ if (!decoder->decode(parameters.userAgent))
+ return false;
#if PLATFORM(WIN)
uint64_t nativeWindow;
diff --git a/WebKit2/Shared/WebPageCreationParameters.h b/WebKit2/Shared/WebPageCreationParameters.h
index 1c672c1..8a59dd8 100644
--- a/WebKit2/Shared/WebPageCreationParameters.h
+++ b/WebKit2/Shared/WebPageCreationParameters.h
@@ -30,6 +30,7 @@
#include "WebPageGroupData.h"
#include "WebPreferencesStore.h"
#include <WebCore/IntSize.h>
+#include <wtf/text/WTFString.h>
namespace CoreIPC {
class ArgumentDecoder;
@@ -50,6 +51,8 @@ struct WebPageCreationParameters {
bool drawsBackground;
bool drawsTransparentBackground;
+ String userAgent;
+
#if PLATFORM(WIN)
HWND nativeWindow;
#endif
diff --git a/WebKit2/UIProcess/API/C/WKPage.cpp b/WebKit2/UIProcess/API/C/WKPage.cpp
index 6d09856..844065c 100644
--- a/WebKit2/UIProcess/API/C/WKPage.cpp
+++ b/WebKit2/UIProcess/API/C/WKPage.cpp
@@ -164,6 +164,21 @@ double WKPageGetEstimatedProgress(WKPageRef pageRef)
return toImpl(pageRef)->estimatedProgress();
}
+WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
+{
+ return toCopiedAPI(toImpl(pageRef)->userAgent());
+}
+
+WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
+{
+ return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
+}
+
+void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
+{
+ toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
+}
+
WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->customUserAgent());
@@ -171,7 +186,7 @@ WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
{
- toImpl(pageRef)->setCustomUserAgent(toImpl(userAgentRef)->string());
+ toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
}
void WKPageTerminate(WKPageRef pageRef)
diff --git a/WebKit2/UIProcess/API/C/WKPage.h b/WebKit2/UIProcess/API/C/WKPage.h
index 13844f1..8a82b81 100644
--- a/WebKit2/UIProcess/API/C/WKPage.h
+++ b/WebKit2/UIProcess/API/C/WKPage.h
@@ -251,6 +251,11 @@ WK_EXPORT double WKPageGetEstimatedProgress(WKPageRef page);
WK_EXPORT WKInspectorRef WKPageGetInspector(WKPageRef page);
#endif
+WK_EXPORT WKStringRef WKPageCopyUserAgent(WKPageRef page);
+
+WK_EXPORT WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef page);
+WK_EXPORT void WKPageSetApplicationNameForUserAgent(WKPageRef page, WKStringRef applicationName);
+
WK_EXPORT WKStringRef WKPageCopyCustomUserAgent(WKPageRef page);
WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent);
diff --git a/WebKit2/UIProcess/WebPageProxy.cpp b/WebKit2/UIProcess/WebPageProxy.cpp
index 54c5c6c..cddda13 100644
--- a/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/WebKit2/UIProcess/WebPageProxy.cpp
@@ -90,6 +90,7 @@ WebPageProxy::WebPageProxy(WebContext* context, WebPageGroup* pageGroup, uint64_
, m_context(context)
, m_pageGroup(pageGroup)
, m_mainFrame(0)
+ , m_userAgent(standardUserAgent())
, m_estimatedProgress(0.0)
, m_isInWindow(false)
, m_backForwardList(WebBackForwardList::create(this))
@@ -223,8 +224,6 @@ void WebPageProxy::close()
process()->disconnectFramesFromPage(this);
m_mainFrame = 0;
- m_customUserAgent = String();
-
#if ENABLE(INSPECTOR)
if (m_inspector) {
m_inspector->invalidate();
@@ -603,16 +602,42 @@ void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* fr
process()->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
}
-void WebPageProxy::setCustomUserAgent(const String& userAgent)
+void WebPageProxy::setUserAgent(const String& userAgent)
{
+ if (m_userAgent == userAgent)
+ return;
+ m_userAgent = userAgent;
+
if (!isValid())
return;
+ process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
+}
+
+void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
+{
+ if (m_applicationNameForUserAgent == applicationName)
+ return;
+
+ m_applicationNameForUserAgent = applicationName;
+ if (!m_customUserAgent.isEmpty())
+ return;
+
+ setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
+}
+
+void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
+{
+ if (m_customUserAgent == customUserAgent)
+ return;
- if (m_customUserAgent == userAgent || (m_customUserAgent.isEmpty() && userAgent.isEmpty()))
+ m_customUserAgent = customUserAgent;
+
+ if (m_customUserAgent.isEmpty()) {
+ setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
return;
+ }
- m_customUserAgent = userAgent;
- process()->send(Messages::WebPage::SetCustomUserAgent(userAgent), m_pageID);
+ setUserAgent(m_customUserAgent);
}
void WebPageProxy::terminateProcess()
@@ -1582,7 +1607,6 @@ void WebPageProxy::processDidCrash()
}
#endif
- m_customUserAgent = String();
m_pageTitle = String();
m_toolTip = String();
@@ -1615,6 +1639,7 @@ WebPageCreationParameters WebPageProxy::creationParameters(const IntSize& size)
parameters.pageGroupData = m_pageGroup->data();
parameters.drawsBackground = m_drawsBackground;
parameters.drawsTransparentBackground = m_drawsTransparentBackground;
+ parameters.userAgent = userAgent();
#if PLATFORM(WIN)
parameters.nativeWindow = m_pageClient->nativeWindow();
diff --git a/WebKit2/UIProcess/WebPageProxy.h b/WebKit2/UIProcess/WebPageProxy.h
index 1970eda..223e54b 100644
--- a/WebKit2/UIProcess/WebPageProxy.h
+++ b/WebKit2/UIProcess/WebPageProxy.h
@@ -195,12 +195,16 @@ public:
const String& pageTitle() const { return m_pageTitle; }
const String& toolTip() const { return m_toolTip; }
+
+ void setUserAgent(const String&);
+ const String& userAgent() const { return m_userAgent; }
+ void setApplicationNameForUserAgent(const String&);
+ const String& applicationNameForUserAgent() const { return m_applicationNameForUserAgent; }
+ void setCustomUserAgent(const String&);
const String& customUserAgent() const { return m_customUserAgent; }
double estimatedProgress() const { return m_estimatedProgress; }
- void setCustomUserAgent(const String&);
-
void terminateProcess();
typedef bool (*WebPageProxySessionStateFilterCallback)(WKPageRef, WKStringRef type, WKTypeRef object, void* context);
@@ -397,6 +401,8 @@ private:
void setComplexTextInputEnabled(uint64_t pluginComplexTextInputIdentifier, bool complexTextInputEnabled);
#endif
+ static String standardUserAgent(const String& applicationName = String());
+
PageClient* m_pageClient;
WebLoaderClient m_loaderClient;
WebPolicyClient m_policyClient;
@@ -412,6 +418,8 @@ private:
RefPtr<WebFrameProxy> m_focusedFrame;
String m_pageTitle;
+ String m_userAgent;
+ String m_applicationNameForUserAgent;
String m_customUserAgent;
#if ENABLE(INSPECTOR)
diff --git a/WebKit2/UIProcess/mac/WebPageProxyMac.mm b/WebKit2/UIProcess/mac/WebPageProxyMac.mm
new file mode 100644
index 0000000..0fc3fa7
--- /dev/null
+++ b/WebKit2/UIProcess/mac/WebPageProxyMac.mm
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "WebPageProxy.h"
+
+#include <WebCore/Language.h>
+#include <wtf/text/StringConcatenate.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+#if defined(__ppc__) || defined(__ppc64__)
+#define PROCESSOR "PPC"
+#elif defined(__i386__) || defined(__x86_64__)
+#define PROCESSOR "Intel"
+#else
+#error Unknown architecture
+#endif
+
+static inline int callGestalt(OSType selector)
+{
+ SInt32 value = 0;
+ Gestalt(selector, &value);
+ return value;
+}
+
+// Uses underscores instead of dots because if "4." ever appears in a user agent string, old DHTML libraries treat it as Netscape 4.
+static String macOSXVersionString()
+{
+ // Can't use -[NSProcessInfo operatingSystemVersionString] because it has too much stuff we don't want.
+ int major = callGestalt(gestaltSystemVersionMajor);
+ ASSERT(major);
+
+ int minor = callGestalt(gestaltSystemVersionMinor);
+ int bugFix = callGestalt(gestaltSystemVersionBugFix);
+ if (bugFix)
+ return String::format("%d_%d_%d", major, minor, bugFix);
+ if (minor)
+ return String::format("%d_%d", major, minor);
+ return String::format("%d", major);
+}
+
+static String userVisibleWebKitVersionString()
+{
+ // If the version is 4 digits long or longer, then the first digit represents
+ // the version of the OS. Our user agent string should not include this first digit,
+ // so strip it off and report the rest as the version. <rdar://problem/4997547>
+ NSString *fullVersion = [[NSBundle bundleForClass:NSClassFromString(@"WKView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
+ NSRange nonDigitRange = [fullVersion rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
+ if (nonDigitRange.location == NSNotFound && [fullVersion length] >= 4)
+ return [fullVersion substringFromIndex:1];
+ if (nonDigitRange.location != NSNotFound && nonDigitRange.location >= 4)
+ return [fullVersion substringFromIndex:1];
+ return fullVersion;
+}
+
+String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
+{
+ DEFINE_STATIC_LOCAL(String, osVersion, (macOSXVersionString()));
+ DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));
+
+ // FIXME: We should upate the user agent if the default language changes.
+ String language = defaultLanguage();
+
+ if (applicationNameForUserAgent.isEmpty())
+ return makeString("Mozilla/5.0 (Macintosh; U; " PROCESSOR " Mac OS X ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)");
+ return makeString("Mozilla/5.0 (Macintosh; U; " PROCESSOR " Mac OS X ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) ", applicationNameForUserAgent);
+}
+
+} // namespace WebKit
diff --git a/WebKit2/UIProcess/qt/WebPageProxyQt.cpp b/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
new file mode 100644
index 0000000..baf765a
--- /dev/null
+++ b/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "WebPageProxy.h"
+
+namespace WebKit {
+
+String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
+{
+ // FIXME: This should not be hard coded.
+ return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/531.4 (KHTML, like Gecko) Version/4.0.3 Safari/531.4";
+}
+
+} // namespace WebKit
diff --git a/WebKit2/UIProcess/win/WebPageProxyWin.cpp b/WebKit2/UIProcess/win/WebPageProxyWin.cpp
new file mode 100644
index 0000000..6b0efd1
--- /dev/null
+++ b/WebKit2/UIProcess/win/WebPageProxyWin.cpp
@@ -0,0 +1,113 @@
+/*
+* Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+*/
+
+#include "WebPageProxy.h"
+
+#include <tchar.h>
+#include <WebCore/Language.h>
+#include <WebCore/WebCoreInstanceHandle.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/StringConcatenate.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static String windowsVersion()
+{
+ String osVersion;
+ OSVERSIONINFO versionInfo = { 0 };
+ versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
+ ::GetVersionEx(&versionInfo);
+
+ if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+ if (versionInfo.dwMajorVersion == 4) {
+ if (versionInfo.dwMinorVersion == 0)
+ osVersion = "Windows 95";
+ else if (versionInfo.dwMinorVersion == 10)
+ osVersion = "Windows 98";
+ else if (versionInfo.dwMinorVersion == 90)
+ osVersion = "Windows 98; Win 9x 4.90";
+ }
+ } else if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
+ osVersion = makeString("Windows NT ", String::number(versionInfo.dwMajorVersion), '.', String::number(versionInfo.dwMinorVersion));
+
+ if (!osVersion.length())
+ osVersion = makeString("Windows ", String::number(versionInfo.dwMajorVersion), '.', String::number(versionInfo.dwMinorVersion));
+ return osVersion;
+}
+
+static String userVisibleWebKitVersionString()
+{
+ String versionStr = "420+";
+ void* data = 0;
+
+ struct LANGANDCODEPAGE {
+ WORD wLanguage;
+ WORD wCodePage;
+ } *lpTranslate;
+
+ TCHAR path[MAX_PATH];
+ ::GetModuleFileName(instanceHandle(), path, WTF_ARRAY_LENGTH(path));
+ DWORD handle;
+ DWORD versionSize = ::GetFileVersionInfoSize(path, &handle);
+ if (!versionSize)
+ goto exit;
+ data = fastMalloc(versionSize);
+ if (!data)
+ goto exit;
+ if (!::GetFileVersionInfo(path, 0, versionSize, data))
+ goto exit;
+ UINT cbTranslate;
+ if (!::VerQueryValue(data, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate))
+ goto exit;
+ TCHAR key[256];
+ _stprintf_s(key, WTF_ARRAY_LENGTH(key), TEXT("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
+ LPCTSTR productVersion;
+ UINT productVersionLength;
+ if (!::VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&productVersion, &productVersionLength))
+ goto exit;
+ versionStr = String(productVersion, productVersionLength - 1);
+
+exit:
+ if (data)
+ fastFree(data);
+ return versionStr;
+}
+
+String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
+{
+ DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersion()));
+ DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));
+
+ // FIXME: We should upate the user agent if the default language changes.
+ String language = defaultLanguage();
+
+ if (applicationNameForUserAgent.isEmpty())
+ return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)");
+ return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) ", applicationNameForUserAgent);
+}
+
+} // namespace WebKit
diff --git a/WebKit2/WebKit2.pro b/WebKit2/WebKit2.pro
index 3f6ca98..199c399 100644
--- a/WebKit2/WebKit2.pro
+++ b/WebKit2/WebKit2.pro
@@ -545,6 +545,7 @@ SOURCES += \
UIProcess/qt/WebContextMenuProxyQt.cpp \
UIProcess/qt/WebContextQt.cpp \
UIProcess/qt/WebInspectorProxyQt.cpp \
+ UIProcess/qt/WebPageProxyQt.cpp \
UIProcess/qt/WebPopupMenuProxyQt.cpp \
UIProcess/qt/WebPreferencesQt.cpp \
WebProcess/Authentication/AuthenticationManager.cpp \
diff --git a/WebKit2/WebKit2.xcodeproj/project.pbxproj b/WebKit2/WebKit2.xcodeproj/project.pbxproj
index 48e0b15..99990b1 100644
--- a/WebKit2/WebKit2.xcodeproj/project.pbxproj
+++ b/WebKit2/WebKit2.xcodeproj/project.pbxproj
@@ -439,6 +439,7 @@
BC8452A71162C80900CAB9B5 /* DrawingArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC8452A51162C80900CAB9B5 /* DrawingArea.cpp */; };
BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8452A61162C80900CAB9B5 /* DrawingArea.h */; };
BC84EB1812A7100C0083F2DA /* WebPreferencesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */; };
+ BC857E8712B71EBB00EDEB2E /* WebPageProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */; };
BC8699B5116AADAA002A925B /* WKView.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8699B2116AADAA002A925B /* WKView.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC8699B6116AADAA002A925B /* WKView.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8699B3116AADAA002A925B /* WKView.mm */; };
BC8699B7116AADAA002A925B /* WKViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8699B4116AADAA002A925B /* WKViewInternal.h */; };
@@ -1085,6 +1086,7 @@
BC8452A51162C80900CAB9B5 /* DrawingArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingArea.cpp; sourceTree = "<group>"; };
BC8452A61162C80900CAB9B5 /* DrawingArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawingArea.h; sourceTree = "<group>"; };
BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPreferencesMac.mm; sourceTree = "<group>"; };
+ BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPageProxyMac.mm; sourceTree = "<group>"; };
BC8699B2116AADAA002A925B /* WKView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKView.h; sourceTree = "<group>"; };
BC8699B3116AADAA002A925B /* WKView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKView.mm; sourceTree = "<group>"; };
BC8699B4116AADAA002A925B /* WKViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKViewInternal.h; sourceTree = "<group>"; };
@@ -2249,6 +2251,7 @@
51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */,
51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */,
1CA8B935127C774E00576C2B /* WebInspectorProxyMac.mm */,
+ BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */,
BC5750951268F3C6006F0F12 /* WebPopupMenuProxyMac.h */,
BC5750961268F3C6006F0F12 /* WebPopupMenuProxyMac.mm */,
BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */,
@@ -3102,6 +3105,7 @@
F62A766112B1ABED0005F1B6 /* WKDatabaseManager.cpp in Sources */,
F62A76B612B1B25F0005F1B6 /* WebDatabaseManagerMessageReceiver.cpp in Sources */,
F62A76B812B1B25F0005F1B6 /* WebDatabaseManagerProxyMessageReceiver.cpp in Sources */,
+ BC857E8712B71EBB00EDEB2E /* WebPageProxyMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/WebKit2/WebProcess/WebPage/WebPage.cpp b/WebKit2/WebProcess/WebPage/WebPage.cpp
index fb49bce..0855e42 100644
--- a/WebKit2/WebProcess/WebPage/WebPage.cpp
+++ b/WebKit2/WebProcess/WebPage/WebPage.cpp
@@ -159,6 +159,8 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
setDrawsBackground(parameters.drawsBackground);
setDrawsTransparentBackground(parameters.drawsTransparentBackground);
+ m_userAgent = parameters.userAgent;
+
#ifndef NDEBUG
webPageCounter.increment();
#endif
@@ -860,18 +862,9 @@ void WebPage::show()
send(Messages::WebPageProxy::ShowPage());
}
-void WebPage::setCustomUserAgent(const String& customUserAgent)
+void WebPage::setUserAgent(const String& userAgent)
{
- m_customUserAgent = customUserAgent;
-}
-
-String WebPage::userAgent() const
-{
- if (!m_customUserAgent.isEmpty())
- return m_customUserAgent;
-
- // FIXME: This should be based on an application name.
- return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/531.4 (KHTML, like Gecko) Version/4.0.3 Safari/531.4";
+ m_userAgent = userAgent;
}
IntRect WebPage::windowResizerRect() const
diff --git a/WebKit2/WebProcess/WebPage/WebPage.h b/WebKit2/WebProcess/WebPage/WebPage.h
index fc307d0..b8f364d 100644
--- a/WebKit2/WebProcess/WebPage/WebPage.h
+++ b/WebKit2/WebProcess/WebPage/WebPage.h
@@ -126,7 +126,7 @@ public:
bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
#endif
void show();
- String userAgent() const;
+ String userAgent() const { return m_userAgent; }
WebCore::IntRect windowResizerRect() const;
bool tabsToLinks() const { return m_tabToLinks; }
@@ -301,7 +301,7 @@ private:
void updatePreferences(const WebPreferencesStore&);
void didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID);
- void setCustomUserAgent(const String&);
+ void setUserAgent(const String&);
#if PLATFORM(MAC)
void setWindowIsVisible(bool windowIsVisible);
@@ -332,7 +332,7 @@ private:
RefPtr<WebPageGroupProxy> m_pageGroup;
- String m_customUserAgent;
+ String m_userAgent;
WebCore::IntSize m_viewSize;
RefPtr<DrawingArea> m_drawingArea;
diff --git a/WebKit2/WebProcess/WebPage/WebPage.messages.in b/WebKit2/WebProcess/WebPage/WebPage.messages.in
index 6657211..6d63f71 100644
--- a/WebKit2/WebProcess/WebPage/WebPage.messages.in
+++ b/WebKit2/WebProcess/WebPage/WebPage.messages.in
@@ -57,7 +57,7 @@ messages -> WebPage {
PreferencesDidChange(WebKit::WebPreferencesStore store)
- SetCustomUserAgent(WTF::String customUserAgent)
+ SetUserAgent(WTF::String userAgent)
#if ENABLE(TILED_BACKING_STORE)
SetActualVisibleContentRect(WebCore::IntRect rect)
diff --git a/WebKit2/win/WebKit2.vcproj b/WebKit2/win/WebKit2.vcproj
index 10cbd4a..d0f95ce 100755
--- a/WebKit2/win/WebKit2.vcproj
+++ b/WebKit2/win/WebKit2.vcproj
@@ -2466,6 +2466,10 @@
>
</File>
<File
+ RelativePath="..\UIProcess\win\WebPageProxyWin.cpp"
+ >
+ </File>
+ <File
RelativePath="..\UIProcess\win\WebPopupMenuProxyWin.cpp"
>
</File>
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list