Changeset 239384 in webkit
- Timestamp:
- Dec 19, 2018, 12:21:31 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 19 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/loader/DocumentLoader.h (modified) (2 diffs)
-
Source/WebCore/loader/FrameLoader.cpp (modified) (1 diff)
-
Source/WebCore/loader/FrameLoader.h (modified) (1 diff)
-
Source/WebCore/page/Navigator.cpp (modified) (1 diff)
-
Source/WebCore/page/Navigator.h (modified) (2 diffs)
-
Source/WebCore/page/NavigatorBase.cpp (modified) (1 diff)
-
Source/WebCore/page/NavigatorBase.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Shared/WebsitePoliciesData.cpp (modified) (4 diffs)
-
Source/WebKit/Shared/WebsitePoliciesData.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIWebsitePolicies.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/Cocoa/NavigationState.mm (modified) (1 diff)
-
Source/WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r239381 r239384 1 2018-12-19 Megan Gardner <megan_gardner@apple.com> 2 3 Allow clients to set the navigator platform 4 https://bugs.webkit.org/show_bug.cgi?id=192735 5 6 Reviewed by Tim Horton. 7 8 Expanded TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm. 9 10 Lots of piping to allow the setting of a custom navigator platform. 11 12 * loader/DocumentLoader.h: 13 (WebCore::DocumentLoader::setCustomNavigatorPlatform): 14 (WebCore::DocumentLoader::customNavigatorPlatform const): 15 * loader/FrameLoader.cpp: 16 (WebCore::FrameLoader::navigatorPlatform const): 17 * loader/FrameLoader.h: 18 * page/Navigator.cpp: 19 (WebCore::Navigator::platform const): 20 * page/Navigator.h: 21 * page/NavigatorBase.cpp: 22 (WebCore::NavigatorBase::platform const): 23 (WebCore::NavigatorBase::platform): Deleted. 24 * page/NavigatorBase.h: 25 1 26 2018-12-19 Ryan Haddad <ryanhaddad@apple.com> 2 27 -
trunk/Source/WebCore/loader/DocumentLoader.h
r239182 r239384 267 267 void setCustomUserAgent(const String& customUserAgent) { m_customUserAgent = customUserAgent; } 268 268 const String& customUserAgent() const { return m_customUserAgent; } 269 270 void setCustomNavigatorPlatform(const String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; } 271 const String& customNavigatorPlatform() const { return m_customNavigatorPlatform; } 269 272 270 273 OptionSet<AutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; } … … 537 540 #endif 538 541 String m_customUserAgent; 542 String m_customNavigatorPlatform; 539 543 bool m_userContentExtensionsEnabled { true }; 540 544 AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default }; -
trunk/Source/WebCore/loader/FrameLoader.cpp
r239182 r239384 2678 2678 return m_client.userAgent(url); 2679 2679 } 2680 2681 String FrameLoader::navigatorPlatform() const 2682 { 2683 if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { 2684 auto& customNavigatorPlatform = documentLoader->customNavigatorPlatform(); 2685 if (!customNavigatorPlatform.isEmpty()) 2686 return customNavigatorPlatform; 2687 } 2688 return String(); 2689 } 2680 2690 2681 2691 void FrameLoader::dispatchOnloadEvents() -
trunk/Source/WebCore/loader/FrameLoader.h
r238819 r239384 235 235 void dispatchOnloadEvents(); 236 236 String userAgent(const URL&) const; 237 String navigatorPlatform() const; 237 238 238 239 void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld&); -
trunk/Source/WebCore/page/Navigator.cpp
r237266 r239384 96 96 return m_userAgent; 97 97 } 98 99 const String& Navigator::platform() const 100 { 101 auto* frame = this->frame(); 102 if (!frame || !frame->page()) 103 return m_platform; 104 105 if (m_platform.isNull()) 106 m_platform = frame->loader().navigatorPlatform(); 107 108 if (m_platform.isNull()) 109 m_platform = NavigatorBase::platform(); 110 return m_platform; 111 } 98 112 99 113 void Navigator::userAgentChanged() -
trunk/Source/WebCore/page/Navigator.h
r237266 r239384 43 43 bool javaEnabled() const; 44 44 const String& userAgent() const final; 45 const String& platform() const final; 45 46 void userAgentChanged(); 46 47 bool onLine() const final; … … 59 60 mutable RefPtr<DOMMimeTypeArray> m_mimeTypes; 60 61 mutable String m_userAgent; 62 mutable String m_platform; 61 63 }; 62 64 -
trunk/Source/WebCore/page/NavigatorBase.cpp
r238538 r239384 101 101 } 102 102 103 String NavigatorBase::platform() 103 const String& NavigatorBase::platform() const 104 104 { 105 static NeverDestroyed<String> defaultPlatform = WEBCORE_NAVIGATOR_PLATFORM; 105 106 #if OS(LINUX) 106 107 if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty()) 107 return WEBCORE_NAVIGATOR_PLATFORM;108 return defaultPlatform; 108 109 struct utsname osname; 109 110 static NeverDestroyed<String> platformName(uname(&osname) >= 0 ? String(osname.sysname) + " "_str + String(osname.machine) : emptyString()); 110 111 return platformName; 111 112 #else 112 return WEBCORE_NAVIGATOR_PLATFORM;113 return defaultPlatform; 113 114 #endif 114 115 } -
trunk/Source/WebCore/page/NavigatorBase.h
r237185 r239384 44 44 String appVersion() const; 45 45 virtual const String& userAgent() const = 0; 46 static String platform();46 virtual const String& platform() const; 47 47 48 48 static String appCodeName(); -
trunk/Source/WebKit/ChangeLog
r239380 r239384 1 2018-12-19 Megan Gardner <megan_gardner@apple.com> 2 3 Allow clients to set the navigator platform 4 https://bugs.webkit.org/show_bug.cgi?id=192735 5 6 Reviewed by Tim Horton. 7 8 Add private API to allow clients to override the default navigator 9 platform. Some websites check for the platform, which 10 interfears with our request desktop site feature. This should 11 help more sites function as expected. 12 13 * Shared/WebsitePoliciesData.cpp: 14 (WebKit::WebsitePoliciesData::encode const): 15 (WebKit::WebsitePoliciesData::decode): 16 (WebKit::WebsitePoliciesData::applyToDocumentLoader): 17 * Shared/WebsitePoliciesData.h: 18 * UIProcess/API/APIWebsitePolicies.cpp: 19 (API::WebsitePolicies::data): 20 * UIProcess/API/APIWebsitePolicies.h: 21 * UIProcess/API/Cocoa/_WKWebsitePolicies.h: 22 * UIProcess/API/Cocoa/_WKWebsitePolicies.mm: 23 (-[_WKWebsitePolicies setCustomNavigatorPlatform:]): 24 (-[_WKWebsitePolicies customNavigatorPlatform]): 25 * UIProcess/Cocoa/NavigationState.mm: 26 (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction): 27 1 28 2018-12-19 Truitt Savell <tsavell@apple.com> 2 29 -
trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp
r239046 r239384 44 44 encoder << websiteDataStoreParameters; 45 45 encoder << customUserAgent; 46 encoder << customNavigatorPlatform; 46 47 } 47 48 … … 82 83 if (!customUserAgent) 83 84 return std::nullopt; 85 86 std::optional<String> customNavigatorPlatform; 87 decoder >> customNavigatorPlatform; 88 if (!customNavigatorPlatform) 89 return std::nullopt; 84 90 85 91 return { { … … 91 97 WTFMove(*websiteDataStoreParameters), 92 98 WTFMove(*customUserAgent), 99 WTFMove(*customNavigatorPlatform), 93 100 } }; 94 101 } … … 98 105 documentLoader.setCustomHeaderFields(WTFMove(websitePolicies.customHeaderFields)); 99 106 documentLoader.setCustomUserAgent(websitePolicies.customUserAgent); 107 documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform); 100 108 101 109 // Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers. -
trunk/Source/WebKit/Shared/WebsitePoliciesData.h
r239046 r239384 54 54 std::optional<WebsiteDataStoreParameters> websiteDataStoreParameters; 55 55 String customUserAgent; 56 String customNavigatorPlatform; 56 57 57 58 void encode(IPC::Encoder&) const; -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
r239046 r239384 57 57 if (m_websiteDataStore) 58 58 parameters = m_websiteDataStore->websiteDataStore().parameters(); 59 return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent };59 return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customNavigatorPlatform }; 60 60 } 61 61 -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h
r239046 r239384 72 72 void setCustomUserAgent(const WTF::String& customUserAgent) { m_customUserAgent = customUserAgent; } 73 73 const WTF::String& customUserAgent() const { return m_customUserAgent; } 74 75 void setCustomNavigatorPlatform(const WTF::String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; } 76 const WTF::String& customNavigatorPlatform() const { return m_customNavigatorPlatform; } 74 77 75 78 private: … … 83 86 RefPtr<WebsiteDataStore> m_websiteDataStore; 84 87 WTF::String m_customUserAgent; 88 WTF::String m_customNavigatorPlatform; 85 89 }; 86 90 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h
r239046 r239384 59 59 @property (nonatomic, strong) WKWebsiteDataStore *websiteDataStore WK_API_AVAILABLE(macosx(10.13.4), ios(11.3)); 60 60 @property (nonatomic, copy) NSString *customUserAgent WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 61 @property (nonatomic, copy) NSString *customNavigatorPlatform WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 61 62 62 63 @end -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm
r239046 r239384 194 194 } 195 195 196 - (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform 197 { 198 _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform); 199 } 200 201 - (NSString *)customNavigatorPlatform 202 { 203 return _websitePolicies->customNavigatorPlatform(); 204 } 205 196 206 - (NSString *)description 197 207 { -
trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm
r239078 r239384 550 550 if (!apiWebsitePolicies->customUserAgent().isNull() && subframeNavigation) 551 551 [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customUserAgent must be nil for subframe navigations."]; 552 if (!apiWebsitePolicies->customNavigatorPlatform().isNull() && subframeNavigation) 553 [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customNavigatorPlatform must be nil for subframe navigations."]; 552 554 } 553 555 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r239313 r239384 1 2018-12-19 Megan Gardner <megan_gardner@apple.com> 2 3 Allow clients to set the navigator platform 4 https://bugs.webkit.org/show_bug.cgi?id=192735 5 6 Reviewed by Tim Horton. 7 8 Add stubs to fill out the added functionality in FrameLoaderClient. 9 10 * WebCoreSupport/WebFrameLoaderClient.h: 11 * WebCoreSupport/WebFrameLoaderClient.mm: 12 (WebFrameLoaderClient::navigatorPlatform): 13 1 14 2018-12-17 Ryosuke Niwa <rniwa@webkit.org> 2 15 -
trunk/Tools/ChangeLog
r239380 r239384 1 2018-12-19 Megan Gardner <megan_gardner@apple.com> 2 3 Allow clients to set the navigator platform 4 https://bugs.webkit.org/show_bug.cgi?id=192735 5 6 Reviewed by Tim Horton. 7 8 Add a test for setting a custom navigator platform. 9 10 * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm: 11 (-[CustomNavigatorPlatformDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]): 12 (-[CustomNavigatorPlatformDelegate webView:didFinishNavigation:]): 13 1 14 2018-12-19 Truitt Savell <tsavell@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
r239210 r239384 984 984 } 985 985 986 @interface CustomNavigatorPlatformDelegate : NSObject <WKNavigationDelegate> { 987 } 988 @end 989 990 @implementation CustomNavigatorPlatformDelegate 991 992 - (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler 993 { 994 _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; 995 if (navigationAction.targetFrame.mainFrame) 996 [websitePolicies setCustomNavigatorPlatform:@"Test Custom Platform"]; 997 998 decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); 999 } 1000 1001 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation 1002 { 1003 finishedNavigation = true; 1004 } 1005 1006 @end 1007 1008 TEST(WebKit, WebsitePoliciesCustomNavigatorPlatform) 1009 { 1010 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1011 1012 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1013 1014 auto delegate = adoptNS([[CustomNavigatorPlatformDelegate alloc] init]); 1015 [webView setNavigationDelegate:delegate.get()]; 1016 1017 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,hello"]]; 1018 [webView loadRequest:request]; 1019 1020 TestWebKitAPI::Util::run(&finishedNavigation); 1021 finishedNavigation = false; 1022 1023 EXPECT_STREQ("Test Custom Platform", [[webView stringByEvaluatingJavaScript:@"navigator.platform"] UTF8String]); 1024 } 1025 1026 986 1027 @interface PopUpPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate> 987 1028 @property (nonatomic, copy) _WKWebsitePopUpPolicy(^popUpPolicyForURL)(NSURL *);
Note:
See TracChangeset
for help on using the changeset viewer.