Changeset 69530 in webkit


Ignore:
Timestamp:
Oct 11, 2010 3:12:54 PM (13 years ago)
Author:
Martin Robinson
Message:

2010-10-11 Martin Robinson <mrobinson@igalia.com>

Reviewed by Tony Chang.

[GTK] editing/pasteboard/dataTransfer-setData-getData.html fails on GTK+
https://bugs.webkit.org/show_bug.cgi?id=47244

Unskip the freshly passing test and add a baseline which has a PASS for all
tests.

  • platform/gtk/Skipped: Unskip passing test.
  • platform/gtk/editing/pasteboard/dataTransfer-setData-getData-expected.txt:

2010-10-11 Martin Robinson <mrobinson@igalia.com>

Reviewed by Tony Chang.

[GTK] editing/pasteboard/dataTransfer-setData-getData.html fails on GTK+
https://bugs.webkit.org/show_bug.cgi?id=47244

Store the URI list as a String in DataObjectGtk, so that non-URI elements
are preserved when getData(...) is called. This necessitates some other
changes, including adding a m_filenames member to DataObjectGtk to store
filenames extracted during setURIList(...). The logic in getData(...) has
also changed to set success = true no matter what to match the spec. A
followup patch will remove this parameter completely for all platforms.

  • platform/gtk/ClipboardGtk.cpp: (WebCore::ClipboardGtk::getData): Always succeed to match the HTML5 spec and Firefox. Simply return the uriList string from the DataObject instead of reconstructing it from a vector of KURLs. (WebCore::ClipboardGtk::setData): The DataObject now accepts a string for the uriList parameter. (WebCore::ClipboardGtk::types): Predicate the "Files" member on DataObjectGtk::hasFilenames(). (WebCore::ClipboardGtk::files): Update to reflect the change from DataObjectGtk::files() to DataObjectGtk::filenames().
  • platform/gtk/DataObjectGtk.cpp: (WebCore::DataObjectGtk::setURIList): Expanded this setter to find the first valid URL to use as the m_url member and also extract a list of filenames from the URI list. (WebCore::DataObjectGtk::setURL): Updated to reflect changes to m_uriList. (WebCore::DataObjectGtk::clear): Updated to reflect changes to m_uriList and also leave a comment explaining why we do not clear filenames here.
  • platform/gtk/DataObjectGtk.h: (WebCore::DataObjectGtk::url): This implementation is now a simple getter. (WebCore::DataObjectGtk::uriList): Ditto. (WebCore::DataObjectGtk::filenames): Added. (WebCore::DataObjectGtk::hasURL): Now a simple check. (WebCore::DataObjectGtk::hasFilenames): Added. (WebCore::DataObjectGtk::clearURIList): Simple setter. (WebCore::DataObjectGtk::clearURL): Ditto.
  • platform/gtk/DragDataGtk.cpp: (WebCore::DragData::containsFiles): Updated to access DataObjectGtk::hasFilenames(). (WebCore::DragData::asFilenames): Updated to access DataObjectGtk::filenames().
  • platform/gtk/PasteboardHelper.cpp: (WebCore::PasteboardHelper::getClipboardContents): Use the uriList as a string now. (WebCore::PasteboardHelper::fillSelectionData): Ditto. (WebCore::PasteboardHelper::fillDataObjectFromDropData): Ditto.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r69528 r69530  
     12010-10-11  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Tony Chang.
     4
     5        [GTK] editing/pasteboard/dataTransfer-setData-getData.html fails on GTK+
     6        https://bugs.webkit.org/show_bug.cgi?id=47244
     7
     8        Unskip the freshly passing test and add a baseline which has a PASS for all
     9        tests.
     10
     11        * platform/gtk/Skipped: Unskip passing test.
     12        * platform/gtk/editing/pasteboard/dataTransfer-setData-getData-expected.txt:
     13
    1142010-10-11  Martin Robinson  <mrobinson@igalia.com>
    215
  • trunk/LayoutTests/platform/gtk/editing/pasteboard/dataTransfer-setData-getData-expected.txt

    r64082 r69530  
    66--- Test set/get 'URL':
    77PASS getDataResultType is "string"
    8 PASS getDataLines.length is 1
    9 PASS getDataLines[0].replace(/\/$/, '') is "http://test.com"
     8PASS getDataResult is "http://test.com/"
     9--- Test set/get 'URL' with multiple URLs:
     10PASS getDataResultType is "string"
     11PASS getDataResult is "http://test.com/"
    1012--- Test set/get 'text/uri-list':
    1113PASS getDataResultType is "string"
    12 PASS getDataLines.length is 2
    13 PASS getDataLines[0].replace(/\/$/, '') is "http://test.com"
    14 PASS getDataLines[1].replace(/\/$/, '') is "http://check.com"
     14PASS getDataResult is "http://test.com\r\nhttp://check.com"
     15--- Test set/get 'text/uri-list' using '\n':
     16PASS getDataResultType is "string"
     17PASS getDataResult is "http://test.com\nhttp://check.com"
    1518--- Test set 'text/uri-list', get 'URL':
    1619PASS getDataResultType is "string"
    17 PASS getDataLines.length is 1
    18 PASS getDataLines[0].replace(/\/$/, '') is "http://test.com"
     20PASS getDataResult is "http://test.com/"
     21--- Test set 'URL', get 'text/uri-list':
     22PASS getDataResultType is "string"
     23PASS getDataResult is "http://test.com\r\nhttp://check.com"
    1924--- Test set 'text/uri-list', get 'URL', using only '\n':
    2025PASS getDataResultType is "string"
    21 PASS getDataLines.length is 1
    22 PASS getDataLines[0].replace(/\/$/, '') is "http://test.com"
     26PASS getDataResult is "http://test.com/"
    2327--- Test set/get 'text/uri-list' with comments:
    2428PASS getDataResultType is "string"
    25 PASS getDataLines.length is 2
    26 PASS getDataLines[0].replace(/\/$/, '') is "http://test.com"
    27 PASS getDataLines[1].replace(/\/$/, '') is "http://check.com"
     29PASS getDataResult is "# comment\r\nhttp://test.com\r\nhttp://check.com"
     30--- Test set 'text/uri-list', get 'URL' with comments:
     31PASS getDataResultType is "string"
     32PASS getDataResult is "http://test.com/"
     33--- Test set 'text/uri-list', get 'URL' with only comments:
     34PASS getDataResultType is "string"
     35PASS getDataResult is ""
    2836--- Test set/get 'text/plain':
    2937PASS getDataResultType is "string"
    30 PASS getDataLines.length is 1
    31 PASS getDataLines[0].replace(/\/$/, '') is "Lorem ipsum dolor sit amet."
     38PASS getDataResult is "Lorem ipsum dolor sit amet."
    3239PASS successfullyParsed is true
    3340
  • trunk/WebCore/ChangeLog

    r69529 r69530  
     12010-10-11  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Tony Chang.
     4
     5        [GTK] editing/pasteboard/dataTransfer-setData-getData.html fails on GTK+
     6        https://bugs.webkit.org/show_bug.cgi?id=47244
     7
     8        Store the URI list as a String in DataObjectGtk, so that non-URI elements
     9        are preserved when getData(...) is called. This necessitates some other
     10        changes, including adding a m_filenames member to DataObjectGtk to store
     11        filenames extracted during setURIList(...). The logic in getData(...) has
     12        also changed to set success = true no matter what to match the spec. A
     13        followup patch will remove this parameter completely for all platforms.
     14
     15        * platform/gtk/ClipboardGtk.cpp:
     16        (WebCore::ClipboardGtk::getData): Always succeed to match the HTML5
     17        spec and Firefox. Simply return the uriList string from the DataObject
     18        instead of reconstructing it from a vector of KURLs.
     19        (WebCore::ClipboardGtk::setData): The DataObject now accepts a string
     20        for the uriList parameter.
     21        (WebCore::ClipboardGtk::types): Predicate the "Files" member on
     22        DataObjectGtk::hasFilenames().
     23        (WebCore::ClipboardGtk::files): Update to reflect the change from
     24        DataObjectGtk::files() to DataObjectGtk::filenames().
     25        * platform/gtk/DataObjectGtk.cpp:
     26        (WebCore::DataObjectGtk::setURIList): Expanded this setter to find the
     27        first valid URL to use as the m_url member and also extract a list of filenames
     28        from the URI list.
     29        (WebCore::DataObjectGtk::setURL): Updated to reflect changes to m_uriList.
     30        (WebCore::DataObjectGtk::clear): Updated to reflect changes to m_uriList and
     31        also leave a comment explaining why we do not clear filenames here.
     32        * platform/gtk/DataObjectGtk.h:
     33        (WebCore::DataObjectGtk::url): This implementation is now a simple getter.
     34        (WebCore::DataObjectGtk::uriList): Ditto.
     35        (WebCore::DataObjectGtk::filenames): Added.
     36        (WebCore::DataObjectGtk::hasURL): Now a simple check.
     37        (WebCore::DataObjectGtk::hasFilenames): Added.
     38        (WebCore::DataObjectGtk::clearURIList): Simple setter.
     39        (WebCore::DataObjectGtk::clearURL): Ditto.
     40        * platform/gtk/DragDataGtk.cpp:
     41        (WebCore::DragData::containsFiles): Updated to access DataObjectGtk::hasFilenames().
     42        (WebCore::DragData::asFilenames): Updated to access DataObjectGtk::filenames().
     43        * platform/gtk/PasteboardHelper.cpp:
     44        (WebCore::PasteboardHelper::getClipboardContents): Use the uriList as a string now.
     45        (WebCore::PasteboardHelper::fillSelectionData):  Ditto.
     46        (WebCore::PasteboardHelper::fillDataObjectFromDropData): Ditto.
     47
    1482010-10-11  James Robinson  <jamesr@chromium.org>
    249
  • trunk/WebCore/platform/gtk/ClipboardGtk.cpp

    r67973 r69530  
    140140}
    141141
    142 static String joinURIList(Vector<KURL> uriList)
    143 {
    144     if (uriList.isEmpty())
    145         return String();
    146 
    147     String joined(uriList[0].string());
    148     for (size_t i = 1; i < uriList.size(); i++) {
    149         joined.append("\r\n");
    150         joined.append(uriList[i].string());
    151     }
    152 
    153     return joined;
    154 }
    155 
    156142String ClipboardGtk::getData(const String& typeString, bool& success) const
    157143{
    158     success = false; // Pessimism.
     144    success = true; // According to http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html
     145    // "The getData(format) method must return the data that is associated with the type format converted
     146    // to ASCII lowercase, if any, and must return the empty string otherwise." Since success == false
     147    // results in an 'undefined' return value, we always want to return success == true. This parameter
     148    // should eventually be removed.
    159149    if (policy() != ClipboardReadable || !m_dataObject)
    160150        return String();
     
    164154
    165155    ClipboardDataType type = dataObjectTypeFromHTMLClipboardType(typeString);
    166     if (type == ClipboardDataTypeURIList) {
    167         if (!m_dataObject->hasURIList())
    168             return String();
    169         success = true;
    170         return joinURIList(m_dataObject->uriList());
    171     }
    172 
    173     if (type == ClipboardDataTypeURL) {
    174         if (!m_dataObject->hasURL())
    175             return String();
    176         success = true;
     156    if (type == ClipboardDataTypeURIList)
     157        return m_dataObject->uriList();
     158    if (type == ClipboardDataTypeURL)
    177159        return m_dataObject->url();
    178     }
    179 
    180     if (type == ClipboardDataTypeMarkup) {
    181         if (!m_dataObject->hasMarkup())
    182             return String();
    183         success = true;
     160    if (type == ClipboardDataTypeMarkup)
    184161        return m_dataObject->markup();
    185     }
    186 
    187     if (type == ClipboardDataTypeText) {
    188         if (!m_dataObject->hasText())
    189                 return String();
    190         success = true;
     162    if (type == ClipboardDataTypeText)
    191163        return m_dataObject->text();
    192     }
    193164
    194165    return String();
     
    203174    ClipboardDataType type = dataObjectTypeFromHTMLClipboardType(typeString);
    204175    if (type == ClipboardDataTypeURIList || type == ClipboardDataTypeURL) {
    205         Vector<KURL> uriList;
    206         gchar** uris = g_uri_list_extract_uris(data.utf8().data());
    207         if (uris) {
    208             gchar** currentURI = uris;
    209             while (*currentURI) {
    210                 uriList.append(KURL(KURL(), *currentURI));
    211                 currentURI++;
    212             }
    213             g_strfreev(uris);
    214             m_dataObject->setURIList(uriList);
    215             success = true;
    216         }
     176        m_dataObject->setURIList(data);
     177        success = true;
    217178    } else if (type == ClipboardDataTypeMarkup) {
    218179        m_dataObject->setMarkup(data);
     
    249210        types.add("text/uri-list");
    250211        types.add("URL");
     212    }
     213
     214    if (m_dataObject->hasFilenames())
    251215        types.add("Files");
    252     }
    253216
    254217    return types;
     
    264227
    265228    RefPtr<FileList> fileList = FileList::create();
    266     Vector<String> fileVector(m_dataObject->files());
    267 
    268     for (size_t i = 0; i < fileVector.size(); i++)
    269         fileList->append(File::create(fileVector[i]));
    270 
     229    const Vector<String>& filenames = m_dataObject->filenames();
     230    for (size_t i = 0; i < filenames.size(); i++)
     231        fileList->append(File::create(filenames[i]));
    271232    return fileList.release();
    272233}
  • trunk/WebCore/platform/gtk/DataObjectGtk.cpp

    r61281 r69530  
    6060}
    6161
     62void DataObjectGtk::setURIList(const String& uriListString)
     63{
     64    m_uriList = uriListString;
     65
     66    // This code is originally from: platform/chromium/ChromiumDataObject.cpp.
     67    // FIXME: We should make this code cross-platform eventually.
     68
     69    // Line separator is \r\n per RFC 2483 - however, for compatibility
     70    // reasons we also allow just \n here.
     71    Vector<String> uriList;
     72    uriListString.split('\n', uriList);
     73
     74    // Process the input and copy the first valid URL into the url member.
     75    // In case no URLs can be found, subsequent calls to getData("URL")
     76    // will get an empty string. This is in line with the HTML5 spec (see
     77    // "The DragEvent and DataTransfer interfaces"). Also extract all filenames
     78    // from the URI list.
     79    bool setURL = false;
     80    for (size_t i = 0; i < uriList.size(); ++i) {
     81        String& line = uriList[i];
     82        line = line.stripWhiteSpace();
     83        if (line.isEmpty())
     84            continue;
     85        if (line[0] == '#')
     86            continue;
     87
     88        KURL url = KURL(KURL(), line);
     89        if (url.isValid()) {
     90            if (!setURL) {
     91                m_url = url;
     92                setURL = true;
     93            }
     94
     95            GOwnPtr<GError> error;
     96            GOwnPtr<gchar> filename(g_filename_from_uri(line.utf8().data(), 0, &error.outPtr()));
     97            if (!error && filename)
     98                m_filenames.append(String::fromUTF8(filename.get()));
     99        }
     100    }
     101}
     102
    62103void DataObjectGtk::setURL(const KURL& url, const String& label)
    63104{
     105    m_url = url;
     106    m_uriList = url;
    64107    setText(url.string());
    65108
     
    76119    append(markup, "</a>");
    77120    setMarkup(String::adopt(markup));
    78 
    79     Vector<KURL> uriList;
    80     uriList.append(url);
    81     setURIList(uriList);
    82121}
    83122
     
    94133}
    95134
    96 Vector<String> DataObjectGtk::files()
    97 {
    98     Vector<KURL> uris(uriList());
    99     Vector<String> files;
    100 
    101     for (size_t i = 0; i < uris.size(); i++) {
    102         KURL& uri = uris[0];
    103         if (!uri.isValid() || !uri.isLocalFile())
    104             continue;
    105 
    106         files.append(uri.string());
    107     }
    108 
    109     return files;
    110 }
    111 
    112 String DataObjectGtk::url()
    113 {
    114     Vector<KURL> uris(uriList());
    115     for (size_t i = 0; i < uris.size(); i++) {
    116         KURL& uri = uris[0];
    117         if (uri.isValid())
    118             return uri;
    119     }
    120 
    121     return String();
    122 }
    123 
    124135String DataObjectGtk::urlLabel()
    125136{
     
    133144}
    134145
    135 bool DataObjectGtk::hasURL()
    136 {
    137     return !url().isEmpty();
    138 }
    139 
    140146void DataObjectGtk::clear()
    141147{
    142148    m_text = "";
    143149    m_markup = "";
    144     m_uriList.clear();
     150    m_uriList = "";
     151    m_url = KURL();
    145152    m_image = 0;
    146153    m_range = 0;
     154
     155    // We do not clear filenames. According to the spec: "The clearData() method
     156    // does not affect whether any files were included in the drag, so the types
     157    // attribute's list might still not be empty after calling clearData() (it would
     158    // still contain the "Files" string if any files were included in the drag)."
    147159}
    148160
  • trunk/WebCore/platform/gtk/DataObjectGtk.h

    r66531 r69530  
    3737    }
    3838
    39     Vector<KURL> uriList() { return m_uriList; }
     39    const KURL& url() { return m_url; }
     40    const String& uriList() { return m_uriList; }
     41    const Vector<String>& filenames() { return m_filenames; }
    4042    GdkPixbuf* image() { return m_image.get(); }
    4143    void setRange(PassRefPtr<Range> newRange) { m_range = newRange; }
    42     void setURIList(const Vector<KURL>& newURIList) {  m_uriList = newURIList; }
    4344    void setImage(GdkPixbuf* newImage) { m_image = newImage; }
    4445    void setDragContext(GdkDragContext* newDragContext) { m_dragContext = newDragContext; }
     
    4748    bool hasMarkup() { return m_range || !m_markup.isEmpty(); }
    4849    bool hasURIList() { return !m_uriList.isEmpty(); }
     50    bool hasURL() { return !m_url.isEmpty() && m_url.isValid(); }
     51    bool hasFilenames() { return !m_filenames.isEmpty(); }
    4952    bool hasImage() { return m_image; }
    50     void clearURIList() { m_uriList.clear(); }
     53    void clearURIList() { m_uriList = ""; }
     54    void clearURL() { m_url = KURL(); }
    5155    void clearImage() { m_image = 0; }
    5256    GdkDragContext* dragContext() { return m_dragContext.get(); }
     
    5458    String text();
    5559    String markup();
    56     Vector<String> files();
    57     void setText(const String& newText);
    58     void setMarkup(const String& newMarkup);
    59     bool hasURL();
    60     String url();
     60    void setText(const String&);
     61    void setMarkup(const String&);
     62    void setURIList(const String&);
    6163    String urlLabel();
    6264    void clear();
     
    6971    String m_text;
    7072    String m_markup;
    71     Vector<KURL> m_uriList;
     73    KURL m_url;
     74    String m_uriList;
     75    Vector<String> m_filenames;
    7276    PlatformRefPtr<GdkPixbuf> m_image;
    7377    PlatformRefPtr<GdkDragContext> m_dragContext;
  • trunk/WebCore/platform/gtk/DragDataGtk.cpp

    r64152 r69530  
    3838bool DragData::containsFiles() const
    3939{
    40     return !m_platformDragData->files().isEmpty();
     40    return m_platformDragData->hasFilenames();
    4141}
    4242
    4343void DragData::asFilenames(Vector<String>& result) const
    4444{
    45     Vector<String> files(m_platformDragData->files());
    46     for (size_t i = 0; i < files.size(); i++)
    47         result.append(files[i]);
     45    result = m_platformDragData->filenames();
    4846}
    4947
  • trunk/WebCore/platform/gtk/PasteboardHelper.cpp

    r66024 r69530  
    9393}
    9494
    95 static Vector<KURL> urisToKURLVector(gchar** uris)
    96 {
    97     ASSERT(uris);
    98 
    99     Vector<KURL> uriList;
    100     for (int i = 0; *(uris + i); i++)
    101         uriList.append(KURL(KURL(), *(uris + i)));
    102 
    103     return uriList;
    104 }
    105 
    10695static String selectionDataToUTF8String(GtkSelectionData* data)
    10796{
     
    131120    if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) {
    132121        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) {
    133             gchar** uris = gtk_selection_data_get_uris(data);
    134             if (uris) {
    135                 dataObject->setURIList(urisToKURLVector(uris));
    136                 g_strfreev(uris);
    137             }
     122            dataObject->setURIList(selectionDataToUTF8String(data));
    138123            gtk_selection_data_free(data);
    139124        }
     
    152137
    153138    } else if (info == getIdForTargetType(TargetTypeURIList)) {
    154         Vector<KURL> uriList(dataObject->uriList());
    155         gchar** uris = g_new0(gchar*, uriList.size() + 1);
    156         for (size_t i = 0; i < uriList.size(); i++)
    157             uris[i] = g_strdup(uriList[i].string().utf8().data());
    158 
    159         gtk_selection_data_set_uris(selectionData, uris);
    160         g_strfreev(uris);
     139        CString uriList = dataObject->uriList().utf8();
     140        gtk_selection_data_set(selectionData, uriListAtom, 8,
     141            reinterpret_cast<const guchar*>(uriList.data()), uriList.length() + 1);
    161142
    162143    } else if (info == getIdForTargetType(TargetTypeNetscapeURL) && dataObject->hasURL()) {
     
    210191        dataObject->setMarkup(selectionDataToUTF8String(data));
    211192    else if (target == uriListAtom) {
    212         gchar** uris = gtk_selection_data_get_uris(data);
    213         if (!uris)
    214             return;
    215 
    216         Vector<KURL> uriList(urisToKURLVector(uris));
    217         dataObject->setURIList(uriList);
    218         g_strfreev(uris);
     193        dataObject->setURIList(selectionDataToUTF8String(data));
    219194    } else if (target == netscapeURLAtom) {
    220195        String urlWithLabel(selectionDataToUTF8String(data));
    221 
    222196        Vector<String> pieces;
    223197        urlWithLabel.split("\n", pieces);
     
    225199        // Give preference to text/uri-list here, as it can hold more
    226200        // than one URI but still take  the label if there is one.
    227         if (!dataObject->hasURL()) {
    228             Vector<KURL> uriList;
    229             uriList.append(KURL(KURL(), pieces[0]));
    230             dataObject->setURIList(uriList);
    231         }
    232 
     201        if (!dataObject->hasURIList())
     202            dataObject->setURIList(pieces[0]);
    233203        if (pieces.size() > 1)
    234204            dataObject->setText(pieces[1]);
Note: See TracChangeset for help on using the changeset viewer.