[GTK] Implement JavaScript dialog methods of API::AutomationSessionClient
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Aug 2017 06:25:23 +0000 (06:25 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Aug 2017 06:25:23 +0000 (06:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175259

Reviewed by Michael Catanzaro.

Source/WebCore/platform/gtk/po:

* POTFILES.in: Add WebKitScriptDialogGtk.cpp.

Source/WebKit:

Move the default implementation of WebKitScriptDialog from WebKitWebView platform specific files to their own
files. Implement all JavaScript dialog methods of API::AutomationSessionClient in WebKitAutomationSession. For
now it only works when the user doesn't override WebKitWebView::script-dialog signal and default implementation
is used.

* PlatformGTK.cmake: Add new files to compilation.
* PlatformWPE.cmake: Ditto.
* UIProcess/API/glib/WebKitAutomationSession.cpp:
(webkitAutomationSessionCreate): Pass the WebKitWebContext to the constructor and keep a pointer to it in session.
* UIProcess/API/glib/WebKitAutomationSessionPrivate.h:
* UIProcess/API/glib/WebKitScriptDialogPrivate.h:
* UIProcess/API/glib/WebKitWebContext.cpp:
* UIProcess/API/glib/WebKitWebView.cpp:
(webkitWebViewRunJavaScriptAlert): Set the currently script dialog for the scope of the function.
(webkitWebViewRunJavaScriptConfirm): Ditto.
(webkitWebViewRunJavaScriptPrompt): Ditto.
(webkitWebViewRunJavaScriptBeforeUnloadConfirm): Ditto.
(webkitWebViewIsShowingScriptDialog): Ask current dialog if there's one.
(webkitWebViewGetCurrentScriptDialogMessage): Ditto.
(webkitWebViewSetCurrentScriptDialogUserInput): Ditto.
(webkitWebViewAcceptCurrentScriptDialog): Ditto.
(webkitWebViewDismissCurrentScriptDialog): Ditto.
* UIProcess/API/glib/WebKitWebViewPrivate.h:
* UIProcess/API/gtk/WebKitScriptDialogGtk.cpp: Added.
(webkitWebViewCreateJavaScriptDialog): Moved from WebKitWebViewGtk.cpp.
(webkitScriptDialogRun): Run the dialog, this code is moved from WebKitWebViewGtk.cpp.
(webkitScriptDialogIsRunning): Return true if the script dialog has a native dialog running.
(webkitScriptDialogAccept): Send Ok or Close response to the native dialog depending on the dialog type.
(webkitScriptDialogDismiss): Send Close response to the native dialog.
(webkitScriptDialogSetUserInput): Set the given text on the prompt dialog entry.
* UIProcess/API/gtk/WebKitWebViewGtk.cpp:
(webkitWebViewScriptDialog): Simply call webkitScriptDialogRun() now.
* UIProcess/API/wpe/WebKitScriptDialogWPE.cpp: Copied from Source/WebKit/UIProcess/API/glib/WebKitAutomationSessionPrivate.h.
(webkitScriptDialogRun):
(webkitScriptDialogIsRunning):
(webkitScriptDialogAccept):
(webkitScriptDialogDismiss):
(webkitScriptDialogSetUserInput):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220387 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/platform/gtk/po/ChangeLog
Source/WebCore/platform/gtk/po/POTFILES.in
Source/WebKit/ChangeLog
Source/WebKit/PlatformGTK.cmake
Source/WebKit/PlatformWPE.cmake
Source/WebKit/UIProcess/API/glib/WebKitAutomationSession.cpp
Source/WebKit/UIProcess/API/glib/WebKitAutomationSessionPrivate.h
Source/WebKit/UIProcess/API/glib/WebKitScriptDialogPrivate.h
Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp
Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp
Source/WebKit/UIProcess/API/glib/WebKitWebViewPrivate.h
Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp
Source/WebKit/UIProcess/API/wpe/WebKitScriptDialogWPE.cpp [new file with mode: 0644]

index 96df037..0ffcee0 100644 (file)
@@ -1,3 +1,12 @@
+2017-08-07  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Implement JavaScript dialog methods of API::AutomationSessionClient
+        https://bugs.webkit.org/show_bug.cgi?id=175259
+
+        Reviewed by Michael Catanzaro.
+
+        * POTFILES.in: Add WebKitScriptDialogGtk.cpp.
+
 2017-07-13  Matthew Hanson  <matthew_hanson@apple.com>
 
         Fix the cMake builds (GTK and WPE.)
index 899fcd4..533df6f 100644 (file)
@@ -30,6 +30,7 @@ LocalizedStringsGtk.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitColorChooserRequest.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitPrintCustomWidget.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitPrintOperation.cpp
+../../../WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebInspector.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp
index bc38b6c..021507d 100644 (file)
@@ -1,3 +1,49 @@
+2017-08-07  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Implement JavaScript dialog methods of API::AutomationSessionClient
+        https://bugs.webkit.org/show_bug.cgi?id=175259
+
+        Reviewed by Michael Catanzaro.
+
+        Move the default implementation of WebKitScriptDialog from WebKitWebView platform specific files to their own
+        files. Implement all JavaScript dialog methods of API::AutomationSessionClient in WebKitAutomationSession. For
+        now it only works when the user doesn't override WebKitWebView::script-dialog signal and default implementation
+        is used.
+
+        * PlatformGTK.cmake: Add new files to compilation.
+        * PlatformWPE.cmake: Ditto.
+        * UIProcess/API/glib/WebKitAutomationSession.cpp:
+        (webkitAutomationSessionCreate): Pass the WebKitWebContext to the constructor and keep a pointer to it in session.
+        * UIProcess/API/glib/WebKitAutomationSessionPrivate.h:
+        * UIProcess/API/glib/WebKitScriptDialogPrivate.h:
+        * UIProcess/API/glib/WebKitWebContext.cpp:
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkitWebViewRunJavaScriptAlert): Set the currently script dialog for the scope of the function.
+        (webkitWebViewRunJavaScriptConfirm): Ditto.
+        (webkitWebViewRunJavaScriptPrompt): Ditto.
+        (webkitWebViewRunJavaScriptBeforeUnloadConfirm): Ditto.
+        (webkitWebViewIsShowingScriptDialog): Ask current dialog if there's one.
+        (webkitWebViewGetCurrentScriptDialogMessage): Ditto.
+        (webkitWebViewSetCurrentScriptDialogUserInput): Ditto.
+        (webkitWebViewAcceptCurrentScriptDialog): Ditto.
+        (webkitWebViewDismissCurrentScriptDialog): Ditto.
+        * UIProcess/API/glib/WebKitWebViewPrivate.h:
+        * UIProcess/API/gtk/WebKitScriptDialogGtk.cpp: Added.
+        (webkitWebViewCreateJavaScriptDialog): Moved from WebKitWebViewGtk.cpp.
+        (webkitScriptDialogRun): Run the dialog, this code is moved from WebKitWebViewGtk.cpp.
+        (webkitScriptDialogIsRunning): Return true if the script dialog has a native dialog running.
+        (webkitScriptDialogAccept): Send Ok or Close response to the native dialog depending on the dialog type.
+        (webkitScriptDialogDismiss): Send Close response to the native dialog.
+        (webkitScriptDialogSetUserInput): Set the given text on the prompt dialog entry.
+        * UIProcess/API/gtk/WebKitWebViewGtk.cpp:
+        (webkitWebViewScriptDialog): Simply call webkitScriptDialogRun() now.
+        * UIProcess/API/wpe/WebKitScriptDialogWPE.cpp: Copied from Source/WebKit/UIProcess/API/glib/WebKitAutomationSessionPrivate.h.
+        (webkitScriptDialogRun):
+        (webkitScriptDialogIsRunning):
+        (webkitScriptDialogAccept):
+        (webkitScriptDialogDismiss):
+        (webkitScriptDialogSetUserInput):
+
 2017-08-07  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Preview Canvas path when viewing a recording
index 2fc1f2b..2594988 100644 (file)
@@ -183,6 +183,7 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/gtk/WebKitPrintCustomWidget.cpp
     UIProcess/API/gtk/WebKitPrintOperation.cpp
     UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp
+    UIProcess/API/gtk/WebKitScriptDialogGtk.cpp
     UIProcess/API/gtk/WebKitVersion.cpp
     UIProcess/API/gtk/WebKitVersion.h.in
     UIProcess/API/gtk/WebKitWebInspector.cpp
index f30e6c2..419dceb 100644 (file)
@@ -190,6 +190,7 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/wpe/CompositingManagerProxy.cpp
     UIProcess/API/wpe/PageClientImpl.cpp
     UIProcess/API/wpe/ScrollGestureController.cpp
+    UIProcess/API/wpe/WebKitScriptDialogWPE.cpp
     UIProcess/API/wpe/WebKitWebViewWPE.cpp
     UIProcess/API/wpe/WPEView.cpp
 
index 96cc292..ed50baf 100644 (file)
@@ -23,6 +23,7 @@
 #include "APIAutomationSessionClient.h"
 #include "WebKitApplicationInfo.h"
 #include "WebKitAutomationSessionPrivate.h"
+#include "WebKitWebContextPrivate.h"
 #include "WebKitWebViewPrivate.h"
 #include <glib/gi18n-lib.h>
 #include <wtf/glib/WTFGType.h>
@@ -60,6 +61,7 @@ enum {
 struct _WebKitAutomationSessionPrivate {
     RefPtr<WebAutomationSession> session;
     WebKitApplicationInfo* applicationInfo;
+    WebKitWebContext* webContext;
     CString id;
 };
 
@@ -90,6 +92,46 @@ private:
         return &webkitWebViewGetPage(webView);
     }
 
+    bool isShowingJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy& page) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return false;
+        return webkitWebViewIsShowingScriptDialog(webView);
+    }
+
+    void dismissCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy& page) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return;
+        webkitWebViewDismissCurrentScriptDialog(webView);
+    }
+
+    void acceptCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy& page) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return;
+        webkitWebViewAcceptCurrentScriptDialog(webView);
+    }
+
+    String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy& page) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return { };
+        return webkitWebViewGetCurrentScriptDialogMessage(webView);
+    }
+
+    void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession&, WebPageProxy& page, const String& userInput) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return;
+        webkitWebViewSetCurrentScriptDialogUserInput(webView, userInput);
+    }
+
     WebKitAutomationSession* m_session;
 };
 
