Changeset 238538 in webkit


Ignore:
Timestamp:
Nov 26, 2018 5:37:22 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Insert <attachment> elements under editable images to make their backing data accessible
https://bugs.webkit.org/show_bug.cgi?id=191844
<rdar://problem/30900149>

Reviewed by Simon Fraser.

Source/WebCore:

Test: editing/images/editable-image-creates-attachment.html

  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::parseAttribute):
(WebCore::HTMLImageElement::insertedIntoAncestor):
(WebCore::HTMLImageElement::removedFromAncestor):
When the x-apple-editable-image attribute changes, or the element is
moved into or out of a document, call updateEditableImage.

(WebCore::HTMLImageElement::editableImageViewID const):
Adopt EditableImageReference.

(WebCore::HTMLImageElement::updateEditableImage):
When the image element moves into a document, the setting is on, and
the appropriate attribute is applied, add an <attachment> into the
shadow DOM, and inform the UI process both of the editable image's
creation and that it should be associated with the new attachment.

Use an EditableImageReference to extend the lifetime of the
corresponding editable image in the UI process, and to communicate
the attachment association.

If the element was cloned from another editable image element, use the
EditableImageReference and attachmentID from the original; the embedded
view will be re-parented under this element's layer, and the attachment
will be cloned (with a new ID) by editing code if the element is parented.

(WebCore::HTMLImageElement::attachmentIdentifier const):
(WebCore::HTMLImageElement::copyNonAttributePropertiesFromElement):
Store the aforementioned bits of information when cloned so that we can
reconstitute the appropriate attachment data and embedded view.

  • html/HTMLImageElement.h:
  • page/ChromeClient.h:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • page/EditableImageReference.cpp: Added.

(WebCore::EditableImageReference::EditableImageReference):
(WebCore::EditableImageReference::~EditableImageReference):
(WebCore::EditableImageReference::associateWithAttachment):

  • page/EditableImageReference.h: Added.

(WebCore::EditableImageReference::create):
(WebCore::EditableImageReference::embeddedViewID const):
Add EditableImageReference, which manages the lifetime of the UI-side
EditableImage and helps clients communicate about it. It is refcounted
so that cloned <img> elements can potentially borrow the UI-side state
(in the case where they end up getting parented).

  • page/NavigatorBase.cpp:

Fix an unrelated unified build failure that I exposed.

Source/WebKit:

  • DerivedSources.make:
  • SourcesCocoa.txt:
  • UIProcess/API/APIAttachment.h:

fileWrapper() is no longer a trivial getter; it can now construct
the file wrapper from a file wrapper generator if necessary.

Add setFileWrapperGenerator() and invalidateGeneratedFileWrapper().

Make m_fileWrapper mutable so it can be adjusted inside its own getter.

  • UIProcess/API/Cocoa/APIAttachmentCocoa.mm:

(API::Attachment::fileWrapper const):
If we have a fileWrapperGenerator and don't have a cached file wrapper,
create one before returning it.

(API::Attachment::invalidateGeneratedFileWrapper):
Invalidate the currently-cached file wrapper. The next time a client
requests the file wrapper it will be regenerated.

(API::Attachment::fileName const):
(API::Attachment::fileSizeForDisplay const):
(API::Attachment::enclosingImageData const):
(API::Attachment::isEmpty const):
(API::Attachment::createSerializedRepresentation const):
Make use of fileWrapper() instead of m_fileWrapper directly, to ensure
that it is created lazily if necessary.

(API::Attachment::setFileWrapperGenerator):

  • UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:

(WebKit::RemoteLayerTreeHost::createEmbeddedView):

  • UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.h:
  • UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:

(-[WKEmbeddedView initWithEmbeddedViewID:]):
Defer to EditableImageController for creating WKDrawingViews for
editable images. This is done primarily so we don't have to pollute
Remote Layer Tree and DrawingArea interfaces with editable-image-specific messages.

  • UIProcess/WebPageProxy.cpp:

(WebKit::m_editableImageController):
(WebKit::m_resetRecentCrashCountTimer): Deleted.

  • UIProcess/WebPageProxy.h:

(WebKit::WebPageProxy::editableImageController):
Keep an EditableImageController on the WebPageProxy.

  • UIProcess/ios/EditableImageController.h: Added.
  • UIProcess/ios/EditableImageController.messages.in: Added.
  • UIProcess/ios/EditableImageController.mm: Added.

(WebKit::EditableImageController::EditableImageController):
(WebKit::EditableImageController::~EditableImageController):
(WebKit::EditableImageController::ensureEditableImage):
(WebKit::EditableImageController::editableImage):
(WebKit::EditableImageController::didCreateEditableImage):
(WebKit::EditableImageController::didDestroyEditableImage):
(WebKit::EditableImageController::associateWithAttachment):
(WebKit::EditableImageController::invalidateAttachmentForEditableImage):
Add EditableImageController, which keeps track of EditableImages.
It can be messaged directly to create or destroy the UI-side state
of an editable image, and also to associate a WKDrawingView with
a particular attachment.

  • UIProcess/ios/WKDrawingView.h:
  • UIProcess/ios/WKDrawingView.mm:

(-[WKDrawingView initWithEmbeddedViewID:webPageProxy:]):
Store the WebPageProxy (weakly) so that we can get to the EditableImageController.

(-[WKDrawingView layoutSubviews]):
(-[WKDrawingView PNGRepresentation]):
Synchronously render the PKCanvasView to PNG.

(-[WKDrawingView drawingDidChange:]):
If the drawing changes, inform the APIAttachment that it needs
to discard its NSFileWrapper; a new one will be generated lazily.

(-[WKDrawingView init]): Deleted.

  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/WebCoreSupport/WebChromeClient.h:
  • WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm:

(WebKit::WebChromeClient::associateEditableImageWithAttachment):
(WebKit::WebChromeClient::didCreateEditableImage):
(WebKit::WebChromeClient::didDestroyEditableImage):

Tools:

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::attachmentInfo):

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:

(WTR::UIScriptController::attachmentInfo):

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::attachmentInfo):
Add a UIScriptController mechanism to retrieve information about
a given attachment.

