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/debugger/devtools_file_helper.h" | 5 #include "chrome/browser/debugger/devtools_file_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/md5.h" | 11 #include "base/md5.h" |
11 #include "base/value_conversions.h" | 12 #include "base/value_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/download/download_prefs.h" | 14 #include "chrome/browser/download/download_prefs.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/chrome_select_file_policy.h" |
17 #include "chrome/browser/ui/select_file_dialog.h" | 19 #include "chrome/browser/ui/select_file_dialog.h" |
18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
19 | 21 |
20 using content::BrowserThread; | 22 using content::BrowserThread; |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 base::LazyInstance<FilePath>::Leaky | 26 base::LazyInstance<FilePath>::Leaky |
25 g_last_save_path = LAZY_INSTANCE_INITIALIZER; | 27 g_last_save_path = LAZY_INSTANCE_INITIALIZER; |
26 | 28 |
27 } // namespace | 29 } // namespace |
28 | 30 |
29 class DevToolsFileHelper::SaveAsDialog : public SelectFileDialog::Listener, | 31 class DevToolsFileHelper::SaveAsDialog : public SelectFileDialog::Listener, |
30 public base::RefCounted<SaveAsDialog> { | 32 public base::RefCounted<SaveAsDialog> { |
31 public: | 33 public: |
32 explicit SaveAsDialog(DevToolsFileHelper* helper) | 34 explicit SaveAsDialog(DevToolsFileHelper* helper) |
33 : helper_(helper) { | 35 : helper_(helper) { |
34 select_file_dialog_ = SelectFileDialog::Create(this); | 36 select_file_dialog_ = SelectFileDialog::Create( |
| 37 this, new ChromeSelectFilePolicy(NULL)); |
35 } | 38 } |
36 | 39 |
37 void ResetHelper() { | 40 void ResetHelper() { |
38 helper_ = NULL; | 41 helper_ = NULL; |
39 } | 42 } |
40 | 43 |
41 void Show(const std::string& url, | 44 void Show(const std::string& url, |
42 const FilePath& initial_path, | 45 const FilePath& initial_path, |
43 const std::string& content) { | 46 const std::string& content) { |
44 AddRef(); // Balanced in the three listener outcomes. | 47 AddRef(); // Balanced in the three listener outcomes. |
45 | 48 |
46 url_ = url; | 49 url_ = url; |
47 content_ = content; | 50 content_ = content; |
48 | 51 |
49 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 52 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, |
50 string16(), | 53 string16(), |
51 initial_path, | 54 initial_path, |
52 NULL, | 55 NULL, |
53 0, | 56 0, |
54 FILE_PATH_LITERAL(""), | 57 FILE_PATH_LITERAL(""), |
55 NULL, | 58 NULL, |
56 NULL, | |
57 NULL); | 59 NULL); |
58 } | 60 } |
59 | 61 |
60 // SelectFileDialog::Listener implementation. | 62 // SelectFileDialog::Listener implementation. |
61 virtual void FileSelected(const FilePath& path, | 63 virtual void FileSelected(const FilePath& path, |
62 int index, void* params) { | 64 int index, void* params) { |
63 if (helper_) | 65 if (helper_) |
64 helper_->FileSelected(url_, path, content_); | 66 helper_->FileSelected(url_, path, content_); |
65 Release(); // Balanced in ::Show. | 67 Release(); // Balanced in ::Show. |
66 } | 68 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 files_map->SetWithoutPathExpansion(base::MD5String(url), | 183 files_map->SetWithoutPathExpansion(base::MD5String(url), |
182 base::CreateFilePathValue(path)); | 184 base::CreateFilePathValue(path)); |
183 delegate_->FileSavedAs(url); | 185 delegate_->FileSavedAs(url); |
184 | 186 |
185 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
186 BrowserThread::FILE, FROM_HERE, | 188 BrowserThread::FILE, FROM_HERE, |
187 base::Bind(&DevToolsFileHelper::WriteFile, | 189 base::Bind(&DevToolsFileHelper::WriteFile, |
188 path, | 190 path, |
189 content)); | 191 content)); |
190 } | 192 } |
OLD | NEW |