DragData should not depend on Clipboard, DocumentFragment, and Document
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Sep 2014 06:27:46 +0000 (06:27 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Sep 2014 06:27:46 +0000 (06:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=21358

Reviewed by Darin Adler.

Source/WebCore:

Refactor DragData to not depend on Frame, DocumentFragment,
Document and Range. DragData::asFragment() has been moved to
DragController and implemented in the platform specific file.
DragData methods using Frame has been reworked in Mac to not use
Frame, since all other ports were ignoreing the frame parameter.

* page/DragController.cpp:
(WebCore::DragController::documentFragmentFromDragData): Make it
a static member to be able to use createFragmentFromDragData().
(WebCore::DragController::performDragOperation): Update to
DragData API changes.
(WebCore::DragController::dispatchTextInputEventFor): Ditto.
(WebCore::DragController::concludeEditDrag): Ditto.
(WebCore::documentFragmentFromDragData): Deleted.
* page/DragController.h:
* page/efl/DragControllerEfl.cpp:
(WebCore::DragController::createFragmentFromDragData): Move
DragData::asFragment() implementation here.
* page/gtk/DragControllerGtk.cpp:
(WebCore::DragController::dragOperation):
(WebCore::DragController::createFragmentFromDragData): Ditto.
* page/mac/DragControllerMac.mm:
(WebCore::DragController::dragOperation):
(WebCore::DragController::createFragmentFromDragData): Ditto.
* page/win/DragControllerWin.cpp:
(WebCore::DragController::createFragmentFromDragData): Ditto.
* platform/DragData.h:
* platform/efl/DragDataEfl.cpp:
(WebCore::DragData::asPlainText): Remove Frame parameter.
(WebCore::DragData::containsURL): Ditto.
(WebCore::DragData::asURL): Ditto.
(WebCore::DragData::asFragment): Deleted.
* platform/gtk/DragDataGtk.cpp:
(WebCore::DragData::asPlainText): Remove Frame parameter.
(WebCore::DragData::containsCompatibleContent):
(WebCore::DragData::containsURL): Ditto.
(WebCore::DragData::asURL): Ditto.
(WebCore::DragData::asFragment): Deleted.
* platform/mac/DragDataMac.mm:
(WebCore::DragData::asPlainText): Same implementation as the
Editor.
(WebCore::DragData::containsURL): Remove Frame parameter.
(WebCore::DragData::asURL): Use URLByCanonicalizingURL() instead
of using the Editor client.
(WebCore::DragData::asFragment): Deleted.
* platform/win/DragDataWin.cpp:
(WebCore::DragData::containsURL): Remove Frame parameter.
(WebCore::DragData::asURL): Ditto.
(WebCore::DragData::asPlainText): Ditto.
(WebCore::DragData::containsCompatibleContent):
(WebCore::DragData::asFragment): Deleted.

Source/WebKit2:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::performDragControllerAction): Update to API
change in DragData::asURL().

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/DragController.cpp
Source/WebCore/page/DragController.h
Source/WebCore/page/efl/DragControllerEfl.cpp
Source/WebCore/page/gtk/DragControllerGtk.cpp
Source/WebCore/page/mac/DragControllerMac.mm
Source/WebCore/page/win/DragControllerWin.cpp
Source/WebCore/platform/DragData.h
Source/WebCore/platform/efl/DragDataEfl.cpp
Source/WebCore/platform/gtk/DragDataGtk.cpp
Source/WebCore/platform/mac/DragDataMac.mm
Source/WebCore/platform/win/ClipboardUtilitiesWin.h
Source/WebCore/platform/win/DragDataWin.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp

index 7dff6e6..52ea6d8 100644 (file)
@@ -1,3 +1,62 @@
+2014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        DragData should not depend on Clipboard, DocumentFragment, and Document
+        https://bugs.webkit.org/show_bug.cgi?id=21358
+
+        Reviewed by Darin Adler.
+
+        Refactor DragData to not depend on Frame, DocumentFragment,
+        Document and Range. DragData::asFragment() has been moved to
+        DragController and implemented in the platform specific file.
+        DragData methods using Frame has been reworked in Mac to not use
+        Frame, since all other ports were ignoreing the frame parameter.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::documentFragmentFromDragData): Make it
+        a static member to be able to use createFragmentFromDragData().
+        (WebCore::DragController::performDragOperation): Update to
+        DragData API changes.
+        (WebCore::DragController::dispatchTextInputEventFor): Ditto.
+        (WebCore::DragController::concludeEditDrag): Ditto.
+        (WebCore::documentFragmentFromDragData): Deleted.
+        * page/DragController.h:
+        * page/efl/DragControllerEfl.cpp:
+        (WebCore::DragController::createFragmentFromDragData): Move
+        DragData::asFragment() implementation here.
+        * page/gtk/DragControllerGtk.cpp:
+        (WebCore::DragController::dragOperation):
+        (WebCore::DragController::createFragmentFromDragData): Ditto.
+        * page/mac/DragControllerMac.mm:
+        (WebCore::DragController::dragOperation):
+        (WebCore::DragController::createFragmentFromDragData): Ditto.
+        * page/win/DragControllerWin.cpp:
+        (WebCore::DragController::createFragmentFromDragData): Ditto.
+        * platform/DragData.h:
+        * platform/efl/DragDataEfl.cpp:
+        (WebCore::DragData::asPlainText): Remove Frame parameter.
+        (WebCore::DragData::containsURL): Ditto.
+        (WebCore::DragData::asURL): Ditto.
+        (WebCore::DragData::asFragment): Deleted.
+        * platform/gtk/DragDataGtk.cpp:
+        (WebCore::DragData::asPlainText): Remove Frame parameter.
+        (WebCore::DragData::containsCompatibleContent):
+        (WebCore::DragData::containsURL): Ditto.
+        (WebCore::DragData::asURL): Ditto.
+        (WebCore::DragData::asFragment): Deleted.
+        * platform/mac/DragDataMac.mm:
+        (WebCore::DragData::asPlainText): Same implementation as the
+        Editor.
+        (WebCore::DragData::containsURL): Remove Frame parameter.
+        (WebCore::DragData::asURL): Use URLByCanonicalizingURL() instead
+        of using the Editor client.
+        (WebCore::DragData::asFragment): Deleted.
+        * platform/win/DragDataWin.cpp:
+        (WebCore::DragData::containsURL): Remove Frame parameter.
+        (WebCore::DragData::asURL): Ditto.
+        (WebCore::DragData::asPlainText): Ditto.
+        (WebCore::DragData::containsCompatibleContent):
+        (WebCore::DragData::asFragment): Deleted.
+
 2014-09-16  Chris Dumez  <cdumez@apple.com>
 
         Rename Node::childNode(index) to traverseToChildAt(index) for clarity
