WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Fixed the test on iOS
bug-174165-20171005191642.patch (text/plain), 19.42 KB, created by
Ryosuke Niwa
on 2017-10-05 19:16:43 PDT
(
hide
)
Description:
Fixed the test on iOS
Filename:
MIME Type:
Creator:
Ryosuke Niwa
Created:
2017-10-05 19:16:43 PDT
Size:
19.42 KB
patch
obsolete
>Subversion Revision: 222771 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 7ca954d60f11b8a82c3c156906e12be016949b45..b7517c18b8b3ced6aa5e1b4c70ea9f90e298de22 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,40 @@ >+2017-10-05 Ryosuke Niwa <rniwa@webkit.org> >+ >+ DataTransfer shouldn't contain text/html when performing Paste and Match Style >+ https://bugs.webkit.org/show_bug.cgi?id=174165 >+ <rdar://problem/33138027> >+ >+ Reviewed by Wenson Hsieh. >+ >+ When performing Paste and Match Style, only expose the plain text by creating a StaticPasteboard with plain text content. >+ >+ This patch introduces ClipboardEventKind enum class to differentiate regular paste and paste and match style (internally >+ called as pasteAsPlainText) since both operations use "paste" event. >+ >+ Tests: editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled.html >+ editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text.html >+ >+ * dom/DataTransfer.cpp: >+ (WebCore::DataTransfer::createForCopyAndPaste): Made this function take Pasteboard as an argument. >+ * dom/DataTransfer.h: >+ * editing/Editor.cpp: >+ (WebCore::ClipboardEventKind): Added. >+ (WebCore::eventNameForClipboardEvent): Added. >+ (WebCore::createDataTransferForClipboardEvent): Added. >+ (WebCore::dispatchClipboardEvent): >+ (WebCore::Editor::canDHTMLCut): >+ (WebCore::Editor::canDHTMLCopy): >+ (WebCore::Editor::canDHTMLPaste): >+ (WebCore::Editor::tryDHTMLCopy): >+ (WebCore::Editor::tryDHTMLCut): >+ (WebCore::Editor::tryDHTMLPaste): Deleted. >+ (WebCore::Editor::paste): >+ (WebCore::Editor::pasteAsPlainText): >+ * platform/ios/PasteboardIOS.mm: >+ (WebCore::Pasteboard::addHTMLClipboardTypesForCocoaType): Add "text/html" when public.html UTI is in the pasteboard >+ even when the custom pasteboard data is disabled. We continue to add public.html in the case some app dependent on >+ seeing "public.html" in dataTransfer.types. >+ > 2017-10-02 Myles C. Maxfield <mmaxfield@apple.com> > > Move LineEnding.{h,cpp} from WebCore/platform/text to wtf/text >diff --git a/Source/WebCore/dom/DataTransfer.cpp b/Source/WebCore/dom/DataTransfer.cpp >index addef0f9173c456a81eae74905124f0c2f493fe2..0a0966db44cf3460b176999b8d680a0f757f663a 100644 >--- a/Source/WebCore/dom/DataTransfer.cpp >+++ b/Source/WebCore/dom/DataTransfer.cpp >@@ -75,9 +75,9 @@ DataTransfer::DataTransfer(StoreMode mode, std::unique_ptr<Pasteboard> pasteboar > #endif > } > >-Ref<DataTransfer> DataTransfer::createForCopyAndPaste(StoreMode mode) >+Ref<DataTransfer> DataTransfer::createForCopyAndPaste(StoreMode storeMode, std::unique_ptr<Pasteboard>&& pasteboard) > { >- return adoptRef(*new DataTransfer(mode, mode == StoreMode::ReadWrite ? std::make_unique<StaticPasteboard>() : Pasteboard::createForCopyAndPaste())); >+ return adoptRef(*new DataTransfer(storeMode, WTFMove(pasteboard))); > } > > DataTransfer::~DataTransfer() >diff --git a/Source/WebCore/dom/DataTransfer.h b/Source/WebCore/dom/DataTransfer.h >index 09d4dff32b11fb8fef2e07bc8e15b3c405e2f16f..894202ca7da0f7624fcc6a7305f36044db315870 100644 >--- a/Source/WebCore/dom/DataTransfer.h >+++ b/Source/WebCore/dom/DataTransfer.h >@@ -43,7 +43,7 @@ public: > // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode > enum class StoreMode { Invalid, ReadWrite, Readonly, Protected }; > >- static Ref<DataTransfer> createForCopyAndPaste(StoreMode); >+ static Ref<DataTransfer> createForCopyAndPaste(StoreMode, std::unique_ptr<Pasteboard>&&); > static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText); > > WEBCORE_EXPORT ~DataTransfer(); >diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp >index 16552545c35eac6da38c18fbbd4d83235ddf9120..c4c25ab684bd5bb2000411c3441e813bcddad86c 100644 >--- a/Source/WebCore/editing/Editor.cpp >+++ b/Source/WebCore/editing/Editor.cpp >@@ -314,36 +314,83 @@ bool Editor::canEditRichly() const > return m_frame.selection().selection().isContentRichlyEditable(); > } > >+enum class ClipboardEventKind { >+ Copy, >+ Cut, >+ Paste, >+ PasteAsPlainText, >+ BeforeCopy, >+ BeforeCut, >+ BeforePaste, >+}; >+ >+static AtomicString eventNameForClipboardEvent(ClipboardEventKind kind) >+{ >+ switch (kind) { >+ case ClipboardEventKind::Copy: >+ return eventNames().copyEvent; >+ case ClipboardEventKind::Cut: >+ return eventNames().cutEvent; >+ case ClipboardEventKind::Paste: >+ case ClipboardEventKind::PasteAsPlainText: >+ return eventNames().pasteEvent; >+ case ClipboardEventKind::BeforeCopy: >+ return eventNames().beforecopyEvent; >+ case ClipboardEventKind::BeforeCut: >+ return eventNames().beforecutEvent; >+ case ClipboardEventKind::BeforePaste: >+ return eventNames().beforepasteEvent; >+ } >+ ASSERT_NOT_REACHED(); >+ return { }; >+} >+ >+static Ref<DataTransfer> createDataTransferForClipboardEvent(ClipboardEventKind kind) >+{ >+ switch (kind) { >+ case ClipboardEventKind::Copy: >+ case ClipboardEventKind::Cut: >+ return DataTransfer::createForCopyAndPaste(DataTransfer::StoreMode::ReadWrite, std::make_unique<StaticPasteboard>()); >+ case ClipboardEventKind::PasteAsPlainText: >+ if (Settings::customPasteboardDataEnabled()) { >+ auto plainTextType = ASCIILiteral("text/plain"); >+ auto plainText = Pasteboard::createForCopyAndPaste()->readString(plainTextType); >+ auto pasteboard = std::make_unique<StaticPasteboard>(); >+ pasteboard->writeString(plainTextType, plainText); >+ return DataTransfer::createForCopyAndPaste(DataTransfer::StoreMode::Readonly, WTFMove(pasteboard)); >+ } >+ FALLTHROUGH; >+ case ClipboardEventKind::Paste: >+ return DataTransfer::createForCopyAndPaste(DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste()); >+ case ClipboardEventKind::BeforeCopy: >+ case ClipboardEventKind::BeforeCut: >+ case ClipboardEventKind::BeforePaste: >+ return DataTransfer::createForCopyAndPaste(DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>()); >+ } >+ ASSERT_NOT_REACHED(); >+ return DataTransfer::createForCopyAndPaste(DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>()); >+} >+ > // Returns whether caller should continue with "the default processing", which is the same as > // the event handler NOT setting the return value to false > // https://w3c.github.io/clipboard-apis/#fire-a-clipboard-event >-static bool dispatchClipboardEvent(RefPtr<Element>&& target, const AtomicString& eventType) >+static bool dispatchClipboardEvent(RefPtr<Element>&& target, ClipboardEventKind kind) > { > // FIXME: Move the target selection code here. > if (!target) > return true; > >- DataTransfer::StoreMode storeMode; >- if (eventType == eventNames().pasteEvent) >- storeMode = DataTransfer::StoreMode::Readonly; >- else if (eventType == eventNames().copyEvent || eventType == eventNames().cutEvent) >- storeMode = DataTransfer::StoreMode::ReadWrite; >- else { >- ASSERT(eventType == eventNames().beforecutEvent || eventType == eventNames().beforecopyEvent || eventType == eventNames().beforepasteEvent); >- storeMode = DataTransfer::StoreMode::Invalid; >- } >- >- auto dataTransfer = DataTransfer::createForCopyAndPaste(storeMode); >+ auto dataTransfer = createDataTransferForClipboardEvent(kind); > > ClipboardEvent::Init init; > init.bubbles = true; > init.cancelable = true; > init.clipboardData = dataTransfer.ptr(); >- auto event = ClipboardEvent::create(eventType, init, Event::IsTrusted::Yes); >+ auto event = ClipboardEvent::create(eventNameForClipboardEvent(kind), init, Event::IsTrusted::Yes); > > target->dispatchEvent(event); > bool noDefaultProcessing = event->defaultPrevented(); >- if (noDefaultProcessing && storeMode == DataTransfer::StoreMode::ReadWrite) { >+ if (noDefaultProcessing && (kind == ClipboardEventKind::Copy || kind == ClipboardEventKind::Cut)) { > auto pasteboard = Pasteboard::createForCopyAndPaste(); > pasteboard->clear(); > downcast<StaticPasteboard>(dataTransfer->pasteboard()).commitToPasteboard(*pasteboard); >@@ -364,19 +411,19 @@ bool Editor::canDHTMLCut() > if (m_frame.selection().selection().isInPasswordField()) > return false; > >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforecutEvent); >+ return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::BeforeCut); > } > > bool Editor::canDHTMLCopy() > { > if (m_frame.selection().selection().isInPasswordField()) > return false; >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforecopyEvent); >+ return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::BeforeCopy); > } > > bool Editor::canDHTMLPaste() > { >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforepasteEvent); >+ return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::BeforePaste); > } > > bool Editor::canCut() const >@@ -644,7 +691,7 @@ bool Editor::tryDHTMLCopy() > if (m_frame.selection().selection().isInPasswordField()) > return false; > >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().copyEvent); >+ return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::Copy); > } > > bool Editor::tryDHTMLCut() >@@ -652,12 +699,7 @@ bool Editor::tryDHTMLCut() > if (m_frame.selection().selection().isInPasswordField()) > return false; > >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().cutEvent); >-} >- >-bool Editor::tryDHTMLPaste() >-{ >- return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().pasteEvent); >+ return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::Cut); > } > > bool Editor::shouldInsertText(const String& text, Range* range, EditorInsertAction action) const >@@ -1336,7 +1378,7 @@ void Editor::paste() > > void Editor::paste(Pasteboard& pasteboard) > { >- if (tryDHTMLPaste()) >+ if (!dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::Paste)) > return; // DHTML did the whole operation > if (!canPaste()) > return; >@@ -1350,7 +1392,7 @@ void Editor::paste(Pasteboard& pasteboard) > > void Editor::pasteAsPlainText() > { >- if (tryDHTMLPaste()) >+ if (!dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::PasteAsPlainText)) > return; > if (!canPaste()) > return; >diff --git a/Source/WebCore/editing/Editor.h b/Source/WebCore/editing/Editor.h >index 84405cb9b7ff6855d35ed3717d01e4344993f67e..aa885ff599c1a075d3da0d07cdf2258516aea37d 100644 >--- a/Source/WebCore/editing/Editor.h >+++ b/Source/WebCore/editing/Editor.h >@@ -146,7 +146,6 @@ public: > WEBCORE_EXPORT bool canDHTMLPaste(); > bool tryDHTMLCopy(); > bool tryDHTMLCut(); >- WEBCORE_EXPORT bool tryDHTMLPaste(); > > WEBCORE_EXPORT bool canCut() const; > WEBCORE_EXPORT bool canCopy() const; >diff --git a/Source/WebCore/platform/ios/PasteboardIOS.mm b/Source/WebCore/platform/ios/PasteboardIOS.mm >index ce42c4aa25d6142a0520dcdba07c0334917f22d9..941028d73f6d8f86d815f13ef8fe3fd95461608d 100644 >--- a/Source/WebCore/platform/ios/PasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PasteboardIOS.mm >@@ -358,6 +358,10 @@ void Pasteboard::addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTy > resultTypes.add(ASCIILiteral("text/uri-list")); > return; > } >+ if ([cocoaType isEqualToString:(NSString *)kUTTypeHTML]) { >+ resultTypes.add(ASCIILiteral("text/html")); >+ // We don't return here for App compatibility. >+ } > if (Pasteboard::shouldTreatCocoaTypeAsFile(cocoaType)) > return; > String utiType = utiTypeFromCocoaType(cocoaType); >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index a9f6be0a3b9e605d918c92dd211dc7d993812343..07c72453b17574f9573d66ce1f43d8919c694e7e 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,18 @@ >+2017-10-05 Ryosuke Niwa <rniwa@webkit.org> >+ >+ DataTransfer shouldn't contain text/html when performing Paste and Match Style >+ https://bugs.webkit.org/show_bug.cgi?id=174165 >+ <rdar://problem/33138027> >+ >+ Reviewed by Wenson Hsieh. >+ >+ Added regression tests for pasting as plain text. >+ >+ * editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-expected.txt: Added. >+ * editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled-expected.txt: Added. >+ * editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled.html: Added. >+ * editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text.html: Added. >+ > 2017-10-02 Wenson Hsieh <wenson_hsieh@apple.com> > > REGRESSION(r222595): Intermittent crash while accessing DataTransferItemList >diff --git a/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-expected.txt b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..892bfb799cdfd941075d8a27d2a4eec6cf2e3124 >--- /dev/null >+++ b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-expected.txt >@@ -0,0 +1,15 @@ >+Tests that pasting as plain text only exposes "text/plain" in the clipboard. To manually test, press "Copy" below and paste (Command+V on macOS and Control+V elsewhere). >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS JSON.stringify(event.clipboardData.types) is "[\"text/plain\"]" >+PASS event.clipboardData.getData("text/plain") is "hello, world\nWebKit" >+PASS event.clipboardData.getData("text/html") is "" >+PASS event.clipboardData.items.length is 1 >+PASS item = event.clipboardData.items[0]; item.kind is "string" >+PASS item.type is "text/plain" >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled-expected.txt b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..45991490a727c2dbbb0bcb2c6ba61cf33ad04cd2 >--- /dev/null >+++ b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled-expected.txt >@@ -0,0 +1,16 @@ >+Tests that pasting as plain text only exposes "text/html" as well as "text/plain" in the clipboard when custom data support is turned off. >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS event.clipboardData.types.includes("text/plain") is true >+PASS event.clipboardData.types.includes("text/html") is true >+PASS event.clipboardData.getData("text/plain") is "hello, world\nWebKit" >+PASS event.clipboardData.getData("text/html") is not "" >+PASS items = Array.from(event.clipboardData.items); items.length >= 2 is true >+PASS items.some((item) => item.type == "text/plain") is true >+PASS items.some((item) => item.type == "text/html") is true >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled.html b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled.html >new file mode 100644 >index 0000000000000000000000000000000000000000..68cceaff13d2d47cbf4d3524ae9015932e78a428 >--- /dev/null >+++ b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text-when-custom-pasteboard-data-disabled.html >@@ -0,0 +1,40 @@ >+<!DOCTYPE html> >+<html> >+<body> >+<script src="../../resources/js-test-pre.js"></script> >+<div id="container"> >+<div id="source" contenteditable="true">hello, <b>world</b><br>WebKit</div> >+<div id="destination" onpaste="check(event)" contenteditable="true"></div> >+</div> >+</body> >+<script> >+description('Tests that pasting as plain text only exposes "text/html" as well as "text/plain" in the clipboard when custom data support is turned off.'); >+ >+if (!window.internals || !window.internals.settings) >+ testFailed('This test requires internals.settings'); >+else { >+ internals.settings.setCustomPasteboardDataEnabled(false); >+ >+ document.getElementById("source").focus(); >+ document.execCommand("SelectAll"); >+ document.execCommand("Copy"); >+ >+ document.getElementById("destination").focus(); >+ document.execCommand("Paste"); >+ document.getElementById('container').remove(); >+} >+ >+function check(event) >+{ >+ shouldBeTrue('event.clipboardData.types.includes("text/plain")'); >+ shouldBeTrue('event.clipboardData.types.includes("text/html")'); >+ shouldBeEqualToString('event.clipboardData.getData("text/plain")', 'hello, world\nWebKit'); >+ shouldNotBeEqualToString('event.clipboardData.getData("text/html")', ''); >+ shouldBeTrue('items = Array.from(event.clipboardData.items); items.length >= 2'); >+ shouldBeTrue('items.some((item) => item.type == "text/plain")'); >+ shouldBeTrue('items.some((item) => item.type == "text/html")'); >+} >+ >+</script> >+<script src="../../resources/js-test-post.js"></script> >+</html> >diff --git a/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text.html b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text.html >new file mode 100644 >index 0000000000000000000000000000000000000000..b77e7480e614da5885cd44c4bbf054d90d0d8121 >--- /dev/null >+++ b/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-as-plain-text.html >@@ -0,0 +1,48 @@ >+<!DOCTYPE html> >+<html> >+<body> >+<script src="../../resources/js-test-pre.js"></script> >+<div id="container"> >+<button onclick="runTest()">Copy</button> >+<div id="source" contenteditable="true">hello, <b>world</b><br>WebKit</div> >+<div id="destination" onpaste="check(event)" contenteditable="true" style="width: 500px; height: 100px; border: solid red 1px"></div> >+</div> >+</body> >+<script> >+description('Tests that pasting as plain text only exposes "text/plain" in the clipboard. To manually test, press "Copy" below and paste (Command+V on macOS and Control+V elsewhere).'); >+jsTestIsAsync = true; >+ >+function runTest() >+{ >+ if (window.internals) >+ internals.settings.setCustomPasteboardDataEnabled(true); >+ >+ document.getElementById("source").focus(); >+ document.execCommand("SelectAll"); >+ document.execCommand("Copy"); >+ >+ document.getElementById("destination").focus(); >+ if (window.testRunner) >+ document.execCommand("PasteAndMatchStyle"); >+} >+ >+function check(event) >+{ >+ shouldBeEqualToString('JSON.stringify(event.clipboardData.types)', '["text/plain"]'); >+ shouldBeEqualToString('event.clipboardData.getData("text/plain")', 'hello, world\nWebKit'); >+ shouldBeEqualToString('event.clipboardData.getData("text/html")', ''); >+ shouldBe('event.clipboardData.items.length', '1'); >+ shouldBeEqualToString('item = event.clipboardData.items[0]; item.kind', 'string'); >+ shouldBeEqualToString('item.type', 'text/plain'); >+ >+ document.getElementById('container').remove(); >+ >+ finishJSTest(); >+} >+ >+if (window.testRunner) >+ runTest(); >+ >+</script> >+<script src="../../resources/js-test-post.js"></script> >+</html>
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 174165
:
314620
|
322781
|
322791
|
322794
|
322805
|
322960
| 322966