Rename DataTransferAccessPolicy to match spec and refactor related node
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2017 21:53:51 +0000 (21:53 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Aug 2017 21:53:51 +0000 (21:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175704

Reviewed by Wenson Hsieh.

Renamed DataTransferAccessPolicy to DataTransfer::StoreMode to match the drag data store mode concept
in the HTML5 specification:
https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode

DataTransfer in addition to those states can be disassociated from the drag data store when it becomes
no longer valid. We also support a special mode which allows only updating the drag image.
These two states, Invalid and DragImageWritable, are added in addition to the three states in the spec.

Also split DragAndDrop type of DataTransfer into DragAndDropData and DragAndDropFiles, and refactored
the related code.

No new tests since there should be no behavioral change.

* WebCore.xcodeproj/project.pbxproj:
* dom/DataTransfer.cpp:
(WebCore::DataTransfer::DataTransfer): No longer takes forFileDrag boolean since it's folded into type.
(WebCore::DataTransfer::createForCopyAndPaste):
(WebCore::DataTransfer::~DataTransfer):
(WebCore::DataTransfer::setAccessPolicy): Deleted.
(WebCore::DataTransfer::canReadTypes const):
(WebCore::DataTransfer::canReadData const):
(WebCore::DataTransfer::canWriteData const):
(WebCore::DataTransfer::createForInputEvent):
(WebCore::DataTransfer::createForDrag):
(WebCore::DataTransfer::createForDrop):
(WebCore::DataTransfer::canSetDragImage const):
* dom/DataTransfer.h:
(WebCore::DataTransfer::makeInvalidForSecurity): Added.
(WebCore::DataTransfer::makeDragImageWritable): Added.
* dom/DataTransferAccessPolicy.h: Removed.
* editing/Editor.cpp:
(WebCore::dispatchClipboardEvent): Moved and renamed from dispatchCPPEvent. Now computes the store mode
inside the function to match the spec: https://w3c.github.io/clipboard-apis/#fire-a-clipboard-event
(WebCore::Editor::canDHTMLCut):
(WebCore::Editor::canDHTMLCopy):
(WebCore::Editor::canDHTMLPaste):
(WebCore::Editor::tryDHTMLCopy):
(WebCore::Editor::tryDHTMLCut):
(WebCore::Editor::tryDHTMLPaste):
(WebCore::Editor::dispatchCPPEvent): Deleted.
* editing/Editor.h:
* page/DragController.cpp:
(WebCore::createDataTransferToUpdateDrag): Extracted to share code.
(WebCore::DragController::dragExited):
(WebCore::DragController::performDragOperation):
(WebCore::DragController::tryDHTMLDrag):
* page/EventHandler.cpp:
(WebCore::EventHandler::invalidateDataTransfer):
(WebCore::EventHandler::handleDrag):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/DataTransfer.h
Source/WebCore/dom/DataTransferAccessPolicy.h [deleted file]
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp

index 75d67bb..0784fba 100644 (file)
@@ -1,3 +1,60 @@
+2017-08-18  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Rename DataTransferAccessPolicy to match spec and refactor related node
+        https://bugs.webkit.org/show_bug.cgi?id=175704
+
+        Reviewed by Wenson Hsieh.
+
+        Renamed DataTransferAccessPolicy to DataTransfer::StoreMode to match the drag data store mode concept
+        in the HTML5 specification:
+        https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode
+
+        DataTransfer in addition to those states can be disassociated from the drag data store when it becomes
+        no longer valid. We also support a special mode which allows only updating the drag image.
+        These two states, Invalid and DragImageWritable, are added in addition to the three states in the spec.
+
+        Also split DragAndDrop type of DataTransfer into DragAndDropData and DragAndDropFiles, and refactored
+        the related code.
+
+        No new tests since there should be no behavioral change.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/DataTransfer.cpp:
+        (WebCore::DataTransfer::DataTransfer): No longer takes forFileDrag boolean since it's folded into type.
+        (WebCore::DataTransfer::createForCopyAndPaste):
+        (WebCore::DataTransfer::~DataTransfer):
+        (WebCore::DataTransfer::setAccessPolicy): Deleted.
+        (WebCore::DataTransfer::canReadTypes const):
+        (WebCore::DataTransfer::canReadData const):
+        (WebCore::DataTransfer::canWriteData const):
+        (WebCore::DataTransfer::createForInputEvent):
+        (WebCore::DataTransfer::createForDrag):
+        (WebCore::DataTransfer::createForDrop):
+        (WebCore::DataTransfer::canSetDragImage const):
+        * dom/DataTransfer.h:
+        (WebCore::DataTransfer::makeInvalidForSecurity): Added.
+        (WebCore::DataTransfer::makeDragImageWritable): Added.
+        * dom/DataTransferAccessPolicy.h: Removed.
+        * editing/Editor.cpp:
+        (WebCore::dispatchClipboardEvent): Moved and renamed from dispatchCPPEvent. Now computes the store mode
+        inside the function to match the spec: https://w3c.github.io/clipboard-apis/#fire-a-clipboard-event
+        (WebCore::Editor::canDHTMLCut):
+        (WebCore::Editor::canDHTMLCopy):
+        (WebCore::Editor::canDHTMLPaste):
+        (WebCore::Editor::tryDHTMLCopy):
+        (WebCore::Editor::tryDHTMLCut):
+        (WebCore::Editor::tryDHTMLPaste):
+        (WebCore::Editor::dispatchCPPEvent): Deleted.
+        * editing/Editor.h:
+        * page/DragController.cpp:
+        (WebCore::createDataTransferToUpdateDrag): Extracted to share code.
+        (WebCore::DragController::dragExited):
+        (WebCore::DragController::performDragOperation):
+        (WebCore::DragController::tryDHTMLDrag):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::invalidateDataTransfer):
+        (WebCore::EventHandler::handleDrag):
+
 2017-08-18  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Followup (r220289): RenderImageResourceStyleImage code clean up
index da762b2..4b6b34b 100644 (file)
                4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */; };
                4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6FA6F20C39E48C00087011 /* SmartReplace.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4B6FA6F70C39E4A100087011 /* SmartReplaceCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */; };