@@ -192,9 +234,11 @@ static void webkit_automation_session_class_init(WebKitAutomationSessionClass* s
         G_TYPE_NONE);
 }
 
-WebKitAutomationSession* webkitAutomationSessionCreate(const char* sessionID)
+WebKitAutomationSession* webkitAutomationSessionCreate(WebKitWebContext* webContext, const char* sessionID)
 {
-    return WEBKIT_AUTOMATION_SESSION(g_object_new(WEBKIT_TYPE_AUTOMATION_SESSION, "id", sessionID, nullptr));
+    auto* session = WEBKIT_AUTOMATION_SESSION(g_object_new(WEBKIT_TYPE_AUTOMATION_SESSION, "id", sessionID, nullptr));
+    session->priv->webContext = webContext;
+    return session;
 }
 
 WebAutomationSession& webkitAutomationSessionGetSession(WebKitAutomationSession* session)
index 40cd932..ae2a2cc 100644 (file)
@@ -21,8 +21,9 @@
 
 #include "WebAutomationSession.h"
 #include "WebKitAutomationSession.h"
+#include "WebKitWebContext.h"
 
-WebKitAutomationSession* webkitAutomationSessionCreate(const char* sessionID);
+WebKitAutomationSession* webkitAutomationSessionCreate(WebKitWebContext*, const char* sessionID);
 WebKit::WebAutomationSession& webkitAutomationSessionGetSession(WebKitAutomationSession*);
 String webkitAutomationSessionGetBrowserName(WebKitAutomationSession*);
 String webkitAutomationSessionGetBrowserVersion(WebKitAutomationSession*);