LayoutTests:

  • editing/images/editable-image-creates-attachment-expected.txt: Added.
  • editing/images/editable-image-creates-attachment.html: Added.
  • resources/ui-helper.js:

(window.UIHelper.attachmentInfo):
(window.UIHelper):

Location:
trunk
Files:
6 added
30 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238526 r238538  
     12018-11-26  Tim Horton  <timothy_horton@apple.com>
     2
     3        Insert <attachment> elements under editable images to make their backing data accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=191844
     5        <rdar://problem/30900149>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * editing/images/editable-image-creates-attachment-expected.txt: Added.
     10        * editing/images/editable-image-creates-attachment.html: Added.
     11        * resources/ui-helper.js:
     12        (window.UIHelper.attachmentInfo):
     13        (window.UIHelper):
     14
    1152018-11-26  Daniel Bates  <dabates@apple.com>
    216
  • trunk/LayoutTests/resources/ui-helper.js

    r238526 r238538  
    455455        });
    456456    }
     457
     458    static attachmentInfo(attachmentIdentifier)
     459    {
     460        if (!this.isWebKit2())
     461            return Promise.resolve();
     462
     463        return new Promise(resolve => {
     464            testRunner.runUIScript(`(() => {
     465                uiController.uiScriptComplete(JSON.stringify(uiController.attachmentInfo('${attachmentIdentifier}')));
     466            })()`, jsonString => {
     467                resolve(JSON.parse(jsonString));
     468            })
     469        });
     470    }
    457471}
  • trunk/Source/WebCore/ChangeLog

    r238528 r238538  
     12018-11-26  Tim Horton  <timothy_horton@apple.com>
     2
     3        Insert <attachment> elements under editable images to make their backing data accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=191844
     5        <rdar://problem/30900149>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Test: editing/images/editable-image-creates-attachment.html
     10
     11        * html/HTMLImageElement.cpp:
     12        (WebCore::HTMLImageElement::parseAttribute):
     13        (WebCore::HTMLImageElement::insertedIntoAncestor):
     14        (WebCore::HTMLImageElement::removedFromAncestor):
     15        When the x-apple-editable-image attribute changes, or the element is
     16        moved into or out of a document, call updateEditableImage.
     17
     18        (WebCore::HTMLImageElement::editableImageViewID const):
     19        Adopt EditableImageReference.
     20
     21        (WebCore::HTMLImageElement::updateEditableImage):
     22        When the image element moves into a document, the setting is on, and
     23        the appropriate attribute is applied, add an <attachment> into the
     24        shadow DOM, and inform the UI process both of the editable image's
     25        creation and that it should be associated with the new attachment.
     26
     27        Use an EditableImageReference to extend the lifetime of the
     28        corresponding editable image in the UI process, and to communicate
     29        the attachment association.
     30
     31        If the element was cloned from another editable image element, use the
     32        EditableImageReference and attachmentID from the original; the embedded
     33        view will be re-parented under this element's layer, and the attachment
     34        will be cloned (with a new ID) by editing code if the element is parented.
     35
     36        (WebCore::HTMLImageElement::attachmentIdentifier const):
     37        (WebCore::HTMLImageElement::copyNonAttributePropertiesFromElement):
     38        Store the aforementioned bits of information when cloned so that we can
     39        reconstitute the appropriate attachment data and embedded view.
     40
     41        * html/HTMLImageElement.h:
     42        * page/ChromeClient.h:
     43
     44        * Sources.txt:
     45        * WebCore.xcodeproj/project.pbxproj:
     46        * page/EditableImageReference.cpp: Added.
     47        (WebCore::EditableImageReference::EditableImageReference):
     48        (WebCore::EditableImageReference::~EditableImageReference):
     49        (WebCore::EditableImageReference::associateWithAttachment):
     50        * page/EditableImageReference.h: Added.
     51        (WebCore::EditableImageReference::create):
     52        (WebCore::EditableImageReference::embeddedViewID const):
     53        Add EditableImageReference, which manages the lifetime of the UI-side
     54        EditableImage and helps clients communicate about it. It is refcounted
     55        so that cloned <img> elements can potentially borrow the UI-side state
     56        (in the case where they end up getting parented).
     57
     58        * page/NavigatorBase.cpp:
     59        Fix an unrelated unified build failure that I exposed.
     60
    1612018-11-26  Jer Noble  <jer.noble@apple.com>
    262
  • trunk/Source/WebCore/Sources.txt

    r238475 r238538  
    14201420page/DisabledAdaptations.cpp
    14211421page/DragController.cpp
     1422page/EditableImageReference.cpp
    14221423page/EventHandler.cpp
    14231424page/EventSource.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r238475 r238538  
    734734                2D29ECC8192ECC8300984B78 /* DisplayRefreshMonitorManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D29ECC4192ECC8300984B78 /* DisplayRefreshMonitorManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
    735735                2D29ECCA192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D29ECC9192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h */; };
     736                2D2E34AC21A4E192004598B5 /* EditableImageReference.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2E34A921A4E191004598B5 /* EditableImageReference.h */; };
    736737                2D3A0E3613A7D76100E85AF0 /* SVGParsingError.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3A0E3513A7D76100E85AF0 /* SVGParsingError.h */; settings = {ATTRIBUTES = (Private, ); }; };
    737738                2D3EF4481917915C00034184 /* WebActionDisablingCALayerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3EF4441917915C00034184 /* WebActionDisablingCALayerDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    66136614                2D29ECC4192ECC8300984B78 /* DisplayRefreshMonitorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitorManager.h; sourceTree = "<group>"; };
    66146615                2D29ECC9192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitorIOS.h; sourceTree = "<group>"; };
     6616                2D2E34A921A4E191004598B5 /* EditableImageReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditableImageReference.h; sourceTree = "<group>"; };
     6617                2D2E34AB21A4E192004598B5 /* EditableImageReference.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditableImageReference.cpp; sourceTree = "<group>"; };
    66156618                2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossfadeGeneratedImage.cpp; sourceTree = "<group>"; };
    66166619                2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossfadeGeneratedImage.h; sourceTree = "<group>"; };
     
    1998919992                                A7CA595B0B27BD9E00FA021D /* DragController.h */,
    1999019993                                81F65FF513788FAA00FF6F2D /* DragState.h */,
     19994                                2D2E34AB21A4E192004598B5 /* EditableImageReference.cpp */,
     19995                                2D2E34A921A4E191004598B5 /* EditableImageReference.h */,
    1999119996                                1AF326770D78B9440068F0C4 /* EditorClient.h */,
    1999219997                                93C09A800B064F00005ABD4D /* EventHandler.cpp */,
     
    2864428649                                FD537357137B653B00008DCE /* DynamicsCompressorKernel.h in Headers */,
    2864528650                                FD6ED2C4136B8E42003CF072 /* DynamicsCompressorNode.h in Headers */,
     28651                                2D2E34AC21A4E192004598B5 /* EditableImageReference.h in Headers */,
    2864628652                                93309DE2099E64920056E581 /* EditAction.h in Headers */,
    2864728653                                93309DE4099E64920056E581 /* EditCommand.h in Headers */,
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r238108 r238538  
    2727#include "CSSValueKeywords.h"
    2828#include "CachedImage.h"
     29#include "Chrome.h"
     30#include "ChromeClient.h"
     31#include "EditableImageReference.h"
     32#include "Editor.h"
    2933#include "ElementIterator.h"
    3034#include "FrameView.h"
     
    239243        updateImageControls();
    240244#endif
    241     } else {
     245    } else if (name == x_apple_editable_imageAttr)
     246        updateEditableImage(isConnected() ? IsConnectedToDocument::Yes : IsConnectedToDocument::No);
     247    else {
    242248        if (name == nameAttr) {
    243249            bool willHaveName = !value.isNull();
     
    327333            m_form->registerImgElement(this);
    328334    }
     335
     336    if (insertionType.connectedToDocument)
     337        updateEditableImage(IsConnectedToDocument::Yes);
     338
    329339    // Insert needs to complete first, before we start updating the loader. Loader dispatches events which could result
    330340    // in callbacks back to this node.
     
    358368        setPictureElement(nullptr);
    359369
     370    if (removalType.disconnectedFromDocument)
     371        updateEditableImage(IsConnectedToDocument::No);
     372
    360373    m_form = nullptr;
    361374    HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
     375}
     376
     377GraphicsLayer::EmbeddedViewID HTMLImageElement::editableImageViewID() const
     378{
     379    if (!m_editableImage)
     380        return 0;
     381    return m_editableImage->embeddedViewID();
     382}
     383
     384void HTMLImageElement::updateEditableImage(IsConnectedToDocument connected)
     385{
     386    if (!document().settings().editableImagesEnabled())
     387        return;
     388
     389    auto* page = document().page();
     390    if (!page)
     391        return;
     392
     393    bool hasEditableAttribute = hasAttributeWithoutSynchronization(x_apple_editable_imageAttr);
     394    bool isCurrentlyEditable = !!m_editableImage;
     395    bool shouldBeEditable = (connected == IsConnectedToDocument::Yes) && hasEditableAttribute;
     396
     397#if ENABLE(ATTACHMENT_ELEMENT)
     398    // Create the inner attachment for editable images, or non-editable
     399    // images that were cloned from editable image sources.
     400    if (!attachmentElement() && (shouldBeEditable || !m_pendingClonedAttachmentID.isEmpty())) {
     401        auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document());
     402        if (!m_pendingClonedAttachmentID.isEmpty())
     403            attachment->setUniqueIdentifier(WTFMove(m_pendingClonedAttachmentID));
     404        else
     405            attachment->ensureUniqueIdentifier();
     406        setAttachmentElement(WTFMove(attachment));
     407    }
     408#endif
     409
     410    if (shouldBeEditable == isCurrentlyEditable)
     411        return;
     412
     413    if (!hasEditableAttribute) {
     414        m_editableImage = nullptr;
     415        return;
     416    }
     417
     418    if (!m_editableImage)
     419        m_editableImage = EditableImageReference::create(document());
     420
     421#if ENABLE(ATTACHMENT_ELEMENT)
     422    m_editableImage->associateWithAttachment(attachmentElement()->uniqueIdentifier());
     423#endif
    362424}
    363425
     
    634696const String& HTMLImageElement::attachmentIdentifier() const
    635697{
     698    if (!m_pendingClonedAttachmentID.isEmpty())
     699        return m_pendingClonedAttachmentID;
     700
    636701    if (auto attachment = attachmentElement())
    637702        return attachment->uniqueIdentifier();
     
    738803#endif
    739804
    740 GraphicsLayer::EmbeddedViewID HTMLImageElement::editableImageViewID() const
    741 {
    742     if (!m_editableImageViewID)
    743         m_editableImageViewID = GraphicsLayer::nextEmbeddedViewID();
    744     return m_editableImageViewID;
    745 }
    746 
    747 }
     805void HTMLImageElement::copyNonAttributePropertiesFromElement(const Element& source)
     806{
     807    auto& sourceImage = static_cast<const HTMLImageElement&>(source);
     808#if ENABLE(ATTACHMENT_ELEMENT)
     809    m_pendingClonedAttachmentID = !sourceImage.m_pendingClonedAttachmentID.isEmpty() ? sourceImage.m_pendingClonedAttachmentID : sourceImage.attachmentIdentifier();
     810#endif
     811    m_editableImage = sourceImage.m_editableImage;
     812    Element::copyNonAttributePropertiesFromElement(source);
     813}
     814
     815}
  • trunk/Source/WebCore/html/HTMLImageElement.h

    r238108 r238538  
    3333namespace WebCore {
    3434
     35class EditableImageReference;
    3536class HTMLAttachmentElement;
    3637class HTMLFormElement;
     
    153154    ImageCandidate bestFitSourceFromPictureElement();
    154155
     156    enum class IsConnectedToDocument : bool { No, Yes };
     157    void updateEditableImage(IsConnectedToDocument);
     158
     159    void copyNonAttributePropertiesFromElement(const Element&) final;
     160
    155161#if ENABLE(SERVICE_CONTROLS)
    156162    void updateImageControls();
     
    173179    bool m_hadNameBeforeAttributeChanged { false }; // FIXME: We only need this because parseAttribute() can't see the old value.
    174180
    175     mutable GraphicsLayer::EmbeddedViewID m_editableImageViewID { 0 };
     181    RefPtr<EditableImageReference> m_editableImage;
     182#if ENABLE(ATTACHMENT_ELEMENT)
     183    String m_pendingClonedAttachmentID;
     184#endif
    176185
    177186    friend class HTMLPictureElement;
  • trunk/Source/WebCore/page/ChromeClient.h

    r238322 r238538  
    3131#include "FrameLoader.h"
    3232#include "GraphicsContext.h"
     33#include "GraphicsLayer.h"
    3334#include "HTMLMediaElementEnums.h"
    3435#include "HostWindow.h"
     
    490491    virtual String signedPublicKeyAndChallengeString(unsigned, const String&, const URL&) const { return emptyString(); }
    491492
     493    virtual void associateEditableImageWithAttachment(GraphicsLayer::EmbeddedViewID, const String&) { }
     494    virtual void didCreateEditableImage(GraphicsLayer::EmbeddedViewID) { }
     495    virtual void didDestroyEditableImage(GraphicsLayer::EmbeddedViewID) { }
     496
    492497protected:
    493498    virtual ~ChromeClient() = default;
  • trunk/Source/WebCore/page/NavigatorBase.cpp

    r237990 r238538  
    2828#include "NavigatorBase.h"
    2929
     30#include "Document.h"
    3031#include "ServiceWorkerContainer.h"
    3132#include <mutex>
  • trunk/Source/WebKit/ChangeLog

    r238528 r238538  
     12018-11-26  Tim Horton  <timothy_horton@apple.com>
     2
     3        Insert <attachment> elements under editable images to make their backing data accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=191844
     5        <rdar://problem/30900149>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * DerivedSources.make:
     10        * SourcesCocoa.txt:
     11        * UIProcess/API/APIAttachment.h:
     12        fileWrapper() is no longer a trivial getter; it can now construct
     13        the file wrapper from a file wrapper generator if necessary.
     14
     15        Add setFileWrapperGenerator() and invalidateGeneratedFileWrapper().
     16
     17        Make m_fileWrapper mutable so it can be adjusted inside its own getter.
     18
     19        * UIProcess/API/Cocoa/APIAttachmentCocoa.mm:
     20        (API::Attachment::fileWrapper const):
     21        If we have a fileWrapperGenerator and don't have a cached file wrapper,
     22        create one before returning it.
     23
     24        (API::Attachment::invalidateGeneratedFileWrapper):
     25        Invalidate the currently-cached file wrapper. The next time a client
     26        requests the file wrapper it will be regenerated.
     27
     28        (API::Attachment::fileName const):
     29        (API::Attachment::fileSizeForDisplay const):
     30        (API::Attachment::enclosingImageData const):
     31        (API::Attachment::isEmpty const):
     32        (API::Attachment::createSerializedRepresentation const):
     33        Make use of fileWrapper() instead of m_fileWrapper directly, to ensure
     34        that it is created lazily if necessary.
     35
     36        (API::Attachment::setFileWrapperGenerator):
     37        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:
     38        (WebKit::RemoteLayerTreeHost::createEmbeddedView):
     39        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.h:
     40        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:
     41        (-[WKEmbeddedView initWithEmbeddedViewID:]):
     42        Defer to EditableImageController for creating WKDrawingViews for
     43        editable images. This is done primarily so we don't have to pollute
     44        Remote Layer Tree and DrawingArea interfaces with editable-image-specific messages.
     45
     46        * UIProcess/WebPageProxy.cpp:
     47        (WebKit::m_editableImageController):
     48        (WebKit::m_resetRecentCrashCountTimer): Deleted.
     49        * UIProcess/WebPageProxy.h:
     50        (WebKit::WebPageProxy::editableImageController):
     51        Keep an EditableImageController on the WebPageProxy.
     52
     53        * UIProcess/ios/EditableImageController.h: Added.
     54        * UIProcess/ios/EditableImageController.messages.in: Added.
     55        * UIProcess/ios/EditableImageController.mm: Added.
     56        (WebKit::EditableImageController::EditableImageController):
     57        (WebKit::EditableImageController::~EditableImageController):
     58        (WebKit::EditableImageController::ensureEditableImage):
     59        (WebKit::EditableImageController::editableImage):
     60        (WebKit::EditableImageController::didCreateEditableImage):
     61        (WebKit::EditableImageController::didDestroyEditableImage):
     62        (WebKit::EditableImageController::associateWithAttachment):
     63        (WebKit::EditableImageController::invalidateAttachmentForEditableImage):
     64        Add EditableImageController, which keeps track of EditableImages.
     65        It can be messaged directly to create or destroy the UI-side state
     66        of an editable image, and also to associate a WKDrawingView with
     67        a particular attachment.
     68
     69        * UIProcess/ios/WKDrawingView.h:
     70        * UIProcess/ios/WKDrawingView.mm:
     71        (-[WKDrawingView initWithEmbeddedViewID:webPageProxy:]):
     72        Store the WebPageProxy (weakly) so that we can get to the EditableImageController.
     73
     74        (-[WKDrawingView layoutSubviews]):
     75        (-[WKDrawingView PNGRepresentation]):
     76        Synchronously render the PKCanvasView to PNG.
     77
     78        (-[WKDrawingView drawingDidChange:]):
     79        If the drawing changes, inform the APIAttachment that it needs
     80        to discard its NSFileWrapper; a new one will be generated lazily.
     81
     82        (-[WKDrawingView init]): Deleted.
     83        * WebKit.xcodeproj/project.pbxproj:
     84        * WebProcess/WebCoreSupport/WebChromeClient.h:
     85        * WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm:
     86        (WebKit::WebChromeClient::associateEditableImageWithAttachment):
     87        (WebKit::WebChromeClient::didCreateEditableImage):
     88        (WebKit::WebChromeClient::didDestroyEditableImage):
     89
    1902018-11-26  Jer Noble  <jer.noble@apple.com>
    291
  • trunk/Source/WebKit/DerivedSources.make

    r238008 r238538  
    105105    DrawingArea \
    106106    DrawingAreaProxy \
     107    EditableImageController \
    107108    EventDispatcher \
    108109    LegacyCustomProtocolManager \
  • trunk/Source/WebKit/SourcesCocoa.txt

    r238515 r238538  
    369369
    370370UIProcess/ios/DragDropInteractionState.mm
     371UIProcess/ios/EditableImageController.mm
    371372UIProcess/ios/InputViewUpdateDeferrer.mm
    372373UIProcess/ios/PageClientImplIOS.mm
     
    557558WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm @no-unify
    558559WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm
     560
     561// Derived Sources
     562
     563EditableImageControllerMessageReceiver.cpp
  • trunk/Source/WebKit/UIProcess/API/APIAttachment.h

    r237624 r238538  
    6161
    6262#if PLATFORM(COCOA)
    63     NSFileWrapper *fileWrapper() const { return m_fileWrapper.get(); }
     63    NSFileWrapper *fileWrapper() const;
    6464    void setFileWrapper(NSFileWrapper *fileWrapper) { m_fileWrapper = fileWrapper; }
    6565    void setFileWrapperAndUpdateContentType(NSFileWrapper *, NSString *contentType);
     66    void setFileWrapperGenerator(Function<RetainPtr<NSFileWrapper>(void)>&&);
     67    void invalidateGeneratedFileWrapper();
    6668    WTF::String utiType() const;
    6769#endif
     
    9395
    9496#if PLATFORM(COCOA)
    95     RetainPtr<NSFileWrapper> m_fileWrapper;
     97    mutable RetainPtr<NSFileWrapper> m_fileWrapper;
     98    Function<RetainPtr<NSFileWrapper>(void)> m_fileWrapperGenerator;
    9699#endif
    97100    WTF::String m_identifier;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm

    r237667 r238538  
    5454}
    5555
     56NSFileWrapper *Attachment::fileWrapper() const
     57{
     58    if (m_fileWrapperGenerator && !m_fileWrapper)
     59        m_fileWrapper = m_fileWrapperGenerator();
     60    return m_fileWrapper.get();
     61}
     62
     63void Attachment::invalidateGeneratedFileWrapper()
     64{
     65    ASSERT(m_fileWrapperGenerator);
     66    m_fileWrapper = nil;
     67}
     68
    5669WTF::String Attachment::mimeType() const
    5770{
     
    7487WTF::String Attachment::fileName() const
    7588{
    76     if ([m_fileWrapper filename].length)
    77         return [m_fileWrapper filename];
     89    auto fileWrapper = this->fileWrapper();
    7890
    79     return [m_fileWrapper preferredFilename];
     91    if ([fileWrapper filename].length)
     92        return [fileWrapper filename];
     93
     94    return [fileWrapper preferredFilename];
    8095}
    8196
     
    99114std::optional<uint64_t> Attachment::fileSizeForDisplay() const
    100115{
    101     if (![m_fileWrapper isRegularFile]) {
     116    auto fileWrapper = this->fileWrapper();
     117
     118    if (![fileWrapper isRegularFile]) {
    102119        // FIXME: We should display a size estimate for directory-type file wrappers.
    103120        return std::nullopt;
    104121    }
    105122
    106     if (auto fileSize = [[m_fileWrapper fileAttributes][NSFileSize] unsignedLongLongValue])
     123    if (auto fileSize = [[fileWrapper fileAttributes][NSFileSize] unsignedLongLongValue])
    107124        return fileSize;
    108125
    109     return [m_fileWrapper regularFileContents].length;
     126    return [fileWrapper regularFileContents].length;
    110127}
    111128
     
    115132        return nullptr;
    116133
    117     if (![m_fileWrapper isRegularFile])
     134    auto fileWrapper = this->fileWrapper();
     135
     136    if (![fileWrapper isRegularFile])
    118137        return nullptr;
    119138
    120     NSData *data = [m_fileWrapper regularFileContents];
     139    NSData *data = [fileWrapper regularFileContents];
    121140    if (!data)
    122141        return nullptr;
     
    127146bool Attachment::isEmpty() const
    128147{
    129     return !m_fileWrapper;
     148    return !m_fileWrapper && !m_fileWrapperGenerator;
    130149}
    131150
    132151RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const
    133152{
    134     if (!m_fileWrapper || !m_webPage)
     153    auto fileWrapper = this->fileWrapper();
     154
     155    if (!fileWrapper || !m_webPage)
    135156        return nullptr;
    136157
    137158#if CAN_SECURELY_ARCHIVE_FILE_WRAPPER
    138     NSData *serializedData = securelyArchivedDataWithRootObject(m_fileWrapper.get());
     159    NSData *serializedData = securelyArchivedDataWithRootObject(fileWrapper);
    139160#else
    140     NSData *serializedData = insecurelyArchivedDataWithRootObject(m_fileWrapper.get());
     161    NSData *serializedData = insecurelyArchivedDataWithRootObject(fileWrapper);
    141162#endif
    142163
     
    169190}
    170191
     192void Attachment::setFileWrapperGenerator(Function<RetainPtr<NSFileWrapper>(void)>&& fileWrapperGenerator)
     193{
     194    m_fileWrapperGenerator = WTFMove(fileWrapperGenerator);
     195    m_fileWrapper = nil;
     196}
     197
    171198} // namespace API
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm

    r238476 r238538  
    2929#if PLATFORM(IOS_FAMILY)
    3030
     31#import "EditableImageController.h"
    3132#import "RemoteLayerTreeDrawingAreaProxy.h"
    3233#import "RemoteLayerTreeViews.h"
     
    124125RetainPtr<WKEmbeddedView> RemoteLayerTreeHost::createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
    125126{
    126     Class embeddedViewClass = nil;
    127     switch (properties.type) {
    128     case PlatformCALayer::LayerTypeEditableImageLayer:
    129 #if HAVE(PENCILKIT)
    130         embeddedViewClass = [WKDrawingView class];
    131 #endif
    132         break;
    133     default:
    134         break;
    135     }
    136 
    137     if (!embeddedViewClass || m_isDebugLayerTreeHost)
     127    if (m_isDebugLayerTreeHost)
    138128        return adoptNS([[UIView alloc] init]);
    139129
    140     auto result = m_embeddedViews.ensure(properties.embeddedViewID, [&] {
    141         return adoptNS([[embeddedViewClass alloc] init]);
     130    auto result = m_embeddedViews.ensure(properties.embeddedViewID, [&]() -> RetainPtr<UIView *> {
     131        switch (properties.type) {
     132#if HAVE(PENCILKIT)
     133        case PlatformCALayer::LayerTypeEditableImageLayer: {
     134            auto editableImage = m_drawingArea->page().editableImageController().editableImage(properties.embeddedViewID);
     135            return editableImage ? editableImage->drawingView : nil;
     136        }
     137#endif
     138        default:
     139            return adoptNS([[UIView alloc] init]);
     140        }
    142141    });
    143142    auto view = result.iterator->value;
    144143    if (!result.isNewEntry)
    145         m_layerToEmbeddedViewMap.remove([view layerID]);
    146     [view setLayerID:properties.layerID];
    147     m_embeddedViews.set(properties.embeddedViewID, view);
     144        m_layerToEmbeddedViewMap.remove(RemoteLayerTreeNode::layerID([view layer]));
    148145    m_layerToEmbeddedViewMap.set(properties.layerID, properties.embeddedViewID);
    149146    return view;
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.h

    r238108 r238538  
    3030#import "UIKitSPI.h"
    3131#import <WebCore/GraphicsLayer.h>
     32
     33namespace WebKit {
     34class WebPageProxy;
     35}
    3236
    3337@protocol WKNativelyInteractible <NSObject>
     
    6367@interface WKEmbeddedView : UIView
    6468
    65 @property (nonatomic, assign) WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID;
    66 @property (nonatomic, assign) WebCore::GraphicsLayer::PlatformLayerID layerID;
     69- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID;
     70
     71@property (nonatomic, readonly, assign) WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID;
    6772
    6873@end
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm

    r238476 r238538  
    203203
    204204@implementation WKEmbeddedView
     205
     206- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID
     207{
     208    self = [super init];
     209    if (!self)
     210        return nil;
     211
     212    _embeddedViewID = embeddedViewID;
     213
     214    return self;
     215}
     216
    205217@end
    206218
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r238471 r238538  
    234234#endif
    235235
     236#if HAVE(PENCILKIT)
     237#include "EditableImageController.h"
     238#endif
     239
    236240// This controls what strategy we use for mouse wheel coalescing.
    237241#define MERGE_WHEEL_EVENTS 1
     
    437441#endif
    438442    , m_resetRecentCrashCountTimer(RunLoop::main(), this, &WebPageProxy::resetRecentCrashCount)
     443#if HAVE(PENCILKIT)
     444    , m_editableImageController(std::make_unique<EditableImageController>(*this))
     445#endif
    439446{
    440447    m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r238475 r238538  
    218218namespace WebKit {
    219219class DrawingAreaProxy;
     220class EditableImageController;
    220221class NativeWebGestureEvent;
    221222class NativeWebKeyboardEvent;
     
    13691370    void updateAttachmentAttributes(const API::Attachment&, Function<void(CallbackBase::Error)>&&);
    13701371    void serializedAttachmentDataForIdentifiers(const Vector<String>&, Vector<WebCore::SerializedAttachmentData>&);
     1372    void registerAttachmentIdentifier(const String&);
    13711373#endif
    13721374
     
    13891391
    13901392    void updateCurrentModifierState();
     1393
     1394#if HAVE(PENCILKIT)
     1395    EditableImageController& editableImageController() { return *m_editableImageController; }
     1396#endif
    13911397
    13921398private:
     
    18541860    void registerAttachmentIdentifierFromFilePath(const String&, const String& contentType, const String& filePath);
    18551861    void registerAttachmentsFromSerializedData(Vector<WebCore::SerializedAttachmentData>&&);
    1856     void registerAttachmentIdentifier(const String&);
    18571862    void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier);
    18581863
     
    22812286
    22822287    bool m_needsFontAttributes { false };
     2288
     2289#if HAVE(PENCILKIT)
     2290    std::unique_ptr<EditableImageController> m_editableImageController;
     2291#endif
    22832292};
    22842293
  • trunk/Source/WebKit/UIProcess/ios/EditableImageController.h

    r238535 r238538  
    2424 */
    2525
    26 #import "config.h"
    27 #import "WKDrawingView.h"
     26#pragma once
    2827
    2928#if HAVE(PENCILKIT)
    3029
    31 #import "PencilKitSPI.h"
    32 #import <wtf/RetainPtr.h>
     30#include "MessageReceiver.h"
     31#include <WebCore/GraphicsLayer.h>
     32#include <wtf/Noncopyable.h>
     33#include <wtf/WeakObjCPtr.h>
     34#include <wtf/WeakPtr.h>
     35#include <wtf/text/WTFString.h>
    3336
    34 SOFT_LINK_PRIVATE_FRAMEWORK(PencilKit);
    35 SOFT_LINK_CLASS(PencilKit, PKCanvasView);
     37OBJC_CLASS WKDrawingView;
    3638
    37 @implementation WKDrawingView {
    38     RetainPtr<PKCanvasView> _pencilView;
    39 }
     39namespace WebKit {
    4040
    41 - (id)init
    42 {
    43     self = [super init];
    44     if (!self)
    45         return nil;
     41class WebPageProxy;
    4642
    47     _pencilView = adoptNS([allocPKCanvasViewInstance() initWithFrame:CGRectZero]);
     43struct EditableImage {
     44    RetainPtr<WKDrawingView> drawingView;
     45    String attachmentID;
     46};
    4847
    49     [_pencilView setFingerDrawingEnabled:NO];
    50     [_pencilView setUserInteractionEnabled:YES];
    51     [_pencilView setOpaque:NO];
     48class EditableImageController : private IPC::MessageReceiver {
     49    WTF_MAKE_NONCOPYABLE(EditableImageController);
     50public:
     51    explicit EditableImageController(WebPageProxy&);
     52    ~EditableImageController();
    5253
    53     [self addSubview:_pencilView.get()];
     54    // IPC::MessageReceiver.
     55    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    5456
    55     return self;
    56 }
     57    EditableImage* editableImage(WebCore::GraphicsLayer::EmbeddedViewID);
     58    EditableImage& ensureEditableImage(WebCore::GraphicsLayer::EmbeddedViewID);
    5759
    58 - (void)layoutSubviews
    59 {
    60     [_pencilView setFrame:self.bounds];
    61 }
     60    void invalidateAttachmentForEditableImage(WebCore::GraphicsLayer::EmbeddedViewID);
    6261
    63 @end
     62private:
     63    void didCreateEditableImage(WebCore::GraphicsLayer::EmbeddedViewID);
     64    void didDestroyEditableImage(WebCore::GraphicsLayer::EmbeddedViewID);
     65
     66    void associateWithAttachment(WebCore::GraphicsLayer::EmbeddedViewID, const String& attachmentID);
     67
     68    WeakPtr<WebPageProxy> m_webPageProxy;
     69
     70    HashMap<WebCore::GraphicsLayer::EmbeddedViewID, std::unique_ptr<EditableImage>> m_editableImages;
     71};
     72
     73} // namespace WebKit
    6474
    6575#endif // HAVE(PENCILKIT)
  • trunk/Source/WebKit/UIProcess/ios/WKDrawingView.h

    r238108 r238538  
    3131@interface WKDrawingView : WKEmbeddedView <WKNativelyInteractible>
    3232
     33- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy;
     34
     35- (NSData *)PNGRepresentation;
     36
    3337@end
    3438
  • trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm

    r238474 r238538  
    2929#if HAVE(PENCILKIT)
    3030
     31#import "EditableImageController.h"
    3132#import "PencilKitSPI.h"
     33#import <wtf/OSObjectPtr.h>
    3234#import <wtf/RetainPtr.h>
    3335
    3436SOFT_LINK_PRIVATE_FRAMEWORK(PencilKit);
    3537SOFT_LINK_CLASS(PencilKit, PKCanvasView);
     38SOFT_LINK_CLASS(PencilKit, PKImageRenderer);
     39
     40@interface WKDrawingView () <PKCanvasViewDelegate>
     41@end
    3642
    3743@implementation WKDrawingView {
    3844    RetainPtr<PKCanvasView> _pencilView;
     45
     46    OSObjectPtr<dispatch_queue_t> _renderQueue;
     47    RetainPtr<PKImageRenderer> _renderer;
     48
     49    WeakPtr<WebKit::WebPageProxy> _webPageProxy;
    3950}
    4051
    41 - (id)init
     52- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy
    4253{
    43     self = [super init];
     54    self = [super initWithEmbeddedViewID:embeddedViewID];
    4455    if (!self)
    4556        return nil;
     57
     58    _webPageProxy = makeWeakPtr(webPageProxy);
    4659
    4760    _pencilView = adoptNS([allocPKCanvasViewInstance() initWithFrame:CGRectZero]);
     
    5063    [_pencilView setUserInteractionEnabled:YES];
    5164    [_pencilView setOpaque:NO];
     65    [_pencilView setDrawingDelegate:self];
    5266
    5367    [self addSubview:_pencilView.get()];
     
    5872- (void)layoutSubviews
    5973{
    60     [_pencilView setFrame:self.bounds];
     74    if (!CGRectEqualToRect([_pencilView frame], self.bounds)) {
     75        [_pencilView setFrame:self.bounds];
     76
     77        // The renderer is instantiated for a particular size output; if
     78        // the size changes, we need to re-create the renderer.
     79        _renderer = nil;
     80    }
     81}
     82
     83- (NSData *)PNGRepresentation
     84{
     85    if (!_renderQueue)
     86        _renderQueue = adoptOSObject(dispatch_queue_create("com.apple.WebKit.WKDrawingView.Rendering", DISPATCH_QUEUE_SERIAL));
     87
     88    if (!_renderer)
     89        _renderer = adoptNS([allocPKImageRendererInstance() initWithSize:self.bounds.size scale:self.window.screen.scale renderQueue:_renderQueue.get()]);
     90
     91    __block RetainPtr<UIImage> resultImage;
     92    [_renderer renderDrawing:[_pencilView drawing] completion:^(UIImage *image) {
     93        resultImage = image;
     94    }];
     95
     96    // FIXME: Ideally we would not synchronously wait for this rendering,
     97    // but NSFileWrapper requires data synchronously, and our clients expect
     98    // an NSFileWrapper to be available synchronously.
     99    dispatch_sync(_renderQueue.get(), ^{ });
     100
     101    return UIImagePNGRepresentation(resultImage.get());
     102}
     103
     104- (void)drawingDidChange:(PKCanvasView *)canvasView
     105{
     106    if (!_webPageProxy)
     107        return;
     108    auto& page = *_webPageProxy;
     109
     110    page.editableImageController().invalidateAttachmentForEditableImage(self.embeddedViewID);
    61111}
    62112
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r238515 r238538  
    605605                2D54C31A212F3B330049C174 /* UnifiedSource61-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D54C306212F3B330049C174 /* UnifiedSource61-mm.mm */; };
    606606                2D54C31B212F4DA60049C174 /* ProcessLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE117F511DBB30900981615 /* ProcessLauncher.cpp */; };
     607                2D5875BF219B53150070B9AA /* EditableImageController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5875BD219B53150070B9AA /* EditableImageController.h */; };
    607608                2D5C9D0619C81D8F00B3C5C1 /* WebPageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */; };
    608609                2D6AB541192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D6AB53F192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h */; };
     
    25382539                2D54C305212F3B330049C174 /* UnifiedSource62-mm.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = "UnifiedSource62-mm.mm"; path = "DerivedSources/WebKit2/unified-sources/UnifiedSource62-mm.mm"; sourceTree = BUILT_PRODUCTS_DIR; };
    25392540                2D54C306212F3B330049C174 /* UnifiedSource61-mm.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = "UnifiedSource61-mm.mm"; path = "DerivedSources/WebKit2/unified-sources/UnifiedSource61-mm.mm"; sourceTree = BUILT_PRODUCTS_DIR; };
     2541                2D5875BB219B28A50070B9AA /* EditableImageController.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = EditableImageController.messages.in; path = ios/EditableImageController.messages.in; sourceTree = "<group>"; };
     2542                2D5875BD219B53150070B9AA /* EditableImageController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditableImageController.h; path = ios/EditableImageController.h; sourceTree = "<group>"; };
     2543                2D5875BE219B53150070B9AA /* EditableImageController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = EditableImageController.mm; path = ios/EditableImageController.mm; sourceTree = "<group>"; };
    25402544                2D5C9D0319C81D8F00B3C5C1 /* WebPageOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageOverlay.cpp; sourceTree = "<group>"; };
    25412545                2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageOverlay.h; sourceTree = "<group>"; };
     
    57905794                                F496A42F1F58A272004C1757 /* DragDropInteractionState.h */,
    57915795                                F496A4301F58A272004C1757 /* DragDropInteractionState.mm */,
     5796                                2D5875BD219B53150070B9AA /* EditableImageController.h */,
     5797                                2D5875BB219B28A50070B9AA /* EditableImageController.messages.in */,
     5798                                2D5875BE219B53150070B9AA /* EditableImageController.mm */,
    57925799                                2DD45ADC1E5F8972006C355F /* InputViewUpdateDeferrer.h */,
    57935800                                2DD45ADD1E5F8972006C355F /* InputViewUpdateDeferrer.mm */,
     
    89918998                                1A64230912DD09EB00CAAE2C /* DrawingAreaProxyMessages.h in Headers */,
    89928999                                2DA6731A20C754B1003CB401 /* DynamicViewportSizeUpdate.h in Headers */,
     9000                                2D5875BF219B53150070B9AA /* EditableImageController.h in Headers */,
    89939001                                E105FE5418D7B9DE008F57A8 /* EditingRange.h in Headers */,
    89949002                                1AA41AB512C02EC4002BE67B /* EditorState.h in Headers */,
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h

    r238322 r238538  
    179179
    180180    Seconds eventThrottlingDelay() final;
     181
     182    void associateEditableImageWithAttachment(WebCore::GraphicsLayer::EmbeddedViewID, const String& attachmentID) final;
     183    void didCreateEditableImage(WebCore::GraphicsLayer::EmbeddedViewID) final;
     184    void didDestroyEditableImage(WebCore::GraphicsLayer::EmbeddedViewID) final;
    181185#endif
    182186
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm

    r237266 r238538  
    3030
    3131#import "DrawingArea.h"
     32#import "EditableImageControllerMessages.h"
    3233#import "UIKitSPI.h"
    3334#import "WebCoreArgumentCoders.h"
     
    160161}
    161162
     163void WebChromeClient::associateEditableImageWithAttachment(GraphicsLayer::EmbeddedViewID embeddedViewID, const String& attachmentID)
     164{
     165#if HAVE(PENCILKIT)
     166    m_page.send(Messages::EditableImageController::AssociateWithAttachment(embeddedViewID, attachmentID));
     167#else
     168    UNUSED_PARAM(embeddedViewID);
     169    UNUSED_PARAM(attachmentID);
     170#endif
     171}
     172
     173void WebChromeClient::didCreateEditableImage(GraphicsLayer::EmbeddedViewID embeddedViewID)
     174{
     175#if HAVE(PENCILKIT)
     176    m_page.send(Messages::EditableImageController::DidCreateEditableImage(embeddedViewID));
     177#else
     178    UNUSED_PARAM(embeddedViewID);
     179#endif
     180}
     181
     182void WebChromeClient::didDestroyEditableImage(GraphicsLayer::EmbeddedViewID embeddedViewID)
     183{
     184#if HAVE(PENCILKIT)
     185    m_page.send(Messages::EditableImageController::DidDestroyEditableImage(embeddedViewID));
     186#else
     187    UNUSED_PARAM(embeddedViewID);
     188#endif
     189}
     190
    162191} // namespace WebKit
    163192
  • trunk/Tools/ChangeLog

    r238535 r238538  
     12018-11-26  Tim Horton  <timothy_horton@apple.com>
     2
     3        Insert <attachment> elements under editable images to make their backing data accessible
     4        https://bugs.webkit.org/show_bug.cgi?id=191844
     5        <rdar://problem/30900149>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     10        (WTR::UIScriptController::attachmentInfo):
     11        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     12        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     13        (WTR::UIScriptController::attachmentInfo):
     14        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     15        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     16        (WTR::UIScriptController::attachmentInfo):
     17        Add a UIScriptController mechanism to retrieve information about
     18        a given attachment.
     19
    1202018-11-26  Aakash Jain  <aakash_jain@apple.com>
    221
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r238512 r238538  
    428428}
    429429
     430JSObjectRef UIScriptController::attachmentInfo(JSStringRef)
     431{
     432    return nullptr;
     433}
     434
    430435}
    431436
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r238512 r238538  
    287287    void drawSquareInEditableImage();
    288288    readonly attribute long numberOfStrokesInEditableImage;
     289
     290    object attachmentInfo(DOMString attachmentIdentifier);
    289291};
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r238512 r238538  
    502502}
    503503
     504JSObjectRef UIScriptController::attachmentInfo(JSStringRef)
     505{
     506    return nullptr;
     507}
     508
    504509#endif
    505510
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r238512 r238538  
    201201    long numberOfStrokesInEditableImage();
    202202
     203    JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier);
     204
    203205private:
    204206    UIScriptController(UIScriptContext&);
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r238526 r238538  
    932932}
    933933
     934JSObjectRef UIScriptController::attachmentInfo(JSStringRef jsAttachmentIdentifier)
     935{
     936    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     937
     938    auto attachmentIdentifier = toWTFString(toWK(jsAttachmentIdentifier));
     939    _WKAttachment *attachment = [webView _attachmentForIdentifier:attachmentIdentifier];
     940    _WKAttachmentInfo *attachmentInfo = attachment.info;
     941
     942    NSDictionary *attachmentInfoDictionary = @{
     943        @"id": attachmentIdentifier,
     944        @"name": attachmentInfo.name,
     945        @"contentType": attachmentInfo.contentType,
     946        @"filePath": attachmentInfo.filePath,
     947        @"size": @(attachmentInfo.data.length),
     948    };
     949
     950    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:attachmentInfoDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
     951}
     952
    934953}
    935954
Note: See TracChangeset for help on using the changeset viewer.