Title: [286019] trunk/Source
Revision
286019
Author
[email protected]
Date
2021-11-18 11:38:01 -0800 (Thu, 18 Nov 2021)

Log Message

[Model] add support for getting and setting the camera
https://bugs.webkit.org/show_bug.cgi?id=233265
<rdar://problem/85426290>

Reviewed by Darin Adler.

Source/WebCore:

We add two new promise-based methods to the HTMLModelElement IDL to access and set the camera:
getCamera() and setCamera(). The camera is represented by a new HTMLModelElementCamera dictionary
which has yaw, pitch and scale members.

* CMakeLists.txt:
* Headers.cmake:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::getCamera):
(WebCore::HTMLModelElement::setCamera):
* Modules/model-element/HTMLModelElement.h:
* Modules/model-element/HTMLModelElement.idl:
* Modules/model-element/HTMLModelElementCamera.h: Copied from Source/WebCore/Modules/model-element/HTMLModelElement.idl.
(WebCore::HTMLModelElementCamera::encode const):
(WebCore::HTMLModelElementCamera::decode):
* Modules/model-element/HTMLModelElementCamera.idl: Copied from Source/WebCore/Modules/model-element/HTMLModelElement.idl.
* Modules/model-element/ModelPlayer.h:
* Modules/model-element/dummy/DummyModelPlayer.cpp:
(WebCore::DummyModelPlayer::getCamera):
(WebCore::DummyModelPlayer::setCamera):
* Modules/model-element/dummy/DummyModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.h:
* Modules/model-element/scenekit/SceneKitModelPlayer.mm:
(WebCore::SceneKitModelPlayer::getCamera):
(WebCore::SceneKitModelPlayer::setCamera):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* loader/EmptyClients.cpp:
(WebCore::EmptyChromeClient::takeModelElementFullscreen const): Deleted.
* loader/EmptyClients.h:
* page/ChromeClient.h:
(WebCore::ChromeClient::takeModelElementFullscreen const): Deleted.

Source/WebCore/PAL:

Add the new ARQL SPIs we are using.

* pal/spi/ios/SystemPreviewSPI.h:
* pal/spi/mac/SystemPreviewSPI.h:

Source/WebKit:

The ARQL APIs we'd adopted so far were specific to either macOS or iOS. The new camera
methods are different since they exist on both platforms.

In order to expose a single message for both platforms, we introduce a new ModelIdentifier
struct which wraps the UUID string for macOS and the layer identifier for iOS. Then on
ModelElementController, we have the previewForModelIdentifier() method to get the matching
ASVInlinePreview for the provided ModelIdentifier.

This allows getCameraForModelElement() and setCameraForModelElement to be specified for both
iOS and macOS with a single implementation.

We also modify takeModelElementFullscreen() to take advantage of ModelIdentifier which showed
that we had some lingering code in ChromeClient related to this method that was no longer
necessary following r285922.

* Shared/ModelIdentifier.h: Copied from Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h.
(WebKit::ModelIdentifier::encode const):
(WebKit::ModelIdentifier::decode):
* UIProcess/Cocoa/ModelElementControllerCocoa.mm:
(WebKit::ModelElementController::modelViewForModelIdentifier):
(WebKit::ModelElementController::previewForModelIdentifier):
(WebKit::ModelElementController::takeModelElementFullscreen):
(WebKit::previewHasCameraSupport):
(WebKit::ModelElementController::getCameraForModelElement):
(WebKit::ModelElementController::setCameraForModelElement):
* UIProcess/ModelElementController.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::modelElementGetCamera):
(WebKit::WebPageProxy::modelElementSetCamera):
(WebKit::WebPageProxy::takeModelElementFullscreen):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Model/ARKitInlinePreviewModelPlayer.h:
* WebProcess/Model/ARKitInlinePreviewModelPlayer.mm:
(WebKit::ARKitInlinePreviewModelPlayer::getCamera):
(WebKit::ARKitInlinePreviewModelPlayer::setCamera):
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h:
* WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm:
(WebKit::ARKitInlinePreviewModelPlayerIOS::modelIdentifier):
(WebKit::ARKitInlinePreviewModelPlayerIOS::enterFullscreen):
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h:
* WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm:
(WebKit::ARKitInlinePreviewModelPlayerMac::modelIdentifier):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::takeModelElementFullscreen const): Deleted.
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::takeModelElementFullscreen): Deleted.
* WebProcess/WebPage/WebPage.h:

Source/WTF:

Add a new compile-time flag for the new ARQL SPIs we are using.

* wtf/PlatformEnableCocoa.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (286018 => 286019)


--- trunk/Source/WTF/ChangeLog	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WTF/ChangeLog	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1,3 +1,15 @@
+2021-11-18  Antoine Quint  <[email protected]>
+
+        [Model] add support for getting and setting the camera
+        https://bugs.webkit.org/show_bug.cgi?id=233265
+        <rdar://problem/85426290>
+
+        Reviewed by Darin Adler.
+
+        Add a new compile-time flag for the new ARQL SPIs we are using.
+
+        * wtf/PlatformEnableCocoa.h:
+
 2021-11-17  John Wilander  <[email protected]>
 
         PCM: Add capability for click destination to fire triggering event without cross-site requests to the click source

Modified: trunk/Source/WTF/wtf/PlatformEnableCocoa.h (286018 => 286019)


--- trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -743,3 +743,7 @@
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS) || ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 #define ENABLE_ARKIT_INLINE_PREVIEW 1
 #endif
+
+#if (ENABLE(ARKIT_INLINE_PREVIEW_MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 120400) || (ENABLE(ARKIT_INLINE_PREVIEW_IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150400)
+#define ENABLE_ARKIT_INLINE_PREVIEW_CAMERA_TRANSFORM 1
+#endif

Modified: trunk/Source/WebCore/CMakeLists.txt (286018 => 286019)


--- trunk/Source/WebCore/CMakeLists.txt	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/CMakeLists.txt	2021-11-18 19:38:01 UTC (rev 286019)
@@ -463,6 +463,7 @@
     Modules/mediastream/RTCTransformEvent.idl
 
     Modules/model-element/HTMLModelElement.idl
+    Modules/model-element/HTMLModelElementCamera.idl
 
     Modules/notifications/Notification.idl
     Modules/notifications/NotificationPermission.idl

Modified: trunk/Source/WebCore/ChangeLog (286018 => 286019)


