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

Side by Side Diff: content/browser/download/save_package.cc

Issue 7300005: Move filename determination to net_util (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 9 years, 5 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 pure_file_name->clear(); 364 pure_file_name->clear();
365 return false; 365 return false;
366 } 366 }
367 367
368 // Generate name for saving resource. 368 // Generate name for saving resource.
369 bool SavePackage::GenerateFileName(const std::string& disposition, 369 bool SavePackage::GenerateFileName(const std::string& disposition,
370 const GURL& url, 370 const GURL& url,
371 bool need_html_ext, 371 bool need_html_ext,
372 FilePath::StringType* generated_name) { 372 FilePath::StringType* generated_name) {
373 // TODO(jungshik): Figure out the referrer charset when having one 373 // TODO(jungshik): Figure out the referrer charset when having one
374 // makes sense and pass it to GetSuggestedFilename. 374 // makes sense and pass it to GenerateFileName.
375 string16 suggested_name = 375 FilePath file_path = net::GenerateFileName(url, disposition, "", "", "",
376 net::GetSuggestedFilename(url, disposition, "", "", 376 ASCIIToUTF16(kDefaultSaveName));
377 ASCIIToUTF16(kDefaultSaveName));
378
379 // TODO(evan): this code is totally wrong -- we should just generate
380 // Unicode filenames and do all this encoding switching at the end.
381 // However, I'm just shuffling wrong code around, at least not adding
382 // to it.
383 #if defined(OS_WIN)
384 FilePath file_path = FilePath(suggested_name);
385 #else
386 FilePath file_path = FilePath(
387 base::SysWideToNativeMB(UTF16ToWide(suggested_name)));
388 #endif
389 377
390 DCHECK(!file_path.empty()); 378 DCHECK(!file_path.empty());
391 FilePath::StringType pure_file_name = 379 FilePath::StringType pure_file_name =
392 file_path.RemoveExtension().BaseName().value(); 380 file_path.RemoveExtension().BaseName().value();
393 FilePath::StringType file_name_ext = file_path.Extension(); 381 FilePath::StringType file_name_ext = file_path.Extension();
394 382
395 // If it is HTML resource, use ".htm{l,}" as its extension. 383 // If it is HTML resource, use ".htm{l,}" as its extension.
396 if (need_html_ext) { 384 if (need_html_ext) {
397 file_name_ext = FILE_PATH_LITERAL("."); 385 file_name_ext = FILE_PATH_LITERAL(".");
398 file_name_ext.append(kDefaultHtmlExtension); 386 file_name_ext.append(kDefaultHtmlExtension);
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1259
1272 content::GetContentClient()->browser()->ChooseSavePath( 1260 content::GetContentClient()->browser()->ChooseSavePath(
1273 AsWeakPtr(), suggested_path, can_save_as_complete); 1261 AsWeakPtr(), suggested_path, can_save_as_complete);
1274 } 1262 }
1275 1263
1276 // Called after the save file dialog box returns. 1264 // Called after the save file dialog box returns.
1277 void SavePackage::OnPathPicked(const FilePath& final_name, 1265 void SavePackage::OnPathPicked(const FilePath& final_name,
1278 SavePackageType type) { 1266 SavePackageType type) {
1279 // Ensure the filename is safe. 1267 // Ensure the filename is safe.
1280 saved_main_file_path_ = final_name; 1268 saved_main_file_path_ = final_name;
1281 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), 1269 // TODO(asanka): This call is going to block on IO and shouldn't be
1282 &saved_main_file_path_); 1270 // made from the UI thread.
rvargas (doing something else) 2011/07/26 22:25:41 Could you clarify (for me) what does this mean?. A
asanka 2011/07/28 20:04:38 This is documenting a pre-existing problem. net::
1271 net::GenerateSafeFileName(tab_contents()->contents_mime_type(),
1272 &saved_main_file_path_);
1283 1273
1284 saved_main_directory_path_ = saved_main_file_path_.DirName(); 1274 saved_main_directory_path_ = saved_main_file_path_.DirName();
1285 1275
1286 PrefService* prefs = tab_contents()->profile()->GetPrefs(); 1276 PrefService* prefs = tab_contents()->profile()->GetPrefs();
1287 StringPrefMember save_file_path; 1277 StringPrefMember save_file_path;
1288 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); 1278 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL);
1289 #if defined(OS_POSIX) 1279 #if defined(OS_POSIX)
1290 std::string path_string = saved_main_directory_path_.value(); 1280 std::string path_string = saved_main_directory_path_.value();
1291 #elif defined(OS_WIN) 1281 #elif defined(OS_WIN)
1292 std::string path_string = WideToUTF8(saved_main_directory_path_.value()); 1282 std::string path_string = WideToUTF8(saved_main_directory_path_.value());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { 1316 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) {
1327 // WebKit creates Document object when MIME type is application/xhtml+xml, 1317 // WebKit creates Document object when MIME type is application/xhtml+xml,
1328 // so we also support this MIME type. 1318 // so we also support this MIME type.
1329 return contents_mime_type == "text/html" || 1319 return contents_mime_type == "text/html" ||
1330 contents_mime_type == "text/xml" || 1320 contents_mime_type == "text/xml" ||
1331 contents_mime_type == "application/xhtml+xml" || 1321 contents_mime_type == "application/xhtml+xml" ||
1332 contents_mime_type == "text/plain" || 1322 contents_mime_type == "text/plain" ||
1333 contents_mime_type == "text/css" || 1323 contents_mime_type == "text/css" ||
1334 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); 1324 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str());
1335 } 1325 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | net/base/net_util.h » ('j') | net/base/net_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698