index dcbf938..9542965 100644 (file)
@@ -114,25 +114,25 @@ DragController::~DragController()
     m_client.dragControllerDestroyed();
 }
 
-static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData& dragData, Frame* frame, Range& context, bool allowPlainText, bool& chosePlainText)
+PassRefPtr<DocumentFragment> DragController::documentFragmentFromDragData(DragData& dragData, Frame& frame, Range& context, bool allowPlainText, bool& chosePlainText)
 {
     chosePlainText = false;
 
     Document& document = context.ownerDocument();
     if (dragData.containsCompatibleContent()) {
-        if (PassRefPtr<DocumentFragment> fragment = dragData.asFragment(frame, context, allowPlainText, chosePlainText))
+        if (PassRefPtr<DocumentFragment> fragment = createFragmentFromDragData(dragData, frame, context, allowPlainText, chosePlainText))
             return fragment;
 
-        if (dragData.containsURL(frame, DragData::DoNotConvertFilenames)) {
+        if (dragData.containsURL(DragData::DoNotConvertFilenames)) {
             String title;
-            String url = dragData.asURL(frame, DragData::DoNotConvertFilenames, &title);
+            String url = dragData.asURL(DragData::DoNotConvertFilenames, &title);
             if (!url.isEmpty()) {
                 RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document);
                 anchor->setHref(url);
                 if (title.isEmpty()) {
                     // Try the plain text first because the url might be normalized or escaped.
                     if (dragData.containsPlainText())
-                        title = dragData.asPlainText(frame);
+                        title = dragData.asPlainText();
                     if (title.isEmpty())
                         title = url;
                 }
@@ -146,7 +146,7 @@ static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData& dragD
     }
     if (allowPlainText && dragData.containsPlainText()) {
         chosePlainText = true;
-        return createFragmentFromText(context, dragData.asPlainText(frame)).get();
+        return createFragmentFromText(context, dragData.asPlainText()).get();
     }
 
     return 0;
@@ -234,7 +234,7 @@ bool DragController::performDragOperation(DragData& dragData)
         return false;
 
     m_client.willPerformDragDestinationAction(DragDestinationActionLoad, dragData);
-    m_page.mainFrame().loader().load(FrameLoadRequest(&m_page.mainFrame(), ResourceRequest(dragData.asURL(&m_page.mainFrame()))));
+    m_page.mainFrame().loader().load(FrameLoadRequest(&m_page.mainFrame(), ResourceRequest(dragData.asURL())));
     return true;
 }
 
@@ -425,7 +425,7 @@ static bool setSelectionToDragCaret(Frame* frame, VisibleSelection& dragCaret, R
 bool DragController::dispatchTextInputEventFor(Frame* innerFrame, DragData& dragData)
 {
     ASSERT(m_page.dragCaretController().hasCaret());
-    String text = m_page.dragCaretController().isContentRichlyEditable() ? emptyString() : dragData.asPlainText(innerFrame);
+    String text = m_page.dragCaretController().isContentRichlyEditable() ? emptyString() : dragData.asPlainText();
     Node* target = innerFrame->editor().findEventTargetFrom(m_page.dragCaretController().caretPosition());
     return target->dispatchEvent(TextEvent::createForDrop(innerFrame->document()->domWindow(), text), IGNORE_EXCEPTION);
 }
@@ -494,7 +494,7 @@ bool DragController::concludeEditDrag(DragData& dragData)
     ResourceCacheValidationSuppressor validationSuppressor(cachedResourceLoader);
     if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRichlyEditable()) {
         bool chosePlainText = false;
-        RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, innerFrame.get(), *range, true, chosePlainText);
+        RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, *innerFrame, *range, true, chosePlainText);
         if (!fragment || !innerFrame->editor().shouldInsertFragment(fragment, range, EditorInsertActionDropped)) {
             return false;
         }
@@ -517,7 +517,7 @@ bool DragController::concludeEditDrag(DragData& dragData)
             }
         }
     } else {
-        String text = dragData.asPlainText(innerFrame.get());
+        String text = dragData.asPlainText();
         if (text.isEmpty() || !innerFrame->editor().shouldInsertText(text, range.get(), EditorInsertActionDropped)) {
             return false;
         }
index 25a616f..7eeb171 100644 (file)
@@ -35,6 +35,7 @@ namespace WebCore {
 
     class DataTransfer;
     class Document;
+    class DocumentFragment;
     class DragClient;
     class DragData;
     class Element;
@@ -44,6 +45,7 @@ namespace WebCore {
     class IntRect;
     class Page;
     class PlatformMouseEvent;
+    class Range;
 
     struct DragState;
 
@@ -113,6 +115,10 @@ namespace WebCore {
         void cleanupAfterSystemDrag();
         void declareAndWriteDragImage(DataTransfer&, Element&, const URL&, const String& label);
 
+        // FIXME: Move createFragmentFromDragData implementation to the Editor and make documentFragmentFromDragData a static function again.
+        static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData&, Frame&, Range&, bool allowPlainText, bool& chosePlainText);
+        static PassRefPtr<DocumentFragment> createFragmentFromDragData(DragData&, Frame&, Range&, bool allowPlainText, bool& chosePlainText);
+
         Page& m_page;
         DragClient& m_client;
 
index 9db3868..3615548 100644 (file)
@@ -29,6 +29,8 @@
 #include "config.h"
 #include "DragController.h"
 
+#include "Document.h"
+#include "DocumentFragment.h"
 #include "DragData.h"
 #include "Frame.h"
 #include "FrameView.h"
@@ -50,7 +52,7 @@ bool DragController::isCopyKeyDown(DragData&)
 
 DragOperation DragController::dragOperation(DragData& dragData)
 {
-    if (dragData.containsURL(0))
+    if (dragData.containsURL())
         return DragOperationCopy;
 
     return DragOperationNone;
@@ -71,4 +73,9 @@ void DragController::declareAndWriteDragImage(DataTransfer&, Element&, const URL
 {
 }
 
+PassRefPtr<DocumentFragment> DragController::createFragmentFromDragData(DragData&, Frame&, Range&, bool /*allowPlainText*/, bool& /*chosePlainText*/)
+{
+    return nullptr;
+}
+
 }
index 54fc8e6..172c5d4 100644 (file)
 #include "config.h"
 #include "DragController.h"
 
+#include "DataObjectGtk.h"
 #include "DataTransfer.h"
+#include "Document.h"
+#include "DocumentFragment.h"
 #include "DragData.h"
 #include "Element.h"
 #include "Frame.h"
 #include "FrameView.h"
 #include "Page.h"
 #include "Pasteboard.h"
+#include "markup.h"
 
 namespace WebCore {
 
@@ -53,7 +57,7 @@ bool DragController::isCopyKeyDown(DragData&)
 DragOperation DragController::dragOperation(DragData& dragData)
 {
     // FIXME: This logic is incomplete
-    if (dragData.containsURL(0))
+    if (dragData.containsURL())
         return DragOperationCopy;
 
     return DragOperationNone;
@@ -74,4 +78,12 @@ void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Elemen
     dataTransfer.pasteboard().writeImage(element, url, label);
 }
 
+PassRefPtr<DocumentFragment> DragController::createFragmentFromDragData(DragData& dragData, Frame& frame, Range&, bool /*allowPlainText*/, bool& /*chosePlainText*/)
+{
+    if (!dragData.platformData()->hasMarkup() || !frame.document())
+        return nullptr;
+
+    return createFragmentFromMarkup(*frame.document(), dragData.platformData()->markup(), "");
+}
+
 }
index 94afa1c..97a6ac3 100644 (file)
 #if ENABLE(DRAG_SUPPORT)
 
 #import "DataTransfer.h"
+#import "Document.h"
+#import "DocumentFragment.h"
 #import "DragClient.h"
 #import "DragData.h"
+#import "Editor.h"
+#import "EditorClient.h"
 #import "Element.h"
 #import "FrameView.h"
 #import "MainFrame.h"
 #import "Page.h"
 #import "Pasteboard.h"
+#import "Range.h"
 
 namespace WebCore {
 
@@ -54,7 +59,7 @@ bool DragController::isCopyKeyDown(DragData& dragData)
     
 DragOperation DragController::dragOperation(DragData& dragData)
 {
-    if ((dragData.flags() & DragApplicationIsModal) || !dragData.containsURL(&m_page.mainFrame()))
+    if ((dragData.flags() & DragApplicationIsModal) || !dragData.containsURL())
         return DragOperationNone;
 
     if (!m_documentUnderMouse || (!(dragData.flags() & (DragApplicationHasAttachedSheet | DragApplicationIsSource))))
@@ -87,6 +92,12 @@ void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Elemen
     m_client.declareAndWriteDragImage(dataTransfer.pasteboard().name(), element, url, label, element.document().frame());
 }
 
+PassRefPtr<DocumentFragment> DragController::createFragmentFromDragData(DragData& dragData, Frame& frame, Range& context, bool allowPlainText, bool& chosePlainText)
+{
+    Pasteboard pasteboard(dragData.pasteboardName());
+    return frame.editor().webContentFromPasteboard(pasteboard, context, allowPlainText, chosePlainText);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(DRAG_SUPPORT)
index d19ca88..bb06a45 100644 (file)
 #include "config.h"
 #include "DragController.h"
 
+#include "ClipboardUtilitiesWin.h"
 #include "DataTransfer.h"
+#include "Document.h"
+#include "DocumentFragment.h"
 #include "DragData.h"
 #include "Element.h"
+#include "Frame.h"
 #include "FrameSelection.h"
 #include "Pasteboard.h"
 #include "markup.h"
@@ -50,7 +54,7 @@ DragOperation DragController::dragOperation(DragData& dragData)
     //if we are a modal window, we are the drag source, or the window is an attached sheet
     //If this can be determined from within WebCore operationForDrag can be pulled into 
     //WebCore itself
-    return dragData.containsURL(0) && !m_didInitiateDrag ? DragOperationCopy : DragOperationNone;
+    return dragData.containsURL() && !m_didInitiateDrag ? DragOperationCopy : DragOperationNone;
 }
 
 bool DragController::isCopyKeyDown(DragData&)
@@ -83,4 +87,27 @@ void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Elemen
     pasteboard.writeMarkup(createMarkup(element, IncludeNode, 0, ResolveAllURLs));
 }
 
+template <typename PlatformDragData>
+static PassRefPtr<DocumentFragment> createFragmentFromPlatformData(PlatformDragData* platformDragData, Frame& frame)
+{
+    if (containsFilenames(platformDragData)) {
+        if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(frame.document(), platformDragData))
+            return fragment;
+    }
+
+    if (containsHTML(platformDragData)) {
+        if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(frame.document(), platformDragData))
+            return fragment;
+    }
+    return nullptr;
+}
+
+PassRefPtr<DocumentFragment> DragController::createFragmentFromDragData(DragData& dragData, Frame& frame, Range&, bool /*allowPlainText*/, bool& /*chosePlainText*/)
+{
+    if (DragDataRef platformDragData = dragData.platformData())
+        return createFragmentFromPlatformData(platformDragData, frame);
+
+    return createFragmentFromPlatformData(&dragData.dragDataMap(), frame);
+}
+
 }
index 880126d..56b1197 100644 (file)
@@ -60,10 +60,7 @@ typedef void* DragDataRef;
 
 namespace WebCore {
 
-class Frame;
-class DocumentFragment;
 class URL;
-class Range;
 
 enum DragApplicationFlags {
     DragApplicationNone = 0,
@@ -95,14 +92,13 @@ public:
     DragApplicationFlags flags() const { return m_applicationFlags; }
     DragDataRef platformData() const { return m_platformDragData; }
     DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; }
-    bool containsURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames) const;
+    bool containsURL(FilenameConversionPolicy = ConvertFilenames) const;
     bool containsPlainText() const;
     bool containsCompatibleContent() const;
-    String asURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames, String* title = 0) const;
-    String asPlainText(Frame*) const;
+    String asURL(FilenameConversionPolicy = ConvertFilenames, String* title = nullptr) const;
+    String asPlainText() const;
     void asFilenames(Vector<String>&) const;
     Color asColor() const;
