Diff
Modified: trunk/Source/WebKit2/ChangeLog (102674 => 102675)
--- trunk/Source/WebKit2/ChangeLog 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/ChangeLog 2011-12-13 13:31:55 UTC (rev 102675)
@@ -1,3 +1,38 @@
+2011-12-13 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Add support for _javascript_ dialogs in WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=71362
+
+ Reviewed by Martin Robinson.
+
+ * UIProcess/API/gtk/WebKitUIClient.cpp:
+ (runJavaScriptAlert): Call webkitWebViewRunJavaScriptAlert().
+ (runJavaScriptConfirm): Call webkitWebViewRunJavaScriptConfirm().
+ (runJavaScriptPrompt): Call webkitWebViewRunJavaScriptPrompt().
+ (webkitUIClientAttachUIClientToPage): Add implementation for
+ runJavaScriptAlert, runJavaScriptConfirm and runJavaScriptPrompt
+ callbacks.
+ * UIProcess/API/gtk/WebKitWebView.cpp:
+ (webkitWebViewCreateJavaScriptDialog): Helper function to create
+ _javascript_ dialogs.
+ (webkitWebViewScriptAlert): Default implementation of signal
+ WebKitWebView::script-alert that shows a message dialog.
+ (webkitWebViewScriptConfirm): Default implementation of signal
+ WebKitWebView::script-confirm that shows a question dialog.
+ (webkitWebViewScriptPrompt): Default implementation of signal
+ WebKitWebView::script-prompt that shows a question dialog with a
+ text entry.
+ (webkit_web_view_class_init):
+ (webkitWebViewRunJavaScriptAlert): Emit WebKitWebView::script-alert.
+ (webkitWebViewRunJavaScriptConfirm): Emit WebKitWebView::script-confirm.
+ (webkitWebViewRunJavaScriptPrompt): Emit WebKitWebView::script-prompt.
+ * UIProcess/API/gtk/WebKitWebView.h:
+ * UIProcess/API/gtk/WebKitWebViewPrivate.h:
+ * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+ (testWebViewJavaScriptDialogs):
+ (beforeAll):
+ * UIProcess/API/gtk/webkit2marshal.list:
+
2011-12-13 Kenneth Rohde Christiansen <[email protected]>
[Qt] Make sure that touch events result in the page view gaining focus
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp 2011-12-13 13:31:55 UTC (rev 102675)
@@ -43,6 +43,22 @@
webkitWebViewClosePage(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()));
}
+static void runJavaScriptAlert(WKPageRef page, WKStringRef message, WKFrameRef, const void*)
+{
+ webkitWebViewRunJavaScriptAlert(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), toImpl(message)->string().utf8());
+}
+
+static bool runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef, const void*)
+{
+ return webkitWebViewRunJavaScriptConfirm(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), toImpl(message)->string().utf8());
+}
+
+static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void*)
+{
+ return webkitWebViewRunJavaScriptPrompt(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()), toImpl(message)->string().utf8(),
+ toImpl(defaultValue)->string().utf8());
+}
+
void webkitUIClientAttachUIClientToPage(WebKitUIClient* uiClient, WKPageRef wkPage)
{
WKPageUIClient wkUIClient = {
@@ -54,9 +70,9 @@
0, // takeFocus
0, // focus
0, // unfocus
- 0, // runJavaScriptAlert
- 0, // runJavaScriptConfirm
- 0, // runJavaScriptPrompt
+ runJavaScriptAlert,
+ runJavaScriptConfirm,
+ runJavaScriptPrompt,
0, // setStatusText
0, // mouseDidMoveOverElement_deprecatedForUseWithV0
0, // missingPluginButtonClicked
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2011-12-13 13:31:55 UTC (rev 102675)
@@ -36,6 +36,7 @@
#include <WebKit2/WKBase.h>
#include <WebKit2/WKRetainPtr.h>
#include <WebKit2/WKURL.h>
+#include <wtf/gobject/GOwnPtr.h>
#include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h>
@@ -47,6 +48,10 @@
READY_TO_SHOW,
CLOSE,
+ SCRIPT_ALERT,
+ SCRIPT_CONFIRM,
+ SCRIPT_PROMPT,
+
LAST_SIGNAL
};
@@ -81,6 +86,49 @@
return 0;
}
+static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* message)
+{
+ GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(webView));
+ GtkWidget* dialog = gtk_message_dialog_new(gtk_widget_is_toplevel(parent) ? GTK_WINDOW(parent) : 0,
+ GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", message);
+ GOwnPtr<char> title(g_strdup_printf("_javascript_ - %s", webkit_web_view_get_uri(webView)));
+ gtk_window_set_title(GTK_WINDOW(dialog), title.get());
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
+
+ return dialog;
+}
+
+
+static gboolean webkitWebViewScriptAlert(WebKitWebView* webView, const char* message)
+{
+ GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ return TRUE;
+}
+
+static gboolean webkitWebViewScriptConfirm(WebKitWebView* webView, const char* message, gboolean* confirmed)
+{
+ GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message);
+ *confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
+ gtk_widget_destroy(dialog);
+ return TRUE;
+}
+
+static gboolean webkitWebViewScriptPrompt(WebKitWebView* webView, const char* message, const char* defaultText, char** text)
+{
+ GtkWidget* dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message);
+ GtkWidget* entry = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(entry), defaultText);
+ gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry);
+ gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
+ gtk_widget_show(entry);
+
+ *text = (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) ? g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))) : 0;
+ return TRUE;
+}
+
+
static void webkitWebViewSetLoaderClient(WebKitWebView* webView, WebKitWebLoaderClient* loaderClient, WKPageRef wkPage)
{
webView->priv->loaderClient = loaderClient;
@@ -179,6 +227,9 @@
gObjectClass->finalize = webkitWebViewFinalize;
webViewClass->create = webkitWebViewCreate;
+ webViewClass->script_alert = webkitWebViewScriptAlert;
+ webViewClass->script_confirm = webkitWebViewScriptConfirm;
+ webViewClass->script_prompt = webkitWebViewScriptPrompt;
g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
@@ -300,6 +351,78 @@
0, 0,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
+ /**
+ * WebKitWebView::script-alert:
+ * @web_view: the #WebKitWebView on which the signal is emitted
+ * @message: the message text
+ *
+ * Emitted when _javascript_ code calls <function>window.alert</function>. If the
+ * signal is not handled a message dialog with a single Close button will be
+ * shown with the message text.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[SCRIPT_ALERT] =
+ g_signal_new("script-alert",
+ G_TYPE_FROM_CLASS(webViewClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitWebViewClass, script_alert),
+ g_signal_accumulator_true_handled, 0,
+ webkit_marshal_BOOLEAN__STRING,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING);
+
+ /**
+ * WebKitWebView::script-confirm:
+ * @web_view: the #WebKitWebView on which the signal is emitted
+ * @message: the message text
+ * @confirmed: (out): return location for confirm dialog response
+ *
+ * Emitted when _javascript_ code calls <function>confirm</function>. If the
+ * signal is not handled a message dialog with OK and Cancel buttons will be
+ * shown with the message text. If OK button is clicked @confirmed will be
+ * set to %TRUE, otherwise it will be %FALSE.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[SCRIPT_CONFIRM] =
+ g_signal_new("script-confirm",
+ G_TYPE_FROM_CLASS(webViewClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm),
+ g_signal_accumulator_true_handled, 0,
+ webkit_marshal_BOOLEAN__STRING_POINTER,
+ G_TYPE_BOOLEAN, 2,
+ G_TYPE_STRING, G_TYPE_POINTER);
+
+ /**
+ * WebKitWebView::script-prompt:
+ * @web_view: the #WebKitWebView on which the signal is emitted
+ * @message: the message text
+ * @default (allow-none): the default text
+ * @text: (out): return location for prompt dialog text response
+ *
+ * Emitted when _javascript_ code calls <function>prompt</function>. If the
+ * signal is not handled a message dialog with OK and Cancel buttons and
+ * a text entry will be shown with the message text. If OK button is clicked
+ * @text will contain the text entered by the user, otherwise it will be %NULL.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[SCRIPT_PROMPT] =
+ g_signal_new("script-prompt",
+ G_TYPE_FROM_CLASS(webViewClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt),
+ g_signal_accumulator_true_handled, 0,
+ webkit_marshal_BOOLEAN__STRING_STRING_POINTER,
+ G_TYPE_BOOLEAN, 3,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
+
}
void webkitWebViewSetTitle(WebKitWebView* webView, const CString& title)
@@ -355,6 +478,27 @@
g_signal_emit(webView, signals[CLOSE], 0, NULL);
}
+void webkitWebViewRunJavaScriptAlert(WebKitWebView* webView, const CString& message)
+{
+ gboolean returnValue;
+ g_signal_emit(webView, signals[SCRIPT_ALERT], 0, message.data(), &returnValue);
+}
+
+bool webkitWebViewRunJavaScriptConfirm(WebKitWebView* webView, const CString& message)
+{
+ gboolean returnValue, confirmed;
+ g_signal_emit(webView, signals[SCRIPT_CONFIRM], 0, message.data(), &confirmed, &returnValue);
+ return confirmed;
+}
+
+WKStringRef webkitWebViewRunJavaScriptPrompt(WebKitWebView* webView, const CString& message, const CString& defaultText)
+{
+ gboolean returnValue;
+ GOwnPtr<char> text;
+ g_signal_emit(webView, signals[SCRIPT_PROMPT], 0, message.data(), defaultText.data(), &text.outPtr(), &returnValue);
+ return text ? WKStringCreateWithUTF8CString(text.get()) : 0;
+}
+
/**
* webkit_web_view_new:
*
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2011-12-13 13:31:55 UTC (rev 102675)
@@ -57,10 +57,20 @@
struct _WebKitWebViewClass {
WebKitWebViewBaseClass parent;
- GtkWidget *(* create) (WebKitWebView *web_view);
- void (* ready_to_show) (WebKitWebView *web_view);
- void (* close) (WebKitWebView *web_view);
+ GtkWidget *(* create) (WebKitWebView *web_view);
+ void (* ready_to_show) (WebKitWebView *web_view);
+ void (* close) (WebKitWebView *web_view);
+ gboolean (* script_alert) (WebKitWebView *web_view,
+ const gchar *message);
+ gboolean (* script_confirm) (WebKitWebView *web_view,
+ const gchar *message,
+ gboolean *confirmed);
+ gboolean (* script_prompt) (WebKitWebView *web_view,
+ const gchar *message,
+ const gchar *default_text,
+ gchar **text);
+
/* Padding for future expansion */
void (*_webkit_reserved0) (void);
void (*_webkit_reserved1) (void);
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h 2011-12-13 13:31:55 UTC (rev 102675)
@@ -28,6 +28,7 @@
#define WebKitWebViewPrivate_h
#include "WebKitWebView.h"
+#include <wtf/text/CString.h>
#include <WebKit2/WebKit2.h>
#include <wtf/text/CString.h>
@@ -37,5 +38,8 @@
WKPageRef webkitWebViewCreateNewPage(WebKitWebView*);
void webkitWebViewReadyToShowPage(WebKitWebView*);
void webkitWebViewClosePage(WebKitWebView*);
+void webkitWebViewRunJavaScriptAlert(WebKitWebView*, const CString& message);
+bool webkitWebViewRunJavaScriptConfirm(WebKitWebView*, const CString& message);
+WKStringRef webkitWebViewRunJavaScriptPrompt(WebKitWebView*, const CString& message, const CString& defaultText);
#endif // WebKitWebViewPrivate_h
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2011-12-13 13:31:55 UTC (rev 102675)
@@ -75,6 +75,11 @@
g_assert(webkit_settings_get_enable_javascript(settings));
}
+static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message";
+static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message";
+static const char* kPromptDialogMessage = "WebKitGTK+ prompt dialog message";
+static const char* kPromptDialogReturnedText = "WebKitGTK+ prompt dialog returned text";
+
class UIClientTest: public WebViewTest {
public:
MAKE_GLIB_TEST_FIXTURE(UIClientTest);
@@ -85,6 +90,12 @@
Close
};
+ enum ScriptType {
+ Alert,
+ Confirm,
+ Prompt
+ };
+
static void viewClose(WebKitWebView* webView, UIClientTest* test)
{
g_assert(webView != test->m_webView);
@@ -117,10 +128,56 @@
return newWebView;
}
+ static gboolean scriptAlert(WebKitWebView*, const char* message, UIClientTest* test)
+ {
+ switch (test->m_scriptType) {
+ case UIClientTest::Alert:
+ g_assert_cmpstr(message, ==, kAlertDialogMessage);
+ break;
+ case UIClientTest::Confirm:
+ g_assert(test->m_scriptDialogConfirmed);
+ g_assert_cmpstr(message, ==, "confirmed");
+
+ break;
+ case UIClientTest::Prompt:
+ g_assert_cmpstr(message, ==, kPromptDialogReturnedText);
+ break;
+ }
+
+ g_main_loop_quit(test->m_mainLoop);
+
+ return TRUE;
+ }
+
+ static gboolean scriptConfirm(WebKitWebView*, const char* message, gboolean* confirmed, UIClientTest* test)
+ {
+ g_assert_cmpstr(message, ==, kConfirmDialogMessage);
+ g_assert(confirmed);
+ test->m_scriptDialogConfirmed = !test->m_scriptDialogConfirmed;
+ *confirmed = test->m_scriptDialogConfirmed;
+
+ return TRUE;
+ }
+
+ static gboolean scriptPrompt(WebKitWebView*, const char* message, const char* defaultText, char **text, UIClientTest* test)
+ {
+ g_assert_cmpstr(message, ==, kPromptDialogMessage);
+ g_assert_cmpstr(defaultText, ==, "default");
+ g_assert(text);
+ *text = g_strdup(kPromptDialogReturnedText);
+
+ return TRUE;
+ }
+
UIClientTest()
+ : m_scriptType(Alert)
+ , m_scriptDialogConfirmed(true)
{
webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE);
g_signal_connect(m_webView, "create", G_CALLBACK(viewCreate), this);
+ g_signal_connect(m_webView, "script-alert", G_CALLBACK(scriptAlert), this);
+ g_signal_connect(m_webView, "script-confirm", G_CALLBACK(scriptConfirm), this);
+ g_signal_connect(m_webView, "script-prompt", G_CALLBACK(scriptPrompt), this);
}
~UIClientTest()
@@ -134,6 +191,8 @@
}
Vector<WebViewEvents> m_webViewEvents;
+ ScriptType m_scriptType;
+ bool m_scriptDialogConfirmed;
};
static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer)
@@ -148,6 +207,32 @@
g_assert_cmpint(events[2], ==, UIClientTest::Close);
}
+static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
+{
+ static const char* htmlOnLoadFormat = "<html><body _onLoad_=\"%s\"></body></html>";
+ static const char* jsAlertFormat = "alert('%s')";
+ static const char* jsConfirmFormat = "do { confirmed = confirm('%s'); } while (!confirmed); alert('confirmed');";
+ static const char* jsPromptFormat = "alert(prompt('%s', 'default'));";
+
+ test->m_scriptType = UIClientTest::Alert;
+ GOwnPtr<char> alertDialogMessage(g_strdup_printf(jsAlertFormat, kAlertDialogMessage));
+ GOwnPtr<char> alertHTML(g_strdup_printf(htmlOnLoadFormat, alertDialogMessage.get()));
+ test->loadHtml(alertHTML.get(), 0);
+ test->waitUntilMainLoopFinishes();
+
+ test->m_scriptType = UIClientTest::Confirm;
+ GOwnPtr<char> confirmDialogMessage(g_strdup_printf(jsConfirmFormat, kConfirmDialogMessage));
+ GOwnPtr<char> confirmHTML(g_strdup_printf(htmlOnLoadFormat, confirmDialogMessage.get()));
+ test->loadHtml(confirmHTML.get(), 0);
+ test->waitUntilMainLoopFinishes();
+
+ test->m_scriptType = UIClientTest::Prompt;
+ GOwnPtr<char> promptDialogMessage(g_strdup_printf(jsPromptFormat, kPromptDialogMessage));
+ GOwnPtr<char> promptHTML(g_strdup_printf(htmlOnLoadFormat, promptDialogMessage.get()));
+ test->loadHtml(promptHTML.get(), 0);
+ test->waitUntilMainLoopFinishes();
+}
+
void beforeAll()
{
WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext);
@@ -155,6 +240,7 @@
Test::add("WebKitWebView", "webviews-share-clients", testWebViewsShareClients);
WebViewTest::add("WebKitWebView", "settings", testWebViewSettings);
UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose);
+ UIClientTest::add("WebKitWebView", "_javascript_-dialogs", testWebViewJavaScriptDialogs);
}
void afterAll()
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list (102674 => 102675)
--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list 2011-12-13 13:28:32 UTC (rev 102674)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list 2011-12-13 13:31:55 UTC (rev 102675)
@@ -1,5 +1,8 @@
BOOLEAN:OBJECT,STRING,POINTER
BOOLEAN:OBJECT
+BOOLEAN:STRING
+BOOLEAN:STRING,POINTER
+BOOLEAN:STRING,STRING,POINTER
BOOLEAN:VOID
OBJECT:VOID
VOID:OBJECT,POINTER