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 "chrome/browser/ui/chrome_select_file_policy.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const DownloadPrefs* prefs = | 62 const DownloadPrefs* prefs = |
63 DownloadPrefs::FromBrowserContext(item->GetBrowserContext()); | 63 DownloadPrefs::FromBrowserContext(item->GetBrowserContext()); |
64 DCHECK(prefs); | 64 DCHECK(prefs); |
65 // Only record UMA if we aren't prompting the user for all downloads. | 65 // Only record UMA if we aren't prompting the user for all downloads. |
66 should_record_file_picker_result_ = !prefs->PromptForDownload(); | 66 should_record_file_picker_result_ = !prefs->PromptForDownload(); |
67 | 67 |
68 WebContents* web_contents = item->GetWebContents(); | 68 WebContents* web_contents = item->GetWebContents(); |
69 select_file_dialog_ = ui::SelectFileDialog::Create( | 69 select_file_dialog_ = ui::SelectFileDialog::Create( |
70 this, new ChromeSelectFilePolicy(web_contents)); | 70 this, new ChromeSelectFilePolicy(web_contents)); |
71 ui::SelectFileDialog::FileTypeInfo file_type_info; | 71 ui::SelectFileDialog::FileTypeInfo file_type_info; |
72 base::FilePath::StringType extension = suggested_path_.Extension(); | 72 // Platform file pickers, notably on Mac and Windows, tend to break |
| 73 // with double extensions like .tar.gz, so only pass in normal ones. |
| 74 base::FilePath::StringType extension = suggested_path_.FinalExtension(); |
73 if (!extension.empty()) { | 75 if (!extension.empty()) { |
74 extension.erase(extension.begin()); // drop the . | 76 extension.erase(extension.begin()); // drop the . |
75 file_type_info.extensions.resize(1); | 77 file_type_info.extensions.resize(1); |
76 file_type_info.extensions[0].push_back(extension); | 78 file_type_info.extensions[0].push_back(extension); |
77 } | 79 } |
78 file_type_info.include_all_files = true; | 80 file_type_info.include_all_files = true; |
79 file_type_info.support_drive = true; | 81 file_type_info.support_drive = true; |
80 gfx::NativeWindow owning_window = web_contents ? | 82 gfx::NativeWindow owning_window = web_contents ? |
81 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()) : | 83 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()) : |
82 NULL; | 84 NULL; |
(...skipping 30 matching lines...) Expand all Loading... |
113 // Deletes |this| | 115 // Deletes |this| |
114 } | 116 } |
115 | 117 |
116 // static | 118 // static |
117 void DownloadFilePicker::ShowFilePicker(DownloadItem* item, | 119 void DownloadFilePicker::ShowFilePicker(DownloadItem* item, |
118 const base::FilePath& suggested_path, | 120 const base::FilePath& suggested_path, |
119 const FileSelectedCallback& callback) { | 121 const FileSelectedCallback& callback) { |
120 new DownloadFilePicker(item, suggested_path, callback); | 122 new DownloadFilePicker(item, suggested_path, callback); |
121 // DownloadFilePicker deletes itself. | 123 // DownloadFilePicker deletes itself. |
122 } | 124 } |
OLD | NEW |