Changeset 238538 in webkit
- Timestamp:
- Nov 26, 2018 5:37:22 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 30 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r238526 r238538 1 2018-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 1 15 2018-11-26 Daniel Bates <dabates@apple.com> 2 16 -
trunk/LayoutTests/resources/ui-helper.js
r238526 r238538 455 455 }); 456 456 } 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 } 457 471 } -
trunk/Source/WebCore/ChangeLog
r238528 r238538 1 2018-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 1 61 2018-11-26 Jer Noble <jer.noble@apple.com> 2 62 -
trunk/Source/WebCore/Sources.txt
r238475 r238538 1420 1420 page/DisabledAdaptations.cpp 1421 1421 page/DragController.cpp 1422 page/EditableImageReference.cpp 1422 1423 page/EventHandler.cpp 1423 1424 page/EventSource.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r238475 r238538 734 734 2D29ECC8192ECC8300984B78 /* DisplayRefreshMonitorManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D29ECC4192ECC8300984B78 /* DisplayRefreshMonitorManager.h */; settings = {ATTRIBUTES = (Private, ); }; }; 735 735 2D29ECCA192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D29ECC9192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h */; }; 736 2D2E34AC21A4E192004598B5 /* EditableImageReference.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2E34A921A4E191004598B5 /* EditableImageReference.h */; }; 736 737 2D3A0E3613A7D76100E85AF0 /* SVGParsingError.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3A0E3513A7D76100E85AF0 /* SVGParsingError.h */; settings = {ATTRIBUTES = (Private, ); }; }; 737 738 2D3EF4481917915C00034184 /* WebActionDisablingCALayerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3EF4441917915C00034184 /* WebActionDisablingCALayerDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 6613 6614 2D29ECC4192ECC8300984B78 /* DisplayRefreshMonitorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitorManager.h; sourceTree = "<group>"; }; 6614 6615 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>"; }; 6615 6618 2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossfadeGeneratedImage.cpp; sourceTree = "<group>"; }; 6616 6619 2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossfadeGeneratedImage.h; sourceTree = "<group>"; }; … … 19989 19992 A7CA595B0B27BD9E00FA021D /* DragController.h */, 19990 19993 81F65FF513788FAA00FF6F2D /* DragState.h */, 19994 2D2E34AB21A4E192004598B5 /* EditableImageReference.cpp */, 19995 2D2E34A921A4E191004598B5 /* EditableImageReference.h */, 19991 19996 1AF326770D78B9440068F0C4 /* EditorClient.h */, 19992 19997 93C09A800B064F00005ABD4D /* EventHandler.cpp */, … … 28644 28649 FD537357137B653B00008DCE /* DynamicsCompressorKernel.h in Headers */, 28645 28650 FD6ED2C4136B8E42003CF072 /* DynamicsCompressorNode.h in Headers */, 28651 2D2E34AC21A4E192004598B5 /* EditableImageReference.h in Headers */, 28646 28652 93309DE2099E64920056E581 /* EditAction.h in Headers */, 28647 28653 93309DE4099E64920056E581 /* EditCommand.h in Headers */, -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r238108 r238538 27 27 #include "CSSValueKeywords.h" 28 28 #include "CachedImage.h" 29 #include "Chrome.h" 30 #include "ChromeClient.h" 31 #include "EditableImageReference.h" 32 #include "Editor.h" 29 33 #include "ElementIterator.h" 30 34 #include "FrameView.h" … … 239 243 updateImageControls(); 240 244 #endif 241 } else { 245 } else if (name == x_apple_editable_imageAttr) 246 updateEditableImage(isConnected() ? IsConnectedToDocument::Yes : IsConnectedToDocument::No); 247 else { 242 248 if (name == nameAttr) { 243 249 bool willHaveName = !value.isNull(); … … 327 333 m_form->registerImgElement(this); 328 334 } 335 336 if (insertionType.connectedToDocument) 337 updateEditableImage(IsConnectedToDocument::Yes); 338 329 339 // Insert needs to complete first, before we start updating the loader. Loader dispatches events which could result 330 340 // in callbacks back to this node. … … 358 368 setPictureElement(nullptr); 359 369 370 if (removalType.disconnectedFromDocument) 371 updateEditableImage(IsConnectedToDocument::No); 372 360 373 m_form = nullptr; 361 374 HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree); 375 } 376 377 GraphicsLayer::EmbeddedViewID HTMLImageElement::editableImageViewID() const 378 { 379 if (!m_editableImage) 380 return 0; 381 return m_editableImage->embeddedViewID(); 382 } 383 384 void 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 362 424 } 363 425 … … 634 696 const String& HTMLImageElement::attachmentIdentifier() const 635 697 { 698 if (!m_pendingClonedAttachmentID.isEmpty()) 699 return m_pendingClonedAttachmentID; 700 636 701 if (auto attachment = attachmentElement()) 637 702 return attachment->uniqueIdentifier(); … … 738 803 #endif 739 804 740 GraphicsLayer::EmbeddedViewID HTMLImageElement::editableImageViewID() const 741 { 742 if (!m_editableImageViewID) 743 m_editableImageViewID = GraphicsLayer::nextEmbeddedViewID(); 744 return m_editableImageViewID; 745 } 746 747 } 805 void 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 33 33 namespace WebCore { 34 34 35 class EditableImageReference; 35 36 class HTMLAttachmentElement; 36 37 class HTMLFormElement; … … 153 154 ImageCandidate bestFitSourceFromPictureElement(); 154 155 156 enum class IsConnectedToDocument : bool { No, Yes }; 157 void updateEditableImage(IsConnectedToDocument); 158 159 void copyNonAttributePropertiesFromElement(const Element&) final; 160 155 161 #if ENABLE(SERVICE_CONTROLS) 156 162 void updateImageControls(); … … 173 179 bool m_hadNameBeforeAttributeChanged { false }; // FIXME: We only need this because parseAttribute() can't see the old value. 174 180 175 mutable GraphicsLayer::EmbeddedViewID m_editableImageViewID { 0 }; 181 RefPtr<EditableImageReference> m_editableImage; 182 #if ENABLE(ATTACHMENT_ELEMENT) 183 String m_pendingClonedAttachmentID; 184 #endif 176 185 177 186 friend class HTMLPictureElement; -
trunk/Source/WebCore/page/ChromeClient.h
r238322 r238538 31 31 #include "FrameLoader.h" 32 32 #include "GraphicsContext.h" 33 #include "GraphicsLayer.h" 33 34 #include "HTMLMediaElementEnums.h" 34 35 #include "HostWindow.h" … … 490 491 virtual String signedPublicKeyAndChallengeString(unsigned, const String&, const URL&) const { return emptyString(); } 491 492 493 virtual void associateEditableImageWithAttachment(GraphicsLayer::EmbeddedViewID, const String&) { } 494 virtual void didCreateEditableImage(GraphicsLayer::EmbeddedViewID) { } 495 virtual void didDestroyEditableImage(GraphicsLayer::EmbeddedViewID) { } 496 492 497 protected: 493 498 virtual ~ChromeClient() = default; -
trunk/Source/WebCore/page/NavigatorBase.cpp
r237990 r238538 28 28 #include "NavigatorBase.h" 29 29 30 #include "Document.h" 30 31 #include "ServiceWorkerContainer.h" 31 32 #include <mutex> -
trunk/Source/WebKit/ChangeLog
r238528 r238538 1 2018-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 1 90 2018-11-26 Jer Noble <jer.noble@apple.com> 2 91 -
trunk/Source/WebKit/DerivedSources.make
r238008 r238538 105 105 DrawingArea \ 106 106 DrawingAreaProxy \ 107 EditableImageController \ 107 108 EventDispatcher \ 108 109 LegacyCustomProtocolManager \ -
trunk/Source/WebKit/SourcesCocoa.txt
r238515 r238538 369 369 370 370 UIProcess/ios/DragDropInteractionState.mm 371 UIProcess/ios/EditableImageController.mm 371 372 UIProcess/ios/InputViewUpdateDeferrer.mm 372 373 UIProcess/ios/PageClientImplIOS.mm … … 557 558 WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm @no-unify 558 559 WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm 560 561 // Derived Sources 562 563 EditableImageControllerMessageReceiver.cpp -
trunk/Source/WebKit/UIProcess/API/APIAttachment.h
r237624 r238538 61 61 62 62 #if PLATFORM(COCOA) 63 NSFileWrapper *fileWrapper() const { return m_fileWrapper.get(); }63 NSFileWrapper *fileWrapper() const; 64 64 void setFileWrapper(NSFileWrapper *fileWrapper) { m_fileWrapper = fileWrapper; } 65 65 void setFileWrapperAndUpdateContentType(NSFileWrapper *, NSString *contentType); 66 void setFileWrapperGenerator(Function<RetainPtr<NSFileWrapper>(void)>&&); 67 void invalidateGeneratedFileWrapper(); 66 68 WTF::String utiType() const; 67 69 #endif … … 93 95 94 96 #if PLATFORM(COCOA) 95 RetainPtr<NSFileWrapper> m_fileWrapper; 97 mutable RetainPtr<NSFileWrapper> m_fileWrapper; 98 Function<RetainPtr<NSFileWrapper>(void)> m_fileWrapperGenerator; 96 99 #endif 97 100 WTF::String m_identifier; -
trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm
r237667 r238538 54 54 } 55 55 56 NSFileWrapper *Attachment::fileWrapper() const 57 { 58 if (m_fileWrapperGenerator && !m_fileWrapper) 59 m_fileWrapper = m_fileWrapperGenerator(); 60 return m_fileWrapper.get(); 61 } 62 63 void Attachment::invalidateGeneratedFileWrapper() 64 { 65 ASSERT(m_fileWrapperGenerator); 66 m_fileWrapper = nil; 67 } 68 56 69 WTF::String Attachment::mimeType() const 57 70 { … … 74 87 WTF::String Attachment::fileName() const 75 88 { 76 if ([m_fileWrapper filename].length) 77 return [m_fileWrapper filename]; 89 auto fileWrapper = this->fileWrapper(); 78 90 79 return [m_fileWrapper preferredFilename]; 91 if ([fileWrapper filename].length) 92 return [fileWrapper filename]; 93 94 return [fileWrapper preferredFilename]; 80 95 } 81 96 … … 99 114 std::optional<uint64_t> Attachment::fileSizeForDisplay() const 100 115 { 101 if (![m_fileWrapper isRegularFile]) { 116 auto fileWrapper = this->fileWrapper(); 117 118 if (![fileWrapper isRegularFile]) { 102 119 // FIXME: We should display a size estimate for directory-type file wrappers. 103 120 return std::nullopt; 104 121 } 105 122 106 if (auto fileSize = [[ m_fileWrapper fileAttributes][NSFileSize] unsignedLongLongValue])123 if (auto fileSize = [[fileWrapper fileAttributes][NSFileSize] unsignedLongLongValue]) 107 124 return fileSize; 108 125 109 return [ m_fileWrapper regularFileContents].length;126 return [fileWrapper regularFileContents].length; 110 127 } 111 128 … … 115 132 return nullptr; 116 133 117 if (![m_fileWrapper isRegularFile]) 134 auto fileWrapper = this->fileWrapper(); 135 136 if (![fileWrapper isRegularFile]) 118 137 return nullptr; 119 138 120 NSData *data = [ m_fileWrapper regularFileContents];139 NSData *data = [fileWrapper regularFileContents]; 121 140 if (!data) 122 141 return nullptr; … … 127 146 bool Attachment::isEmpty() const 128 147 { 129 return !m_fileWrapper ;148 return !m_fileWrapper && !m_fileWrapperGenerator; 130 149 } 131 150 132 151 RefPtr<WebCore::SharedBuffer> Attachment::createSerializedRepresentation() const 133 152 { 134 if (!m_fileWrapper || !m_webPage) 153 auto fileWrapper = this->fileWrapper(); 154 155 if (!fileWrapper || !m_webPage) 135 156 return nullptr; 136 157 137 158 #if CAN_SECURELY_ARCHIVE_FILE_WRAPPER 138 NSData *serializedData = securelyArchivedDataWithRootObject( m_fileWrapper.get());159 NSData *serializedData = securelyArchivedDataWithRootObject(fileWrapper); 139 160 #else 140 NSData *serializedData = insecurelyArchivedDataWithRootObject( m_fileWrapper.get());161 NSData *serializedData = insecurelyArchivedDataWithRootObject(fileWrapper); 141 162 #endif 142 163 … … 169 190 } 170 191 192 void Attachment::setFileWrapperGenerator(Function<RetainPtr<NSFileWrapper>(void)>&& fileWrapperGenerator) 193 { 194 m_fileWrapperGenerator = WTFMove(fileWrapperGenerator); 195 m_fileWrapper = nil; 196 } 197 171 198 } // namespace API -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm
r238476 r238538 29 29 #if PLATFORM(IOS_FAMILY) 30 30 31 #import "EditableImageController.h" 31 32 #import "RemoteLayerTreeDrawingAreaProxy.h" 32 33 #import "RemoteLayerTreeViews.h" … … 124 125 RetainPtr<WKEmbeddedView> RemoteLayerTreeHost::createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties& properties) 125 126 { 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) 138 128 return adoptNS([[UIView alloc] init]); 139 129 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 } 142 141 }); 143 142 auto view = result.iterator->value; 144 143 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])); 148 145 m_layerToEmbeddedViewMap.set(properties.layerID, properties.embeddedViewID); 149 146 return view; -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.h
r238108 r238538 30 30 #import "UIKitSPI.h" 31 31 #import <WebCore/GraphicsLayer.h> 32 33 namespace WebKit { 34 class WebPageProxy; 35 } 32 36 33 37 @protocol WKNativelyInteractible <NSObject> … … 63 67 @interface WKEmbeddedView : UIView 64 68 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; 67 72 68 73 @end -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm
r238476 r238538 203 203 204 204 @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 205 217 @end 206 218 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r238471 r238538 234 234 #endif 235 235 236 #if HAVE(PENCILKIT) 237 #include "EditableImageController.h" 238 #endif 239 236 240 // This controls what strategy we use for mouse wheel coalescing. 237 241 #define MERGE_WHEEL_EVENTS 1 … … 437 441 #endif 438 442 , m_resetRecentCrashCountTimer(RunLoop::main(), this, &WebPageProxy::resetRecentCrashCount) 443 #if HAVE(PENCILKIT) 444 , m_editableImageController(std::make_unique<EditableImageController>(*this)) 445 #endif 439 446 { 440 447 m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore); -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r238475 r238538 218 218 namespace WebKit { 219 219 class DrawingAreaProxy; 220 class EditableImageController; 220 221 class NativeWebGestureEvent; 221 222 class NativeWebKeyboardEvent; … … 1369 1370 void updateAttachmentAttributes(const API::Attachment&, Function<void(CallbackBase::Error)>&&); 1370 1371 void serializedAttachmentDataForIdentifiers(const Vector<String>&, Vector<WebCore::SerializedAttachmentData>&); 1372 void registerAttachmentIdentifier(const String&); 1371 1373 #endif 1372 1374 … … 1389 1391 1390 1392 void updateCurrentModifierState(); 1393 1394 #if HAVE(PENCILKIT) 1395 EditableImageController& editableImageController() { return *m_editableImageController; } 1396 #endif 1391 1397 1392 1398 private: … … 1854 1860 void registerAttachmentIdentifierFromFilePath(const String&, const String& contentType, const String& filePath); 1855 1861 void registerAttachmentsFromSerializedData(Vector<WebCore::SerializedAttachmentData>&&); 1856 void registerAttachmentIdentifier(const String&);1857 1862 void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier); 1858 1863 … … 2281 2286 2282 2287 bool m_needsFontAttributes { false }; 2288 2289 #if HAVE(PENCILKIT) 2290 std::unique_ptr<EditableImageController> m_editableImageController; 2291 #endif 2283 2292 }; 2284 2293 -
trunk/Source/WebKit/UIProcess/ios/EditableImageController.h
r238535 r238538 24 24 */ 25 25 26 #import "config.h" 27 #import "WKDrawingView.h" 26 #pragma once 28 27 29 28 #if HAVE(PENCILKIT) 30 29 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> 33 36 34 SOFT_LINK_PRIVATE_FRAMEWORK(PencilKit); 35 SOFT_LINK_CLASS(PencilKit, PKCanvasView); 37 OBJC_CLASS WKDrawingView; 36 38 37 @implementation WKDrawingView { 38 RetainPtr<PKCanvasView> _pencilView; 39 } 39 namespace WebKit { 40 40 41 - (id)init 42 { 43 self = [super init]; 44 if (!self) 45 return nil; 41 class WebPageProxy; 46 42 47 _pencilView = adoptNS([allocPKCanvasViewInstance() initWithFrame:CGRectZero]); 43 struct EditableImage { 44 RetainPtr<WKDrawingView> drawingView; 45 String attachmentID; 46 }; 48 47 49 [_pencilView setFingerDrawingEnabled:NO]; 50 [_pencilView setUserInteractionEnabled:YES]; 51 [_pencilView setOpaque:NO]; 48 class EditableImageController : private IPC::MessageReceiver { 49 WTF_MAKE_NONCOPYABLE(EditableImageController); 50 public: 51 explicit EditableImageController(WebPageProxy&); 52 ~EditableImageController(); 52 53 53 [self addSubview:_pencilView.get()]; 54 // IPC::MessageReceiver. 55 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; 54 56 55 return self;56 } 57 EditableImage* editableImage(WebCore::GraphicsLayer::EmbeddedViewID); 58 EditableImage& ensureEditableImage(WebCore::GraphicsLayer::EmbeddedViewID); 57 59 58 - (void)layoutSubviews 59 { 60 [_pencilView setFrame:self.bounds]; 61 } 60 void invalidateAttachmentForEditableImage(WebCore::GraphicsLayer::EmbeddedViewID); 62 61 63 @end 62 private: 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 64 74 65 75 #endif // HAVE(PENCILKIT) -
trunk/Source/WebKit/UIProcess/ios/WKDrawingView.h
r238108 r238538 31 31 @interface WKDrawingView : WKEmbeddedView <WKNativelyInteractible> 32 32 33 - (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy; 34 35 - (NSData *)PNGRepresentation; 36 33 37 @end 34 38 -
trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm
r238474 r238538 29 29 #if HAVE(PENCILKIT) 30 30 31 #import "EditableImageController.h" 31 32 #import "PencilKitSPI.h" 33 #import <wtf/OSObjectPtr.h> 32 34 #import <wtf/RetainPtr.h> 33 35 34 36 SOFT_LINK_PRIVATE_FRAMEWORK(PencilKit); 35 37 SOFT_LINK_CLASS(PencilKit, PKCanvasView); 38 SOFT_LINK_CLASS(PencilKit, PKImageRenderer); 39 40 @interface WKDrawingView () <PKCanvasViewDelegate> 41 @end 36 42 37 43 @implementation WKDrawingView { 38 44 RetainPtr<PKCanvasView> _pencilView; 45 46 OSObjectPtr<dispatch_queue_t> _renderQueue; 47 RetainPtr<PKImageRenderer> _renderer; 48 49 WeakPtr<WebKit::WebPageProxy> _webPageProxy; 39 50 } 40 51 41 - (i d)init52 - (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy 42 53 { 43 self = [super init ];54 self = [super initWithEmbeddedViewID:embeddedViewID]; 44 55 if (!self) 45 56 return nil; 57 58 _webPageProxy = makeWeakPtr(webPageProxy); 46 59 47 60 _pencilView = adoptNS([allocPKCanvasViewInstance() initWithFrame:CGRectZero]); … … 50 63 [_pencilView setUserInteractionEnabled:YES]; 51 64 [_pencilView setOpaque:NO]; 65 [_pencilView setDrawingDelegate:self]; 52 66 53 67 [self addSubview:_pencilView.get()]; … … 58 72 - (void)layoutSubviews 59 73 { 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); 61 111 } 62 112 -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r238515 r238538 605 605 2D54C31A212F3B330049C174 /* UnifiedSource61-mm.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D54C306212F3B330049C174 /* UnifiedSource61-mm.mm */; }; 606 606 2D54C31B212F4DA60049C174 /* ProcessLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE117F511DBB30900981615 /* ProcessLauncher.cpp */; }; 607 2D5875BF219B53150070B9AA /* EditableImageController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5875BD219B53150070B9AA /* EditableImageController.h */; }; 607 608 2D5C9D0619C81D8F00B3C5C1 /* WebPageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */; }; 608 609 2D6AB541192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D6AB53F192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h */; }; … … 2538 2539 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; }; 2539 2540 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>"; }; 2540 2544 2D5C9D0319C81D8F00B3C5C1 /* WebPageOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageOverlay.cpp; sourceTree = "<group>"; }; 2541 2545 2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageOverlay.h; sourceTree = "<group>"; }; … … 5790 5794 F496A42F1F58A272004C1757 /* DragDropInteractionState.h */, 5791 5795 F496A4301F58A272004C1757 /* DragDropInteractionState.mm */, 5796 2D5875BD219B53150070B9AA /* EditableImageController.h */, 5797 2D5875BB219B28A50070B9AA /* EditableImageController.messages.in */, 5798 2D5875BE219B53150070B9AA /* EditableImageController.mm */, 5792 5799 2DD45ADC1E5F8972006C355F /* InputViewUpdateDeferrer.h */, 5793 5800 2DD45ADD1E5F8972006C355F /* InputViewUpdateDeferrer.mm */, … … 8991 8998 1A64230912DD09EB00CAAE2C /* DrawingAreaProxyMessages.h in Headers */, 8992 8999 2DA6731A20C754B1003CB401 /* DynamicViewportSizeUpdate.h in Headers */, 9000 2D5875BF219B53150070B9AA /* EditableImageController.h in Headers */, 8993 9001 E105FE5418D7B9DE008F57A8 /* EditingRange.h in Headers */, 8994 9002 1AA41AB512C02EC4002BE67B /* EditorState.h in Headers */, -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
r238322 r238538 179 179 180 180 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; 181 185 #endif 182 186 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm
r237266 r238538 30 30 31 31 #import "DrawingArea.h" 32 #import "EditableImageControllerMessages.h" 32 33 #import "UIKitSPI.h" 33 34 #import "WebCoreArgumentCoders.h" … … 160 161 } 161 162 163 void 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 173 void 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 182 void 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 162 191 } // namespace WebKit 163 192 -
trunk/Tools/ChangeLog
r238535 r238538 1 2018-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 1 20 2018-11-26 Aakash Jain <aakash_jain@apple.com> 2 21 -
trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
r238512 r238538 428 428 } 429 429 430 JSObjectRef UIScriptController::attachmentInfo(JSStringRef) 431 { 432 return nullptr; 433 } 434 430 435 } 431 436 -
trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
r238512 r238538 287 287 void drawSquareInEditableImage(); 288 288 readonly attribute long numberOfStrokesInEditableImage; 289 290 object attachmentInfo(DOMString attachmentIdentifier); 289 291 }; -
trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
r238512 r238538 502 502 } 503 503 504 JSObjectRef UIScriptController::attachmentInfo(JSStringRef) 505 { 506 return nullptr; 507 } 508 504 509 #endif 505 510 -
trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
r238512 r238538 201 201 long numberOfStrokesInEditableImage(); 202 202 203 JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier); 204 203 205 private: 204 206 UIScriptController(UIScriptContext&); -
trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
r238526 r238538 932 932 } 933 933 934 JSObjectRef 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 934 953 } 935 954
Note: See TracChangeset
for help on using the changeset viewer.