index 5f1a43d..00da6ed 100644 (file)
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef WebKitScriptDialogPrivate_h
-#define WebKitScriptDialogPrivate_h
+#pragma once
 
 #include "WebKitScriptDialog.h"
+#include "WebKitWebView.h"
 #include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
 
 struct _WebKitScriptDialog {
     _WebKitScriptDialog(unsigned type, const CString& message)
@@ -55,6 +56,14 @@ struct _WebKitScriptDialog {
 
     bool confirmed;
     CString text;
+
+#if PLATFORM(GTK)
+    GtkWidget* nativeDialog { nullptr };
+#endif
 };
 
-#endif // WebKitScriptDialogPrivate_h
+void webkitScriptDialogRun(WebKitScriptDialog*, WebKitWebView*);
+bool webkitScriptDialogIsRunning(WebKitScriptDialog*);
+void webkitScriptDialogAccept(WebKitScriptDialog*);
+void webkitScriptDialogDismiss(WebKitScriptDialog*);
+void webkitScriptDialogSetUserInput(WebKitScriptDialog*, const String&);
index 4ab901e..3a0b4f3 100644 (file)
@@ -233,7 +233,7 @@ private:
     void requestAutomationSession(const String& sessionIdentifier) override
     {
         ASSERT(!m_webContext->priv->automationSession);
-        m_webContext->priv->automationSession = adoptGRef(webkitAutomationSessionCreate(sessionIdentifier.utf8().data()));
+        m_webContext->priv->automationSession = adoptGRef(webkitAutomationSessionCreate(m_webContext, sessionIdentifier.utf8().data()));
         g_signal_emit(m_webContext, signals[AUTOMATION_STARTED], 0, m_webContext->priv->automationSession.get());
         m_webContext->priv->processPool->setAutomationSession(&webkitAutomationSessionGetSession(m_webContext->priv->automationSession.get()));
     }
index f2f8b68..0bf7b94 100644 (file)
@@ -66,6 +66,7 @@
 #include <WebCore/JSDOMExceptionHandling.h>
 #include <WebCore/RefPtrCairo.h>
 #include <glib/gi18n-lib.h>
+#include <wtf/SetForScope.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/WTFGType.h>
 #include <wtf/text/CString.h>
@@ -219,6 +220,8 @@ struct _WebKitWebViewPrivate {
     GRefPtr<WebKitWebResource> mainResource;
     LoadingResourcesMap loadingResourcesMap;
 
+    WebKitScriptDialog* currentScriptDialog;
+
 #if PLATFORM(GTK)
     GRefPtr<WebKitWebInspector> inspector;
 #endif
@@ -2008,6 +2011,7 @@ void webkitWebViewClosePage(WebKitWebView* webView)
 void webkitWebViewRunJavaScriptAlert(WebKitWebView* webView, const CString& message)
 {
     WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_ALERT, message);
+    SetForScope<WebKitScriptDialog*> change(webView->priv->currentScriptDialog, &dialog);
     gboolean returnValue;
     g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue);
 }
