Title: [231531] trunk
Revision
231531
Author
[email protected]
Date
2018-05-08 17:37:55 -0700 (Tue, 08 May 2018)

Log Message

Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa
https://bugs.webkit.org/show_bug.cgi?id=185340

Reviewed by Tim Horton.

Source/WebCore:

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.

Tools:

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):

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231530 => 231531)


--- trunk/Source/WebCore/ChangeLog	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/ChangeLog	2018-05-09 00:37:55 UTC (rev 231531)
@@ -1,3 +1,30 @@
+2018-05-08  Wenson Hsieh  <[email protected]>
+
+        Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa
+        https://bugs.webkit.org/show_bug.cgi?id=185340
+
+        Reviewed by Tim Horton.
+
+        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-08  Zalan Bujtas  <[email protected]>
 
         [Simple line layout] Cache run resolver.

Modified: trunk/Source/WebCore/SourcesCocoa.txt (231530 => 231531)


--- trunk/Source/WebCore/SourcesCocoa.txt	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2018-05-09 00:37:55 UTC (rev 231531)
@@ -84,7 +84,6 @@
 
 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/FrameSelectionMac.mm
 editing/mac/TextAlternativeWithRange.mm
 editing/mac/TextUndoInsertionMarkupMac.mm
-editing/mac/WebContentReaderMac.mm
 
 editing/ios/AutofillElements.cpp
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (231530 => 231531)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-05-09 00:37:55 UTC (rev 231531)
@@ -10766,7 +10766,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>"; };
@@ -10801,7 +10800,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>"; };
@@ -17126,7 +17124,6 @@
 				D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */,
 				D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */,
 				FED13D390CEA934600D89466 /* EditorIOS.mm */,
-				9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */,
 			);
 			path = ios;
 			sourceTree = "<group>";
@@ -25338,7 +25335,6 @@
 				CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */,
 				29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */,
 				29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */,
-				9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";

Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (231530 => 231531)


--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2018-05-09 00:37:55 UTC (rev 231531)
@@ -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 @@
     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;
 }
+
+}

Deleted: trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm (231530 => 231531)


--- trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm	2018-05-09 00:37:55 UTC (rev 231531)
@@ -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)

Deleted: trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm (231530 => 231531)


--- trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm	2018-05-09 00:37:55 UTC (rev 231531)
@@ -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)

Modified: trunk/Tools/ChangeLog (231530 => 231531)


--- trunk/Tools/ChangeLog	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Tools/ChangeLog	2018-05-09 00:37:55 UTC (rev 231531)
@@ -1,3 +1,16 @@
+2018-05-08  Wenson Hsieh  <[email protected]>
+
+        Consolidate WebContentReaderIOS and WebContentReaderMac into WebContentReaderCocoa
+        https://bugs.webkit.org/show_bug.cgi?id=185340
+
+        Reviewed by Tim Horton.
+
+        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-08  Valerie R Young  <[email protected]>
 
         test262/Runner.pm: create results dir for results of test262 run

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm (231530 => 231531)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm	2018-05-09 00:31:04 UTC (rev 231530)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm	2018-05-09 00:37:55 UTC (rev 231531)
@@ -237,6 +237,20 @@
     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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to