-               4B8AF4AA0B1CE02B00687690 /* DataTransferAccessPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8AF4A90B1CE02B00687690 /* DataTransferAccessPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4BAE95B10B2FA9CE00AED8A0 /* EditorDeleteAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4E1959210A39DABA00220FE5 /* MediaFeatureNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */; };
                4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageSourceCG.h; sourceTree = "<group>"; };
                4B6FA6F20C39E48C00087011 /* SmartReplace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartReplace.h; sourceTree = "<group>"; };
                4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmartReplaceCF.cpp; sourceTree = "<group>"; };
-               4B8AF4A90B1CE02B00687690 /* DataTransferAccessPolicy.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DataTransferAccessPolicy.h; sourceTree = "<group>"; };
                4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorDeleteAction.h; sourceTree = "<group>"; };
                4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaFeatureNames.cpp; sourceTree = "<group>"; };
                4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaFeatureNames.h; sourceTree = "<group>"; };
                                A784941A0B5FE507001E237A /* DataTransfer.cpp */,
                                85031B280A44EFC700F992E0 /* DataTransfer.h */,
                                BCA83E360D7CDC4E003421A8 /* DataTransfer.idl */,
-                               4B8AF4A90B1CE02B00687690 /* DataTransferAccessPolicy.h */,
                                9B098BD51F3D6033002DD562 /* DataTransferItem.cpp */,
                                81AC5997131636E60009A7E0 /* DataTransferItem.h */,
                                81AC5AE81316392E0009A7E0 /* DataTransferItem.idl */,
                                BC22746F0E83664500E7F975 /* DataRef.h in Headers */,
                                BC64641C11D7F416006455B0 /* DatasetDOMStringMap.h in Headers */,
                                85031B3E0A44EFC700F992E0 /* DataTransfer.h in Headers */,
-                               4B8AF4AA0B1CE02B00687690 /* DataTransferAccessPolicy.h in Headers */,
                                81AC5999131636E60009A7E0 /* DataTransferItem.h in Headers */,
                                81AC599A131636E60009A7E0 /* DataTransferItemList.h in Headers */,
                                E4A007831B820EC8002C5A6E /* DataURLDecoder.h in Headers */,