--- trunk/Source/WebCore/ChangeLog	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/ChangeLog	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1,3 +1,46 @@
+2021-11-18  Antoine Quint  <[email protected]>
+
+        [Model] add support for getting and setting the camera
+        https://bugs.webkit.org/show_bug.cgi?id=233265
+        <rdar://problem/85426290>
+
+        Reviewed by Darin Adler.
+
+        We add two new promise-based methods to the HTMLModelElement IDL to access and set the camera:
+        getCamera() and setCamera(). The camera is represented by a new HTMLModelElementCamera dictionary
+        which has yaw, pitch and scale members.
+
+        * CMakeLists.txt:
+        * Headers.cmake:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/model-element/HTMLModelElement.cpp:
+        (WebCore::HTMLModelElement::getCamera):
+        (WebCore::HTMLModelElement::setCamera):
+        * Modules/model-element/HTMLModelElement.h:
+        * Modules/model-element/HTMLModelElement.idl:
+        * Modules/model-element/HTMLModelElementCamera.h: Copied from Source/WebCore/Modules/model-element/HTMLModelElement.idl.
+        (WebCore::HTMLModelElementCamera::encode const):
+        (WebCore::HTMLModelElementCamera::decode):
+        * Modules/model-element/HTMLModelElementCamera.idl: Copied from Source/WebCore/Modules/model-element/HTMLModelElement.idl.
+        * Modules/model-element/ModelPlayer.h:
+        * Modules/model-element/dummy/DummyModelPlayer.cpp:
+        (WebCore::DummyModelPlayer::getCamera):
+        (WebCore::DummyModelPlayer::setCamera):
+        * Modules/model-element/dummy/DummyModelPlayer.h:
+        * Modules/model-element/scenekit/SceneKitModelPlayer.h:
+        * Modules/model-element/scenekit/SceneKitModelPlayer.mm:
+        (WebCore::SceneKitModelPlayer::getCamera):
+        (WebCore::SceneKitModelPlayer::setCamera):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/EmptyClients.cpp:
+        (WebCore::EmptyChromeClient::takeModelElementFullscreen const): Deleted.
+        * loader/EmptyClients.h:
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::takeModelElementFullscreen const): Deleted.
+
 2021-11-18  David Kilzer  <[email protected]>
 
         Add missing dependencies for <wtf/Platform.h> when generating derived sources

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (286018 => 286019)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-11-18 19:38:01 UTC (rev 286019)
@@ -441,6 +441,7 @@
 $(PROJECT_DIR)/Modules/mediastream/RTCTrackEvent.idl
 $(PROJECT_DIR)/Modules/mediastream/RTCTransformEvent.idl
 $(PROJECT_DIR)/Modules/model-element/HTMLModelElement.idl
+$(PROJECT_DIR)/Modules/model-element/HTMLModelElementCamera.idl
 $(PROJECT_DIR)/Modules/modern-media-controls/controls/activity-indicator.css
 $(PROJECT_DIR)/Modules/modern-media-controls/controls/airplay-button.css
 $(PROJECT_DIR)/Modules/modern-media-controls/controls/airplay-button.js

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (286018 => 286019)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1283,6 +1283,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLModElement.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLModelElement.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLModelElement.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLModelElementCamera.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLModelElementCamera.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLOListElement.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLOListElement.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSHTMLObjectElement.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (286018 => 286019)


--- trunk/Source/WebCore/DerivedSources.make	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/DerivedSources.make	2021-11-18 19:38:01 UTC (rev 286019)
@@ -457,6 +457,7 @@
     $(WebCore)/Modules/mediastream/RTCTrackEvent.idl \
     $(WebCore)/Modules/mediastream/RTCTransformEvent.idl \
     $(WebCore)/Modules/model-element/HTMLModelElement.idl \
+    $(WebCore)/Modules/model-element/HTMLModelElementCamera.idl \
     $(WebCore)/Modules/notifications/Notification.idl \
     $(WebCore)/Modules/notifications/NotificationPermission.idl \
     $(WebCore)/Modules/notifications/NotificationPermissionCallback.idl \

Modified: trunk/Source/WebCore/Headers.cmake (286018 => 286019)


--- trunk/Source/WebCore/Headers.cmake	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Headers.cmake	2021-11-18 19:38:01 UTC (rev 286019)
@@ -137,6 +137,7 @@
     Modules/mediastream/libwebrtc/LibWebRTCUtils.h
 
     Modules/model-element/HTMLModelElement.h
+    Modules/model-element/HTMLModelElementCamera.h
     Modules/model-element/ModelPlayer.h
     Modules/model-element/ModelPlayerClient.h
     Modules/model-element/ModelPlayerProvider.h

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -37,11 +37,14 @@
 #include "EventNames.h"
 #include "GraphicsLayer.h"
 #include "GraphicsLayerCA.h"
+#include "HTMLModelElementCamera.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
 #include "HTMLSourceElement.h"
+#include "JSDOMPromiseDeferred.h"
 #include "JSEventTarget.h"
 #include "JSHTMLModelElement.h"
+#include "JSHTMLModelElementCamera.h"
 #include "Model.h"
 #include "ModelPlayer.h"
 #include "ModelPlayerProvider.h"
@@ -360,6 +363,38 @@
         m_modelPlayer->handleMouseUp(event.pageLocation(), event.timeStamp());
 }
 
+// MARK: – Camera support.
+
+void HTMLModelElement::getCamera(CameraPromise&& promise)
+{
+    if (!m_modelPlayer) {
+        promise.reject();
+        return;
+    }
+
+    m_modelPlayer->getCamera([promise = WTFMove(promise)] (std::optional<HTMLModelElementCamera> camera) mutable {
+        if (!camera)
+            promise.reject();
+        else
+            promise.resolve(*camera);
+    });
 }
 
+void HTMLModelElement::setCamera(HTMLModelElementCamera camera, DOMPromiseDeferred<void>&& promise)
+{
+    if (!m_modelPlayer) {
+        promise.reject();
+        return;
+    }
+
+    m_modelPlayer->setCamera(camera, [promise = WTFMove(promise)] (bool success) mutable {
+        if (success)
+            promise.resolve();
+        else
+            promise.reject();
+    });
+}
+
+}
+
 #endif // ENABLE(MODEL_ELEMENT)

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -32,6 +32,7 @@
 #include "CachedResourceHandle.h"
 #include "GraphicsLayer.h"
 #include "HTMLElement.h"
+#include "HTMLModelElementCamera.h"
 #include "IDLTypes.h"
 #include "ModelPlayerClient.h"
 #include "PlatformLayer.h"
@@ -45,6 +46,7 @@
 class ModelPlayer;
 class MouseEvent;
 
+template<typename IDLType> class DOMPromiseDeferred;
 template<typename IDLType> class DOMPromiseProxyWithResolveCallback;
 
 class HTMLModelElement final : public HTMLElement, private CachedRawResourceClient, public ModelPlayerClient {
@@ -69,6 +71,10 @@
 
     void enterFullscreen();
 
+    using CameraPromise = DOMPromiseDeferred<IDLDictionary<HTMLModelElementCamera>>;
+    void getCamera(CameraPromise&&);
+    void setCamera(HTMLModelElementCamera, DOMPromiseDeferred<void>&&);
+
     bool isDraggableIgnoringAttributes() const final { return true; }
 
 private:

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl	2021-11-18 19:38:01 UTC (rev 286019)
@@ -33,4 +33,7 @@
     readonly attribute Promise<HTMLModelElement> ready;
 
     undefined enterFullscreen();
+
+    Promise<HTMLModelElementCamera> getCamera();
+    Promise<undefined> setCamera(HTMLModelElementCamera camera);
 };