-    PassRefPtr<DocumentFragment> asFragment(Frame*, Range& context, bool allowPlainText, bool& chosePlainText) const;
     bool canSmartReplace() const;
     bool containsColor() const;
     bool containsFiles() const;
index dcc8efb..002a790 100644 (file)
@@ -21,8 +21,7 @@
 #include "config.h"
 #include "DragData.h"
 
-#include "Document.h"
-#include "DocumentFragment.h"
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -55,7 +54,7 @@ bool DragData::containsPlainText() const
     return false;
 }
 
-String DragData::asPlainText(Frame*) const
+String DragData::asPlainText() const
 {
     return String();
 }
@@ -70,19 +69,14 @@ bool DragData::containsCompatibleContent() const
     return false;
 }
 
-bool DragData::containsURL(Frame*, FilenameConversionPolicy) const
+bool DragData::containsURL(FilenameConversionPolicy) const
 {
     return false;
 }
 
-String DragData::asURL(Frame*, FilenameConversionPolicy, String*) const
+String DragData::asURL(FilenameConversionPolicy, String*) const
 {
     return String();
 }
 
-PassRefPtr<DocumentFragment> DragData::asFragment(Frame*, Range&, bool, bool&) const
-{
-    return 0;
-}
-
 }
index 2bf34df..598c444 100644 (file)
 #include "DragData.h"
 
 #include "DataObjectGtk.h"
