2015-11-17 19:20:13 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/file_dialog_manager.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "include/cef_dialog_handler.h"
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2018-10-24 22:37:39 +02:00
|
|
|
#include "content/public/browser/file_select_listener.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "net/base/directory_lister.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CefFileDialogCallbackImpl : public CefFileDialogCallback {
|
|
|
|
public:
|
2020-03-04 01:29:39 +01:00
|
|
|
using CallbackType = CefFileDialogRunner::RunFileChooserCallback;
|
|
|
|
|
|
|
|
explicit CefFileDialogCallbackImpl(CallbackType callback)
|
|
|
|
: callback_(std::move(callback)) {}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
~CefFileDialogCallbackImpl() override {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
CancelNow(std::move(callback_));
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
2020-03-04 01:29:39 +01:00
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(&CefFileDialogCallbackImpl::CancelNow,
|
|
|
|
std::move(callback_)));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Continue(int selected_accept_filter,
|
|
|
|
const std::vector<CefString>& file_paths) override {
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
std::vector<base::FilePath> vec;
|
|
|
|
if (!file_paths.empty()) {
|
|
|
|
std::vector<CefString>::const_iterator it = file_paths.begin();
|
|
|
|
for (; it != file_paths.end(); ++it)
|
|
|
|
vec.push_back(base::FilePath(*it));
|
|
|
|
}
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback_).Run(selected_accept_filter, vec);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-03-04 01:29:39 +01:00
|
|
|
base::BindOnce(&CefFileDialogCallbackImpl::Continue, this,
|
|
|
|
selected_accept_filter, file_paths));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() override {
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
if (!callback_.is_null()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
CancelNow(std::move(callback_));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2020-03-04 01:29:39 +01:00
|
|
|
base::BindOnce(&CefFileDialogCallbackImpl::Cancel, this));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
CallbackType Disconnect() WARN_UNUSED_RESULT { return std::move(callback_); }
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
private:
|
2020-03-04 01:29:39 +01:00
|
|
|
static void CancelNow(CallbackType callback) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
std::vector<base::FilePath> file_paths;
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback).Run(0, file_paths);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
CallbackType callback_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefFileDialogCallbackImpl);
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void RunFileDialogDismissed(CefRefPtr<CefRunFileDialogCallback> callback,
|
|
|
|
int selected_accept_filter,
|
|
|
|
const std::vector<base::FilePath>& file_paths) {
|
2015-11-17 19:20:13 +01:00
|
|
|
std::vector<CefString> paths;
|
|
|
|
if (file_paths.size() > 0) {
|
|
|
|
for (size_t i = 0; i < file_paths.size(); ++i)
|
|
|
|
paths.push_back(file_paths[i].value());
|
|
|
|
}
|
|
|
|
callback->OnFileDialogDismissed(selected_accept_filter, paths);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class UploadFolderHelper
|
|
|
|
: public net::DirectoryLister::DirectoryListerDelegate {
|
2015-11-17 19:20:13 +01:00
|
|
|
public:
|
|
|
|
explicit UploadFolderHelper(
|
2020-03-04 01:29:39 +01:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback)
|
|
|
|
: callback_(std::move(callback)) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
UploadFolderHelper(const UploadFolderHelper&) = delete;
|
|
|
|
UploadFolderHelper& operator=(const UploadFolderHelper&) = delete;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
~UploadFolderHelper() override {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
CancelNow(std::move(callback_));
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
2020-03-04 01:29:39 +01:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(&UploadFolderHelper::CancelNow,
|
|
|
|
std::move(callback_)));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnListFile(
|
|
|
|
const net::DirectoryLister::DirectoryListerData& data) override {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (!data.info.IsDirectory())
|
|
|
|
select_files_.push_back(data.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnListDone(int error) override {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (!callback_.is_null()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback_).Run(0, select_files_);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-03-04 01:29:39 +01:00
|
|
|
static void CancelNow(CefFileDialogRunner::RunFileChooserCallback callback) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
std::vector<base::FilePath> file_paths;
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback).Run(0, file_paths);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback_;
|
|
|
|
std::vector<base::FilePath> select_files_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefFileDialogManager::CefFileDialogManager(
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl* browser,
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefFileDialogRunner> runner)
|
2018-10-24 22:37:39 +02:00
|
|
|
: browser_(browser),
|
2016-01-06 20:20:54 +01:00
|
|
|
runner_(std::move(runner)),
|
2015-11-17 19:20:13 +01:00
|
|
|
file_chooser_pending_(false),
|
2018-10-24 22:37:39 +02:00
|
|
|
weak_ptr_factory_(this) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefFileDialogManager::~CefFileDialogManager() {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
void CefFileDialogManager::Destroy() {
|
|
|
|
DCHECK(!file_chooser_pending_);
|
2020-01-15 14:36:24 +01:00
|
|
|
runner_.reset(nullptr);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::RunFileDialog(
|
2017-05-17 11:29:28 +02:00
|
|
|
cef_file_dialog_mode_t mode,
|
|
|
|
const CefString& title,
|
|
|
|
const CefString& default_file_path,
|
|
|
|
const std::vector<CefString>& accept_filters,
|
|
|
|
int selected_accept_filter,
|
|
|
|
CefRefPtr<CefRunFileDialogCallback> callback) {
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(callback.get());
|
|
|
|
if (!callback.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefFileDialogRunner::FileChooserParams params;
|
|
|
|
switch (mode & FILE_DIALOG_TYPE_MASK) {
|
|
|
|
case FILE_DIALOG_OPEN:
|
2018-10-02 14:14:11 +02:00
|
|
|
params.mode = blink::mojom::FileChooserParams::Mode::kOpen;
|
2015-11-17 19:20:13 +01:00
|
|
|
break;
|
|
|
|
case FILE_DIALOG_OPEN_MULTIPLE:
|
2018-10-02 14:14:11 +02:00
|
|
|
params.mode = blink::mojom::FileChooserParams::Mode::kOpenMultiple;
|
2015-11-17 19:20:13 +01:00
|
|
|
break;
|
|
|
|
case FILE_DIALOG_OPEN_FOLDER:
|
2018-10-02 14:14:11 +02:00
|
|
|
params.mode = blink::mojom::FileChooserParams::Mode::kUploadFolder;
|
2015-11-17 19:20:13 +01:00
|
|
|
break;
|
|
|
|
case FILE_DIALOG_SAVE:
|
2018-10-02 14:14:11 +02:00
|
|
|
params.mode = blink::mojom::FileChooserParams::Mode::kSave;
|
2015-11-17 19:20:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_GE(selected_accept_filter, 0);
|
|
|
|
params.selected_accept_filter = selected_accept_filter;
|
|
|
|
|
|
|
|
params.overwriteprompt = !!(mode & FILE_DIALOG_OVERWRITEPROMPT_FLAG);
|
|
|
|
params.hidereadonly = !!(mode & FILE_DIALOG_HIDEREADONLY_FLAG);
|
|
|
|
|
|
|
|
params.title = title;
|
|
|
|
if (!default_file_path.empty())
|
|
|
|
params.default_file_name = base::FilePath(default_file_path);
|
|
|
|
|
|
|
|
if (!accept_filters.empty()) {
|
|
|
|
std::vector<CefString>::const_iterator it = accept_filters.begin();
|
|
|
|
for (; it != accept_filters.end(); ++it)
|
|
|
|
params.accept_types.push_back(*it);
|
|
|
|
}
|
|
|
|
|
2021-06-04 03:34:56 +02:00
|
|
|
RunFileChooser(params, base::BindOnce(RunFileDialogDismissed, callback));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::RunFileChooser(
|
2020-08-29 00:39:23 +02:00
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
2018-10-02 14:14:11 +02:00
|
|
|
const blink::mojom::FileChooserParams& params) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
CefFileDialogRunner::FileChooserParams cef_params;
|
2018-10-02 14:14:11 +02:00
|
|
|
static_cast<blink::mojom::FileChooserParams&>(cef_params) = params;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback;
|
2018-10-02 14:14:11 +02:00
|
|
|
if (params.mode == blink::mojom::FileChooserParams::Mode::kUploadFolder) {
|
2020-03-04 01:29:39 +01:00
|
|
|
callback = base::BindOnce(
|
2016-06-21 00:59:23 +02:00
|
|
|
&CefFileDialogManager::OnRunFileChooserUploadFolderDelegateCallback,
|
2020-08-29 00:39:23 +02:00
|
|
|
weak_ptr_factory_.GetWeakPtr(), params.mode, listener);
|
2016-06-21 00:59:23 +02:00
|
|
|
} else {
|
2020-08-29 00:39:23 +02:00
|
|
|
callback =
|
|
|
|
base::BindOnce(&CefFileDialogManager::OnRunFileChooserDelegateCallback,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), params.mode, listener);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
RunFileChooserInternal(cef_params, std::move(callback));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::RunFileChooser(
|
|
|
|
const CefFileDialogRunner::FileChooserParams& params,
|
2020-03-04 01:29:39 +01:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback) {
|
|
|
|
CefFileDialogRunner::RunFileChooserCallback host_callback =
|
|
|
|
base::BindOnce(&CefFileDialogManager::OnRunFileChooserCallback,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), std::move(callback));
|
|
|
|
RunFileChooserInternal(params, std::move(host_callback));
|
2016-06-21 00:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::RunFileChooserInternal(
|
|
|
|
const CefFileDialogRunner::FileChooserParams& params,
|
2020-03-04 01:29:39 +01:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback) {
|
2015-11-17 19:20:13 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (file_chooser_pending_) {
|
|
|
|
// Dismiss the new dialog immediately.
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback).Run(0, std::vector<base::FilePath>());
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_chooser_pending_ = true;
|
|
|
|
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
if (browser_->client().get()) {
|
|
|
|
CefRefPtr<CefDialogHandler> handler =
|
|
|
|
browser_->client()->GetDialogHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
int mode = FILE_DIALOG_OPEN;
|
|
|
|
switch (params.mode) {
|
2018-10-02 14:14:11 +02:00
|
|
|
case blink::mojom::FileChooserParams::Mode::kOpen:
|
2015-11-17 19:20:13 +01:00
|
|
|
mode = FILE_DIALOG_OPEN;
|
|
|
|
break;
|
2018-10-02 14:14:11 +02:00
|
|
|
case blink::mojom::FileChooserParams::Mode::kOpenMultiple:
|
2015-11-17 19:20:13 +01:00
|
|
|
mode = FILE_DIALOG_OPEN_MULTIPLE;
|
|
|
|
break;
|
2018-10-02 14:14:11 +02:00
|
|
|
case blink::mojom::FileChooserParams::Mode::kUploadFolder:
|
2015-11-17 19:20:13 +01:00
|
|
|
mode = FILE_DIALOG_OPEN_FOLDER;
|
|
|
|
break;
|
2018-10-02 14:14:11 +02:00
|
|
|
case blink::mojom::FileChooserParams::Mode::kSave:
|
2015-11-17 19:20:13 +01:00
|
|
|
mode = FILE_DIALOG_SAVE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.overwriteprompt)
|
|
|
|
mode |= FILE_DIALOG_OVERWRITEPROMPT_FLAG;
|
|
|
|
if (params.hidereadonly)
|
|
|
|
mode |= FILE_DIALOG_HIDEREADONLY_FLAG;
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::vector<std::u16string>::const_iterator it;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
std::vector<CefString> accept_filters;
|
|
|
|
it = params.accept_types.begin();
|
|
|
|
for (; it != params.accept_types.end(); ++it)
|
|
|
|
accept_filters.push_back(*it);
|
|
|
|
|
|
|
|
CefRefPtr<CefFileDialogCallbackImpl> callbackImpl(
|
2020-03-04 01:29:39 +01:00
|
|
|
new CefFileDialogCallbackImpl(std::move(callback)));
|
2015-11-17 19:20:13 +01:00
|
|
|
handled = handler->OnFileDialog(
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_, static_cast<cef_file_dialog_mode_t>(mode), params.title,
|
|
|
|
params.default_file_name.value(), accept_filters,
|
|
|
|
params.selected_accept_filter, callbackImpl.get());
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!handled) {
|
2020-03-04 01:29:39 +01:00
|
|
|
// May return nullptr if the client has already executed the callback.
|
|
|
|
callback = callbackImpl->Disconnect();
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
if (!handled && !callback.is_null()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (runner_.get()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
runner_->Run(browser_, params, std::move(callback));
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
|
|
|
LOG(WARNING) << "No file dialog runner available for this platform";
|
2020-03-04 01:29:39 +01:00
|
|
|
std::move(callback).Run(0, std::vector<base::FilePath>());
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::OnRunFileChooserCallback(
|
2020-03-04 01:29:39 +01:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback,
|
2015-11-17 19:20:13 +01:00
|
|
|
int selected_accept_filter,
|
|
|
|
const std::vector<base::FilePath>& file_paths) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
Cleanup();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Execute the callback asynchronously.
|
2020-03-04 01:29:39 +01:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::BindOnce(std::move(callback),
|
|
|
|
selected_accept_filter, file_paths));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::OnRunFileChooserUploadFolderDelegateCallback(
|
2018-10-02 14:14:11 +02:00
|
|
|
const blink::mojom::FileChooserParams::Mode mode,
|
2020-08-29 00:39:23 +02:00
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
2015-11-17 19:20:13 +01:00
|
|
|
int selected_accept_filter,
|
|
|
|
const std::vector<base::FilePath>& file_paths) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2018-10-02 14:14:11 +02:00
|
|
|
DCHECK_EQ(mode, blink::mojom::FileChooserParams::Mode::kUploadFolder);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
if (file_paths.size() == 0) {
|
|
|
|
// Client canceled the file chooser.
|
2020-08-29 00:39:23 +02:00
|
|
|
OnRunFileChooserDelegateCallback(mode, listener, selected_accept_filter,
|
|
|
|
file_paths);
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
|
|
|
lister_.reset(new net::DirectoryLister(
|
2017-05-17 11:29:28 +02:00
|
|
|
file_paths[0], net::DirectoryLister::NO_SORT_RECURSIVE,
|
2020-03-04 01:29:39 +01:00
|
|
|
new UploadFolderHelper(base::BindOnce(
|
|
|
|
&CefFileDialogManager::OnRunFileChooserDelegateCallback,
|
2020-08-29 00:39:23 +02:00
|
|
|
weak_ptr_factory_.GetWeakPtr(), mode, listener))));
|
2017-03-03 23:37:23 +01:00
|
|
|
lister_->Start();
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::OnRunFileChooserDelegateCallback(
|
2018-10-02 14:14:11 +02:00
|
|
|
blink::mojom::FileChooserParams::Mode mode,
|
2020-08-29 00:39:23 +02:00
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
2015-11-17 19:20:13 +01:00
|
|
|
int selected_accept_filter,
|
|
|
|
const std::vector<base::FilePath>& file_paths) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
base::FilePath base_dir;
|
2018-10-02 14:14:11 +02:00
|
|
|
std::vector<blink::mojom::FileChooserFileInfoPtr> selected_files;
|
2018-11-30 23:21:07 +01:00
|
|
|
|
|
|
|
if (!file_paths.empty()) {
|
|
|
|
if (mode == blink::mojom::FileChooserParams::Mode::kUploadFolder) {
|
2019-08-26 21:43:55 +02:00
|
|
|
base_dir = file_paths[0].DirName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert FilePath list to SelectedFileInfo list.
|
|
|
|
for (size_t i = 0; i < file_paths.size(); ++i) {
|
|
|
|
auto info = blink::mojom::FileChooserFileInfo::NewNativeFile(
|
2021-04-21 00:52:34 +02:00
|
|
|
blink::mojom::NativeFileInfo::New(file_paths[i], std::u16string()));
|
2019-08-26 21:43:55 +02:00
|
|
|
selected_files.push_back(std::move(info));
|
2018-11-30 23:21:07 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
listener->FileSelected(std::move(selected_files), base_dir, mode);
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFileDialogManager::Cleanup() {
|
|
|
|
if (lister_)
|
|
|
|
lister_.reset();
|
|
|
|
|
|
|
|
file_chooser_pending_ = false;
|
|
|
|
}
|