Copied: trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.h (from rev 286018, trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl) (0 => 286019)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <optional>
+
+namespace WebCore {
+
+struct HTMLModelElementCamera {
+    double pitch { 0 };
+    double yaw { 0 };
+    double scale { 1 };
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<HTMLModelElementCamera> decode(Decoder&);
+};
+
+template<class Encoder> void HTMLModelElementCamera::encode(Encoder& encoder) const
+{
+    encoder << pitch;
+    encoder << yaw;
+    encoder << scale;
+}
+
+template<class Decoder> std::optional<HTMLModelElementCamera> HTMLModelElementCamera::decode(Decoder& decoder)
+{
+    std::optional<double> pitch;
+    decoder >> pitch;
+    if (!pitch)
+        return std::nullopt;
+
+    std::optional<double> yaw;
+    decoder >> yaw;
+    if (!yaw)
+        return std::nullopt;
+
+    std::optional<double> scale;
+    decoder >> scale;
+    if (!scale)
+        return std::nullopt;
+
+    return { { *pitch, *yaw, *scale } };
+}
+
+} // namespace WebCore
+

Copied: trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl (from rev 286018, trunk/Source/WebCore/Modules/model-element/HTMLModelElement.idl) (0 => 286019)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl	2021-11-18 19:38:01 UTC (rev 286019)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=MODEL_ELEMENT,
+    EnabledBySetting=ModelElementEnabled,
+    JSGenerateToJSObject
+] dictionary HTMLModelElementCamera {
+    double pitch;
+    double yaw;
+    double scale;
+};

Modified: trunk/Source/WebCore/Modules/model-element/ModelPlayer.h (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/ModelPlayer.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/ModelPlayer.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -25,9 +25,11 @@
 
 #pragma once
 
+#include "HTMLModelElementCamera.h"
 #include "LayoutPoint.h"
 #include "LayoutSize.h"
 #include "PlatformLayer.h"
+#include <optional>
 #include <wtf/Forward.h>
 #include <wtf/MonotonicTime.h>
 
@@ -47,7 +49,8 @@
     virtual void handleMouseDown(const LayoutPoint&, MonotonicTime) = 0;
     virtual void handleMouseMove(const LayoutPoint&, MonotonicTime) = 0;
     virtual void handleMouseUp(const LayoutPoint&, MonotonicTime) = 0;
-
+    virtual void getCamera(CompletionHandler<void(std::optional<HTMLModelElementCamera>&&)>&&) = 0;
+    virtual void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) = 0;
 };
 
 }

Modified: trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -70,4 +70,12 @@
 {
 }
 
+void DummyModelPlayer::getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&&)
+{
 }
+
+void DummyModelPlayer::setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&)
+{
+}
+
+}

Modified: trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/dummy/DummyModelPlayer.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -47,6 +47,8 @@
     void handleMouseDown(const LayoutPoint&, MonotonicTime) override;
     void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
     void handleMouseUp(const LayoutPoint&, MonotonicTime) override;
+    void getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&&) override;
+    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
 
     WeakPtr<ModelPlayerClient> m_client;
 };

Modified: trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -61,6 +61,8 @@
     void handleMouseDown(const LayoutPoint&, MonotonicTime) override;
     void handleMouseMove(const LayoutPoint&, MonotonicTime) override;
     void handleMouseUp(const LayoutPoint&, MonotonicTime) override;
+    void getCamera(CompletionHandler<void(std::optional<HTMLModelElementCamera>&&)>&&) override;
+    void setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
 
     // SceneKitModelLoaderClient overrides.
     virtual void didFinishLoading(SceneKitModelLoader&, Ref<SceneKitModel>) override;

Modified: trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm (286018 => 286019)


--- trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.mm	2021-11-18 19:38:01 UTC (rev 286019)
@@ -88,6 +88,14 @@
 {
 }
 
+void SceneKitModelPlayer::getCamera(CompletionHandler<void(std::optional<HTMLModelElementCamera>&&)>&&)
+{
+}
+
+void SceneKitModelPlayer::setCamera(HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&)
+{
+}
+
 // MARK: - SceneKitModelLoaderClient overrides.
 
 void SceneKitModelPlayer::didFinishLoading(SceneKitModelLoader& loader, Ref<SceneKitModel> model)

Modified: trunk/Source/WebCore/PAL/ChangeLog (286018 => 286019)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1,5 +1,18 @@
 2021-11-18  Antoine Quint  <[email protected]>
 
+        [Model] add support for getting and setting the camera
+        https://bugs.webkit.org/show_bug.cgi?id=233265
+        <rdar://problem/85426290>
+
+        Reviewed by Darin Adler.
+
+        Add the new ARQL SPIs we are using.
+
+        * pal/spi/ios/SystemPreviewSPI.h:
+        * pal/spi/mac/SystemPreviewSPI.h:
+
+2021-11-18  Antoine Quint  <[email protected]>
+
         [Model] [macOS] Add support for interaction on macOS
         https://bugs.webkit.org/show_bug.cgi?id=233105
         <rdar://problem/80079386>

Modified: trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h (286018 => 286019)


--- trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/SystemPreviewSPI.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -58,10 +58,11 @@
 @property (nonatomic, assign) QLItem *thumbnailItem;
 @property (nonatomic) CGSize maxThumbnailSize;
 @end
-#endif
 
 NS_ASSUME_NONNULL_END
 
+#endif
+
 #if HAVE(ARKIT_QUICK_LOOK_PREVIEW_ITEM)
 #import <ARKit/ARKit.h>
 
@@ -77,10 +78,16 @@
 - (void)setDelegate:(id <ARQuickLookWebKitItemDelegate>)delegate;
 @end
 
+NS_ASSUME_NONNULL_END
+
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
 
+#import <simd/simd.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
 @class ASVInlinePreview;
 @class CAFenceHandle;
 @interface ASVInlinePreview : NSObject
@@ -97,10 +104,14 @@
 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
 
+typedef void (^ASVCameraTransformReplyBlock) (simd_float3 cameraTransform, NSError * _Nullable error);
+- (void)getCameraTransform:(ASVCameraTransformReplyBlock)reply;
+- (void)setCameraTransform:(simd_float3)transform;
+
 @end
 
-#endif
-
 NS_ASSUME_NONNULL_END
 
 #endif
+
+#endif

