cef/tests/cefclient/browser/dialog_handler_gtk.h
Marshall Greenblatt 8e79307a62 Pass mime type values as file dialog accept filters (see #3314)
File dialogs that specify mime type (e.g. "image/*") accept filters will pass
those values unchanged to the OnFileDialog |accept_filters| parameter. The
default dialog implementation will show those filters in addition to a combined
"Custom Files" filter. This is a change from preexisting Google Chrome
behavior where only the combined "Custom Files" filter is displayed, and
restores CEF behavior that existed prior to 2ea7459a89.

Document the fact that OnFileDialog may be called twice, once before MIME type
expansion and once afterwards.

Add new OnFileDialog |accept_extensions| and |accept_descriptions| parameters
for MIME type extensions and descriptions.

Details: This change adds a SelectFileDialog::FileTypeInfo::extension_mimetypes
member and improves the logic in FileSelectHelper::GetFileTypesFromAcceptType
and file_dialog_manager.cc SelectFileToFileChooserParams to support recall of
the source mime type when populating the FileChooserParams structure.

To test:
- Run `ceftests --gtest_filter=DialogTest.*`
- Run `cefclient --url=https://tests/dialogs`
2024-05-30 15:38:36 -04:00

87 lines
3.1 KiB
C++

// Copyright (c) 2015 The Chromium Embedded Framework 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_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_
#pragma once
#include <gtk/gtk.h>
#include "include/base/cef_callback_forward.h"
#include "include/cef_dialog_handler.h"
#include "include/cef_jsdialog_handler.h"
namespace client {
class ClientDialogHandlerGtk : public CefDialogHandler,
public CefJSDialogHandler {
public:
ClientDialogHandlerGtk();
// CefDialogHandler methods.
bool OnFileDialog(CefRefPtr<CefBrowser> browser,
FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
const std::vector<CefString>& accept_extensions,
const std::vector<CefString>& accept_descriptions,
CefRefPtr<CefFileDialogCallback> callback) override;
// CefJSDialogHandler methods.
bool OnJSDialog(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) override;
bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) override;
void OnResetDialogState(CefRefPtr<CefBrowser> browser) override;
private:
struct OnFileDialogParams {
CefRefPtr<CefBrowser> browser;
FileDialogMode mode;
CefString title;
CefString default_file_path;
std::vector<CefString> accept_filters;
std::vector<CefString> accept_extensions;
std::vector<CefString> accept_descriptions;
CefRefPtr<CefFileDialogCallback> callback;
};
void OnFileDialogContinue(const OnFileDialogParams& params,
GtkWindow* window);
struct OnJSDialogParams {
CefRefPtr<CefBrowser> browser;
CefString origin_url;
JSDialogType dialog_type;
CefString message_text;
CefString default_prompt_text;
CefRefPtr<CefJSDialogCallback> callback;
};
void OnJSDialogContinue(const OnJSDialogParams& params, GtkWindow* window);
void GetWindowAndContinue(CefRefPtr<CefBrowser> browser,
base::OnceCallback<void(GtkWindow*)> callback);
static void OnDialogResponse(GtkDialog* dialog,
gint response_id,
ClientDialogHandlerGtk* handler);
GtkWidget* gtk_dialog_;
CefRefPtr<CefJSDialogCallback> js_dialog_callback_;
IMPLEMENT_REFCOUNTING(ClientDialogHandlerGtk);
DISALLOW_COPY_AND_ASSIGN(ClientDialogHandlerGtk);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_