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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_FILE_DIALOG_MANAGER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_FILE_DIALOG_MANAGER_H_
|
|
|
|
#pragma once
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2022-04-15 21:55:23 +02:00
|
|
|
#include "base/memory/scoped_refptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_browser.h"
|
2022-04-15 21:55:23 +02:00
|
|
|
#include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
|
|
|
|
#include "ui/shell_dialogs/select_file_dialog.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
namespace content {
|
2018-10-24 22:37:39 +02:00
|
|
|
class FileSelectListener;
|
|
|
|
} // namespace content
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
class CefBrowserHostBase;
|
|
|
|
class CefSelectFileDialogListener;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2018-10-24 22:37:39 +02:00
|
|
|
class CefFileDialogManager {
|
2015-11-17 19:20:13 +01:00
|
|
|
public:
|
2022-04-15 21:55:23 +02:00
|
|
|
explicit CefFileDialogManager(CefBrowserHostBase* browser);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefFileDialogManager(const CefFileDialogManager&) = delete;
|
|
|
|
CefFileDialogManager& operator=(const CefFileDialogManager&) = delete;
|
|
|
|
|
2018-10-24 22:37:39 +02:00
|
|
|
~CefFileDialogManager();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Delete the runner to free any platform constructs.
|
|
|
|
void Destroy();
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Run a file dialog with the specified parameters. See
|
|
|
|
// CefBrowserHost::RunFileDialog for usage documentation. This method should
|
|
|
|
// be called via CefBrowserHostBase::RunFileDialog.
|
2017-05-17 11:29:28 +02:00
|
|
|
void RunFileDialog(cef_file_dialog_mode_t mode,
|
|
|
|
const CefString& title,
|
|
|
|
const CefString& default_file_path,
|
|
|
|
const std::vector<CefString>& accept_filters,
|
|
|
|
CefRefPtr<CefRunFileDialogCallback> callback);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// The argument vector will be empty if the dialog was canceled.
|
|
|
|
using RunFileChooserCallback =
|
|
|
|
base::OnceCallback<void(const std::vector<base::FilePath>&)>;
|
|
|
|
|
|
|
|
// Run the file dialog specified by |params|. |callback| will be executed
|
|
|
|
// synchronously or asynchronously after the dialog is dismissed. This method
|
|
|
|
// should be called via CefBrowserHostBase::RunFileChooser.
|
|
|
|
void RunFileChooser(const blink::mojom::FileChooserParams& params,
|
|
|
|
RunFileChooserCallback callback);
|
|
|
|
|
|
|
|
// Run a ui::SelectFileDialog with the specified parameters. See
|
|
|
|
// ui::SelectFileDialog for usage documentation. This method should be called
|
|
|
|
// via CefBrowserHostBase::RunSelectFile. It will be called for all file
|
|
|
|
// dialogs after interception via CefSelectFileDialog::SelectFileImpl.
|
|
|
|
void RunSelectFile(ui::SelectFileDialog::Listener* listener,
|
|
|
|
std::unique_ptr<ui::SelectFilePolicy> policy,
|
|
|
|
ui::SelectFileDialog::Type type,
|
|
|
|
const std::u16string& title,
|
|
|
|
const base::FilePath& default_path,
|
|
|
|
const ui::SelectFileDialog::FileTypeInfo* file_types,
|
|
|
|
int file_type_index,
|
|
|
|
const base::FilePath::StringType& default_extension,
|
2024-07-29 19:09:20 +02:00
|
|
|
gfx::NativeWindow owning_window);
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
// Must be called when the |listener| passed to RunSelectFile is destroyed.
|
|
|
|
void SelectFileListenerDestroyed(ui::SelectFileDialog::Listener* listener);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
private:
|
2024-05-29 22:38:00 +02:00
|
|
|
using Extensions = std::vector<std::vector<base::FilePath::StringType>>;
|
|
|
|
using Descriptions = std::vector<std::u16string>;
|
2022-04-15 21:55:23 +02:00
|
|
|
[[nodiscard]] RunFileChooserCallback MaybeRunDelegate(
|
|
|
|
const blink::mojom::FileChooserParams& params,
|
2024-05-29 22:38:00 +02:00
|
|
|
const Extensions& extensions,
|
|
|
|
const Descriptions& descriptions,
|
2022-04-15 21:55:23 +02:00
|
|
|
RunFileChooserCallback callback);
|
|
|
|
|
|
|
|
void SelectFileDoneByDelegateCallback(
|
2024-06-25 19:56:04 +02:00
|
|
|
MayBeDangling<ui::SelectFileDialog::Listener> listener,
|
2022-04-15 21:55:23 +02:00
|
|
|
const std::vector<base::FilePath>& paths);
|
2024-06-20 19:55:23 +02:00
|
|
|
void SelectFileDoneByListenerCallback(
|
2024-06-25 19:56:04 +02:00
|
|
|
MayBeDangling<ui::SelectFileDialog::Listener> listener,
|
2024-06-20 19:55:23 +02:00
|
|
|
bool listener_destroyed);
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
// CefBrowserHostBase pointer is guaranteed to outlive this object.
|
2024-05-11 17:48:38 +02:00
|
|
|
const raw_ptr<CefBrowserHostBase> browser_;
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
// Used when running a platform dialog via RunSelectFile.
|
|
|
|
scoped_refptr<ui::SelectFileDialog> dialog_;
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefSelectFileDialogListener> dialog_listener_ = nullptr;
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
// List of all currently active listeners.
|
2024-05-13 23:36:09 +02:00
|
|
|
std::set<raw_ptr<ui::SelectFileDialog::Listener>> active_listeners_;
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
base::WeakPtrFactory<CefFileDialogManager> weak_ptr_factory_{this};
|
2015-11-17 19:20:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
|