@@ -2015,6 +2019,7 @@ void webkitWebViewRunJavaScriptAlert(WebKitWebView* webView, const CString& mess
 bool webkitWebViewRunJavaScriptConfirm(WebKitWebView* webView, const CString& message)
 {
     WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_CONFIRM, message);
+    SetForScope<WebKitScriptDialog*> change(webView->priv->currentScriptDialog, &dialog);
     gboolean returnValue;
     g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue);
     return dialog.confirmed;
@@ -2023,6 +2028,7 @@ bool webkitWebViewRunJavaScriptConfirm(WebKitWebView* webView, const CString& me
 CString webkitWebViewRunJavaScriptPrompt(WebKitWebView* webView, const CString& message, const CString& defaultText)
 {
     WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_PROMPT, message, defaultText);
+    SetForScope<WebKitScriptDialog*> change(webView->priv->currentScriptDialog, &dialog);
     gboolean returnValue;
     g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue);
     return dialog.text;
@@ -2031,11 +2037,59 @@ CString webkitWebViewRunJavaScriptPrompt(WebKitWebView* webView, const CString&
 bool webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView* webView, const CString& message)
 {
     WebKitScriptDialog dialog(WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM, message);
+    SetForScope<WebKitScriptDialog*> change(webView->priv->currentScriptDialog, &dialog);
     gboolean returnValue;
     g_signal_emit(webView, signals[SCRIPT_DIALOG], 0, &dialog, &returnValue);
     return dialog.confirmed;
 }
 