-#include "Document.h"
-#include "DocumentFragment.h"
-#include "Frame.h"
-#include "markup.h"
 
 namespace WebCore {
 
@@ -55,7 +51,7 @@ bool DragData::containsPlainText() const
     return m_platformDragData->hasText();
 }
 
-String DragData::asPlainText(Frame*) const
+String DragData::asPlainText() const
 {
     return m_platformDragData->text();
 }
@@ -67,15 +63,15 @@ Color DragData::asColor() const
 
 bool DragData::containsCompatibleContent() const
 {
-    return containsPlainText() || containsURL(0) || m_platformDragData->hasMarkup() || containsColor() || containsFiles();
+    return containsPlainText() || containsURL() || m_platformDragData->hasMarkup() || containsColor() || containsFiles();
 }
 
-bool DragData::containsURL(Frame* frame, FilenameConversionPolicy filenamePolicy) const
+bool DragData::containsURL(FilenameConversionPolicy filenamePolicy) const
 {
-    return !asURL(frame, filenamePolicy).isEmpty();
+    return !asURL(filenamePolicy).isEmpty();
 }
 
-String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
+String DragData::asURL(FilenameConversionPolicy filenamePolicy, String* title) const
 {
     if (!m_platformDragData->hasURL())
         return String();
@@ -91,16 +87,4 @@ String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String*
     return url;
 }
 