Modified: trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h (286018 => 286019)


--- trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -31,10 +31,12 @@
 
 #else // USE(APPLE_INTERNAL_SDK)
 
+#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
+
+#import <simd/simd.h>
+
 NS_ASSUME_NONNULL_BEGIN
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
-
 @class ASVInlinePreview;
 
 @interface ASVInlinePreview : NSObject
@@ -52,10 +54,14 @@
 - (void)mouseDraggedAtLocation:(CGPoint)location timestamp:(NSTimeInterval)timestamp;
 - (void)mouseUpAtLocation:(CGPoint)location timestamp:(NSTimeInterval)timestamp;
 
+typedef void (^ASVCameraTransformReplyBlock) (simd_float3 cameraTransform, NSError * _Nullable error);
+- (void)getCameraTransform:(ASVCameraTransformReplyBlock)reply;
+- (void)setCameraTransform:(simd_float3)transform;
+
 @end
 
+NS_ASSUME_NONNULL_END
+
 #endif // ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 
-NS_ASSUME_NONNULL_END
-
 #endif // USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebCore/Sources.txt (286018 => 286019)


--- trunk/Source/WebCore/Sources.txt	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/Sources.txt	2021-11-18 19:38:01 UTC (rev 286019)
@@ -3301,6 +3301,7 @@
 JSHTMLMeterElement.cpp
 JSHTMLModElement.cpp
 JSHTMLModelElement.cpp
+JSHTMLModelElementCamera.cpp
 JSHTMLOListElement.cpp
 JSHTMLObjectElement.cpp
 JSHTMLOptGroupElement.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (286018 => 286019)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-11-18 19:38:01 UTC (rev 286019)
@@ -2274,6 +2274,7 @@
 		715AD7212050513F00D592DC /* CSSTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 7123C186204739BA00789392 /* CSSTransition.h */; };
 		71729F7B20F3BA4900801CE6 /* DocumentTimelineOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 71729F7A20F3BA3A00801CE6 /* DocumentTimelineOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		71729F7E20F3BB4700801CE6 /* JSDocumentTimelineOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 71729F7C20F3BAB900801CE6 /* JSDocumentTimelineOptions.h */; };
+		7177AD57274295D1002F103B /* HTMLModelElementCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 7177AD5627429590002F103B /* HTMLModelElementCamera.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7181A16C244F0F40007D8A24 /* DocumentTimelinesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7181A169244F0F2C007D8A24 /* DocumentTimelinesController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		71A1B6081DEE5AD70073BCFB /* modern-media-controls-localized-strings.js in Resources */ = {isa = PBXBuildFile; fileRef = 71A1B6061DEE5A820073BCFB /* modern-media-controls-localized-strings.js */; };
 		71A3D1812562B85B0064E2A6 /* HTMLModelElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 71A3D17D2562B8240064E2A6 /* HTMLModelElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10775,6 +10776,10 @@
 		71729F7C20F3BAB900801CE6 /* JSDocumentTimelineOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDocumentTimelineOptions.h; sourceTree = "<group>"; };
 		71729F7D20F3BABA00801CE6 /* JSDocumentTimelineOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentTimelineOptions.cpp; sourceTree = "<group>"; };
 		7173DEBD2614DF040097DF32 /* Styleable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Styleable.cpp; sourceTree = "<group>"; };
+		7177AD542742952F002F103B /* HTMLModelElementCamera.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLModelElementCamera.idl; sourceTree = "<group>"; };
+		7177AD5627429590002F103B /* HTMLModelElementCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLModelElementCamera.h; sourceTree = "<group>"; };
+		7177AD5827429CCA002F103B /* JSHTMLModelElementCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLModelElementCamera.cpp; sourceTree = "<group>"; };
+		7177AD5927429CCB002F103B /* JSHTMLModelElementCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLModelElementCamera.h; sourceTree = "<group>"; };
 		7177E2461DB80D2F00919A0B /* media-controller-support.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = "media-controller-support.js"; sourceTree = "<group>"; };
 		7177E2471DB80D2F00919A0B /* mute-support.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = "mute-support.js"; sourceTree = "<group>"; };
 		7177E2481DB80D2F00919A0B /* start-support.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = "start-support.js"; sourceTree = "<group>"; };
@@ -23807,6 +23812,8 @@
 				71A3D1802562B8250064E2A6 /* HTMLModelElement.cpp */,
 				71A3D17D2562B8240064E2A6 /* HTMLModelElement.h */,
 				71A3D17F2562B8240064E2A6 /* HTMLModelElement.idl */,
+				7177AD5627429590002F103B /* HTMLModelElementCamera.h */,
+				7177AD542742952F002F103B /* HTMLModelElementCamera.idl */,
 				BC2B41142732F06200A2D191 /* ModelPlayer.cpp */,
 				BC2B41132732F06200A2D191 /* ModelPlayer.h */,
 				BC2B41122732F03C00A2D191 /* ModelPlayerClient.cpp */,
@@ -26085,6 +26092,8 @@
 				A7BBE26511AFB3F20005EA03 /* JSHTMLMeterElement.h */,
 				71A3D1822562BDDB0064E2A6 /* JSHTMLModelElement.cpp */,
 				71A3D1832562BDDB0064E2A6 /* JSHTMLModelElement.h */,
+				7177AD5827429CCA002F103B /* JSHTMLModelElementCamera.cpp */,
+				7177AD5927429CCB002F103B /* JSHTMLModelElementCamera.h */,
 				1AE2AB1F0A1CE63B00B42B25 /* JSHTMLModElement.cpp */,
 				1AE2AB200A1CE63B00B42B25 /* JSHTMLModElement.h */,
 				BC305C770C076BB300CD20F0 /* JSHTMLObjectElement.cpp */,
@@ -33718,6 +33727,7 @@
 				A871DC240A15205700B12A68 /* HTMLMetaElement.h in Headers */,
 				A454424B119B3661009BE912 /* HTMLMeterElement.h in Headers */,
 				71A3D1812562B85B0064E2A6 /* HTMLModelElement.h in Headers */,
+				7177AD57274295D1002F103B /* HTMLModelElementCamera.h in Headers */,
 				A8CFF7A70A156978000A4234 /* HTMLModElement.h in Headers */,
 				A8DF3FD4097FA0FC0052981B /* HTMLNameCollection.h in Headers */,
 				A871D45A0A127CBC00B12A68 /* HTMLObjectElement.h in Headers */,

Modified: trunk/Source/WebCore/loader/EmptyClients.cpp (286018 => 286019)


--- trunk/Source/WebCore/loader/EmptyClients.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/loader/EmptyClients.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -583,12 +583,6 @@
 {
 }
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-void EmptyChromeClient::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID) const
-{
-}
-#endif
-
 void EmptyFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const NavigationAction&, const ResourceRequest&, FormState*, const String&, PolicyCheckIdentifier, FramePolicyFunction&&)
 {
 }

