WebKit Bugzilla
Attachment 339635 Details for
Bug 185340
: Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185340-20180504221450.patch (text/plain), 16.01 KB, created by
Wenson Hsieh
on 2018-05-04 22:14:51 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-05-04 22:14:51 PDT
Size:
16.01 KB
patch
obsolete
>Subversion Revision: 231396 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 643899057e03d25ecbc3c3fdd48bce9166e16eaa..23f537a439114e842d1eb3ed7afc199d790a8459 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,30 @@ >+2018-05-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa >+ https://bugs.webkit.org/show_bug.cgi?id=185340 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ WebContentReader::readURL is currently the only method implemented separately in iOS and macOS platform >+ WebContentReader files. The implementation across macOS and iOS is nearly identical (with some exceptions with >+ the way iOS handles file URLs and plain text editing), so we can merge these into a single method >+ WebContentReaderCocoa and delete WebContentReaderIOS and WebContentReaderMac. >+ >+ This also has the added bonus of fixing a latent bug in WebContentReaderMac, wherein URLs written to the >+ pasteboard using -[NSPasteboard writeObjects:] are currently pasted as empty anchor elements. In this case, the >+ link title isn't made explicit, so the `title` passed in to WebContentReader::readURL is empty. On iOS, we have >+ code to fall back to pasting the absolute string of the URL if the title is empty, but on macOS, we'll just use >+ this empty string as the title of the anchor. >+ >+ Test: PasteMixedContent.PasteURLWrittenToPasteboardUsingWriteObjects >+ >+ * SourcesCocoa.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * editing/cocoa/WebContentReaderCocoa.mm: >+ (WebCore::WebContentReader::readURL): >+ * editing/ios/WebContentReaderIOS.mm: Removed. >+ * editing/mac/WebContentReaderMac.mm: Removed. >+ > 2018-05-04 Wenson Hsieh <wenson_hsieh@apple.com> > > [iOS] Multiple links in Mail are dropped in a single line, and are difficult to tell apart >diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt >index 26fb2f0ca452cea250834669047ec468617a6eb5..d1d831dce4059535de27e187d7f0179a7cf64c55 100644 >--- a/Source/WebCore/SourcesCocoa.txt >+++ b/Source/WebCore/SourcesCocoa.txt >@@ -84,7 +84,6 @@ editing/cocoa/WebContentReaderCocoa.mm > > editing/ios/DictationCommandIOS.cpp > editing/ios/EditorIOS.mm >-editing/ios/WebContentReaderIOS.mm > > editing/mac/AlternativeTextUIController.mm > editing/mac/DictionaryLookup.mm >@@ -92,7 +91,6 @@ editing/mac/EditorMac.mm > editing/mac/FrameSelectionMac.mm > editing/mac/TextAlternativeWithRange.mm > editing/mac/TextUndoInsertionMarkupMac.mm >-editing/mac/WebContentReaderMac.mm > > editing/ios/AutofillElements.cpp > >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index ec0c7b736dafb4ad41d7ab461ed1de09e177f934..589ff99ec9fe15ee73986b3b642d8630597a1fa2 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -10763,7 +10763,6 @@ > 9B03D8061BB3110D00B764DA /* JSDOMBindingInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMBindingInternalsBuiltins.h; sourceTree = "<group>"; }; > 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStreamBuiltins.h; sourceTree = "<group>"; }; > 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStreamInternalsBuiltins.h; sourceTree = "<group>"; }; >- 9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderIOS.mm; sourceTree = "<group>"; }; > 9B098BD51F3D6033002DD562 /* DataTransferItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransferItem.cpp; sourceTree = "<group>"; }; > 9B098BDD1F3D673D002DD562 /* JSDataTransferItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDataTransferItem.cpp; sourceTree = "<group>"; }; > 9B098BDE1F3D673D002DD562 /* JSDataTransferItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDataTransferItem.h; sourceTree = "<group>"; }; >@@ -10798,7 +10797,6 @@ > 9B6C41521344949000085B62 /* StringWithDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringWithDirection.h; sourceTree = "<group>"; }; > 9B714E1E1C91166900AC0E92 /* EventPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventPath.cpp; sourceTree = "<group>"; }; > 9B714E1F1C91166900AC0E92 /* EventPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventPath.h; sourceTree = "<group>"; }; >- 9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebContentReaderMac.mm; sourceTree = "<group>"; }; > 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderCocoa.mm; sourceTree = "<group>"; }; > 9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogicalSelectionOffsetCaches.h; sourceTree = "<group>"; }; > 9BA827781F06156500F71E75 /* NavigationDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationDisabler.h; sourceTree = "<group>"; }; >@@ -17120,7 +17118,6 @@ > D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */, > D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */, > FED13D390CEA934600D89466 /* EditorIOS.mm */, >- 9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */, > ); > path = ios; > sourceTree = "<group>"; >@@ -25330,7 +25327,6 @@ > CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */, > 29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */, > 29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */, >- 9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */, > ); > path = mac; > sourceTree = "<group>"; >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index 27cd6c85351e5bfec987b5cba65adb75fb80c5e8..522ebb000b5d83ec04dbeb5d68fdbf054f7b2aa5 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -39,6 +39,7 @@ > #import "FrameLoader.h" > #import "FrameLoaderClient.h" > #import "HTMLAttachmentElement.h" >+#import "HTMLBRElement.h" > #import "HTMLBodyElement.h" > #import "HTMLIFrameElement.h" > #import "HTMLImageElement.h" >@@ -653,4 +654,35 @@ bool WebContentReader::readFilePaths(const Vector<String>& paths) > return true; > } > >+bool WebContentReader::readURL(const URL& url, const String& title) >+{ >+ if (url.isEmpty()) >+ return false; >+ >+#if PLATFORM(IOS) >+ // FIXME: This code shouldn't be accessing selection and changing the behavior. >+ if (!frame.editor().client()->hasRichlyEditableSelection()) { >+ if (readPlainText([(NSURL *)url absoluteString])) >+ return true; >+ } >+ >+ if ([(NSURL *)url isFileURL]) >+ return false; >+#endif // PLATFORM(IOS) >+ >+ auto document = makeRef(*frame.document()); >+ auto anchor = HTMLAnchorElement::create(document.get()); >+ anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string()); >+ >+ NSString *linkText = title.isEmpty() ? [(NSURL *)url absoluteString] : (NSString *)title; >+ anchor->appendChild(document->createTextNode([linkText precomposedStringWithCanonicalMapping])); >+ >+ auto newFragment = document->createDocumentFragment(); >+ if (fragment) >+ newFragment->appendChild(HTMLBRElement::create(document.get())); >+ newFragment->appendChild(anchor); >+ addFragment(WTFMove(newFragment)); >+ return true; >+} >+ > } >diff --git a/Source/WebCore/editing/ios/WebContentReaderIOS.mm b/Source/WebCore/editing/ios/WebContentReaderIOS.mm >deleted file mode 100644 >index 8de5c15006cb9a9d833e18795af0a2e74704cb0c..0000000000000000000000000000000000000000 >--- a/Source/WebCore/editing/ios/WebContentReaderIOS.mm >+++ /dev/null >@@ -1,73 +0,0 @@ >-/* >- * Copyright (C) 2006-2017 Apple Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#import "config.h" >-#import "WebContentReader.h" >- >-#if PLATFORM(IOS) >- >-#import "Document.h" >-#import "DocumentFragment.h" >-#import "Editor.h" >-#import "EditorClient.h" >-#import "HTMLAnchorElement.h" >-#import "HTMLBRElement.h" >-#import "HTMLNames.h" >-#import "Text.h" >- >-namespace WebCore { >- >-bool WebContentReader::readURL(const URL& url, const String& title) >-{ >- if (url.isEmpty()) >- return false; >- >- // FIXME: This code shoudln't be accessing selection and changing the behavior. >- if (!frame.editor().client()->hasRichlyEditableSelection()) { >- if (readPlainText([(NSURL *)url absoluteString])) >- return true; >- } >- >- if ([(NSURL *)url isFileURL]) >- return false; >- >- auto document = makeRef(*frame.document()); >- auto anchor = HTMLAnchorElement::create(document.get()); >- anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string()); >- >- String linkText = title.length() ? title : String([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]); >- anchor->appendChild(document->createTextNode(linkText)); >- >- auto newFragment = document->createDocumentFragment(); >- if (fragment) >- newFragment->appendChild(HTMLBRElement::create(document.get())); >- newFragment->appendChild(anchor); >- addFragment(WTFMove(newFragment)); >- return true; >-} >- >-} >- >-#endif // PLATFORM(IOS) >diff --git a/Source/WebCore/editing/mac/WebContentReaderMac.mm b/Source/WebCore/editing/mac/WebContentReaderMac.mm >deleted file mode 100644 >index eef0672bcfa09ae823fe98eac12a8e9562f7d039..0000000000000000000000000000000000000000 >--- a/Source/WebCore/editing/mac/WebContentReaderMac.mm >+++ /dev/null >@@ -1,68 +0,0 @@ >-/* >- * Copyright (C) 2006-2017 Apple Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#import "config.h" >-#import "WebContentReader.h" >- >-#if PLATFORM(MAC) >- >-#import "ArchiveResource.h" >-#import "Document.h" >-#import "DocumentFragment.h" >-#import "DocumentLoader.h" >-#import "Editing.h" >-#import "Editor.h" >-#import "EditorClient.h" >-#import "File.h" >-#import "FragmentScriptingPermission.h" >-#import "FrameLoader.h" >-#import "FrameLoaderClient.h" >-#import "HTMLAnchorElement.h" >-#import "HTMLNames.h" >-#import "LegacyWebArchive.h" >-#import "Settings.h" >-#import "Text.h" >-#import "WebCoreNSURLExtras.h" >-#import "markup.h" >- >-namespace WebCore { >- >-bool WebContentReader::readURL(const URL& url, const String& title) >-{ >- if (url.string().isEmpty()) >- return false; >- >- auto anchor = HTMLAnchorElement::create(*frame.document()); >- anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string()); >- anchor->appendChild(frame.document()->createTextNode([title precomposedStringWithCanonicalMapping])); >- >- fragment = frame.document()->createDocumentFragment(); >- fragment->appendChild(anchor); >- return true; >-} >- >-} >- >-#endif // PLATFORM(MAC) >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 5a2e27668cb51f1d50f98892aee48fc9c862c56f..89c565204c9fc64426aaf462afbaada5befca7dd 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2018-05-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa >+ https://bugs.webkit.org/show_bug.cgi?id=185340 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adds a new API test to verify that URLs written using -[NSPasteboard writeObjects:] are pasted as anchors with >+ non-empty text in a contenteditable. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm: >+ (TestWebKitAPI::TEST): >+ > 2018-05-04 Wenson Hsieh <wenson_hsieh@apple.com> > > [iOS] Multiple links in Mail are dropped in a single line, and are difficult to tell apart >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm >index 04114ab4fe5e4745f8918c2ab9579e9cdd4bdef1..9f4ae5f071b3c0be10424e0f2cf22fe814615fbd 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm >@@ -237,6 +237,20 @@ TEST(PasteMixedContent, ImageDataAndPlainTextAndURLAndHTML) > EXPECT_FALSE([[webView stringByEvaluatingJavaScript:@"rawHTMLData.textContent"] containsString:@"script"]); > } > >+TEST(PasteMixedContent, PasteURLWrittenToPasteboardUsingWriteObjects) >+{ >+ NSString *urlToCopy = @"https://www.webkit.org/"; >+ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]); >+ [webView synchronouslyLoadHTMLString:@"<body contenteditable></body><script>document.body.focus()</script>"]; >+ [[NSPasteboard generalPasteboard] clearContents]; >+ [[NSPasteboard generalPasteboard] writeObjects:@[ [NSURL URLWithString:urlToCopy] ]]; >+ [webView paste:nil]; >+ >+ EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"document.querySelector('a').href"], urlToCopy); >+ EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"document.querySelector('a').textContent"], urlToCopy); >+} >+ > } // namespace TestWebKitAPI > > #endif // PLATFORM(MAC) && WK_API_ENABLED
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 185340
: 339635