Title: [243525] trunk/Source/WebCore
Revision
243525
Author
wenson_hs...@apple.com
Date
2019-03-26 16:41:42 -0700 (Tue, 26 Mar 2019)

Log Message

[Cocoa] Refactor some helper functions for building UserAgent strings
https://bugs.webkit.org/show_bug.cgi?id=195990

Reviewed by Brent Fulgham.

Add an optional argument to standardUserAgentWithApplicationName to request the desktop version of the user
agent in Cocoa platforms. Work towards refactoring some codepaths to make the implementation of the "Request
Desktop Site" feature in Safari a bit more straightforward.

No change in behavior.

* platform/UserAgent.h:
* platform/ios/UserAgentIOS.mm:
(WebCore::standardUserAgentWithApplicationName):

The corresponding macOS version is currently hard-coded — the followup bug webkit.org/b/196275 tracks making
this dynamically fetch the paired macOS version when building for iOS.

* platform/mac/UserAgentMac.mm:
(WebCore::standardUserAgentWithApplicationName):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (243524 => 243525)


--- trunk/Source/WebCore/ChangeLog	2019-03-26 23:29:13 UTC (rev 243524)
+++ trunk/Source/WebCore/ChangeLog	2019-03-26 23:41:42 UTC (rev 243525)
@@ -1,3 +1,26 @@
+2019-03-26  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Cocoa] Refactor some helper functions for building UserAgent strings
+        https://bugs.webkit.org/show_bug.cgi?id=195990
+
+        Reviewed by Brent Fulgham.
+
+        Add an optional argument to standardUserAgentWithApplicationName to request the desktop version of the user
+        agent in Cocoa platforms. Work towards refactoring some codepaths to make the implementation of the "Request
+        Desktop Site" feature in Safari a bit more straightforward.
+
+        No change in behavior.
+
+        * platform/UserAgent.h:
+        * platform/ios/UserAgentIOS.mm:
+        (WebCore::standardUserAgentWithApplicationName):
+
+        The corresponding macOS version is currently hard-coded — the followup bug webkit.org/b/196275 tracks making
+        this dynamically fetch the paired macOS version when building for iOS.
+
+        * platform/mac/UserAgentMac.mm:
+        (WebCore::standardUserAgentWithApplicationName):
+
 2019-03-26  Said Abou-Hallawa  <s...@apple.com>
 
         Remove the SVG tear off objects for SVGLength, SVGLengthList and SVGAnimatedLengthList

Modified: trunk/Source/WebCore/platform/UserAgent.h (243524 => 243525)


--- trunk/Source/WebCore/platform/UserAgent.h	2019-03-26 23:29:13 UTC (rev 243524)
+++ trunk/Source/WebCore/platform/UserAgent.h	2019-03-26 23:41:42 UTC (rev 243525)
@@ -31,7 +31,8 @@
 namespace WebCore {
 
 #if PLATFORM(COCOA)
-WEBCORE_EXPORT String standardUserAgentWithApplicationName(const String& applicationName);
+enum class UserAgentType { Default, Desktop };
+WEBCORE_EXPORT String standardUserAgentWithApplicationName(const String& applicationName, UserAgentType = UserAgentType::Default);
 
 String systemMarketingVersionForUserAgentString();
 #else

Modified: trunk/Source/WebCore/platform/ios/UserAgentIOS.mm (243524 => 243525)


--- trunk/Source/WebCore/platform/ios/UserAgentIOS.mm	2019-03-26 23:29:13 UTC (rev 243524)
+++ trunk/Source/WebCore/platform/ios/UserAgentIOS.mm	2019-03-26 23:41:42 UTC (rev 243525)
@@ -76,8 +76,13 @@
     return name;
 }
 
-String standardUserAgentWithApplicationName(const String& applicationName)
+String standardUserAgentWithApplicationName(const String& applicationName, UserAgentType type)
 {
+    if (type == UserAgentType::Desktop) {
+        String appNameSuffix = applicationName.isEmpty() ? "" : makeString(" ", applicationName);
+        return makeString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko)", appNameSuffix);
+    }
+
     // FIXME: Is this needed any more? Mac doesn't have this check,
     // Check to see if there is a user agent override for all WebKit clients.
     CFPropertyListRef override = CFPreferencesCopyAppValue(CFSTR("UserAgent"), CFSTR("com.apple.WebFoundation"));

Modified: trunk/Source/WebCore/platform/mac/UserAgentMac.mm (243524 => 243525)


--- trunk/Source/WebCore/platform/mac/UserAgentMac.mm	2019-03-26 23:29:13 UTC (rev 243524)
+++ trunk/Source/WebCore/platform/mac/UserAgentMac.mm	2019-03-26 23:41:42 UTC (rev 243525)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-String standardUserAgentWithApplicationName(const String& applicationName)
+String standardUserAgentWithApplicationName(const String& applicationName, UserAgentType)
 {
     String osVersion = systemMarketingVersionForUserAgentString();
     String appNameSuffix = applicationName.isEmpty() ? "" : makeString(" ", applicationName);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to