Bug 134522 - Remove duplication in code that prepares the user agent string on Mac and iOS
Summary: Remove duplication in code that prepares the user agent string on Mac and iOS
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Rowe (bdash)
URL:
Keywords:
Depends on:
Blocks: 134524
  Show dependency treegraph
 
Reported: 2014-07-01 16:30 PDT by Mark Rowe (bdash)
Modified: 2014-07-02 16:10 PDT (History)
0 users

See Also:


Attachments
Patch (12.23 KB, patch)
2014-07-01 16:40 PDT, Mark Rowe (bdash)
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Rowe (bdash) 2014-07-01 16:30:38 PDT
We have three copies of the code that formats the WebKit version for use in the user agent string. We should move the logic to WebCore so it can be shared between WebKit and WebKit2.
Comment 1 Mark Rowe (bdash) 2014-07-01 16:40:59 PDT
Created attachment 234216 [details]
Patch
Comment 2 Simon Fraser (smfr) 2014-07-02 14:50:05 PDT
Comment on attachment 234216 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=234216&action=review

> Source/WebCore/page/cocoa/UserAgent.mm:51
> +    // If the version is longer than 3 digits then the leading digits represent the version of the OS. Our user agent
> +    // string should not include the leading digits, so strip them off and report the rest as the version. <rdar://problem/4997547>
> +    NSRange nonDigitRange = [fullWebKitVersion rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
> +    if (nonDigitRange.location == NSNotFound && fullWebKitVersion.length > 3)
> +        return [fullWebKitVersion substringFromIndex:fullWebKitVersion.length - 3];
> +    if (nonDigitRange.location != NSNotFound && nonDigitRange.location > 3)
> +        return [fullWebKitVersion substringFromIndex:nonDigitRange.location - 3];

Sad that we go to NSString and back.

> Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm:66
> +    return [[NSBundle bundleForClass:NSClassFromString(@"WKView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

There's a WKView in WebCore. Is that really the one we want?

> Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm:102
> +    return [[NSBundle bundleForClass:NSClassFromString(@"WKView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

WKView again?
Comment 3 Mark Rowe (bdash) 2014-07-02 15:09:00 PDT
(In reply to comment #2)
> > Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm:66
> > +    return [[NSBundle bundleForClass:NSClassFromString(@"WKView")] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
> 
> There's a WKView in WebCore. Is that really the one we want?

The WKView class lives in WebKit2. I'll change to WKWebView though since that's now WebKit2's primary class.
Comment 4 Mark Rowe (bdash) 2014-07-02 16:10:15 PDT
Landed in r170734.
<https://trac.webkit.org/r170734>