index 21b4a51..505403c 100644 (file)
@@ -57,26 +57,25 @@ private:
 
 #endif
 
-DataTransfer::DataTransfer(DataTransferAccessPolicy policy, std::unique_ptr<Pasteboard> pasteboard, Type type, bool forFileDrag)
-    : m_policy(policy)
+DataTransfer::DataTransfer(StoreMode mode, std::unique_ptr<Pasteboard> pasteboard, Type type)
+    : m_storeMode(mode)
     , m_pasteboard(WTFMove(pasteboard))
 #if ENABLE(DRAG_SUPPORT)
-    , m_forDrag(type == DragAndDrop)
-    , m_forFileDrag(forFileDrag)
+    , m_forDrag(type == Type::DragAndDropData || type == Type::DragAndDropFiles)
+    , m_forFileDrag(type == Type::DragAndDropFiles)
     , m_dropEffect(ASCIILiteral("uninitialized"))
     , m_effectAllowed(ASCIILiteral("uninitialized"))
     , m_shouldUpdateDragImage(false)
 #endif
 {
 #if !ENABLE(DRAG_SUPPORT)
-    ASSERT_UNUSED(type, type != DragAndDrop);
-    ASSERT_UNUSED(forFileDrag, !forFileDrag);
+    ASSERT_UNUSED(type, type != DragAndDropData && type != DragAndDropFiles);
 #endif
 }
 
-Ref<DataTransfer> DataTransfer::createForCopyAndPaste(DataTransferAccessPolicy policy)
+Ref<DataTransfer> DataTransfer::createForCopyAndPaste(StoreMode mode)
 {
-    return adoptRef(*new DataTransfer(policy, policy == DataTransferAccessPolicy::Writable ? Pasteboard::createPrivate() : Pasteboard::createForCopyAndPaste()));
+    return adoptRef(*new DataTransfer(mode, mode == StoreMode::ReadWrite ? Pasteboard::createPrivate() : Pasteboard::createForCopyAndPaste()));
 }
 
 DataTransfer::~DataTransfer()
@@ -86,27 +85,20 @@ DataTransfer::~DataTransfer()
         m_dragImageLoader->stopLoading(m_dragImage);
 #endif
 }
-    
-void DataTransfer::setAccessPolicy(DataTransferAccessPolicy policy)
-{
-    // Once the dataTransfer goes numb, it can never go back.
-    ASSERT(m_policy != DataTransferAccessPolicy::Numb || policy == DataTransferAccessPolicy::Numb);
-    m_policy = policy;
-}
 
 bool DataTransfer::canReadTypes() const
 {
-    return m_policy == DataTransferAccessPolicy::Readable || m_policy == DataTransferAccessPolicy::TypesReadable || m_policy == DataTransferAccessPolicy::Writable;
+    return m_storeMode == StoreMode::Readonly || m_storeMode == StoreMode::Protected || m_storeMode == StoreMode::ReadWrite;
 }
 
 bool DataTransfer::canReadData() const
 {
-    return m_policy == DataTransferAccessPolicy::Readable || m_policy == DataTransferAccessPolicy::Writable;
+    return m_storeMode == StoreMode::Readonly || m_storeMode == StoreMode::ReadWrite;
 }
 
 bool DataTransfer::canWriteData() const
 {
-    return m_policy == DataTransferAccessPolicy::Writable;
+    return m_storeMode == StoreMode::ReadWrite;
 }
 
 void DataTransfer::clearData(const String& type)
@@ -214,7 +206,7 @@ Ref<DataTransfer> DataTransfer::createForInputEvent(const String& plainText, con
     TypeToStringMap typeToStringMap;
     typeToStringMap.set(ASCIILiteral("text/plain"), plainText);
     typeToStringMap.set(ASCIILiteral("text/html"), htmlText);
-    return adoptRef(*new DataTransfer(DataTransferAccessPolicy::Readable, StaticPasteboard::create(WTFMove(typeToStringMap)), InputEvent));
+    return adoptRef(*new DataTransfer(StoreMode::Readonly, StaticPasteboard::create(WTFMove(typeToStringMap)), Type::InputEvent));
 }
 
 #if !ENABLE(DRAG_SUPPORT)
