- Revision
- 243187
- Author
- m...@apple.com
- Date
- 2019-03-19 19:52:33 -0700 (Tue, 19 Mar 2019)
Log Message
Simplify Cocoa platform user agent logic by using string constants instead of function calls for the frozen parts
https://bugs.webkit.org/show_bug.cgi?id=195936
Reviewed by Dean Jackson.
No new tests because no behavior changes. Existing behavior is tested by fast/dom/navigator-userAgent-frozen.html
* platform/UserAgent.h: Remove prototype of removed function.
* platform/cocoa/UserAgentCocoa.mm:
(WebCore::userAgentBundleVersion): Deleted.
* platform/ios/UserAgentIOS.mm:
* platform/ios/UserAgentIOS.mm:
(WebCore::osNameForUserAgent): Use WTF String instead of NSString
(WebCore::deviceNameForUserAgent): dutto
(WebCore::standardUserAgentWithApplicationName): Simplify this
function to account for WebKit version now being frozen. Also
use String instead of NSString.
* platform/mac/UserAgentMac.mm:
(WebCore::standardUserAgentWithApplicationName): Simplify this
function to account for CPU and WEbKit version now being
frozen. Also avoid two separate but very similar calls to
makeString().
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (243186 => 243187)
--- trunk/Source/WebCore/ChangeLog 2019-03-20 02:01:41 UTC (rev 243186)
+++ trunk/Source/WebCore/ChangeLog 2019-03-20 02:52:33 UTC (rev 243187)
@@ -1,3 +1,28 @@
+2019-03-18 Maciej Stachowiak <m...@apple.com>
+
+ Simplify Cocoa platform user agent logic by using string constants instead of function calls for the frozen parts
+ https://bugs.webkit.org/show_bug.cgi?id=195936
+
+ Reviewed by Dean Jackson.
+
+ No new tests because no behavior changes. Existing behavior is tested by fast/dom/navigator-userAgent-frozen.html
+
+ * platform/UserAgent.h: Remove prototype of removed function.
+ * platform/cocoa/UserAgentCocoa.mm:
+ (WebCore::userAgentBundleVersion): Deleted.
+ * platform/ios/UserAgentIOS.mm:
+ * platform/ios/UserAgentIOS.mm:
+ (WebCore::osNameForUserAgent): Use WTF String instead of NSString
+ (WebCore::deviceNameForUserAgent): dutto
+ (WebCore::standardUserAgentWithApplicationName): Simplify this
+ function to account for WebKit version now being frozen. Also
+ use String instead of NSString.
+ * platform/mac/UserAgentMac.mm:
+ (WebCore::standardUserAgentWithApplicationName): Simplify this
+ function to account for CPU and WEbKit version now being
+ frozen. Also avoid two separate but very similar calls to
+ makeString().
+
2019-03-19 Ross Kirsling <ross.kirsl...@sony.com>
Unreviewed adjustment to r242842 per Darin's request.
Modified: trunk/Source/WebCore/platform/UserAgent.h (243186 => 243187)
--- trunk/Source/WebCore/platform/UserAgent.h 2019-03-20 02:01:41 UTC (rev 243186)
+++ trunk/Source/WebCore/platform/UserAgent.h 2019-03-20 02:52:33 UTC (rev 243187)
@@ -34,7 +34,6 @@
WEBCORE_EXPORT String standardUserAgentWithApplicationName(const String& applicationName);
String systemMarketingVersionForUserAgentString();
-String userAgentBundleVersion();
#else
WEBCORE_EXPORT String standardUserAgent(const String& applicationName = emptyString(), const String& applicationVersion = emptyString());
Modified: trunk/Source/WebCore/platform/cocoa/UserAgentCocoa.mm (243186 => 243187)
--- trunk/Source/WebCore/platform/cocoa/UserAgentCocoa.mm 2019-03-20 02:01:41 UTC (rev 243186)
+++ trunk/Source/WebCore/platform/cocoa/UserAgentCocoa.mm 2019-03-20 02:52:33 UTC (rev 243187)
@@ -38,9 +38,4 @@
return [systemMarketingVersion() stringByReplacingOccurrencesOfString:@"." withString:@"_"];
}
-String userAgentBundleVersion()
-{
- return "605.1.15"_s;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/ios/UserAgentIOS.mm (243186 => 243187)
--- trunk/Source/WebCore/platform/ios/UserAgentIOS.mm 2019-03-20 02:01:41 UTC (rev 243186)
+++ trunk/Source/WebCore/platform/ios/UserAgentIOS.mm 2019-03-20 02:52:33 UTC (rev 243187)
@@ -52,26 +52,26 @@
return isClassic() && [PAL::getUIApplicationClass() _classicMode] != UIApplicationSceneClassicModeOriginalPad;
}
-static inline NSString *osNameForUserAgent()
+static inline String osNameForUserAgent()
{
if (deviceHasIPadCapability() && !isClassicPhone())
- return @"OS";
- return @"iPhone OS";
+ return "OS";
+ return "iPhone OS";
}
-static inline NSString *deviceNameForUserAgent()
+static inline String deviceNameForUserAgent()
{
if (isClassic()) {
if (isClassicPad())
- return @"iPad";
- return @"iPhone";
+ return "iPad";
+ return "iPhone";
}
- NSString *name = deviceName();
+ String name = deviceName();
#if PLATFORM(IOS_FAMILY_SIMULATOR)
- NSUInteger location = [name rangeOfString:@" Simulator" options:NSBackwardsSearch].location;
- if (location != NSNotFound && location > 0)
- return [name substringToIndex:location];
+ size_t location = name.find(" Simulator");
+ if (location != notFound)
+ return name.substring(0, location);
#endif
return name;
}
@@ -78,6 +78,7 @@
String standardUserAgentWithApplicationName(const String& applicationName)
{
+ // 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"));
if (override) {
@@ -86,12 +87,10 @@
CFRelease(override);
}
- // FIXME: We should implement this with String and/or StringBuilder instead.
- NSString *webKitVersion = userAgentBundleVersion();
- NSString *osMarketingVersionString = systemMarketingVersionForUserAgentString();
- if (applicationName.isEmpty())
- return [NSString stringWithFormat:@"Mozilla/5.0 (%@; CPU %@ %@ like Mac OS X) AppleWebKit/%@ (KHTML, like Gecko)", deviceNameForUserAgent(), osNameForUserAgent(), osMarketingVersionString, webKitVersion];
- return [NSString stringWithFormat:@"Mozilla/5.0 (%@; CPU %@ %@ like Mac OS X) AppleWebKit/%@ (KHTML, like Gecko) %@", deviceNameForUserAgent(), osNameForUserAgent(), osMarketingVersionString, webKitVersion, static_cast<NSString *>(applicationName)];
+ String osVersion = systemMarketingVersionForUserAgentString();
+ String appNameSuffix = applicationName.isEmpty() ? "" : makeString(" ", applicationName);
+
+ return makeString("Mozilla/5.0 (", deviceNameForUserAgent(), "; CPU ", osNameForUserAgent(), " ", osVersion, " like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko)", appNameSuffix);
}
} // namespace WebCore.
Modified: trunk/Source/WebCore/platform/mac/UserAgentMac.mm (243186 => 243187)
--- trunk/Source/WebCore/platform/mac/UserAgentMac.mm 2019-03-20 02:01:41 UTC (rev 243186)
+++ trunk/Source/WebCore/platform/mac/UserAgentMac.mm 2019-03-20 02:52:33 UTC (rev 243187)
@@ -32,22 +32,12 @@
namespace WebCore {
-#if defined(__ppc__) || defined(__ppc64__)
-#define PROCESSOR "PPC"
-#elif defined(__i386__) || defined(__x86_64__)
-#define PROCESSOR "Intel"
-#else
-#error Unknown architecture
-#endif
-
String standardUserAgentWithApplicationName(const String& applicationName)
{
String osVersion = systemMarketingVersionForUserAgentString();
- String webKitVersionString = userAgentBundleVersion();
+ String appNameSuffix = applicationName.isEmpty() ? "" : makeString(" ", applicationName);
- if (applicationName.isEmpty())
- return makeString("Mozilla/5.0 (Macintosh; " PROCESSOR " Mac OS X ", osVersion, ") AppleWebKit/", webKitVersionString, " (KHTML, like Gecko)");
- return makeString("Mozilla/5.0 (Macintosh; " PROCESSOR " Mac OS X ", osVersion, ") AppleWebKit/", webKitVersionString, " (KHTML, like Gecko) ", applicationName);
+ return makeString("Mozilla/5.0 (Macintosh; Intel Mac OS X ", osVersion, ") AppleWebKit/605.1.15 (KHTML, like Gecko)", appNameSuffix);
}
} // namespace WebCore