Modified: trunk/Source/WebCore/loader/EmptyClients.h (286018 => 286019)


--- trunk/Source/WebCore/loader/EmptyClients.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/loader/EmptyClients.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -217,10 +217,6 @@
     void didAssociateFormControls(const Vector<RefPtr<Element>>&, Frame&) final { }
     bool shouldNotifyOnFormChanges() final { return false; }
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID) const final;
-#endif
-
     RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) final { return nullptr; }
 };
 

Modified: trunk/Source/WebCore/page/ChromeClient.h (286018 => 286019)


--- trunk/Source/WebCore/page/ChromeClient.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebCore/page/ChromeClient.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -605,10 +605,6 @@
     virtual void textAutosizingUsesIdempotentModeChanged() { }
 #endif
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    virtual void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID) const { }
-#endif
-
 #if ENABLE(APPLE_PAY_AMS_UI)
     virtual void startApplePayAMSUISession(const URL&, const ApplePayAMSUIRequest&, CompletionHandler<void(std::optional<bool>&&)>&& completionHandler) { completionHandler(std::nullopt); }
     virtual void abortApplePayAMSUISession() { }

Modified: trunk/Source/WebKit/ChangeLog (286018 => 286019)


--- trunk/Source/WebKit/ChangeLog	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/ChangeLog	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1,3 +1,62 @@
+2021-11-18  Antoine Quint  <[email protected]>
+
+        [Model] add support for getting and setting the camera
+        https://bugs.webkit.org/show_bug.cgi?id=233265
+        <rdar://problem/85426290>
+
+        Reviewed by Darin Adler.
+
+        The ARQL APIs we'd adopted so far were specific to either macOS or iOS. The new camera
+        methods are different since they exist on both platforms.
+
+        In order to expose a single message for both platforms, we introduce a new ModelIdentifier
+        struct which wraps the UUID string for macOS and the layer identifier for iOS. Then on
+        ModelElementController, we have the previewForModelIdentifier() method to get the matching
+        ASVInlinePreview for the provided ModelIdentifier.
+
+        This allows getCameraForModelElement() and setCameraForModelElement to be specified for both
+        iOS and macOS with a single implementation.
+
+        We also modify takeModelElementFullscreen() to take advantage of ModelIdentifier which showed
+        that we had some lingering code in ChromeClient related to this method that was no longer
+        necessary following r285922.
+
+        * Shared/ModelIdentifier.h: Copied from Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h.
+        (WebKit::ModelIdentifier::encode const):
+        (WebKit::ModelIdentifier::decode):
+        * UIProcess/Cocoa/ModelElementControllerCocoa.mm:
+        (WebKit::ModelElementController::modelViewForModelIdentifier):
+        (WebKit::ModelElementController::previewForModelIdentifier):
+        (WebKit::ModelElementController::takeModelElementFullscreen):
+        (WebKit::previewHasCameraSupport):
+        (WebKit::ModelElementController::getCameraForModelElement):
+        (WebKit::ModelElementController::setCameraForModelElement):
+        * UIProcess/ModelElementController.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::modelElementGetCamera):
+        (WebKit::WebPageProxy::modelElementSetCamera):
+        (WebKit::WebPageProxy::takeModelElementFullscreen):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Model/ARKitInlinePreviewModelPlayer.h:
+        * WebProcess/Model/ARKitInlinePreviewModelPlayer.mm:
+        (WebKit::ARKitInlinePreviewModelPlayer::getCamera):
+        (WebKit::ARKitInlinePreviewModelPlayer::setCamera):
+        * WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h:
+        * WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm:
+        (WebKit::ARKitInlinePreviewModelPlayerIOS::modelIdentifier):
+        (WebKit::ARKitInlinePreviewModelPlayerIOS::enterFullscreen):
+        * WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h:
+        * WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm:
+        (WebKit::ARKitInlinePreviewModelPlayerMac::modelIdentifier):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::takeModelElementFullscreen const): Deleted.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::takeModelElementFullscreen): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+
 2021-11-18  Chris Dumez  <[email protected]>
 
         Drop ServiceWorkerClientIdentifier / DocumentIdentifier and use ScriptExecutionContextIdentifier instead

Copied: trunk/Source/WebKit/Shared/ModelIdentifier.h (from rev 286018, trunk/Source/WebCore/Modules/model-element/scenekit/SceneKitModelPlayer.h) (0 => 286019)


--- trunk/Source/WebKit/Shared/ModelIdentifier.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/ModelIdentifier.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebKit {
+
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+
+#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+#import <WebCore/GraphicsLayer.h>
+#endif
+
+struct ModelIdentifier {
+#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
+    String uuid;
+#elif ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+    WebCore::GraphicsLayer::PlatformLayerID layerIdentifier;
+#endif
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<ModelIdentifier> decode(Decoder&);
+};
+
+template<class Encoder> void ModelIdentifier::encode(Encoder& encoder) const
+{
+#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
+    encoder << uuid;
+#elif ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+    encoder << layerIdentifier;
+#endif
+}
+
+template<class Decoder> std::optional<ModelIdentifier> ModelIdentifier::decode(Decoder& decoder)
+{
+#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
+    std::optional<String> uuid;
+    decoder >> uuid;
+    if (!uuid)
+        return std::nullopt;
+    return { { WTFMove(*uuid) } };
+#elif ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+    std::optional<WebCore::GraphicsLayer::PlatformLayerID> layerIdentifier;
+    decoder >> layerIdentifier;
+    if (!layerIdentifier)
+        return std::nullopt;
+    return { { *layerIdentifier } };
+#endif
+}
+
+#endif
+
+} // namespace WebKit
+

Modified: trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm (286018 => 286019)


--- trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2021-11-18 19:38:01 UTC (rev 286019)
@@ -30,6 +30,12 @@
 
 #import "Logging.h"
 #import "WebPageProxy.h"
+#import <WebCore/LayoutPoint.h>
+#import <WebCore/LayoutUnit.h>
+#import <WebCore/ResourceError.h>
+#import <simd/simd.h>
+#import <wtf/MainThread.h>
+#import <wtf/MonotonicTime.h>
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
 #import "APIUIClient.h"
@@ -42,12 +48,7 @@
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
-#import <WebCore/LayoutPoint.h>
-#import <WebCore/LayoutUnit.h>
-#import <WebCore/ResourceError.h>
 #import <pal/spi/mac/SystemPreviewSPI.h>
-#import <wtf/MainThread.h>
-#import <wtf/MonotonicTime.h>
 #endif
 
 SOFT_LINK_PRIVATE_FRAMEWORK(AssetViewer);
@@ -57,30 +58,36 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
 
