1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_ 7 #pragma once 8 9 #include <gtk/gtk.h> 10 11 #include "include/base/cef_callback_forward.h" 12 #include "include/cef_dialog_handler.h" 13 #include "include/cef_jsdialog_handler.h" 14 15 namespace client { 16 17 class ClientDialogHandlerGtk : public CefDialogHandler, 18 public CefJSDialogHandler { 19 public: 20 ClientDialogHandlerGtk(); 21 22 // CefDialogHandler methods. 23 bool OnFileDialog(CefRefPtr<CefBrowser> browser, 24 FileDialogMode mode, 25 const CefString& title, 26 const CefString& default_file_path, 27 const std::vector<CefString>& accept_filters, 28 int selected_accept_filter, 29 CefRefPtr<CefFileDialogCallback> callback) override; 30 31 // CefJSDialogHandler methods. 32 bool OnJSDialog(CefRefPtr<CefBrowser> browser, 33 const CefString& origin_url, 34 JSDialogType dialog_type, 35 const CefString& message_text, 36 const CefString& default_prompt_text, 37 CefRefPtr<CefJSDialogCallback> callback, 38 bool& suppress_message) override; 39 bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser, 40 const CefString& message_text, 41 bool is_reload, 42 CefRefPtr<CefJSDialogCallback> callback) override; 43 void OnResetDialogState(CefRefPtr<CefBrowser> browser) override; 44 45 private: 46 struct OnFileDialogParams { 47 CefRefPtr<CefBrowser> browser; 48 FileDialogMode mode; 49 CefString title; 50 CefString default_file_path; 51 std::vector<CefString> accept_filters; 52 int selected_accept_filter; 53 CefRefPtr<CefFileDialogCallback> callback; 54 }; 55 void OnFileDialogContinue(OnFileDialogParams params, GtkWindow* window); 56 57 struct OnJSDialogParams { 58 CefRefPtr<CefBrowser> browser; 59 CefString origin_url; 60 JSDialogType dialog_type; 61 CefString message_text; 62 CefString default_prompt_text; 63 CefRefPtr<CefJSDialogCallback> callback; 64 }; 65 void OnJSDialogContinue(OnJSDialogParams params, GtkWindow* window); 66 67 void GetWindowAndContinue(CefRefPtr<CefBrowser> browser, 68 base::OnceCallback<void(GtkWindow*)> callback); 69 70 static void OnDialogResponse(GtkDialog* dialog, 71 gint response_id, 72 ClientDialogHandlerGtk* handler); 73 74 GtkWidget* gtk_dialog_; 75 CefRefPtr<CefJSDialogCallback> js_dialog_callback_; 76 77 IMPLEMENT_REFCOUNTING(ClientDialogHandlerGtk); 78 DISALLOW_COPY_AND_ASSIGN(ClientDialogHandlerGtk); 79 }; 80 81 } // namespace client 82 83 #endif // CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_ 84