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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/md5.h" | 13 #include "base/md5.h" |
14 #include "base/value_conversions.h" | 14 #include "base/value_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/download/download_prefs.h" | 16 #include "chrome/browser/download/download_prefs.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/chrome_select_file_policy.h" | 20 #include "chrome/browser/ui/chrome_select_file_policy.h" |
21 #include "chrome/browser/ui/select_file_dialog.h" | |
22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
| 24 #include "ui/base/dialogs/select_file_dialog.h" |
25 | 25 |
26 using content::BrowserContext; | 26 using content::BrowserContext; |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
28 using content::DownloadManager; | 28 using content::DownloadManager; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 base::LazyInstance<FilePath>::Leaky | 32 base::LazyInstance<FilePath>::Leaky |
33 g_last_save_path = LAZY_INSTANCE_INITIALIZER; | 33 g_last_save_path = LAZY_INSTANCE_INITIALIZER; |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 class DevToolsFileHelper::SaveAsDialog : public SelectFileDialog::Listener, | 37 class DevToolsFileHelper::SaveAsDialog : public ui::SelectFileDialog::Listener, |
38 public base::RefCounted<SaveAsDialog> { | 38 public base::RefCounted<SaveAsDialog> { |
39 public: | 39 public: |
40 explicit SaveAsDialog(DevToolsFileHelper* helper) | 40 explicit SaveAsDialog(DevToolsFileHelper* helper) |
41 : helper_(helper) { | 41 : helper_(helper) { |
42 select_file_dialog_ = SelectFileDialog::Create( | 42 select_file_dialog_ = ui::SelectFileDialog::Create( |
43 this, new ChromeSelectFilePolicy(NULL)); | 43 this, new ChromeSelectFilePolicy(NULL)); |
44 } | 44 } |
45 | 45 |
46 void ResetHelper() { | 46 void ResetHelper() { |
47 helper_ = NULL; | 47 helper_ = NULL; |
48 } | 48 } |
49 | 49 |
50 void Show(const std::string& url, | 50 void Show(const std::string& url, |
51 const FilePath& initial_path, | 51 const FilePath& initial_path, |
52 const std::string& content) { | 52 const std::string& content) { |
53 AddRef(); // Balanced in the three listener outcomes. | 53 AddRef(); // Balanced in the three listener outcomes. |
54 | 54 |
55 url_ = url; | 55 url_ = url; |
56 content_ = content; | 56 content_ = content; |
57 | 57 |
58 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 58 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
59 string16(), | 59 string16(), |
60 initial_path, | 60 initial_path, |
61 NULL, | 61 NULL, |
62 0, | 62 0, |
63 FILE_PATH_LITERAL(""), | 63 FILE_PATH_LITERAL(""), |
64 NULL, | 64 NULL, |
65 NULL); | 65 NULL); |
66 } | 66 } |
67 | 67 |
68 // SelectFileDialog::Listener implementation. | 68 // ui::SelectFileDialog::Listener implementation. |
69 virtual void FileSelected(const FilePath& path, | 69 virtual void FileSelected(const FilePath& path, |
70 int index, void* params) { | 70 int index, void* params) { |
71 if (helper_) | 71 if (helper_) |
72 helper_->FileSelected(url_, path, content_); | 72 helper_->FileSelected(url_, path, content_); |
73 Release(); // Balanced in ::Show. | 73 Release(); // Balanced in ::Show. |
74 } | 74 } |
75 | 75 |
76 virtual void MultiFilesSelected( | 76 virtual void MultiFilesSelected( |
77 const std::vector<FilePath>& files, void* params) { | 77 const std::vector<FilePath>& files, void* params) { |
78 Release(); // Balanced in ::Show. | 78 Release(); // Balanced in ::Show. |
79 NOTREACHED() << "Should not be able to select multiple files"; | 79 NOTREACHED() << "Should not be able to select multiple files"; |
80 } | 80 } |
81 | 81 |
82 virtual void FileSelectionCanceled(void* params) { | 82 virtual void FileSelectionCanceled(void* params) { |
83 Release(); // Balanced in ::Show. | 83 Release(); // Balanced in ::Show. |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 friend class base::RefCounted<SaveAsDialog>; | 87 friend class base::RefCounted<SaveAsDialog>; |
88 virtual ~SaveAsDialog() {} | 88 virtual ~SaveAsDialog() {} |
89 | 89 |
90 scoped_refptr<SelectFileDialog> select_file_dialog_; | 90 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
91 std::string url_; | 91 std::string url_; |
92 std::string content_; | 92 std::string content_; |
93 DevToolsFileHelper* helper_; | 93 DevToolsFileHelper* helper_; |
94 }; | 94 }; |
95 | 95 |
96 // static | 96 // static |
97 void DevToolsFileHelper::WriteFile(const FilePath& path, | 97 void DevToolsFileHelper::WriteFile(const FilePath& path, |
98 const std::string& content) { | 98 const std::string& content) { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
100 DCHECK(!path.empty()); | 100 DCHECK(!path.empty()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 files_map->SetWithoutPathExpansion(base::MD5String(url), | 190 files_map->SetWithoutPathExpansion(base::MD5String(url), |
191 base::CreateFilePathValue(path)); | 191 base::CreateFilePathValue(path)); |
192 delegate_->FileSavedAs(url); | 192 delegate_->FileSavedAs(url); |
193 | 193 |
194 BrowserThread::PostTask( | 194 BrowserThread::PostTask( |
195 BrowserThread::FILE, FROM_HERE, | 195 BrowserThread::FILE, FROM_HERE, |
196 base::Bind(&DevToolsFileHelper::WriteFile, | 196 base::Bind(&DevToolsFileHelper::WriteFile, |
197 path, | 197 path, |
198 content)); | 198 content)); |
199 } | 199 } |
OLD | NEW |