Chromium Code Reviews| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // Because this class returns notifications to the RenderViewHost, it is | 435 // Because this class returns notifications to the RenderViewHost, it is |
| 436 // difficult for callers to know how long to keep a reference to this | 436 // difficult for callers to know how long to keep a reference to this |
| 437 // instance. We AddRef() here to keep the instance alive after we return | 437 // instance. We AddRef() here to keep the instance alive after we return |
| 438 // to the caller, until the last callback is received from the file dialog. | 438 // to the caller, until the last callback is received from the file dialog. |
| 439 // At that point, we must call RunFileChooserEnd(). | 439 // At that point, we must call RunFileChooserEnd(). |
| 440 AddRef(); | 440 AddRef(); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void FileSelectHelper::GetFileTypesOnFileThread( | 443 void FileSelectHelper::GetFileTypesOnFileThread( |
| 444 scoped_ptr<FileChooserParams> params) { | 444 scoped_ptr<FileChooserParams> params) { |
| 445 select_file_types_ = GetFileTypesFromAcceptType(params->accept_types); | 445 select_file_types_ = GetFileTypesFromAcceptType(params->accept_types); |
|
Nathan Parker
2016/01/21 01:32:26
Do we know how often this contains multiple items?
asanka
2016/01/21 01:37:10
We don't have data for how often we get multiple f
Nathan Parker
2016/01/21 17:11:14
Yea to gauge the order of magnitude of how often t
| |
| 446 select_file_types_->support_drive = !params->need_local_path; | 446 select_file_types_->support_drive = !params->need_local_path; |
| 447 | 447 |
| 448 BrowserThread::PostTask( | 448 BrowserThread::PostTask( |
| 449 BrowserThread::UI, FROM_HERE, | 449 BrowserThread::UI, FROM_HERE, |
| 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) { | |
|
sky
2016/01/21 20:13:15
Isn't this the same as alternate_extensions = sele
asanka
2016/01/21 20:25:34
select_file_types_->extensions is a vector<vector<
| |
| 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 |