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

Side by Side Diff: webkit/browser/fileapi/dragged_file_util.cc

Issue 190533005: Bug 343571: Dragging and dropping a directory containing a symlink results in the symlink being ign… Base URL: https://chromium.googlesource.com/chromium/src.git@344225
Patch Set: Created 6 years, 9 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 unified diff | Download patch
« no previous file with comments | « webkit/browser/fileapi/dragged_file_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/browser/fileapi/dragged_file_util.h" 5 #include "webkit/browser/fileapi/dragged_file_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_enumerator.h"
11 #include "webkit/browser/fileapi/file_system_context.h" 12 #include "webkit/browser/fileapi/file_system_context.h"
12 #include "webkit/browser/fileapi/file_system_operation_context.h" 13 #include "webkit/browser/fileapi/file_system_operation_context.h"
13 #include "webkit/browser/fileapi/file_system_url.h" 14 #include "webkit/browser/fileapi/file_system_url.h"
14 #include "webkit/browser/fileapi/isolated_context.h" 15 #include "webkit/browser/fileapi/isolated_context.h"
15 #include "webkit/browser/fileapi/native_file_util.h" 16 #include "webkit/browser/fileapi/native_file_util.h"
16 #include "webkit/common/blob/shareable_file_reference.h" 17 #include "webkit/common/blob/shareable_file_reference.h"
17 18
18 namespace fileapi { 19 namespace fileapi {
19 20
20 typedef IsolatedContext::MountPointInfo FileInfo; 21 typedef IsolatedContext::MountPointInfo FileInfo;
(...skipping 23 matching lines...) Expand all
44 virtual base::Time LastModifiedTime() OVERRIDE { 45 virtual base::Time LastModifiedTime() OVERRIDE {
45 return file_info_.last_modified; 46 return file_info_.last_modified;
46 } 47 }
47 48
48 private: 49 private:
49 std::vector<FileInfo> files_; 50 std::vector<FileInfo> files_;
50 std::vector<FileInfo>::const_iterator file_iter_; 51 std::vector<FileInfo>::const_iterator file_iter_;
51 base::File::Info file_info_; 52 base::File::Info file_info_;
52 }; 53 };
53 54
55 // Like fileapi::LocalFileEnumerator, but without skipping symbolic links.
56 class FollowSymlinksLocalFileEnumerator
57 : public FileSystemFileUtil::AbstractFileEnumerator {
58 public:
59 FollowSymlinksLocalFileEnumerator(
60 const base::FilePath& platform_root_path,
61 const base::FilePath& virtual_root_path,
62 int file_type)
63 : file_enum_(platform_root_path, false /* recursive */, file_type),
64 platform_root_path_(platform_root_path),
65 virtual_root_path_(virtual_root_path) {
66 }
67
68 virtual ~FollowSymlinksLocalFileEnumerator() {}
69
70 virtual base::FilePath Next() OVERRIDE;
71 virtual int64 Size() OVERRIDE;
72 virtual base::Time LastModifiedTime() OVERRIDE;
73 virtual bool IsDirectory() OVERRIDE;
74
75 private:
76 base::FileEnumerator file_enum_;
77 base::FileEnumerator::FileInfo file_util_info_;
78 base::FilePath platform_root_path_;
79 base::FilePath virtual_root_path_;
80 };
81
54 } // namespace 82 } // namespace
55 83
56 //------------------------------------------------------------------------- 84 //-------------------------------------------------------------------------
57 85
86 base::FilePath FollowSymlinksLocalFileEnumerator::Next() {
87 base::FilePath next = file_enum_.Next();
88
89 if (next.empty())
90 return next;
91 file_util_info_ = file_enum_.GetInfo();
92
93 base::FilePath path;
94 platform_root_path_.AppendRelativePath(next, &path);
95 return virtual_root_path_.Append(path);
96 }
97
98 int64 FollowSymlinksLocalFileEnumerator::Size() {
99 return file_util_info_.GetSize();
100 }
101
102 base::Time FollowSymlinksLocalFileEnumerator::LastModifiedTime() {
103 return file_util_info_.GetLastModifiedTime();
104 }
105
106 bool FollowSymlinksLocalFileEnumerator::IsDirectory() {
107 return file_util_info_.IsDirectory();
108 }
109
58 DraggedFileUtil::DraggedFileUtil() {} 110 DraggedFileUtil::DraggedFileUtil() {}
59 111
112 base::File::Error DraggedFileUtil::CreateOrOpen(
113 FileSystemOperationContext* context,
114 const FileSystemURL& url, int file_flags,
115 base::PlatformFile* file_handle, bool* created) {
116 *created = false;
117 base::FilePath file_path;
118 base::File::Error error = GetLocalFilePath(context, url, &file_path);
119 if (error != base::File::FILE_OK)
120 return error;
121
122 return NativeFileUtil::CreateOrOpen(file_path, file_flags, file_handle,
123 created);
124 }
125
60 base::File::Error DraggedFileUtil::GetFileInfo( 126 base::File::Error DraggedFileUtil::GetFileInfo(
61 FileSystemOperationContext* context, 127 FileSystemOperationContext* context,
62 const FileSystemURL& url, 128 const FileSystemURL& url,
63 base::File::Info* file_info, 129 base::File::Info* file_info,
64 base::FilePath* platform_path) { 130 base::FilePath* platform_path) {
65 DCHECK(file_info); 131 DCHECK(file_info);
66 std::string filesystem_id; 132 std::string filesystem_id;
67 DCHECK(url.is_valid()); 133 DCHECK(url.is_valid());
68 if (url.path().empty()) { 134 if (url.path().empty()) {
69 // The root directory case. 135 // The root directory case.
70 // For now we leave three time fields (modified/accessed/creation time) 136 // For now we leave three time fields (modified/accessed/creation time)
71 // NULL as it is not really clear what to be set for this virtual directory. 137 // NULL as it is not really clear what to be set for this virtual directory.
72 // TODO(kinuko): Maybe we want to set the time when this filesystem is 138 // TODO(kinuko): Maybe we want to set the time when this filesystem is
73 // created (i.e. when the files/directories are dropped). 139 // created (i.e. when the files/directories are dropped).
74 file_info->is_directory = true; 140 file_info->is_directory = true;
75 file_info->is_symbolic_link = false; 141 file_info->is_symbolic_link = false;
76 file_info->size = 0; 142 file_info->size = 0;
77 return base::File::FILE_OK; 143 return base::File::FILE_OK;
78 } 144 }
79 base::File::Error error = 145 base::File::Error error =
80 NativeFileUtil::GetFileInfo(url.path(), file_info); 146 NativeFileUtil::GetFileInfo(url.path(), file_info);
81 if (base::IsLink(url.path()) && !base::FilePath().IsParent(url.path())) {
82 // Don't follow symlinks unless it's the one that are selected by the user.
83 return base::File::FILE_ERROR_NOT_FOUND;
84 }
85 if (error == base::File::FILE_OK) 147 if (error == base::File::FILE_OK)
86 *platform_path = url.path(); 148 *platform_path = url.path();
87 return error; 149 return error;
88 } 150 }
89 151
90 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 152 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
91 DraggedFileUtil::CreateFileEnumerator( 153 DraggedFileUtil::CreateFileEnumerator(
92 FileSystemOperationContext* context, 154 FileSystemOperationContext* context,
93 const FileSystemURL& root) { 155 const FileSystemURL& root) {
94 DCHECK(root.is_valid()); 156 DCHECK(root.is_valid());
95 if (!root.path().empty()) 157 if (!root.path().empty()) {
96 return LocalFileUtil::CreateFileEnumerator(context, root); 158 base::FilePath file_path;
159 if (GetLocalFilePath(context, root, &file_path) !=
160 base::File::FILE_OK) {
161 return make_scoped_ptr(new EmptyFileEnumerator)
162 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
163 }
164
165 return make_scoped_ptr(new FollowSymlinksLocalFileEnumerator(
166 file_path, root.path(),
167 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES))
168 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
169 }
97 170
98 // Root path case. 171 // Root path case.
99 std::vector<FileInfo> toplevels; 172 std::vector<FileInfo> toplevels;
100 IsolatedContext::GetInstance()->GetDraggedFileInfo( 173 IsolatedContext::GetInstance()->GetDraggedFileInfo(
101 root.filesystem_id(), &toplevels); 174 root.filesystem_id(), &toplevels);
102 return scoped_ptr<AbstractFileEnumerator>(new SetFileEnumerator(toplevels)); 175 return scoped_ptr<AbstractFileEnumerator>(new SetFileEnumerator(toplevels));
103 } 176 }
104 177
105 } // namespace fileapi 178 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/dragged_file_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698