WebKit Bugzilla
Attachment 356962 Details for
Bug 192509
: Add SPI to allow the client to set the user-agent at main frame level, from the UIProcess
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192509-20181210085037.patch (text/plain), 16.97 KB, created by
Chris Dumez
on 2018-12-10 08:50:38 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2018-12-10 08:50:38 PST
Size:
16.97 KB
patch
obsolete
>Subversion Revision: 238951 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index cfd3fe4b3a060b505fda1f947e5006592b03e384..423c4e34e2e9985a1577093df6af33c4eb9f12f5 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,17 @@ >+2018-12-07 Chris Dumez <cdumez@apple.com> >+ >+ Add SPI to allow the client to set the user-agent at frame level, from the UIProcess >+ https://bugs.webkit.org/show_bug.cgi?id=192509 >+ <rdar://problem/46500832> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * loader/DocumentLoader.h: >+ (WebCore::DocumentLoader::setCustomUserAgent): >+ (WebCore::DocumentLoader::customUserAgent const): >+ * loader/FrameLoader.cpp: >+ (WebCore::FrameLoader::userAgent const): >+ > 2018-12-07 Thibault Saunier <tsaunier@igalia.com> > > [WPE][GTK] Implement WebAudioSourceProviderGStreamer to allow bridging MediaStream and the WebAudio APIs >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 5896003dbcbd0f6211660c56d8a80a02912c8b57..c74ab57600d659da33e64fc53272791392ee10af 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,31 @@ >+2018-12-07 Chris Dumez <cdumez@apple.com> >+ >+ Add SPI to allow the client to set the user-agent at frame level, from the UIProcess >+ https://bugs.webkit.org/show_bug.cgi?id=192509 >+ <rdar://problem/46500832> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add SPI to allow the client to set the user-agent at frame level, from the UIProcess instead of doing >+ it at resource-level from the injected bundle. >+ >+ The custom user-agent string can now be set on _WKWebsitePolicies during the >+ decidePolicyForNavigationAction as impacts this main resource load as well as its >+ future subresource loads. >+ >+ * Shared/WebsitePoliciesData.cpp: >+ (WebKit::WebsitePoliciesData::encode const): >+ (WebKit::WebsitePoliciesData::decode): >+ (WebKit::WebsitePoliciesData::applyToDocumentLoader): >+ * Shared/WebsitePoliciesData.h: >+ * UIProcess/API/APIWebsitePolicies.cpp: >+ (API::WebsitePolicies::data): >+ * UIProcess/API/APIWebsitePolicies.h: >+ * UIProcess/API/Cocoa/_WKWebsitePolicies.h: >+ * UIProcess/API/Cocoa/_WKWebsitePolicies.mm: >+ (-[_WKWebsitePolicies setCustomUserAgent:]): >+ (-[_WKWebsitePolicies customUserAgent]): >+ > 2018-12-06 David Kilzer <ddkilzer@apple.com> > > Injected bundle for WebKitTestRunner leaks WKTypeRef objects >diff --git a/Source/WebCore/loader/DocumentLoader.h b/Source/WebCore/loader/DocumentLoader.h >index a62ff4428b4c00c7442c1737dbf0fc0814b0ec6b..501a527378f98161166f0a1cbe761425141105e0 100644 >--- a/Source/WebCore/loader/DocumentLoader.h >+++ b/Source/WebCore/loader/DocumentLoader.h >@@ -264,6 +264,9 @@ public: > AutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; } > void setAutoplayPolicy(AutoplayPolicy policy) { m_autoplayPolicy = policy; } > >+ void setCustomUserAgent(const String& customUserAgent) { m_customUserAgent = customUserAgent; } >+ const String& customUserAgent() const { return m_customUserAgent; } >+ > OptionSet<AutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; } > void setAllowedAutoplayQuirks(OptionSet<AutoplayQuirk> allowedQuirks) { m_allowedAutoplayQuirks = allowedQuirks; } > >@@ -532,6 +535,7 @@ private: > HashMap<String, RefPtr<StyleSheetContents>> m_pendingNamedContentExtensionStyleSheets; > HashMap<String, Vector<std::pair<String, uint32_t>>> m_pendingContentExtensionDisplayNoneSelectors; > #endif >+ String m_customUserAgent; > bool m_userContentExtensionsEnabled { true }; > AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default }; > OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks; >diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp >index a857e8feea96e1a4bfc27b1b3a77154e3271560b..915ddcae377bed77451b9d8ef4d1af63f33fbe3d 100644 >--- a/Source/WebCore/loader/FrameLoader.cpp >+++ b/Source/WebCore/loader/FrameLoader.cpp >@@ -2664,6 +2664,12 @@ int FrameLoader::numPendingOrLoadingRequests(bool recurse) const > > String FrameLoader::userAgent(const URL& url) const > { >+ if (auto* documentLoader = activeDocumentLoader()) { >+ auto& customUserAgent = documentLoader->customUserAgent(); >+ if (!customUserAgent.isEmpty()) >+ return customUserAgent; >+ } >+ > return m_client.userAgent(url); > } > >diff --git a/Source/WebKit/Shared/WebsitePoliciesData.cpp b/Source/WebKit/Shared/WebsitePoliciesData.cpp >index 6073b2fa512d5517f5ab097e98d64b5d9f37098f..df6d3ae2c187da405b548d6774a85d295edada1e 100644 >--- a/Source/WebKit/Shared/WebsitePoliciesData.cpp >+++ b/Source/WebKit/Shared/WebsitePoliciesData.cpp >@@ -42,6 +42,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const > encoder << customHeaderFields; > encoder << popUpPolicy; > encoder << websiteDataStoreParameters; >+ encoder << customUserAgent; > } > > std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder) >@@ -75,6 +76,11 @@ std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& dec > decoder >> websiteDataStoreParameters; > if (!websiteDataStoreParameters) > return std::nullopt; >+ >+ std::optional<String> customUserAgent; >+ decoder >> customUserAgent; >+ if (!customUserAgent) >+ return std::nullopt; > > return { { > WTFMove(*contentBlockersEnabled), >@@ -83,12 +89,14 @@ std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& dec > WTFMove(*customHeaderFields), > WTFMove(*popUpPolicy), > WTFMove(*websiteDataStoreParameters), >+ WTFMove(*customUserAgent), > } }; > } > > void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePolicies, WebCore::DocumentLoader& documentLoader) > { > documentLoader.setCustomHeaderFields(WTFMove(websitePolicies.customHeaderFields)); >+ documentLoader.setCustomUserAgent(websitePolicies.customUserAgent); > > // Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers. > if (documentLoader.userContentExtensionsEnabled()) >diff --git a/Source/WebKit/Shared/WebsitePoliciesData.h b/Source/WebKit/Shared/WebsitePoliciesData.h >index 447df65bf4d110a6ff22c37328fd3724cb59b933..7944c466ec60e1637a5a93428a17fa6da64d2427 100644 >--- a/Source/WebKit/Shared/WebsitePoliciesData.h >+++ b/Source/WebKit/Shared/WebsitePoliciesData.h >@@ -52,6 +52,7 @@ struct WebsitePoliciesData { > Vector<WebCore::HTTPHeaderField> customHeaderFields; > WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default }; > std::optional<WebsiteDataStoreParameters> websiteDataStoreParameters; >+ String customUserAgent; > > void encode(IPC::Encoder&) const; > static std::optional<WebsitePoliciesData> decode(IPC::Decoder&); >diff --git a/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp b/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >index 740b6b56e76c729a4f14a5cd5c54e38d9f9a86a6..f4414425a9d4abfacbba3876fe7c4c29cc45100c 100644 >--- a/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >+++ b/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >@@ -56,7 +56,7 @@ WebKit::WebsitePoliciesData WebsitePolicies::data() > std::optional<WebKit::WebsiteDataStoreParameters> parameters; > if (m_websiteDataStore) > parameters = m_websiteDataStore->websiteDataStore().parameters(); >- return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters) }; >+ return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent }; > } > > } >diff --git a/Source/WebKit/UIProcess/API/APIWebsitePolicies.h b/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >index 95ae1a1ea10ab7b71e7910e973b317f42d8358e3..5f66abeba614b8a515676cf0afc7a00196d9e606 100644 >--- a/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >+++ b/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >@@ -69,6 +69,9 @@ public: > > WebKit::WebsitePoliciesData data(); > >+ void setCustomUserAgent(const WTF::String& customUserAgent) { m_customUserAgent = customUserAgent; } >+ const WTF::String& customUserAgent() const { return m_customUserAgent; } >+ > private: > WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&); > >@@ -78,6 +81,7 @@ private: > Vector<WebCore::HTTPHeaderField> m_customHeaderFields; > WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default }; > RefPtr<WebsiteDataStore> m_websiteDataStore; >+ WTF::String m_customUserAgent; > }; > > } // namespace API >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >index fe95705d377505c7b3b9c35761975346c369cb5b..ead50191863079a944d56bf7e1d992f07a9502fa 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >@@ -57,6 +57,7 @@ WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3)) > @property (nonatomic, copy) NSDictionary<NSString *, NSString *> *customHeaderFields WK_API_AVAILABLE(macosx(10.13.4), ios(11.3)); > @property (nonatomic) _WKWebsitePopUpPolicy popUpPolicy WK_API_AVAILABLE(macosx(10.14), ios(12.0)); > @property (nonatomic, strong) WKWebsiteDataStore *websiteDataStore WK_API_AVAILABLE(macosx(10.13.4), ios(11.3)); >+@property (nonatomic, copy) NSString *customUserAgent WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > > @end > >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >index 375f08df4ffc744eec14d71adeb7577acfa17d0c..03bd177942e5baa91d5d69b08a607153d815cd45 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >@@ -183,6 +183,16 @@ - (void)setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore > _websitePolicies->setWebsiteDataStore(websiteDataStore->_websiteDataStore.get()); > } > >+- (void)setCustomUserAgent:(NSString *)customUserAgent >+{ >+ _websitePolicies->setCustomUserAgent(customUserAgent); >+} >+ >+- (NSString *)customUserAgent >+{ >+ return _websitePolicies->customUserAgent(); >+} >+ > - (NSString *)description > { > return [NSString stringWithFormat:@"<%@: %p; contentBlockersEnabled = %d>", NSStringFromClass(self.class), self, self.contentBlockersEnabled]; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 97a692bad01dc317e908b26f01318ba7eb506a64..fa30831c8023fa98d3d999bd665fd5ac8d1d5379 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,21 @@ >+2018-12-07 Chris Dumez <cdumez@apple.com> >+ >+ Add SPI to allow the client to set the user-agent at frame level, from the UIProcess >+ https://bugs.webkit.org/show_bug.cgi?id=192509 >+ <rdar://problem/46500832> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add API test coverage. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm: >+ (-[DataMappingSchemeHandler addMappingFromURLString:toData:]): >+ (-[DataMappingSchemeHandler webView:startURLSchemeTask:]): >+ (-[DataMappingSchemeHandler webView:stopURLSchemeTask:]): >+ (-[CustomUserAgentDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]): >+ (-[CustomUserAgentDelegate webView:didFinishNavigation:]): >+ (websiteDataStoreTestWebView): Deleted. >+ > 2018-12-06 Jonathan Bedard <jbedard@apple.com> > > Consecutive DumpRenderTree crashes are happening again on WinCairo BuildBots since r238903 >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm >index f146b796e90c2537c7d2a8dbee45b0177de01e04..62d7f81c38fd0c1315a00f07f3c8b55a417d9939 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm >@@ -38,8 +38,10 @@ > #import <WebKit/_WKUserContentExtensionStorePrivate.h> > #import <WebKit/_WKWebsiteDataStoreConfiguration.h> > #import <WebKit/_WKWebsitePolicies.h> >+#import <wtf/HashMap.h> > #import <wtf/MainThread.h> > #import <wtf/RetainPtr.h> >+#import <wtf/text/StringHash.h> > #import <wtf/text/WTFString.h> > > #if PLATFORM(IOS_FAMILY) >@@ -54,6 +56,7 @@ @end > > static bool doneCompiling; > static bool receivedAlert; >+static bool finishedNavigation; > > #if PLATFORM(MAC) > static std::optional<_WKAutoplayEvent> receivedAutoplayEvent; >@@ -859,6 +862,122 @@ TEST(WebKit, CustomHeaderFields) > TestWebKitAPI::Util::run(&thirdTestDone); > } > >+static unsigned loadCount; >+ >+@interface DataMappingSchemeHandler : NSObject <WKURLSchemeHandler> { >+ HashMap<String, RetainPtr<NSData *>> _dataMappings; >+} >+- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data; >+@end >+ >+@implementation DataMappingSchemeHandler >+ >+- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data >+{ >+ _dataMappings.set(urlString, [NSData dataWithBytesNoCopy:(void*)data length:strlen(data) freeWhenDone:NO]); >+} >+ >+- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task >+{ >+ NSURL *finalURL = task.request.URL; >+ >+ ++loadCount; >+ if ([finalURL.host isEqualToString:@"www.webkit.org"]) >+ EXPECT_STREQ("Main Frame Custom UserAgent", [[task.request valueForHTTPHeaderField:@"User-Agent"] UTF8String]); >+ else >+ EXPECT_STREQ("Subframe Custom UserAgent", [[task.request valueForHTTPHeaderField:@"User-Agent"] UTF8String]); >+ >+ auto response = adoptNS([[NSURLResponse alloc] initWithURL:finalURL MIMEType:@"text/html" expectedContentLength:1 textEncodingName:nil]); >+ [task didReceiveResponse:response.get()]; >+ >+ if (auto data = _dataMappings.get([finalURL absoluteString])) >+ [task didReceiveData:data.get()]; >+ else >+ [task didReceiveData:[@"Hello" dataUsingEncoding:NSUTF8StringEncoding]]; >+ [task didFinish]; >+} >+ >+- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task >+{ >+} >+ >+@end >+ >+@interface CustomUserAgentDelegate : NSObject <WKNavigationDelegate> { >+} >+@end >+ >+@implementation CustomUserAgentDelegate >+ >+- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler >+{ >+ _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; >+ if (navigationAction.targetFrame.mainFrame) >+ [websitePolicies setCustomUserAgent:@"Main Frame Custom UserAgent"]; >+ else >+ [websitePolicies setCustomUserAgent:@"Subframe Custom UserAgent"]; >+ decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); >+} >+ >+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation >+{ >+ finishedNavigation = true; >+} >+ >+@end >+ >+static const char* customUserAgentMainFrameTestBytes = R"TESTRESOURCE( >+<script src="test://www.webkit.org/script.js"></script> >+<img src="test://www.webkit.org/image.png"></img> >+<iframe src="test://www.apple.com/subframe.html"></iframe> >+<script> >+onload = () => { >+ setTimeout(() => { >+ fetch("test://www.webkit.org/fetchResource.html"); >+ }, 0); >+} >+</script> >+)TESTRESOURCE"; >+ >+static const char* customUserAgentSubFrameTestBytes = R"TESTRESOURCE( >+<script src="test://www.apple.com/script.js"></script> >+<img src="test://www.apple.com/image.png"></img> >+<iframe src="test://www.apple.com/subframe2.html"></iframe> >+<script> >+onload = () => { >+ setTimeout(() => { >+ fetch("test://www.apple.com/fetchResource.html"); >+ }, 0); >+} >+</script> >+)TESTRESOURCE"; >+ >+TEST(WebKit, WebsitePoliciesCustomUserAgent) >+{ >+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); >+ >+ auto schemeHandler = adoptNS([[DataMappingSchemeHandler alloc] init]); >+ [schemeHandler addMappingFromURLString:@"test://www.webkit.org/main.html" toData:customUserAgentMainFrameTestBytes]; >+ [schemeHandler addMappingFromURLString:@"test://www.apple.com/subframe.html" toData:customUserAgentSubFrameTestBytes]; >+ [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"]; >+ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); >+ >+ auto delegate = adoptNS([[CustomUserAgentDelegate alloc] init]); >+ [webView setNavigationDelegate:delegate.get()]; >+ >+ loadCount = 0; >+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"test://www.webkit.org/main.html"]]; >+ [webView loadRequest:request]; >+ >+ TestWebKitAPI::Util::run(&finishedNavigation); >+ finishedNavigation = false; >+ >+ while (loadCount != 9U) >+ TestWebKitAPI::Util::spinRunLoop(); >+ loadCount = 0; >+} >+ > @interface PopUpPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate> > @property (nonatomic, copy) _WKWebsitePopUpPolicy(^popUpPolicyForURL)(NSURL *); > @end
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192509
:
356829
|
356962
|
356966