- Revision
- 167784
- Author
- [email protected]
- Date
- 2014-04-24 17:48:38 -0700 (Thu, 24 Apr 2014)
Log Message
Dropzone effects don't work in non-file documents
https://bugs.webkit.org/show_bug.cgi?id=131770
Reviewed by Darin Adler.
File documents have two quirks that were making dropzone work in these before:
1. An ancient hack for Dashboard allows pasteboard access from JS.
2. On Mac, sandbox doesn't prevent File object creation, as we already have the access.
* dom/DataTransfer.cpp:
(WebCore::DataTransfer::hasFileOfType):
(WebCore::DataTransfer::hasStringOfType):
* dom/DataTransfer.h:
Moved these functions from EventHandler to DataTransfer. We can't create a DataTransfer
with Files while dragging, security doesn't permit us to. But we can get the file name.
* fileapi/File.cpp:
(WebCore::createBlobDataForFile):
(WebCore::createBlobDataForFileWithName):
(WebCore::File::contentTypeFromFilePath):
(WebCore::getContentTypeFromFileName): Deleted.
* fileapi/File.h:
Exposed a function to get file type from path without creating a File first.
This is much cheaper than creating a File, and works even when sandbox disallows
read access to content, such as when dragging over a target.
* page/EventHandler.cpp:
(WebCore::hasDropZoneType):
(WebCore::hasFileOfType): Deleted.
(WebCore::hasStringOfType): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (167783 => 167784)
--- trunk/Source/WebCore/ChangeLog 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/ChangeLog 2014-04-25 00:48:38 UTC (rev 167784)
@@ -1,3 +1,36 @@
+2014-04-24 Alexey Proskuryakov <[email protected]>
+
+ Dropzone effects don't work in non-file documents
+ https://bugs.webkit.org/show_bug.cgi?id=131770
+
+ Reviewed by Darin Adler.
+
+ File documents have two quirks that were making dropzone work in these before:
+ 1. An ancient hack for Dashboard allows pasteboard access from JS.
+ 2. On Mac, sandbox doesn't prevent File object creation, as we already have the access.
+
+ * dom/DataTransfer.cpp:
+ (WebCore::DataTransfer::hasFileOfType):
+ (WebCore::DataTransfer::hasStringOfType):
+ * dom/DataTransfer.h:
+ Moved these functions from EventHandler to DataTransfer. We can't create a DataTransfer
+ with Files while dragging, security doesn't permit us to. But we can get the file name.
+
+ * fileapi/File.cpp:
+ (WebCore::createBlobDataForFile):
+ (WebCore::createBlobDataForFileWithName):
+ (WebCore::File::contentTypeFromFilePath):
+ (WebCore::getContentTypeFromFileName): Deleted.
+ * fileapi/File.h:
+ Exposed a function to get file type from path without creating a File first.
+ This is much cheaper than creating a File, and works even when sandbox disallows
+ read access to content, such as when dragging over a target.
+
+ * page/EventHandler.cpp:
+ (WebCore::hasDropZoneType):
+ (WebCore::hasFileOfType): Deleted.
+ (WebCore::hasStringOfType): Deleted.
+
2014-04-24 Commit Queue <[email protected]>
Unreviewed, rolling out r167441.
Modified: trunk/Source/WebCore/dom/DataTransfer.cpp (167783 => 167784)
--- trunk/Source/WebCore/dom/DataTransfer.cpp 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/dom/DataTransfer.cpp 2014-04-25 00:48:38 UTC (rev 167784)
@@ -184,6 +184,25 @@
return m_fileList.get();
}
+bool DataTransfer::hasFileOfType(const String& type)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(canReadTypes());
+
+ for (const String& filename : m_pasteboard->readFilenames()) {
+ if (equalIgnoringCase(File::contentTypeFromFilePath(filename, File::AllContentTypes), type))
+ return true;
+ }
+
+ return false;
+}
+
+bool DataTransfer::hasStringOfType(const String& type)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(canReadTypes());
+
+ return !type.isNull() && types().contains(type);
+}
+
#if !ENABLE(DRAG_SUPPORT)
String DataTransfer::dropEffect() const
Modified: trunk/Source/WebCore/dom/DataTransfer.h (167783 => 167784)
--- trunk/Source/WebCore/dom/DataTransfer.h 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/dom/DataTransfer.h 2014-04-25 00:48:38 UTC (rev 167784)
@@ -76,6 +76,9 @@
bool canReadData() const;
bool canWriteData() const;
+ bool hasFileOfType(const String&);
+ bool hasStringOfType(const String&);
+
Pasteboard& pasteboard() { return *m_pasteboard; }
#if ENABLE(DRAG_SUPPORT)
Modified: trunk/Source/WebCore/fileapi/File.cpp (167783 => 167784)
--- trunk/Source/WebCore/fileapi/File.cpp 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/fileapi/File.cpp 2014-04-25 00:48:38 UTC (rev 167784)
@@ -35,21 +35,6 @@
namespace WebCore {
-static String getContentTypeFromFileName(const String& name, File::ContentTypeLookupPolicy policy)
-{
- String type;
- int index = name.reverseFind('.');
- if (index != -1) {
- if (policy == File::WellKnownContentTypes)
- type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
- else {
- ASSERT(policy == File::AllContentTypes);
- type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
- }
- }
- return type;
-}
-
static std::unique_ptr<BlobData> createBlobDataForFileWithType(const String& path, const String& contentType)
{
auto blobData = std::make_unique<BlobData>();
@@ -61,12 +46,12 @@
static std::unique_ptr<BlobData> createBlobDataForFile(const String& path, File::ContentTypeLookupPolicy policy)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
+ return createBlobDataForFileWithType(path, File::contentTypeFromFilePath(path, policy));
}
static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName, File::ContentTypeLookupPolicy policy)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName, policy));
+ return createBlobDataForFileWithType(path, File::contentTypeFromFilePath(fileSystemName, policy));
}
File::File(const String& path, ContentTypeLookupPolicy policy)
@@ -127,4 +112,19 @@
snapshotModificationTime = metadata.modificationTime;
}
+String File::contentTypeFromFilePath(const String& name, File::ContentTypeLookupPolicy policy)
+{
+ String type;
+ int index = name.reverseFind('.');
+ if (index != -1) {
+ if (policy == File::WellKnownContentTypes)
+ type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
+ else {
+ ASSERT(policy == File::AllContentTypes);
+ type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
+ }
+ }
+ return type;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/fileapi/File.h (167783 => 167784)
--- trunk/Source/WebCore/fileapi/File.h 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/fileapi/File.h 2014-04-25 00:48:38 UTC (rev 167784)
@@ -75,6 +75,8 @@
// Note that this involves synchronous file operation. Think twice before calling this function.
void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
+ static String contentTypeFromFilePath(const String&, ContentTypeLookupPolicy);
+
private:
File(const String& path, ContentTypeLookupPolicy);
Modified: trunk/Source/WebCore/page/EventHandler.cpp (167783 => 167784)
--- trunk/Source/WebCore/page/EventHandler.cpp 2014-04-25 00:17:07 UTC (rev 167783)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2014-04-25 00:48:38 UTC (rev 167784)
@@ -2059,28 +2059,13 @@
}
}
-static inline bool hasFileOfType(DataTransfer& dataTransfer, const String& type)
-{
- RefPtr<FileList> fileList = dataTransfer.files();
- for (unsigned i = 0; i < fileList->length(); i++) {
- if (equalIgnoringCase(fileList->item(i)->type(), type))
- return true;
- }
- return false;
-}
-
-static inline bool hasStringOfType(DataTransfer& dataTransfer, const String& type)
-{
- return !type.isNull() && dataTransfer.types().contains(type);
-}
-
static bool hasDropZoneType(DataTransfer& dataTransfer, const String& keyword)
{
if (keyword.startsWith("file:"))
- return hasFileOfType(dataTransfer, keyword.substring(5));
+ return dataTransfer.hasFileOfType(keyword.substring(5));
if (keyword.startsWith("string:"))
- return hasStringOfType(dataTransfer, keyword.substring(7));
+ return dataTransfer.hasStringOfType(keyword.substring(7));
return false;
}