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/save_package_file_picker.h" | 5 #include "chrome/browser/download/save_package_file_picker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // switching save-as file formats, and remove the flag/switch. | 137 // switching save-as file formats, and remove the flag/switch. |
138 if (ShouldSaveAsMHTML()) { | 138 if (ShouldSaveAsMHTML()) { |
139 default_extension_copy = FILE_PATH_LITERAL("mhtml"); | 139 default_extension_copy = FILE_PATH_LITERAL("mhtml"); |
140 suggested_path_copy = suggested_path_copy.ReplaceExtension( | 140 suggested_path_copy = suggested_path_copy.ReplaceExtension( |
141 default_extension_copy); | 141 default_extension_copy); |
142 } else if (can_save_as_complete_) { | 142 } else if (can_save_as_complete_) { |
143 // NOTE: this branch will never run on chromeos because ShouldSaveAsHTML() | 143 // NOTE: this branch will never run on chromeos because ShouldSaveAsHTML() |
144 // == can_save_as_complete_ on chromeos. | 144 // == can_save_as_complete_ on chromeos. |
145 bool add_extra_extension = false; | 145 bool add_extra_extension = false; |
146 base::FilePath::StringType extra_extension; | 146 base::FilePath::StringType extra_extension; |
147 if (!suggested_path_copy.Extension().empty() && | 147 if (!suggested_path_copy.FinalExtension().empty() && |
148 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".htm")) && | 148 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".htm")) && |
149 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".html"))) { | 149 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".html"))) { |
150 add_extra_extension = true; | 150 add_extra_extension = true; |
151 extra_extension = suggested_path_copy.Extension().substr(1); | 151 extra_extension = suggested_path_copy.FinalExtension().substr(1); |
152 } | 152 } |
153 | 153 |
154 static const size_t kNumberExtensions = arraysize(kIndexToIDS) - 1; | 154 static const size_t kNumberExtensions = arraysize(kIndexToIDS) - 1; |
155 file_type_info.extensions.resize(kNumberExtensions); | 155 file_type_info.extensions.resize(kNumberExtensions); |
156 file_type_info.extension_description_overrides.resize(kNumberExtensions); | 156 file_type_info.extension_description_overrides.resize(kNumberExtensions); |
157 | 157 |
158 // Indices into kIndexToIDS are 1-based whereas indices into | 158 // Indices into kIndexToIDS are 1-based whereas indices into |
159 // file_type_info.extensions are 0-based. Hence the '-1's. | 159 // file_type_info.extensions are 0-based. Hence the '-1's. |
160 // If you switch these resize()/direct-assignment patterns to push_back(), | 160 // If you switch these resize()/direct-assignment patterns to push_back(), |
161 // then you risk breaking FileSelected()'s use of |index|. | 161 // then you risk breaking FileSelected()'s use of |index|. |
(...skipping 20 matching lines...) Expand all Loading... |
182 if (add_extra_extension) { | 182 if (add_extra_extension) { |
183 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( | 183 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( |
184 extra_extension); | 184 extra_extension); |
185 } | 185 } |
186 | 186 |
187 file_type_info.include_all_files = false; | 187 file_type_info.include_all_files = false; |
188 } else { | 188 } else { |
189 // The contents can not be saved as complete-HTML, so do not show the file | 189 // The contents can not be saved as complete-HTML, so do not show the file |
190 // filters. | 190 // filters. |
191 file_type_info.extensions.resize(1); | 191 file_type_info.extensions.resize(1); |
192 file_type_info.extensions[0].push_back(suggested_path_copy.Extension()); | 192 file_type_info.extensions[0].push_back( |
| 193 suggested_path_copy.FinalExtension()); |
193 | 194 |
194 if (!file_type_info.extensions[0][0].empty()) { | 195 if (!file_type_info.extensions[0][0].empty()) { |
195 // Drop the . | 196 // Drop the . |
196 file_type_info.extensions[0][0].erase(0, 1); | 197 file_type_info.extensions[0][0].erase(0, 1); |
197 } | 198 } |
198 | 199 |
199 file_type_info.include_all_files = true; | 200 file_type_info.include_all_files = true; |
200 file_type_index = 1; | 201 file_type_index = 1; |
201 } | 202 } |
202 | 203 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 281 } |
281 #endif | 282 #endif |
282 | 283 |
283 callback_.Run(path_copy, save_type, | 284 callback_.Run(path_copy, save_type, |
284 base::Bind(&OnSavePackageDownloadCreated)); | 285 base::Bind(&OnSavePackageDownloadCreated)); |
285 } | 286 } |
286 | 287 |
287 void SavePackageFilePicker::FileSelectionCanceled(void* unused_params) { | 288 void SavePackageFilePicker::FileSelectionCanceled(void* unused_params) { |
288 delete this; | 289 delete this; |
289 } | 290 } |
OLD | NEW |