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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 10663014: Add tests for chrome.fileSystem app API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using new Blob constructor Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "chrome/browser/extensions/shell_window_registry.h" 10 #include "chrome/browser/extensions/shell_window_registry.h"
(...skipping 14 matching lines...) Expand all
25 const char kUserCancelled[] = "User cancelled"; 25 const char kUserCancelled[] = "User cancelled";
26 const char kWritableFileError[] = "Invalid file for writing"; 26 const char kWritableFileError[] = "Invalid file for writing";
27 27
28 const char kSaveFileOption[] = "saveFile"; 28 const char kSaveFileOption[] = "saveFile";
29 29
30 namespace file_system = extensions::api::file_system; 30 namespace file_system = extensions::api::file_system;
31 namespace ChooseFile = file_system::ChooseFile; 31 namespace ChooseFile = file_system::ChooseFile;
32 32
33 namespace { 33 namespace {
34 34
35 bool g_skip_picker = false;
36 FilePath* g_path_to_be_picked;
37
35 bool GetFilePathOfFileEntry(const std::string& filesystem_name, 38 bool GetFilePathOfFileEntry(const std::string& filesystem_name,
36 const std::string& filesystem_path, 39 const std::string& filesystem_path,
37 const content::RenderViewHost* render_view_host, 40 const content::RenderViewHost* render_view_host,
38 FilePath* file_path, 41 FilePath* file_path,
39 std::string* error) { 42 std::string* error) {
40 std::string filesystem_id; 43 std::string filesystem_id;
41 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { 44 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) {
42 *error = kInvalidParameters; 45 *error = kInvalidParameters;
43 return false; 46 return false;
44 } 47 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 FilePath::StringType extension = suggested_path.Extension(); 122 FilePath::StringType extension = suggested_path.Extension();
120 if (!extension.empty()) { 123 if (!extension.empty()) {
121 extension.erase(extension.begin()); // drop the . 124 extension.erase(extension.begin()); // drop the .
122 file_type_info.extensions.resize(1); 125 file_type_info.extensions.resize(1);
123 file_type_info.extensions[0].push_back(extension); 126 file_type_info.extensions[0].push_back(extension);
124 } 127 }
125 file_type_info.include_all_files = true; 128 file_type_info.include_all_files = true;
126 gfx::NativeWindow owning_window = web_contents ? 129 gfx::NativeWindow owning_window = web_contents ?
127 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; 130 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL;
128 131
132 if (g_skip_picker) {
133 if (g_path_to_be_picked) {
134 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
135 base::Bind(&FileSystemPickerFunction::FilePicker::FileSelected,
136 base::Unretained(this), *g_path_to_be_picked, 1,
137 static_cast<void*>(NULL)));
138 } else {
139 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
140 base::Bind(
141 &FileSystemPickerFunction::FilePicker::FileSelectionCanceled,
142 base::Unretained(this), static_cast<void*>(NULL)));
143 }
144 return;
145 }
146
129 select_file_dialog_->SelectFile(for_save ? 147 select_file_dialog_->SelectFile(for_save ?
130 SelectFileDialog::SELECT_SAVEAS_FILE : 148 SelectFileDialog::SELECT_SAVEAS_FILE :
131 SelectFileDialog::SELECT_OPEN_FILE, 149 SelectFileDialog::SELECT_OPEN_FILE,
132 string16(), 150 string16(),
133 suggested_path, 151 suggested_path,
134 &file_type_info, 0, FILE_PATH_LITERAL(""), 152 &file_type_info, 0, FILE_PATH_LITERAL(""),
135 web_contents, owning_window, NULL); 153 web_contents, owning_window, NULL);
136 } 154 }
137 155
138 virtual ~FilePicker() {} 156 virtual ~FilePicker() {}
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 194 }
177 195
178 // The file picker will hold a reference to this function instance, preventing 196 // The file picker will hold a reference to this function instance, preventing
179 // its destruction (and subsequent sending of the function response) until the 197 // its destruction (and subsequent sending of the function response) until the
180 // user has selected a file or cancelled the picker. At that point, the picker 198 // user has selected a file or cancelled the picker. At that point, the picker
181 // will delete itself, which will also free the function instance. 199 // will delete itself, which will also free the function instance.
182 new FilePicker(this, shell_window->web_contents(), suggested_path, for_save); 200 new FilePicker(this, shell_window->web_contents(), suggested_path, for_save);
183 return true; 201 return true;
184 } 202 }
185 203
204 // static
205 void FileSystemPickerFunction::SkipPickerAndAlwaysSelectPath(FilePath* path) {
206 g_skip_picker = true;
207 g_path_to_be_picked = path;
208 }
209
210 // static
211 void FileSystemPickerFunction::SkipPickerAndAlwaysCancel() {
212 g_skip_picker = true;
213 g_path_to_be_picked = NULL;
214 }
215
216 // static
217 void FileSystemPickerFunction::StopSkippingPicker() {
218 g_skip_picker = false;
219 }
220
186 void FileSystemPickerFunction::FileSelected(const FilePath& path, 221 void FileSystemPickerFunction::FileSelected(const FilePath& path,
187 bool for_save) { 222 bool for_save) {
188 if (for_save) { 223 if (for_save) {
189 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 224 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
190 base::Bind(&FileSystemPickerFunction::CheckWritableFile, this, path)); 225 base::Bind(&FileSystemPickerFunction::CheckWritableFile, this, path));
191 return; 226 return;
192 } 227 }
193 228
194 // Don't need to check the file, it's for reading. 229 // Don't need to check the file, it's for reading.
195 RegisterFileSystemAndSendResponse(path, false); 230 RegisterFileSystemAndSendResponse(path, false);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 file_system::ChooseFileOptions* options = params->options.get(); 310 file_system::ChooseFileOptions* options = params->options.get();
276 if (options) { 311 if (options) {
277 if (options->type.get() && *options->type == kSaveFileOption) 312 if (options->type.get() && *options->type == kSaveFileOption)
278 for_save = true; 313 for_save = true;
279 } 314 }
280 315
281 return ShowPicker(FilePath(), for_save); 316 return ShowPicker(FilePath(), for_save);
282 } 317 }
283 318
284 } // namespace extensions 319 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698