<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[167784] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/167784">167784</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-04-24 17:48:38 -0700 (Thu, 24 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDataTransfercpp">trunk/Source/WebCore/dom/DataTransfer.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDataTransferh">trunk/Source/WebCore/dom/DataTransfer.h</a></li>
<li><a href="#trunkSourceWebCorefileapiFilecpp">trunk/Source/WebCore/fileapi/File.cpp</a></li>
<li><a href="#trunkSourceWebCorefileapiFileh">trunk/Source/WebCore/fileapi/File.h</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2014-04-24 Alexey Proskuryakov <ap@apple.com>
+
+ 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.
+
</ins><span class="cx"> 2014-04-24 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r167441.
</span></span></pre></div>
<a id="trunkSourceWebCoredomDataTransfercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DataTransfer.cpp (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -184,6 +184,25 @@
</span><span class="cx"> return m_fileList.get();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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);
+}
+
</ins><span class="cx"> #if !ENABLE(DRAG_SUPPORT)
</span><span class="cx">
</span><span class="cx"> String DataTransfer::dropEffect() const
</span></span></pre></div>
<a id="trunkSourceWebCoredomDataTransferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DataTransfer.h (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -76,6 +76,9 @@
</span><span class="cx"> bool canReadData() const;
</span><span class="cx"> bool canWriteData() const;
</span><span class="cx">
</span><ins>+ bool hasFileOfType(const String&);
+ bool hasStringOfType(const String&);
+
</ins><span class="cx"> Pasteboard& pasteboard() { return *m_pasteboard; }
</span><span class="cx">
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiFilecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/File.cpp (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -35,21 +35,6 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-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;
-}
-
</del><span class="cx"> static std::unique_ptr<BlobData> createBlobDataForFileWithType(const String& path, const String& contentType)
</span><span class="cx"> {
</span><span class="cx"> auto blobData = std::make_unique<BlobData>();
</span><span class="lines">@@ -61,12 +46,12 @@
</span><span class="cx">
</span><span class="cx"> static std::unique_ptr<BlobData> createBlobDataForFile(const String& path, File::ContentTypeLookupPolicy policy)
</span><span class="cx"> {
</span><del>- return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
</del><ins>+ return createBlobDataForFileWithType(path, File::contentTypeFromFilePath(path, policy));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName, File::ContentTypeLookupPolicy policy)
</span><span class="cx"> {
</span><del>- return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName, policy));
</del><ins>+ return createBlobDataForFileWithType(path, File::contentTypeFromFilePath(fileSystemName, policy));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> File::File(const String& path, ContentTypeLookupPolicy policy)
</span><span class="lines">@@ -127,4 +112,19 @@
</span><span class="cx"> snapshotModificationTime = metadata.modificationTime;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorefileapiFileh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/fileapi/File.h (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -75,6 +75,8 @@
</span><span class="cx"> // Note that this involves synchronous file operation. Think twice before calling this function.
</span><span class="cx"> void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
</span><span class="cx">
</span><ins>+ static String contentTypeFromFilePath(const String&, ContentTypeLookupPolicy);
+
</ins><span class="cx"> private:
</span><span class="cx"> File(const String& path, ContentTypeLookupPolicy);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (167783 => 167784)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2059,28 +2059,13 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-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);
-}
-
</del><span class="cx"> static bool hasDropZoneType(DataTransfer& dataTransfer, const String& keyword)
</span><span class="cx"> {
</span><span class="cx"> if (keyword.startsWith("file:"))
</span><del>- return hasFileOfType(dataTransfer, keyword.substring(5));
</del><ins>+ return dataTransfer.hasFileOfType(keyword.substring(5));
</ins><span class="cx">
</span><span class="cx"> if (keyword.startsWith("string:"))
</span><del>- return hasStringOfType(dataTransfer, keyword.substring(7));
</del><ins>+ return dataTransfer.hasStringOfType(keyword.substring(7));
</ins><span class="cx">
</span><span class="cx"> return false;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>