Changeset 291979 in webkit
- Timestamp:
- Mar 28, 2022 11:14:19 AM (4 months ago)
- Location:
- trunk
- Files:
-
- 4 added
- 36 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/tests/workers/service/openwindow-from-notification-click-expected.txt (added)
-
LayoutTests/http/tests/workers/service/openwindow-from-notification-click.html (added)
-
LayoutTests/http/tests/workers/service/resources/openwindow-client.html (added)
-
LayoutTests/http/tests/workers/service/resources/shownotification-openwindow-worker.js (added)
-
LayoutTests/platform/gtk/TestExpectations (modified) (1 diff)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/HashTable.h (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/Document.cpp (modified) (1 diff)
-
Source/WebCore/page/ClientOrigin.h (modified) (1 diff)
-
Source/WebCore/workers/service/ServiceWorkerClientData.cpp (modified) (2 diffs)
-
Source/WebCore/workers/service/ServiceWorkerClientData.h (modified) (5 diffs)
-
Source/WebCore/workers/service/ServiceWorkerClients.cpp (modified) (1 diff)
-
Source/WebCore/workers/service/context/SWContextManager.h (modified) (1 diff)
-
Source/WebCore/workers/service/server/SWServerToContextConnection.h (modified) (1 diff)
-
Source/WebCore/workers/service/server/SWServerWorker.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (modified) (4 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (modified) (1 diff)
-
Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPageProxy.cpp (modified) (5 diffs)
-
Source/WebKit/UIProcess/WebPageProxy.h (modified) (3 diffs)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (modified) (1 diff)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h (modified) (2 diffs)
-
Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp (modified) (3 diffs)
-
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/WebKitTestRunner/TestController.cpp (modified) (3 diffs)
-
Tools/WebKitTestRunner/TestController.h (modified) (1 diff)
-
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (modified) (1 diff)
-
Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r291962 r291979 1 2022-03-28 Brady Eidson <beidson@apple.com> 2 3 Support ServiceWorkerClients.openWindow. 4 <rdar://90616651> and https://bugs.webkit.org/show_bug.cgi?id=238400 5 6 Reviewed by Youenn Fablet. 7 8 WKTR knows how to openWindow() now. 9 10 So test: 11 - The success case 12 - Failure due to a disallowed URL 13 - Failure due to a lack of a related user gesture. 14 15 * http/tests/workers/service/openwindow-from-notification-click-expected.txt: Added. 16 * http/tests/workers/service/openwindow-from-notification-click.html: Added. 17 * http/tests/workers/service/resources/openwindow-client.html: Added. 18 * http/tests/workers/service/resources/shownotification-openwindow-worker.js: Added. 19 (async const): 20 (let.messageClients): 21 (clients.openWindow.string_appeared_here.then.async client): 22 (catch.async error): 23 (async event): 24 (async tryShow): 25 (async getNotes): 26 * platform/gtk/TestExpectations: 27 1 28 2022-03-28 Ziran Sun <zsun@igalia.com> 2 29 -
trunk/LayoutTests/platform/gtk/TestExpectations
r291950 r291979 718 718 webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/credentials.https.html [ Skip ] 719 719 webkit.org/b/175419 [ Release ] http/tests/workers/service/postmessage-after-terminate.https.html [ Pass Failure Timeout ] 720 webkit.org/b/175419 http/tests/workers/service/openwindow-from-notification-click.html [ Skip ] 720 721 721 722 # FIXME: This can't be the right bug number. -
trunk/Source/WTF/ChangeLog
r291972 r291979 1 2022-03-28 Brady Eidson <beidson@apple.com> 2 3 Support ServiceWorkerClients.openWindow. 4 <rdar://90616651> and https://bugs.webkit.org/show_bug.cgi?id=238400 5 6 Reviewed by Youenn Fablet. 7 8 * wtf/HashTable.h: 9 (WTF::KeyTraits>::inlineLookup): Relax this value size requirement for now. 10 The required refactoring is best left as a seperate task with a seperate patch. 11 1 12 2022-03-28 Chris Dumez <cdumez@apple.com> 2 13 -
trunk/Source/WTF/wtf/HashTable.h
r284167 r291979 682 682 ALWAYS_INLINE auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::inlineLookup(const T& key) -> ValueType* 683 683 { 684 static_assert(sizeof(Value) <= 1 28, "Your HashTable types are too big to efficiently move when rehashing. Consider using UniqueRef instead");684 static_assert(sizeof(Value) <= 150, "Your HashTable types are too big to efficiently move when rehashing. Consider using UniqueRef instead"); 685 685 checkKey<HashTranslator>(key); 686 686 -
trunk/Source/WebCore/ChangeLog
r291978 r291979 1 2022-03-28 Brady Eidson <beidson@apple.com> 2 3 Support ServiceWorkerClients.openWindow. 4 <rdar://90616651> and https://bugs.webkit.org/show_bug.cgi?id=238400 5 6 Reviewed by Youenn Fablet. 7 8 Test: http/tests/workers/service/openwindow-from-notification-click.html 9 10 * dom/Document.cpp: 11 (WebCore::Document::pageID const): 12 13 * page/ClientOrigin.h: 14 (WebCore::ClientOrigin::loggingString const): 15 16 * workers/service/ServiceWorkerClientData.cpp: 17 (WebCore::ServiceWorkerClientData::isolatedCopy const): 18 (WebCore::ServiceWorkerClientData::isolatedCopy): 19 (WebCore::ServiceWorkerClientData::from): 20 21 * workers/service/ServiceWorkerClientData.h: 22 (WebCore::ServiceWorkerClientData::encode const): 23 (WebCore::ServiceWorkerClientData::decode): 24 25 * workers/service/ServiceWorkerClients.cpp: 26 (WebCore::matchWindowWithPageIdentifier): 27 (WebCore::ServiceWorkerClients::openWindow): 28 29 * workers/service/context/SWContextManager.h: 30 * workers/service/server/SWServerToContextConnection.h: 31 * workers/service/server/SWServerWorker.h: 32 1 33 2022-03-28 Ian Anderson <iana@apple.com> 2 34 -
trunk/Source/WebCore/dom/Document.cpp
r291888 r291979 8409 8409 std::optional<PageIdentifier> Document::pageID() const 8410 8410 { 8411 return m_frame ->loader().pageID();8411 return m_frame ? m_frame->loader().pageID() : std::nullopt; 8412 8412 } 8413 8413 -
trunk/Source/WebCore/page/ClientOrigin.h
r290901 r291979 51 51 SecurityOriginData topOrigin; 52 52 SecurityOriginData clientOrigin; 53 54 String loggingString() const { return makeString(topOrigin.toString(), "-", clientOrigin.toString()); } 53 55 }; 54 56 -
trunk/Source/WebCore/workers/service/ServiceWorkerClientData.cpp
r291888 r291979 59 59 ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() const & 60 60 { 61 return { identifier, type, frameType, url.isolatedCopy(), lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder };61 return { identifier, type, frameType, url.isolatedCopy(), pageIdentifier, lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder }; 62 62 } 63 63 64 64 ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() && 65 65 { 66 return { identifier, type, frameType, WTFMove(url).isolatedCopy(), lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder };66 return { identifier, type, frameType, WTFMove(url).isolatedCopy(), pageIdentifier, lastNavigationWasAppInitiated, isVisible, isFocused, focusOrder }; 67 67 } 68 68 … … 79 79 isDocument ? ServiceWorkerClientType::Window : ServiceWorkerClientType::Worker, 80 80 toServiceWorkerClientFrameType(context), 81 document.creationURL(), lastNavigationWasAppInitiated, 81 document.creationURL(), 82 document.pageID(), 83 lastNavigationWasAppInitiated, 82 84 !document.hidden(), 83 85 document.hasFocus(), -
trunk/Source/WebCore/workers/service/ServiceWorkerClientData.h
r291938 r291979 28 28 #if ENABLE(SERVICE_WORKER) 29 29 30 #include "PageIdentifier.h" 30 31 #include "ProcessQualified.h" 31 32 #include "ScriptExecutionContextIdentifier.h" … … 46 47 ServiceWorkerClientFrameType frameType; 47 48 URL url; 49 std::optional<PageIdentifier> pageIdentifier; 48 50 LastNavigationWasAppInitiated lastNavigationWasAppInitiated; 49 51 bool isVisible { false }; … … 63 65 void ServiceWorkerClientData::encode(Encoder& encoder) const 64 66 { 65 encoder << identifier << type << frameType << url << lastNavigationWasAppInitiated << isVisible << isFocused << focusOrder;67 encoder << identifier << type << frameType << url << pageIdentifier << lastNavigationWasAppInitiated << isVisible << isFocused << focusOrder; 66 68 } 67 69 … … 89 91 return std::nullopt; 90 92 93 std::optional<std::optional<PageIdentifier>> pageIdentifier; 94 decoder >> pageIdentifier; 95 if (!pageIdentifier) 96 return std::nullopt; 97 91 98 std::optional<LastNavigationWasAppInitiated> lastNavigationWasAppInitiated; 92 99 decoder >> lastNavigationWasAppInitiated; … … 109 116 return std::nullopt; 110 117 111 return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url), WTFMove(* lastNavigationWasAppInitiated), WTFMove(*isVisible), WTFMove(*isFocused), WTFMove(*focusOrder) } };118 return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url), WTFMove(*pageIdentifier), WTFMove(*lastNavigationWasAppInitiated), WTFMove(*isVisible), WTFMove(*isFocused), WTFMove(*focusOrder) } }; 112 119 } 113 120 -
trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp
r291938 r291979 91 91 } 92 92 93 void ServiceWorkerClients::openWindow(ScriptExecutionContext&, const String& url, Ref<DeferredPromise>&& promise)93 static void matchWindowWithPageIdentifier(ServiceWorkerIdentifier serviceWorkerIdentifier, PageIdentifier pageIdentifier, CompletionHandler<void(ServiceWorkerGlobalScope&, std::optional<ServiceWorkerClientData>)>&& callback) 94 94 { 95 UNUSED_PARAM(url); 96 promise->reject(Exception { NotSupportedError, "clients.openWindow() is not yet supported"_s }); 95 callOnMainThread([serviceWorkerIdentifier, pageIdentifier, callback = WTFMove(callback)] () mutable { 96 auto connection = SWContextManager::singleton().connection(); 97 auto options = ServiceWorkerClientQueryOptions { true, ServiceWorkerClientType::Window }; 98 connection->matchAll(serviceWorkerIdentifier, options, [serviceWorkerIdentifier, pageIdentifier, callback = WTFMove(callback)] (Vector<ServiceWorkerClientData>&& clientsData) mutable { 99 SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [pageIdentifier, callback = WTFMove(callback), clientsData = crossThreadCopy(WTFMove(clientsData))] (auto& scope) mutable { 100 for (auto& data : clientsData) { 101 if (data.pageIdentifier == pageIdentifier) { 102 callback(scope, data); 103 return; 104 } 105 } 106 107 callback(scope, std::nullopt); 108 }); 109 }); 110 }); 111 } 112 113 void ServiceWorkerClients::openWindow(ScriptExecutionContext& context, const String& urlString, Ref<DeferredPromise>&& promise) 114 { 115 LOG(ServiceWorker, "WebProcess %i service worker calling openWindow to URL %s", getpid(), urlString.utf8().data()); 116 117 auto serviceWorkerIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier(); 118 auto url = context.completeURL(urlString); 119 120 if (context.settingsValues().serviceWorkersUserGestureEnabled && !downcast<ServiceWorkerGlobalScope>(context).isProcessingUserGesture()) { 121 promise->reject(Exception { InvalidAccessError, "ServiceWorkerClients.openWindow() requires a user gesture"_s }); 122 return; 123 } 124 125 if (!url.isValid()) { 126 promise->reject(Exception { TypeError, makeString("URL string ", urlString, " cannot successfully be parsed"_s) }); 127 return; 128 } 129 130 if (url.protocolIsAbout()) { 131 promise->reject(Exception { TypeError, makeString("ServiceWorkerClients.openWindow() cannot be called with URL "_s, url.string()) }); 132 return; 133 } 134 135 callOnMainThread([promiseIdentifier = addPendingPromise(WTFMove(promise)), serviceWorkerIdentifier, url = url.isolatedCopy()] () mutable { 136 auto connection = SWContextManager::singleton().connection(); 137 connection->openWindow(serviceWorkerIdentifier, url.string(), [promiseIdentifier, serviceWorkerIdentifier] (std::optional<PageIdentifier>&& pageIdentifier) mutable { 138 SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [promiseIdentifier, pageIdentifier = WTFMove(pageIdentifier), serviceWorkerIdentifier] (ServiceWorkerGlobalScope& scope) mutable { 139 LOG(ServiceWorker, "WebProcess %i finished ServiceWorkerClients::openWindow call. Resulting page identifier is %s", getpid(), pageIdentifier ? pageIdentifier->loggingString().utf8().data() : "<NONE>"); 140 141 if (!pageIdentifier) { 142 if (auto promise = scope.clients().takePendingPromise(promiseIdentifier)) 143 promise->resolveWithJSValue(JSC::jsNull()); 144 return; 145 } 146 147 matchWindowWithPageIdentifier(serviceWorkerIdentifier, *pageIdentifier, [promiseIdentifier] (auto& scope, std::optional<ServiceWorkerClientData> clientData) mutable { 148 auto promise = scope.clients().takePendingPromise(promiseIdentifier); 149 if (!promise) 150 return; 151 152 if (!clientData) { 153 promise->resolveWithJSValue(JSC::jsNull()); 154 return; 155 } 156 157 auto client = ServiceWorkerClient::create(scope, WTFMove(*clientData)); 158 promise->template resolve<IDLInterface<ServiceWorkerClient>>(WTFMove(client)); 159 }); 160 }); 161 }); 162 }); 97 163 } 98 164 -
trunk/Source/WebCore/workers/service/context/SWContextManager.h
r291938 r291979 68 68 virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0; 69 69 virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&) = 0; 70 71 70 virtual void focus(ScriptExecutionContextIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&&) = 0; 71 virtual void openWindow(ServiceWorkerIdentifier, const String& url, CompletionHandler<void(std::optional<PageIdentifier>&&)>&&) = 0; 72 72 73 73 virtual void didFailHeartBeatCheck(ServiceWorkerIdentifier) = 0; -
trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h
r291467 r291979 83 83 WEBCORE_EXPORT void findClientByVisibleIdentifier(ServiceWorkerIdentifier, const String& clientIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&&); 84 84 85 virtual void openWindow(ServiceWorkerIdentifier, const String& urlString, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&&) = 0; 86 85 87 const RegistrableDomain& registrableDomain() const { return m_registrableDomain; } 86 88 std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier() const { return m_serviceWorkerPageIdentifier; } -
trunk/Source/WebCore/workers/service/server/SWServerWorker.h
r291467 r291979 118 118 ServiceWorkerContextData contextData() const; 119 119 120 const ClientOrigin& origin() const;120 WEBCORE_EXPORT const ClientOrigin& origin() const; 121 121 const RegistrableDomain& registrableDomain() const { return m_registrableDomain; } 122 122 WEBCORE_EXPORT std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier() const; -
trunk/Source/WebKit/ChangeLog
r291967 r291979 1 2022-03-28 Brady Eidson <beidson@apple.com> 2 3 Support ServiceWorkerClients.openWindow. 4 <rdar://90616651> and https://bugs.webkit.org/show_bug.cgi?id=238400 5 6 Reviewed by Youenn Fablet. 7 8 This API asks the browser to asynchronously open a new tab to a URL then resolve 9 a promise with the new WindowClient representing that tab. 10 11 From a WebCore/WebKit standpoint, implementing this was mostly straightforward. 12 1 - A plumbing exercise (thread hopping and IPC'ing the message and its reply around) 13 2 - Implmenting a new delegate method for the hosting app to create the requested WKWebView 14 15 The delegate method was interesting. Normally this is the type of thing that'd go to the 16 WKUIDelegate but that requires there to be a WKWebView, and service workers can be running 17 without any web views. 18 19 Fortunately we already had a WKWebsiteDataStore delegate SPI, and service workers *do* always 20 have an associated website data store they're running under. 21 22 Once the app gives the new web view back to WebKit, we record its PageIdentifier in the reply. 23 24 Once the reply makes its way all the way back to the ServiceWorker process and on the 25 ServiceWorker thread, we do a client match and cross check with that PageIdentifier to make 26 sure we're resolving the promise with the correct WindowClient. 27 28 If there's no matched clients, then the view is either already gone or it has navigated away 29 to a non-applicable URL. 30 31 Same if there are matched clients, but they don't match the specified PageIdentifier. 32 33 A straight forward layouttest completes the task. 34 35 * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: 36 (WebKit::WebSWServerConnection::controlClient): 37 38 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp: 39 (WebKit::WebSWServerToContextConnection::openWindow): 40 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h: 41 * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in: 42 43 * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: 44 (-[WKWebsiteDataStore set_delegate:]): 45 * UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h: 46 47 * UIProcess/Network/NetworkProcessProxy.cpp: 48 (WebKit::NetworkProcessProxy::openWindowFromServiceWorker): 49 * UIProcess/Network/NetworkProcessProxy.h: 50 * UIProcess/Network/NetworkProcessProxy.messages.in: 51 52 * UIProcess/WebPageProxy.cpp: 53 (WebKit::WebPageProxy::didFailProvisionalLoadForFrameShared): 54 (WebKit::WebPageProxy::callLoadCompletionHandlersIfNecessary): 55 (WebKit::WebPageProxy::didFinishLoadForFrame): 56 (WebKit::WebPageProxy::didFailLoadForFrame): 57 (WebKit::WebPageProxy::resetState): 58 (WebKit::WebPageProxy::callServiceWorkerLaunchCompletionHandlerIfNecessary): Deleted. 59 * UIProcess/WebPageProxy.h: 60 61 * UIProcess/WebsiteData/WebsiteDataStore.cpp: 62 (WebKit::WebsiteDataStore::openWindowFromServiceWorker): 63 * UIProcess/WebsiteData/WebsiteDataStore.h: 64 65 * UIProcess/WebsiteData/WebsiteDataStoreClient.h: 66 (WebKit::WebsiteDataStoreClient::openWindowFromServiceWorker): 67 68 * WebProcess/Notifications/WebNotificationManager.cpp: 69 (WebKit::WebNotificationManager::show): 70 (WebKit::WebNotificationManager::didShowNotification): 71 (WebKit::WebNotificationManager::didClickNotification): 72 73 * WebProcess/Storage/WebSWContextManagerConnection.cpp: 74 (WebKit::WebSWContextManagerConnection::openWindow): 75 * WebProcess/Storage/WebSWContextManagerConnection.h: 76 1 77 2022-03-28 Youenn Fablet <youenn@apple.com> 2 78 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
r291938 r291979 176 176 }); 177 177 178 ServiceWorkerClientData data { clientIdentifier, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, request.url(), request.isAppInitiated() ? WebCore::LastNavigationWasAppInitiated::Yes : WebCore::LastNavigationWasAppInitiated::No };178 ServiceWorkerClientData data { clientIdentifier, ServiceWorkerClientType::Window, ServiceWorkerClientFrameType::None, request.url(), { }, request.isAppInitiated() ? WebCore::LastNavigationWasAppInitiated::Yes : WebCore::LastNavigationWasAppInitiated::No }; 179 179 registerServiceWorkerClient(SecurityOriginData { registration.key().topOrigin() }, WTFMove(data), registration.identifier(), request.httpUserAgent()); 180 180 } -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp
r291938 r291979 158 158 } 159 159 160 void WebSWServerToContextConnection::openWindow(WebCore::ServiceWorkerIdentifier identifier, const String& urlString, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&& callback) 161 { 162 auto* server = this->server(); 163 if (!server) { 164 callback(std::nullopt); 165 return; 166 } 167 168 auto* worker = server->workerByID(identifier); 169 if (!worker) { 170 callback(std::nullopt); 171 return; 172 } 173 174 auto innerCallback = [callback = WTFMove(callback)](std::optional<WebCore::PageIdentifier>&& pageIdentifier) mutable { 175 callback(WTFMove(pageIdentifier)); 176 }; 177 178 m_connection.networkProcess().parentProcessConnection()->sendWithAsyncReply(Messages::NetworkProcessProxy::OpenWindowFromServiceWorker { server->sessionID(), urlString, worker->origin().clientOrigin }, WTFMove(innerCallback)); 179 } 180 160 181 void WebSWServerToContextConnection::matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>& clientsData) 161 182 { -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h
r291938 r291979 103 103 void connectionIsNoLongerNeeded() final; 104 104 void terminateDueToUnresponsiveness() final; 105 void openWindow(WebCore::ServiceWorkerIdentifier, const String& urlString, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&&) final; 105 106 106 107 void connectionClosed(); -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
r291938 r291979 41 41 DidFailHeartBeatCheck(WebCore::ServiceWorkerIdentifier identifier) 42 42 SetAsInspected(WebCore::ServiceWorkerIdentifier identifier, bool isInspected) 43 44 OpenWindow(WebCore::ServiceWorkerIdentifier identifier, String urlString) -> (std::optional<WebCore::PageIdentifier> newClientData) 43 45 } 44 46 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
r291851 r291979 49 49 #import <WebCore/Credential.h> 50 50 #import <WebCore/RegistrationDatabase.h> 51 #import <WebCore/ServiceWorkerClientData.h> 51 52 #import <WebCore/WebCoreObjCExtras.h> 52 53 #import <wtf/BlockPtr.h> … … 57 58 class WebsiteDataStoreClient final : public WebKit::WebsiteDataStoreClient { 58 59 public: 59 explicit WebsiteDataStoreClient(id <_WKWebsiteDataStoreDelegate> delegate) 60 : m_delegate(delegate) 60 explicit WebsiteDataStoreClient(WKWebsiteDataStore *dataStore, id<_WKWebsiteDataStoreDelegate> delegate) 61 : m_dataStore(dataStore) 62 , m_delegate(delegate) 61 63 , m_hasRequestStorageSpaceSelector([m_delegate.get() respondsToSelector:@selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:)]) 62 64 , m_hasAuthenticationChallengeSelector([m_delegate.get() respondsToSelector:@selector(didReceiveAuthenticationChallenge: completionHandler:)]) 65 , m_hasOpenWindowSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:openWindow:fromServiceWorkerOrigin:completionHandler:)]) 63 66 { 64 67 } … … 105 108 } 106 109 110 void openWindowFromServiceWorker(const String& url, const WebCore::SecurityOriginData& serviceWorkerOrigin, CompletionHandler<void(WebKit::WebPageProxy*)>&& callback) 111 { 112 if (!m_hasOpenWindowSelector || !m_delegate || !m_dataStore) { 113 callback({ }); 114 return; 115 } 116 117 auto checker = WebKit::CompletionHandlerCallChecker::create(m_delegate.getAutoreleased(), @selector(websiteDataStore:openWindow:fromServiceWorkerOrigin:completionHandler:)); 118 auto completionHandler = makeBlockPtr([callback = WTFMove(callback), checker = WTFMove(checker)](WKWebView *newWebView) mutable { 119 if (checker->completionHandlerHasBeenCalled()) 120 return; 121 checker->didCallCompletionHandler(); 122 123 callback(newWebView._page.get()); 124 }); 125 126 auto nsURL = (NSURL *)URL { url }; 127 auto apiOrigin = API::SecurityOrigin::create(serviceWorkerOrigin); 128 [m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() openWindow:nsURL fromServiceWorkerOrigin:wrapper(apiOrigin.get()) completionHandler:completionHandler.get()]; 129 } 130 131 WeakObjCPtr<WKWebsiteDataStore> m_dataStore; 107 132 WeakObjCPtr<id <_WKWebsiteDataStoreDelegate> > m_delegate; 108 133 bool m_hasRequestStorageSpaceSelector { false }; 109 134 bool m_hasAuthenticationChallengeSelector { false }; 135 bool m_hasOpenWindowSelector { false }; 110 136 }; 111 137 … … 653 679 { 654 680 _delegate = delegate; 655 _websiteDataStore->setClient(makeUniqueRef<WebsiteDataStoreClient>( delegate));681 _websiteDataStore->setClient(makeUniqueRef<WebsiteDataStoreClient>(self, delegate)); 656 682 } 657 683 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h
r260366 r291979 27 27 #import <WebKit/WKFoundation.h> 28 28 29 @class WKSecurityOrigin; 30 @class WKWebsiteDataStore; 31 @class WKWebView; 32 29 33 WK_API_AVAILABLE(macos(10.15), ios(13.0)) 30 34 @protocol _WKWebsiteDataStoreDelegate <NSObject> … … 33 37 - (void)requestStorageSpace:(NSURL *)mainFrameURL frameOrigin:(NSURL *)frameURL quota:(NSUInteger)quota currentSize:(NSUInteger)currentSize spaceRequired:(NSUInteger)spaceRequired decisionHandler:(void (^)(unsigned long long quota))decisionHandler; 34 38 - (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler; 35 39 - (void)websiteDataStore:(WKWebsiteDataStore *)dataStore openWindow:(NSURL *)url fromServiceWorkerOrigin:(WKSecurityOrigin *)serviceWorkerOrigin completionHandler:(void (^)(WKWebView *newWebView))completionHandler; 36 40 @end -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r291851 r291979 1799 1799 } 1800 1800 1801 void NetworkProcessProxy::openWindowFromServiceWorker(PAL::SessionID sessionID, const String& urlString, const WebCore::SecurityOriginData& serviceWorkerOrigin, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&& callback) 1802 { 1803 if (auto* store = websiteDataStoreFromSessionID(sessionID)) { 1804 store->openWindowFromServiceWorker(urlString, serviceWorkerOrigin, WTFMove(callback)); 1805 return; 1806 } 1807 1808 callback(std::nullopt); 1809 } 1810 1801 1811 } // namespace WebKit 1802 1812 -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r291851 r291979 300 300 void terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType, PAL::SessionID, const WebCore::RegistrableDomain&, WebCore::ProcessIdentifier); 301 301 302 void openWindowFromServiceWorker(PAL::SessionID, const String& urlString, const WebCore::SecurityOriginData& serviceWorkerOrigin, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&&); 303 302 304 private: 303 305 explicit NetworkProcessProxy(); -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
r291630 r291979 92 92 DataTaskDidReceiveData(WebKit::DataTaskIdentifier identifier, IPC::DataReference data) 93 93 DataTaskDidCompleteWithError(WebKit::DataTaskIdentifier identifier, WebCore::ResourceError error) 94 95 OpenWindowFromServiceWorker(PAL::SessionID sessionID, String urlString, struct WebCore::SecurityOriginData serviceWorkerOrigin) -> (std::optional<WebCore::PageIdentifier> newPage) 94 96 } 95 97 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r291938 r291979 4871 4871 navigation->setClientNavigationActivity(nullptr); 4872 4872 4873 call ServiceWorkerLaunchCompletionHandlerIfNecessary();4873 callLoadCompletionHandlersIfNecessary(false); 4874 4874 } 4875 4875 … … 4906 4906 #endif 4907 4907 4908 void WebPageProxy::call ServiceWorkerLaunchCompletionHandlerIfNecessary()4908 void WebPageProxy::callLoadCompletionHandlersIfNecessary(bool success) 4909 4909 { 4910 4910 #if ENABLE(SERVICE_WORKER) 4911 if (m_isServiceWorkerPage && m_serviceWorkerLaunchCompletionHandler )4911 if (m_isServiceWorkerPage && m_serviceWorkerLaunchCompletionHandler && !success) 4912 4912 m_serviceWorkerLaunchCompletionHandler(false); 4913 4913 #endif 4914 4915 if (m_serviceWorkerOpenWindowCompletionCallback) 4916 m_serviceWorkerOpenWindowCompletionCallback(success); 4914 4917 } 4915 4918 … … 5135 5138 5136 5139 notifyProcessPoolToPrewarm(); 5140 5141 callLoadCompletionHandlersIfNecessary(true); 5137 5142 } 5138 5143 … … 5183 5188 navigation->setClientNavigationActivity(nullptr); 5184 5189 5185 call ServiceWorkerLaunchCompletionHandlerIfNecessary();5190 callLoadCompletionHandlersIfNecessary(false); 5186 5191 } 5187 5192 } … … 8019 8024 8020 8025 if (resetStateReason != ResetStateReason::NavigationSwap) 8021 call ServiceWorkerLaunchCompletionHandlerIfNecessary();8026 callLoadCompletionHandlersIfNecessary(false); 8022 8027 8023 8028 if (m_openPanelResultListener) { -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r291938 r291979 2082 2082 void interactableRegionsInRootViewCoordinates(WebCore::FloatRect, CompletionHandler<void(Vector<WebCore::FloatRect>)>&&); 2083 2083 2084 #if ENABLE(SERVICE_WORKER) 2085 void setServiceWorkerOpenWindowCompletionCallback(CompletionHandler<void(bool)>&& completionCallback) 2086 { 2087 ASSERT(!m_serviceWorkerOpenWindowCompletionCallback); 2088 m_serviceWorkerOpenWindowCompletionCallback = WTFMove(completionCallback); 2089 } 2090 #endif 2091 2084 2092 private: 2085 2093 WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&); … … 2608 2616 void didFinishServiceWorkerPageRegistration(bool success); 2609 2617 #endif 2610 void call ServiceWorkerLaunchCompletionHandlerIfNecessary();2618 void callLoadCompletionHandlersIfNecessary(bool success); 2611 2619 2612 2620 #if PLATFORM(IOS_FAMILY) … … 3120 3128 bool m_isServiceWorkerPage { false }; 3121 3129 CompletionHandler<void(bool)> m_serviceWorkerLaunchCompletionHandler; 3130 CompletionHandler<void(bool)> m_serviceWorkerOpenWindowCompletionCallback; 3122 3131 #endif 3123 3132 -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
r291851 r291979 2088 2088 } 2089 2089 2090 } 2090 void WebsiteDataStore::openWindowFromServiceWorker(const String& urlString, const WebCore::SecurityOriginData& serviceWorkerOrigin, CompletionHandler<void(std::optional<WebCore::PageIdentifier>)>&& callback) 2091 { 2092 auto innerCallback = [callback = WTFMove(callback)] (WebPageProxy* newPage) mutable { 2093 if (!newPage) { 2094 callback(std::nullopt); 2095 return; 2096 } 2097 2098 if (!newPage->pageLoadState().isLoading()) { 2099 RELEASE_LOG(Loading, "The WKWebView provided in response to a ServiceWorker openWindow request was not in the loading state"); 2100 callback(std::nullopt); 2101 return; 2102 } 2103 2104 auto innerCallback = [pageID = newPage->identifier(), callback = WTFMove(callback)] (bool success) mutable { 2105 auto* newPage = WebProcessProxy::webPage(pageID); 2106 if (!newPage || !success) { 2107 callback(std::nullopt); 2108 return; 2109 } 2110 2111 callback(newPage->webPageID()); 2112 }; 2113 2114 newPage->setServiceWorkerOpenWindowCompletionCallback(WTFMove(innerCallback)); 2115 }; 2116 2117 m_client->openWindowFromServiceWorker(urlString, serviceWorkerOrigin, WTFMove(innerCallback)); 2118 } 2119 2120 } -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
r291851 r291979 380 380 void didDestroyServiceWorkerNotification(const UUID& notificationID); 381 381 382 void openWindowFromServiceWorker(const String& urlString, const WebCore::SecurityOriginData& serviceWorkerOrigin, CompletionHandler<void(std::optional<WebCore::PageIdentifier>)>&&); 383 382 384 private: 383 385 enum class ForceReinitialization : bool { No, Yes }; -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h
r278253 r291979 37 37 namespace WebKit { 38 38 39 class WebPageProxy; 40 39 41 class WebsiteDataStoreClient { 40 42 WTF_MAKE_FAST_ALLOCATED; … … 51 53 challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling); 52 54 } 55 56 virtual void openWindowFromServiceWorker(const String&, const WebCore::SecurityOriginData&, CompletionHandler<void(WebPageProxy*)>&& completionHandler) 57 { 58 completionHandler(nullptr); 59 } 53 60 }; 54 61 -
trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp
r289721 r291979 151 151 bool WebNotificationManager::show(Notification& notification, WebPage* page) 152 152 { 153 LOG(Notifications, "WebProcess %i going to show notification %s", getpid(), notification.identifier().toString().utf8().data()); 154 153 155 ASSERT(isMainRunLoop()); 154 156 #if ENABLE(NOTIFICATIONS) … … 209 211 ASSERT(isMainRunLoop()); 210 212 213 LOG(Notifications, "WebProcess %i DID SHOW notification %s", getpid(), notificationID.toString().utf8().data()); 214 211 215 #if ENABLE(NOTIFICATIONS) 212 216 RefPtr<Notification> notification = m_notificationIDMap.get(notificationID); … … 224 228 ASSERT(isMainRunLoop()); 225 229 230 LOG(Notifications, "WebProcess %i DID CLICK notification %s", getpid(), notificationID.toString().utf8().data()); 231 226 232 #if ENABLE(NOTIFICATIONS) 227 233 RefPtr<Notification> notification = m_notificationIDMap.get(notificationID); 228 234 if (!notification) 229 235 return; 236 237 LOG(Notifications, "WebProcess %i handling click event for notification %s", getpid(), notificationID.toString().utf8().data()); 230 238 231 239 // Indicate that this event is being dispatched in reaction to a user's interaction with a platform notification. -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
r291938 r291979 333 333 } 334 334 335 void WebSWContextManagerConnection::openWindow(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, const String& url, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&& callback) 336 { 337 m_connectionToNetworkProcess->sendWithAsyncReply(Messages::WebSWServerToContextConnection::OpenWindow { serviceWorkerIdentifier, url }, WTFMove(callback)); 338 } 339 335 340 void WebSWContextManagerConnection::claim(ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& callback) 336 341 { -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
r291938 r291979 88 88 void didFailHeartBeatCheck(WebCore::ServiceWorkerIdentifier) final; 89 89 void setAsInspected(WebCore::ServiceWorkerIdentifier, bool) final; 90 void openWindow(WebCore::ServiceWorkerIdentifier, const String& url, CompletionHandler<void(std::optional<WebCore::PageIdentifier>&&)>&&) final; 90 91 91 92 // IPC messages. -
trunk/Tools/ChangeLog
r291966 r291979 1 2022-03-28 Brady Eidson <beidson@apple.com> 2 3 Support ServiceWorkerClients.openWindow. 4 <rdar://90616651> and https://bugs.webkit.org/show_bug.cgi?id=238400 5 6 Reviewed by Youenn Fablet. 7 8 Implement the new delegate to create the new view. 9 10 * WebKitTestRunner/TestController.cpp: 11 (WTR::TestController::createOtherPage): 12 (WTR::TestController::createOtherPlatformWebView): 13 * WebKitTestRunner/TestController.h: 14 15 * WebKitTestRunner/cocoa/TestControllerCocoa.mm: 16 (WTR::TestController::platformCreateOtherPage): 17 * WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm: 18 (-[TestWebsiteDataStoreDelegate websiteDataStore:openWindow:fromServiceWorkerOrigin:completionHandler:]): 19 1 20 2022-03-28 Noam Rosenthal <noam@webkit.org> 2 21 -
trunk/Tools/WebKitTestRunner/TestController.cpp
r291737 r291979 382 382 WKPageRef TestController::createOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures) 383 383 { 384 auto* platformWebView = createOtherPlatformWebView(parentView, configuration, navigationAction, windowFeatures); 385 if (!platformWebView) 386 return nullptr; 387 388 auto* page = platformWebView->page(); 389 WKRetain(page); 390 return page; 391 } 392 393 PlatformWebView* TestController::createOtherPlatformWebView(PlatformWebView* parentView, WKPageConfigurationRef configuration, WKNavigationActionRef, WKWindowFeaturesRef) 394 { 384 395 m_currentInvocation->willCreateNewPage(); 385 396 … … 390 401 m_createdOtherPage = true; 391 402 392 auto view = platformCreateOtherPage(parentView, configuration, parentView->options()); 403 auto options = parentView ? parentView->options() : m_mainWebView->options(); 404 auto view = platformCreateOtherPage(parentView, configuration, options); 393 405 WKPageRef newPage = view->page(); 394 406 … … 510 522 TestController::singleton().updateWindowScaleForTest(view.ptr(), *TestController::singleton().m_currentInvocation); 511 523 524 PlatformWebView* viewToReturn = view.ptr(); 512 525 m_auxiliaryWebViews.append(WTFMove(view)); 513 WKRetain(newPage); 514 return newPage; 526 return viewToReturn; 515 527 } 516 528 -
trunk/Tools/WebKitTestRunner/TestController.h
r291737 r291979 379 379 bool denyNotificationPermissionOnPrompt(WKStringRef origin); 380 380 381 PlatformWebView* createOtherPlatformWebView(PlatformWebView* parentView, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef); 382 381 383 private: 382 384 WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(const TestOptions&); -
trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm
r290098 r291979 215 215 { 216 216 auto newConfiguration = adoptNS([globalWebViewConfiguration() copy]); 217 [newConfiguration _setRelatedWebView:static_cast<WKWebView*>(parentView->platformView())]; 217 if (parentView) 218 [newConfiguration _setRelatedWebView:static_cast<WKWebView*>(parentView->platformView())]; 218 219 if ([newConfiguration _relatedWebView]) 219 220 [newConfiguration setWebsiteDataStore:[newConfiguration _relatedWebView].configuration.websiteDataStore]; -
trunk/Tools/WebKitTestRunner/cocoa/TestWebsiteDataStoreDelegate.mm
r249096 r291979 26 26 #import "config.h" 27 27 #import "TestWebsiteDataStoreDelegate.h" 28 29 #import "PlatformWebView.h" 30 #import "TestController.h" 31 #import "TestRunnerWKWebView.h" 32 #import <WebKit/WKWebView.h> 33 #import <wtf/UniqueRef.h> 28 34 29 35 @implementation TestWebsiteDataStoreDelegate { } … … 62 68 } 63 69 70 - (void)websiteDataStore:(WKWebsiteDataStore *)dataStore openWindow:(NSURL *)url fromServiceWorkerOrigin:(WKSecurityOrigin *)serviceWorkerOrigin completionHandler:(void (^)(WKWebView *newWebView))completionHandler 71 { 72 auto* newView = WTR::TestController::singleton().createOtherPlatformWebView(nullptr, nullptr, nullptr, nullptr); 73 WKWebView *webView = newView->platformView(); 74 75 ASSERT(webView.configuration.websiteDataStore == dataStore); 76 77 [webView loadRequest:[NSURLRequest requestWithURL:url]]; 78 completionHandler(webView); 79 } 80 64 81 @end
Note: See TracChangeset
for help on using the changeset viewer.