Unify Windows version checks.
authorpkasting@chromium.org <pkasting@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2011 04:19:56 +0000 (04:19 +0000)
committerpkasting@chromium.org <pkasting@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2011 04:19:56 +0000 (04:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=55979

Reviewed by Mihai Parparita.

Source/WebCore:

* GNUmakefile.am: Fix spaces -> tabs.
* StringsNotToBeLocalized.txt:
* WebCore.pro: Add SystemInfo.* to Qt build.
* platform/chromium/ScrollbarThemeChromiumWin.cpp:
(WebCore::ScrollbarThemeChromiumWin::invalidateOnMouseEnterExit):
(WebCore::ScrollbarThemeChromiumWin::getThemeState):
(WebCore::ScrollbarThemeChromiumWin::getThemeArrowState):
* platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp:
(WebCore::fillBMPGlyphs):
* platform/win/CursorWin.cpp:
(WebCore::createSharedCursor):
* platform/win/ScrollbarThemeWin.cpp:
(WebCore::ScrollbarThemeWin::ScrollbarThemeWin):
* platform/win/SystemInfo.cpp: Add full-fledged version check and UA string helper function.
(WebCore::windowsVersion):
(WebCore::windowsVersionForUAString):
* platform/win/SystemInfo.h: Add full-fledged version check and UA string helper function.
* rendering/RenderThemeChromiumWin.cpp:
(WebCore::getNonClientMetrics):
* rendering/RenderThemeWin.cpp:
(WebCore::RenderThemeWin::getThemeData):
(WebCore::RenderThemeWin::paintMenuList):
(WebCore::RenderThemeWin::paintMenuListButton):

Source/WebKit/gtk:

* webkit/webkitwebsettings.cpp:
(webkitOSVersion):

Source/WebKit/qt:

* Api/qwebpage.cpp:
(QWebPage::userAgentForUrl):

Source/WebKit/win:

* WebView.cpp:
(WebView::standardUserAgentWithApplicationName):
(webKitVersionString):

Source/WebKit2:

* UIProcess/win/WebPageProxyWin.cpp:
(WebKit::WebPageProxy::standardUserAgent):

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/StringsNotToBeLocalized.txt
Source/WebCore/WebCore.pro
Source/WebCore/platform/chromium/ScrollbarThemeChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp
Source/WebCore/platform/win/CursorWin.cpp
Source/WebCore/platform/win/ScrollbarThemeWin.cpp
Source/WebCore/platform/win/SystemInfo.cpp
Source/WebCore/platform/win/SystemInfo.h
Source/WebCore/rendering/RenderThemeChromiumWin.cpp
Source/WebCore/rendering/RenderThemeWin.cpp
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/webkit/webkitwebsettings.cpp
Source/WebKit/qt/Api/qwebpage.cpp
Source/WebKit/qt/ChangeLog
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/win/WebPageProxyWin.cpp

index 1a48c4d..0874921 100644 (file)
@@ -1,3 +1,34 @@
+2011-03-09  Peter Kasting  <pkasting@google.com>
+
+        Reviewed by Mihai Parparita.
+
+        Unify Windows version checks.
+        https://bugs.webkit.org/show_bug.cgi?id=55979
+
+        * GNUmakefile.am: Fix spaces -> tabs.
+        * StringsNotToBeLocalized.txt:
+        * WebCore.pro: Add SystemInfo.* to Qt build.
+        * platform/chromium/ScrollbarThemeChromiumWin.cpp:
+        (WebCore::ScrollbarThemeChromiumWin::invalidateOnMouseEnterExit):
+        (WebCore::ScrollbarThemeChromiumWin::getThemeState):
+        (WebCore::ScrollbarThemeChromiumWin::getThemeArrowState):
+        * platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp:
+        (WebCore::fillBMPGlyphs):
+        * platform/win/CursorWin.cpp:
+        (WebCore::createSharedCursor):
+        * platform/win/ScrollbarThemeWin.cpp:
+        (WebCore::ScrollbarThemeWin::ScrollbarThemeWin):
+        * platform/win/SystemInfo.cpp: Add full-fledged version check and UA string helper function.
+        (WebCore::windowsVersion):
+        (WebCore::windowsVersionForUAString):
+        * platform/win/SystemInfo.h: Add full-fledged version check and UA string helper function.
+        * rendering/RenderThemeChromiumWin.cpp:
+        (WebCore::getNonClientMetrics):
+        * rendering/RenderThemeWin.cpp:
+        (WebCore::RenderThemeWin::getThemeData):
+        (WebCore::RenderThemeWin::paintMenuList):
+        (WebCore::RenderThemeWin::paintMenuListButton):
+
 2011-03-09  Mihai Parparita  <mihaip@chromium.org>
 
         Reviewed by Tony Gentilcore.
index 2eb7206..5e81dfa 100644 (file)
@@ -3851,8 +3851,8 @@ if TARGET_WIN32
 webcore_sources += \
        Source/WebCore/platform/ScrollAnimatorWin.cpp \
        Source/WebCore/platform/ScrollAnimatorWin.h \
-    Source/WebCore/platform/win/SystemInfo.cpp \
-    Source/WebCore/platform/win/SystemInfo.h \
+       Source/WebCore/platform/win/SystemInfo.cpp \
+       Source/WebCore/platform/win/SystemInfo.h \
        Source/WebCore/plugins/win/PluginDatabaseWin.cpp \
        Source/WebCore/plugins/win/PluginMessageThrottlerWin.cpp \
        Source/WebCore/plugins/win/PluginMessageThrottlerWin.h
index 6fb11f2..bde82cb 100644 (file)
 "WebViewWindowClass"
 "WebWorkersPrivate"
 "Windows "
+"Windows CE"
+"Windows CE "
+"Windows CE .NET"
+"Windows 3.1"
 "Windows 95"
 "Windows 98"
 "Windows 98; Win 9x 4.90"
+"WinNT4.0"
 "Windows NT "
 "WmvPlugin"
 "XSL"
index 08f0636..14a7d3b 100644 (file)
@@ -2523,7 +2523,9 @@ contains(DEFINES, ENABLE_SMOOTH_SCROLLING=1) {
 }
 
 win32-*|wince* {
+    HEADERS += platform/win/SystemInfo.h
     SOURCES += \
+        platform/win/SystemInfo.cpp \
         platform/win/SystemTimeWin.cpp \
         platform/graphics/win/TransformationMatrixWin.cpp
 }
index d261106..7229c51 100644 (file)
@@ -70,7 +70,7 @@ int ScrollbarThemeChromiumWin::scrollbarThickness(ScrollbarControlSize controlSi
 
 bool ScrollbarThemeChromiumWin::invalidateOnMouseEnterExit()
 {
-    return isRunningOnVistaOrLater();
+    return windowsVersion() >= WindowsVista;
 }
 
 bool ScrollbarThemeChromiumWin::shouldSnapBackToDragOrigin(Scrollbar* scrollbar, const PlatformMouseEvent& evt)
@@ -160,12 +160,12 @@ int ScrollbarThemeChromiumWin::getThemeState(Scrollbar* scrollbar, ScrollbarPart
     if (scrollbar->pressedPart() == ThumbPart) {
         if (part == ThumbPart)
             return SCRBS_PRESSED;
-        return isRunningOnVistaOrLater() ? SCRBS_HOVER : SCRBS_NORMAL;
+        return (windowsVersion() < WindowsVista) ? SCRBS_NORMAL : SCRBS_HOVER;
     }
     if (!scrollbar->enabled())
         return SCRBS_DISABLED;
     if (scrollbar->hoveredPart() != part || part == BackTrackPart || part == ForwardTrackPart)
-        return (scrollbar->hoveredPart() == NoPart || !isRunningOnVistaOrLater()) ? SCRBS_NORMAL : SCRBS_HOVER;
+        return (scrollbar->hoveredPart() == NoPart || (windowsVersion() < WindowsVista)) ? SCRBS_NORMAL : SCRBS_HOVER;
     if (scrollbar->pressedPart() == NoPart)
         return SCRBS_HOT;
     return (scrollbar->pressedPart() == part) ? SCRBS_PRESSED : SCRBS_NORMAL;
@@ -179,43 +179,43 @@ int ScrollbarThemeChromiumWin::getThemeArrowState(Scrollbar* scrollbar, Scrollba
     if (part == BackButtonStartPart || part == ForwardButtonStartPart) {
         if (scrollbar->orientation() == HorizontalScrollbar) {
             if (scrollbar->pressedPart() == ThumbPart)
-                return !isRunningOnVistaOrLater() ? ABS_LEFTNORMAL : ABS_LEFTHOVER;
+                return (windowsVersion() < WindowsVista) ? ABS_LEFTNORMAL : ABS_LEFTHOVER;
             if (!scrollbar->enabled())
                 return ABS_LEFTDISABLED;
             if (scrollbar->hoveredPart() != part)
-                return ((scrollbar->hoveredPart() == NoPart) || !isRunningOnVistaOrLater()) ? ABS_LEFTNORMAL : ABS_LEFTHOVER;
+                return ((scrollbar->hoveredPart() == NoPart) || (windowsVersion() < WindowsVista)) ? ABS_LEFTNORMAL : ABS_LEFTHOVER;
             if (scrollbar->pressedPart() == NoPart)
                 return ABS_LEFTHOT;
             return (scrollbar->pressedPart() == part) ?
                 ABS_LEFTPRESSED : ABS_LEFTNORMAL;
         }
         if (scrollbar->pressedPart() == ThumbPart)
-            return !isRunningOnVistaOrLater() ? ABS_UPNORMAL : ABS_UPHOVER;
+            return (windowsVersion() < WindowsVista) ? ABS_UPNORMAL : ABS_UPHOVER;
         if (!scrollbar->enabled())
             return ABS_UPDISABLED;
         if (scrollbar->hoveredPart() != part)
-            return ((scrollbar->hoveredPart() == NoPart) || !isRunningOnVistaOrLater()) ? ABS_UPNORMAL : ABS_UPHOVER;
+            return ((scrollbar->hoveredPart() == NoPart) || (windowsVersion() < WindowsVista)) ? ABS_UPNORMAL : ABS_UPHOVER;
         if (scrollbar->pressedPart() == NoPart)
             return ABS_UPHOT;
         return (scrollbar->pressedPart() == part) ? ABS_UPPRESSED : ABS_UPNORMAL;
     }
     if (scrollbar->orientation() == HorizontalScrollbar) {
         if (scrollbar->pressedPart() == ThumbPart)
-            return !isRunningOnVistaOrLater() ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER;
+            return (windowsVersion() < WindowsVista) ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER;
         if (!scrollbar->enabled())
             return ABS_RIGHTDISABLED;
         if (scrollbar->hoveredPart() != part)
-            return ((scrollbar->hoveredPart() == NoPart) || !isRunningOnVistaOrLater()) ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER;
+            return ((scrollbar->hoveredPart() == NoPart) || (windowsVersion() < WindowsVista)) ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER;
         if (scrollbar->pressedPart() == NoPart)
             return ABS_RIGHTHOT;
         return (scrollbar->pressedPart() == part) ? ABS_RIGHTPRESSED : ABS_RIGHTNORMAL;
     }
     if (scrollbar->pressedPart() == ThumbPart)
-        return !isRunningOnVistaOrLater() ? ABS_DOWNNORMAL : ABS_DOWNHOVER;
+        return (windowsVersion() < WindowsVista) ? ABS_DOWNNORMAL : ABS_DOWNHOVER;
     if (!scrollbar->enabled())
         return ABS_DOWNDISABLED;
     if (scrollbar->hoveredPart() != part)
-        return ((scrollbar->hoveredPart() == NoPart) || !isRunningOnVistaOrLater()) ? ABS_DOWNNORMAL : ABS_DOWNHOVER;
+        return ((scrollbar->hoveredPart() == NoPart) || (windowsVersion() < WindowsVista)) ? ABS_DOWNNORMAL : ABS_DOWNHOVER;
     if (scrollbar->pressedPart() == NoPart)
         return ABS_DOWNHOT;
     return (scrollbar->pressedPart() == part) ? ABS_DOWNPRESSED : ABS_DOWNNORMAL;
index 31eebed..cfc1754 100644 (file)
@@ -134,7 +134,7 @@ static bool fillBMPGlyphs(unsigned offset,
     bool haveGlyphs = false;
     int invalidGlyph = 0xFFFF;
     const DWORD cffTableTag = 0x20464643; // 4-byte identifier for OpenType CFF table ('CFF ').
-    if (!isRunningOnVistaOrLater() && !(tm.tmPitchAndFamily & TMPF_TRUETYPE) && (GetFontData(dc, cffTableTag, 0, 0, 0) == GDI_ERROR))
+    if ((windowsVersion() < WindowsVista) && !(tm.tmPitchAndFamily & TMPF_TRUETYPE) && (GetFontData(dc, cffTableTag, 0, 0, 0) == GDI_ERROR))
         invalidGlyph = 0x1F;
 
     Glyph spaceGlyph = 0;  // Glyph for a space. Lazily filled.
index 0036388..3a8cc09 100644 (file)
@@ -30,6 +30,7 @@
 #include "BitmapInfo.h"
 #include "Image.h"
 #include "IntPoint.h"
+#include "SystemInfo.h"
 
 #include <wtf/OwnPtr.h>
 
 
 namespace WebCore {
 
-static inline bool supportsAlphaCursors() 
-{
-    OSVERSIONINFO osinfo = {0};
-    osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&osinfo);
-    return osinfo.dwMajorVersion > 5 || (osinfo.dwMajorVersion == 5 && osinfo.dwMinorVersion > 0);
-}
-
 static PassRefPtr<SharedCursor> createSharedCursor(Image* img, const IntPoint& hotSpot)
 {
     RefPtr<SharedCursor> impl;
 
     IntPoint effectiveHotSpot = determineHotSpot(img, hotSpot);
-    static bool doAlpha = supportsAlphaCursors();
+    static bool doAlpha = windowsVersion() >= WindowsXP;
     BitmapInfo cursorImage = BitmapInfo::create(IntSize(img->width(), img->height()));
 
     HDC dc = GetDC(0);
index ff3aaa4..576cd92 100644 (file)
@@ -100,7 +100,7 @@ ScrollbarThemeWin::ScrollbarThemeWin()
     if (!initialized) {
         initialized = true;
         checkAndInitScrollbarTheme();
-        runningVista = isRunningOnVistaOrLater();
+        runningVista = (windowsVersion() >= WindowsVista);
     }
 }
 
index f2fe62b..55e33db 100644 (file)
 #include "SystemInfo.h"
 
 #include <windows.h>
+#include <wtf/text/StringConcatenate.h>
 
 namespace WebCore {
 
-bool isRunningOnVistaOrLater()
+WindowsVersion windowsVersion(int* major, int* minor)
 {
+    static bool initialized = false;
+    static WindowsVersion version;
+    static int majorVersion, minorVersion;
+
+    if (!initialized) {
+        initialized = true;
 #if OS(WINCE)
-    return false;
+        OSVERSIONINFO versionInfo = {0};
 #else
-    static bool isVistaOrLater;
-    static bool initialized;
-
-    if (initialized)
-        return isVistaOrLater;
+        OSVERSIONINFOEX versionInfo = {0};
+#endif
+        versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
+        GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&versionInfo));
+        majorVersion = versionInfo.dwMajorVersion;
+        minorVersion = versionInfo.dwMinorVersion;
 
-    initialized = true;
+#if OS(WINCE)
+        if (majorVersion >= 1 && majorVersion <= 7)
+            version = static_cast<WindowsVersion>(WindowsCE1 + (majorVersion - 1));
+        else
+            version = (majorVersion < 1) ? WindowsCE1 : WindowsCE7;
+#else
+        if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32s)
+            version = Windows3_1;
+        else if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+            if (!minorVersion)
+                version = Windows95;
+            else
+                version = (minorVersion == 10) ? Windows98 : WindowsME;
+        } else {
+            if (majorVersion == 5) {
+                if (!minorVersion)
+                    version = Windows2000;
+                else
+                    version = (minorVersion == 1) ? WindowsXP : WindowsServer2003;
+            } else if (majorVersion >= 6) {
+                if (versionInfo.wProductType == VER_NT_WORKSTATION)
+                    version = (majorVersion == 6 && !minorVersion) ? WindowsVista : Windows7;
+                else
+                    version = WindowsServer2008;
+            } else
+                version = (majorVersion == 4) ? WindowsNT4 : WindowsNT3;
+        }
+#endif
+    }
 
-    OSVERSIONINFOEX vi = {0};
-    vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-    GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&vi));
+    if (major)
+        *major = majorVersion;
+    if (minor)
+        *minor = minorVersion;
+    return version;
+}
 