-
-PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, Range&, bool, bool&) const
-{
-    if (!m_platformDragData->hasMarkup())
-        return nullptr;
-
-    if (!frame->document())
-        return nullptr;
-
-    return createFragmentFromMarkup(*frame->document(), m_platformDragData->markup(), "");
-}
-
 }
index d52a4ea..9cb208a 100644 (file)
 #import "DragData.h"
 
 #if ENABLE(DRAG_SUPPORT)
-#import "Document.h"
-#import "DocumentFragment.h"
-#import "DOMDocumentFragment.h"
-#import "DOMDocumentFragmentInternal.h"
-#import "Editor.h"
-#import "EditorClient.h"
-#import "Frame.h"
 #import "MIMETypeRegistry.h"
 #import "Pasteboard.h"
 #import "PasteboardStrategy.h"
 #import "PlatformStrategies.h"
-#import "Range.h"
+#import "WebCoreNSURLExtras.h"
 
 namespace WebCore {
 
@@ -107,9 +100,20 @@ bool DragData::containsPlainText() const
         || platformStrategies()->pasteboardStrategy()->stringForType(String(NSURLPboardType), m_pasteboardName).length();
 }
 
-String DragData::asPlainText(Frame *frame) const
+String DragData::asPlainText() const
 {
-    return frame->editor().readPlainTextFromPasteboard(*Pasteboard::create(m_pasteboardName));
+    Pasteboard pasteboard(m_pasteboardName);
+    PasteboardPlainText text;
+    pasteboard.read(text);
+    String string = text.text;
+
+    // FIXME: It's not clear this is 100% correct since we know -[NSURL URLWithString:] does not handle
+    // all the same cases we handle well in the URL code for creating an NSURL.
+    if (text.isURL)
+        return userVisibleString([NSURL URLWithString:string]);
+
+    // FIXME: WTF should offer a non-Mac-specific way to convert string to precomposed form so we can do it for all platforms.
+    return [(NSString *)string precomposedStringWithCanonicalMapping];
 }
 
 Color DragData::asColor() const
