Bug 58206 - [Qt] HTML5 drag and drop not working when getData is used
Summary: [Qt] HTML5 drag and drop not working when getData is used
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords: Qt, QtTriaged
Depends on: 56486
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-10 10:46 PDT by Aparna Nandyal
Modified: 2014-02-03 03:17 PST (History)
7 users (show)

See Also:


Attachments
Patch for review (1.38 KB, patch)
2011-04-10 11:11 PDT, Aparna Nandyal
kling: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Aparna Nandyal 2011-04-10 10:46:52 PDT
Steps to reproduce the problem:

1. Open QtTestBrowser or any other simple app that with QWebView 
2. Load http://ljouanneau.com/lab/html5/demodragdrop.html. This page has HTML5 drag and drop.
3. Perform the operations in the page as illustrated - that is drag boxes. 

Expected result: 
Dragging and dropping of boxes is possible as illustrated in the page

Actual result:
Unable to drag the content

Other information:
https://bugs.webkit.org/show_bug.cgi?id=56486 has been raised for a similar issue but the problem with other websites mentioned in 56486 is different from this bug, hence raising another bug for this as discussed.
Comment 1 Aparna Nandyal 2011-04-10 10:59:50 PDT
Analysis:
It is found that the value returned by getData in the following script in wrong:


function dragOver(ev) {
    var idelt = ev.dataTransfer.getData("Text");
    var id = ev.target.getAttribute('id');
    if( (id =='boxB' || id =='boxA') && (idelt == 'drag' || idelt=='drag2'))
        return false;
    else if( id =='boxC' && idelt == 'drag3')
        return false;
    else
        return true;
}

idelt is always undefined. On the other hand if the same web page (http://ljouanneau.com/lab/html5/demodragdrop.html) is downloaded and saved as html and opened through the QtTestBrowser, it works fine. 

Problem in the code:
String ClipboardQt::getData(const String& type, bool& success) const
{

    if (policy() != ClipboardReadable) {
        success = false;
        return String();
    }

    ....
}

The policy value is set as ClipboardTypesReadable in this case hence empty string is returned. The policy value is set in DragController::tryDHTMLDrag. If the URL is local, then clipboardReadable is set (which is why it works when the same html page is saved locally and then loaded in QtTestBrowser) else clipboardTypesReadable is set. 


Additional information: To get this fix working, patch in https://bugs.webkit.org/show_bug.cgi?id=56486 is a required (which is to get generic HTML5 drag and drop to work)
Comment 2 Aparna Nandyal 2011-04-10 11:11:34 PDT
Created attachment 88954 [details]
Patch for review

getData JavaScript API is an important integral part of HTML5 D&D usage which is always returning an undefined value in this case. Fix rectifies this problem.

Existing test cases cover D&D. DRT does not support D&D yet. Also this case is reproducible for pages online only.
Comment 3 Eric Seidel (no email) 2011-04-10 15:40:34 PDT
Comment on attachment 88954 [details]
Patch for review

How do we test this?
Comment 4 Benjamin Poulain 2011-04-11 04:57:45 PDT
(In reply to comment #3)
> (From update of attachment 88954 [details])
> How do we test this?

That is quite a problem. I looked at testing drag-and-drop last week and we have big issue because of the way Qt handle drag and drop.

Currently, we do not run the layout tests. :(
Comment 5 Eric Seidel (no email) 2011-04-11 06:17:34 PDT
In general things which aren't tested are broken.  So I think it is probably more worth your time to fix the drag and drop testing on Qt... then at least you'll know what's broken there in comparison to other ports. :)
Comment 6 Andreas Kling 2011-04-26 17:17:45 PDT
Comment on attachment 88954 [details]
Patch for review

Just tested this on Safari and Chromium, and the test doesn't work on either of them. We should not be adding different behavior for QtWebKit.
Comment 7 Aparna Nandyal 2011-05-01 23:19:52 PDT
This is broken on all the ports because, we dont allow getData to be called when drag start or drag over is happening. This is for security reason, that getData can be accessed only during drop event and not before that. This so, because when you are dragging data across documents on your desktop, you do not want getData to be called by intermittent document which is not suppose to have access to data. The real solution to this problem would be to check if the dragging is happening within the same document (if within same domain), then getData can be accessed in drag enter and drag over event too. This is the implementation in other browsers like firefox.
Comment 8 Rhema 2011-10-22 17:15:14 PDT
This is a huge problem for me (see http://stackoverflow.com/questions/7830249/how-do-you-get-the-selected-items-from-a-dragstart-event-in-chrome-is-datatrans) this solution makes perfect sense.  For example, a dragstart should have the data being dragged available if the event is registered on that document.
E.G.  Add this to the Chrome Javascript dev console...
window.addEventListener("dragstart", function(event) {
        alert(event.dataTransfer.getData("Text"));
    });

Returns alerts 'undefined' when selected text is dragged. :(

  (In reply to comment #7)
> This is broken on all the ports because, we dont allow getData to be called when drag start or drag over is happening. This is for security reason, that getData can be accessed only during drop event and not before that. This so, because when you are dragging data across documents on your desktop, you do not want getData to be called by intermittent document which is not suppose to have access to data. The real solution to this problem would be to check if the dragging is happening within the same document (if within same domain), then getData can be accessed in drag enter and drag over event too. This is the implementation in other browsers like firefox.
Comment 9 Jocelyn Turcotte 2014-02-03 03:17:30 PST
=== Bulk closing of Qt bugs ===

If you believe that this bug report is still relevant for a non-Qt port of webkit.org, please re-open it and remove [Qt] from the summary.

If you believe that this is still an important QtWebKit bug, please fill a new report at https://bugreports.qt-project.org and add a link to this issue. See http://qt-project.org/wiki/ReportingBugsInQt for additional guidelines.