WebKit Bugzilla
Attachment 348112 Details for
Bug 188903
: [Cocoa] Exception (fileType 'dyn.agq8u' is not a valid UTI) raised when dragging an attachment whose file wrapper is a directory
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Rebase on trunk
bug-188903-20180826195535.patch (text/plain), 51.11 KB, created by
Wenson Hsieh
on 2018-08-26 19:55:36 PDT
(
hide
)
Description:
Rebase on trunk
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-08-26 19:55:36 PDT
Size:
51.11 KB
patch
obsolete
>Subversion Revision: 235347 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 55f02363367dba45739ecd7bb21de33451688123..9327f997ad87517c73e6987dc1eaf0f649b48e19 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,45 @@ >+2018-08-26 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [Cocoa] Exception (fileType 'dyn.agq8u' is not a valid UTI) raised when dragging an attachment whose file wrapper is a directory >+ https://bugs.webkit.org/show_bug.cgi?id=188903 >+ <rdar://problem/43702993> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Fixes the exception for attachments that are created when dropping files with extensions that don't map to any >+ known UTIs, and when dropping folders. See below for more detail. >+ >+ Tests: WKAttachmentTests.InsertFolderAndFileWithUnknownExtension >+ WKAttachmentTests.DropFolderAsAttachmentAndMoveByDragging >+ WKAttachmentTests.ChangeAttachmentDataAndFileInformation >+ >+ * editing/Editor.cpp: >+ (WebCore::Editor::insertAttachment): >+ * editing/Editor.h: >+ * editing/cocoa/WebContentReaderCocoa.mm: >+ (WebCore::WebContentReader::readFilePaths): >+ >+ When creating an attachment by dropping or pasting a file backed by a file path, handle the cases where⦠>+ (1) the dropped path is a directory, by setting the UTI to "public.directory". This allows us to show a >+ folder icon for the dropped attachment element on macOS. >+ (2) the dropped path is a file whose UTI is unknown, by defaulting to "public.data". >+ >+ By ensuring that the UTI of a dropped file-backed attachment is set to a concrete type in any case, we avoid an >+ exception when dragging the attachment on macOS, and on iOS, avoid silently failing to drag an attachment. >+ >+ * html/HTMLAttachmentElement.cpp: >+ (WebCore::HTMLAttachmentElement::updateAttributes): >+ >+ Change this method to take an optional file size (the subtitle attribute will only be set if the file size is >+ not `std::nullopt`). Furthermore, allow callers of this method to clear attributes on the attachment element by >+ passing in `std::nullopt` for any of the three arguments. This allows us to handle the case where an >+ attachment's file wrapper is changed from a regular file to a folder whose total size is currently unknown. >+ Instead of showing "0 bytes", we'll simply refrain from showing a subtitle at all (in the future, this should >+ be improved by implementing a way to estimate the size of the files in the folder, or perhaps show the number of >+ items in the folder as the subtitle). >+ >+ * html/HTMLAttachmentElement.h: >+ > 2018-08-26 Youenn Fablet <youenn@apple.com> > > Make IDBCursor::m_request a WeakPtr >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 5243277f4dc09d92b8d72a299a3dce2c9fb2a07d..7b404ebb855295cbd60f7af81ce9ff3014ec5775 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,71 @@ >+2018-08-26 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [Cocoa] Exception (fileType 'dyn.agq8u' is not a valid UTI) raised when dragging an attachment whose file wrapper is a directory >+ https://bugs.webkit.org/show_bug.cgi?id=188903 >+ <rdar://problem/43702993> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Fixes the bug by supporting NSFileWrappers of type directory, as well as NSFileWrappers with file that do not >+ map to concrete type identifiers. Among other things, this patch ensures that: >+ - Inserting a directory file wrapper (or using -setFileWrapper:â¦: to change an existing _WKAttachment's >+ file wrapper to a directory) does not cause the attachment element to show "0 bytes" as the subtitle. >+ - In the above scenario, we also won't end up with a missing "type" attribute for the attachment element, >+ as well as a corresponding API::Attachment::contentType() that's an empty string. >+ - Dropping or pasting attachments backed by paths on disk also doesn't trigger these problems, if the path >+ is a directory or of unknown file type. >+ >+ Changes are verified by 2 new API tests. >+ >+ * UIProcess/API/APIAttachment.cpp: >+ (API::Attachment::updateAttributes): >+ (API::Attachment::fileSizeForDisplay const): >+ * UIProcess/API/APIAttachment.h: >+ * UIProcess/API/Cocoa/APIAttachmentCocoa.mm: >+ (API::Attachment::setFileWrapperAndUpdateContentType): >+ >+ Add a helper that sets the file wrapper to the given NSFileWrapper, and either sets the content type to the >+ given content type if it's specified, or infers it from the file extension of the new NSFileWrapper. Invoked >+ whenever an NSFileWrapper and content type combination is set on an API attachment via WebKit SPI. >+ >+ (API::Attachment::fileSizeForDisplay const): >+ >+ Returns a file size to be displayed in the attachment element's subtitle. This returns an optional file size, >+ where `std::nullopt` indicates that there should not be a file size shown. For now, this returns `std::nullopt` >+ for directory file wrappers, though in the future, this should be done only in cases where we don't immediately >+ have a size estimate for the file wrapper. >+ >+ * UIProcess/API/Cocoa/WKWebView.mm: >+ (-[WKWebView _insertAttachmentWithFileWrapper:contentType:options:completion:]): >+ >+ Use API::Attachment::setFileWrapperAndUpdateContentType() instead of trying to come up with a fallback UTI. >+ >+ * UIProcess/API/Cocoa/_WKAttachment.mm: >+ (-[_WKAttachment setFileWrapper:contentType:completion:]): >+ >+ Use API::Attachment::setFileWrapperAndUpdateContentType() instead of trying to come up with a fallback UTI. >+ >+ * UIProcess/WebPageProxy.cpp: >+ (WebKit::WebPageProxy::insertAttachment): >+ >+ Remove the separate arguments for file size, content type, and file name, and instead get them from the given >+ API Attachment object. >+ >+ (WebKit::WebPageProxy::updateAttachmentAttributes): >+ >+ Remove separate arguments for file size, content type and file name and just take an API::Attachment instead. >+ These separate pieces of information can simply be asked from the Attachment itself. >+ >+ * UIProcess/WebPageProxy.h: >+ * WebProcess/WebPage/WebPage.cpp: >+ (WebKit::WebPage::insertAttachment): >+ (WebKit::WebPage::updateAttachmentAttributes): >+ >+ Adjust some interfaces here to allow the displayed file size to be optional. >+ >+ * WebProcess/WebPage/WebPage.h: >+ * WebProcess/WebPage/WebPage.messages.in: >+ > 2018-08-26 Sam Weinig <sam@webkit.org> > > Using _WKRemoteObjectInterface with a protocol that inherits from a non-NSObject protocol crashes >diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp >index 176a4a0528bc59facba2f113b5e6426d8f3d6b31..4eca9150d6a7990dec2741ca36d4c68a9f57567a 100644 >--- a/Source/WebCore/editing/Editor.cpp >+++ b/Source/WebCore/editing/Editor.cpp >@@ -3876,11 +3876,11 @@ void Editor::notifyClientOfAttachmentUpdates() > } > } > >-void Editor::insertAttachment(const String& identifier, const AttachmentDisplayOptions&, uint64_t fileSize, const String& fileName, std::optional<String>&& explicitContentType) >+void Editor::insertAttachment(const String& identifier, const AttachmentDisplayOptions&, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType) > { > auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document()); > attachment->setUniqueIdentifier(identifier); >- attachment->updateAttributes(fileSize, WTFMove(explicitContentType), fileName); >+ attachment->updateAttributes(WTFMove(fileSize), contentType, fileName); > > auto fragmentToInsert = document().createDocumentFragment(); > fragmentToInsert->appendChild(attachment.get()); >diff --git a/Source/WebCore/editing/Editor.h b/Source/WebCore/editing/Editor.h >index 1ec120bef33da8ecab5e894ab55efaab95128cac..6f5abbac2da99699e7a52e500bded4bfe46d1280 100644 >--- a/Source/WebCore/editing/Editor.h >+++ b/Source/WebCore/editing/Editor.h >@@ -503,7 +503,7 @@ public: > bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; } > > #if ENABLE(ATTACHMENT_ELEMENT) >- WEBCORE_EXPORT void insertAttachment(const String& identifier, const AttachmentDisplayOptions&, uint64_t fileSize, const String& fileName, std::optional<String>&& explicitContentType = std::nullopt); >+ WEBCORE_EXPORT void insertAttachment(const String& identifier, const AttachmentDisplayOptions&, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType); > void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* preferredFileName */, Ref<SharedBuffer>&&); > void registerAttachmentIdentifier(const String&, const String& /* contentType */, const String& /* filePath */); > void cloneAttachmentData(const String& fromIdentifier, const String& toIdentifier); >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index 1c91351b73af47f971b9ce17434c8d56b45a40d4..c883a2369ad36f7012cbc486cfad0bc02b04c43c 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -701,9 +701,18 @@ bool WebContentReader::readFilePaths(const Vector<String>& paths) > for (auto& path : paths) { > auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document); > if (supportsClientSideAttachmentData(frame)) { >- long long fileSize { 0 }; >- FileSystem::getFileSize(path, fileSize); >- auto contentType = File::contentTypeForFile(path); >+ String contentType; >+ std::optional<uint64_t> fileSizeForDisplay; >+ if (FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes)) >+ contentType = kUTTypeDirectory; >+ else { >+ long long fileSize; >+ FileSystem::getFileSize(path, fileSize); >+ fileSizeForDisplay = fileSize; >+ contentType = File::contentTypeForFile(path); >+ if (contentType.isEmpty()) >+ contentType = kUTTypeData; >+ } > frame.editor().registerAttachmentIdentifier(attachment->ensureUniqueIdentifier(), contentType, path); > if (contentTypeIsSuitableForInlineImageRepresentation(contentType)) { > auto image = HTMLImageElement::create(document); >@@ -711,7 +720,7 @@ bool WebContentReader::readFilePaths(const Vector<String>& paths) > image->setAttachmentElement(WTFMove(attachment)); > fragment->appendChild(image); > } else { >- attachment->updateAttributes(fileSize, contentType, FileSystem::pathGetFileName(path)); >+ attachment->updateAttributes(WTFMove(fileSizeForDisplay), contentType, FileSystem::pathGetFileName(path)); > fragment->appendChild(attachment); > } > } else { >diff --git a/Source/WebCore/html/HTMLAttachmentElement.cpp b/Source/WebCore/html/HTMLAttachmentElement.cpp >index 405cb3eb9e217be39265733bec7c5b6082a9eda1..3edbc51dad889ef6f8304b021a1d5254ca7cd866 100644 >--- a/Source/WebCore/html/HTMLAttachmentElement.cpp >+++ b/Source/WebCore/html/HTMLAttachmentElement.cpp >@@ -144,15 +144,23 @@ String HTMLAttachmentElement::attachmentPath() const > return attributeWithoutSynchronization(webkitattachmentpathAttr); > } > >-void HTMLAttachmentElement::updateAttributes(uint64_t fileSize, std::optional<String>&& newContentType, std::optional<String>&& newFilename) >+void HTMLAttachmentElement::updateAttributes(std::optional<uint64_t>&& newFileSize, std::optional<String>&& newContentType, std::optional<String>&& newFilename) > { > if (newFilename) > setAttributeWithoutSynchronization(HTMLNames::titleAttr, *newFilename); >+ else >+ removeAttribute(HTMLNames::titleAttr); > > if (newContentType) > setAttributeWithoutSynchronization(HTMLNames::typeAttr, *newContentType); >+ else >+ removeAttribute(HTMLNames::typeAttr); >+ >+ if (newFileSize) >+ setAttributeWithoutSynchronization(HTMLNames::subtitleAttr, fileSizeDescription(*newFileSize)); >+ else >+ removeAttribute(HTMLNames::subtitleAttr); > >- setAttributeWithoutSynchronization(HTMLNames::subtitleAttr, fileSizeDescription(fileSize)); > if (auto* renderer = this->renderer()) > renderer->invalidate(); > } >diff --git a/Source/WebCore/html/HTMLAttachmentElement.h b/Source/WebCore/html/HTMLAttachmentElement.h >index 5b64192bc56f94a36ec3d10a88257375e83f3b85..61ea15a928f0baa452e9dffe179acf4eed32762d 100644 >--- a/Source/WebCore/html/HTMLAttachmentElement.h >+++ b/Source/WebCore/html/HTMLAttachmentElement.h >@@ -49,7 +49,7 @@ public: > const String& uniqueIdentifier() const { return m_uniqueIdentifier; } > void setUniqueIdentifier(const String& uniqueIdentifier) { m_uniqueIdentifier = uniqueIdentifier; } > >- WEBCORE_EXPORT void updateAttributes(uint64_t fileSize, std::optional<String>&& newContentType = std::nullopt, std::optional<String>&& newFilename = std::nullopt); >+ WEBCORE_EXPORT void updateAttributes(std::optional<uint64_t>&& newFileSize = std::nullopt, std::optional<String>&& newContentType = std::nullopt, std::optional<String>&& newFilename = std::nullopt); > > InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final; > void removedFromAncestor(RemovalType, ContainerNode&) final; >diff --git a/Source/WebKit/UIProcess/API/APIAttachment.cpp b/Source/WebKit/UIProcess/API/APIAttachment.cpp >index b6150483de5f66adee7cc6f4abfd0e0365b6a432..073a44ce4486cafd62e25cbde8e9fbc93bcc7f46 100644 >--- a/Source/WebKit/UIProcess/API/APIAttachment.cpp >+++ b/Source/WebKit/UIProcess/API/APIAttachment.cpp >@@ -57,17 +57,14 @@ void Attachment::setDisplayOptions(WebCore::AttachmentDisplayOptions options, Fu > callback(WebKit::CallbackBase::Error::OwnerWasInvalidated); > } > >-void Attachment::updateAttributes(uint64_t fileSize, const WTF::String& newContentType, const WTF::String& newFilename, Function<void(WebKit::CallbackBase::Error)>&& callback) >+void Attachment::updateAttributes(Function<void(WebKit::CallbackBase::Error)>&& callback) > { >- setContentType(newContentType); >- setFilePath({ }); >- >- auto optionalNewContentType = newContentType.isNull() ? std::nullopt : std::optional<WTF::String> { newContentType }; >- auto optionalNewFilename = newFilename.isNull() ? std::nullopt : std::optional<WTF::String> { newFilename }; >- if (m_webPage) >- m_webPage->updateAttachmentAttributes(m_identifier, fileSize, WTFMove(optionalNewContentType), WTFMove(optionalNewFilename), WTFMove(callback)); >- else >+ if (!m_webPage) { > callback(WebKit::CallbackBase::Error::OwnerWasInvalidated); >+ return; >+ } >+ >+ m_webPage->updateAttachmentAttributes(*this, WTFMove(callback)); > } > > void Attachment::invalidate() >@@ -93,6 +90,11 @@ WTF::String Attachment::fileName() const > return { }; > } > >+std::optional<uint64_t> Attachment::fileSizeForDisplay() const >+{ >+ return std::nullopt; >+} >+ > #endif // !PLATFORM(COCOA) > > } >diff --git a/Source/WebKit/UIProcess/API/APIAttachment.h b/Source/WebKit/UIProcess/API/APIAttachment.h >index 71741ff4134dfa45e2add77248d789971f546384..8443f430bc9363b93b08a37a343210f0bcc2dfc4 100644 >--- a/Source/WebKit/UIProcess/API/APIAttachment.h >+++ b/Source/WebKit/UIProcess/API/APIAttachment.h >@@ -56,7 +56,7 @@ public: > > const WTF::String& identifier() const { return m_identifier; } > void setDisplayOptions(WebCore::AttachmentDisplayOptions, Function<void(WebKit::CallbackBase::Error)>&&); >- void updateAttributes(uint64_t fileSize, const WTF::String& newContentType, const WTF::String& newFilename, Function<void(WebKit::CallbackBase::Error)>&&); >+ void updateAttributes(Function<void(WebKit::CallbackBase::Error)>&&); > > void invalidate(); > bool isValid() const { return !!m_webPage; } >@@ -64,6 +64,7 @@ public: > #if PLATFORM(COCOA) > NSFileWrapper *fileWrapper() const { return m_fileWrapper.get(); } > void setFileWrapper(NSFileWrapper *fileWrapper) { m_fileWrapper = fileWrapper; } >+ void setFileWrapperAndUpdateContentType(NSFileWrapper *, NSString *contentType); > WTF::String utiType() const; > #endif > WTF::String mimeType() const; >@@ -78,6 +79,8 @@ public: > InsertionState insertionState() const { return m_insertionState; } > void setInsertionState(InsertionState state) { m_insertionState = state; } > >+ std::optional<uint64_t> fileSizeForDisplay() const; >+ > private: > explicit Attachment(const WTF::String& identifier, WebKit::WebPageProxy&); > >diff --git a/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm b/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm >index 9e8b588fed2aaed0049c0d50e31ac4c41a05d520..51740d7e22ffadc2467640215cfc80c971b5e958 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm >@@ -74,4 +74,34 @@ WTF::String Attachment::fileName() const > return [m_fileWrapper preferredFilename]; > } > >+void Attachment::setFileWrapperAndUpdateContentType(NSFileWrapper *fileWrapper, NSString *contentType) >+{ >+ if (!contentType.length) { >+ if (fileWrapper.directory) >+ contentType = (NSString *)kUTTypeDirectory; >+ else if (fileWrapper.regularFile) { >+ if (NSString *pathExtension = (fileWrapper.filename.length ? fileWrapper.filename : fileWrapper.preferredFilename).pathExtension) >+ contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(pathExtension); >+ if (!contentType.length) >+ contentType = (NSString *)kUTTypeData; >+ } >+ } >+ >+ setContentType(contentType); >+ setFileWrapper(fileWrapper); >+} >+ >+std::optional<uint64_t> Attachment::fileSizeForDisplay() const >+{ >+ if (![m_fileWrapper isRegularFile]) { >+ // FIXME: We should display a size estimate for directory-type file wrappers. >+ return std::nullopt; >+ } >+ >+ if (auto fileSize = [[m_fileWrapper fileAttributes][NSFileSize] unsignedLongLongValue]) >+ return fileSize; >+ >+ return [m_fileWrapper regularFileContents].length; >+} >+ > } // namespace API >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >index 0f2a4b86a2f526676c7502670e15d48830f90ece..37732c0aa9b04d2a19030950e4a72c68e6b174ef 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >@@ -4452,18 +4452,8 @@ WEBCORE_COMMAND(yankAndSelect) > auto identifier = createCanonicalUUIDString(); > auto coreOptions = options ? options.coreDisplayOptions : WebCore::AttachmentDisplayOptions { }; > auto attachment = API::Attachment::create(identifier, *_page); >- attachment->setFileWrapper(fileWrapper); >- >- if (!contentType.length) { >- if (NSString *pathExtension = (fileWrapper.filename.length ? fileWrapper.filename : fileWrapper.preferredFilename).pathExtension) >- contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(pathExtension); >- } >- >- auto fileSize = [[[fileWrapper fileAttributes] objectForKey:NSFileSize] unsignedLongLongValue]; >- if (!fileSize && fileWrapper.regularFile) >- fileSize = fileWrapper.regularFileContents.length; >- >- _page->insertAttachment(attachment.copyRef(), coreOptions, fileSize, [fileWrapper preferredFilename], contentType.length ? std::optional<String> { contentType } : std::nullopt, [capturedHandler = makeBlockPtr(completionHandler)] (WebKit::CallbackBase::Error error) { >+ attachment->setFileWrapperAndUpdateContentType(fileWrapper, contentType); >+ _page->insertAttachment(attachment.copyRef(), coreOptions, [capturedHandler = makeBlockPtr(completionHandler)] (WebKit::CallbackBase::Error error) { > if (capturedHandler) > capturedHandler(error == WebKit::CallbackBase::Error::None); > }); >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm b/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm >index 7df48b2955dad9ecdc7e2ede662a51af0bf4fd3e..0ca3d539386155c4aa40a49dc389457360b62e4b 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm >@@ -157,17 +157,11 @@ static const NSInteger InvalidAttachmentErrorCode = 2; > return; > } > >- auto fileSize = [fileWrapper.fileAttributes[NSFileSize] unsignedLongLongValue]; >- if (!fileSize && fileWrapper.regularFile) >- fileSize = fileWrapper.regularFileContents.length; >- >- if (!contentType.length) { >- if (NSString *pathExtension = (fileWrapper.filename.length ? fileWrapper.filename : fileWrapper.preferredFilename).pathExtension) >- contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(pathExtension); >- } >- >- _attachment->setFileWrapper(fileWrapper); >- _attachment->updateAttributes(fileSize, contentType, fileWrapper.preferredFilename, [capturedBlock = makeBlockPtr(completionHandler)] (auto error) { >+ // This file path member is only populated when the attachment is generated upon dropping files. When data is specified via NSFileWrapper >+ // from the SPI client, the corresponding file path of the data is unknown, if it even exists at all. >+ _attachment->setFilePath({ }); >+ _attachment->setFileWrapperAndUpdateContentType(fileWrapper, contentType); >+ _attachment->updateAttributes([capturedBlock = makeBlockPtr(completionHandler)] (auto error) { > if (!capturedBlock) > return; > >diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp >index 002becf24e41e7e5297c0c939a7d409d5ae99683..763b28ebab9f10e3e1082a2f424a61f0127002a6 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.cpp >+++ b/Source/WebKit/UIProcess/WebPageProxy.cpp >@@ -7751,21 +7751,17 @@ RefPtr<API::Attachment> WebPageProxy::attachmentForIdentifier(const String& iden > return m_attachmentIdentifierToAttachmentMap.get(identifier); > } > >-void WebPageProxy::insertAttachment(Ref<API::Attachment>&& attachment, const AttachmentDisplayOptions& options, uint64_t fileSize, const String& filename, std::optional<String> contentType, Function<void(CallbackBase::Error)>&& callback) >+void WebPageProxy::insertAttachment(Ref<API::Attachment>&& attachment, const AttachmentDisplayOptions& options, Function<void(CallbackBase::Error)>&& callback) > { > if (!isValid()) { > callback(CallbackBase::Error::OwnerWasInvalidated); > return; > } > >- if (contentType) >- attachment->setContentType(*contentType); >- > auto attachmentIdentifier = attachment->identifier(); >- m_attachmentIdentifierToAttachmentMap.set(attachmentIdentifier, WTFMove(attachment)); >- > auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken()); >- m_process->send(Messages::WebPage::InsertAttachment(attachmentIdentifier, options, fileSize, filename, contentType, callbackID), m_pageID); >+ m_process->send(Messages::WebPage::InsertAttachment(attachmentIdentifier, options, attachment->fileSizeForDisplay(), attachment->fileName(), attachment->contentType(), callbackID), m_pageID); >+ m_attachmentIdentifierToAttachmentMap.set(attachmentIdentifier, WTFMove(attachment)); > } > > void WebPageProxy::setAttachmentDisplayOptions(const String& identifier, AttachmentDisplayOptions options, Function<void(CallbackBase::Error)>&& callback) >@@ -7779,7 +7775,7 @@ void WebPageProxy::setAttachmentDisplayOptions(const String& identifier, Attachm > m_process->send(Messages::WebPage::SetAttachmentDisplayOptions(identifier, options, callbackID), m_pageID); > } > >-void WebPageProxy::updateAttachmentAttributes(const String& identifier, uint64_t fileSize, std::optional<String>&& newContentType, std::optional<String>&& newFilename, Function<void(CallbackBase::Error)>&& callback) >+void WebPageProxy::updateAttachmentAttributes(const API::Attachment& attachment, Function<void(CallbackBase::Error)>&& callback) > { > if (!isValid()) { > callback(CallbackBase::Error::OwnerWasInvalidated); >@@ -7787,7 +7783,9 @@ void WebPageProxy::updateAttachmentAttributes(const String& identifier, uint64_t > } > > auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken()); >- m_process->send(Messages::WebPage::UpdateAttachmentAttributes(identifier, fileSize, WTFMove(newContentType), WTFMove(newFilename), callbackID), m_pageID); >+ auto name = attachment.fileName(); >+ auto optionalName = name.isNull() ? std::nullopt : std::optional<WTF::String> { name }; >+ m_process->send(Messages::WebPage::UpdateAttachmentAttributes(attachment.identifier(), attachment.fileSizeForDisplay(), attachment.contentType(), WTFMove(optionalName), callbackID), m_pageID); > } > > void WebPageProxy::registerAttachmentIdentifierFromData(const String& identifier, const String& contentType, const String& preferredFileName, const IPC::DataReference& data) >diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h >index 2eb241ef7a83b4d46462e183a0060d28c5adcad3..71913ac5f89482ae08970d772398062a79d6e19a 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.h >+++ b/Source/WebKit/UIProcess/WebPageProxy.h >@@ -1319,9 +1319,9 @@ public: > > #if ENABLE(ATTACHMENT_ELEMENT) > RefPtr<API::Attachment> attachmentForIdentifier(const String& identifier) const; >- void insertAttachment(Ref<API::Attachment>&&, const WebCore::AttachmentDisplayOptions&, uint64_t fileSize, const String& fileName, std::optional<String> contentType, Function<void(CallbackBase::Error)>&&); >+ void insertAttachment(Ref<API::Attachment>&&, const WebCore::AttachmentDisplayOptions&, Function<void(CallbackBase::Error)>&&); > void setAttachmentDisplayOptions(const String& identifier, WebCore::AttachmentDisplayOptions, Function<void(CallbackBase::Error)>&&); >- void updateAttachmentAttributes(const String& identifier, uint64_t fileSize, std::optional<String>&& newContentType, std::optional<String>&& newFilename, Function<void(CallbackBase::Error)>&&); >+ void updateAttachmentAttributes(const API::Attachment&, Function<void(CallbackBase::Error)>&&); > #endif > > #if ENABLE(APPLICATION_MANIFEST) >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >index b5b711a6c658c6da12b7f4f6f5a8d8feae4f8d6f..4b5f5ab8690efe69adcd1360e7c1988adf050ff5 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp >@@ -6066,10 +6066,10 @@ void WebPage::storageAccessResponse(bool wasGranted, uint64_t contextId) > > #if ENABLE(ATTACHMENT_ELEMENT) > >-void WebPage::insertAttachment(const String& identifier, const AttachmentDisplayOptions& options, uint64_t fileSize, const String& fileName, std::optional<String> contentType, CallbackID callbackID) >+void WebPage::insertAttachment(const String& identifier, const AttachmentDisplayOptions& options, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CallbackID callbackID) > { > auto& frame = m_page->focusController().focusedOrMainFrame(); >- frame.editor().insertAttachment(identifier, options, fileSize, fileName, WTFMove(contentType)); >+ frame.editor().insertAttachment(identifier, options, WTFMove(fileSize), fileName, contentType); > send(Messages::WebPageProxy::VoidCallback(callbackID)); > } > >@@ -6078,11 +6078,11 @@ void WebPage::setAttachmentDisplayOptions(const String&, const AttachmentDisplay > send(Messages::WebPageProxy::VoidCallback(callbackID)); > } > >-void WebPage::updateAttachmentAttributes(const String& identifier, uint64_t fileSize, std::optional<String> newContentType, std::optional<String> newFilename, CallbackID callbackID) >+void WebPage::updateAttachmentAttributes(const String& identifier, std::optional<uint64_t>&& fileSize, const String& contentType, std::optional<String>&& newFilename, CallbackID callbackID) > { > if (auto attachment = attachmentElementWithIdentifier(identifier)) { > attachment->document().updateLayout(); >- attachment->updateAttributes(fileSize, WTFMove(newContentType), WTFMove(newFilename)); >+ attachment->updateAttributes(WTFMove(fileSize), contentType, WTFMove(newFilename)); > } > send(Messages::WebPageProxy::VoidCallback(callbackID)); > } >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index 6be1cbfc76c336976fb1f21d4091ad7616ed8f02..4d4ae851b265ecb39e0f5eea40ae01069d440081 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -1075,9 +1075,9 @@ public: > #endif > > #if ENABLE(ATTACHMENT_ELEMENT) >- void insertAttachment(const String& identifier, const WebCore::AttachmentDisplayOptions&, uint64_t fileSize, const String& fileName, std::optional<String> contentType, CallbackID); >+ void insertAttachment(const String& identifier, const WebCore::AttachmentDisplayOptions&, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CallbackID); > void setAttachmentDisplayOptions(const String& identifier, const WebCore::AttachmentDisplayOptions&, CallbackID); >- void updateAttachmentAttributes(const String& identifier, uint64_t fileSize, std::optional<String> newContentType, std::optional<String> newFilename, CallbackID); >+ void updateAttachmentAttributes(const String& identifier, std::optional<uint64_t>&& fileSize, const String& contentType, std::optional<String>&& newFilename, CallbackID); > #endif > > #if ENABLE(APPLICATION_MANIFEST) >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >index 96e487ee62f5a146dada87ed9a8e19af4eddbf1a..289abda87f053b4bac25bead05524647d974659f 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >@@ -510,9 +510,9 @@ messages -> WebPage LegacyReceiver { > #endif > > #if ENABLE(ATTACHMENT_ELEMENT) >- InsertAttachment(String identifier, struct WebCore::AttachmentDisplayOptions options, uint64_t fileSize, String fileName, std::optional<String> contentType, WebKit::CallbackID callbackID) >+ InsertAttachment(String identifier, struct WebCore::AttachmentDisplayOptions options, std::optional<uint64_t> fileSize, String fileName, String contentType, WebKit::CallbackID callbackID) > SetAttachmentDisplayOptions(String identifier, struct WebCore::AttachmentDisplayOptions options, WebKit::CallbackID callbackID) >- UpdateAttachmentAttributes(String identifier, uint64_t fileSize, std::optional<String> newContentType, std::optional<String> newFilename, WebKit::CallbackID callbackID) >+ UpdateAttachmentAttributes(String identifier, std::optional<uint64_t> fileSize, String newContentType, std::optional<String> newFilename, WebKit::CallbackID callbackID) > #endif > > #if ENABLE(APPLICATION_MANIFEST) >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 63a875cc5802bbfc2d7b612758bcec2f7b7c1792..ff8d82ef053e732a34846787c1586878a7454dec 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,48 @@ >+2018-08-26 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [Cocoa] Exception (fileType 'dyn.agq8u' is not a valid UTI) raised when dragging an attachment whose file wrapper is a directory >+ https://bugs.webkit.org/show_bug.cgi?id=188903 >+ <rdar://problem/43702993> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add two API tests and adjust existing WKAttachment API tests. The new tests exercise the following scenarios, in >+ both iOS and macOS: >+ ⢠Dropping a folder as an attachment element, and then moving that attachment element in the document by >+ dragging and dropping. >+ ⢠Using WKWebView SPI to insert a folder and a file with an unknown extension, and then using more >+ _WKAttachment SPI to swap the attachments' backing file wrappers. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: >+ (runTestWithTemporaryFolder): >+ >+ Add a helper function to run a test with a new folder path, created in the temporary directory and populated >+ with some sample content. This folder is deleted after running the test. >+ >+ (simulateFolderDragWithURL): >+ >+ Add a helper function to prepare a given DragAndDropSimulator for simulating a dragged folder from a source >+ external to the web view. >+ >+ (TestWebKitAPI::TEST): >+ >+ Add new API tests, and adjust existing tests to reflect new -setFileWrapper:â¦: behavior. Specifically, >+ ChangeAttachmentDataAndFileInformation previously required that changing a _WKAttachment's NSFileWrapper would >+ preserve the previous NSFileWrapper's preferred name if the new file wrapper does not have a preferred name, but >+ this quirk is no longer supported. >+ >+ Also add a few bridging casts when converting from CFStringRef to NSString and vice versa. >+ >+ * TestWebKitAPI/cocoa/DragAndDropSimulator.h: >+ >+ Add a new hook to clear any external drag information on an existing DragAndDropSimulator. This is convenient >+ when using the same DragAndDropSimulator to perform multiple drags in a single test. >+ >+ * TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm: >+ (-[DragAndDropSimulator clearExternalDragInformation]): >+ * TestWebKitAPI/mac/DragAndDropSimulatorMac.mm: >+ (-[DragAndDropSimulator clearExternalDragInformation]): >+ > 2018-08-26 Sam Weinig <sam@webkit.org> > > Using _WKRemoteObjectInterface with a protocol that inherits from a non-NSObject protocol crashes >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >index dd2687941f863632f115ff29c5fb297cd23039c8..1fe0e2c26aa4f1c7df85ad679d1a7958a6ecdc8b 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >@@ -398,6 +398,37 @@ static NSData *testPDFData() > > @end > >+static void runTestWithTemporaryFolder(void(^runTest)(NSURL *folderURL)) >+{ >+ NSFileManager *defaultManager = [NSFileManager defaultManager]; >+ auto temporaryFolder = retainPtr([NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"folder-%@", NSUUID.UUID]] isDirectory:YES]); >+ [defaultManager removeItemAtURL:temporaryFolder.get() error:nil]; >+ [defaultManager createDirectoryAtURL:temporaryFolder.get() withIntermediateDirectories:NO attributes:nil error:nil]; >+ [testImageData() writeToURL:[temporaryFolder.get() URLByAppendingPathComponent:@"image.png" isDirectory:NO] atomically:YES]; >+ [testZIPData() writeToURL:[temporaryFolder.get() URLByAppendingPathComponent:@"archive.zip" isDirectory:NO] atomically:YES]; >+ @try { >+ runTest(temporaryFolder.get()); >+ } @finally { >+ [[NSFileManager defaultManager] removeItemAtURL:temporaryFolder.get() error:nil]; >+ } >+} >+ >+static void simulateFolderDragWithURL(DragAndDropSimulator *simulator, NSURL *folderURL) >+{ >+#if PLATFORM(MAC) >+ [simulator writePromisedFiles:@[ folderURL ]]; >+#else >+ auto folderProvider = adoptNS([[NSItemProvider alloc] init]); >+ [folderProvider setSuggestedName:folderURL.lastPathComponent]; >+ [folderProvider setPreferredPresentationStyle:UIPreferredPresentationStyleAttachment]; >+ [folderProvider registerFileRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypeFolder fileOptions:0 visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[&] (void(^completion)(NSURL *, BOOL, NSError *)) -> NSProgress * { >+ completion(folderURL, NO, nil); >+ return nil; >+ }]; >+ simulator.externalItemProviders = @[ folderProvider.get() ]; >+#endif >+} >+ > #pragma mark - Platform testing helper functions > > #if PLATFORM(MAC) >@@ -458,9 +489,9 @@ typedef void(^ItemProviderDataLoadHandler)(NSData *, NSError *); > > void platformCopyRichTextWithMultipleAttachments() > { >- auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(NSString *)kUTTypePNG]); >- auto pdf = adoptNS([[NSTextAttachment alloc] initWithData:testPDFData() ofType:(NSString *)kUTTypePDF]); >- auto zip = adoptNS([[NSTextAttachment alloc] initWithData:testZIPData() ofType:(NSString *)kUTTypeZipArchive]); >+ auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(__bridge NSString *)kUTTypePNG]); >+ auto pdf = adoptNS([[NSTextAttachment alloc] initWithData:testPDFData() ofType:(__bridge NSString *)kUTTypePDF]); >+ auto zip = adoptNS([[NSTextAttachment alloc] initWithData:testZIPData() ofType:(__bridge NSString *)kUTTypeZipArchive]); > > auto richText = adoptNS([[NSMutableAttributedString alloc] init]); > [richText appendAttributedString:[NSAttributedString attributedStringWithAttachment:image.get()]]; >@@ -481,7 +512,7 @@ void platformCopyRichTextWithMultipleAttachments() > void platformCopyRichTextWithImage() > { > auto richText = adoptNS([[NSMutableAttributedString alloc] init]); >- auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(NSString *)kUTTypePNG]); >+ auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(__bridge NSString *)kUTTypePNG]); > > [richText appendAttributedString:[[[NSAttributedString alloc] initWithString:@"Lorem ipsum "] autorelease]]; > [richText appendAttributedString:[NSAttributedString attributedStringWithAttachment:image.get()]]; >@@ -508,7 +539,7 @@ void platformCopyPNG() > UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; > auto item = adoptNS([[UIItemProvider alloc] init]); > [item setPreferredPresentationStyle:UIPreferredPresentationStyleAttachment]; >- [item registerData:testImageData() type:(NSString *)kUTTypePNG]; >+ [item registerData:testImageData() type:(__bridge NSString *)kUTTypePNG]; > pasteboard.itemProviders = @[ item.get() ]; > #endif > } >@@ -740,6 +771,87 @@ TEST(WKAttachmentTests, AttachmentDataForEmptyFile) > [attachment expectRequestedDataToBe:[NSData data]]; > } > >+TEST(WKAttachmentTests, DropFolderAsAttachmentAndMoveByDragging) >+{ >+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); >+ [configuration _setAttachmentElementEnabled:YES]; >+ >+ auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:NSMakeRect(0, 0, 400, 400) configuration:configuration.get()]); >+ [[simulator webView] synchronouslyLoadHTMLString:attachmentEditingTestMarkup]; >+ >+ runTestWithTemporaryFolder([simulator] (NSURL *folderURL) { >+ simulateFolderDragWithURL(simulator.get(), folderURL); >+ [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(50, 50)]; >+ >+ TestWKWebView *webView = [simulator webView]; >+ auto attachment = retainPtr([simulator insertedAttachments].firstObject); >+ EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').uniqueIdentifier"]); >+ EXPECT_WK_STREQ((__bridge NSString *)kUTTypeDirectory, [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); >+ EXPECT_WK_STREQ(folderURL.lastPathComponent, [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); >+ >+ NSFileWrapper *image = [attachment info].fileWrapper.fileWrappers[@"image.png"]; >+ NSFileWrapper *archive = [attachment info].fileWrapper.fileWrappers[@"archive.zip"]; >+ EXPECT_TRUE([image.regularFileContents isEqualToData:testImageData()]); >+ EXPECT_TRUE([archive.regularFileContents isEqualToData:testZIPData()]); >+ >+ [webView evaluateJavaScript:@"getSelection().collapseToEnd()" completionHandler:nil]; >+ [webView _executeEditCommand:@"InsertParagraph" argument:nil completion:nil]; >+ [webView _executeEditCommand:@"InsertHTML" argument:@"<em>foo</em>" completion:nil]; >+ [webView _executeEditCommand:@"InsertParagraph" argument:nil completion:nil]; >+ >+ [webView expectElementTag:@"ATTACHMENT" toComeBefore:@"EM"]; >+ [simulator clearExternalDragInformation]; >+ [simulator runFrom:webView.attachmentElementMidPoint to:CGPointMake(300, 300)]; >+ [webView expectElementTag:@"EM" toComeBefore:@"ATTACHMENT"]; >+ }); >+} >+ >+TEST(WKAttachmentTests, InsertFolderAndFileWithUnknownExtension) >+{ >+ auto webView = webViewForTestingAttachments(); >+ auto file = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testHTMLData()]); >+ [file setPreferredFilename:@"test.foobar"]; >+ auto image = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testImageData()]); >+ auto document = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testPDFData()]); >+ auto folder = adoptNS([[NSFileWrapper alloc] initDirectoryWithFileWrappers:@{ @"image.png": image.get(), @"document.pdf": document.get() }]); >+ [folder setPreferredFilename:@"folder"]; >+ >+ RetainPtr<_WKAttachment> firstAttachment; >+ RetainPtr<_WKAttachment> secondAttachment; >+ { >+ ObserveAttachmentUpdatesForScope observer(webView.get()); >+ firstAttachment = [webView synchronouslyInsertAttachmentWithFileWrapper:file.get() contentType:nil]; >+ observer.expectAttachmentUpdates(@[ ], @[ firstAttachment.get() ]); >+ } >+ { >+ ObserveAttachmentUpdatesForScope observer(webView.get()); >+ secondAttachment = [webView synchronouslyInsertAttachmentWithFileWrapper:folder.get() contentType:nil]; >+ observer.expectAttachmentUpdates(@[ ], @[ secondAttachment.get() ]); >+ } >+ >+ auto checkAttachmentConsistency = [webView, file, folder] (_WKAttachment *expectedFileAttachment, _WKAttachment *expectedFolderAttachment) { >+ [webView expectElementCount:2 tagName:@"ATTACHMENT"]; >+ EXPECT_TRUE(UTTypeConformsTo((__bridge CFStringRef)[webView valueOfAttribute:@"type" forQuerySelector:@"attachment[title=folder]"], kUTTypeDirectory)); >+ EXPECT_TRUE(UTTypeConformsTo((__bridge CFStringRef)[webView valueOfAttribute:@"type" forQuerySelector:@"attachment[title^=test]"], kUTTypeData)); >+ EXPECT_WK_STREQ(expectedFileAttachment.uniqueIdentifier, [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment[title^=test]').uniqueIdentifier"]); >+ EXPECT_WK_STREQ(expectedFolderAttachment.uniqueIdentifier, [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment[title=folder]').uniqueIdentifier"]); >+ EXPECT_TRUE([expectedFileAttachment.info.fileWrapper isEqual:file.get()]); >+ EXPECT_TRUE([expectedFolderAttachment.info.fileWrapper isEqual:folder.get()]); >+ }; >+ >+ checkAttachmentConsistency(firstAttachment.get(), secondAttachment.get()); >+ >+ { >+ // Swap the two attachments' file wrappers without creating or destroying attachment elements. >+ ObserveAttachmentUpdatesForScope observer(webView.get()); >+ [firstAttachment synchronouslySetFileWrapper:folder.get() newContentType:nil error:nil]; >+ [secondAttachment synchronouslySetFileWrapper:file.get() newContentType:nil error:nil]; >+ observer.expectAttachmentUpdates(@[ ], @[ ]); >+ } >+ >+ checkAttachmentConsistency(secondAttachment.get(), firstAttachment.get()); >+} >+ > TEST(WKAttachmentTests, ChangeAttachmentDataAndFileInformation) > { > auto webView = webViewForTestingAttachments(); >@@ -763,7 +875,7 @@ TEST(WKAttachmentTests, ChangeAttachmentDataAndFileInformation) > observer.expectAttachmentUpdates(@[], @[]); > } > { >- RetainPtr<NSData> textData = testHTMLData(); >+ RetainPtr<NSData> textData = [@"Hello world" dataUsingEncoding:NSUTF8StringEncoding]; > ObserveAttachmentUpdatesForScope observer(webView.get()); > // The new content type should be inferred from the file name. > [attachment synchronouslySetData:textData.get() newContentType:nil newFilename:@"foo.txt" error:nil]; >@@ -773,13 +885,13 @@ TEST(WKAttachmentTests, ChangeAttachmentDataAndFileInformation) > observer.expectAttachmentUpdates(@[], @[]); > } > { >- RetainPtr<NSData> secondTextData = [@"Hello world" dataUsingEncoding:NSUTF8StringEncoding]; >+ RetainPtr<NSData> htmlData = testHTMLData(); > ObserveAttachmentUpdatesForScope observer(webView.get()); > // Both the previous file name and type should be inferred. >- [attachment synchronouslySetData:secondTextData.get() newContentType:nil newFilename:nil error:nil]; >- [attachment expectRequestedDataToBe:secondTextData.get()]; >- EXPECT_WK_STREQ(@"foo.txt", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); >- EXPECT_WK_STREQ(@"text/plain", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); >+ [attachment synchronouslySetData:htmlData.get() newContentType:@"text/html" newFilename:@"bar" error:nil]; >+ [attachment expectRequestedDataToBe:htmlData.get()]; >+ EXPECT_WK_STREQ(@"bar", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); >+ EXPECT_WK_STREQ(@"text/html", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); > observer.expectAttachmentUpdates(@[], @[]); > } > [webView expectUpdatesAfterCommand:@"DeleteBackward" withArgument:nil expectedRemovals:@[attachment.get()] expectedInsertions:@[]]; >@@ -1313,7 +1425,7 @@ TEST(WKAttachmentTestsIOS, InsertDroppedImageAsAttachment) > auto webView = webViewForTestingAttachments(); > auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); > auto item = adoptNS([[NSItemProvider alloc] init]); >- [item registerData:testImageData() type:(NSString *)kUTTypePNG]; >+ [item registerData:testImageData() type:(__bridge NSString *)kUTTypePNG]; > [dragAndDropSimulator setExternalItemProviders:@[ item.get() ]]; > [dragAndDropSimulator runFrom:CGPointZero to:CGPointMake(50, 50)]; > >@@ -1335,7 +1447,7 @@ TEST(WKAttachmentTestsIOS, InsertDroppedAttributedStringContainingAttachment) > { > auto webView = webViewForTestingAttachments(); > auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); >- auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(NSString *)kUTTypePNG]); >+ auto image = adoptNS([[NSTextAttachment alloc] initWithData:testImageData() ofType:(__bridge NSString *)kUTTypePNG]); > auto item = adoptNS([[NSItemProvider alloc] init]); > [item registerObject:[NSAttributedString attributedStringWithAttachment:image.get()] visibility:NSItemProviderRepresentationVisibilityAll]; > >@@ -1401,7 +1513,7 @@ TEST(WKAttachmentTestsIOS, InsertDroppedZipArchiveAsAttachment) > // presentation style (e.g. Notes) into Mail. > auto item = adoptNS([[NSItemProvider alloc] init]); > NSData *data = testZIPData(); >- [item registerData:data type:(NSString *)kUTTypeZipArchive]; >+ [item registerData:data type:(__bridge NSString *)kUTTypeZipArchive]; > [item setSuggestedName:@"archive.zip"]; > > auto webView = webViewForTestingAttachments(); >@@ -1431,7 +1543,7 @@ TEST(WKAttachmentTestsIOS, InsertDroppedItemProvidersInOrder) > [inlineTextItem registerObject:appleURL.get() visibility:NSItemProviderRepresentationVisibilityAll]; > > auto secondAttachmentItem = adoptNS([[NSItemProvider alloc] init]); >- [secondAttachmentItem registerData:testPDFData() type:(NSString *)kUTTypePDF]; >+ [secondAttachmentItem registerData:testPDFData() type:(__bridge NSString *)kUTTypePDF]; > [secondAttachmentItem setSuggestedName:@"second.pdf"]; > > auto webView = webViewForTestingAttachments(); >@@ -1458,7 +1570,7 @@ TEST(WKAttachmentTestsIOS, DragAttachmentInsertedAsFile) > { > auto item = adoptNS([[NSItemProvider alloc] init]); > auto data = retainPtr(testPDFData()); >- [item registerData:data.get() type:(NSString *)kUTTypePDF]; >+ [item registerData:data.get() type:(__bridge NSString *)kUTTypePDF]; > [item setSuggestedName:@"document.pdf"]; > > auto webView = webViewForTestingAttachments(); >@@ -1481,7 +1593,7 @@ TEST(WKAttachmentTestsIOS, DragAttachmentInsertedAsFile) > EXPECT_EQ(1U, [dragAndDropSimulator sourceItemProviders].count); > NSItemProvider *itemProvider = [dragAndDropSimulator sourceItemProviders].firstObject; > EXPECT_EQ(UIPreferredPresentationStyleAttachment, itemProvider.preferredPresentationStyle); >- [itemProvider expectType:(NSString *)kUTTypePDF withData:data.get()]; >+ [itemProvider expectType:(__bridge NSString *)kUTTypePDF withData:data.get()]; > EXPECT_WK_STREQ("document.pdf", [itemProvider suggestedName]); > [dragAndDropSimulator endDataTransfer]; > } >@@ -1510,7 +1622,7 @@ TEST(WKAttachmentTestsIOS, DragAttachmentInsertedAsData) > EXPECT_EQ(1U, [dragAndDropSimulator sourceItemProviders].count); > NSItemProvider *itemProvider = [dragAndDropSimulator sourceItemProviders].firstObject; > EXPECT_EQ(UIPreferredPresentationStyleAttachment, itemProvider.preferredPresentationStyle); >- [itemProvider expectType:(NSString *)kUTTypePDF withData:data.get()]; >+ [itemProvider expectType:(__bridge NSString *)kUTTypePDF withData:data.get()]; > EXPECT_WK_STREQ("document.pdf", [itemProvider suggestedName]); > [dragAndDropSimulator endDataTransfer]; > } >diff --git a/Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h b/Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h >index 761a36f0e1c0dd6b93acb5649ec5e2c08b3bda96..1d7e10e8928a19c61ec116b6b2c5eca707e45589 100644 >--- a/Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h >+++ b/Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h >@@ -80,6 +80,7 @@ typedef NSDictionary<NSNumber *, NSValue *> *ProgressToCGPointValueMap; > // The start location, end location, and locations of additional item requests are all in window coordinates. > - (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation; > - (void)endDataTransfer; >+- (void)clearExternalDragInformation; > @property (nonatomic, readonly) NSArray<_WKAttachment *> *insertedAttachments; > @property (nonatomic, readonly) NSArray<_WKAttachment *> *removedAttachments; > @property (nonatomic, readonly) TestWKWebView *webView; >diff --git a/Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm b/Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm >index 0f97a39db60ab2902a58834145a7409b231b57e6..cebd4600a948103dfb05797a3d44eaf06385dd72 100644 >--- a/Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm >+++ b/Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm >@@ -568,6 +568,11 @@ static NSArray *dragAndDropEventNames() > [self _scheduleAdvanceProgress]; > } > >+- (void)clearExternalDragInformation >+{ >+ _externalItemProviders = nil; >+} >+ > - (CGPoint)_currentLocation > { > CGFloat distanceX = _endLocation.x - _startLocation.x; >diff --git a/Tools/TestWebKitAPI/mac/DragAndDropSimulatorMac.mm b/Tools/TestWebKitAPI/mac/DragAndDropSimulatorMac.mm >index e528301e56d4bd33bc0edb0985b1d37b33ebaf1f..2efbb5c9eb6328df2dd79846d69dc99b0afbce22 100644 >--- a/Tools/TestWebKitAPI/mac/DragAndDropSimulatorMac.mm >+++ b/Tools/TestWebKitAPI/mac/DragAndDropSimulatorMac.mm >@@ -358,6 +358,13 @@ static NSImage *defaultExternalDragImage() > return _externalPromisedFiles.get(); > } > >+- (void)clearExternalDragInformation >+{ >+ _externalPromisedFiles = nil; >+ _externalDragImage = nil; >+ _externalDragPasteboard = nil; >+} >+ > static BOOL getFilePathsAndTypeIdentifiers(NSArray<NSURL *> *fileURLs, NSArray<NSString *> **outFilePaths, NSArray<NSString *> **outTypeIdentifiers) > { > NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:fileURLs.count];
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188903
:
348089
|
348112
|
348155
|
348187