diff --git a/shell/browser/web_dialog_helper.cc b/shell/browser/web_dialog_helper.cc index e959bd046ef5..0d3c84cc0ae1 100644 --- a/shell/browser/web_dialog_helper.cc +++ b/shell/browser/web_dialog_helper.cc @@ -128,7 +128,9 @@ class FileSelectHelper : public base::RefCounted, // listener is called from the directory enumerator. bool ready_to_call_listener = false; - if (!canceled) { + if (canceled) { + OnSelectionCancelled(); + } else { std::vector paths; if (result.Get("filePaths", &paths)) { // If we are uploading a folder we need to enumerate its contents @@ -153,10 +155,10 @@ class FileSelectHelper : public base::RefCounted, paths[0].DirName()); } } + // We should only call this if we have not cancelled the dialog + if (ready_to_call_listener) + OnFilesSelected(std::move(file_info), lister_base_dir_); } - - if (ready_to_call_listener) - OnFilesSelected(std::move(file_info), lister_base_dir_); } void OnSaveDialogDone(mate::Dictionary result) { @@ -164,15 +166,18 @@ class FileSelectHelper : public base::RefCounted, bool canceled = true; result.Get("canceled", &canceled); - if (!canceled) { + if (canceled) { + OnSelectionCancelled(); + } else { base::FilePath path; if (result.Get("filePath", &path)) { file_info.push_back(FileChooserFileInfo::NewNativeFile( blink::mojom::NativeFileInfo::New( path, path.BaseName().AsUTF16Unsafe()))); } + // We should only call this if we have not cancelled the dialog + OnFilesSelected(std::move(file_info), base::FilePath()); } - OnFilesSelected(std::move(file_info), base::FilePath()); } void OnFilesSelected(std::vector file_info, @@ -184,6 +189,14 @@ class FileSelectHelper : public base::RefCounted, render_frame_host_ = nullptr; } + void OnSelectionCancelled() { + if (listener_) { + listener_->FileSelectionCanceled(); + listener_.reset(); + } + render_frame_host_ = nullptr; + } + // content::WebContentsObserver: void RenderFrameHostChanged(content::RenderFrameHost* old_host, content::RenderFrameHost* new_host) override {