https://bugs.webkit.org/show_bug.cgi?id=87234
Reviewed by Eric Seidel.
Source/WebCore:
No new tests as this must have no side effect.
* bindings/v8/custom/V8BlobCustom.cpp:
(WebCore::toV8):
* fileapi/Blob.cpp:
(WebCore::Blob::webkitSlice):
* fileapi/Blob.h:
(Blob):
* fileapi/File.h:
(WebCore::toFile): Added.
(WebCore):
* fileapi/FileReader.cpp:
(WebCore::FileReader::readAsArrayBuffer):
(WebCore::FileReader::readAsBinaryString):
(WebCore::FileReader::readAsText):
(WebCore::FileReader::readAsDataURL):
* fileapi/WebKitBlobBuilder.cpp:
(WebCore::WebKitBlobBuilder::append):
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::files):
* platform/network/FormData.cpp:
(WebCore::FormData::appendKeyValuePairItems):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::send):
Source/WebKit/chromium:
* src/WebDragData.cpp:
(WebKit::WebDragData::items):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118394
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-05-24 Kinuko Yasuda <kinuko@chromium.org>
+
+ Cleanup: introduce toFile() to reduce static cast from Blob to File
+ https://bugs.webkit.org/show_bug.cgi?id=87234
+
+ Reviewed by Eric Seidel.
+
+ No new tests as this must have no side effect.
+
+ * bindings/v8/custom/V8BlobCustom.cpp:
+ (WebCore::toV8):
+ * fileapi/Blob.cpp:
+ (WebCore::Blob::webkitSlice):
+ * fileapi/Blob.h:
+ (Blob):
+ * fileapi/File.h:
+ (WebCore::toFile): Added.
+ (WebCore):
+ * fileapi/FileReader.cpp:
+ (WebCore::FileReader::readAsArrayBuffer):
+ (WebCore::FileReader::readAsBinaryString):
+ (WebCore::FileReader::readAsText):
+ (WebCore::FileReader::readAsDataURL):
+ * fileapi/WebKitBlobBuilder.cpp:
+ (WebCore::WebKitBlobBuilder::append):
+ * platform/chromium/ClipboardChromium.cpp:
+ (WebCore::ClipboardChromium::files):
+ * platform/network/FormData.cpp:
+ (WebCore::FormData::appendKeyValuePairItems):
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::send):
+
2012-05-24 Darin Adler <darin@apple.com>
SVGElement::addEventListener has peculiar RefPtr usage
return v8::Null();
if (impl->isFile())
- return toV8(static_cast<File*>(impl), isolate);
+ return toV8(toFile(impl), isolate);
return V8Blob::wrap(impl, isolate);
}
// The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed.
long long size;
double modificationTime;
- if (isFile())
+ if (isFile()) {
// FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
- static_cast<const File*>(this)->captureSnapshot(size, modificationTime);
- else {
+ toFile(this)->captureSnapshot(size, modificationTime);
+ } else {
ASSERT(m_size != -1);
size = m_size;
}
OwnPtr<BlobData> blobData = BlobData::create();
blobData->setContentType(contentType);
if (isFile())
- blobData->appendFile(static_cast<const File*>(this)->path(), start, length, modificationTime);
+ blobData->appendFile(toFile(this)->path(), start, length, modificationTime);
else
blobData->appendBlob(m_internalURL, start, length);
// as an identifier for this blob. The internal URL is never used to source the blob's content
// into an HTML or for FileRead'ing, public blob URLs must be used for those purposes.
KURL m_internalURL;
-
+
String m_type;
long long m_size;
};
#endif
};
+inline File* toFile(Blob* blob)
+{
+ ASSERT(!blob || blob->isFile());
+ return static_cast<File*>(blob);
+}
+
+inline const File* toFile(const Blob* blob)
+{
+ ASSERT(!blob || blob->isFile());
+ return static_cast<const File*>(blob);
+}
+
} // namespace WebCore
#endif // File_h
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec);
}
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec);
}
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
m_encoding = encoding;
readInternal(blob, FileReaderLoader::ReadAsText, ec);
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsDataURL, ec);
}
if (!blob)
return;
if (blob->isFile()) {
+ File* file = toFile(blob);
// If the blob is file that is not snapshoted, capture the snapshot now.
// FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
- File* file = static_cast<File*>(blob);
long long snapshotSize;
double snapshotModificationTime;
file->captureSnapshot(snapshotSize, snapshotModificationTime);
if (m_dataObject->item(i)->kind() == DataTransferItem::kindFile) {
RefPtr<Blob> blob = m_dataObject->item(i)->getAsFile();
if (blob && blob->isFile())
- files->append(static_cast<File*>(blob.get()));
+ files->append(toFile(blob.get()));
}
}
if (value.blob()) {
String name;
if (value.blob()->isFile()) {
+ File* file = toFile(value.blob());
// For file blob, use the filename (or relative path if it is present) as the name.
- File* file = static_cast<File*>(value.blob());
#if ENABLE(DIRECTORY_UPLOAD)
name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath();
#else
appendData(header.data(), header.size());
if (value.blob()) {
if (value.blob()->isFile()) {
+ File* file = toFile(value.blob());
// Do not add the file if the path is empty.
- if (!static_cast<File*>(value.blob())->path().isEmpty())
- appendFile(static_cast<File*>(value.blob())->path(), shouldGenerateFile);
+ if (!file->path().isEmpty())
+ appendFile(file->path(), shouldGenerateFile);
}
#if ENABLE(BLOB)
else
// FIXME: add support for uploading bundles.
m_requestEntityBody = FormData::create();
if (body->isFile())
- m_requestEntityBody->appendFile(static_cast<File*>(body)->path());
+ m_requestEntityBody->appendFile(toFile(body)->path());
#if ENABLE(BLOB)
else
m_requestEntityBody->appendBlob(body->url());
+2012-05-24 Kinuko Yasuda <kinuko@chromium.org>
+
+ Cleanup: introduce toFile() to reduce static cast from Blob to File
+ https://bugs.webkit.org/show_bug.cgi?id=87234
+
+ Reviewed by Eric Seidel.
+
+ * src/WebDragData.cpp:
+ (WebKit::WebDragData::items):
+
2012-05-24 Lu Guanqun <guanqun.lu@intel.com>
use built-in data type DashArray
item.storageType = Item::StorageTypeFilename;
RefPtr<WebCore::Blob> blob = originalItem->getAsFile();
if (blob->isFile()) {
- File* file = static_cast<File*>(blob.get());
+ File* file = toFile(blob.get());
item.filenameData = file->path();
item.displayNameData = file->name();
} else