Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Unified Diff: Source/core/html/forms/FileInputType.cpp

Issue 640723006: Pass the selected non-native file information from the browser to FileInputType. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/forms/FileInputType.h ('k') | Source/core/html/forms/FileInputTypeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/forms/FileInputType.cpp
diff --git a/Source/core/html/forms/FileInputType.cpp b/Source/core/html/forms/FileInputType.cpp
index 5c74604d1c3ab71f6f326edf3f8fe3683e0e25ab..120759f4700399a14b432e427543e5e88ee169f8 100644
--- a/Source/core/html/forms/FileInputType.cpp
+++ b/Source/core/html/forms/FileInputType.cpp
@@ -217,7 +217,7 @@ void FileInputType::setValue(const String&, bool valueChanged, TextFieldEventBeh
element().setNeedsValidityCheck();
}
-FileList* FileInputType::createFileList(const Vector<FileChooserFileInfo>& files) const
+FileList* FileInputType::createFileList(const Vector<FileChooserFileInfo>& files, bool hasWebkitDirectoryAttr)
{
FileList* fileList(FileList::create());
size_t size = files.size();
@@ -225,10 +225,10 @@ FileList* FileInputType::createFileList(const Vector<FileChooserFileInfo>& files
// If a directory is being selected, the UI allows a directory to be chosen
// and the paths provided here share a root directory somewhere up the tree;
// we want to store only the relative paths from that point.
- if (size && element().fastHasAttribute(webkitdirectoryAttr)) {
+ if (size && hasWebkitDirectoryAttr) {
// Find the common root path.
String rootPath = directoryName(files[0].path);
- for (size_t i = 1; i < size; i++) {
+ for (size_t i = 1; i < size; ++i) {
while (!files[i].path.startsWith(rootPath))
rootPath = directoryName(rootPath);
}
@@ -237,7 +237,7 @@ FileList* FileInputType::createFileList(const Vector<FileChooserFileInfo>& files
int rootLength = rootPath.length();
if (rootPath[rootLength - 1] != '\\' && rootPath[rootLength - 1] != '/')
rootLength += 1;
- for (size_t i = 0; i < size; i++) {
+ for (size_t i = 0; i < size; ++i) {
// Normalize backslashes to slashes before exposing the relative path to script.
String relativePath = files[i].path.substring(rootLength).replace('\\', '/');
fileList->append(File::createWithRelativePath(files[i].path, relativePath));
@@ -245,8 +245,13 @@ FileList* FileInputType::createFileList(const Vector<FileChooserFileInfo>& files
return fileList;
}
- for (size_t i = 0; i < size; i++)
- fileList->append(File::createForUserProvidedFile(files[i].path, files[i].displayName));
+ for (size_t i = 0; i < size; ++i) {
+ if (files[i].fileSystemURL.isEmpty()) {
+ fileList->append(File::createForUserProvidedFile(files[i].path, files[i].displayName));
+ } else {
+ fileList->append(File::createForFileSystemFile(files[i].fileSystemURL, files[i].metadata));
+ }
+ }
return fileList;
}
@@ -281,13 +286,13 @@ void FileInputType::setFiles(FileList* files)
RefPtrWillBeRawPtr<HTMLInputElement> input(element());
- bool pathsChanged = false;
+ bool filesChanged = false;
if (files->length() != m_fileList->length()) {
- pathsChanged = true;
+ filesChanged = true;
} else {
for (unsigned i = 0; i < files->length(); ++i) {
- if (files->item(i)->path() != m_fileList->item(i)->path()) {
- pathsChanged = true;
+ if (!files->item(i)->hasSameSource(*m_fileList->item(i))) {
+ filesChanged = true;
break;
}
}
@@ -301,7 +306,7 @@ void FileInputType::setFiles(FileList* files)
if (input->renderer())
input->renderer()->setShouldDoFullPaintInvalidation();
- if (pathsChanged) {
+ if (filesChanged) {
// This call may cause destruction of this instance.
// input instance is safe since it is ref-counted.
input->dispatchChangeEvent();
@@ -311,7 +316,7 @@ void FileInputType::setFiles(FileList* files)
void FileInputType::filesChosen(const Vector<FileChooserFileInfo>& files)
{
- setFiles(createFileList(files));
+ setFiles(createFileList(files, element().fastHasAttribute(webkitdirectoryAttr)));
}
void FileInputType::receiveDropForDirectoryUpload(const Vector<String>& paths)
« no previous file with comments | « Source/core/html/forms/FileInputType.h ('k') | Source/core/html/forms/FileInputTypeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698