Expose DataTransferItem.getAsEntry() to allow users access dropped files as FileEntry
authorkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Apr 2012 07:29:28 +0000 (07:29 +0000)
committerkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Apr 2012 07:29:28 +0000 (07:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82592

Reviewed by David Levin.

Source/WebCore:

For now the method is prefixed thus it is to be exposed as 'webkitGetAsEntry'.

The API is proposed and discussed in the following whatwg thread:
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-November/033814.html

Add DataTransferItemFilesystem under Modules/filesystem and implemented the bridging part for chromium.

Test: editing/pasteboard/data-transfer-items-drag-drop-entry.html

* Modules/filesystem/DataTransferItemFileSystem.h: Added.
(DataTransferItemFileSystem):
* Modules/filesystem/DataTransferItemFileSystem.idl: Added for DataTransferItem.getAsEntry which is only exposed if filesystem is enabled.
* Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp: Added for chromium implementation.
* Modules/filesystem/chromium/DataTransferItemFileSystemChromium.h: Added.
* Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp: Added.
* Modules/filesystem/chromium/DraggedIsolatedFileSystem.h: Added.
* WebCore.gypi:
* platform/chromium/ChromiumDataObject.cpp:
* platform/chromium/ChromiumDataObject.h:
(WebCore::ChromiumDataObject::filesystemId): Added.
(WebCore::ChromiumDataObject::setFilesystemId): Added.
* platform/chromium/ClipboardChromium.cpp:

Source/WebKit/chromium:

* src/WebDragData.cpp:
(WebKit::WebDragData::filesystemId): Added implementation.
(WebKit::WebDragData::setFilesystemId): Added implementation.

Tools:

Added filesystem hook support in EventSender.beginDragWithFiles() for DumpRenderTree.

* DumpRenderTree/chromium/EventSender.cpp:
(EventSender::beginDragWithFiles):

LayoutTests:

* editing/pasteboard/data-transfer-items-drag-drop-entry-expected.txt: Added.
* editing/pasteboard/data-transfer-items-drag-drop-entry.html: Added.
* editing/pasteboard/resources/test_directory/test.txt: Added.
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:

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

24 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/resources/test_directory/test.txt [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
Source/WebCore/ChangeLog
Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.h [new file with mode: 0644]
Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.idl [new file with mode: 0644]
Source/WebCore/Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp [new file with mode: 0644]
Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp [new file with mode: 0644]
Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.h [new file with mode: 0644]
Source/WebCore/WebCore.gyp/WebCore.gyp
Source/WebCore/WebCore.gypi
Source/WebCore/platform/chromium/ChromiumDataObject.cpp
Source/WebCore/platform/chromium/ChromiumDataObject.h
Source/WebCore/platform/chromium/ClipboardChromium.cpp
Source/WebCore/platform/chromium/ClipboardChromium.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDragData.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/EventSender.cpp

index 7014c66..ac19091 100644 (file)
@@ -1,3 +1,18 @@
+2012-04-05  Kinuko Yasuda  <kinuko@chromium.org>
+
+        Expose DataTransferItem.getAsEntry() to allow users access dropped files as FileEntry
+        https://bugs.webkit.org/show_bug.cgi?id=82592
+
+        Reviewed by David Levin.
+
+        * editing/pasteboard/data-transfer-items-drag-drop-entry-expected.txt: Added.
+        * editing/pasteboard/data-transfer-items-drag-drop-entry.html: Added.
+        * editing/pasteboard/resources/test_directory/test.txt: Added.
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+
 2012-04-05  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, GTK rebaseline after r113279.
diff --git a/LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry-expected.txt b/LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry-expected.txt
new file mode 100644 (file)
index 0000000..6227512
--- /dev/null
@@ -0,0 +1,28 @@
+This tests the basic functionality and properties of DataTransferItems for files with drag and drop. This test requires DRT.
+Drop files here if you test this manually
+Dragging file: resources/mozilla.gif
+Dragging file: resources/drop-file-svg.svg
+Dragging file: resources/copy-backslash-euc.html
+Dragging file: resources/test_directory
+Verifying contents of DataTransferItems...
+PASS: "4" == "4"
+PASS: "file" == "file"
+PASS: "file" == "file"
+PASS: "file" == "file"
+PASS: "file" == "file"
+entry: /mozilla.gif [file]
+PASS: "/mozilla.gif" == "/mozilla.gif"
+PASS: "false" == "false"
+entry: /drop-file-svg.svg [file]
+PASS: "/drop-file-svg.svg" == "/drop-file-svg.svg"
+PASS: "false" == "false"
+entry: /copy-backslash-euc.html [file]
+PASS: "/copy-backslash-euc.html" == "/copy-backslash-euc.html"
+PASS: "false" == "false"
+entry: /test_directory [dir]
+PASS: "/test_directory" == "/test_directory"
+PASS: "true" == "true"
+PASS: "2593" == "2593"
+PASS: "109" == "109"
+PASS: "478" == "478"
+
diff --git a/LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry.html b/LayoutTests/editing/pasteboard/data-transfer-items-drag-drop-entry.html
new file mode 100644 (file)
index 0000000..cbf62e6
--- /dev/null
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div>This tests the basic functionality and properties of DataTransferItems for files with drag and drop. This test requires DRT.</div>
+
+<div id="destination" style="min-height:100px; border: solid 1px black">Drop files here if you test this manually</div>
+
+<div id="console"></div>
+
+<script>
+var testFiles = [
+  { path: 'resources/mozilla.gif',
+    directory: false,
+    size: 2593 },
+  { path: 'resources/drop-file-svg.svg',
+    directory: false,
+    size: 109 },
+  { path: 'resources/copy-backslash-euc.html',
+    directory: false,
+    size: 478 },
+  { path: 'resources/test_directory',
+    directory: true,
+    size: 0 }
+];
+
+function log(text)
+{
+    var console = document.getElementById('console');
+    console.appendChild(document.createTextNode(text));
+    console.appendChild(document.createElement('br'));
+}
+
+function test(expect, actual)
+{
+    log((expect == actual ? 'PASS' : 'FAIL') + ': "' + expect + '" == "' + actual + '"');
+}
+
+function startTest()
+{
+    var destination = document.getElementById('destination');
+    destination.addEventListener('dragover', handleDragOver, false);
+    destination.addEventListener('drop', handleDrop, false);
+
+    if (!window.layoutTestController)
+        return;
+    layoutTestController.waitUntilDone();
+    layoutTestController.dumpAsText();
+
+    var files = [];
+    for (var i = 0; i < testFiles.length; ++i) {
+      log('Dragging file: ' + testFiles[i].path);
+      files.push(testFiles[i].path);
+    }
+
+    // Perform drag-and-drop with the testFiles.
+    eventSender.beginDragWithFiles(files);
+    eventSender.leapForward(100);
+    eventSender.mouseMoveTo(destination.offsetLeft + 10, destination.offsetTop + destination.offsetHeight / 2);
+    eventSender.mouseUp();
+}
+
+function handleDragOver(e)
+{
+    e.stopPropagation();
+    e.preventDefault();
+}
+
+function handleDrop(e)
+{
+    e.stopPropagation();
+    e.preventDefault();
+
+    log('Verifying contents of DataTransferItems...');
+    var items = e.dataTransfer.items;
+    var files = [];
+    test(testFiles.length, items.length);
+    for (var i = 0; i < items.length; ++i) {
+        // The items should be in the same order as we added.
+        var expected = testFiles[i];
+        var file = items[i].getAsFile();
+        files.push(file);
+
+        test('file', items[i].kind);
+        with ({last: i + 1 == items.length, expected: expected}) {
+            items[i].webkitGetAsEntry(function(entry) {
+                log('entry: ' + entry.fullPath + (entry.isDirectory ? ' [dir]' : ' [file]'));
+                var components = expected.path.split('/');
+                var name = components[components.length - 1];
+                test('/' + name, entry.fullPath);
+                test(expected.directory, entry.isDirectory);
+
+                entry.getMetadata(function(metadata) {
+                    if (!expected.directory)
+                        test(expected.size, metadata.size);
+                    if (last && window.layoutTestController)
+                        layoutTestController.notifyDone();
+                });
+            });
+        }
+    }
+}
+
+startTest();
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/pasteboard/resources/test_directory/test.txt b/LayoutTests/editing/pasteboard/resources/test_directory/test.txt
new file mode 100644 (file)
index 0000000..15cdaf1
--- /dev/null
@@ -0,0 +1 @@
+Lorem ipsum.
index fd9f395..44d9d7f 100644 (file)
@@ -321,6 +321,7 @@ media/media-captions.html
 editing/pasteboard/data-transfer-items.html
 editing/pasteboard/data-transfer-items-image-png.html
 editing/pasteboard/data-transfer-items-drag-drop-file.html
+editing/pasteboard/data-transfer-items-drag-drop-entry.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
index eb93b0d..927bf29 100644 (file)
@@ -359,6 +359,7 @@ compositing/webgl/webgl-nonpremultiplied-blend.html
 editing/pasteboard/data-transfer-items.html
 editing/pasteboard/data-transfer-items-image-png.html
 editing/pasteboard/data-transfer-items-drag-drop-file.html
+editing/pasteboard/data-transfer-items-drag-drop-entry.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
index dfcd117..7be7e5e 100644 (file)
@@ -473,6 +473,7 @@ editing/pasteboard/drag-and-drop-objectimage-contenteditable.html
 # See bug https://bugs.webkit.org/show_bug.cgi?id=60068
 editing/pasteboard/data-transfer-items.html
 editing/pasteboard/data-transfer-items-drag-drop-file.html
+editing/pasteboard/data-transfer-items-drag-drop-entry.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
index 773682a..2e5fcad 100644 (file)
@@ -1344,6 +1344,7 @@ editing/pasteboard/onpaste-text-html-types.html
 editing/pasteboard/data-transfer-items.html
 editing/pasteboard/data-transfer-items-image-png.html
 editing/pasteboard/data-transfer-items-drag-drop-file.html
+editing/pasteboard/data-transfer-items-drag-drop-entry.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
index 950aae1..4c8ec9c 100644 (file)
@@ -1,3 +1,33 @@
+2012-04-05  Kinuko Yasuda  <kinuko@chromium.org>
+
+        Expose DataTransferItem.getAsEntry() to allow users access dropped files as FileEntry
+        https://bugs.webkit.org/show_bug.cgi?id=82592
+
+        Reviewed by David Levin.
+
+        For now the method is prefixed thus it is to be exposed as 'webkitGetAsEntry'.
+
+        The API is proposed and discussed in the following whatwg thread:
+        http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-November/033814.html
+
+        Add DataTransferItemFilesystem under Modules/filesystem and implemented the bridging part for chromium.
+
+        Test: editing/pasteboard/data-transfer-items-drag-drop-entry.html
+
+        * Modules/filesystem/DataTransferItemFileSystem.h: Added.
+        (DataTransferItemFileSystem):
+        * Modules/filesystem/DataTransferItemFileSystem.idl: Added for DataTransferItem.getAsEntry which is only exposed if filesystem is enabled.
+        * Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp: Added for chromium implementation.
+        * Modules/filesystem/chromium/DataTransferItemFileSystemChromium.h: Added.
+        * Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp: Added.
+        * Modules/filesystem/chromium/DraggedIsolatedFileSystem.h: Added.
+        * WebCore.gypi:
+        * platform/chromium/ChromiumDataObject.cpp:
+        * platform/chromium/ChromiumDataObject.h:
+        (WebCore::ChromiumDataObject::filesystemId): Added.
+        (WebCore::ChromiumDataObject::setFilesystemId): Added.
+        * platform/chromium/ClipboardChromium.cpp:
+
 2012-04-04  Patrick Gansterer  <paroga@webkit.org>
 
         Add WTF::getCurrentLocalTime()
diff --git a/Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.h b/Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.h
new file mode 100644 (file)
index 0000000..7154301
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#ifndef DataTransferItemFileSystem_h
+#define DataTransferItemFileSystem_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class DataTransferItem;
+class EntryCallback;
+class ScriptExecutionContext;
+
+class DataTransferItemFileSystem {
+public:
+    static void webkitGetAsEntry(DataTransferItem*, ScriptExecutionContext*, PassRefPtr<EntryCallback>);
+
+private:
+    DataTransferItemFileSystem();
+    ~DataTransferItemFileSystem();
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DataTransferItemFileSystem_h
diff --git a/Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.idl b/Source/WebCore/Modules/filesystem/DataTransferItemFileSystem.idl
new file mode 100644 (file)
index 0000000..28f42c4
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+module core {
+
+    interface [
+        Conditional=DATA_TRANSFER_ITEMS&FILE_SYSTEM,
+        Supplemental=DataTransferItem
+    ] DataTransferItemFileSystem {
+        [CallWith=ScriptExecutionContext] void webkitGetAsEntry(in [Callback,Optional=DefaultIsUndefined] EntryCallback callback);
+    };
+
+}
diff --git a/Source/WebCore/Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp b/Source/WebCore/Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp
new file mode 100644 (file)
index 0000000..c75554c
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#include "config.h"
+#include "DataTransferItemFileSystem.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "AsyncFileSystemCallbacks.h"
+#include "ChromiumDataObject.h"
+#include "ClipboardChromium.h"
+#include "DOMFilePath.h"
+#include "DOMFileSystem.h"
+#include "DirectoryEntry.h"
+#include "DraggedIsolatedFileSystem.h"
+#include "Entry.h"
+#include "EntryCallback.h"
+#include "File.h"
+#include "FileEntry.h"
+#include "FileMetadata.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+namespace {
+
+class GetAsEntryCallbacks : public AsyncFileSystemCallbacks {
+    WTF_MAKE_NONCOPYABLE(GetAsEntryCallbacks);
+public:
+    static PassOwnPtr<GetAsEntryCallbacks> create(PassRefPtr<DOMFileSystem> filesystem, const String& virtualPath, PassRefPtr<EntryCallback> callback)
+    {
+        return adoptPtr(new GetAsEntryCallbacks(filesystem, virtualPath, callback));
+    }
+
+    virtual ~GetAsEntryCallbacks()
+    {
+    }
+
+    virtual void didReadMetadata(const FileMetadata& metadata)
+    {
+        if (metadata.type == FileMetadata::TypeDirectory)
+            m_callback->handleEvent(DirectoryEntry::create(m_filesystem, m_virtualPath).get());
+        else
+            m_callback->handleEvent(FileEntry::create(m_filesystem, m_virtualPath).get());
+    }
+
+    virtual void didFail(int error)
+    {
+        // FIXME: Return a special FileEntry which will let any succeeding operations fail with the error code.
+        m_callback->handleEvent(0);
+    }
+
+private:
+    GetAsEntryCallbacks(PassRefPtr<DOMFileSystem> filesystem, const String& virtualPath, PassRefPtr<EntryCallback> callback)
+        : m_filesystem(filesystem)
+        , m_virtualPath(virtualPath)
+        , m_callback(callback)
+    {
+    }
+
+    RefPtr<DOMFileSystem> m_filesystem;
+    String m_virtualPath;
+    RefPtr<EntryCallback> m_callback;
+};
+
+} // namespace
+
+// static
+void DataTransferItemFileSystem::webkitGetAsEntry(DataTransferItem* item, ScriptExecutionContext* scriptExecutionContext, PassRefPtr<EntryCallback> callback)
+{
+    DataTransferItemPolicyWrapper* itemPolicyWrapper = static_cast<DataTransferItemPolicyWrapper*>(item);
+
+    if (!callback || !itemPolicyWrapper->dataObjectItem()->isFilename())
+        return;
+
+    // For dragged files getAsFile must be pretty lightweight.
+    Blob* file = itemPolicyWrapper->getAsFile().get();
+    // The clipboard may not be in a readable state.
+    if (!file)
+        return;
+    ASSERT(file->isFile());
+
+    DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(itemPolicyWrapper->clipboard()->dataObject().get());
+    DOMFileSystem* domFileSystem = filesystem ? filesystem->getDOMFileSystem(scriptExecutionContext) : 0;
+    if (!filesystem) {
+        // IsolatedFileSystem may not be enabled.
+        DOMFileSystem::scheduleCallback(scriptExecutionContext, callback, adoptRef(static_cast<Entry*>(0)));
+        return;
+    }
+
+    ASSERT(domFileSystem);
+
+    // The dropped entries are mapped as top-level entries in the isolated filesystem.
+    String virtualPath = DOMFilePath::append("/", static_cast<File*>(file)->name());
+    domFileSystem->asyncFileSystem()->readMetadata(virtualPath, GetAsEntryCallbacks::create(domFileSystem, virtualPath, callback));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp b/Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp
new file mode 100644 (file)
index 0000000..df5c14c
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#include "config.h"
+#include "DraggedIsolatedFileSystem.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystem.h"
+#include "PlatformSupport.h"
+#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
+#include "Supplementable.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+DraggedIsolatedFileSystem::~DraggedIsolatedFileSystem()
+{
+}
+
+DOMFileSystem* DraggedIsolatedFileSystem::getDOMFileSystem(ScriptExecutionContext* scriptExecutionContext)
+{
+    ASSERT(!m_filesystemId.isEmpty());
+    if (!m_filesystem) {
+        ASSERT(scriptExecutionContext);
+        SecurityOrigin* securityOrigin = scriptExecutionContext->securityOrigin();
+        String filesystemName = PlatformSupport::createIsolatedFileSystemName(securityOrigin->databaseIdentifier(), m_filesystemId);
+        m_filesystem = DOMFileSystem::create(scriptExecutionContext, filesystemName, PlatformSupport::createIsolatedFileSystem(securityOrigin->toString(), m_filesystemId));
+    }
+    return m_filesystem.get();
+}
+
+// static
+const AtomicString& DraggedIsolatedFileSystem::supplementName()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("DraggedIsolatedFileSystem"));
+    return name;
+}
+
+DraggedIsolatedFileSystem::DraggedIsolatedFileSystem(const String& filesystemId)
+    : m_filesystemId(filesystemId)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.h b/Source/WebCore/Modules/filesystem/chromium/DraggedIsolatedFileSystem.h
new file mode 100644 (file)
index 0000000..87896e5
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#ifndef DraggedIsolatedFileSystem_h
+#define DraggedIsolatedFileSystem_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "ChromiumDataObject.h"
+#include <wtf/Forward.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class DOMFileSystem;
+
+class DraggedIsolatedFileSystem : public Supplement<ChromiumDataObject> {
+public:
+    ~DraggedIsolatedFileSystem();
+
+    static PassOwnPtr<DraggedIsolatedFileSystem> create(const String& filesystemId)
+    {
+        return adoptPtr(new DraggedIsolatedFileSystem(filesystemId));
+    }
+
+    const String& filesystemId() const { return m_filesystemId; }
+    DOMFileSystem* getDOMFileSystem(ScriptExecutionContext*);
+
+    static const AtomicString& supplementName();
+    static DraggedIsolatedFileSystem* from(ChromiumDataObject* dataObject) { return static_cast<DraggedIsolatedFileSystem*>(Supplement<ChromiumDataObject>::from(dataObject, supplementName())); }
+
+private:
+    DraggedIsolatedFileSystem(const String& filesystemId);
+    RefPtr<DOMFileSystem> m_filesystem;
+    String m_filesystemId;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DraggedIsolatedFileSystem_h
index c1d9757..f64e71b 100644 (file)
@@ -52,6 +52,7 @@
       '../',
       '../..',
       '../Modules/filesystem',
+      '../Modules/filesystem/chromium',
       '../Modules/gamepad',
       '../Modules/geolocation',
       '../Modules/intents',
index c05a526..d85ffb7 100644 (file)
             'Modules/filesystem/DOMFileSystem.idl',
             'Modules/filesystem/DOMFileSystemSync.idl',
             'Modules/filesystem/DOMWindowFileSystem.idl',
+            'Modules/filesystem/DataTransferItemFileSystem.idl',
             'Modules/filesystem/DirectoryEntry.idl',
             'Modules/filesystem/DirectoryEntrySync.idl',
             'Modules/filesystem/DirectoryReader.idl',
             'Modules/filesystem/DOMFileSystemSync.h',
             'Modules/filesystem/DOMWindowFileSystem.cpp',
             'Modules/filesystem/DOMWindowFileSystem.h',
+            'Modules/filesystem/DataTransferItemFileSystem.h',
             'Modules/filesystem/DirectoryEntry.cpp',
             'Modules/filesystem/DirectoryEntry.h',
             'Modules/filesystem/DirectoryEntrySync.cpp',
             'Modules/filesystem/WebKitFlags.h',
             'Modules/filesystem/WorkerContextFileSystem.cpp',
             'Modules/filesystem/WorkerContextFileSystem.h',
+            'Modules/filesystem/chromium/DataTransferItemFileSystemChromium.cpp',
+            'Modules/filesystem/chromium/DraggedIsolatedFileSystem.cpp',
+            'Modules/filesystem/chromium/DraggedIsolatedFileSystem.h',
             'Modules/gamepad/Gamepad.cpp',
             'Modules/gamepad/Gamepad.h',
             'Modules/gamepad/GamepadList.cpp',
index 0a1f8b6..9f44986 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
+ * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
index 4419828..f36bb0a 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "ChromiumDataObjectItem.h"
 #include "PlatformString.h"
+#include "Supplementable.h"
 #include <wtf/HashSet.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
@@ -48,7 +49,7 @@ typedef int ExceptionCode;
 // A data object for holding data that would be in a clipboard or moved
 // during a drag-n-drop operation.  This is the data that WebCore is aware
 // of and is not specific to a platform.
-class ChromiumDataObject : public RefCounted<ChromiumDataObject> {
+class ChromiumDataObject : public RefCounted<ChromiumDataObject>, public Supplementable<ChromiumDataObject> {
 public:
     static PassRefPtr<ChromiumDataObject> createFromPasteboard();
     static PassRefPtr<ChromiumDataObject> create();
index 1821c88..25e89c3 100644 (file)
@@ -32,7 +32,6 @@
 #include "ChromiumDataObjectItem.h"
 #include "ClipboardMimeTypes.h"
 #include "ClipboardUtilitiesChromium.h"
-#include "DataTransferItem.h"
 #include "DataTransferItemList.h"
 #include "Document.h"
 #include "DragData.h"
@@ -58,19 +57,18 @@ namespace WebCore {
 
 namespace {
 
-// These wrapper classes invalidate a DataTransferItem/DataTransferItemList when the associated
-// Clipboard object goes out of scope.
+// A wrapper class that invalidates a DataTransferItemList when the associated Clipboard object goes out of scope.
 class DataTransferItemListPolicyWrapper : public DataTransferItemList {
 public:
-    static PassRefPtr<DataTransferItemListPolicyWrapper> create(
-        PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObject>);
+    static PassRefPtr<DataTransferItemListPolicyWrapper> create(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObject>);
+    virtual ~DataTransferItemListPolicyWrapper();
 
     virtual size_t length() const;
-    virtual PassRefPtr<DataTransferItem> item(unsigned long index);
-    virtual void deleteItem(unsigned long index, ExceptionCode&);
-    virtual void clear();
-    virtual void add(const String& data, const String& type, ExceptionCode&);
-    virtual void add(PassRefPtr<File>);
+    virtual PassRefPtr<DataTransferItem> item(unsigned long index) OVERRIDE;
+    virtual void deleteItem(unsigned long index, ExceptionCode&) OVERRIDE;
+    virtual void clear() OVERRIDE;
+    virtual void add(const String& data, const String& type, ExceptionCode&) OVERRIDE;
+    virtual void add(PassRefPtr<File>) OVERRIDE;
 
 private:
     DataTransferItemListPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObject>);
@@ -79,23 +77,6 @@ private:
     RefPtr<ChromiumDataObject> m_dataObject;
 };
 
-class DataTransferItemPolicyWrapper : public DataTransferItem {
-public:
-    static PassRefPtr<DataTransferItemPolicyWrapper> create(
-        PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
-
-    virtual String kind() const;
-    virtual String type() const;
-
-    virtual void getAsString(PassRefPtr<StringCallback>) const;
-    virtual PassRefPtr<Blob> getAsFile() const;
-
-private:
-    DataTransferItemPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
-
-    RefPtr<ClipboardChromium> m_clipboard;
-    RefPtr<ChromiumDataObjectItem> m_item;
-};
 
 PassRefPtr<DataTransferItemListPolicyWrapper> DataTransferItemListPolicyWrapper::create(
     PassRefPtr<ClipboardChromium> clipboard, PassRefPtr<ChromiumDataObject> list)
@@ -103,6 +84,10 @@ PassRefPtr<DataTransferItemListPolicyWrapper> DataTransferItemListPolicyWrapper:
     return adoptRef(new DataTransferItemListPolicyWrapper(clipboard, list));
 }
 
+DataTransferItemListPolicyWrapper::~DataTransferItemListPolicyWrapper()
+{
+}
+
 size_t DataTransferItemListPolicyWrapper::length() const
 {
     if (m_clipboard->policy() == ClipboardNumb)
@@ -117,6 +102,7 @@ PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::item(unsigned lo
     RefPtr<ChromiumDataObjectItem> item = m_dataObject->item(index);
     if (!item)
         return 0;
+
     return DataTransferItemPolicyWrapper::create(m_clipboard, item);
 }
 
@@ -157,12 +143,18 @@ DataTransferItemListPolicyWrapper::DataTransferItemListPolicyWrapper(
 {
 }
 
+} // namespace
+
 PassRefPtr<DataTransferItemPolicyWrapper> DataTransferItemPolicyWrapper::create(
     PassRefPtr<ClipboardChromium> clipboard, PassRefPtr<ChromiumDataObjectItem> item)
 {
     return adoptRef(new DataTransferItemPolicyWrapper(clipboard, item));
 }
 
+DataTransferItemPolicyWrapper::~DataTransferItemPolicyWrapper()
+{
+}
+
 String DataTransferItemPolicyWrapper::kind() const
 {
     if (m_clipboard->policy() == ClipboardNumb)
@@ -200,8 +192,6 @@ DataTransferItemPolicyWrapper::DataTransferItemPolicyWrapper(
 {
 }
 
-} // namespace
-
 using namespace HTMLNames;
 
 // We provide the IE clipboard types (URL and Text), and the clipboard types specified in the WHATWG Web Applications 1.0 draft
index b1571cb..526cfa8 100644 (file)
 #include "CachedImage.h"
 #include "ChromiumDataObject.h"
 #include "Clipboard.h"
+#include "DataTransferItem.h"
 
 namespace WebCore {
 
     class CachedImage;
+    class ChromiumDataObjectItem;
+    class ClipboardChromium;
     class Frame;
     class IntPoint;
 
+    // A wrapper class that invalidates a DataTransferItem when the associated Clipboard object goes out of scope.
+    class DataTransferItemPolicyWrapper : public DataTransferItem {
+    public:
+        static PassRefPtr<DataTransferItemPolicyWrapper> create(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
+        virtual ~DataTransferItemPolicyWrapper();
+
+        virtual String kind() const OVERRIDE;
+        virtual String type() const OVERRIDE;
+        virtual void getAsString(PassRefPtr<StringCallback>) const OVERRIDE;
+        virtual PassRefPtr<Blob> getAsFile() const OVERRIDE;
+
+        ClipboardChromium* clipboard() { return m_clipboard.get(); }
+        ChromiumDataObjectItem* dataObjectItem() { return m_item.get(); }
+
+    private:
+        DataTransferItemPolicyWrapper(PassRefPtr<ClipboardChromium>, PassRefPtr<ChromiumDataObjectItem>);
+
+        RefPtr<ClipboardChromium> m_clipboard;
+        RefPtr<ChromiumDataObjectItem> m_item;
+    };
+
     class ClipboardChromium : public Clipboard, public CachedImageClient {
         WTF_MAKE_FAST_ALLOCATED;
     public:
index e8ffbf6..e7694db 100644 (file)
@@ -1,3 +1,14 @@
+2012-04-05  Kinuko Yasuda  <kinuko@chromium.org>
+
+        Expose DataTransferItem.getAsEntry() to allow users access dropped files as FileEntry
+        https://bugs.webkit.org/show_bug.cgi?id=82592
+
+        Reviewed by David Levin.
+
+        * src/WebDragData.cpp:
+        (WebKit::WebDragData::filesystemId): Added implementation.
+        (WebKit::WebDragData::setFilesystemId): Added implementation.
+
 2012-04-04  Kent Tamura  <tkent@chromium.org>
 
         [Chromium] Calendar Picker: Add localization functions
index 4229baa..98cc580 100644 (file)
@@ -34,6 +34,7 @@
 #include "ChromiumDataObject.h"
 #include "ClipboardMimeTypes.h"
 #include "DataTransferItem.h"
+#include "DraggedIsolatedFileSystem.h"
 #include "platform/WebData.h"
 #include "platform/WebString.h"
 #include "platform/WebURL.h"
@@ -130,16 +131,22 @@ void WebDragData::addItem(const Item& item)
 
 WebString WebDragData::filesystemId() const
 {
-    // FIXME: Should return the ID set by setFileSystemId().
+#if ENABLE(FILE_SYSTEM)
+    ASSERT(!isNull());
+    DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(m_private);
+    if (filesystem)
+        return filesystem->filesystemId();
+#endif
     return WebString();
 }
 
 void WebDragData::setFilesystemId(const WebString& filesystemId)
 {
-    // FIXME: The given value should be stored internally and is to be used
-    // to instantiate an isolated filesystem for providing FileSystem Entry
-    // access to the dragged files/directories.
+#if ENABLE(FILE_SYSTEM)
     // The ID is an opaque string, given by and validated by chromium port.
+    ensureMutable();
+    DraggedIsolatedFileSystem::provideTo(m_private, DraggedIsolatedFileSystem::supplementName(), DraggedIsolatedFileSystem::create(filesystemId));
+#endif
 }
 
 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
index 74a1705..5a2b464 100644 (file)
@@ -1,3 +1,15 @@
+2012-04-05  Kinuko Yasuda  <kinuko@chromium.org>
+
+        Expose DataTransferItem.getAsEntry() to allow users access dropped files as FileEntry
+        https://bugs.webkit.org/show_bug.cgi?id=82592
+
+        Reviewed by David Levin.
+
+        Added filesystem hook support in EventSender.beginDragWithFiles() for DumpRenderTree.
+
+        * DumpRenderTree/chromium/EventSender.cpp:
+        (EventSender::beginDragWithFiles):
+
 2012-04-04  Tim Horton  <timothy_horton@apple.com>
 
         [mac] WKTR should always keep its windows offscreen
index 2d92b4e..ad4a08e 100644 (file)
@@ -880,12 +880,15 @@ void EventSender::beginDragWithFiles(const CppArgumentList& arguments, CppVarian
 {
     currentDragData.initialize();
     Vector<string> files = arguments[0].toStringVector();
+    Vector<WebString> absoluteFilenames;
     for (size_t i = 0; i < files.size(); ++i) {
         WebDragData::Item item;
         item.storageType = WebDragData::Item::StorageTypeFilename;
         item.filenameData = webkit_support::GetAbsoluteWebStringFromUTF8Path(files[i]);
         currentDragData.addItem(item);
+        absoluteFilenames.append(item.filenameData);
     }
+    currentDragData.setFilesystemId(webkit_support::RegisterIsolatedFileSystem(absoluteFilenames));
     currentDragEffectsAllowed = WebKit::WebDragOperationCopy;
 
     // Provide a drag source.