@@ -245,12 +237,13 @@ void DataTransfer::setDragImage(Element*, int, int)
 
 Ref<DataTransfer> DataTransfer::createForDrag()
 {
-    return adoptRef(*new DataTransfer(DataTransferAccessPolicy::Writable, Pasteboard::createForDragAndDrop(), DragAndDrop));
+    return adoptRef(*new DataTransfer(StoreMode::ReadWrite, Pasteboard::createForDragAndDrop(), Type::DragAndDropData));
 }
 
-Ref<DataTransfer> DataTransfer::createForDrop(DataTransferAccessPolicy policy, const DragData& dragData)
+Ref<DataTransfer> DataTransfer::createForDrop(StoreMode accessMode, const DragData& dragData)
 {
-    return adoptRef(*new DataTransfer(policy, Pasteboard::createForDragAndDrop(dragData), DragAndDrop, dragData.containsFiles()));
+    auto type = dragData.containsFiles() ? Type::DragAndDropFiles : Type::DragAndDropData;
+    return adoptRef(*new DataTransfer(accessMode, Pasteboard::createForDragAndDrop(dragData), type));
 }
 
 bool DataTransfer::canSetDragImage() const
@@ -259,7 +252,7 @@ bool DataTransfer::canSetDragImage() const
     // event. This capability is maintained for backwards compatiblity for ports that have
     // supported this in the past. On many ports, attempting to set a drag image outside the
     // dragstart operation is a no-op anyway.
-    return m_forDrag && (m_policy == DataTransferAccessPolicy::ImageWritable || m_policy == DataTransferAccessPolicy::Writable);
+    return m_forDrag && (m_storeMode == StoreMode::DragImageWritable || m_storeMode == StoreMode::ReadWrite);
 }
 
 void DataTransfer::setDragImage(Element* element, int x, int y)
index 54333be..dd8438a 100644 (file)
@@ -24,7 +24,6 @@
 #pragma once
 
 #include "CachedResourceHandle.h"
-#include "DataTransferAccessPolicy.h"
 #include "DragActions.h"
 #include "DragImage.h"
 #include <wtf/text/WTFString.h>
@@ -41,7 +40,10 @@ class Pasteboard;
 
 class DataTransfer : public RefCounted<DataTransfer> {
 public:
-    static Ref<DataTransfer> createForCopyAndPaste(DataTransferAccessPolicy);
+    // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode
+    enum class StoreMode { Invalid, DragImageWritable, ReadWrite, Readonly, Protected };
+
+    static Ref<DataTransfer> createForCopyAndPaste(StoreMode);
     static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText);
 
     WEBCORE_EXPORT ~DataTransfer();
@@ -65,7 +67,13 @@ public:
 
     void setDragImage(Element*, int x, int y);
 
-    void setAccessPolicy(DataTransferAccessPolicy);
+    void makeInvalidForSecurity() { m_storeMode = StoreMode::Invalid; }
+    void makeDragImageWritable()
+    {
+        ASSERT(m_storeMode != StoreMode::Invalid);
+        m_storeMode = StoreMode::DragImageWritable;
+    }
+
     bool canReadTypes() const;
     bool canReadData() const;
     bool canWriteData() const;
@@ -77,7 +85,7 @@ public:
 
 #if ENABLE(DRAG_SUPPORT)
     static Ref<DataTransfer> createForDrag();
-    static Ref<DataTransfer> createForDrop(DataTransferAccessPolicy, const DragData&);
+    static Ref<DataTransfer> createForDrop(StoreMode, const DragData&);
 
     bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
 
@@ -92,14 +100,14 @@ public:
 #endif
 
 private:
-    enum Type { CopyAndPaste, DragAndDrop, InputEvent };
-    DataTransfer(DataTransferAccessPolicy, std::unique_ptr<Pasteboard>, Type = CopyAndPaste, bool forFileDrag = false);
+    enum class Type { CopyAndPaste, DragAndDropData, DragAndDropFiles, InputEvent };
+    DataTransfer(StoreMode, std::unique_ptr<Pasteboard>, Type = Type::CopyAndPaste);
 
 #if ENABLE(DRAG_SUPPORT)
     bool canSetDragImage() const;
 #endif
 
