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

Unified Diff: chrome/browser/file_select_helper.cc

Issue 1410423003: [SafeBrowsing] Conditionalize unverified download blocking on whitelist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flash-download-block
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/safe_browsing/unverified_download_policy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/file_select_helper.cc
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc
index f1d15f4f3cf47f9bdeea45ea23a41f62e9158298..6fa623fb86460faf6905b3f8bcb0edf63eb50ee7 100644
--- a/chrome/browser/file_select_helper.cc
+++ b/chrome/browser/file_select_helper.cc
@@ -387,7 +387,9 @@ void FileSelectHelper::RunFileChooser(content::WebContents* tab,
// FileSelectHelper will keep itself alive until it sends the result message.
scoped_refptr<FileSelectHelper> file_select_helper(
new FileSelectHelper(profile));
- file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params);
+ file_select_helper->RunFileChooser(
+ tab->GetRenderViewHost(), tab,
+ make_scoped_ptr(new content::FileChooserParams(params)));
}
// static
@@ -404,14 +406,14 @@ void FileSelectHelper::EnumerateDirectory(content::WebContents* tab,
void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host,
content::WebContents* web_contents,
- const FileChooserParams& params) {
+ scoped_ptr<FileChooserParams> params) {
DCHECK(!render_view_host_);
DCHECK(!web_contents_);
- DCHECK(params.default_file_name.empty() ||
- params.mode == FileChooserParams::Save)
+ DCHECK(params->default_file_name.empty() ||
+ params->mode == FileChooserParams::Save)
<< "The default_file_name parameter should only be specified for Save "
"file choosers";
- DCHECK(params.default_file_name == params.default_file_name.BaseName())
+ DCHECK(params->default_file_name == params->default_file_name.BaseName())
<< "The default_file_name parameter should not contain path separators";
render_view_host_ = render_view_host;
@@ -424,7 +426,8 @@ void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host,
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&FileSelectHelper::RunFileChooserOnFileThread, this, params));
+ base::Bind(&FileSelectHelper::GetFileTypesOnFileThread, this,
+ base::Passed(&params)));
// Because this class returns notifications to the RenderViewHost, it is
// difficult for callers to know how long to keep a reference to this
@@ -434,44 +437,72 @@ void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host,
AddRef();
}
-void FileSelectHelper::RunFileChooserOnFileThread(
- const FileChooserParams& params) {
- select_file_types_ = GetFileTypesFromAcceptType(params.accept_types);
- select_file_types_->support_drive = !params.need_local_path;
+void FileSelectHelper::GetFileTypesOnFileThread(
+ scoped_ptr<FileChooserParams> params) {
+ select_file_types_ = GetFileTypesFromAcceptType(params->accept_types);
+ select_file_types_->support_drive = !params->need_local_path;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&FileSelectHelper::RunFileChooserOnUIThread, this, params));
+ base::Bind(&FileSelectHelper::GetSanitizedFilenameOnUIThread, this,
+ base::Passed(&params)));
}
-void FileSelectHelper::RunFileChooserOnUIThread(
- const FileChooserParams& params) {
- if (!render_view_host_ || !web_contents_ || !IsValidProfile(profile_)) {
- // If the renderer was destroyed before we started, just cancel the
- // operation.
- RunFileChooserEnd();
+void FileSelectHelper::GetSanitizedFilenameOnUIThread(
+ scoped_ptr<FileChooserParams> params) {
+ base::FilePath default_file_path = profile_->last_selected_directory().Append(
+ GetSanitizedFileName(params->default_file_name));
+
+#if defined(FULL_SAFE_BROWSING)
+ // Note that FileChooserParams::requestor is not considered a trusted field
+ // since it's provided by the renderer and not validated browserside.
+ if (params->mode == FileChooserParams::Save &&
+ !params->default_file_name.empty()) {
+ GURL requestor = params->requestor;
+ safe_browsing::CheckUnverifiedDownloadPolicy(
+ requestor, default_file_path,
+ base::Bind(&FileSelectHelper::ApplyUnverifiedDownloadPolicy, this,
+ default_file_path, base::Passed(&params)));
return;
}
+#endif
- base::FilePath default_file_path = profile_->last_selected_directory().Append(
- GetSanitizedFileName(params.default_file_name));
+ RunFileChooserOnUIThread(default_file_path, params.Pass());
+}
#if defined(FULL_SAFE_BROWSING)
- if (params.mode == FileChooserParams::Save &&
- !params.default_file_name.empty() &&
- !safe_browsing::IsUnverifiedDownloadAllowed(default_file_path)) {
+void FileSelectHelper::ApplyUnverifiedDownloadPolicy(
+ const base::FilePath& default_path,
+ scoped_ptr<FileChooserParams> params,
+ safe_browsing::UnverifiedDownloadPolicy policy) {
+ DCHECK(params);
+ if (policy == safe_browsing::UnverifiedDownloadPolicy::DISALLOWED) {
NotifyRenderViewHostAndEnd(std::vector<ui::SelectedFileInfo>());
return;
}
+
+ RunFileChooserOnUIThread(default_path, params.Pass());
+}
#endif
+void FileSelectHelper::RunFileChooserOnUIThread(
+ const base::FilePath& default_file_path,
+ scoped_ptr<FileChooserParams> params) {
+ DCHECK(params);
+ if (!render_view_host_ || !web_contents_ || !IsValidProfile(profile_)) {
+ // If the renderer was destroyed before we started, just cancel the
+ // operation.
+ RunFileChooserEnd();
+ return;
+ }
+
select_file_dialog_ = ui::SelectFileDialog::Create(
this, new ChromeSelectFilePolicy(web_contents_));
if (!select_file_dialog_.get())
return;
- dialog_mode_ = params.mode;
- switch (params.mode) {
+ dialog_mode_ = params->mode;
+ switch (params->mode) {
case FileChooserParams::Open:
dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE;
break;
@@ -496,11 +527,11 @@ void FileSelectHelper::RunFileChooserOnUIThread(
#if defined(OS_ANDROID)
// Android needs the original MIME types and an additional capture value.
std::pair<std::vector<base::string16>, bool> accept_types =
- std::make_pair(params.accept_types, params.capture);
+ std::make_pair(params->accept_types, params->capture);
#endif
select_file_dialog_->SelectFile(
- dialog_type_, params.title, default_file_path, select_file_types_.get(),
+ dialog_type_, params->title, default_file_path, select_file_types_.get(),
select_file_types_.get() && !select_file_types_->extensions.empty()
? 1
: 0, // 1-based index of default extension to show.
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/safe_browsing/unverified_download_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698