Changeset 246236 in webkit
- Timestamp:
- Jun 8, 2019 8:55:01 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r246235 r246236 1 2019-06-08 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] The default application name for user agent when requesting desktop content is still "Mobile/15E148" 4 https://bugs.webkit.org/show_bug.cgi?id=198693 5 <rdar://problem/51555371> 6 7 Reviewed by Tim Horton. 8 9 Fixes the bug by introducing an applicationNameForDesktopUserAgent member to WebPageProxy. This 10 applicationNameForDesktopUserAgent is set alongside the regular applicationNameForUserAgent; however, in the 11 case where it is being set via WKWebViewConfiguration, use WKWebViewConfiguration's 12 _applicationNameForDesktopUserAgent instead. See below for more details. 13 14 Tested by adding to the existing API test PreferredContentMode.ApplicationNameForDesktopUserAgent. 15 16 * UIProcess/API/APIWebsitePolicies.cpp: 17 (API::WebsitePolicies::copy const): 18 * UIProcess/API/APIWebsitePolicies.h: 19 20 Drive-by fix: rename applicationNameForUserAgentWithModernCompatibility to applicationNameForDesktopUserAgent in 21 a few places. 22 23 * UIProcess/API/Cocoa/WKBrowsingContextController.mm: 24 (-[WKBrowsingContextController setApplicationNameForUserAgent:]): 25 * UIProcess/API/Cocoa/WKWebView.mm: 26 (-[WKWebView _initializeWithConfiguration:]): 27 (-[WKWebView _setApplicationNameForUserAgent:]): 28 * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: 29 30 Change _applicationNameForUserAgent into an Optional<RetainPtr<NSString>>. A value of WTF::nullopt allows us to 31 know that the default application name should be used (which is different when requesting desktop content). 32 33 (-[WKWebViewConfiguration encodeWithCoder:]): 34 (-[WKWebViewConfiguration initWithCoder:]): 35 (-[WKWebViewConfiguration copyWithZone:]): 36 (-[WKWebViewConfiguration _applicationNameForDesktopUserAgent]): 37 38 Add _applicationNameForDesktopUserAgent to the web view configuration. This behaves like 39 applicationNameForUserAgent, with one exception: in the case where the default applicationNameForUserAgent is 40 used (i.e. the client has not specified any application name), default to `nil` as the application name for user 41 agent, rather than "Mobile/15E148". 42 43 (-[WKWebViewConfiguration applicationNameForUserAgent]): 44 (-[WKWebViewConfiguration setApplicationNameForUserAgent:]): 45 * UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h: 46 * UIProcess/API/Cocoa/WKWebpagePreferences.mm: 47 (-[WKWebpagePreferences _applicationNameForUserAgentWithModernCompatibility]): 48 (-[WKWebpagePreferences _setApplicationNameForUserAgentWithModernCompatibility:]): 49 * UIProcess/WebPageProxy.h: 50 (WebKit::WebPageProxy::setApplicationNameForDesktopUserAgent): 51 (WebKit::WebPageProxy::applicationNameForDesktopUserAgent const): 52 * UIProcess/ios/WebPageProxyIOS.mm: 53 (WebKit::WebPageProxy::effectiveContentModeAfterAdjustingPolicies): 54 1 55 2019-06-08 Andy Estes <aestes@apple.com> 2 56 -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
r246118 r246236 76 76 policies->setCustomHeaderFields(WTFMove(customHeaderFields)); 77 77 policies->setAllowSiteSpecificQuirksToOverrideContentMode(m_allowSiteSpecificQuirksToOverrideContentMode); 78 policies->setApplicationNameFor UserAgentWithModernCompatibility(m_applicationNameForUserAgentWithModernCompatibility);78 policies->setApplicationNameForDesktopUserAgent(m_applicationNameForDesktopUserAgent); 79 79 return policies; 80 80 } -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h
r246118 r246236 112 112 void setAllowSiteSpecificQuirksToOverrideContentMode(bool value) { m_allowSiteSpecificQuirksToOverrideContentMode = value; } 113 113 114 WTF::String applicationNameFor UserAgentWithModernCompatibility() const { return m_applicationNameForUserAgentWithModernCompatibility; }115 void setApplicationNameFor UserAgentWithModernCompatibility(const WTF::String& applicationName) { m_applicationNameForUserAgentWithModernCompatibility= applicationName; }114 WTF::String applicationNameForDesktopUserAgent() const { return m_applicationNameForDesktopUserAgent; } 115 void setApplicationNameForDesktopUserAgent(const WTF::String& applicationName) { m_applicationNameForDesktopUserAgent = applicationName; } 116 116 117 117 private: … … 137 137 WebKit::WebsiteLegacyOverflowScrollingTouchPolicy m_legacyOverflowScrollingTouchPolicy { WebKit::WebsiteLegacyOverflowScrollingTouchPolicy::Default }; 138 138 bool m_allowSiteSpecificQuirksToOverrideContentMode { false }; 139 WTF::String m_applicationNameFor UserAgentWithModernCompatibility;139 WTF::String m_applicationNameForDesktopUserAgent; 140 140 }; 141 141 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm
r242339 r246236 200 200 - (void)setApplicationNameForUserAgent:(NSString *)applicationNameForUserAgent 201 201 { 202 _page->setApplicationNameForDesktopUserAgent(applicationNameForUserAgent); 202 203 _page->setApplicationNameForUserAgent(applicationNameForUserAgent); 203 204 } -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r246230 r246236 749 749 _page->setApplicationNameForUserAgent(applicationNameForUserAgent); 750 750 751 _page->setApplicationNameForDesktopUserAgent(configuration._applicationNameForDesktopUserAgent); 752 751 753 _navigationState = std::make_unique<WebKit::NavigationState>(self); 752 754 _page->setNavigationClient(_navigationState->createNavigationClient()); … … 4783 4785 { 4784 4786 _page->setApplicationNameForUserAgent(applicationNameForUserAgent); 4787 _page->setApplicationNameForDesktopUserAgent(applicationNameForUserAgent); 4785 4788 } 4786 4789 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
r245491 r246236 123 123 WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures; 124 124 RetainPtr<NSString> _groupIdentifier; 125 LazyInitialized<RetainPtr<NSString>> _applicationNameForUserAgent;125 Optional<RetainPtr<NSString>> _applicationNameForUserAgent; 126 126 NSTimeInterval _incrementalRenderingSuppressionTimeout; 127 127 BOOL _respectsImageOrientation; … … 287 287 288 288 [coder encodeBool:self.suppressesIncrementalRendering forKey:@"suppressesIncrementalRendering"]; 289 [coder encodeObject:self.applicationNameForUserAgent forKey:@"applicationNameForUserAgent"]; 289 290 if (_applicationNameForUserAgent.hasValue()) 291 [coder encodeObject:self.applicationNameForUserAgent forKey:@"applicationNameForUserAgent"]; 292 290 293 [coder encodeBool:self.allowsAirPlayForMediaPlayback forKey:@"allowsAirPlayForMediaPlayback"]; 291 294 … … 321 324 322 325 self.suppressesIncrementalRendering = [coder decodeBoolForKey:@"suppressesIncrementalRendering"]; 323 self.applicationNameForUserAgent = decodeObjectOfClassForKeyFromCoder([NSString class], @"applicationNameForUserAgent", coder); 326 327 if ([coder containsValueForKey:@"applicationNameForUserAgent"]) 328 self.applicationNameForUserAgent = decodeObjectOfClassForKeyFromCoder([NSString class], @"applicationNameForUserAgent", coder); 329 324 330 self.allowsAirPlayForMediaPlayback = [coder decodeBoolForKey:@"allowsAirPlayForMediaPlayback"]; 325 331 … … 367 373 368 374 configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering; 369 configuration .applicationNameForUserAgent = self.applicationNameForUserAgent;375 configuration->_applicationNameForUserAgent = self->_applicationNameForUserAgent; 370 376 371 377 configuration->_respectsImageOrientation = self->_respectsImageOrientation; … … 496 502 } 497 503 504 - (NSString *)_applicationNameForDesktopUserAgent 505 { 506 return _applicationNameForUserAgent.valueOr(nil).get(); 507 } 508 498 509 - (NSString *)applicationNameForUserAgent 499 510 { 500 return _applicationNameForUserAgent. get([] { return defaultApplicationNameForUserAgent(); });511 return _applicationNameForUserAgent.valueOr(defaultApplicationNameForUserAgent()).get(); 501 512 } 502 513 503 514 - (void)setApplicationNameForUserAgent:(NSString *)applicationNameForUserAgent 504 515 { 505 _applicationNameForUserAgent. set(adoptNS([applicationNameForUserAgent copy]));516 _applicationNameForUserAgent.emplace(adoptNS(applicationNameForUserAgent.copy)); 506 517 } 507 518 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h
r242339 r246236 36 36 @property (nonatomic, setter=_setContentProviderRegistry:) WKWebViewContentProviderRegistry *_contentProviderRegistry; 37 37 #endif 38 @property (nonatomic, readonly) NSString *_applicationNameForDesktopUserAgent; 38 39 39 40 - (Ref<API::PageConfiguration>)copyPageConfiguration; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
r246118 r246236 319 319 - (NSString *)_applicationNameForUserAgentWithModernCompatibility 320 320 { 321 return _websitePolicies->applicationNameFor UserAgentWithModernCompatibility();321 return _websitePolicies->applicationNameForDesktopUserAgent(); 322 322 } 323 323 324 324 - (void)_setApplicationNameForUserAgentWithModernCompatibility:(NSString *)applicationName 325 325 { 326 _websitePolicies->setApplicationNameFor UserAgentWithModernCompatibility(applicationName);326 _websitePolicies->setApplicationNameForDesktopUserAgent(applicationName); 327 327 } 328 328 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r246235 r246236 856 856 void setApplicationNameForUserAgent(const String&); 857 857 const String& applicationNameForUserAgent() const { return m_applicationNameForUserAgent; } 858 void setApplicationNameForDesktopUserAgent(const String& applicationName) { m_applicationNameForDesktopUserAgent = applicationName; } 859 const String& applicationNameForDesktopUserAgent() const { return m_applicationNameForDesktopUserAgent; } 858 860 void setCustomUserAgent(const String&); 859 861 const String& customUserAgent() const { return m_customUserAgent; } … … 2146 2148 String m_userAgent; 2147 2149 String m_applicationNameForUserAgent; 2150 String m_applicationNameForDesktopUserAgent; 2148 2151 String m_customUserAgent; 2149 2152 String m_customTextEncodingName; -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r246213 r246236 1383 1383 1384 1384 if (policies.customUserAgent().isEmpty() && customUserAgent().isEmpty()) { 1385 auto applicationName = policies.applicationNameFor UserAgentWithModernCompatibility();1385 auto applicationName = policies.applicationNameForDesktopUserAgent(); 1386 1386 if (applicationName.isEmpty()) 1387 applicationName = applicationNameFor UserAgent();1387 applicationName = applicationNameForDesktopUserAgent(); 1388 1388 policies.setCustomUserAgent(standardUserAgentWithApplicationName(applicationName, UserAgentType::Desktop)); 1389 1389 } -
trunk/Tools/ChangeLog
r246233 r246236 1 2019-06-08 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] The default application name for user agent when requesting desktop content is still "Mobile/15E148" 4 https://bugs.webkit.org/show_bug.cgi?id=198693 5 <rdar://problem/51555371> 6 7 Reviewed by Tim Horton. 8 9 Augment an existing API test to exercise three additional scenarios: 10 - The web view configuration's application name is never set; the default should not include 11 "Mobile/15E148" in desktop mode. 12 - The application name is explicitly set to nil; the default application name should still not include 13 "Mobile/15E148". 14 - The application name is explicitly set to the default value, "Mobile/15E148". WKWebView should honor 15 this when generating the user agent, even in desktop mode. 16 17 * TestWebKitAPI/ios/PreferredContentMode.mm: 18 (TestWebKitAPI::setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate): 19 (TestWebKitAPI::setUpWebViewForPreferredContentModeTesting): 20 (TestWebKitAPI::TEST): 21 1 22 2019-06-08 Zalan Bujtas <zalan@apple.com> 2 23 -
trunk/Tools/TestWebKitAPI/ios/PreferredContentMode.mm
r246118 r246236 186 186 187 187 template <typename ViewClass> 188 RetainPtr<ViewClass> setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate(Optional<WKContentMode> defaultContentMode = { }, const String& applicationNameForUserAgent = "TestWebKitAPI", CGSize size = CGSizeMake(1024, 768))188 RetainPtr<ViewClass> setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate(Optional<WKContentMode> defaultContentMode = { }, Optional<String> applicationNameForUserAgent = { "TestWebKitAPI" }, CGSize size = CGSizeMake(1024, 768)) 189 189 { 190 190 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 191 191 if (defaultContentMode) 192 192 [configuration setDefaultWebpagePreferences:[WKWebpagePreferences preferencesWithContentMode:defaultContentMode.value()]]; 193 if ( !!applicationNameForUserAgent)194 [configuration setApplicationNameForUserAgent:applicationNameForUserAgent ];193 if (applicationNameForUserAgent) 194 [configuration setApplicationNameForUserAgent:applicationNameForUserAgent->isNull() ? nil : (NSString *)applicationNameForUserAgent.value()]; 195 195 auto webView = adoptNS([[ViewClass alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) configuration:configuration.get()]); 196 196 EXPECT_TRUE([webView isKindOfClass:WKWebView.class]); … … 199 199 200 200 template <typename ViewClass> 201 std::pair<RetainPtr<ViewClass>, RetainPtr<ContentModeNavigationDelegate>> setUpWebViewForPreferredContentModeTesting(Optional<WKContentMode> defaultContentMode = { }, const String& applicationNameForUserAgent = "TestWebKitAPI", CGSize size = CGSizeMake(1024, 768))201 std::pair<RetainPtr<ViewClass>, RetainPtr<ContentModeNavigationDelegate>> setUpWebViewForPreferredContentModeTesting(Optional<WKContentMode> defaultContentMode = { }, Optional<String> applicationNameForUserAgent = { "TestWebKitAPI" }, CGSize size = CGSizeMake(1024, 768)) 202 202 { 203 203 auto webView = setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate<ViewClass>(defaultContentMode, applicationNameForUserAgent, size); … … 248 248 IPadUserInterfaceSwizzler iPadUserInterface; 249 249 250 auto webView = setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate<TestWKWebView>(WKContentModeDesktop , "TestWebKitAPI");250 auto webView = setUpWebViewForPreferredContentModeTestingWithoutNavigationDelegate<TestWKWebView>(WKContentModeDesktop); 251 251 [webView loadHTMLString:@"<body>Hello world</body>" baseURL:nil]; 252 252 … … 403 403 RetainPtr<TestWKWebView> webView; 404 404 RetainPtr<ContentModeNavigationDelegate> delegate; 405 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>({ }, "TestWebKitAPI", CGSizeZero);405 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>({ }, { "TestWebKitAPI" }, CGSizeZero); 406 406 [webView loadTestPageNamed:@"simple" andExpectEffectiveContentMode:WKContentModeDesktop withPolicyDecisionHandler:nil]; 407 407 [[webView navigatorUserAgent] shouldContainStrings:@"Mozilla/5.0 (Macintosh", @"TestWebKitAPI", nil]; … … 429 429 [[webView navigatorUserAgent] shouldContainStrings:@"Mozilla/5.0 (Macintosh", @"DesktopBrowser", nil]; 430 430 EXPECT_WK_STREQ("MacIntel", [webView navigatorPlatform]); 431 432 { 433 // Don't attempt to change the application name, but still opt into desktop-class browsing; 434 // the application name should not default to "Mobile/15E148". 435 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>(WKContentModeDesktop, { }); 436 [webView loadTestPageNamed:@"simple" withPolicyDecisionHandler:nil]; 437 NSString *userAgent = [webView navigatorUserAgent]; 438 EXPECT_FALSE([userAgent containsString:@"Mobile"]); 439 EXPECT_TRUE([userAgent containsString:@"Macintosh"]); 440 } 441 { 442 // Don't attempt to change the application name, but this time, opt into mobile content. The application 443 // name should default to "Mobile/15E148". 444 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>(WKContentModeMobile, { }); 445 [webView loadTestPageNamed:@"simple" withPolicyDecisionHandler:nil]; 446 NSString *userAgent = [webView navigatorUserAgent]; 447 EXPECT_TRUE([userAgent containsString:@"Mobile"]); 448 EXPECT_FALSE([userAgent containsString:@"Macintosh"]); 449 } 450 { 451 // Manually set the application name for user agent to the default value, Mobile/15E148. 452 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>(WKContentModeDesktop, { "Mobile/15E148" }); 453 [webView loadTestPageNamed:@"simple" withPolicyDecisionHandler:nil]; 454 NSString *userAgent = [webView navigatorUserAgent]; 455 EXPECT_TRUE([userAgent containsString:@"Mobile"]); 456 EXPECT_TRUE([userAgent containsString:@"Macintosh"]); 457 } 458 { 459 // Manually set the application name for user agent to nil. 460 std::tie(webView, delegate) = setUpWebViewForPreferredContentModeTesting<WKWebView>(WKContentModeDesktop, {{ }}); 461 [webView loadTestPageNamed:@"simple" withPolicyDecisionHandler:nil]; 462 NSString *userAgent = [webView navigatorUserAgent]; 463 EXPECT_FALSE([userAgent containsString:@"Mobile"]); 464 EXPECT_TRUE([userAgent containsString:@"Macintosh"]); 465 } 431 466 } 432 467
Note: See TracChangeset
for help on using the changeset viewer.