Title: [264213] trunk/Source
Revision
264213
Author
[email protected]
Date
2020-07-10 02:16:18 -0700 (Fri, 10 Jul 2020)

Log Message

[GTK][WPE] Use mobile user-agent on tablet
https://bugs.webkit.org/show_bug.cgi?id=149496

Patch by Jan-Michael Brummer <[email protected]> on 2020-07-10
Reviewed by Carlos Garcia Campos.

* platform/UserAgentQuirks.cpp:
(WebCore::urlRequiresMacintoshPlatform):
(WebCore::urlRequiresLinuxDesktopPlatform):
(WebCore::UserAgentQuirks::quirksForURL):
* platform/UserAgentQuirks.h:
* platform/glib/UserAgentGLib.cpp:
(WebCore::getChassisType):
(WebCore::platformForUAString):
(WebCore::platformVersionForUAString):
(WebCore::buildUserAgentString):
(WebCore::standardUserAgent):
(WebCore::standardUserAgentForURL):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/wtf/PlatformGTK.cmake (264212 => 264213)


--- trunk/Source/WTF/wtf/PlatformGTK.cmake	2020-07-10 08:16:15 UTC (rev 264212)
+++ trunk/Source/WTF/wtf/PlatformGTK.cmake	2020-07-10 09:16:18 UTC (rev 264213)
@@ -1,6 +1,7 @@
 set(WTF_OUTPUT_NAME WTFGTK)
 
 list(APPEND WTF_PUBLIC_HEADERS
+    glib/ChassisType.h
     glib/GLibUtilities.h
     glib/GMutexLocker.h
     glib/GRefPtr.h
@@ -23,6 +24,7 @@
     generic/MainThreadGeneric.cpp
     generic/WorkQueueGeneric.cpp
 
+    glib/ChassisType.cpp
     glib/FileSystemGlib.cpp
     glib/GLibUtilities.cpp
     glib/GRefPtr.cpp

Modified: trunk/Source/WTF/wtf/PlatformWPE.cmake (264212 => 264213)


--- trunk/Source/WTF/wtf/PlatformWPE.cmake	2020-07-10 08:16:15 UTC (rev 264212)
+++ trunk/Source/WTF/wtf/PlatformWPE.cmake	2020-07-10 09:16:18 UTC (rev 264213)
@@ -1,4 +1,5 @@
 list(APPEND WTF_PUBLIC_HEADERS
+    glib/ChassisType.h
     glib/GLibUtilities.h
     glib/GMutexLocker.h
     glib/GRefPtr.h
@@ -18,6 +19,7 @@
     generic/MemoryFootprintGeneric.cpp
     generic/WorkQueueGeneric.cpp
 
+    glib/ChassisType.cpp
     glib/FileSystemGlib.cpp
     glib/GLibUtilities.cpp
     glib/GRefPtr.cpp

Added: trunk/Source/WTF/wtf/glib/ChassisType.cpp (0 => 264213)


--- trunk/Source/WTF/wtf/glib/ChassisType.cpp	                        (rev 0)
+++ trunk/Source/WTF/wtf/glib/ChassisType.cpp	2020-07-10 09:16:18 UTC (rev 264213)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2020 Jan-Michael Brummer <[email protected]>
+ *
+ * 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. ``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
+ * 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 "config.h"
+#include <wtf/glib/ChassisType.h>
+
+#include <mutex>
+#include <wtf/Optional.h>
+#include <wtf/glib/GUniquePtr.h>
+
+namespace WTF {
+
+static Optional<ChassisType> readMachineInfoChassisType()
+{
+    GUniqueOutPtr<char> buffer;
+    GUniqueOutPtr<GError> error;
+    if (!g_file_get_contents("/etc/machine-info", &buffer.outPtr(), nullptr, &error.outPtr())) {
+        if (!g_error_matches(error.get(), G_FILE_ERROR, G_FILE_ERROR_NOENT))
+            g_warning("Could not open /etc/machine-info: %s", error->message);
+        return WTF::nullopt;
+    }
+
+    GUniquePtr<char*> split(g_strsplit(buffer.get(), "\n", -1));
+    for (int i = 0; split.get()[i]; ++i) {
+        if (g_str_has_prefix(split.get()[i], "CHASSIS=")) {
+            char* chassis = split.get()[i] + 8;
+            if (!strcmp(chassis, "tablet") || !strcmp(chassis, "handset"))
+                return ChassisType::Mobile;
+
+            return ChassisType::Desktop;
+        }
+    }
+
+    return WTF::nullopt;
+}
+
+static Optional<ChassisType> readDMIChassisType()
+{
+    GUniqueOutPtr<char> buffer;
+    GUniqueOutPtr<GError> error;
+    if (g_file_get_contents("/sys/class/dmi/id/chassis_type", &buffer.outPtr(), nullptr, &error.outPtr())) {
+        int type = strtol(buffer.get(), nullptr, 10);
+
+        // See the SMBIOS Specification 3.0 section 7.4.1 for details about the values listed here:
+        // https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
+        switch (type) {
+        case 0x3: /* Desktop */
+        case 0x4: /* Low Profile Desktop */
+        case 0x6: /* Mini Tower */
+        case 0x7: /* Tower */
+        case 0x8: /* Portable */
+        case 0x9: /* Laptop */
+        case 0xA: /* Notebook */
+        case 0xE: /* Sub Notebook */
+        case 0x11: /* Main Server Chassis */
+        case 0x1C: /* Blade */
+        case 0x1D: /* Blade Enclosure */
+        case 0x1F: /* Convertible */
+        case 0x20: /* Detachable */
+            return ChassisType::Desktop;
+
+        case 0xB: /* Hand Held */
+        case 0x1E: /* Tablet */
+            return ChassisType::Mobile;
+        }
+    } else if (!g_error_matches(error.get(), G_FILE_ERROR, G_FILE_ERROR_NOENT))
+        g_warning("Could not open /sys/class/dmi/id/chassis_type: %s", error->message);
+
+    return WTF::nullopt;
+}
+
+static Optional<ChassisType> readACPIChassisType()
+{
+    GUniqueOutPtr<char> buffer;
+    GUniqueOutPtr<GError> error;
+    if (g_file_get_contents("/sys/firmware/acpi/pm_profile", &buffer.outPtr(), nullptr, &error.outPtr())) {
+        int type = strtol(buffer.get(), nullptr, 10);
+
+        // See the ACPI 5.0 Spec Section 5.2.9.1 for details:
+        // http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
+        switch (type) {
+        case 1: /* Desktop */
+        case 2: /* Mobile */
+        case 3: /* Workstation */
+        case 4: /* Enterprise Server */
+        case 5: /* SOHO Server */
+        case 6: /* Appliance PC */
+        case 7: /* Performance Server */
+            return ChassisType::Desktop;
+
+        case 8: /* Tablet */
+            return ChassisType::Mobile;
+        }
+    } else if (!g_error_matches(error.get(), G_FILE_ERROR, G_FILE_ERROR_NOENT))
+        g_warning("Could not open /sys/firmware/acpi/pm_profile: %s", error->message);
+
+    return WTF::nullopt;
+}
+
+ChassisType chassisType()
+{
+    static ChassisType chassisType;
+    static std::once_flag initializeChassis;
+    std::call_once(initializeChassis, [] {
+        Optional<ChassisType> optionalChassisType = readMachineInfoChassisType();
+        if (!optionalChassisType)
+            optionalChassisType = readDMIChassisType();
+        if (!optionalChassisType)
+            optionalChassisType = readACPIChassisType();
+        chassisType = optionalChassisType.valueOr(ChassisType::Desktop);
+    });
+
+    return chassisType;
+}
+
+} // namespace WTF

Added: trunk/Source/WTF/wtf/glib/ChassisType.h (0 => 264213)


--- trunk/Source/WTF/wtf/glib/ChassisType.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/glib/ChassisType.h	2020-07-10 09:16:18 UTC (rev 264213)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 Jan-Michael Brummer <[email protected]>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+namespace WTF {
+
+enum class ChassisType {
+    Desktop,
+    Mobile
+};
+
+WTF_EXPORT_PRIVATE ChassisType chassisType();
+
+} // namespace WTF
+
+using WTF::chassisType;

Modified: trunk/Source/WebCore/ChangeLog (264212 => 264213)


--- trunk/Source/WebCore/ChangeLog	2020-07-10 08:16:15 UTC (rev 264212)
+++ trunk/Source/WebCore/ChangeLog	2020-07-10 09:16:18 UTC (rev 264213)
@@ -1,3 +1,23 @@
+2020-07-10  Jan-Michael Brummer  <[email protected]>
+
+        [GTK][WPE] Use mobile user-agent on tablet
+        https://bugs.webkit.org/show_bug.cgi?id=149496
+
+        Reviewed by Carlos Garcia Campos.
+
+        * platform/UserAgentQuirks.cpp:
+        (WebCore::urlRequiresMacintoshPlatform):
+        (WebCore::urlRequiresLinuxDesktopPlatform):
+        (WebCore::UserAgentQuirks::quirksForURL):
+        * platform/UserAgentQuirks.h:
+        * platform/glib/UserAgentGLib.cpp:
+        (WebCore::getChassisType):
+        (WebCore::platformForUAString):
+        (WebCore::platformVersionForUAString):
+        (WebCore::buildUserAgentString):
+        (WebCore::standardUserAgent):
+        (WebCore::standardUserAgentForURL):
+
 2020-07-10  Alicia Boya GarcĂ­a  <[email protected]>
 
         [MSE][GStreamer] Inline MediaSourceClientGStreamerMSE away

Modified: trunk/Source/WebCore/platform/UserAgentQuirks.cpp (264212 => 264213)


--- trunk/Source/WebCore/platform/UserAgentQuirks.cpp	2020-07-10 08:16:15 UTC (rev 264212)
+++ trunk/Source/WebCore/platform/UserAgentQuirks.cpp	2020-07-10 09:16:18 UTC (rev 264213)
@@ -28,6 +28,7 @@
 
 #include "PublicSuffix.h"
 #include <wtf/URL.h>
+#include <wtf/glib/ChassisType.h>
 
 namespace WebCore {
 
@@ -119,11 +120,11 @@
     String baseDomain = topPrivatelyControlledDomain(domain);
 
     // At least finance.yahoo.com displays a mobile version with WebKitGTK's standard user agent.
-    if (baseDomain == "yahoo.com")
+    if (chassisType() != WTF::ChassisType::Mobile && baseDomain == "yahoo.com")
         return true;
 
     // taobao.com displays a mobile version with WebKitGTK's standard user agent.
-    if (baseDomain == "taobao.com")
+    if (chassisType() != WTF::ChassisType::Mobile && baseDomain == "taobao.com")
         return true;
 
     // web.whatsapp.com completely blocks users with WebKitGTK's standard user agent.
@@ -152,7 +153,7 @@
 
 static bool urlRequiresLinuxDesktopPlatform(const URL& url)
 {
-    return isGoogle(url);
+    return isGoogle(url) && chassisType() != WTF::ChassisType::Mobile;
 }
 
 UserAgentQuirks UserAgentQuirks::quirksForURL(const URL& url)

Modified: trunk/Source/WebCore/platform/glib/UserAgentGLib.cpp (264212 => 264213)


--- trunk/Source/WebCore/platform/glib/UserAgentGLib.cpp	2020-07-10 08:16:15 UTC (rev 264212)
+++ trunk/Source/WebCore/platform/glib/UserAgentGLib.cpp	2020-07-10 09:16:18 UTC (rev 264213)
@@ -31,6 +31,7 @@
 #include "UserAgentQuirks.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/URL.h>
+#include <wtf/glib/ChassisType.h>
 #include <wtf/text/StringBuilder.h>
 
 #if OS(UNIX)
@@ -50,6 +51,8 @@
 #if OS(MAC_OS_X)
     return "Macintosh";
 #else
+    if (chassisType() == WTF::ChassisType::Mobile)
+        return "Linux";
     return "X11";
 #endif
 }
@@ -57,6 +60,9 @@
 static const String platformVersionForUAString()
 {
 #if OS(UNIX)
+    if (chassisType() == WTF::ChassisType::Mobile)
+        return "like Android 4.4";
+
     struct utsname name;
     uname(&name);
     static NeverDestroyed<const String> uaOSVersion(makeString(name.sysname, ' ', name.machine));
@@ -112,6 +118,9 @@
     // https://bugs.webkit.org/show_bug.cgi?id=133403 for details.
     } else
         uaString.appendLiteral("Version/13.0 ");
+
+    if (chassisType() == WTF::ChassisType::Mobile)
+        uaString.appendLiteral("Mobile ");
     uaString.appendLiteral("Safari/");
     uaString.append(versionForUAString());
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to