-void ModelElementController::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
+WKModelView * ModelElementController::modelViewForModelIdentifier(ModelIdentifier modelIdentifier)
 {
     if (!m_webPageProxy.preferences().modelElementEnabled())
-        return;
+        return nil;
 
     if (!is<RemoteLayerTreeDrawingAreaProxy>(m_webPageProxy.drawingArea()))
-        return;
+        return nil;
 
-    auto* node = downcast<RemoteLayerTreeDrawingAreaProxy>(*m_webPageProxy.drawingArea()).remoteLayerTreeHost().nodeForID(contentLayerId);
+    auto* node = downcast<RemoteLayerTreeDrawingAreaProxy>(*m_webPageProxy.drawingArea()).remoteLayerTreeHost().nodeForID(modelIdentifier.layerIdentifier);
     if (!node)
-        return;
+        return nil;
 
-    auto *view = node->uiView();
-    if (!view)
-        return;
+    return dynamic_objc_cast<WKModelView>(node->uiView());
+}
 
-    if (![view isKindOfClass:[WKModelView class]])
-        return;
+ASVInlinePreview * ModelElementController::previewForModelIdentifier(ModelIdentifier modelIdentifier)
+{
+    return [modelViewForModelIdentifier(modelIdentifier) preview];
+}
 
+void ModelElementController::takeModelElementFullscreen(ModelIdentifier modelIdentifier)
+{
     auto *presentingViewController = m_webPageProxy.uiClient().presentingViewController();
     if (!presentingViewController)
         return;
 
-    WKModelView *modelView = (WKModelView *)view;
+    auto modelView = modelViewForModelIdentifier(modelIdentifier);
+    if (!modelView)
+        return;
+
     CGRect initialFrame = [modelView convertRect:modelView.frame toView:nil];
 
     ASVInlinePreview *preview = [modelView preview];
@@ -98,7 +105,7 @@
 
             [presentingViewController presentViewController:remoteViewController animated:NO completion:^(void) {
                 [CATransaction begin];
-                [view.layer.superlayer.context addFence:fenceHandle];
+                [modelView.layer.superlayer.context addFence:fenceHandle];
                 [CATransaction commit];
                 [fenceHandle invalidate];
             }];
@@ -112,7 +119,7 @@
                     }
 
                     [CATransaction begin];
-                    [view.layer.superlayer.context addFence:dismissFenceHandle];
+                    [modelView.layer.superlayer.context addFence:dismissFenceHandle];
                     [CATransaction setCompletionBlock:^{
                         [remoteViewController dismissViewControllerAnimated:NO completion:nil];
                     }];
@@ -128,6 +135,14 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 
+ASVInlinePreview * ModelElementController::previewForModelIdentifier(ModelIdentifier modelIdentifier)
+{
+    if (!m_webPageProxy.preferences().modelElementEnabled())
+        return nullptr;
+
+    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)
 {
     if (!m_webPageProxy.preferences().modelElementEnabled()) {
@@ -150,7 +165,7 @@
     auto url = "" alloc] initFileURLWithPath:fileURL.fileSystemPath()]);
 
     RELEASE_ASSERT(isMainRunLoop());
-    [preview setupRemoteConnectionWithCompletionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, preview, uuid = WTFMove(uuid), url = "" completionHandler = WTFMove(completionHandler)] (NSError * _Nullable contextError) mutable {
+    [preview setupRemoteConnectionWithCompletionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, preview, uuid = WTFMove(uuid), url = "" completionHandler = WTFMove(completionHandler)] (NSError *contextError) mutable {
         if (contextError) {
             LOG(ModelElement, "Unable to create remote connection for uuid %s: %@.", uuid.utf8().data(), contextError.localizedDescription);
 
@@ -165,7 +180,7 @@
 
         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 = "" completionHandler = WTFMove(completionHandler)] (NSError * _Nullable loadError) mutable {
+        [preview preparePreviewOfFileAtURL:url.get() completionHandler:makeBlockPtr([weakThis = WTFMove(weakThis), preview, uuid = WTFMove(uuid), url = "" completionHandler = WTFMove(completionHandler)] (NSError *loadError) mutable {
             if (loadError) {
                 LOG(ModelElement, "Unable to load file for uuid %s: %@.", uuid.utf8().data(), loadError.localizedDescription);
 
@@ -216,6 +231,65 @@
 
 #endif
 
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+
+static bool previewHasCameraSupport(ASVInlinePreview *preview)
+{
+#if ENABLE(ARKIT_INLINE_PREVIEW_CAMERA_TRANSFORM)
+    return [preview respondsToSelector:@selector(getCameraTransform:)];
+#else
+    return false;
+#endif
 }
 
+void ModelElementController::getCameraForModelElement(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&& completionHandler)
+{
+    auto* preview = previewForModelIdentifier(modelIdentifier);
+    if (!preview || !previewHasCameraSupport(preview)) {
+        callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler), error = WebCore::ResourceError { WebCore::ResourceError::Type::General }] () mutable {
+            if (weakThis)
+                completionHandler(makeUnexpected(error));
+        });
+        return;
+    }
+
+    [preview getCameraTransform:makeBlockPtr([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] (simd_float3 cameraTransform, NSError *error) mutable {
+        if (error) {
+            callOnMainRunLoop([weakThis = WTFMove(weakThis), completionHandler = WTFMove(completionHandler), error = WebCore::ResourceError { WebCore::ResourceError::Type::General }] () mutable {
+                if (weakThis)
+                    completionHandler(makeUnexpected(error));
+            });
+            return;
+        }
+
+        callOnMainRunLoop([cameraTransform, weakThis = WTFMove(weakThis), completionHandler = WTFMove(completionHandler)] () mutable {
+            if (weakThis)
+                completionHandler(WebCore::HTMLModelElementCamera { cameraTransform.x, cameraTransform.y, cameraTransform.z });
+        });
+    }).get()];
+}
+
+void ModelElementController::setCameraForModelElement(ModelIdentifier modelIdentifier, WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool)>&& completionHandler)
+{
+    auto* preview = previewForModelIdentifier(modelIdentifier);
+    if (!preview || !previewHasCameraSupport(preview)) {
+        callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
+            if (weakThis)
+                completionHandler(false);
+        });
+        return;
+    }
+
+    [preview setCameraTransform:simd_make_float3(camera.pitch, camera.yaw, camera.scale)];
+
+    callOnMainRunLoop([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
+        if (weakThis)
+            completionHandler(true);
+    });
+}
+
 #endif
+
+}
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/ModelElementController.h (286018 => 286019)


--- trunk/Source/WebKit/UIProcess/ModelElementController.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/UIProcess/ModelElementController.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -27,6 +27,7 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
 
+#include "ModelIdentifier.h"
 #include <WebCore/ElementContext.h>
 #include <WebCore/GraphicsLayer.h>
 #include <wtf/RetainPtr.h>