+bool webkitWebViewIsShowingScriptDialog(WebKitWebView* webView)
+{
+    if (!webView->priv->currentScriptDialog)
+        return false;
+
+    // FIXME: Add API to ask the user in case default implementation is not being used.
+    return webkitScriptDialogIsRunning(webView->priv->currentScriptDialog);
+}
+
+String webkitWebViewGetCurrentScriptDialogMessage(WebKitWebView* webView)
+{
+    if (!webView->priv->currentScriptDialog)
+        return { };
+
+    return String::fromUTF8(webView->priv->currentScriptDialog->message);
+}
+
+void webkitWebViewSetCurrentScriptDialogUserInput(WebKitWebView* webView, const String& userInput)
+{
+    if (!webView->priv->currentScriptDialog)
+        return;
+
+    // FIXME: Add API to ask the user in case default implementation is not being used.
+    if (webkitScriptDialogIsRunning(webView->priv->currentScriptDialog))
+        webkitScriptDialogSetUserInput(webView->priv->currentScriptDialog, userInput);
+}
+
+void webkitWebViewAcceptCurrentScriptDialog(WebKitWebView* webView)
+{
+    if (!webView->priv->currentScriptDialog)
+        return;
+
+    // FIXME: Add API to ask the user in case default implementation is not being used.
+    if (webkitScriptDialogIsRunning(webView->priv->currentScriptDialog))
+        webkitScriptDialogAccept(webView->priv->currentScriptDialog);
+}
+
+void webkitWebViewDismissCurrentScriptDialog(WebKitWebView* webView)
+{
+    if (!webView->priv->currentScriptDialog)
+        return;
+
+    // FIXME: Add API to ask the user in case default implementation is not being used.
+    if (webkitScriptDialogIsRunning(webView->priv->currentScriptDialog))
+        webkitScriptDialogDismiss(webView->priv->currentScriptDialog);
+}
+
 void webkitWebViewMakePolicyDecision(WebKitWebView* webView, WebKitPolicyDecisionType type, WebKitPolicyDecision* decision)
 {
     gboolean returnValue;
index afb83bf..f3c296f 100644 (file)
@@ -53,6 +53,12 @@ void webkitWebViewRunJavaScriptAlert(WebKitWebView*, const CString& message);
 bool webkitWebViewRunJavaScriptConfirm(WebKitWebView*, const CString& message);
 CString webkitWebViewRunJavaScriptPrompt(WebKitWebView*, const CString& message, const CString& defaultText);
 bool webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView*, const CString& message);
+bool webkitWebViewIsShowingScriptDialog(WebKitWebView*);
+bool webkitWebViewIsScriptDialogRunning(WebKitWebView*, WebKitScriptDialog*);
+String webkitWebViewGetCurrentScriptDialogMessage(WebKitWebView*);
+void webkitWebViewSetCurrentScriptDialogUserInput(WebKitWebView*, const String&);
+void webkitWebViewAcceptCurrentScriptDialog(WebKitWebView*);
+void webkitWebViewDismissCurrentScriptDialog(WebKitWebView*);
 void webkitWebViewMakePermissionRequest(WebKitWebView*, WebKitPermissionRequest*);
 void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*);
 void webkitWebViewMouseTargetChanged(WebKitWebView*, const WebKit::WebHitTestResultData&, WebKit::WebEvent::Modifiers);
diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp b/Source/WebKit/UIProcess/API/gtk/WebKitScriptDialogGtk.cpp
new file mode 100644 (file)
index 0000000..da40482
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitScriptDialog.h"
+
+#include "WebKitScriptDialogPrivate.h"
+#include "WebKitWebViewPrivate.h"
+#include <WebCore/GtkUtilities.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <wtf/glib/GUniquePtr.h>
+
+static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* primaryText, const char* secondaryText = nullptr)
+{
+    GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(webView));
+    GtkWidget* dialog = gtk_message_dialog_new(WebCore::widgetIsOnscreenToplevelWindow(parent) ? GTK_WINDOW(parent) : nullptr,
+        GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", primaryText);
+    if (secondaryText)
+        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", secondaryText);
+    GUniquePtr<char> title(g_strdup_printf("JavaScript - %s", webkitWebViewGetPage(webView).pageLoadState().url().utf8().data()));
+    gtk_window_set_title(GTK_WINDOW(dialog), title.get());
+    if (buttons != GTK_BUTTONS_NONE)
+        gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
+
+    return dialog;
+}
+
+void webkitScriptDialogRun(WebKitScriptDialog* scriptDialog, WebKitWebView* webView)
+{
+    GtkWidget* dialog = nullptr;
+
+    switch (scriptDialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT:
+        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, scriptDialog->message.data());
+        scriptDialog->nativeDialog = dialog;
+        gtk_dialog_run(GTK_DIALOG(dialog));
+        break;
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
+        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
+        scriptDialog->nativeDialog = dialog;
+        scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
+        break;
+    case WEBKIT_SCRIPT_DIALOG_PROMPT: {
+        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
+        scriptDialog->nativeDialog = dialog;
+        GtkWidget* entry = gtk_entry_new();
+        gtk_entry_set_text(GTK_ENTRY(entry), scriptDialog->defaultText.data());
+        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);
+        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
+            scriptDialog->text = gtk_entry_get_text(GTK_ENTRY(entry));
+        break;
+    }
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
+        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, GTK_RESPONSE_OK,
+            _("Are you sure you want to leave this page?"), scriptDialog->message.data());
+        scriptDialog->nativeDialog = dialog;
+        gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Stay on Page"), GTK_RESPONSE_CLOSE, _("Leave Page"), GTK_RESPONSE_OK, nullptr);
+        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
+        scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
+        break;
+    }
+
+    gtk_widget_destroy(dialog);
+    scriptDialog->nativeDialog = nullptr;
+}
+
+bool webkitScriptDialogIsRunning(WebKitScriptDialog* scriptDialog)
+{
+    return !!scriptDialog->nativeDialog;
+}
+
+void webkitScriptDialogAccept(WebKitScriptDialog* scriptDialog)
+{
+    int response = 0;
+    switch (scriptDialog->type) {
+    case WEBKIT_SCRIPT_DIALOG_ALERT:
+        response = GTK_RESPONSE_CLOSE;
+        break;
+    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
+    case WEBKIT_SCRIPT_DIALOG_PROMPT:
+    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
+        response = GTK_RESPONSE_OK;
+        break;
+    }
+    ASSERT(scriptDialog->nativeDialog);
+    gtk_dialog_response(GTK_DIALOG(scriptDialog->nativeDialog), response);
+}
+
+void webkitScriptDialogDismiss(WebKitScriptDialog* scriptDialog)
+{
+    ASSERT(scriptDialog->nativeDialog);
+    gtk_dialog_response(GTK_DIALOG(scriptDialog->nativeDialog), GTK_RESPONSE_CLOSE);
+}
+
+void webkitScriptDialogSetUserInput(WebKitScriptDialog* scriptDialog, const String& userInput)
+{
+    if (scriptDialog->type != WEBKIT_SCRIPT_DIALOG_PROMPT)
+        return;
+
+    ASSERT(scriptDialog->nativeDialog);
+    GtkWidget* dialogContentArea = gtk_dialog_get_content_area(GTK_DIALOG(scriptDialog->nativeDialog));
+    GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(dialogContentArea)));
+    for (GList* child = children.get(); child; child = g_list_next(child)) {
+        GtkWidget* childWidget = GTK_WIDGET(child->data);
+        if (GTK_IS_ENTRY(childWidget)) {
+            gtk_entry_set_text(GTK_ENTRY(childWidget), userInput.utf8().data());
+            break;
+        }
+    }
+}
index c7f4e1e..c12eda0 100644 (file)
@@ -36,56 +36,9 @@ gboolean webkitWebViewAuthenticate(WebKitWebView* webView, WebKitAuthenticationR
     return TRUE;
 }
 
