Diff
Modified: trunk/Source/WebKit/ChangeLog (291392 => 291393)
--- trunk/Source/WebKit/ChangeLog 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/ChangeLog 2022-03-17 07:53:51 UTC (rev 291393)
@@ -1,3 +1,35 @@
+2022-03-16 Antoine Quint <[email protected]>
+
+ [model] -[ASVInlinePreview setRemoteContext:] should be called inside the -[ASVInlinePreview setupRemoteConnectionWithCompletionHandler:] callback
+ https://bugs.webkit.org/show_bug.cgi?id=237959
+ rdar://87832635
+
+ Reviewed by Dean Jackson.
+
+ We need to split the code that creates a remote ASVInlinePreview on macOS in two. The first step is to create the remote ASVInlinePreview
+ and obtain its remote context id from the UIProcess, setting it on the WebProcess ASVInlinePreview in the callback.
+
+ The second step is to load the file in the remote ASVInlinePreview.
+
+ For these two steps, we now have two separate WebProxy messages: ModelElementCreateRemotePreview and ModelElementLoadRemotePreview.
+
+ * UIProcess/Cocoa/ModelElementControllerCocoa.mm:
+ (WebKit::ModelElementController::modelElementCreateRemotePreview):
+ (WebKit::ModelElementController::modelElementLoadRemotePreview):
+ (WebKit::ModelElementController::modelElementDidCreatePreview): Deleted.
+ * UIProcess/ModelElementController.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::modelElementCreateRemotePreview):
+ (WebKit::WebPageProxy::modelElementLoadRemotePreview):
+ (WebKit::WebPageProxy::modelElementDidCreatePreview): Deleted.
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ * WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h:
+ * WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm:
+ (WebKit::ARKitInlinePreviewModelPlayerMac::load):
+ (WebKit::ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL):
+ (WebKit::ARKitInlinePreviewModelPlayerMac::didCreateRemotePreviewForModelWithURL):
+
2022-03-17 Youenn Fablet <[email protected]>
AudioContext is suspended on iOS when page is backgrounded
Modified: trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm (291392 => 291393)
--- trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm 2022-03-17 07:53:51 UTC (rev 291393)
@@ -152,7 +152,7 @@
return m_inlinePreviews.get(modelIdentifier.uuid).get();
}
-void ModelElementController::modelElementDidCreatePreview(URL fileURL, String uuid, WebCore::FloatSize size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&& completionHandler)
+void ModelElementController::modelElementCreateRemotePreview(String uuid, WebCore::FloatSize size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&& completionHandler)
{
if (!m_webPageProxy.preferences().modelElementEnabled()) {
completionHandler(makeUnexpected(WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, { }, "Model element disabled"_s }));
@@ -170,15 +170,12 @@
else
iterator->value = preview;
- // FIXME: Why is this not just using normal URL -> NSURL conversion?
- auto url = "" alloc] initFileURLWithPath:fileURL.fileSystemPath()]);
-
- auto handler = CompletionHandlerWithFinalizer<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>(WTFMove(completionHandler), [url] (Function<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>& completionHandler) {
+ auto handler = CompletionHandlerWithFinalizer<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>(WTFMove(completionHandler), [] (Function<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>& completionHandler) {
completionHandler(makeUnexpected(WebCore::ResourceError { WebCore::ResourceError::Type::General }));
});
RELEASE_ASSERT(isMainRunLoop());
- [preview setupRemoteConnectionWithCompletionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, preview, uuid = WTFMove(uuid), url = "" handler = WTFMove(handler)] (NSError *contextError) mutable {
+ [preview setupRemoteConnectionWithCompletionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, preview, uuid = WTFMove(uuid), handler = WTFMove(handler)] (NSError *contextError) mutable {
if (contextError) {
LOG(ModelElement, "Unable to create remote connection for uuid %s: %@.", uuid.utf8().data(), contextError.localizedDescription);
@@ -193,29 +190,53 @@
LOG(ModelElement, "Established remote connection with UUID %s.", uuid.utf8().data());
- [preview preparePreviewOfFileAtURL:url.get() completionHandler:makeBlockPtr([weakThis = WTFMove(weakThis), preview, uuid = WTFMove(uuid), url = "" handler = WTFMove(handler)] (NSError *loadError) mutable {
- if (loadError) {
- LOG(ModelElement, "Unable to load file for uuid %s: %@.", uuid.utf8().data(), loadError.localizedDescription);
+ auto contextId = [preview contextId];
+ callOnMainRunLoop([weakThis = WTFMove(weakThis), uuid = WTFMove(uuid), handler = WTFMove(handler), contextId] () mutable {
+ if (!weakThis)
+ return;
- callOnMainRunLoop([weakThis = WTFMove(weakThis), handler = WTFMove(handler), error = WebCore::ResourceError { loadError }] () mutable {
- if (!weakThis)
- return;
+ handler(std::make_pair(uuid, contextId));
+ });
+ }).get()];
+}
- handler(makeUnexpected(error));
- });
- return;
- }
+void ModelElementController::modelElementLoadRemotePreview(String uuid, URL fileURL, CompletionHandler<void(std::optional<WebCore::ResourceError>&&)>&& completionHandler)
+{
+ if (!m_webPageProxy.preferences().modelElementEnabled()) {
+ completionHandler(WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, { }, "Model element disabled"_s });
+ return;
+ }
- LOG(ModelElement, "Loaded file with UUID %s.", uuid.utf8().data());
+ auto preview = previewForUUID(uuid);
+ if (!preview)
+ completionHandler(WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, { }, "Could not find a preview for the provided UUID"_s });
- auto contextId = [preview contextId];
- callOnMainRunLoop([weakThis = WTFMove(weakThis), uuid = WTFMove(uuid), handler = WTFMove(handler), contextId] () mutable {
+ auto handler = CompletionHandlerWithFinalizer<void(std::optional<WebCore::ResourceError>&&)>(WTFMove(completionHandler), [](Function<void(std::optional<WebCore::ResourceError>&&)>& completionHandler) {
+ completionHandler(WebCore::ResourceError { WebCore::ResourceError::Type::General });
+ });
+
+ RELEASE_ASSERT(isMainRunLoop());
+ [preview preparePreviewOfFileAtURL:[[NSURL alloc] initFileURLWithPath:fileURL.fileSystemPath()] completionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, uuid = WTFMove(uuid), handler = WTFMove(handler)] (NSError *loadError) mutable {
+ if (loadError) {
+ LOG(ModelElement, "Unable to load file for uuid %s: %@.", uuid.utf8().data(), loadError.localizedDescription);
+
+ callOnMainRunLoop([weakThis = WTFMove(weakThis), handler = WTFMove(handler), error = WebCore::ResourceError { loadError }] () mutable {
if (!weakThis)
return;
- handler(std::make_pair(uuid, contextId));
+ handler(error);
});
- }).get()];
+ return;
+ }
+
+ LOG(ModelElement, "Loaded file with UUID %s.", uuid.utf8().data());
+
+ callOnMainRunLoop([weakThis = WTFMove(weakThis), handler = WTFMove(handler)] () mutable {
+ if (!weakThis)
+ return;
+
+ handler({ });
+ });
}).get()];
}
Modified: trunk/Source/WebKit/UIProcess/ModelElementController.h (291392 => 291393)
--- trunk/Source/WebKit/UIProcess/ModelElementController.h 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/UIProcess/ModelElementController.h 2022-03-17 07:53:51 UTC (rev 291393)
@@ -73,7 +73,8 @@
void setInteractionEnabledForModelElement(ModelIdentifier, bool);
#endif
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
- void modelElementDidCreatePreview(URL, String, WebCore::FloatSize, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
+ void modelElementCreateRemotePreview(String, WebCore::FloatSize, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
+ void modelElementLoadRemotePreview(String, URL, CompletionHandler<void(std::optional<WebCore::ResourceError>&&)>&&);
void modelElementSizeDidChange(const String& uuid, WebCore::FloatSize, CompletionHandler<void(Expected<MachSendRight, WebCore::ResourceError>)>&&);
void handleMouseDownForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
void handleMouseMoveForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (291392 => 291393)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-03-17 07:53:51 UTC (rev 291393)
@@ -11107,11 +11107,16 @@
#endif
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
-void WebPageProxy::modelElementDidCreatePreview(const URL& url, const String& uuid, const FloatSize& size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, ResourceError>)>&& completionHandler)
+void WebPageProxy::modelElementCreateRemotePreview(const String& uuid, const FloatSize& size, CompletionHandler<void(Expected<std::pair<String, uint32_t>, ResourceError>)>&& completionHandler)
{
- modelElementController()->modelElementDidCreatePreview(url, uuid, size, WTFMove(completionHandler));
+ modelElementController()->modelElementCreateRemotePreview(uuid, size, WTFMove(completionHandler));
}
+void WebPageProxy::modelElementLoadRemotePreview(const String& uuid, const URL& url, CompletionHandler<void(std::optional<WebCore::ResourceError>&&)>&& completionHandler)
+{
+ modelElementController()->modelElementLoadRemotePreview(uuid, url, WTFMove(completionHandler));
+}
+
void WebPageProxy::modelElementSizeDidChange(const String& uuid, WebCore::FloatSize size, CompletionHandler<void(Expected<MachSendRight, WebCore::ResourceError>)>&& completionHandler)
{
modelElementController()->modelElementSizeDidChange(uuid, size, WTFMove(completionHandler));
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (291392 => 291393)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2022-03-17 07:53:51 UTC (rev 291393)
@@ -613,7 +613,8 @@
void modelElementSetInteractionEnabled(ModelIdentifier, bool);
#endif
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
- void modelElementDidCreatePreview(const URL&, const String&, const WebCore::FloatSize&, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
+ void modelElementCreateRemotePreview(const String&, const WebCore::FloatSize&, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
+ void modelElementLoadRemotePreview(const String&, const URL&, CompletionHandler<void(std::optional<WebCore::ResourceError>&&)>&&);
void modelElementSizeDidChange(const String&, WebCore::FloatSize, CompletionHandler<void(Expected<MachSendRight, WebCore::ResourceError>)>&&);
void handleMouseDownForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
void handleMouseMoveForModelElement(const String&, const WebCore::LayoutPoint&, MonotonicTime);
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (291392 => 291393)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2022-03-17 07:53:51 UTC (rev 291393)
@@ -591,7 +591,8 @@
ModelElementSetInteractionEnabled(struct WebKit::ModelIdentifier modelIdentifier, bool isInteractionEnabled)
#endif
#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
- ModelElementDidCreatePreview(URL url, String uuid, WebCore::FloatSize size) -> (Expected<std::pair<String, uint32_t>, WebCore::ResourceError> result)
+ ModelElementCreateRemotePreview(String uuid, WebCore::FloatSize size) -> (Expected<std::pair<String, uint32_t>, WebCore::ResourceError> result)
+ ModelElementLoadRemotePreview(String uuid, URL url) -> (std::optional<WebCore::ResourceError> error)
ModelElementSizeDidChange(String uuid, WebCore::FloatSize size) -> (Expected<MachSendRight, WebCore::ResourceError> result)
HandleMouseDownForModelElement(String uuid, WebCore::LayoutPoint flippedLocationInElement, MonotonicTime timestamp)
HandleMouseMoveForModelElement(String uuid, WebCore::LayoutPoint flippedLocationInElement, MonotonicTime timestamp)
Modified: trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h (291392 => 291393)
--- trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h 2022-03-17 07:53:51 UTC (rev 291393)
@@ -62,6 +62,9 @@
void createFile(WebCore::Model&);
void clearFile();
+ void createPreviewsForModelWithURL(const URL&);
+ void didCreateRemotePreviewForModelWithURL(const URL&);
+
WebCore::LayoutSize m_size;
String m_filePath;
RetainPtr<ASVInlinePreview> m_inlinePreview;
Modified: trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm (291392 => 291393)
--- trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm 2022-03-17 07:41:49 UTC (rev 291392)
+++ trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm 2022-03-17 07:53:51 UTC (rev 291393)
@@ -140,11 +140,26 @@
}
createFile(modelSource);
+ createPreviewsForModelWithURL(modelSource.url());
+}
- m_inlinePreview = adoptNS([allocASVInlinePreviewInstance() initWithFrame:CGRectMake(0, 0, size.width(), size.height())]);
- LOG(ModelElement, "ARKitInlinePreviewModelPlayer::modelDidChange() created preview with UUID %s and size %f x %f.", ((String)[m_inlinePreview uuid].UUIDString).utf8().data(), size.width(), size.height());
+void ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL(const URL& url)
+{
+ // First, create the WebProcess preview.
+ m_inlinePreview = adoptNS([allocASVInlinePreviewInstance() initWithFrame:CGRectMake(0, 0, m_size.width(), m_size.height())]);
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL() created preview with UUID %s and size %f x %f.", ((String)[m_inlinePreview uuid].UUIDString).utf8().data(), m_size.width(), m_size.height());
- CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)> completionHandler = [weakSelf = WeakPtr { *this }] (Expected<std::pair<String, uint32_t>, WebCore::ResourceError> result) mutable {
+ auto strongClient = client();
+ if (!strongClient)
+ return;
+
+ RefPtr strongPage = page();
+ if (!strongPage) {
+ strongClient->didFailLoading(*this, WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, url, "WebPage destroyed"_s });
+ return;
+ }
+
+ CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)> completionHandler = [weakSelf = WeakPtr { *this }, url] (Expected<std::pair<String, uint32_t>, WebCore::ResourceError> result) mutable {
RefPtr strongSelf = weakSelf.get();
if (!strongSelf)
return;
@@ -154,7 +169,7 @@
return;
if (!result) {
- LOG(ModelElement, "ARKitInlinePreviewModelPlayer::inlinePreviewDidObtainContextId() received error from UIProcess");
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL() received error from UIProcess");
strongClient->didFailLoading(*strongSelf, result.error());
return;
}
@@ -163,18 +178,55 @@
String expectedUUID = [strongSelf->m_inlinePreview uuid].UUIDString;
if (uuid != expectedUUID) {
- LOG(ModelElement, "ARKitInlinePreviewModelPlayer::inlinePreviewDidObtainContextId() UUID mismatch, received %s but expected %s.", uuid.utf8().data(), expectedUUID.utf8().data());
- strongClient->didFailLoading(*strongSelf, WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, { }, makeString("ARKitInlinePreviewModelPlayer::inlinePreviewDidObtainContextId() UUID mismatch, received ", uuid, " but expected ", expectedUUID, ".") });
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL() UUID mismatch, received %s but expected %s.", uuid.utf8().data(), expectedUUID.utf8().data());
+ strongClient->didFailLoading(*strongSelf, WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, { }, makeString("ARKitInlinePreviewModelPlayer::createPreviewsForModelWithURL() UUID mismatch, received ", uuid, " but expected ", expectedUUID, ".") });
return;
}
[strongSelf->m_inlinePreview setRemoteContext:contextId];
- LOG(ModelElement, "ARKitInlinePreviewModelPlayer::inlinePreviewDidObtainContextId() successfully established remote connection for UUID %s.", uuid.utf8().data());
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayerMac::createPreviewsForModelWithURL() successfully established remote connection for UUID %s.", uuid.utf8().data());
+ strongSelf->didCreateRemotePreviewForModelWithURL(url);
+ };
+
+ // Then, create the UIProcess preview.
+ strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementCreateRemotePreview([m_inlinePreview uuid].UUIDString, m_size), WTFMove(completionHandler));
+}
+
+void ARKitInlinePreviewModelPlayerMac::didCreateRemotePreviewForModelWithURL(const URL& url)
+{
+ auto strongClient = client();
+ if (!strongClient)
+ return;
+
+ RefPtr strongPage = page();
+ if (!strongPage) {
+ strongClient->didFailLoading(*this, WebCore::ResourceError { WebCore::errorDomainWebKitInternal, 0, url, "WebPage destroyed"_s });
+ return;
+ }
+
+ CompletionHandler<void(std::optional<WebCore::ResourceError>&&)> completionHandler = [weakSelf = WeakPtr { *this }] (std::optional<WebCore::ResourceError>&& error) mutable {
+ RefPtr strongSelf = weakSelf.get();
+ if (!strongSelf)
+ return;
+
+ auto strongClient = strongSelf->client();
+ if (!strongClient)
+ return;
+
+ if (error) {
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayer::didCreateRemotePreviewForModelWithURL() received error from UIProcess");
+ strongClient->didFailLoading(*strongSelf, *error);
+ return;
+ }
+
+ LOG(ModelElement, "ARKitInlinePreviewModelPlayer::didCreateRemotePreviewForModelWithURL() successfully completed load for UUID %s.", [strongSelf->m_inlinePreview uuid]);
+
strongClient->didFinishLoading(*strongSelf);
};
-
- strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementDidCreatePreview(URL::fileURLWithFileSystemPath(m_filePath), [m_inlinePreview uuid].UUIDString, size), WTFMove(completionHandler));
+
+ // Now that both the WebProcess and UIProcess previews are created, load the file into the remote preview.
+ strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementLoadRemotePreview([m_inlinePreview uuid].UUIDString, URL::fileURLWithFileSystemPath(m_filePath)), WTFMove(completionHandler));
}
void ARKitInlinePreviewModelPlayerMac::sizeDidChange(WebCore::LayoutSize size)