diff --git a/cef1/cef_paths2.gypi b/cef1/cef_paths2.gypi index c71f1472d..83e8750cb 100644 --- a/cef1/cef_paths2.gypi +++ b/cef1/cef_paths2.gypi @@ -167,6 +167,7 @@ 'tests/cefclient/resource_util_linux.cpp', ], 'cefclient_bundle_resources_linux': [ + 'tests/cefclient/res/dialogs.html', 'tests/cefclient/res/domaccess.html', 'tests/cefclient/res/localstorage.html', 'tests/cefclient/res/logo.png', diff --git a/cef1/libcef/browser_webview_delegate_gtk.cc b/cef1/libcef/browser_webview_delegate_gtk.cc index cfa23370f..fe1ab1e62 100644 --- a/cef1/libcef/browser_webview_delegate_gtk.cc +++ b/cef1/libcef/browser_webview_delegate_gtk.cc @@ -94,6 +94,112 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard, } } +void ShowJSAlertDialog(GtkWidget* window, + const gchar* title, + const gchar* message) { + // Create the widgets. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + title, + GTK_WINDOW(window), + GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL), + GTK_STOCK_OK, + GTK_RESPONSE_NONE, + NULL); + GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkWidget* label = gtk_label_new(message); + + // Add the label and show everything we've added to the dialog. + gtk_container_add(GTK_CONTAINER(content_area), label); + + gtk_widget_show_all(dialog); + + gtk_dialog_run(GTK_DIALOG(dialog)); + + gtk_widget_destroy(dialog); +} + +bool ShowJSConfirmDialog(GtkWidget* window, + const gchar* title, + const gchar* message) { + // Create the widgets. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + title, + GTK_WINDOW(window), + GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL), + GTK_STOCK_NO, + GTK_RESPONSE_NO, + GTK_STOCK_YES, + GTK_RESPONSE_YES, + NULL); + GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkWidget* label = gtk_label_new(message); + + // Add the label and show everything we've added to the dialog. + gtk_container_add(GTK_CONTAINER(content_area), label); + gtk_widget_show_all(dialog); + + gint result = gtk_dialog_run(GTK_DIALOG(dialog)); + + gtk_widget_destroy(dialog); + + return (result == GTK_RESPONSE_YES); +} + +bool ShowJSPromptDialog(GtkWidget* window, + const gchar* title, + const gchar* message, + const gchar* default_val, + std::string* return_val) { + // Create the widgets. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + title, + GTK_WINDOW(window), + GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkWidget* label = gtk_label_new(message); + GtkWidget* entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(entry), default_val); + + // Add the label and entry and show everything we've added to the dialog. + gtk_container_add(GTK_CONTAINER(content_area), label); + gtk_container_add(GTK_CONTAINER(content_area), entry); + gtk_widget_show_all(dialog); + + gint result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_OK) + *return_val = std::string(gtk_entry_get_text(GTK_ENTRY(entry))); + + gtk_widget_destroy(dialog); + + return (result == GTK_RESPONSE_OK); +} + +bool ShowJSFileChooser(GtkWidget* window, FilePath* path) { + // Create the widgets. + GtkWidget* dialog = gtk_file_chooser_dialog_new( + "Open File", + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + gtk_widget_show_all(dialog); + + int result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_ACCEPT) + *path = FilePath(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); + + gtk_widget_destroy(dialog); + + return (result == GTK_RESPONSE_ACCEPT); +} + } // namespace // WebViewClient --------------------------------------------------------------- @@ -382,29 +488,67 @@ void BrowserWebViewDelegate::RegisterDragDrop() { void BrowserWebViewDelegate::ShowJavaScriptAlert( WebKit::WebFrame* webframe, const CefString& message) { - NOTIMPLEMENTED(); + std::string messageStr(message); + std::string urlStr(browser_->GetMainFrame()->GetURL()); + + gfx::NativeView view = browser_->UIT_GetMainWndHandle(); + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view)); + + ShowJSAlertDialog(window, + static_cast(urlStr.c_str()), + static_cast(messageStr.c_str())); } bool BrowserWebViewDelegate::ShowJavaScriptConfirm( WebKit::WebFrame* webframe, const CefString& message) { - NOTIMPLEMENTED(); - return false; + std::string messageStr(message); + std::string urlStr(browser_->GetMainFrame()->GetURL()); + + gfx::NativeView view = browser_->UIT_GetMainWndHandle(); + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view)); + + return ShowJSConfirmDialog( + window, + static_cast(urlStr.c_str()), + static_cast(messageStr.c_str())); } bool BrowserWebViewDelegate::ShowJavaScriptPrompt( WebKit::WebFrame* webframe, const CefString& message, const CefString& default_value, CefString* result) { - NOTIMPLEMENTED(); - return false; + std::string messageStr(message); + std::string defaultStr(default_value); + std::string urlStr(browser_->GetMainFrame()->GetURL()); + + gfx::NativeView view = browser_->UIT_GetMainWndHandle(); + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view)); + + std::string return_val; + bool resp = ShowJSPromptDialog( + window, + static_cast(urlStr.c_str()), + static_cast(messageStr.c_str()), + static_cast(defaultStr.c_str()), + &return_val); + if (resp) + *result = return_val; + + return resp; } -// Called to show the file chooser dialog. bool BrowserWebViewDelegate::ShowFileChooser( std::vector& file_names, bool multi_select, const WebKit::WebString& title, const FilePath& default_file, const std::vector& accept_mime_types) { - NOTIMPLEMENTED(); - return false; + gfx::NativeView view = browser_->UIT_GetMainWndHandle(); + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view)); + + FilePath file_name; + bool resp = ShowJSFileChooser(window, &file_name); + if (resp) + file_names.push_back(file_name); + + return resp; } diff --git a/cef1/tests/cefclient/cefclient.cpp b/cef1/tests/cefclient/cefclient.cpp index 12e69743d..0225173fb 100644 --- a/cef1/tests/cefclient/cefclient.cpp +++ b/cef1/tests/cefclient/cefclient.cpp @@ -660,3 +660,7 @@ void RunPluginInfoTest(CefRefPtr browser) { void RunGeolocationTest(CefRefPtr browser) { browser->GetMainFrame()->LoadURL("http://html5demos.com/geo"); } + +void RunDialogsTest(CefRefPtr browser) { + browser->GetMainFrame()->LoadURL("http://tests/dialogs"); +} diff --git a/cef1/tests/cefclient/cefclient.h b/cef1/tests/cefclient/cefclient.h index c5ecd9423..c5c6b2c2a 100644 --- a/cef1/tests/cefclient/cefclient.h +++ b/cef1/tests/cefclient/cefclient.h @@ -52,6 +52,7 @@ void RunDragDropTest(CefRefPtr browser); void RunModalDialogTest(CefRefPtr browser); void RunPluginInfoTest(CefRefPtr browser); void RunGeolocationTest(CefRefPtr browser); +void RunDialogsTest(CefRefPtr browser); #if defined(OS_WIN) void RunTransparentPopupTest(CefRefPtr browser); diff --git a/cef1/tests/cefclient/cefclient_gtk.cpp b/cef1/tests/cefclient/cefclient_gtk.cpp index 15f40c0fc..f3f8bc489 100644 --- a/cef1/tests/cefclient/cefclient_gtk.cpp +++ b/cef1/tests/cefclient/cefclient_gtk.cpp @@ -79,6 +79,14 @@ gboolean PerformanceActivated(GtkWidget* widget) { return FALSE; // Don't stop this message. } +// Callback for Debug > Dialogs... menu item. +gboolean DialogsActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserHwnd()) + RunDialogsTest(g_handler->GetBrowser()); + + return FALSE; // Don't stop this message. +} + // Callback for Debug > Request... menu item. gboolean RequestActivated(GtkWidget* widget) { if (g_handler.get() && g_handler->GetBrowserHwnd()) @@ -291,6 +299,8 @@ GtkWidget* CreateMenuBar() { G_CALLBACK(JSExecuteActivated)); AddMenuEntry(debug_menu, "Performance Tests", G_CALLBACK(PerformanceActivated)); + AddMenuEntry(debug_menu, "Dialogs", + G_CALLBACK(DialogsActivated)); AddMenuEntry(debug_menu, "Request", G_CALLBACK(RequestActivated)); AddMenuEntry(debug_menu, "Local Storage", diff --git a/cef1/tests/cefclient/client_handler_gtk.cpp b/cef1/tests/cefclient/client_handler_gtk.cpp index 7df19a66a..96e73ce0a 100644 --- a/cef1/tests/cefclient/client_handler_gtk.cpp +++ b/cef1/tests/cefclient/client_handler_gtk.cpp @@ -66,6 +66,11 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr browser, resourceStream = GetBinaryResourceReader("performance.html"); response->SetMimeType("text/html"); response->SetStatus(200); + } else if (url == "http://tests/dialogs") { + // Show the dialogs HTML contents + resourceStream = GetBinaryResourceReader("dialogs.html"); + response->SetMimeType("text/html"); + response->SetStatus(200); } return false; diff --git a/cef1/tests/cefclient/res/dialogs.html b/cef1/tests/cefclient/res/dialogs.html new file mode 100644 index 000000000..fe650f8f6 --- /dev/null +++ b/cef1/tests/cefclient/res/dialogs.html @@ -0,0 +1,43 @@ + + +Dialog Test + + + +
+Click a button to show the associated dialog type. +
+
+
+
input type="file": +

+
+ +