-    isVistaOrLater = vi.dwMajorVersion >= 6;
+String windowsVersionForUAString()
+{
+    int major, minor;
+    WindowsVersion version = windowsVersion(&major, &minor);
+    switch (version) {
+    case WindowsCE1:
+    case WindowsCE2:
+    case WindowsCE3:
+        return "Windows CE";
+    case WindowsCE4:
+        return "Windows CE .NET";
+    case Windows3_1:
+        return "Windows 3.1";
+    case Windows95:
+        return "Windows 95";
+    case Windows98:
+        return "Windows 98";
+    case WindowsME:
+        return "Windows 98; Win 9x 4.90";
+    case WindowsNT4:
+        return "WinNT4.0";
+    }
 
-    return isVistaOrLater;
-#endif
+    char* familyName = (version >= WindowsNT3) ? "Windows NT " : "Windows CE ";
+    return makeString(familyName, String::number(major), '.', String::number(minor));
 }
 
 } // namespace WebCore
index 9f2c2a0..2631ace 100644 (file)
 #ifndef SystemInfo_h
 #define SystemInfo_h
 
+#include <wtf/text/WTFString.h>
+
 namespace WebCore {
 
-bool isRunningOnVistaOrLater();
+// NOTE: Keep these in order so callers can do things like
+// "if (windowsVersion() >= WindowsVista) ...". It's OK to change or add values,
+// though.
+enum WindowsVersion {
+    // CE-based versions
+    WindowsCE1 = 0,
+    WindowsCE2,
+    WindowsCE3,
+    WindowsCE4,
+    WindowsCE5,
+    WindowsCE6,
+    WindowsCE7,
+    // 3.x-based versions
+    Windows3_1,
+    // 9x-based versions
+    Windows95,
+    Windows98,
+    WindowsME,
+    // NT-based versions
+    WindowsNT3,
+    WindowsNT4,
+    Windows2000,
+    WindowsXP,
+    WindowsServer2003,
+    WindowsVista,
+    WindowsServer2008,
+    Windows7,
+};
+
+// If supplied, |major| and |minor| are set to the OSVERSIONINFO::dwMajorVersion
+// and dwMinorVersion field values, respectively.
+WindowsVersion windowsVersion(int* major = 0, int* minor = 0);
+
+String windowsVersionForUAString();
 
 } // namespace WebCore
 
