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
|
|
|
|
|
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "libcef/browser/file_dialog_runner.h"
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
|
|
|
|
namespace content {
|
2018-10-24 22:37:39 +02:00
|
|
|
class FileSelectListener;
|
2015-11-17 19:20:13 +01:00
|
|
|
class WebContents;
|
2018-10-24 22:37:39 +02:00
|
|
|
} // namespace content
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
namespace net {
|
|
|
|
class DirectoryLister;
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
class AlloyBrowserHostImpl;
|
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:
|
|
|
|
// |runner| may be NULL if the platform doesn't implement dialogs.
|
2020-09-22 21:54:02 +02:00
|
|
|
CefFileDialogManager(AlloyBrowserHostImpl* browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
std::unique_ptr<CefFileDialogRunner> runner);
|
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();
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// Called from AlloyBrowserHostImpl::RunFileChooser.
|
2015-11-17 19:20:13 +01:00
|
|
|
// See CefBrowserHost::RunFileDialog documentation.
|
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,
|
|
|
|
int selected_accept_filter,
|
|
|
|
CefRefPtr<CefRunFileDialogCallback> callback);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// Called from AlloyBrowserHostImpl::RunFileChooser.
|
2015-11-17 19:20:13 +01:00
|
|
|
// See WebContentsDelegate::RunFileChooser documentation.
|
2020-08-29 00:39:23 +02:00
|
|
|
void RunFileChooser(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
|
|
|
|
|
|
|
// Run the file chooser dialog specified by |params|. Only a single dialog may
|
|
|
|
// be pending at any given time. |callback| will be executed asynchronously
|
|
|
|
// after the dialog is dismissed or if another dialog is already pending.
|
2020-03-04 01:29:39 +01:00
|
|
|
void RunFileChooser(const CefFileDialogRunner::FileChooserParams& params,
|
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
private:
|
2016-06-21 00:59:23 +02:00
|
|
|
void RunFileChooserInternal(
|
|
|
|
const CefFileDialogRunner::FileChooserParams& params,
|
2020-03-04 01:29:39 +01:00
|
|
|
CefFileDialogRunner::RunFileChooserCallback callback);
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
// Used with the RunFileChooser variant where the caller specifies a callback
|
|
|
|
// (no associated RenderFrameHost).
|
2015-11-17 19:20:13 +01:00
|
|
|
void 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);
|
|
|
|
|
|
|
|
// Used with WebContentsDelegate::RunFileChooser when mode is
|
2018-10-02 14:14:11 +02:00
|
|
|
// blink::mojom::FileChooserParams::Mode::kUploadFolder.
|
2015-11-17 19:20:13 +01:00
|
|
|
void 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);
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
// Used with WebContentsDelegate::RunFileChooser to notify the
|
|
|
|
// RenderFrameHost.
|
2015-11-17 19:20:13 +01:00
|
|
|
void 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);
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
// Clean up state associated with the last run.
|
|
|
|
void Cleanup();
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl pointer is guaranteed to outlive this object.
|
|
|
|
AlloyBrowserHostImpl* browser_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefFileDialogRunner> runner_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// True if a file chooser is currently pending.
|
|
|
|
bool file_chooser_pending_;
|
|
|
|
|
|
|
|
// Used for asynchronously listing directory contents.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::DirectoryLister> lister_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Must be the last member.
|
|
|
|
base::WeakPtrFactory<CefFileDialogManager> weak_ptr_factory_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefFileDialogManager);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
|