@@ -134,12 +138,12 @@ bool DragData::containsCompatibleContent() const
         || types.contains(String(kUTTypePNG));
 }
     
-bool DragData::containsURL(Frame* frame, FilenameConversionPolicy filenamePolicy) const
+bool DragData::containsURL(FilenameConversionPolicy filenamePolicy) const
 {
-    return !asURL(frame, filenamePolicy).isEmpty();
+    return !asURL(filenamePolicy).isEmpty();
 }
 
-String DragData::asURL(Frame* frame, FilenameConversionPolicy, String* title) const
+String DragData::asURL(FilenameConversionPolicy, String* title) const
 {
     // FIXME: Use filenamePolicy.
 
@@ -151,17 +155,13 @@ String DragData::asURL(Frame* frame, FilenameConversionPolicy, String* title) co
     
     Vector<String> types;
     platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName);
-    
-    // FIXME: using the editorClient to call into WebKit, for now, since 
-    // calling webkit_canonicalize from WebCore involves migrating a sizable amount of 
-    // helper code that should either be done in a separate patch or figured out in another way.
-    
+
     if (types.contains(String(NSURLPboardType))) {
         NSURL *URLFromPasteboard = [NSURL URLWithString:platformStrategies()->pasteboardStrategy()->stringForType(String(NSURLPboardType), m_pasteboardName)];
         NSString *scheme = [URLFromPasteboard scheme];
         // Cannot drop other schemes unless <rdar://problem/10562662> and <rdar://problem/11187315> are fixed.
         if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"])
-            return [frame->editor().client()->canonicalizeURL(URLFromPasteboard) absoluteString];
+            return [URLByCanonicalizingURL(URLFromPasteboard) absoluteString];
     }
     
     if (types.contains(String(NSStringPboardType))) {
@@ -171,7 +171,7 @@ String DragData::asURL(Frame* frame, FilenameConversionPolicy, String* title) co
         // The result of this function is used to initiate navigation, so we shouldn't allow arbitrary file URLs.
         // FIXME: Should we allow only http family schemes, or anything non-local?
         if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"])
-            return [frame->editor().client()->canonicalizeURL(URLFromPasteboard) absoluteString];
+            return [URLByCanonicalizingURL(URLFromPasteboard) absoluteString];
     }
     
     if (types.contains(String(NSFilenamesPboardType))) {
@@ -181,19 +181,13 @@ String DragData::asURL(Frame* frame, FilenameConversionPolicy, String* title) co
             BOOL isDirectory;
             if ([[NSFileManager defaultManager] fileExistsAtPath:files[0] isDirectory:&isDirectory] && isDirectory)
                 return String();
-            return [frame->editor().client()->canonicalizeURL([NSURL fileURLWithPath:files[0]]) absoluteString];
+            return [URLByCanonicalizingURL([NSURL fileURLWithPath:files[0]]) absoluteString];
         }
     }
     
     return String();        
 }
 
-PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, Range& range, bool allowPlainText, bool& chosePlainText) const
-{
-    Pasteboard pasteboard(m_pasteboardName);
-    return frame->editor().webContentFromPasteboard(pasteboard, range, allowPlainText, chosePlainText);
-}
-    
 } // namespace WebCore
 
 #endif // ENABLE(DRAG_SUPPORT)
index 417ce2f..c2f16d7 100644 (file)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class Document;
+class DocumentFragment;
 class URL;
 
 HGLOBAL createGlobalData(const String&);
index 5a7f736..700570a 100644 (file)
 
 #include "COMPtr.h"
 #include "ClipboardUtilitiesWin.h"
-#include "Frame.h"
-#include "DocumentFragment.h"
-#include "Markup.h"
-#include "Range.h"
 #include "TextEncoding.h"
 #include <objidl.h>
 #include <shlwapi.h>
@@ -56,7 +52,7 @@ DragData::DragData(const DragDataMap& data, const IntPoint& clientPosition, cons
 {
 }
 
-bool DragData::containsURL(Frame*, FilenameConversionPolicy filenamePolicy) const
+bool DragData::containsURL(FilenameConversionPolicy filenamePolicy) const
 {
     if (m_platformDragData)
         return SUCCEEDED(m_platformDragData->QueryGetData(urlWFormat())) 
@@ -101,7 +97,7 @@ void DragData::getDragFileContentData(int size, void* dataBlob)
         getFileContentData(m_platformDragData, size, dataBlob);
 }
 
-String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
+String DragData::asURL(FilenameConversionPolicy filenamePolicy, String* title) const
 {
     return (m_platformDragData) ? getURL(m_platformDragData, filenamePolicy, title) : getURL(&m_dragDataMap, filenamePolicy, title);
 }
@@ -181,7 +177,7 @@ bool DragData::containsPlainText() const
     return m_dragDataMap.contains(plainTextWFormat()->cfFormat) || m_dragDataMap.contains(plainTextFormat()->cfFormat);
 }
 