-    DataTransferAccessPolicy m_policy;
+    StoreMode m_storeMode;
     std::unique_ptr<Pasteboard> m_pasteboard;
     std::unique_ptr<DataTransferItemList> m_itemList;
 
diff --git a/Source/WebCore/dom/DataTransferAccessPolicy.h b/Source/WebCore/dom/DataTransferAccessPolicy.h
deleted file mode 100644 (file)
index a50e87a..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2006 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. 
- */
-
-#pragma once
-
-namespace WebCore {
-
-enum class DataTransferAccessPolicy {
-    Numb, ImageWritable, Writable, TypesReadable, Readable
-};
-
-} // namespace WebCore
index 9924403..47a7405 100644 (file)
@@ -313,6 +313,46 @@ bool Editor::canEditRichly() const
     return m_frame.selection().selection().isContentRichlyEditable();
 }
 
+// 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)
+{
+    // 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);
+
+    ClipboardEvent::Init init;
+    init.bubbles = true;
+    init.cancelable = true;
+    init.clipboardData = dataTransfer.ptr();
+    auto event = ClipboardEvent::create(eventType, init, Event::IsTrusted::Yes);
+
+    target->dispatchEvent(event);
+    bool noDefaultProcessing = event->defaultPrevented();
+    if (noDefaultProcessing && storeMode == DataTransfer::StoreMode::ReadWrite) {
+        auto pasteboard = Pasteboard::createForCopyAndPaste();
+        pasteboard->clear();
+        pasteboard->writePasteboard(dataTransfer->pasteboard());
+    }
+
+    dataTransfer->makeInvalidForSecurity();
+
+    return !noDefaultProcessing;
+}
+
 // WinIE uses onbeforecut and onbeforepaste to enables the cut and paste menu items.  They
 // also send onbeforecopy, apparently for symmetry, but it doesn't affect the menu items.
 // We need to use onbeforecopy as a real menu enabler because we allow elements that are not
@@ -320,17 +360,22 @@ bool Editor::canEditRichly() const
 
 bool Editor::canDHTMLCut()
 {
-    return !m_frame.selection().selection().isInPasswordField() && !dispatchCPPEvent(eventNames().beforecutEvent, DataTransferAccessPolicy::Numb);
+    if (m_frame.selection().selection().isInPasswordField())
+        return false;
+
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforecutEvent);
 }
 
 bool Editor::canDHTMLCopy()
 {
-    return !m_frame.selection().selection().isInPasswordField() && !dispatchCPPEvent(eventNames().beforecopyEvent, DataTransferAccessPolicy::Numb);
+    if (m_frame.selection().selection().isInPasswordField())
+        return false;
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforecopyEvent);
 }
 
 bool Editor::canDHTMLPaste()
 {
-    return !dispatchCPPEvent(eventNames().beforepasteEvent, DataTransferAccessPolicy::Numb);
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().beforepasteEvent);
 }
 
 bool Editor::canCut() const
@@ -598,7 +643,7 @@ bool Editor::tryDHTMLCopy()
     if (m_frame.selection().selection().isInPasswordField())
         return false;
 
-    return !dispatchCPPEvent(eventNames().copyEvent, DataTransferAccessPolicy::Writable);
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().copyEvent);
 }
 
 bool Editor::tryDHTMLCut()
@@ -606,12 +651,12 @@ bool Editor::tryDHTMLCut()
     if (m_frame.selection().selection().isInPasswordField())
         return false;
     
-    return !dispatchCPPEvent(eventNames().cutEvent, DataTransferAccessPolicy::Writable);
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().cutEvent);
 }
 
 bool Editor::tryDHTMLPaste()
 {
-    return !dispatchCPPEvent(eventNames().pasteEvent, DataTransferAccessPolicy::Readable);
+    return !dispatchClipboardEvent(findEventTargetFromSelection(), eventNames().pasteEvent);
 }
 
 bool Editor::shouldInsertText(const String& text, Range* range, EditorInsertAction action) const