index e627597..53ec9cb 100644 (file)
@@ -141,8 +141,8 @@ bool ThemePainter::s_hasInstance = false;
 
 static void getNonClientMetrics(NONCLIENTMETRICS* metrics)
 {
-    static UINT size = isRunningOnVistaOrLater() ?
-        sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
+    static UINT size = (windowsVersion() >= WindowsVista) ?
+        (sizeof NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
     metrics->cbSize = size;
     bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, metrics, 0);
     ASSERT(success);
index d5e4155..af100b7 100644 (file)
@@ -569,15 +569,17 @@ ThemeData RenderThemeWin::getThemeData(RenderObject* o, ControlSubPart subPart)
             result.m_state = determineState(o);
             break;
         case MenulistPart:
-        case MenulistButtonPart:
-            result.m_part = isRunningOnVistaOrLater() ? CP_DROPDOWNBUTTONRIGHT : CP_DROPDOWNBUTTON;
-            if (isRunningOnVistaOrLater() && documentIsInApplicationChromeMode(o->document())) {
+        case MenulistButtonPart: {
+            const bool isVistaOrLater = (windowsVersion() >= WindowsVista);
+            result.m_part = isVistaOrLater ? CP_DROPDOWNBUTTONRIGHT : CP_DROPDOWNBUTTON;
+            if (isVistaOrLater && documentIsInApplicationChromeMode(o->document())) {
                 // The "readonly" look we use in application chrome mode
                 // only uses a "normal" look for the drop down button.
                 result.m_state = TS_NORMAL;
             } else
                 result.m_state = determineState(o);
             break;
+        }
         case RadioPart:
             result.m_part = BP_RADIO;
             result.m_state = determineState(o);
@@ -585,7 +587,7 @@ ThemeData RenderThemeWin::getThemeData(RenderObject* o, ControlSubPart subPart)
         case SearchFieldPart:
         case TextFieldPart:
         case TextAreaPart:
-            result.m_part = isRunningOnVistaOrLater() ? EP_EDITBORDER_NOSCROLL : TFP_TEXTFIELD;
+            result.m_part = (windowsVersion() >= WindowsVista) ? EP_EDITBORDER_NOSCROLL : TFP_TEXTFIELD;
             result.m_state = determineState(o);
             break;
         case SliderHorizontalPart:
@@ -728,7 +730,7 @@ bool RenderThemeWin::paintMenuList(RenderObject* o, const PaintInfo& i, const In
 {
     HANDLE theme;
     int part;
-    if (haveTheme && isRunningOnVistaOrLater()) {
+    if (haveTheme && (windowsVersion() >= WindowsVista)) {
         theme = menuListTheme();
         if (documentIsInApplicationChromeMode(o->document()))
             part = CP_READONLY;
@@ -792,7 +794,7 @@ bool RenderThemeWin::paintMenuListButton(RenderObject* o, const PaintInfo& i, co
         buttonRect.setX(buttonRect.maxX() - dropDownButtonWidth);
     buttonRect.setWidth(dropDownButtonWidth);
 
-    if (isRunningOnVistaOrLater()) {
+    if ((windowsVersion() >= WindowsVista)) {
         // Outset the top, right, and bottom borders of the button so that they coincide with the <select>'s border.
         buttonRect.setY(buttonRect.y() - vistaMenuListButtonOutset);
         buttonRect.setHeight(buttonRect.height() + 2 * vistaMenuListButtonOutset);
index c51d37c..408dab5 100644 (file)
@@ -1,3 +1,13 @@
+2011-03-09  Peter Kasting  <pkasting@google.com>
+
+        Reviewed by Mihai Parparita.
+
+        Unify Windows version checks.
+        https://bugs.webkit.org/show_bug.cgi?id=55979
+
+        * webkit/webkitwebsettings.cpp:
+        (webkitOSVersion):
+
 2011-03-08  Christian Dywan  <christian@lanedo.com>
 
         Reviewed by Martin Robinson.
index 7e7a506..0131256 100644 (file)
@@ -39,6 +39,8 @@
 
 #if OS(UNIX)
 #include <sys/utsname.h>
+#elif OS(WINDOWS)
+#include "SystemInfo.h"
 #endif
 
 /**
@@ -208,7 +210,7 @@ static String webkitOSVersion()
     else
         uaOSVersion = String("Unknown");
 #elif OS(WINDOWS)
-    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Windows")));
+    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (windowsVersionForUAString()));
 #else
     DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Unknown")));
 #endif
index 5dd57f5..ddf2ac2 100644 (file)
 #include "Scrollbar.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
+#if defined Q_OS_WIN32
+#include "SystemInfo.h"
+#endif // Q_OS_WIN32
 #include "TextIterator.h"
 #include "WebPlatformStrategies.h"
 #include "WindowFeatures.h"
@@ -3772,52 +3775,7 @@ QString QWebPage::userAgentForUrl(const QUrl&) const
 #ifdef Q_OS_AIX
         firstPartTemp += QString::fromLatin1("AIX");
 #elif defined Q_OS_WIN32
-
-        switch (QSysInfo::WindowsVersion) {
-        case QSysInfo::WV_32s:
-            firstPartTemp += QString::fromLatin1("Windows 3.1");
-            break;
-        case QSysInfo::WV_95:
-            firstPartTemp += QString::fromLatin1("Windows 95");
-            break;
-        case QSysInfo::WV_98:
-            firstPartTemp += QString::fromLatin1("Windows 98");
-            break;
-        case QSysInfo::WV_Me:
-            firstPartTemp += QString::fromLatin1("Windows 98; Win 9x 4.90");
-            break;
-        case QSysInfo::WV_NT:
-            firstPartTemp += QString::fromLatin1("WinNT4.0");
-            break;
-        case QSysInfo::WV_2000:
-            firstPartTemp += QString::fromLatin1("Windows NT 5.0");
-            break;
-        case QSysInfo::WV_XP:
-            firstPartTemp += QString::fromLatin1("Windows NT 5.1");
-            break;
-        case QSysInfo::WV_2003:
-            firstPartTemp += QString::fromLatin1("Windows NT 5.2");
-            break;
-        case QSysInfo::WV_VISTA:
-            firstPartTemp += QString::fromLatin1("Windows NT 6.0");
-            break;
-         case QSysInfo::WV_WINDOWS7:
-            firstPartTemp += QString::fromLatin1("Windows NT 6.1");
-            break;
-         case QSysInfo::WV_CE:
-            firstPartTemp += QString::fromLatin1("Windows CE");
-            break;
-         case QSysInfo::WV_CENET:
-            firstPartTemp += QString::fromLatin1("Windows CE .NET");
-            break;
-         case QSysInfo::WV_CE_5:
-            firstPartTemp += QString::fromLatin1("Windows CE 5.x");
-            break;
-         case QSysInfo::WV_CE_6:
-            firstPartTemp += QString::fromLatin1("Windows CE 6.x");
-            break;
-        }
-
+        firstPartTemp += windowsVersionForUAString();
 #elif defined Q_OS_DARWIN
 #ifdef __i386__ || __x86_64__
         firstPartTemp += QString::fromLatin1("Intel Mac OS X");
index a28825c..ed3f587 100644 (file)
@@ -1,3 +1,13 @@
+2011-03-09  Peter Kasting  <pkasting@google.com>
+
+        Reviewed by Mihai Parparita.
+
+        Unify Windows version checks.
+        https://bugs.webkit.org/show_bug.cgi?id=55979
+
+        * Api/qwebpage.cpp:
+        (QWebPage::userAgentForUrl):
+
 2011-03-07  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Anders Carlsson.
index 5540ab3..6f07272 100644 (file)
@@ -1,3 +1,14 @@
+2011-03-09  Peter Kasting  <pkasting@google.com>
+
+        Reviewed by Mihai Parparita.
+
+        Unify Windows version checks.
+        https://bugs.webkit.org/show_bug.cgi?id=55979
+
+        * WebView.cpp:
+        (WebView::standardUserAgentWithApplicationName):
+        (webKitVersionString):
+
 2011-03-07  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Anders Carlsson.
index 0fb8047..0682535 100644 (file)
 #include <WebCore/SelectionController.h>
 #include <WebCore/Settings.h>
 #include <WebCore/SimpleFontData.h>
+#include <WebCore/SystemInfo.h>
 #include <WebCore/TypingCommand.h>
 #include <WebCore/WindowMessageBroadcaster.h>
 #include <wtf/Threading.h>
@@ -184,8 +185,7 @@ using JSC::JSLock;
 static HMODULE accessibilityLib;
 static HashSet<WebView*> pendingDeleteBackingStoreSet;
 
-static String osVersion();
-static String webKitVersion();
+static String webKitVersionString();
 
 WebView* kit(Page* page)
 {
@@ -1244,9 +1244,10 @@ bool WebView::canHandleRequest(const WebCore::ResourceRequest& request)
 
 String WebView::standardUserAgentWithApplicationName(const String& applicationName)
 {
-    if (applicationName.isEmpty())
-        return makeString("Mozilla/5.0 (", osVersion(), ") AppleWebKit/", webKitVersion(), " (KHTML, like Gecko)");
-    return makeString("Mozilla/5.0 (", osVersion(), ") AppleWebKit/", webKitVersion(), " (KHTML, like Gecko) ", applicationName);
+    DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersionForUAString()));
+    DEFINE_STATIC_LOCAL(String, webKitVersion, (webKitVersionString()));
+
+    return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)", applicationName.isEmpty() ? "" : " ", applicationName);
 }
 
 Page* WebView::page()
@@ -2336,31 +2337,7 @@ bool WebView::developerExtrasEnabled() const
 #endif
 }
 
-static String osVersion()
-{
-    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 webKitVersion()
+static String webKitVersionString()
 {
     LPWSTR buildNumberStringPtr;
     if (!::LoadStringW(gInstance, BUILD_NUMBER, reinterpret_cast<LPWSTR>(&buildNumberStringPtr), 0) || !buildNumberStringPtr)
index 4b13e72..a98c7e5 100644 (file)
@@ -1,3 +1,13 @@
+2011-03-09  Peter Kasting  <pkasting@google.com>
+
+        Reviewed by Mihai Parparita.
+
+        Unify Windows version checks.
+        https://bugs.webkit.org/show_bug.cgi?id=55979
+
+        * UIProcess/win/WebPageProxyWin.cpp:
+        (WebKit::WebPageProxy::standardUserAgent):
+
 2011-03-09  Adele Peterson  <adele@apple.com>
 
         Reviewed by Anders Carlsson.
index 186ad44..1745a06 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "resource.h"
 #include <tchar.h>
+#include <WebCore/SystemInfo.h>
 #include <WebCore/WebCoreInstanceHandle.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringConcatenate.h>
@@ -36,30 +37,6 @@ 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()
 {
     LPWSTR buildNumberStringPtr;
@@ -71,12 +48,10 @@ static String userVisibleWebKitVersionString()
 
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
-    DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersion()));
+    DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersionForUAString()));
     DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));
 
-    if (applicationNameForUserAgent.isEmpty())
-        return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)");
-    return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) ", applicationNameForUserAgent);
+    return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)", applicationNameForUserAgent.isEmpty() ? "" : " ", applicationNameForUserAgent);
 }
 
 } // namespace WebKit