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/download/download_file_picker.h" | 5 #include "chrome/browser/download/download_file_picker.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
9 #include "chrome/browser/platform_util.h" | 9 #include "chrome/browser/platform_util.h" |
| 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
10 #include "content/public/browser/download_item.h" | 11 #include "content/public/browser/download_item.h" |
11 #include "content/public/browser/download_manager.h" | 12 #include "content/public/browser/download_manager.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 | 16 |
16 using content::DownloadItem; | 17 using content::DownloadItem; |
17 using content::DownloadManager; | 18 using content::DownloadManager; |
18 using content::WebContents; | 19 using content::WebContents; |
19 | 20 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { | 58 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { |
58 } | 59 } |
59 | 60 |
60 void DownloadFilePicker::Init(DownloadManager* download_manager, | 61 void DownloadFilePicker::Init(DownloadManager* download_manager, |
61 DownloadItem* item) { | 62 DownloadItem* item) { |
62 download_manager_ = download_manager; | 63 download_manager_ = download_manager; |
63 download_id_ = item->GetId(); | 64 download_id_ = item->GetId(); |
64 InitSuggestedPath(item); | 65 InitSuggestedPath(item); |
65 | 66 |
66 DCHECK(download_manager_); | 67 DCHECK(download_manager_); |
67 select_file_dialog_ = SelectFileDialog::Create(this); | 68 WebContents* web_contents = item->GetWebContents(); |
| 69 select_file_dialog_ = SelectFileDialog::Create( |
| 70 this, new ChromeSelectFilePolicy(web_contents)); |
68 SelectFileDialog::FileTypeInfo file_type_info; | 71 SelectFileDialog::FileTypeInfo file_type_info; |
69 FilePath::StringType extension = suggested_path_.Extension(); | 72 FilePath::StringType extension = suggested_path_.Extension(); |
70 if (!extension.empty()) { | 73 if (!extension.empty()) { |
71 extension.erase(extension.begin()); // drop the . | 74 extension.erase(extension.begin()); // drop the . |
72 file_type_info.extensions.resize(1); | 75 file_type_info.extensions.resize(1); |
73 file_type_info.extensions[0].push_back(extension); | 76 file_type_info.extensions[0].push_back(extension); |
74 } | 77 } |
75 file_type_info.include_all_files = true; | 78 file_type_info.include_all_files = true; |
76 WebContents* web_contents = item->GetWebContents(); | |
77 gfx::NativeWindow owning_window = web_contents ? | 79 gfx::NativeWindow owning_window = web_contents ? |
78 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; | 80 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; |
79 | 81 |
80 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 82 select_file_dialog_->SelectFile( |
81 string16(), | 83 SelectFileDialog::SELECT_SAVEAS_FILE, |
82 suggested_path_, | 84 string16(), |
83 &file_type_info, 0, FILE_PATH_LITERAL(""), | 85 suggested_path_, |
84 web_contents, owning_window, NULL); | 86 &file_type_info, |
| 87 0, |
| 88 FILE_PATH_LITERAL(""), |
| 89 owning_window, |
| 90 NULL); |
85 } | 91 } |
86 | 92 |
87 DownloadFilePicker::~DownloadFilePicker() { | 93 DownloadFilePicker::~DownloadFilePicker() { |
88 } | 94 } |
89 | 95 |
90 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item) { | 96 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item) { |
91 set_suggested_path(item->GetTargetFilePath()); | 97 set_suggested_path(item->GetTargetFilePath()); |
92 } | 98 } |
93 | 99 |
94 void DownloadFilePicker::RecordFileSelected(const FilePath& path) { | 100 void DownloadFilePicker::RecordFileSelected(const FilePath& path) { |
(...skipping 10 matching lines...) Expand all Loading... |
105 download_manager_->FileSelected(path, download_id_); | 111 download_manager_->FileSelected(path, download_id_); |
106 delete this; | 112 delete this; |
107 } | 113 } |
108 | 114 |
109 void DownloadFilePicker::FileSelectionCanceled(void* params) { | 115 void DownloadFilePicker::FileSelectionCanceled(void* params) { |
110 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); | 116 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); |
111 if (download_manager_) | 117 if (download_manager_) |
112 download_manager_->FileSelectionCanceled(download_id_); | 118 download_manager_->FileSelectionCanceled(download_id_); |
113 delete this; | 119 delete this; |
114 } | 120 } |
OLD | NEW |