@@ -775,35 +820,6 @@ void Editor::clearLastEditCommand()
     m_lastEditCommand = nullptr;
 }
 
-// Returns whether caller should continue with "the default processing", which is the same as 
-// the event handler NOT setting the return value to false
-bool Editor::dispatchCPPEvent(const AtomicString& eventType, DataTransferAccessPolicy policy)
-{
-    Element* target = findEventTargetFromSelection();
-    if (!target)
-        return true;
-
-    auto dataTransfer = DataTransfer::createForCopyAndPaste(policy);
-
-    ClipboardEvent::Init init;
-    init.bubbles = true;
-    init.cancelable = true;
-    init.clipboardData = dataTransfer.ptr();
-    auto event = ClipboardEvent::create(eventType, init, Event::IsTrusted::Yes);
-    target->dispatchEvent(event);
-    bool noDefaultProcessing = event->defaultPrevented();
-    if (noDefaultProcessing && policy == DataTransferAccessPolicy::Writable) {
-        auto pasteboard = Pasteboard::createForCopyAndPaste();
-        pasteboard->clear();
-        pasteboard->writePasteboard(dataTransfer->pasteboard());
-    }
-
-    // invalidate dataTransfer here for security
-    dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb);
-    
-    return !noDefaultProcessing;
-}
-
 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const
 {
     Element* target = selection.start().element();
index d651c24..26c027d 100644 (file)
@@ -26,7 +26,6 @@
 #pragma once
 
 #include "CompositionUnderline.h"
-#include "DataTransferAccessPolicy.h"
 #include "DictationAlternative.h"
 #include "DocumentMarker.h"
 #include "EditAction.h"
@@ -219,9 +218,7 @@ public:
 #if PLATFORM(IOS)
     WEBCORE_EXPORT void removeUnchangeableStyles();
 #endif
-    
-    bool dispatchCPPEvent(const AtomicString&, DataTransferAccessPolicy);
-    
+
     WEBCORE_EXPORT void applyStyle(StyleProperties*, EditAction = EditActionUnspecified);
     void applyStyle(RefPtr<EditingStyle>&&, EditAction);
     void applyParagraphStyle(StyleProperties*, EditAction = EditActionUnspecified);
index a13c30e..4713c39 100644 (file)
@@ -220,19 +220,30 @@ DragOperation DragController::dragEntered(const DragData& dragData)
     return dragEnteredOrUpdated(dragData);
 }
 