-String DragData::asPlainText(Frame*) const
+String DragData::asPlainText() const
 {
     return (m_platformDragData) ? getPlainText(m_platformDragData) : getPlainText(&m_dragDataMap);
 }
@@ -200,48 +196,12 @@ bool DragData::canSmartReplace() const
 
 bool DragData::containsCompatibleContent() const
 {
-    return containsPlainText() || containsURL(0) 
+    return containsPlainText() || containsURL()
         || ((m_platformDragData) ? (containsHTML(m_platformDragData) || containsFilenames(m_platformDragData))
             : (containsHTML(&m_dragDataMap) || containsFilenames(&m_dragDataMap)))
         || containsColor();
 }
 
-PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, Range&, bool, bool&) const
-{     
-    /*
-     * Order is richest format first. On OSX this is:
-     * * Web Archive
-     * * Filenames
-     * * HTML
-     * * RTF
-     * * TIFF
-     * * PICT
-     */
-     
-    if (m_platformDragData) {
-        if (containsFilenames(m_platformDragData)) {
-            if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(frame->document(), m_platformDragData))
-                return fragment;
-        }
-
-        if (containsHTML(m_platformDragData)) {
-            if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(frame->document(), m_platformDragData))
-                return fragment;
-        }
-    } else {
-        if (containsFilenames(&m_dragDataMap)) {
-            if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(frame->document(), &m_dragDataMap))
-                return fragment;
-        }
-
-        if (containsHTML(&m_dragDataMap)) {
-            if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(frame->document(), &m_dragDataMap))
-                return fragment;
-        }
-    }
-    return 0;
-}
-
 Color DragData::asColor() const
 {
     return Color();
index 1b591f6..403fde1 100644 (file)
@@ -1,3 +1,14 @@
+2014-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        DragData should not depend on Clipboard, DocumentFragment, and Document
+        https://bugs.webkit.org/show_bug.cgi?id=21358
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::performDragControllerAction): Update to API
+        change in DragData::asURL().
+
 2014-09-16  Daniel Bates  <dabates@apple.com>
 
         [iOS] Add iOS SDK name and version suffix to WebKitSystemInterface debug/release product name
index 4fb7140..ec043d9 100644 (file)
@@ -1369,7 +1369,7 @@ void WebPageProxy::performDragControllerAction(DragControllerAction action, Drag
     UNUSED_PARAM(sandboxExtensionHandle);
     UNUSED_PARAM(sandboxExtensionsForUpload);
 
-    String url = dragData.asURL(nullptr);
+    String url = dragData.asURL();
     if (!url.isEmpty())
         m_process->assumeReadAccessToBaseURL(url);
     m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData), m_pageID);