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

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

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 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
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 "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 // HTML data. 1286 // HTML data.
1287 DoSavingProcess(); 1287 DoSavingProcess();
1288 } else { 1288 } else {
1289 // No savable frames and/or resources - treat it as user cancel. 1289 // No savable frames and/or resources - treat it as user cancel.
1290 Cancel(true); 1290 Cancel(true);
1291 } 1291 }
1292 } 1292 }
1293 1293
1294 base::FilePath SavePackage::GetSuggestedNameForSaveAs( 1294 base::FilePath SavePackage::GetSuggestedNameForSaveAs(
1295 bool can_save_as_complete, 1295 bool can_save_as_complete,
1296 const std::string& contents_mime_type, 1296 const std::string& contents_mime_type) {
1297 const std::string& accept_langs) {
1298 base::FilePath name_with_proper_ext = base::FilePath::FromUTF16Unsafe(title_); 1297 base::FilePath name_with_proper_ext = base::FilePath::FromUTF16Unsafe(title_);
1299 1298
1300 // If the page's title matches its URL, use the URL. Try to use the last path 1299 // If the page's title matches its URL, use the URL. Try to use the last path
1301 // component or if there is none, the domain as the file name. 1300 // component or if there is none, the domain as the file name.
1302 // Normally we want to base the filename on the page title, or if it doesn't 1301 // Normally we want to base the filename on the page title, or if it doesn't
1303 // exist, on the URL. It's not easy to tell if the page has no title, because 1302 // exist, on the URL. It's not easy to tell if the page has no title, because
1304 // if the page has no title, WebContents::GetTitle() will return the page's 1303 // if the page has no title, WebContents::GetTitle() will return the page's
1305 // URL (adjusted for display purposes). Therefore, we convert the "title" 1304 // URL (adjusted for display purposes). Therefore, we convert the "title"
1306 // back to a URL, and if it matches the original page URL, we know the page 1305 // back to a URL, and if it matches the original page URL, we know the page
1307 // had no title (or had a title equal to its URL, which is fine to treat 1306 // had no title (or had a title equal to its URL, which is fine to treat
1308 // similarly). 1307 // similarly).
1309 if (title_ == url_formatter::FormatUrl(page_url_, accept_langs)) { 1308 if (title_ == url_formatter::FormatUrl(page_url_)) {
1310 std::string url_path; 1309 std::string url_path;
1311 if (!page_url_.SchemeIs(url::kDataScheme)) { 1310 if (!page_url_.SchemeIs(url::kDataScheme)) {
1312 std::vector<std::string> url_parts = base::SplitString( 1311 std::vector<std::string> url_parts = base::SplitString(
1313 page_url_.path(), "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1312 page_url_.path(), "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1314 if (!url_parts.empty()) { 1313 if (!url_parts.empty()) {
1315 for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) { 1314 for (int i = static_cast<int>(url_parts.size()) - 1; i >= 0; --i) {
1316 url_path = url_parts[i]; 1315 url_path = url_parts[i];
1317 if (!url_path.empty()) 1316 if (!url_path.empty())
1318 break; 1317 break;
1319 } 1318 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 // before calling to it. 1398 // before calling to it.
1400 base::FilePath website_save_dir, download_save_dir; 1399 base::FilePath website_save_dir, download_save_dir;
1401 bool skip_dir_check = false; 1400 bool skip_dir_check = false;
1402 DCHECK(download_manager_); 1401 DCHECK(download_manager_);
1403 if (download_manager_->GetDelegate()) { 1402 if (download_manager_->GetDelegate()) {
1404 download_manager_->GetDelegate()->GetSaveDir( 1403 download_manager_->GetDelegate()->GetSaveDir(
1405 web_contents()->GetBrowserContext(), &website_save_dir, 1404 web_contents()->GetBrowserContext(), &website_save_dir,
1406 &download_save_dir, &skip_dir_check); 1405 &download_save_dir, &skip_dir_check);
1407 } 1406 }
1408 std::string mime_type = web_contents()->GetContentsMimeType(); 1407 std::string mime_type = web_contents()->GetContentsMimeType();
1409 std::string accept_languages =
1410 GetContentClient()->browser()->GetAcceptLangs(
1411 web_contents()->GetBrowserContext());
1412
1413 BrowserThread::PostTask( 1408 BrowserThread::PostTask(
1414 BrowserThread::FILE, FROM_HERE, 1409 BrowserThread::FILE, FROM_HERE,
1415 base::Bind(&SavePackage::CreateDirectoryOnFileThread, this, 1410 base::Bind(&SavePackage::CreateDirectoryOnFileThread, this,
1416 website_save_dir, download_save_dir, skip_dir_check, 1411 website_save_dir, download_save_dir, skip_dir_check, mime_type));
1417 mime_type, accept_languages));
1418 } 1412 }
1419 1413
1420 void SavePackage::CreateDirectoryOnFileThread( 1414 void SavePackage::CreateDirectoryOnFileThread(
1421 const base::FilePath& website_save_dir, 1415 const base::FilePath& website_save_dir,
1422 const base::FilePath& download_save_dir, 1416 const base::FilePath& download_save_dir,
1423 bool skip_dir_check, 1417 bool skip_dir_check,
1424 const std::string& mime_type, 1418 const std::string& mime_type) {
1425 const std::string& accept_langs) {
1426 base::FilePath save_dir; 1419 base::FilePath save_dir;
1427 // If the default html/websites save folder doesn't exist... 1420 // If the default html/websites save folder doesn't exist...
1428 // We skip the directory check for gdata directories on ChromeOS. 1421 // We skip the directory check for gdata directories on ChromeOS.
1429 if (!skip_dir_check && !base::DirectoryExists(website_save_dir)) { 1422 if (!skip_dir_check && !base::DirectoryExists(website_save_dir)) {
1430 // If the default download dir doesn't exist, create it. 1423 // If the default download dir doesn't exist, create it.
1431 if (!base::DirectoryExists(download_save_dir)) { 1424 if (!base::DirectoryExists(download_save_dir)) {
1432 bool res = base::CreateDirectory(download_save_dir); 1425 bool res = base::CreateDirectory(download_save_dir);
1433 DCHECK(res); 1426 DCHECK(res);
1434 } 1427 }
1435 save_dir = download_save_dir; 1428 save_dir = download_save_dir;
1436 } else { 1429 } else {
1437 // If it does exist, use the default save dir param. 1430 // If it does exist, use the default save dir param.
1438 save_dir = website_save_dir; 1431 save_dir = website_save_dir;
1439 } 1432 }
1440 1433
1441 bool can_save_as_complete = CanSaveAsComplete(mime_type); 1434 bool can_save_as_complete = CanSaveAsComplete(mime_type);
1442 base::FilePath suggested_filename = GetSuggestedNameForSaveAs( 1435 base::FilePath suggested_filename = GetSuggestedNameForSaveAs(
1443 can_save_as_complete, mime_type, accept_langs); 1436 can_save_as_complete, mime_type);
1444 base::FilePath::StringType pure_file_name = 1437 base::FilePath::StringType pure_file_name =
1445 suggested_filename.RemoveExtension().BaseName().value(); 1438 suggested_filename.RemoveExtension().BaseName().value();
1446 base::FilePath::StringType file_name_ext = suggested_filename.Extension(); 1439 base::FilePath::StringType file_name_ext = suggested_filename.Extension();
1447 1440
1448 // Need to make sure the suggested file name is not too long. 1441 // Need to make sure the suggested file name is not too long.
1449 uint32_t max_path = GetMaxPathLengthForDirectory(save_dir); 1442 uint32_t max_path = GetMaxPathLengthForDirectory(save_dir);
1450 1443
1451 if (GetSafePureFileName(save_dir, file_name_ext, max_path, &pure_file_name)) { 1444 if (GetSafePureFileName(save_dir, file_name_ext, max_path, &pure_file_name)) {
1452 save_dir = save_dir.Append(pure_file_name + file_name_ext); 1445 save_dir = save_dir.Append(pure_file_name + file_name_ext);
1453 } else { 1446 } else {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 1519
1527 void SavePackage::FinalizeDownloadEntry() { 1520 void SavePackage::FinalizeDownloadEntry() {
1528 DCHECK(download_); 1521 DCHECK(download_);
1529 DCHECK(download_manager_); 1522 DCHECK(download_manager_);
1530 1523
1531 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1524 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1532 StopObservation(); 1525 StopObservation();
1533 } 1526 }
1534 1527
1535 } // namespace content 1528 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_package.h ('k') | content/browser/download/save_package_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698