OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 base::PLATFORM_FILE_WRITE | | 60 base::PLATFORM_FILE_WRITE | |
61 base::PLATFORM_FILE_WRITE_ATTRIBUTES | | 61 base::PLATFORM_FILE_WRITE_ATTRIBUTES | |
62 base::PLATFORM_FILE_ASYNC; | 62 base::PLATFORM_FILE_ASYNC; |
63 | 63 |
64 int permissions = kReadFilePermissions; | 64 int permissions = kReadFilePermissions; |
65 if (dialog_type == SelectFileDialog::SELECT_SAVEAS_FILE) | 65 if (dialog_type == SelectFileDialog::SELECT_SAVEAS_FILE) |
66 permissions = kWriteFilePermissions; | 66 permissions = kWriteFilePermissions; |
67 render_view_host->FilesSelectedInChooser(files, permissions); | 67 render_view_host->FilesSelectedInChooser(files, permissions); |
68 } | 68 } |
69 | 69 |
70 // Converts a list of FilePaths to a list of SelectedFileInfo, with the | 70 // Converts a list of FilePaths to a list of ui::SelectedFileInfo. |
71 // display name field left empty. | 71 std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( |
72 std::vector<ui::SelectedFileInfo> ConvertToSelectedFileInfoList( | |
73 const std::vector<FilePath>& paths) { | 72 const std::vector<FilePath>& paths) { |
74 std::vector<ui::SelectedFileInfo> selected_files; | 73 std::vector<ui::SelectedFileInfo> selected_files; |
75 for (size_t i = 0; i < paths.size(); ++i) { | 74 for (size_t i = 0; i < paths.size(); ++i) { |
76 selected_files.push_back( | 75 selected_files.push_back( |
77 ui::SelectedFileInfo(paths[i], FilePath::StringType())); | 76 ui::SelectedFileInfo(paths[i], paths[i])); |
78 } | 77 } |
79 return selected_files; | 78 return selected_files; |
80 } | 79 } |
81 | 80 |
82 } // namespace | 81 } // namespace |
83 | 82 |
84 struct FileSelectHelper::ActiveDirectoryEnumeration { | 83 struct FileSelectHelper::ActiveDirectoryEnumeration { |
85 ActiveDirectoryEnumeration() : rvh_(NULL) {} | 84 ActiveDirectoryEnumeration() : rvh_(NULL) {} |
86 | 85 |
87 scoped_ptr<DirectoryListerDispatchDelegate> delegate_; | 86 scoped_ptr<DirectoryListerDispatchDelegate> delegate_; |
(...skipping 23 matching lines...) Expand all Loading... |
111 for (iter = directory_enumerations_.begin(); | 110 for (iter = directory_enumerations_.begin(); |
112 iter != directory_enumerations_.end(); | 111 iter != directory_enumerations_.end(); |
113 ++iter) { | 112 ++iter) { |
114 iter->second->lister_.reset(); | 113 iter->second->lister_.reset(); |
115 delete iter->second; | 114 delete iter->second; |
116 } | 115 } |
117 } | 116 } |
118 | 117 |
119 void FileSelectHelper::FileSelected(const FilePath& path, | 118 void FileSelectHelper::FileSelected(const FilePath& path, |
120 int index, void* params) { | 119 int index, void* params) { |
121 FileSelectedWithExtraInfo( | 120 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); |
122 ui::SelectedFileInfo(path, FilePath::StringType()), | |
123 index, params); | |
124 } | 121 } |
125 | 122 |
126 void FileSelectHelper::FileSelectedWithExtraInfo( | 123 void FileSelectHelper::FileSelectedWithExtraInfo( |
127 const ui::SelectedFileInfo& file, | 124 const ui::SelectedFileInfo& file, |
128 int index, | 125 int index, |
129 void* params) { | 126 void* params) { |
130 if (!render_view_host_) | 127 if (!render_view_host_) |
131 return; | 128 return; |
132 | 129 |
133 const FilePath& path = file.path; | 130 profile_->set_last_selected_directory(file.file_path.DirName()); |
134 profile_->set_last_selected_directory(path.DirName()); | |
135 | 131 |
| 132 const FilePath& path = file.local_path; |
136 if (dialog_type_ == SelectFileDialog::SELECT_FOLDER) { | 133 if (dialog_type_ == SelectFileDialog::SELECT_FOLDER) { |
137 StartNewEnumeration(path, kFileSelectEnumerationId, render_view_host_); | 134 StartNewEnumeration(path, kFileSelectEnumerationId, render_view_host_); |
138 return; | 135 return; |
139 } | 136 } |
140 | 137 |
141 std::vector<ui::SelectedFileInfo> files; | 138 std::vector<ui::SelectedFileInfo> files; |
142 files.push_back(file); | 139 files.push_back(file); |
143 NotifyRenderViewHost(render_view_host_, files, dialog_type_); | 140 NotifyRenderViewHost(render_view_host_, files, dialog_type_); |
144 | 141 |
145 // No members should be accessed from here on. | 142 // No members should be accessed from here on. |
146 RunFileChooserEnd(); | 143 RunFileChooserEnd(); |
147 } | 144 } |
148 | 145 |
149 void FileSelectHelper::MultiFilesSelected(const std::vector<FilePath>& files, | 146 void FileSelectHelper::MultiFilesSelected(const std::vector<FilePath>& files, |
150 void* params) { | 147 void* params) { |
151 std::vector<ui::SelectedFileInfo> selected_files = | 148 std::vector<ui::SelectedFileInfo> selected_files = |
152 ConvertToSelectedFileInfoList(files); | 149 FilePathListToSelectedFileInfoList(files); |
| 150 |
153 MultiFilesSelectedWithExtraInfo(selected_files, params); | 151 MultiFilesSelectedWithExtraInfo(selected_files, params); |
154 } | 152 } |
155 | 153 |
156 void FileSelectHelper::MultiFilesSelectedWithExtraInfo( | 154 void FileSelectHelper::MultiFilesSelectedWithExtraInfo( |
157 const std::vector<ui::SelectedFileInfo>& files, | 155 const std::vector<ui::SelectedFileInfo>& files, |
158 void* params) { | 156 void* params) { |
159 if (!files.empty()) | 157 if (!files.empty()) |
160 profile_->set_last_selected_directory(files[0].path.DirName()); | 158 profile_->set_last_selected_directory(files[0].file_path.DirName()); |
161 if (!render_view_host_) | 159 if (!render_view_host_) |
162 return; | 160 return; |
163 | 161 |
164 NotifyRenderViewHost(render_view_host_, files, dialog_type_); | 162 NotifyRenderViewHost(render_view_host_, files, dialog_type_); |
165 | 163 |
166 // No members should be accessed from here on. | 164 // No members should be accessed from here on. |
167 RunFileChooserEnd(); | 165 RunFileChooserEnd(); |
168 } | 166 } |
169 | 167 |
170 void FileSelectHelper::FileSelectionCanceled(void* params) { | 168 void FileSelectHelper::FileSelectionCanceled(void* params) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 scoped_ptr<ActiveDirectoryEnumeration> entry(directory_enumerations_[id]); | 219 scoped_ptr<ActiveDirectoryEnumeration> entry(directory_enumerations_[id]); |
222 directory_enumerations_.erase(id); | 220 directory_enumerations_.erase(id); |
223 if (!entry->rvh_) | 221 if (!entry->rvh_) |
224 return; | 222 return; |
225 if (error) { | 223 if (error) { |
226 FileSelectionCanceled(NULL); | 224 FileSelectionCanceled(NULL); |
227 return; | 225 return; |
228 } | 226 } |
229 | 227 |
230 std::vector<ui::SelectedFileInfo> selected_files = | 228 std::vector<ui::SelectedFileInfo> selected_files = |
231 ConvertToSelectedFileInfoList(entry->results_); | 229 FilePathListToSelectedFileInfoList(entry->results_); |
232 | 230 |
233 if (id == kFileSelectEnumerationId) | 231 if (id == kFileSelectEnumerationId) |
234 NotifyRenderViewHost(entry->rvh_, selected_files, dialog_type_); | 232 NotifyRenderViewHost(entry->rvh_, selected_files, dialog_type_); |
235 else | 233 else |
236 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); | 234 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); |
237 | 235 |
238 EnumerateDirectoryEnd(); | 236 EnumerateDirectoryEnd(); |
239 } | 237 } |
240 | 238 |
241 SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType( | 239 SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType( |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // A 1 character accept type will always be invalid (either a "." in the case | 471 // A 1 character accept type will always be invalid (either a "." in the case |
474 // of an extension or a "/" in the case of a MIME type). | 472 // of an extension or a "/" in the case of a MIME type). |
475 std::string unused; | 473 std::string unused; |
476 if (accept_type.length() <= 1 || | 474 if (accept_type.length() <= 1 || |
477 StringToLowerASCII(accept_type) != accept_type || | 475 StringToLowerASCII(accept_type) != accept_type || |
478 TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) { | 476 TrimWhitespaceASCII(accept_type, TRIM_ALL, &unused) != TRIM_NONE) { |
479 return false; | 477 return false; |
480 } | 478 } |
481 return true; | 479 return true; |
482 } | 480 } |
OLD | NEW |