Changeset 279451 in webkit


Ignore:
Timestamp:
Jun 30, 2021 11:32:12 PM (13 months ago)
Author:
graouts@webkit.org
Message:

[Model] [macOS] Add support for rendering model resources
https://bugs.webkit.org/show_bug.cgi?id=227530
<rdar://problem/79968206>

Reviewed by Dean Jackson.

Source/WebCore:

On macOS, ASVInlinePreview requires an instance in both the WebProcess and the UIProcess to exist with a matching UUID.

On the WebCore side, in the WebProcess, after writing the model resource as a file to disk, we create an instance when a
<model> element is created and message the UIProcess through the ChromeClient providing the UUID generated for it. When
the UIProcess is done processing this message, it will reply with another message which calls into
HTMLModelElement::inlinePreviewDidObtainContextId() with the matching UUID and a context ID for the remote context.
We can then set that remote context ID on our ASVInlinePreview instance.

We also introduce a HTMLModelElement::platformLayer() method such that RenderLayerBacking::updateConfiguration() can call
it to host the ASVInlinePreview layer.

  • Modules/model-element/HTMLModelElement.cpp:

(WebCore::HTMLModelElement::~HTMLModelElement):
(WebCore::HTMLModelElement::setSourceURL):
(WebCore::HTMLModelElement::notifyFinished):

  • Modules/model-element/HTMLModelElement.h:
  • Modules/model-element/HTMLModelElementCocoa.mm: Added.

(WebCore::HTMLModelElement::createFile):
(WebCore::HTMLModelElement::clearFile):
(WebCore::HTMLModelElement::modelDidChange):
(WebCore::HTMLModelElement::inlinePreviewDidObtainContextId):
(WebCore::HTMLModelElement::platformLayer const):

  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • loader/EmptyClients.cpp:

(WebCore::EmptyChromeClient::modelElementDidCreatePreview const):

  • loader/EmptyClients.h:
  • page/ChromeClient.h:

(WebCore::ChromeClient::modelElementDidCreatePreview const):

  • platform/Logging.h:
  • rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::updateConfiguration):

Source/WebCore/PAL:

Declare the ASVInlinePreview class for macOS.

  • PAL.xcodeproj/project.pbxproj:
  • pal/spi/mac/SystemPreviewSPI.h: Added.

Source/WebKit:

On macOS, ASVInlinePreview requires an instance in both the WebProcess and the UIProcess to exist with a matching UUID.

On the WebKit side, in the UIProcess, we receive a message from the WebProcess when the ASVInlinePreview in that process
was created with its generated UUID. We provide this to the ModelElementController, set the remote connection up and load
the file. When those tasks complete successfully we message back the WebProcess with the UUID and the provided ElementContext
to talk back to the HTMLModelElement instance that initiated the message to the UIProcess in the first place.

  • UIProcess/Cocoa/ModelElementControllerCocoa.mm:

(WebKit::ModelElementController::modelElementDidCreatePreview):

  • UIProcess/ModelElementController.h:
  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::modelElementDidCreatePreview):
(WebKit::WebPageProxy::modelElementPreviewDidObtainContextId):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::modelElementDidCreatePreview const):

  • WebProcess/WebCoreSupport/WebChromeClient.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::modelElementDidCreatePreview):
(WebKit::WebPage::modelElementPreviewDidObtainContextId):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:

Source/WTF:

Add a new compile-time flag indicating the availability of the ASVInlinePreview SPI on macOS.
We only define it when the header itself is present for now to avoid issues with older macOS
12 SDKs, but ultimately we will only use the macOS version check.

  • wtf/PlatformHave.h:
