Changeset 251814 in webkit
- Timestamp:
- Oct 30, 2019 3:39:31 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r251811 r251814 1 2019-10-30 Alex Christensen <achristensen@webkit.org> 2 3 WKContentRuleLists should block requests from service workers 4 https://bugs.webkit.org/show_bug.cgi?id=201980 5 <rdar://problem/55516735> 6 7 Reviewed by Chris Dumez. 8 9 * http/tests/contentextensions/resources/fetch-worker.js: Added. 10 (event.fetch.string_appeared_here.then): 11 (event.catch): 12 * http/tests/contentextensions/resources/serviceworkertest.js: Added. 13 (testServiceWorker): 14 (test): 15 * http/tests/contentextensions/service-worker.https-expected.txt: Added. 16 * http/tests/contentextensions/service-worker.https.html: Added. 17 * http/tests/contentextensions/service-worker.https.html.json: Added. 18 1 19 2019-10-30 Daniel Bates <dabates@apple.com> 2 20 -
trunk/Source/WebKit/ChangeLog
r251798 r251814 1 2019-10-30 Alex Christensen <achristensen@webkit.org> 2 3 WKContentRuleLists should block requests from service workers 4 https://bugs.webkit.org/show_bug.cgi?id=201980 5 <rdar://problem/55516735> 6 7 Reviewed by Chris Dumez. 8 9 Test: http/tests/contentextensions/service-worker.https.html 10 11 Also covered by an API test. 12 13 * Shared/ServiceWorkerInitializationData.cpp: Added. 14 (WebKit::ServiceWorkerInitializationData::encode const): 15 (WebKit::ServiceWorkerInitializationData::decode): 16 * Shared/ServiceWorkerInitializationData.h: Added. 17 * Sources.txt: 18 * UIProcess/UserContent/WebUserContentControllerProxy.cpp: 19 (WebKit::WebUserContentControllerProxy::addProcess): 20 (WebKit::WebUserContentControllerProxy::contentRuleListData): 21 * UIProcess/UserContent/WebUserContentControllerProxy.h: 22 * UIProcess/WebProcessPool.cpp: 23 (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess): 24 (WebKit::WebProcessPool::createWebPage): 25 * UIProcess/WebProcessPool.h: 26 * UIProcess/WebProcessProxy.cpp: 27 (WebKit::WebProcessProxy::createForServiceWorkers): 28 (WebKit::WebProcessProxy::establishServiceWorkerContext): 29 (WebKit::contentRuleListsFromIdentifier): 30 (WebKit::WebProcessProxy::enableServiceWorkers): 31 * UIProcess/WebProcessProxy.h: 32 * WebKit.xcodeproj/project.pbxproj: 33 * WebProcess/Storage/WebSWContextManagerConnection.cpp: 34 (WebKit::WebSWContextManagerConnection::WebSWContextManagerConnection): 35 (WebKit::m_userAgent): 36 (WebKit::WebSWContextManagerConnection::installServiceWorker): 37 * WebProcess/Storage/WebSWContextManagerConnection.h: 38 * WebProcess/WebProcess.cpp: 39 (WebKit::WebProcess::establishWorkerContextConnectionToNetworkProcess): 40 * WebProcess/WebProcess.h: 41 * WebProcess/WebProcess.messages.in: 42 1 43 2019-10-30 Andres Gonzalez <andresg_22@apple.com> 2 44 -
trunk/Source/WebKit/Sources.txt
r251765 r251814 134 134 Shared/RTCNetwork.cpp 135 135 Shared/RTCPacketOptions.cpp 136 Shared/ServiceWorkerInitializationData.cpp 136 137 Shared/SessionState.cpp 137 138 Shared/ShareableBitmap.cpp @no-unify -
trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp
r251361 r251814 122 122 #if ENABLE(CONTENT_EXTENSIONS) 123 123 ASSERT(parameters.contentRuleLists.isEmpty()); 124 parameters.contentRuleLists = contentRuleListData(); 125 #endif 126 } 127 128 #if ENABLE(CONTENT_EXTENSIONS) 129 Vector<std::pair<String, WebCompiledContentRuleListData>> WebUserContentControllerProxy::contentRuleListData() 130 { 131 Vector<std::pair<String, WebCompiledContentRuleListData>> data; 132 data.reserveInitialCapacity(m_contentRuleLists.size()); 124 133 for (const auto& contentRuleList : m_contentRuleLists.values()) 125 parameters.contentRuleLists.append(std::make_pair(contentRuleList->name(), contentRuleList->compiledRuleList().data())); 126 #endif 127 } 134 data.uncheckedAppend(std::make_pair(contentRuleList->name(), contentRuleList->compiledRuleList().data())); 135 return data; 136 } 137 #endif 128 138 129 139 void WebUserContentControllerProxy::removeProcess(WebProcessProxy& webProcessProxy) -
trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h
r251361 r251814 61 61 class WebScriptMessageHandler; 62 62 struct FrameInfoData; 63 class WebCompiledContentRuleListData; 63 64 struct WebPageCreationParameters; 64 65 enum class InjectUserScriptImmediately : bool; … … 105 106 void removeAllContentRuleLists(); 106 107 const HashMap<String, RefPtr<API::ContentRuleList>>& contentExtensionRules() { return m_contentRuleLists; } 108 Vector<std::pair<String, WebCompiledContentRuleListData>> contentRuleListData(); 107 109 #endif 108 110 -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r251778 r251814 79 79 #include "WebProcessProxy.h" 80 80 #include "WebProcessProxyMessages.h" 81 #include "WebUserContentControllerProxy.h" 81 82 #include "WebsiteDataStore.h" 82 83 #include "WebsiteDataStoreParameters.h" … … 723 724 724 725 serviceWorkerProcessProxy = process.get(); 725 serviceWorkerProcessProxy->enableServiceWorkers( );726 serviceWorkerProcessProxy->enableServiceWorkers(userContentControllerIdentifierForServiceWorkers()); 726 727 727 728 RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "WebProcessPool::establishWorkerContextConnectionToNetworkProcess reusing an existing web process %p, process identifier %d", serviceWorkerProcessProxy, serviceWorkerProcessProxy->processIdentifier()); … … 1228 1229 process = &processForRegistrableDomain(*pageConfiguration->websiteDataStore(), nullptr, { }); 1229 1230 1231 RefPtr<WebUserContentControllerProxy> userContentController = pageConfiguration->userContentController(); 1232 1230 1233 ASSERT(process); 1231 1234 … … 1238 1241 serviceWorkerProcess->updateServiceWorkerPreferencesStore(*m_serviceWorkerPreferences); 1239 1242 } 1243 if (userContentController) 1244 m_userContentControllerIDForServiceWorker = userContentController->identifier(); 1240 1245 #endif 1241 1246 -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r251778 r251814 394 394 bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; } 395 395 void updateServiceWorkerUserAgent(const String& userAgent); 396 const Optional<UserContentControllerIdentifier>& userContentControllerIdentifierForServiceWorkers() const { return m_userContentControllerIDForServiceWorker; } 396 397 #endif 397 398 … … 612 613 String m_serviceWorkerUserAgent; 613 614 Optional<WebPreferencesStore> m_serviceWorkerPreferences; 615 Optional<UserContentControllerIdentifier> m_userContentControllerIDForServiceWorker; 614 616 #endif 615 617 -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r251778 r251814 144 144 auto proxy = adoptRef(*new WebProcessProxy(processPool, &websiteDataStore, IsPrewarmed::No)); 145 145 proxy->m_registrableDomain = WTFMove(registrableDomain); 146 proxy->enableServiceWorkers( );146 proxy->enableServiceWorkers(processPool.userContentControllerIdentifierForServiceWorkers()); 147 147 proxy->connect(); 148 148 return proxy; … … 1542 1542 void WebProcessProxy::establishServiceWorkerContext(const WebPreferencesStore& store) 1543 1543 { 1544 send(Messages::WebProcess::EstablishWorkerContextConnectionToNetworkProcess { processPool().defaultPageGroup().pageGroupID(), m_serviceWorkerInformation->serviceWorkerPageProxyID, m_serviceWorkerInformation->serviceWorkerPageID, store, *m_registrableDomain }, 0);1544 send(Messages::WebProcess::EstablishWorkerContextConnectionToNetworkProcess { processPool().defaultPageGroup().pageGroupID(), m_serviceWorkerInformation->serviceWorkerPageProxyID, m_serviceWorkerInformation->serviceWorkerPageID, store, *m_registrableDomain, m_serviceWorkerInformation->initializationData }, 0); 1545 1545 } 1546 1546 … … 1573 1573 } 1574 1574 1575 void WebProcessProxy::enableServiceWorkers() 1575 #if ENABLE(CONTENT_EXTENSIONS) 1576 static Vector<std::pair<String, WebCompiledContentRuleListData>> contentRuleListsFromIdentifier(const Optional<UserContentControllerIdentifier>& userContentControllerIdentifier) 1577 { 1578 if (!userContentControllerIdentifier) { 1579 ASSERT_NOT_REACHED(); 1580 return { }; 1581 } 1582 1583 auto* userContentController = WebUserContentControllerProxy::get(*userContentControllerIdentifier); 1584 if (!userContentController) { 1585 ASSERT_NOT_REACHED(); 1586 return { }; 1587 } 1588 1589 return userContentController->contentRuleListData(); 1590 } 1591 #endif 1592 1593 void WebProcessProxy::enableServiceWorkers(const Optional<UserContentControllerIdentifier>& userContentControllerIdentifier) 1576 1594 { 1577 1595 ASSERT(m_registrableDomain && !m_registrableDomain->isEmpty()); 1578 1596 ASSERT(!m_serviceWorkerInformation); 1579 m_serviceWorkerInformation = ServiceWorkerInformation { WebPageProxyIdentifier::generate(), PageIdentifier::generate() }; 1597 m_serviceWorkerInformation = ServiceWorkerInformation { 1598 WebPageProxyIdentifier::generate(), 1599 PageIdentifier::generate(), 1600 ServiceWorkerInitializationData { 1601 userContentControllerIdentifier, 1602 #if ENABLE(CONTENT_EXTENSIONS) 1603 contentRuleListsFromIdentifier(userContentControllerIdentifier), 1604 #endif 1605 }, 1606 }; 1580 1607 } 1581 1608 -
trunk/Source/WebKit/UIProcess/WebProcessProxy.h
r251791 r251814 36 36 #include "ProcessThrottlerClient.h" 37 37 #include "ResponsivenessTimer.h" 38 #include "ServiceWorkerInitializationData.h" 39 #include "UserContentControllerIdentifier.h" 38 40 #include "VisibleWebPageCounter.h" 39 41 #include "WebConnectionToWebProcess.h" … … 75 77 class VisitedLinkStore; 76 78 class WebBackForwardListItem; 79 class WebCompiledContentRuleListData; 77 80 class WebFrameProxy; 78 81 class WebPageGroup; … … 132 135 bool isInProcessCache() const { return m_isInProcessCache; } 133 136 134 void enableServiceWorkers( );137 void enableServiceWorkers(const Optional<UserContentControllerIdentifier>&); 135 138 void disableServiceWorkers(); 136 139 … … 523 526 WebPageProxyIdentifier serviceWorkerPageProxyID; 524 527 WebCore::PageIdentifier serviceWorkerPageID; 528 ServiceWorkerInitializationData initializationData; 525 529 }; 526 530 Optional<ServiceWorkerInformation> m_serviceWorkerInformation; -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r251765 r251814 3670 3670 5C7FB46E21E97C0B009E3241 /* WebCookieJar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCookieJar.cpp; sourceTree = "<group>"; }; 3671 3671 5C7FB46F21E97C0C009E3241 /* WebCookieJar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCookieJar.h; sourceTree = "<group>"; }; 3672 5C80B3DB23690D8D0086E6DE /* ServiceWorkerInitializationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerInitializationData.h; sourceTree = "<group>"; }; 3673 5C80B3DD23690F100086E6DE /* ServiceWorkerInitializationData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerInitializationData.cpp; sourceTree = "<group>"; }; 3672 3674 5C84CF901F96AC4E00B6705A /* NetworkSessionCreationParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkSessionCreationParameters.h; sourceTree = "<group>"; }; 3673 3675 5C85C7861C3F23C50061A4FA /* PendingDownload.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PendingDownload.cpp; sourceTree = "<group>"; }; … … 5331 5333 1AAB4A8C1296F0A20023952F /* SandboxExtension.h */, 5332 5334 E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */, 5335 5C80B3DD23690F100086E6DE /* ServiceWorkerInitializationData.cpp */, 5336 5C80B3DB23690D8D0086E6DE /* ServiceWorkerInitializationData.h */, 5333 5337 1AFDE6571954A42B00C48FFA /* SessionState.cpp */, 5334 5338 1AFDE6581954A42B00C48FFA /* SessionState.h */, -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
r251488 r251814 35 35 #include "NetworkProcessMessages.h" 36 36 #include "ServiceWorkerFetchTaskMessages.h" 37 #include "ServiceWorkerInitializationData.h" 37 38 #include "WebCacheStorageProvider.h" 39 #include "WebCompiledContentRuleListData.h" 38 40 #include "WebCoreArgumentCoders.h" 39 41 #include "WebDatabaseProvider.h" … … 48 50 #include "WebServiceWorkerFetchTaskClient.h" 49 51 #include "WebSocketProvider.h" 52 #include "WebUserContentController.h" 50 53 #include <WebCore/EditorClient.h> 51 54 #include <WebCore/EmptyClients.h> … … 84 87 } 85 88 86 WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection>&& connection, WebCore::RegistrableDomain&& registrableDomain, uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store )89 WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection>&& connection, WebCore::RegistrableDomain&& registrableDomain, uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store, ServiceWorkerInitializationData&& initializationData) 87 90 : m_connectionToNetworkProcess(WTFMove(connection)) 88 91 , m_registrableDomain(WTFMove(registrableDomain)) … … 96 99 #endif 97 100 { 101 if (initializationData.userContentControllerIdentifier) { 102 m_userContentController = WebUserContentController::getOrCreate(*initializationData.userContentControllerIdentifier); 103 #if ENABLE(CONTENT_EXTENSIONS) 104 m_userContentController->addContentRuleLists(WTFMove(initializationData.contentRuleLists)); 105 #endif 106 } 107 98 108 updatePreferencesStore(store); 99 109 m_connectionToNetworkProcess->send(Messages::NetworkConnectionToWebProcess::EstablishSWContextConnection { m_registrableDomain }, 0); … … 129 139 #endif 130 140 pageConfiguration.socketProvider = WebSocketProvider::create(); 141 pageConfiguration.userContentProvider = m_userContentController; 131 142 132 143 auto effectiveUserAgent = WTFMove(userAgent); -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
r251445 r251814 30 30 #include "Connection.h" 31 31 #include "MessageReceiver.h" 32 #include "UserContentControllerIdentifier.h" 32 33 #include "WebPageProxyIdentifier.h" 33 34 #include "WebSWContextManagerConnectionMessagesReplies.h" … … 50 51 51 52 class ServiceWorkerFrameLoaderClient; 53 struct ServiceWorkerInitializationData; 52 54 struct WebPreferencesStore; 55 class WebUserContentController; 53 56 54 57 class WebSWContextManagerConnection final : public WebCore::SWContextManager::Connection, public IPC::MessageReceiver { 55 58 public: 56 WebSWContextManagerConnection(Ref<IPC::Connection>&&, WebCore::RegistrableDomain&&, uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore& );59 WebSWContextManagerConnection(Ref<IPC::Connection>&&, WebCore::RegistrableDomain&&, uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&, ServiceWorkerInitializationData&&); 57 60 ~WebSWContextManagerConnection(); 58 61 … … 116 119 String m_userAgent; 117 120 bool m_isThrottleable { true }; 121 RefPtr<WebUserContentController> m_userContentController; 118 122 }; 119 123 -
trunk/Source/WebKit/WebProcess/WebProcess.cpp
r251599 r251814 1739 1739 1740 1740 #if ENABLE(SERVICE_WORKER) 1741 void WebProcess::establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store, RegistrableDomain&& registrableDomain )1741 void WebProcess::establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store, RegistrableDomain&& registrableDomain, ServiceWorkerInitializationData&& initializationData) 1742 1742 { 1743 1743 // We are in the Service Worker context process and the call below establishes our connection to the Network Process … … 1745 1745 // NetworkProcessConnection for synchronization purposes. 1746 1746 auto& ipcConnection = ensureNetworkProcessConnection().connection(); 1747 SWContextManager::singleton().setConnection(makeUnique<WebSWContextManagerConnection>(ipcConnection, WTFMove(registrableDomain), pageGroupID, webPageProxyID, pageID, store ));1747 SWContextManager::singleton().setConnection(makeUnique<WebSWContextManagerConnection>(ipcConnection, WTFMove(registrableDomain), pageGroupID, webPageProxyID, pageID, store, WTFMove(initializationData))); 1748 1748 } 1749 1749 -
trunk/Source/WebKit/WebProcess/WebProcess.h
r251599 r251814 36 36 #include "StorageAreaIdentifier.h" 37 37 #include "TextCheckerState.h" 38 #include "UserContentControllerIdentifier.h" 38 39 #include "ViewUpdateDispatcher.h" 39 40 #include "WebInspectorInterruptDispatcher.h" … … 110 111 class NetworkProcessConnection; 111 112 class ObjCObjectGraph; 113 struct ServiceWorkerInitializationData; 112 114 class StorageAreaMap; 113 115 class UserData; … … 115 117 class WebAutomationSessionProxy; 116 118 class WebCacheStorageProvider; 119 class WebCompiledContentRuleListData; 117 120 class WebConnectionToUIProcess; 118 121 class WebFrame; … … 372 375 373 376 #if ENABLE(SERVICE_WORKER) 374 void establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&, WebCore::RegistrableDomain&& );377 void establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&, WebCore::RegistrableDomain&&, ServiceWorkerInitializationData&&); 375 378 void registerServiceWorkerClients(); 376 379 #endif -
trunk/Source/WebKit/WebProcess/WebProcess.messages.in
r251599 r251814 107 107 108 108 #if ENABLE(SERVICE_WORKER) 109 EstablishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebKit::WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier pageID, struct WebKit::WebPreferencesStore store, WebCore::RegistrableDomain domain )109 EstablishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebKit::WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier pageID, struct WebKit::WebPreferencesStore store, WebCore::RegistrableDomain domain, struct WebKit::ServiceWorkerInitializationData initializationData) 110 110 RegisterServiceWorkerClients() 111 111 #endif -
trunk/Tools/ChangeLog
r251813 r251814 1 2019-10-30 Alex Christensen <achristensen@webkit.org> 2 3 WKContentRuleLists should block requests from service workers 4 https://bugs.webkit.org/show_bug.cgi?id=201980 5 <rdar://problem/55516735> 6 7 Reviewed by Chris Dumez. 8 9 NSString initWithContentsOfURL doesn't work with https URLs with certificates without a trusted root, 10 so I use an ephemeral NSURLSession instead so I can tell it to accept any connection, even our WebKit httpd server. 11 I also added an API test. 12 13 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 14 * WebKitTestRunner/mac/TestControllerMac.mm: 15 (-[WKTRSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]): 16 (WTR::TestController::configureContentExtensionForTest): 17 1 18 2019-10-30 Daniel Bates <dabates@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r251439 r251814 1914 1914 EXPECT_EQ(2U, processPool._serviceWorkerProcessCount); 1915 1915 } 1916 1917 static const char* contentRuleListWorkerScript = 1918 "self.addEventListener('message', (event) => {" 1919 " fetch('blockedsubresource').then(() => {" 1920 " event.source.postMessage('FAIL - should have blocked first request');" 1921 " }).catch(() => {" 1922 " fetch('allowedsubresource').then(() => {" 1923 " event.source.postMessage('PASS - blocked first request, allowed second');" 1924 " }).catch(() => {" 1925 " event.source.postMessage('FAIL - should have allowed second request');" 1926 " });" 1927 " });" 1928 "});"; 1929 1930 TEST(ServiceWorkers, ContentRuleList) 1931 { 1932 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 1933 1934 __block bool doneCompiling = false; 1935 __block RetainPtr<WKContentRuleList> contentRuleList; 1936 [[WKContentRuleListStore defaultStore] compileContentRuleListForIdentifier:@"ServiceWorkerRuleList" encodedContentRuleList:@"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"blockedsubresource\"}}]" completionHandler:^(WKContentRuleList *list, NSError *error) { 1937 EXPECT_NOT_NULL(list); 1938 EXPECT_NULL(error); 1939 contentRuleList = list; 1940 doneCompiling = true; 1941 }]; 1942 TestWebKitAPI::Util::run(&doneCompiling); 1943 1944 // Start with a clean slate data store 1945 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 1946 done = true; 1947 }]; 1948 TestWebKitAPI::Util::run(&done); 1949 done = false; 1950 1951 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1952 1953 auto messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]); 1954 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 1955 [[configuration userContentController] addContentRuleList:contentRuleList.get()]; 1956 1957 using namespace TestWebKitAPI; 1958 TCPServer server([] (int socket) { 1959 auto respond = [socket] (const char* body, const char* mimeType) { 1960 NSString *format = @"HTTP/1.1 200 OK\r\n" 1961 "Content-Type: %s\r\n" 1962 "Content-Length: %d\r\n\r\n" 1963 "%s"; 1964 NSString *response = [NSString stringWithFormat:format, mimeType, strlen(body), body]; 1965 TCPServer::write(socket, response.UTF8String, response.length); 1966 }; 1967 TCPServer::read(socket); 1968 respond(mainBytes, "text/html"); 1969 TCPServer::read(socket); 1970 respond(contentRuleListWorkerScript, "application/javascript"); 1971 auto lastRequest = TCPServer::read(socket); 1972 EXPECT_TRUE(strstr((const char*)lastRequest.data(), "allowedsubresource")); 1973 respond("successful fetch", "application/octet-stream"); 1974 }); 1975 1976 expectedMessage = @"Message from worker: PASS - blocked first request, allowed second"; 1977 1978 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1979 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]]; 1980 TestWebKitAPI::Util::run(&done); 1981 1982 __block bool doneRemoving = false; 1983 [[WKContentRuleListStore defaultStore] removeContentRuleListForIdentifier:@"ServiceWorkerRuleList" completionHandler:^(NSError *error) { 1984 EXPECT_NULL(error); 1985 doneRemoving = true; 1986 }]; 1987 TestWebKitAPI::Util::run(&doneRemoving); 1988 } -
trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm
r249327 r251814 51 51 @end 52 52 53 @interface WKTRSessionDelegate : NSObject <NSURLSessionDataDelegate> 54 @end 55 @implementation WKTRSessionDelegate 56 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler 57 { 58 completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); 59 } 60 @end 61 53 62 namespace WTR { 54 63 … … 126 135 NSURL *filterURL = [(__bridge NSURL *)testURL.get() URLByAppendingPathExtension:@"json"]; 127 136 128 NSStringEncoding encoding; 129 NSString *contentExtensionString = [[NSString alloc] initWithContentsOfURL:filterURL usedEncoding:&encoding error:NULL]; 130 if (!contentExtensionString) 131 return; 132 137 __block NSString *contentExtensionString; 138 __block bool doneFetchingContentExtension = false; 139 auto delegate = adoptNS([WKTRSessionDelegate new]); 140 NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:delegate.get() delegateQueue:[NSOperationQueue mainQueue]]; 141 NSURLSessionDataTask *task = [session dataTaskWithRequest:[NSURLRequest requestWithURL:filterURL] completionHandler:^(NSData * data, NSURLResponse *response, NSError *error) { 142 ASSERT(data); 143 ASSERT(response); 144 ASSERT(!error); 145 contentExtensionString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 146 doneFetchingContentExtension = true; 147 }]; 148 [task resume]; 149 platformRunUntil(doneFetchingContentExtension, noTimeout); 150 133 151 __block bool doneCompiling = false; 134 152
Note: See TracChangeset
for help on using the changeset viewer.