@@ -33,8 +34,10 @@
 #include <wtf/URL.h>
 #include <wtf/WeakPtr.h>
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 OBJC_CLASS ASVInlinePreview;
+
+#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+OBJC_CLASS WKModelView;
 #endif
 
 namespace WebKit {
@@ -48,8 +51,12 @@
 
     WebPageProxy& page() { return m_webPageProxy; }
 
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+    void getCameraForModelElement(ModelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&&);
+    void setCameraForModelElement(ModelIdentifier, WebCore::HTMLModelElementCamera, CompletionHandler<void(bool)>&&);
+#endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
+    void takeModelElementFullscreen(ModelIdentifier);
 #endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
     void modelElementDidCreatePreview(URL, String, WebCore::FloatSize, CompletionHandler<void(Expected<std::pair<String, uint32_t>, WebCore::ResourceError>)>&&);
@@ -59,6 +66,14 @@
 #endif
 
 private:
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+    ASVInlinePreview * previewForModelIdentifier(ModelIdentifier);
+#endif
+
+#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+    WKModelView * modelViewForModelIdentifier(ModelIdentifier);
+#endif
+
     WebPageProxy& m_webPageProxy;
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
     RetainPtr<ASVInlinePreview> previewForUUID(const String&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286018 => 286019)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -10832,10 +10832,22 @@
 
 #endif
 
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+void WebPageProxy::modelElementGetCamera(ModelIdentifier modelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&& completionHandler)
+{
+    modelElementController()->getCameraForModelElement(modelIdentifier, WTFMove(completionHandler));
+}
+
+void WebPageProxy::modelElementSetCamera(ModelIdentifier modelIdentifier, WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool)>&& completionHandler)
+{
+    modelElementController()->setCameraForModelElement(modelIdentifier, camera, WTFMove(completionHandler));
+}
+#endif
+
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-void WebPageProxy::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
+void WebPageProxy::takeModelElementFullscreen(ModelIdentifier modelIdentifier)
 {
-    modelElementController()->takeModelElementFullscreen(contentLayerId);
+    modelElementController()->takeModelElementFullscreen(modelIdentifier);
 }
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (286018 => 286019)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -196,6 +196,7 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
 #include "ModelElementController.h"
+#include "ModelIdentifier.h"
 #endif
 
 namespace API {
@@ -587,9 +588,11 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
     ModelElementController* modelElementController() { return m_modelElementController.get(); }
+    void modelElementGetCamera(ModelIdentifier, CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)>&&);
+    void modelElementSetCamera(ModelIdentifier, WebCore::HTMLModelElementCamera, CompletionHandler<void(bool)>&&);
 #endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
+    void takeModelElementFullscreen(ModelIdentifier);
 #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>)>&&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (286018 => 286019)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-11-18 19:38:01 UTC (rev 286019)
@@ -586,7 +586,7 @@
 #endif
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    TakeModelElementFullscreen(uint64_t contentLayerID)
+    TakeModelElementFullscreen(struct WebKit::ModelIdentifier modelIdentifier)
 #endif
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
     ModelElementDidCreatePreview(URL url, String uuid, WebCore::FloatSize size) -> (Expected<std::pair<String, uint32_t>, WebCore::ResourceError> result) Async
@@ -594,6 +594,10 @@
     HandleMouseMoveForModelElement(String uuid, WebCore::LayoutPoint locationInPageCoordinates, MonotonicTime timestamp)
     HandleMouseUpForModelElement(String uuid, WebCore::LayoutPoint locationInPageCoordinates, MonotonicTime timestamp)
 #endif
+#if ENABLE(ARKIT_INLINE_PREVIEW)
+    ModelElementGetCamera(struct WebKit::ModelIdentifier modelIdentifier) -> (Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError> result) Async
+    ModelElementSetCamera(struct WebKit::ModelIdentifier modelIdentifier, struct WebCore::HTMLModelElementCamera camera) -> (bool success) Async
+#endif
 
     requestPermission(struct WebCore::ClientOrigin origin, struct WebCore::PermissionDescriptor descriptor) -> (enum:uint8_t WebCore::PermissionState state) Async
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (286018 => 286019)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-11-18 19:38:01 UTC (rev 286019)
@@ -4708,6 +4708,7 @@
 		71A676A522C62318007D6295 /* WKTouchActionGestureRecognizer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKTouchActionGestureRecognizer.mm; path = ios/WKTouchActionGestureRecognizer.mm; sourceTree = "<group>"; };
 		71BAA73125FFCCBA00D7CD5D /* WKModelView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKModelView.h; path = ios/WKModelView.h; sourceTree = "<group>"; };
 		71BAA73225FFCCBA00D7CD5D /* WKModelView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKModelView.mm; path = ios/WKModelView.mm; sourceTree = "<group>"; };
+		71E9650F2745682E00ADCF43 /* ModelIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ModelIdentifier.h; sourceTree = "<group>"; };
 		71FB810A2260627A00323677 /* WebsiteSimulatedMouseEventsDispatchPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteSimulatedMouseEventsDispatchPolicy.h; sourceTree = "<group>"; };
 		7203449A26A6C44C000A5F54 /* MonotonicObjectIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MonotonicObjectIdentifier.h; sourceTree = "<group>"; };
 		7203449B26A6C476000A5F54 /* RenderingUpdateID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderingUpdateID.h; sourceTree = "<group>"; };
@@ -6834,6 +6835,7 @@
 				2D10875E1D2C573E00B85F82 /* LoadParameters.cpp */,
 				2D10875F1D2C573E00B85F82 /* LoadParameters.h */,
 				49917DB0252E30750050313F /* MediaPlaybackState.h */,
+				71E9650F2745682E00ADCF43 /* ModelIdentifier.h */,
 				7203449A26A6C44C000A5F54 /* MonotonicObjectIdentifier.h */,
 				2D50366A1BCDE17900E20BB3 /* NativeWebGestureEvent.h */,
 				C02BFF1512514FD8009CCBEA /* NativeWebKeyboardEvent.h */,

Modified: trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -27,9 +27,12 @@
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
 
-#include <WebCore/ModelPlayer.h>
-#include <WebCore/ModelPlayerClient.h>
-#include <wtf/Compiler.h>
+#import "ModelIdentifier.h"
+#import "WebPage.h"
+#import "WebPageProxyMessages.h"
+#import <WebCore/ModelPlayer.h>
+#import <WebCore/ModelPlayerClient.h>
+#import <wtf/Compiler.h>
 
 namespace WebKit {
 
@@ -43,11 +46,15 @@
     WebPage* page() { return m_page.get(); }
     WebCore::ModelPlayerClient* client() { return m_client.get(); }
 
+    virtual std::optional<ModelIdentifier> modelIdentifier() = 0;
+
 private:
     // WebCore::ModelPlayer overrides.
     void load(WebCore::Model&, WebCore::LayoutSize) override;
     PlatformLayer* layer() override;
     void enterFullscreen() override;
+    void getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&&) override;
+    void setCamera(WebCore::HTMLModelElementCamera, CompletionHandler<void(bool&&)>&&) override;
 
     WeakPtr<WebPage> m_page;
     WeakPtr<WebCore::ModelPlayerClient> m_client;