-static GtkWidget* webkitWebViewCreateJavaScriptDialog(WebKitWebView* webView, GtkMessageType type, GtkButtonsType buttons, int defaultResponse, const char* primaryText, const char* secondaryText = nullptr)
-{
-    GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(webView));
-    GtkWidget* dialog = gtk_message_dialog_new(WebCore::widgetIsOnscreenToplevelWindow(parent) ? GTK_WINDOW(parent) : nullptr,
-        GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", primaryText);
-    if (secondaryText)
-        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", secondaryText);
-    GUniquePtr<char> title(g_strdup_printf("JavaScript - %s", webkitWebViewGetPage(webView).pageLoadState().url().utf8().data()));
-    gtk_window_set_title(GTK_WINDOW(dialog), title.get());
-    if (buttons != GTK_BUTTONS_NONE)
-        gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
-
-    return dialog;
-}
-
 gboolean webkitWebViewScriptDialog(WebKitWebView* webView, WebKitScriptDialog* scriptDialog)
 {
-    GtkWidget* dialog = 0;
-
-    switch (scriptDialog->type) {
-    case WEBKIT_SCRIPT_DIALOG_ALERT:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, scriptDialog->message.data());
-        gtk_dialog_run(GTK_DIALOG(dialog));
-        break;
-    case WEBKIT_SCRIPT_DIALOG_CONFIRM:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
-        scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
-        break;
-    case WEBKIT_SCRIPT_DIALOG_PROMPT: {
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, scriptDialog->message.data());
-        GtkWidget* entry = gtk_entry_new();
-        gtk_entry_set_text(GTK_ENTRY(entry), scriptDialog->defaultText.data());
-        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);
-        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
-            scriptDialog->text = gtk_entry_get_text(GTK_ENTRY(entry));
-        break;
-    }
-    case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
-        dialog = webkitWebViewCreateJavaScriptDialog(webView, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, GTK_RESPONSE_OK,
-            _("Are you sure you want to leave this page?"), scriptDialog->message.data());
-        gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Stay on Page"), GTK_RESPONSE_CLOSE, _("Leave Page"), GTK_RESPONSE_OK, nullptr);
-        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
-        scriptDialog->confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
-        break;
-    }
-
-    gtk_widget_destroy(dialog);
-
+    webkitScriptDialogRun(scriptDialog, webView);
     return TRUE;
 }
 
diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitScriptDialogWPE.cpp b/Source/WebKit/UIProcess/API/wpe/WebKitScriptDialogWPE.cpp
new file mode 100644 (file)
index 0000000..698a23f
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitScriptDialog.h"
+
+#include "WebKitScriptDialogPrivate.h"
+
+void webkitScriptDialogRun(WebKitScriptDialog*, WebKitWebView*)
+{
+}
+
+bool webkitScriptDialogIsRunning(WebKitScriptDialog*)
+{
+    return false;
+}
+
+void webkitScriptDialogAccept(WebKitScriptDialog*)
+{
+}
+
+void webkitScriptDialogDismiss(WebKitScriptDialog*)
+{
+}
+
+void webkitScriptDialogSetUserInput(WebKitScriptDialog*, const String&)
+{
+}