-void DragController::dragExited(const DragData& dragData)
+static Ref<DataTransfer> createDataTransferToUpdateDrag(const DragData& dragData, const Settings& settings, RefPtr<Document>&& documentUnderMouse)
 {
-    if (RefPtr<FrameView> v = m_page.mainFrame().view()) {
+    auto accessMode = DataTransfer::StoreMode::Protected;
+
 #if ENABLE(DASHBOARD_SUPPORT)
-        DataTransferAccessPolicy policy = (m_page.mainFrame().settings().usesDashboardBackwardCompatibilityMode() && (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin().isLocal()))
-            ? DataTransferAccessPolicy::Readable : DataTransferAccessPolicy::TypesReadable;
+    if (settings.usesDashboardBackwardCompatibilityMode() && (!documentUnderMouse || documentUnderMouse->securityOrigin().isLocal()))
+        accessMode = DataTransfer::StoreMode::Readonly;
 #else
-        DataTransferAccessPolicy policy = DataTransferAccessPolicy::TypesReadable;
+    UNUSED_PARAM(settings);
+    UNUSED_PARAM(documentUnderMouse);
 #endif
-        auto dataTransfer = DataTransfer::createForDrop(policy, dragData);
-        dataTransfer->setSourceOperation(dragData.draggingSourceOperationMask());
+
+    auto dataTransfer = DataTransfer::createForDrop(accessMode, dragData);
+    dataTransfer->setSourceOperation(dragData.draggingSourceOperationMask());
+
+    return dataTransfer;
+}
+
+void DragController::dragExited(const DragData& dragData)
+{
+    if (RefPtr<FrameView> v = m_page.mainFrame().view()) {
+        auto dataTransfer = createDataTransferToUpdateDrag(dragData, m_page.mainFrame().settings(), m_documentUnderMouse.copyRef());
         m_page.mainFrame().eventHandler().cancelDragAndDrop(createMouseEvent(dragData), dataTransfer);
-        dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
+        dataTransfer->makeInvalidForSecurity();
     }
     mouseMovedIntoDocument(nullptr);
     if (m_fileInputElementUnderMouse)
@@ -273,10 +284,10 @@ bool DragController::performDragOperation(const DragData& dragData)
         bool preventedDefault = false;
         if (mainFrame->view()) {
             // Sending an event can result in the destruction of the view and part.
-            auto dataTransfer = DataTransfer::createForDrop(DataTransferAccessPolicy::Readable, dragData);
+            auto dataTransfer = DataTransfer::createForDrop(DataTransfer::StoreMode::Readonly, dragData);
             dataTransfer->setSourceOperation(dragData.draggingSourceOperationMask());
             preventedDefault = mainFrame->eventHandler().performDragAndDrop(createMouseEvent(dragData), dataTransfer);
-            dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
+            dataTransfer->makeInvalidForSecurity();
         }
         if (preventedDefault) {
             clearDragCaret();
@@ -698,23 +709,16 @@ bool DragController::tryDHTMLDrag(const DragData& dragData, DragOperation& opera
     if (!viewProtector)
         return false;
 
-#if ENABLE(DASHBOARD_SUPPORT)
-    DataTransferAccessPolicy policy = (mainFrame->settings().usesDashboardBackwardCompatibilityMode() && m_documentUnderMouse->securityOrigin().isLocal()) ?
-        DataTransferAccessPolicy::Readable : DataTransferAccessPolicy::TypesReadable;
-#else
-    DataTransferAccessPolicy policy = DataTransferAccessPolicy::TypesReadable;
-#endif
-    auto dataTransfer = DataTransfer::createForDrop(policy, dragData);
-    DragOperation srcOpMask = dragData.draggingSourceOperationMask();
-    dataTransfer->setSourceOperation(srcOpMask);
+    auto dataTransfer = createDataTransferToUpdateDrag(dragData, mainFrame->settings(), m_documentUnderMouse.copyRef());
 
     PlatformMouseEvent event = createMouseEvent(dragData);
     if (!mainFrame->eventHandler().updateDragAndDrop(event, dataTransfer)) {
-        dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
+        dataTransfer->makeInvalidForSecurity();
         return false;
     }
 
     operation = dataTransfer->destinationOperation();
+    DragOperation srcOpMask = dragData.draggingSourceOperationMask();
     if (dataTransfer->dropEffectIsUninitialized())
         operation = defaultOperationForDrag(srcOpMask);
     else if (!(srcOpMask & operation)) {
@@ -722,7 +726,7 @@ bool DragController::tryDHTMLDrag(const DragData& dragData, DragOperation& opera
         operation = DragOperationNone;
     }
 
-    dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
+    dataTransfer->makeInvalidForSecurity();
     return true;
 }
 
index 816ebb2..e021fa3 100644 (file)
@@ -3461,7 +3461,7 @@ void EventHandler::invalidateDataTransfer()
 {
     if (!dragState().dataTransfer)
         return;
-    dragState().dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb);
+    dragState().dataTransfer->makeInvalidForSecurity();
     dragState().dataTransfer = nullptr;
 }
 
@@ -3679,14 +3679,14 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
                 return true;
             }
         } 
-        
+
         m_mouseDownMayStartDrag = dispatchDragSrcEvent(eventNames().dragstartEvent, m_mouseDown)
             && !m_frame.selection().selection().isInPasswordField();
-        
+
         // Invalidate dataTransfer here against anymore pasteboard writing for security. The drag
         // image can still be changed as we drag, but not the pasteboard data.
-        dragState().dataTransfer->setAccessPolicy(DataTransferAccessPolicy::ImageWritable);
-        
+        dragState().dataTransfer->makeDragImageWritable();
+
         if (m_mouseDownMayStartDrag) {
             // Gather values from DHTML element, if it set any.
             srcOp = dragState().dataTransfer->sourceOperation();