Commit d687b286 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

FileChooser: Send null FileChooserResult on canceling a file chooser dialog

instead of empty FileChooserResult.

Receivers of the message, Blink and Pepper, still assume the null
FileChooserResult and the empty FileChooserResult have same meaning.
However this CL makes it possible to fix crbug.com/2508.

This CL doesn't have user-visible behavior changes.

Bug: 2508
Change-Id: I14b17e68116d475d6fd49f4a965d8a6c49418b32
Reviewed-on: https://chromium-review.googlesource.com/c/1343815Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609863}
parent 64dd58ed
...@@ -611,7 +611,7 @@ class FileChooserImpl : public blink::mojom::FileChooser, ...@@ -611,7 +611,7 @@ class FileChooserImpl : public blink::mojom::FileChooser,
proxy_ = nullptr; proxy_ = nullptr;
if (!render_frame_host_) if (!render_frame_host_)
return; return;
std::move(callback_).Run(FileChooserResult::New()); std::move(callback_).Run(nullptr);
} }
private: private:
......
...@@ -47,20 +47,22 @@ class PepperFileChooserHost::CompletionHandler { ...@@ -47,20 +47,22 @@ class PepperFileChooserHost::CompletionHandler {
} }
void DidChooseFiles(blink::mojom::FileChooserResultPtr result) { void DidChooseFiles(blink::mojom::FileChooserResultPtr result) {
DCHECK(result);
if (host_.get()) { if (host_.get()) {
std::vector<blink::mojom::FileChooserFileInfoPtr> mojo_files =
std::move(result->files);
std::vector<PepperFileChooserHost::ChosenFileInfo> files; std::vector<PepperFileChooserHost::ChosenFileInfo> files;
for (size_t i = 0; i < mojo_files.size(); i++) { if (result) {
base::FilePath file_path = mojo_files[i]->get_native_file()->file_path; std::vector<blink::mojom::FileChooserFileInfoPtr> mojo_files =
// Drop files of which names can not be converted to Unicode. We std::move(result->files);
// can't expose such files in Flash. for (size_t i = 0; i < mojo_files.size(); i++) {
if (blink::FilePathToWebString(file_path).IsEmpty()) base::FilePath file_path =
continue; mojo_files[i]->get_native_file()->file_path;
files.push_back(PepperFileChooserHost::ChosenFileInfo( // Drop files of which names can not be converted to Unicode. We
file_path, // can't expose such files in Flash.
base::UTF16ToUTF8(mojo_files[i]->get_native_file()->display_name))); if (blink::FilePathToWebString(file_path).IsEmpty())
continue;
files.push_back(PepperFileChooserHost::ChosenFileInfo(
file_path, base::UTF16ToUTF8(
mojo_files[i]->get_native_file()->display_name)));
}
} }
host_->StoreChosenFiles(files); host_->StoreChosenFiles(files);
} }
......
...@@ -103,8 +103,11 @@ void FileChooser::EnumerateChosenDirectory() { ...@@ -103,8 +103,11 @@ void FileChooser::EnumerateChosenDirectory() {
} }
void FileChooser::DidChooseFiles(mojom::blink::FileChooserResultPtr result) { void FileChooser::DidChooseFiles(mojom::blink::FileChooserResultPtr result) {
DCHECK(result); // TODO(tkent): If |result| is nullptr, we should not clear the
FileChooserFileInfoList files = std::move(result->files); // already-selected files in <input type=file> like other browsers.
FileChooserFileInfoList files;
if (result)
files = std::move(result->files);
// FIXME: This is inelegant. We should not be looking at params_ here. // FIXME: This is inelegant. We should not be looking at params_ here.
if (params_->selected_files.size() == files.size()) { if (params_->selected_files.size() == files.size()) {
bool was_changed = false; bool was_changed = false;
...@@ -129,8 +132,10 @@ void FileChooser::DidChooseFiles(mojom::blink::FileChooserResultPtr result) { ...@@ -129,8 +132,10 @@ void FileChooser::DidChooseFiles(mojom::blink::FileChooserResultPtr result) {
} }
} }
if (client_) if (client_) {
client_->FilesChosen(std::move(files), result->base_directory); client_->FilesChosen(std::move(files),
result ? result->base_directory : base::FilePath());
}
DidCloseChooser(); DidCloseChooser();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment