Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/download/save_package_file_picker.cc

Issue 4883003: Add FilePath::FinalExtension() to avoid double extensions (.tar.gz) for file selector (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, work around new Mac problem. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // switching save-as file formats, and remove the flag/switch. 135 // switching save-as file formats, and remove the flag/switch.
136 if (ShouldSaveAsMHTML()) { 136 if (ShouldSaveAsMHTML()) {
137 default_extension_copy = FILE_PATH_LITERAL("mhtml"); 137 default_extension_copy = FILE_PATH_LITERAL("mhtml");
138 suggested_path_copy = suggested_path_copy.ReplaceExtension( 138 suggested_path_copy = suggested_path_copy.ReplaceExtension(
139 default_extension_copy); 139 default_extension_copy);
140 } else if (can_save_as_complete_) { 140 } else if (can_save_as_complete_) {
141 // NOTE: this branch will never run on chromeos because ShouldSaveAsHTML() 141 // NOTE: this branch will never run on chromeos because ShouldSaveAsHTML()
142 // == can_save_as_complete_ on chromeos. 142 // == can_save_as_complete_ on chromeos.
143 bool add_extra_extension = false; 143 bool add_extra_extension = false;
144 base::FilePath::StringType extra_extension; 144 base::FilePath::StringType extra_extension;
145 if (!suggested_path_copy.Extension().empty() && 145 if (!suggested_path_copy.FinalExtension().empty() &&
146 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".htm")) && 146 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".htm")) &&
147 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".html"))) { 147 !suggested_path_copy.MatchesExtension(FILE_PATH_LITERAL(".html"))) {
148 add_extra_extension = true; 148 add_extra_extension = true;
149 extra_extension = suggested_path_copy.Extension().substr(1); 149 extra_extension = suggested_path_copy.FinalExtension().substr(1);
150 } 150 }
151 151
152 static const size_t kNumberExtensions = arraysize(kIndexToIDS) - 1; 152 static const size_t kNumberExtensions = arraysize(kIndexToIDS) - 1;
153 file_type_info.extensions.resize(kNumberExtensions); 153 file_type_info.extensions.resize(kNumberExtensions);
154 file_type_info.extension_description_overrides.resize(kNumberExtensions); 154 file_type_info.extension_description_overrides.resize(kNumberExtensions);
155 155
156 // Indices into kIndexToIDS are 1-based whereas indices into 156 // Indices into kIndexToIDS are 1-based whereas indices into
157 // file_type_info.extensions are 0-based. Hence the '-1's. 157 // file_type_info.extensions are 0-based. Hence the '-1's.
158 // If you switch these resize()/direct-assignment patterns to push_back(), 158 // If you switch these resize()/direct-assignment patterns to push_back(),
159 // then you risk breaking FileSelected()'s use of |index|. 159 // then you risk breaking FileSelected()'s use of |index|.
(...skipping 20 matching lines...) Expand all
180 if (add_extra_extension) { 180 if (add_extra_extension) {
181 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( 181 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back(
182 extra_extension); 182 extra_extension);
183 } 183 }
184 184
185 file_type_info.include_all_files = false; 185 file_type_info.include_all_files = false;
186 } else { 186 } else {
187 // The contents can not be saved as complete-HTML, so do not show the file 187 // The contents can not be saved as complete-HTML, so do not show the file
188 // filters. 188 // filters.
189 file_type_info.extensions.resize(1); 189 file_type_info.extensions.resize(1);
190 file_type_info.extensions[0].push_back(suggested_path_copy.Extension()); 190 file_type_info.extensions[0].push_back(
191 suggested_path_copy.FinalExtension());
191 192
192 if (!file_type_info.extensions[0][0].empty()) { 193 if (!file_type_info.extensions[0][0].empty()) {
193 // Drop the . 194 // Drop the .
194 file_type_info.extensions[0][0].erase(0, 1); 195 file_type_info.extensions[0][0].erase(0, 1);
195 } 196 }
196 197
197 file_type_info.include_all_files = true; 198 file_type_info.include_all_files = true;
198 file_type_index = 1; 199 file_type_index = 1;
199 } 200 }
200 201
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 279 }
279 #endif 280 #endif
280 281
281 callback_.Run(path_copy, save_type, 282 callback_.Run(path_copy, save_type,
282 base::Bind(&OnSavePackageDownloadCreated)); 283 base::Bind(&OnSavePackageDownloadCreated));
283 } 284 }
284 285
285 void SavePackageFilePicker::FileSelectionCanceled(void* unused_params) { 286 void SavePackageFilePicker::FileSelectionCanceled(void* unused_params) {
286 delete this; 287 delete this;
287 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698