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/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 base::Bind(&FileSelectHelper::GetSanitizedFilenameOnUIThread, this, | 450 base::Bind(&FileSelectHelper::GetSanitizedFilenameOnUIThread, this, |
451 base::Passed(¶ms))); | 451 base::Passed(¶ms))); |
452 } | 452 } |
453 | 453 |
454 void FileSelectHelper::GetSanitizedFilenameOnUIThread( | 454 void FileSelectHelper::GetSanitizedFilenameOnUIThread( |
455 scoped_ptr<FileChooserParams> params) { | 455 scoped_ptr<FileChooserParams> params) { |
456 base::FilePath default_file_path = profile_->last_selected_directory().Append( | 456 base::FilePath default_file_path = profile_->last_selected_directory().Append( |
457 GetSanitizedFileName(params->default_file_name)); | 457 GetSanitizedFileName(params->default_file_name)); |
458 | 458 |
459 #if defined(FULL_SAFE_BROWSING) | 459 #if defined(FULL_SAFE_BROWSING) |
| 460 std::vector<base::FilePath::StringType> alternate_extensions; |
| 461 if (select_file_types_) { |
| 462 for (const auto& extensions : select_file_types_->extensions) { |
| 463 alternate_extensions.insert(alternate_extensions.end(), |
| 464 extensions.begin(), extensions.end()); |
| 465 } |
| 466 } |
| 467 |
460 // Note that FileChooserParams::requestor is not considered a trusted field | 468 // Note that FileChooserParams::requestor is not considered a trusted field |
461 // since it's provided by the renderer and not validated browserside. | 469 // since it's provided by the renderer and not validated browserside. |
462 if (params->mode == FileChooserParams::Save && | 470 if (params->mode == FileChooserParams::Save && |
463 !params->default_file_name.empty()) { | 471 (!params->default_file_name.empty() || !alternate_extensions.empty())) { |
464 GURL requestor = params->requestor; | 472 GURL requestor = params->requestor; |
465 safe_browsing::CheckUnverifiedDownloadPolicy( | 473 safe_browsing::CheckUnverifiedDownloadPolicy( |
466 requestor, default_file_path, | 474 requestor, default_file_path, alternate_extensions, |
467 base::Bind(&FileSelectHelper::ApplyUnverifiedDownloadPolicy, this, | 475 base::Bind(&FileSelectHelper::ApplyUnverifiedDownloadPolicy, this, |
468 default_file_path, base::Passed(¶ms))); | 476 default_file_path, base::Passed(¶ms))); |
469 return; | 477 return; |
470 } | 478 } |
471 #endif | 479 #endif |
472 | 480 |
473 RunFileChooserOnUIThread(default_file_path, std::move(params)); | 481 RunFileChooserOnUIThread(default_file_path, std::move(params)); |
474 } | 482 } |
475 | 483 |
476 #if defined(FULL_SAFE_BROWSING) | 484 #if defined(FULL_SAFE_BROWSING) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 635 |
628 // static | 636 // static |
629 base::FilePath FileSelectHelper::GetSanitizedFileName( | 637 base::FilePath FileSelectHelper::GetSanitizedFileName( |
630 const base::FilePath& suggested_filename) { | 638 const base::FilePath& suggested_filename) { |
631 if (suggested_filename.empty()) | 639 if (suggested_filename.empty()) |
632 return base::FilePath(); | 640 return base::FilePath(); |
633 return net::GenerateFileName( | 641 return net::GenerateFileName( |
634 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), | 642 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), |
635 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 643 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
636 } | 644 } |
OLD | NEW |