Modified: trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/ARKitInlinePreviewModelPlayer.mm	2021-11-18 19:38:01 UTC (rev 286019)
@@ -55,6 +55,53 @@
 {
 }
 
+void ARKitInlinePreviewModelPlayer::getCamera(CompletionHandler<void(std::optional<WebCore::HTMLModelElementCamera>&&)>&& completionHandler)
+{
+    auto modelIdentifier = this->modelIdentifier();
+    if (!modelIdentifier) {
+        completionHandler(std::nullopt);
+        return;
+    }
+
+    auto* strongPage = m_page.get();
+    if (!strongPage) {
+        completionHandler(std::nullopt);
+        return;
+    }
+
+    CompletionHandler<void(Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError>)> remoteCompletionHandler = [completionHandler = WTFMove(completionHandler)] (Expected<WebCore::HTMLModelElementCamera, WebCore::ResourceError> result) mutable {
+        if (!result) {
+            completionHandler(std::nullopt);
+            return;
+        }
+
+        completionHandler(*result);
+    };
+
+    strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementGetCamera(*modelIdentifier), WTFMove(remoteCompletionHandler));
 }
 
+void ARKitInlinePreviewModelPlayer::setCamera(WebCore::HTMLModelElementCamera camera, CompletionHandler<void(bool&&)>&& completionHandler)
+{
+    auto modelIdentifier = this->modelIdentifier();
+    if (!modelIdentifier) {
+        completionHandler(false);
+        return;
+    }
+
+    auto* strongPage = m_page.get();
+    if (!strongPage) {
+        completionHandler(false);
+        return;
+    }
+
+    CompletionHandler<void(bool)> remoteCompletionHandler = [completionHandler = WTFMove(completionHandler)] (bool success) mutable {
+        completionHandler(WTFMove(success));
+    };
+
+    strongPage->sendWithAsyncReply(Messages::WebPageProxy::ModelElementSetCamera(*modelIdentifier, camera), WTFMove(remoteCompletionHandler));
+}
+
+}
+
 #endif

Modified: trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -41,6 +41,8 @@
 private:
     ARKitInlinePreviewModelPlayerIOS(WebPage&, WebCore::ModelPlayerClient&);
 
+    std::optional<ModelIdentifier> modelIdentifier() override;
+
     // WebCore::ModelPlayer overrides.
     void enterFullscreen() override;
     void handleMouseDown(const WebCore::LayoutPoint&, MonotonicTime) override;

Modified: trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/ios/ARKitInlinePreviewModelPlayerIOS.mm	2021-11-18 19:38:01 UTC (rev 286019)
@@ -48,15 +48,27 @@
 {
 }
 
+std::optional<ModelIdentifier> ARKitInlinePreviewModelPlayerIOS::modelIdentifier()
+{
+    if (!client())
+        return { };
+
+    if (auto layerId = client()->platformLayerID())
+        return { { layerId } };
+
+    return { };
+}
+
 // MARK: - WebCore::ModelPlayer overrides.
 
 void ARKitInlinePreviewModelPlayerIOS::enterFullscreen()
 {
-    if (!client() || !page())
+    auto* strongPage = page();
+    if (!strongPage)
         return;
 
-    if (auto layerId = client()->platformLayerID())
-        page()->takeModelElementFullscreen(layerId);
+    if (auto modelIdentifier = this->modelIdentifier())
+        strongPage->send(Messages::WebPageProxy::TakeModelElementFullscreen(*modelIdentifier));
 }
 
 void ARKitInlinePreviewModelPlayerIOS::handleMouseDown(const WebCore::LayoutPoint&, MonotonicTime)

Modified: trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -47,6 +47,8 @@
 private:
     ARKitInlinePreviewModelPlayerMac(WebPage&, WebCore::ModelPlayerClient&);
 
+    std::optional<ModelIdentifier> modelIdentifier() override;
+
     // WebCore::ModelPlayer overrides.
     void load(WebCore::Model&, WebCore::LayoutSize) override;
     PlatformLayer* layer() override;

Modified: trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/Model/mac/ARKitInlinePreviewModelPlayerMac.mm	2021-11-18 19:38:01 UTC (rev 286019)
@@ -55,6 +55,13 @@
     clearFile();
 }
 
+std::optional<ModelIdentifier> ARKitInlinePreviewModelPlayerMac::modelIdentifier()
+{
+    if (m_inlinePreview)
+        return { { [m_inlinePreview uuid].UUIDString } };
+    return { };
+}
+
 static String& sharedModelElementCacheDirectory()
 {
     static NeverDestroyed<String> sharedModelElementCacheDirectory;

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1524,13 +1524,6 @@
 }
 #endif
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-void WebChromeClient::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId) const
-{
-    m_page.takeModelElementFullscreen(contentLayerId);
-}
-#endif
-
 #if ENABLE(APPLE_PAY_AMS_UI)
 
 void WebChromeClient::startApplePayAMSUISession(const URL& originatingURL, const ApplePayAMSUIRequest& request, CompletionHandler<void(std::optional<bool>&&)>&& completionHandler)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -455,10 +455,6 @@
     void enumerateImmersiveXRDevices(CompletionHandler<void(const PlatformXR::Instance::DeviceList&)>&&) final;
 #endif
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId) const final;
-#endif
-
 #if ENABLE(APPLE_PAY_AMS_UI)
     void startApplePayAMSUISession(const URL&, const WebCore::ApplePayAMSUIRequest&, CompletionHandler<void(std::optional<bool>&&)>&&) final;
     void abortApplePayAMSUISession() final;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-11-18 19:38:01 UTC (rev 286019)
@@ -7789,13 +7789,6 @@
 }
 #endif
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-void WebPage::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
-{
-    send(Messages::WebPageProxy::TakeModelElementFullscreen(contentLayerId));
-}
-#endif
-
 void WebPage::scrollToRect(const WebCore::FloatRect& targetRect, const WebCore::FloatPoint& origin)
 {
     mainFrameView()->setScrollPosition(IntPoint(targetRect.minXMinYCorner()));

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (286018 => 286019)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-11-18 19:30:52 UTC (rev 286018)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-11-18 19:38:01 UTC (rev 286019)
@@ -1490,10 +1490,6 @@
     PlatformXRSystemProxy& xrSystemProxy();
 #endif
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
-#endif
-
     void prepareToRunModalJavaScriptDialog();
 
 #if USE(ATSPI)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to