Changeset 63454 in webkit


Ignore:
Timestamp:
Jul 15, 2010 1:36:40 PM (14 years ago)
Author:
johnnyg@google.com
Message:

2010-07-07 John Gregg <johnnyg@google.com>

Reviewed by Jian Li.

Experimental directory upload feature.
https://bugs.webkit.org/show_bug.cgi?id=40872

This patch adds a new HTML attribute webkitdirectory which applies to
<input type="file"> tags and allows the user to specify a folder
which is recursively enumerated so that all the files in that folder
are added to the file list.

The files chosen in that way have a .webkitRelativePath attribute which contains
the relative path starting from the chosen folder. The relative path is
also appended to each item in the FormData when uploaded.

All the code is behind an ENABLE_DIRECTORY_UPLOAD flag.

Test: fast/forms/input-file-directory-upload.html

  • html/Blob.cpp: (WebCore::Blob::Blob):
  • html/Blob.h:
  • html/File.cpp: (WebCore::File::File): (WebCore::File::Init): (WebCore::File::webkitRelativePath):
  • html/File.h: (WebCore::File::create):
  • html/File.idl:
  • html/HTMLAttributeNames.in: add webkitdirectory attribute
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setFileListFromRenderer): (WebCore::HTMLInputElement::webkitdirectory):
  • html/HTMLInputElement.h:
  • html/HTMLInputElement.idl:
  • platform/BlobItem.cpp: (WebCore::FileBlobItem::create): (WebCore::FileBlobItem::FileBlobItem):
  • platform/BlobItem.h: (WebCore::FileBlobItem::relativePath):
  • platform/FileChooser.h: (WebCore::FileChooser::allowsDirectoryUpload):
  • platform/network/FormData.cpp: (WebCore::FormData::appendKeyValuePairItems):
  • rendering/RenderFileUploadControl.cpp: (WebCore::RenderFileUploadControl::allowsMultipleFiles): (WebCore::RenderFileUploadControl::allowsDirectoryUpload):
  • rendering/RenderFileUploadControl.h:

2010-07-07 John Gregg <johnnyg@google.com>

Reviewed by Jian Li.

Layout test for experimental directory upload feature. Only enabled on chromium since that's where the feature is compiled in.
https://bugs.webkit.org/show_bug.cgi?id=40872

  • fast/forms/input-file-directory-upload-expected.txt: Added.
  • fast/forms/input-file-directory-upload.html: Added.
  • platform/gtk/Skipped:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:
Location:
trunk
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r63452 r63454  
     12010-07-07  John Gregg  <johnnyg@google.com>
     2
     3        Reviewed by Jian Li.
     4
     5        Layout test for experimental directory upload feature.  Only enabled on chromium since that's where the feature is compiled in.
     6        https://bugs.webkit.org/show_bug.cgi?id=40872
     7
     8        * fast/forms/input-file-directory-upload-expected.txt: Added.
     9        * fast/forms/input-file-directory-upload.html: Added.
     10        * platform/gtk/Skipped:
     11        * platform/mac/Skipped:
     12        * platform/qt/Skipped:
     13        * platform/win/Skipped:
     14
    1152010-07-15  Simon Fraser  <simon.fraser@apple.com>
    216
  • trunk/LayoutTests/platform/gtk/Skipped

    r63409 r63454  
    58595859# Missing DRT API.
    58605860http/tests/loading/preload-slow-loading.php
     5861
     5862# Directory upload is not enabled.
     5863fast/forms/input-file-directory-upload.html
  • trunk/LayoutTests/platform/mac/Skipped

    r63445 r63454  
    289289fast/images/large-size-image-crash.html
    290290
     291# Directory upload is not enabled.
     292fast/forms/input-file-directory-upload.html
  • trunk/LayoutTests/platform/qt/Skipped

    r63409 r63454  
    54615461inspector/timeline-parse-html.html
    54625462inspector/timeline-recalculate-styles.html
     5463
     5464# Directory upload is not enabled.
     5465fast/forms/input-file-directory-upload.html
  • trunk/LayoutTests/platform/win/Skipped

    r63409 r63454  
    954954userscripts/user-style-all-frames.html
    955955userscripts/user-style-top-frame-only.html
     956
     957# Directory upload is not enabled.
     958fast/forms/input-file-directory-upload.html
  • trunk/WebCore/ChangeLog

    r63452 r63454  
     12010-07-07  John Gregg  <johnnyg@google.com>
     2
     3        Reviewed by Jian Li.
     4
     5        Experimental directory upload feature.
     6        https://bugs.webkit.org/show_bug.cgi?id=40872
     7
     8        This patch adds a new HTML attribute webkitdirectory which applies to
     9        <input type="file"> tags and allows the user to specify a folder
     10        which is recursively enumerated so that all the files in that folder
     11        are added to the file list.
     12
     13        The files chosen in that way have a .webkitRelativePath attribute which contains
     14        the relative path starting from the chosen folder.  The relative path is
     15        also appended to each item in the FormData when uploaded.
     16
     17        All the code is behind an ENABLE_DIRECTORY_UPLOAD flag.
     18
     19        Test: fast/forms/input-file-directory-upload.html
     20
     21        * html/Blob.cpp:
     22        (WebCore::Blob::Blob):
     23        * html/Blob.h:
     24        * html/File.cpp:
     25        (WebCore::File::File):
     26        (WebCore::File::Init):
     27        (WebCore::File::webkitRelativePath):
     28        * html/File.h:
     29        (WebCore::File::create):
     30        * html/File.idl:
     31        * html/HTMLAttributeNames.in: add webkitdirectory attribute
     32        * html/HTMLInputElement.cpp:
     33        (WebCore::HTMLInputElement::setFileListFromRenderer):
     34        (WebCore::HTMLInputElement::webkitdirectory):
     35        * html/HTMLInputElement.h:
     36        * html/HTMLInputElement.idl:
     37        * platform/BlobItem.cpp:
     38        (WebCore::FileBlobItem::create):
     39        (WebCore::FileBlobItem::FileBlobItem):
     40        * platform/BlobItem.h:
     41        (WebCore::FileBlobItem::relativePath):
     42        * platform/FileChooser.h:
     43        (WebCore::FileChooser::allowsDirectoryUpload):
     44        * platform/network/FormData.cpp:
     45        (WebCore::FormData::appendKeyValuePairItems):
     46        * rendering/RenderFileUploadControl.cpp:
     47        (WebCore::RenderFileUploadControl::allowsMultipleFiles):
     48        (WebCore::RenderFileUploadControl::allowsDirectoryUpload):
     49        * rendering/RenderFileUploadControl.h:
     50
    1512010-07-15  Simon Fraser  <simon.fraser@apple.com>
    252
  • trunk/WebCore/html/Blob.cpp

    r61343 r63454  
    4242    for (size_t i = 0; i < items.size(); ++i)
    4343        m_items.append(items[i]);
     44}
     45
     46Blob::Blob(const PassRefPtr<BlobItem>& item)
     47{
     48    m_items.append(item);
    4449}
    4550
  • trunk/WebCore/html/Blob.h

    r61343 r63454  
    7272protected:
    7373    Blob(const String& type, const BlobItemList&);
     74    Blob(const PassRefPtr<BlobItem>&);
    7475
    7576    // FIXME: Deprecated constructor.  See also the comment for Blob::create(path).
  • trunk/WebCore/html/File.cpp

    r60799 r63454  
    3535    : Blob(path)
    3636{
     37    Init();
     38}
     39
     40#if ENABLE(DIRECTORY_UPLOAD)
     41File::File(const String& relativePath, const String& filePath)
     42    : Blob(FileBlobItem::create(filePath, relativePath))
     43{
     44    Init();
     45}
     46#endif
     47
     48void File::Init()
     49{
    3750    // We don't use MIMETypeRegistry::getMIMETypeForPath() because it returns "application/octet-stream" upon failure.
    3851    const String& fileName = name();
     
    4760}
    4861
     62#if ENABLE(DIRECTORY_UPLOAD)
     63const String& File::webkitRelativePath() const
     64{
     65    return items().at(0)->toFileBlobItem()->relativePath();
     66}
     67#endif
     68
    4969} // namespace WebCore
  • trunk/WebCore/html/File.h

    r60799 r63454  
    4040    }
    4141
     42#if ENABLE(DIRECTORY_UPLOAD)
     43    static PassRefPtr<File> create(const String& relativePath, const String& path)
     44    {
     45        return adoptRef(new File(relativePath, path));
     46    }
     47#endif
     48
    4249    virtual bool isFile() const { return true; }
    4350
    4451    const String& name() const;
     52#if ENABLE(DIRECTORY_UPLOAD)
     53    // Returns the relative path of this file in the context of a directory selection.
     54    const String& webkitRelativePath() const;
     55#endif
    4556
    4657    // FIXME: obsolete attributes. To be removed.
     
    5061private:
    5162    File(const String& path);
     63    void Init();
     64
     65#if ENABLE(DIRECTORY_UPLOAD)
     66    File(const String& relativePath, const String& path);
     67#endif
    5268};
    5369
  • trunk/WebCore/html/File.idl

    r61223 r63454  
    3131    ] File : Blob {
    3232        readonly attribute DOMString name;
     33#if defined(ENABLE_DIRECTORY_UPLOAD) && ENABLE_DIRECTORY_UPLOAD
     34        readonly attribute DOMString webkitRelativePath;
     35#endif
    3336
    3437        // FIXME: obsolete attributes. To be removed.
  • trunk/WebCore/html/HTMLAttributeNames.in

    r61964 r63454  
    282282vlink
    283283vspace
     284webkitdirectory
    284285width
    285286wrap
  • trunk/WebCore/html/HTMLInputElement.cpp

    r62596 r63454  
    4141#include "File.h"
    4242#include "FileList.h"
     43#include "FileSystem.h"
    4344#include "FocusController.h"
    4445#include "FormDataList.h"
     
    19681969    m_fileList->clear();
    19691970    int size = paths.size();
     1971
     1972#if ENABLE(DIRECTORY_UPLOAD)
     1973    // If a directory is being selected, the UI allows a directory to be chosen
     1974    // and the paths provided here share a root directory somewhere up the tree;
     1975    // we want to store only the relative paths from that point.
     1976    if (webkitdirectory() && size > 0) {
     1977        String rootPath = directoryName(paths[0]);
     1978        // Find the common root path.
     1979        for (int i = 1; i < size; i++) {
     1980            while (!paths[i].startsWith(rootPath))
     1981                rootPath = directoryName(rootPath);
     1982        }
     1983        rootPath = directoryName(rootPath);
     1984        ASSERT(rootPath.length());
     1985        for (int i = 0; i < size; i++)
     1986            m_fileList->append(File::create(paths[i].substring(1 + rootPath.length()), paths[i]));
     1987    } else {
     1988        for (int i = 0; i < size; i++)
     1989            m_fileList->append(File::create(paths[i]));
     1990    }
     1991#else
    19701992    for (int i = 0; i < size; i++)
    19711993        m_fileList->append(File::create(paths[i]));
     1994#endif
    19721995
    19731996    setFormControlValueMatchesRenderer(true);
     
    24492472}
    24502473
     2474#if ENABLE(DIRECTORY_UPLOAD)
     2475bool HTMLInputElement::webkitdirectory() const
     2476{
     2477    return !getAttribute(webkitdirectoryAttr).isNull();
     2478}
     2479#endif
     2480
    24512481void HTMLInputElement::setSize(unsigned size)
    24522482{
  • trunk/WebCore/html/HTMLInputElement.h

    r62705 r63454  
    181181    bool multiple() const;
    182182
     183#if ENABLE(DIRECTORY_UPLOAD)
     184    bool webkitdirectory() const;
     185#endif
     186
    183187    virtual bool isAutofilled() const { return m_autofilled; }
    184188    void setAutofilled(bool value = true);
  • trunk/WebCore/html/HTMLInputElement.idl

    r63057 r63454  
    4141        attribute [Reflect] DOMString min;
    4242        attribute [Reflect] boolean multiple;
     43#if defined(ENABLE_DIRECTORY_UPLOAD) && ENABLE_DIRECTORY_UPLOAD
     44        attribute [Reflect] boolean webkitdirectory;
     45#endif
    4346        attribute [Reflect] DOMString name;
    4447        attribute [Reflect] DOMString pattern;
  • trunk/WebCore/platform/BlobItem.cpp

    r63343 r63454  
    7878{
    7979}
     80
     81#if ENABLE(DIRECTORY_UPLOAD)
     82PassRefPtr<BlobItem> FileBlobItem::create(const String& path, const String& relativePath)
     83{
     84    return adoptRef(static_cast<BlobItem*>(new FileBlobItem(path, relativePath)));
     85}
     86
     87FileBlobItem::FileBlobItem(const String& path, const String& relativePath)
     88    : m_path(path)
     89    , m_fileName(pathGetFileName(m_path))
     90    , m_relativePath(relativePath)
     91{
     92}
     93#endif
    8094
    8195unsigned long long FileBlobItem::size() const
  • trunk/WebCore/platform/BlobItem.h

    r63343 r63454  
    9999public:
    100100    static PassRefPtr<BlobItem> create(const String& path);
     101#if ENABLE(DIRECTORY_UPLOAD)
     102    static PassRefPtr<BlobItem> create(const String& path, const String& relativePath);
     103#endif
    101104    virtual const String& name() const { return m_fileName; }
    102105    virtual const String& path() const { return m_path; }
     106#if ENABLE(DIRECTORY_UPLOAD)
     107    const String& relativePath() const { return m_relativePath; }
     108#endif
    103109
    104110    // BlobItem methods.
     
    111117protected:
    112118    FileBlobItem(const String& path);
     119#if ENABLE(DIRECTORY_UPLOAD)
     120    FileBlobItem(const String& path, const String& relativePath);
     121#endif
    113122    String m_path;
    114123    String m_fileName;
     124#if ENABLE(DIRECTORY_UPLOAD)
     125    String m_relativePath;
     126#endif
    115127};
    116128
  • trunk/WebCore/platform/FileChooser.h

    r56824 r63454  
    4545    virtual void repaint() = 0;
    4646    virtual bool allowsMultipleFiles() = 0;
     47#if ENABLE(DIRECTORY_UPLOAD)
     48    virtual bool allowsDirectoryUpload() = 0;
     49#endif
    4750    virtual String acceptTypes() = 0;
    4851    virtual void chooseIconForFiles(FileChooser*, const Vector<String>&) = 0;
     
    7174
    7275    bool allowsMultipleFiles() const { return m_client ? m_client->allowsMultipleFiles() : false; }
     76#if ENABLE(DIRECTORY_UPLOAD)
     77    bool allowsDirectoryUpload() const { return m_client ? m_client->allowsDirectoryUpload() : false; }
     78#endif
    7379    // Acceptable MIME types.  It's an 'accept' attribute value of the corresponding INPUT element.
    7480    String acceptTypes() const { return m_client ? m_client->acceptTypes() : String(); }
  • trunk/WebCore/platform/network/FormData.cpp

    r61618 r63454  
    225225            if (fileItem) {
    226226                const String& path = fileItem->path();
     227
     228#if ENABLE(DIRECTORY_UPLOAD)
     229                String fileName = !fileItem->relativePath().isEmpty() ? fileItem->relativePath() : fileItem->name();
     230#else
    227231                String fileName = fileItem->name();
     232#endif
    228233
    229234                // Let the application specify a filename if it's going to generate a replacement file for the upload.
  • trunk/WebCore/rendering/RenderFileUploadControl.cpp

    r61293 r63454  
    9595bool RenderFileUploadControl::allowsMultipleFiles()
    9696{
     97#if ENABLE(DIRECTORY_UPLOAD)
     98    if (allowsDirectoryUpload())
     99      return true;
     100#endif
     101
    97102    HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
    98103    return !input->getAttribute(multipleAttr).isNull();
    99104}
     105
     106#if ENABLE(DIRECTORY_UPLOAD)
     107bool RenderFileUploadControl::allowsDirectoryUpload()
     108{
     109    HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
     110    return !input->getAttribute(webkitdirectoryAttr).isNull();
     111}
     112#endif
    100113
    101114String RenderFileUploadControl::acceptTypes()
  • trunk/WebCore/rendering/RenderFileUploadControl.h

    r59876 r63454  
    6363    void repaint() { RenderBlock::repaint(); }
    6464    bool allowsMultipleFiles();
     65#if ENABLE(DIRECTORY_UPLOAD)
     66    bool allowsDirectoryUpload();
     67#endif
    6568    String acceptTypes();
    6669    void chooseIconForFiles(FileChooser*, const Vector<String>&);
Note: See TracChangeset for help on using the changeset viewer.