Location:
trunk/Source
Files:
1 added
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r279444 r279451  
     12021-06-30  Antoine Quint  <graouts@webkit.org>
     2
     3        [Model] [macOS] Add support for rendering model resources
     4        https://bugs.webkit.org/show_bug.cgi?id=227530
     5        <rdar://problem/79968206>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add a new compile-time flag indicating the availability of the ASVInlinePreview SPI on macOS.
     10        We only define it when the header itself is present for now to avoid issues with older macOS
     11        12 SDKs, but ultimately we will only use the macOS version check.
     12
     13        * wtf/PlatformHave.h:
     14
    1152021-06-30  Megan Gardner  <megan_gardner@apple.com>
    216
  • trunk/Source/WTF/wtf/PlatformHave.h

    r279407 r279451  
    10151015#define HAVE_ARKIT_INLINE_PREVIEW_IOS 1
    10161016#endif
     1017
     1018#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000
     1019#define HAVE_ARKIT_INLINE_PREVIEW_MAC 1
     1020#endif
    10171021#endif
    10181022
  • trunk/Source/WebCore/ChangeLog

    r279444 r279451  
     12021-06-30  Antoine Quint  <graouts@webkit.org>
     2
     3        [Model] [macOS] Add support for rendering model resources
     4        https://bugs.webkit.org/show_bug.cgi?id=227530
     5        <rdar://problem/79968206>
     6
     7        Reviewed by Dean Jackson.
     8
     9        On macOS, ASVInlinePreview requires an instance in both the WebProcess and the UIProcess to exist with a matching UUID.
     10
     11        On the WebCore side, in the WebProcess, after writing the model resource as a file to disk, we create an instance when a
     12        <model> element is created and message the UIProcess through the ChromeClient providing the UUID generated for it. When
     13        the UIProcess is done processing this message, it will reply with another message which calls into
     14        HTMLModelElement::inlinePreviewDidObtainContextId() with the matching UUID and a context ID for the remote context.
     15        We can then set that remote context ID on our ASVInlinePreview instance.
     16
     17        We also introduce a HTMLModelElement::platformLayer() method such that RenderLayerBacking::updateConfiguration() can call
     18        it to host the ASVInlinePreview layer.
     19
     20        * Modules/model-element/HTMLModelElement.cpp:
     21        (WebCore::HTMLModelElement::~HTMLModelElement):
     22        (WebCore::HTMLModelElement::setSourceURL):
     23        (WebCore::HTMLModelElement::notifyFinished):
     24        * Modules/model-element/HTMLModelElement.h:
     25        * Modules/model-element/HTMLModelElementCocoa.mm: Added.
     26        (WebCore::HTMLModelElement::createFile):
     27        (WebCore::HTMLModelElement::clearFile):
     28        (WebCore::HTMLModelElement::modelDidChange):
     29        (WebCore::HTMLModelElement::inlinePreviewDidObtainContextId):
     30        (WebCore::HTMLModelElement::platformLayer const):
     31        * SourcesCocoa.txt:
     32        * WebCore.xcodeproj/project.pbxproj:
     33        * loader/EmptyClients.cpp:
     34        (WebCore::EmptyChromeClient::modelElementDidCreatePreview const):
     35        * loader/EmptyClients.h:
     36        * page/ChromeClient.h:
     37        (WebCore::ChromeClient::modelElementDidCreatePreview const):
     38        * platform/Logging.h:
     39        * rendering/RenderLayerBacking.cpp:
     40        (WebCore::RenderLayerBacking::updateConfiguration):
     41
    1422021-06-30  Megan Gardner  <megan_gardner@apple.com>
    243
  • trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp

    r279420 r279451  
    7070        m_resource = nullptr;
    7171    }
     72
     73#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     74    clearFile();
     75#endif
    7276}
    7377
     
    132136    m_readyPromise = makeUniqueRef<ReadyPromise>(*this, &HTMLModelElement::readyPromiseResolve);
    133137
    134     if (m_sourceURL.isEmpty())
    135         return;
     138    if (m_sourceURL.isEmpty()) {
     139#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     140        clearFile();
     141#endif
     142        return;
     143    }
    136144
    137145    ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
     
    225233
    226234    m_readyPromise->resolve(*this);
     235
     236#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     237    modelDidChange();
     238#endif
    227239}
    228240
  • trunk/Source/WebCore/Modules/model-element/HTMLModelElement.h

    r279420 r279451  
    3636#include <wtf/UniqueRef.h>
    3737
     38#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     39#include "PlatformLayer.h"
     40OBJC_CLASS ASVInlinePreview;
     41#endif
     42
    3843namespace WebCore {
    3944
     
    6065    WEBCORE_EXPORT static const String& modelElementCacheDirectory();
    6166
     67#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     68    PlatformLayer* platformLayer() const;
     69    WEBCORE_EXPORT void inlinePreviewDidObtainContextId(const String& uuid, uint32_t contextId);
     70#endif
     71
    6272    void enterFullscreen();
    6373
     
    6777    void setSourceURL(const URL&);
    6878    HTMLModelElement& readyPromiseResolve();
     79
     80#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     81    void clearFile();
     82    void createFile();
     83    void modelDidChange();
     84#endif
    6985
    7086    // DOM overrides.
     
    84100    UniqueRef<ReadyPromise> m_readyPromise;
    85101    bool m_dataComplete { false };
     102
     103#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     104    String m_filePath;
     105    RetainPtr<ASVInlinePreview> m_inlinePreview;
     106#endif
    86107};
    87108
  • trunk/Source/WebCore/PAL/ChangeLog

    r279420 r279451  
     12021-06-30  Antoine Quint  <graouts@webkit.org>
     2
     3        [Model] [macOS] Add support for rendering model resources
     4        https://bugs.webkit.org/show_bug.cgi?id=227530
     5        <rdar://problem/79968206>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Declare the ASVInlinePreview class for macOS.
     10
     11        * PAL.xcodeproj/project.pbxproj:
     12        * pal/spi/mac/SystemPreviewSPI.h: Added.
     13
    1142021-06-30  Antoine Quint  <graouts@webkit.org>
    215
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r279030 r279451  
    149149                5C7C787623AC3E850065F47E /* ManagedConfigurationSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C7C787523AC3E850065F47E /* ManagedConfigurationSPI.h */; };
    150150                63C7EDC721AFAE04006A7B99 /* NSProgressSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 63E369F921AFA83F001C14BC /* NSProgressSPI.h */; };
     151                71B1142026823ACD004D6701 /* SystemPreviewSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 71B1141F26823ACD004D6701 /* SystemPreviewSPI.h */; };
    151152                72E5BE972679A80A00ADBFA9 /* VideoToolboxSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 72E5BE962679A80900ADBFA9 /* VideoToolboxSPI.h */; };
    152153                7A36D0F9223AD9AB00B0522E /* CommonCryptoSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A36D0F8223AD9AB00B0522E /* CommonCryptoSPI.h */; };
     
    368369                5C7C787523AC3E850065F47E /* ManagedConfigurationSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ManagedConfigurationSPI.h; sourceTree = "<group>"; };
    369370                63E369F921AFA83F001C14BC /* NSProgressSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSProgressSPI.h; sourceTree = "<group>"; };
     371                71B1141F26823ACD004D6701 /* SystemPreviewSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemPreviewSPI.h; sourceTree = "<group>"; };
    370372                72E5BE962679A80900ADBFA9 /* VideoToolboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoToolboxSPI.h; sourceTree = "<group>"; };
    371373                7A36D0F8223AD9AB00B0522E /* CommonCryptoSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonCryptoSPI.h; sourceTree = "<group>"; };
     
    629631                                0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */,
    630632                                A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */,
     633                                71B1141F26823ACD004D6701 /* SystemPreviewSPI.h */,
    631634                                0C7785881F45130F00F4EBB6 /* TelephonyUtilitiesSPI.h */,
    632635                        );
     
    991994                                A1175B491F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h in Headers */,
    992995                                0C5AF9211F43A4C7002EAC02 /* SQLite3SPI.h in Headers */,
     996                                71B1142026823ACD004D6701 /* SystemPreviewSPI.h in Headers */,
    993997                                31308B1420A21705003FB929 /* SystemPreviewSPI.h in Headers */,
    994998                                A3AB6E581F3D1DDB009C14B1 /* SystemSleepListener.h in Headers */,
  • trunk/Source/WebCore/PAL/pal/spi/mac/SystemPreviewSPI.h

    r279450 r279451  
    2424 */
    2525
    26 #pragma once
    27 
    28 #if ENABLE(MODEL_ELEMENT)
    29 
    30 #include <WebCore/ElementContext.h>
    31 #include <WebCore/GraphicsLayer.h>
    32 #include <wtf/RetainPtr.h>
    33 #include <wtf/URL.h>
    34 #include <wtf/WeakPtr.h>
     26#if USE(APPLE_INTERNAL_SDK)
    3527
    3628#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
    37 OBJC_CLASS ASVInlinePreview;
     29#import <AssetViewer/ASVInlinePreview.h>
    3830#endif
    3931
    40 namespace WebKit {
     32#else
    4133
    42 class WebPageProxy;
     34#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
    4335
    44 class ModelElementController : public CanMakeWeakPtr<ModelElementController> {
    45     WTF_MAKE_FAST_ALLOCATED;
    46 public:
    47     explicit ModelElementController(WebPageProxy&);
     36@class ASVInlinePreview;
    4837
    49     WebPageProxy& page() { return m_webPageProxy; }
     38@interface ASVInlinePreview : NSObject
     39@property (nonatomic, readonly) NSUUID *uuid;
     40@property (nonatomic, readonly) CALayer *layer;
     41@property (nonatomic, readonly) uint32_t contextId;
    5042
    51 #if HAVE(ARKIT_INLINE_PREVIEW_IOS)
    52     void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
     43- (instancetype)initWithFrame:(CGRect)frame;
     44- (instancetype)initWithFrame:(CGRect)frame UUID:(NSUUID *)uuid;
     45- (void)setupRemoteConnectionWithCompletionHandler:(void (^)(NSError * _Nullable error))handler;
     46- (void)preparePreviewOfFileAtURL:(NSURL *)url completionHandler:(void (^)(NSError * _Nullable error))handler;
     47- (void)setRemoteContext:(uint32_t)contextId;
     48
     49@end
     50
    5351#endif
    5452
    55 private:
    56     WebPageProxy& m_webPageProxy;
    57 };
    58 
    59 }
    60 
    6153#endif
  • trunk/Source/WebCore/SourcesCocoa.txt

    r279102 r279451  
    100100Modules/async-clipboard/mac/ClipboardImageReaderMac.mm
    101101Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp
     102Modules/model-element/HTMLModelElementCocoa.mm
    102103Modules/plugins/QuickTimePluginReplacement.mm
    103104Modules/plugins/YouTubePluginReplacement.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r279355 r279451  
    1029410294                71C5BB1B1FB611EA0007A2AE /* Animatable.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Animatable.idl; sourceTree = "<group>"; };
    1029510295                71C916071D1483A300ACA47D /* UserInterfaceLayoutDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserInterfaceLayoutDirection.h; sourceTree = "<group>"; };
     10296                71CAA3D9268D0BF900F25410 /* HTMLModelElementCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLModelElementCocoa.mm; sourceTree = "<group>"; };
    1029610297                71CE2C512209DC7F00C494BD /* MouseEventIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseEventIOS.cpp; sourceTree = "<group>"; };
    1029710298                71D02D901DB55C4E00DD5CF5 /* main.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = main.js; sourceTree = "<group>"; };
     
    2312323124                                71A3D17D2562B8240064E2A6 /* HTMLModelElement.h */,
    2312423125                                71A3D17F2562B8240064E2A6 /* HTMLModelElement.idl */,
     23126                                71CAA3D9268D0BF900F25410 /* HTMLModelElementCocoa.mm */,
    2312523127                        );
    2312623128                        path = "model-element";
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r279420 r279451  
    580580
    581581#if ENABLE(MODEL_ELEMENT)
     582
    582583void EmptyChromeClient::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID) const
    583584{
    584585}
     586
     587void EmptyChromeClient::modelElementDidCreatePreview(WebCore::HTMLModelElement&, const URL&, const String&, const WebCore::FloatSize&) const
     588{
     589}
     590
    585591#endif
    586592
  • trunk/Source/WebCore/loader/EmptyClients.h

    r279420 r279451  
    222222
    223223    RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) final { return nullptr; }
     224
     225#if ENABLE(MODEL_ELEMENT)
     226    void modelElementDidCreatePreview(WebCore::HTMLModelElement&, const URL&, const String&, const WebCore::FloatSize&) const final;
     227#endif
    224228};
    225229
  • trunk/Source/WebCore/page/ChromeClient.h

    r279420 r279451  
    7979#endif
    8080
     81#if ENABLE(MODEL_ELEMENT)
     82class HTMLModelElement;
     83#endif
     84
    8185#if ENABLE(WEBXR)
    8286#include "PlatformXR.h"
     
    599603#if ENABLE(MODEL_ELEMENT)
    600604    virtual void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID) const { }
     605    virtual void modelElementDidCreatePreview(WebCore::HTMLModelElement&, const URL&, const String&, const WebCore::FloatSize&) const { };
    601606#endif
    602607
  • trunk/Source/WebCore/platform/Logging.h

    r278007 r279451  
    8585    M(MemoryPressure) \
    8686    M(MessagePorts) \
     87    M(ModelElement) \
    8788    M(Network) \
    8889    M(NotYetImplemented) \
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r278883 r279451  
    10761076    else if (is<RenderModel>(renderer())) {
    10771077        auto element = downcast<HTMLModelElement>(renderer().element());
     1078#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     1079        if (auto* platformLayer = element->platformLayer())
     1080            m_graphicsLayer->setContentsToPlatformLayer(platformLayer, GraphicsLayer::ContentsLayerPurpose::Model);
     1081#else
    10781082        if (auto model = element->model())
    10791083            m_graphicsLayer->setContentsToModel(WTFMove(model));
     1084#endif
    10801085
    10811086        layerConfigChanged = true;
  • trunk/Source/WebKit/ChangeLog

    r279450 r279451  
     12021-06-30  Antoine Quint  <graouts@webkit.org>
     2
     3        [Model] [macOS] Add support for rendering model resources
     4        https://bugs.webkit.org/show_bug.cgi?id=227530
     5        <rdar://problem/79968206>
     6
     7        Reviewed by Dean Jackson.
     8
     9        On macOS, ASVInlinePreview requires an instance in both the WebProcess and the UIProcess to exist with a matching UUID.
     10
     11        On the WebKit side, in the UIProcess, we receive a message from the WebProcess when the ASVInlinePreview in that process
     12        was created with its generated UUID. We provide this to the ModelElementController, set the remote connection up and load
     13        the file. When those tasks complete successfully we message back the WebProcess with the UUID and the provided ElementContext
     14        to talk back to the HTMLModelElement instance that initiated the message to the UIProcess in the first place.
     15
     16        * UIProcess/Cocoa/ModelElementControllerCocoa.mm:
     17        (WebKit::ModelElementController::modelElementDidCreatePreview):
     18        * UIProcess/ModelElementController.h:
     19        * UIProcess/PageClient.h:
     20        * UIProcess/WebPageProxy.cpp:
     21        (WebKit::WebPageProxy::modelElementDidCreatePreview):
     22        (WebKit::WebPageProxy::modelElementPreviewDidObtainContextId):
     23        * UIProcess/WebPageProxy.h:
     24        * UIProcess/WebPageProxy.messages.in:
     25        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     26        (WebKit::WebChromeClient::modelElementDidCreatePreview const):
     27        * WebProcess/WebCoreSupport/WebChromeClient.h:
     28        * WebProcess/WebPage/WebPage.cpp:
     29        (WebKit::WebPage::modelElementDidCreatePreview):
     30        (WebKit::WebPage::modelElementPreviewDidObtainContextId):
     31        * WebProcess/WebPage/WebPage.h:
     32        * WebProcess/WebPage/WebPage.messages.in:
     33
    1342021-06-30  Chris Dumez  <cdumez@apple.com>
    235
  • trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm

    r279420 r279451  
    2929#if ENABLE(MODEL_ELEMENT)
    3030
     31#import "Logging.h"
     32#import "WebPageProxy.h"
     33
     34#if HAVE(ARKIT_INLINE_PREVIEW_IOS)
    3135#import "APIUIClient.h"
    32 #import "Logging.h"
    3336#import "RemoteLayerTreeDrawingAreaProxy.h"
    3437#import "RemoteLayerTreeHost.h"
    3538#import "RemoteLayerTreeViews.h"
    3639#import "WKModelView.h"
    37 #import "WebPageProxy.h"
    3840#import <pal/spi/cocoa/QuartzCoreSPI.h>
    39 #if HAVE(ARKIT_INLINE_PREVIEW_IOS)
    4041#import <pal/spi/ios/SystemPreviewSPI.h>
     42#endif
     43
     44#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     45#import <pal/spi/mac/SystemPreviewSPI.h>
     46#import <wtf/MainThread.h>
    4147#endif
    4248
     
    4753
    4854#if HAVE(ARKIT_INLINE_PREVIEW_IOS)
     55
    4956void ModelElementController::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
    5057{
     
    110117    }];
    111118}
     119
     120#endif
     121
     122#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     123
     124void ModelElementController::modelElementDidCreatePreview(const WebCore::ElementContext& context, const URL& fileURL, const String& uuid, const WebCore::FloatSize& size)
     125{
     126    auto preview = adoptNS([allocASVInlinePreviewInstance() initWithFrame:CGRectMake(0, 0, size.width(), size.height()) UUID:[[NSUUID alloc] initWithUUIDString:uuid]]);
     127
     128    LOG(ModelElement, "Created remote preview with UUID %s.", uuid.utf8().data());
     129
     130    auto iterator = m_inlinePreviews.find(uuid);
     131    if (iterator == m_inlinePreviews.end())
     132        m_inlinePreviews.set(uuid, preview);
     133    else
     134        iterator->value = preview;
     135
     136    RELEASE_ASSERT(isMainRunLoop());
     137    auto weakThis = makeWeakPtr(*this);
     138    auto elementContextCopy = context;
     139    auto uuidCopy = uuid;
     140    NSURL *url = [NSURL fileURLWithPath:fileURL.fileSystemPath()];
     141    [preview setupRemoteConnectionWithCompletionHandler:^(NSError * _Nullable contextError) {
     142        if (contextError) {
     143            LOG(ModelElement, "Unable to create remote connection for uuid %s: %@.", uuidCopy.utf8().data(), [contextError localizedDescription]);
     144            return;
     145        }
     146
     147        LOG(ModelElement, "Established remote connection with UUID %s.", uuidCopy.utf8().data());
     148
     149        [preview preparePreviewOfFileAtURL:url completionHandler:^(NSError * _Nullable loadError) {
     150            if (loadError) {
     151                LOG(ModelElement, "Unable to load file for uuid %s: %@.", uuidCopy.utf8().data(), [loadError localizedDescription]);
     152                return;
     153            }
     154
     155            LOG(ModelElement, "Loaded file with UUID %s.", uuidCopy.utf8().data());
     156
     157            callOnMainRunLoop([weakThis, elementContextCopy, uuidCopy, contextId = [preview contextId]]() mutable {
     158                weakThis->m_webPageProxy.modelElementPreviewDidObtainContextId(elementContextCopy, uuidCopy, contextId);
     159            });
     160        }];
     161    }];
     162}
     163
    112164#endif
    113165
  • trunk/Source/WebKit/UIProcess/ModelElementController.h

    r279420 r279451  
    5353#endif
    5454
     55#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     56    void modelElementDidCreatePreview(const WebCore::ElementContext&, const URL&, const String&, const WebCore::FloatSize&);
     57#endif
     58
    5559private:
    5660    WebPageProxy& m_webPageProxy;
     61#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     62    HashMap<String, RetainPtr<ASVInlinePreview>> m_inlinePreviews;
     63#endif
    5764};
    5865
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r279164 r279451  
    133133struct TranslationContextMenuInfo;
    134134#endif
     135
     136#if ENABLE(MODEL_ELEMENT)
     137struct ElementContext;
     138#endif
    135139}
    136140
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r279420 r279451  
    1069010690
    1069110691#if ENABLE(MODEL_ELEMENT)
     10692
    1069210693void WebPageProxy::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
    1069310694{
     
    1069610697#endif
    1069710698}
     10699
     10700void WebPageProxy::modelElementDidCreatePreview(const WebCore::ElementContext& context, const URL& url, const String& uuid, const FloatSize& size)
     10701{
     10702#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     10703    modelElementController()->modelElementDidCreatePreview(context, url, uuid, size);
     10704#endif
     10705}
     10706
     10707void WebPageProxy::modelElementPreviewDidObtainContextId(const WebCore::ElementContext& context, const String& uuid, uint32_t contextId)
     10708{
     10709    if (hasRunningProcess())
     10710        send(Messages::WebPage::ModelElementPreviewDidObtainContextId(context, uuid, contextId));
     10711}
     10712
    1069810713#endif
    1069910714
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r279420 r279451  
    577577    ModelElementController* modelElementController() { return m_modelElementController.get(); }
    578578    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
     579    void modelElementDidCreatePreview(const WebCore::ElementContext&, const URL&, const String&, const WebCore::FloatSize&);
     580    void modelElementPreviewDidObtainContextId(const WebCore::ElementContext&, const String&, uint32_t);
    579581#endif
    580582
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r279420 r279451  
    596596#if ENABLE(MODEL_ELEMENT)
    597597    TakeModelElementFullscreen(uint64_t contentLayerID)
     598    ModelElementDidCreatePreview(struct WebCore::ElementContext elementContext, URL url, String uuid, WebCore::FloatSize size)
    598599#endif
    599600}
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r279420 r279451  
    15171517
    15181518#if ENABLE(MODEL_ELEMENT)
     1519
    15191520void WebChromeClient::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId) const
    15201521{
    15211522    m_page.takeModelElementFullscreen(contentLayerId);
    15221523}
     1524
     1525void WebChromeClient::modelElementDidCreatePreview(WebCore::HTMLModelElement& element, const URL& url, const String& uuid, const WebCore::FloatSize& size) const
     1526{
     1527    m_page.modelElementDidCreatePreview(element, url, uuid, size);
     1528}
     1529
    15231530#endif
    15241531
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h

    r279420 r279451  
    455455#if ENABLE(MODEL_ELEMENT)
    456456    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId) const final;
     457    void modelElementDidCreatePreview(WebCore::HTMLModelElement&, const URL&, const String&, const WebCore::FloatSize&) const final;
    457458#endif
    458459
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r279450 r279451  
    270270#endif
    271271
     272#if ENABLE(MODEL_ELEMENT)
     273#include <WebCore/HTMLModelElement.h>
     274#endif
     275
    272276#if ENABLE(DATA_DETECTION)
    273277#include "DataDetectionResult.h"
     
    76767680
    76777681#if ENABLE(MODEL_ELEMENT)
     7682
    76787683void WebPage::takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId)
    76797684{
    76807685    send(Messages::WebPageProxy::TakeModelElementFullscreen(contentLayerId));
     7686}
     7687
     7688void WebPage::modelElementDidCreatePreview(WebCore::HTMLModelElement& element, const URL& url, const String& uuid, const WebCore::FloatSize& size)
     7689{
     7690    if (auto elementContext = contextForElement(element))
     7691        send(Messages::WebPageProxy::ModelElementDidCreatePreview(*elementContext, url, uuid, size));
     7692}
     7693
     7694void WebPage::modelElementPreviewDidObtainContextId(const WebCore::ElementContext& elementContext, const String& uuid, uint32_t contextId)
     7695{
     7696#if HAVE(ARKIT_INLINE_PREVIEW_MAC)
     7697    auto element = elementForContext(elementContext);
     7698    if (is<WebCore::HTMLModelElement>(element))
     7699        downcast<WebCore::HTMLModelElement>(*element).inlinePreviewDidObtainContextId(uuid, contextId);
     7700#else
     7701    UNUSED_PARAM(elementContext);
     7702    UNUSED_PARAM(uuid);
     7703    UNUSED_PARAM(contextId);
     7704#endif
    76817705}
    76827706
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r279420 r279451  
    211211class VisiblePosition;
    212212
     213#if ENABLE(MODEL_ELEMENT)
     214class HTMLModelElement;
     215#endif
     216
    213217enum SyntheticClickType : int8_t;
    214218enum class CreateNewGroupForHighlight : bool;
     
    14641468#if ENABLE(MODEL_ELEMENT)
    14651469    void takeModelElementFullscreen(WebCore::GraphicsLayer::PlatformLayerID contentLayerId);
     1470    void modelElementDidCreatePreview(WebCore::HTMLModelElement&, const URL&, const String&, const WebCore::FloatSize&);
     1471    void modelElementPreviewDidObtainContextId(const WebCore::ElementContext&, const String&, uint32_t);
    14661472#endif
    14671473
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r278880 r279451  
    644644    UpdateWithTextRecognitionResult(struct WebCore::TextRecognitionResult result, struct WebCore::ElementContext element, WebCore::FloatPoint location) -> (enum:uint8_t WebKit::TextRecognitionUpdateResult result) Async
    645645#endif
     646
     647#if ENABLE(MODEL_ELEMENT)
     648    ModelElementPreviewDidObtainContextId(struct WebCore::ElementContext elementContext, String uuid, uint32_t contextId)
     649#endif
    646650}
Note: See TracChangeset for help on using the changeset viewer.