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

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

Issue 10667026: Start consolidating cross-port file selection code into ui/base/dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos Created 8 years, 5 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"
11 #include "chrome/browser/platform_util.h" 11 #include "chrome/browser/platform_util.h"
12 #include "chrome/browser/ui/chrome_select_file_policy.h"
12 #include "chrome/browser/ui/extensions/shell_window.h" 13 #include "chrome/browser/ui/extensions/shell_window.h"
13 #include "chrome/browser/ui/select_file_dialog.h" 14 #include "chrome/browser/ui/select_file_dialog.h"
14 #include "chrome/common/extensions/api/file_system.h" 15 #include "chrome/common/extensions/api/file_system.h"
15 #include "content/public/browser/child_process_security_policy.h" 16 #include "content/public/browser/child_process_security_policy.h"
16 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "webkit/fileapi/file_system_util.h" 20 #include "webkit/fileapi/file_system_util.h"
20 #include "webkit/fileapi/isolated_context.h" 21 #include "webkit/fileapi/isolated_context.h"
21 22
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // save or open. 111 // save or open.
111 class FileSystemPickerFunction::FilePicker : public SelectFileDialog::Listener { 112 class FileSystemPickerFunction::FilePicker : public SelectFileDialog::Listener {
112 public: 113 public:
113 FilePicker(FileSystemPickerFunction* function, 114 FilePicker(FileSystemPickerFunction* function,
114 content::WebContents* web_contents, 115 content::WebContents* web_contents,
115 const FilePath& suggested_path, 116 const FilePath& suggested_path,
116 bool for_save) 117 bool for_save)
117 : suggested_path_(suggested_path), 118 : suggested_path_(suggested_path),
118 for_save_(for_save), 119 for_save_(for_save),
119 function_(function) { 120 function_(function) {
120 select_file_dialog_ = SelectFileDialog::Create(this); 121 select_file_dialog_ = SelectFileDialog::Create(
122 this, new ChromeSelectFilePolicy(web_contents));
121 SelectFileDialog::FileTypeInfo file_type_info; 123 SelectFileDialog::FileTypeInfo file_type_info;
122 FilePath::StringType extension = suggested_path.Extension(); 124 FilePath::StringType extension = suggested_path.Extension();
123 if (!extension.empty()) { 125 if (!extension.empty()) {
124 extension.erase(extension.begin()); // drop the . 126 extension.erase(extension.begin()); // drop the .
125 file_type_info.extensions.resize(1); 127 file_type_info.extensions.resize(1);
126 file_type_info.extensions[0].push_back(extension); 128 file_type_info.extensions[0].push_back(extension);
127 } 129 }
128 file_type_info.include_all_files = true; 130 file_type_info.include_all_files = true;
129 gfx::NativeWindow owning_window = web_contents ? 131 gfx::NativeWindow owning_window = web_contents ?
130 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; 132 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL;
131 133
132 if (g_skip_picker_for_test) { 134 if (g_skip_picker_for_test) {
133 if (g_path_to_be_picked_for_test) { 135 if (g_path_to_be_picked_for_test) {
134 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 136 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
135 base::Bind(&FileSystemPickerFunction::FilePicker::FileSelected, 137 base::Bind(&FileSystemPickerFunction::FilePicker::FileSelected,
136 base::Unretained(this), *g_path_to_be_picked_for_test, 1, 138 base::Unretained(this), *g_path_to_be_picked_for_test, 1,
137 static_cast<void*>(NULL))); 139 static_cast<void*>(NULL)));
138 } else { 140 } else {
139 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 141 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
140 base::Bind( 142 base::Bind(
141 &FileSystemPickerFunction::FilePicker::FileSelectionCanceled, 143 &FileSystemPickerFunction::FilePicker::FileSelectionCanceled,
142 base::Unretained(this), static_cast<void*>(NULL))); 144 base::Unretained(this), static_cast<void*>(NULL)));
143 } 145 }
144 return; 146 return;
145 } 147 }
146 148
147 select_file_dialog_->SelectFile(for_save ? 149 select_file_dialog_->SelectFile(
148 SelectFileDialog::SELECT_SAVEAS_FILE : 150 for_save ?
149 SelectFileDialog::SELECT_OPEN_FILE, 151 SelectFileDialog::SELECT_SAVEAS_FILE :
150 string16(), 152 SelectFileDialog::SELECT_OPEN_FILE,
151 suggested_path, 153 string16(),
152 &file_type_info, 0, FILE_PATH_LITERAL(""), 154 suggested_path,
153 web_contents, owning_window, NULL); 155 &file_type_info, 0, FILE_PATH_LITERAL(""),
156 owning_window, NULL);
154 } 157 }
155 158
156 virtual ~FilePicker() {} 159 virtual ~FilePicker() {}
157 160
158 private: 161 private:
159 // SelectFileDialog::Listener implementation. 162 // SelectFileDialog::Listener implementation.
160 virtual void FileSelected(const FilePath& path, 163 virtual void FileSelected(const FilePath& path,
161 int index, 164 int index,
162 void* params) OVERRIDE { 165 void* params) OVERRIDE {
163 function_->FileSelected(path, for_save_); 166 function_->FileSelected(path, for_save_);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 file_system::ChooseFileOptions* options = params->options.get(); 314 file_system::ChooseFileOptions* options = params->options.get();
312 if (options) { 315 if (options) {
313 if (options->type.get() && *options->type == kSaveFileOption) 316 if (options->type.get() && *options->type == kSaveFileOption)
314 for_save = true; 317 for_save = true;
315 } 318 }
316 319
317 return ShowPicker(FilePath(), for_save); 320 return ShowPicker(FilePath(), for_save);
318 } 321 }
319 322
320 } // namespace extensions 323 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698