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