Title: [217963] trunk
Revision
217963
Author
[email protected]
Date
2017-06-08 22:26:41 -0700 (Thu, 08 Jun 2017)

Log Message

[GTK] Use API::FormClient instead of the C API in WebKitFormClient
https://bugs.webkit.org/show_bug.cgi?id=173098

Reviewed by Žan Doberšek.

Source/WebKit2:

* UIProcess/API/gtk/WebKitFormClient.cpp:
(attachFormClientToView):
(willSubmitForm): Deleted.
* UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp:
(webkitFormSubmissionRequestCreate):
(webkit_form_submission_request_get_text_fields):
* UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h:
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkitWebPageCreate):

Tools:

Fix memory leak and runtime warning when running /webkit2/WebKitWebView/submit-form. The web extension is
assuming that all tests containing forms define ids for the form elements like
/webkit2/WebKitWebExtension/form-controls-associated-signal does.

* TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
(formControlsAssociatedCallback):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (217962 => 217963)


--- trunk/Source/WebKit2/ChangeLog	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Source/WebKit2/ChangeLog	2017-06-09 05:26:41 UTC (rev 217963)
@@ -1,5 +1,22 @@
 2017-06-08  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Use API::FormClient instead of the C API in WebKitFormClient
+        https://bugs.webkit.org/show_bug.cgi?id=173098
+
+        Reviewed by Žan Doberšek.
+
+        * UIProcess/API/gtk/WebKitFormClient.cpp:
+        (attachFormClientToView):
+        (willSubmitForm): Deleted.
+        * UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp:
+        (webkitFormSubmissionRequestCreate):
+        (webkit_form_submission_request_get_text_fields):
+        * UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h:
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (webkitWebPageCreate):
+
+2017-06-08  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Use API::Findclient instead of the C API in WebKitFindController
         https://bugs.webkit.org/show_bug.cgi?id=173095
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp (217962 => 217963)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp	2017-06-09 05:26:41 UTC (rev 217963)
@@ -20,7 +20,7 @@
 #include "config.h"
 #include "WebKitFormClient.h"
 
-#include "APIDictionary.h"
+#include "APIFormClient.h"
 #include "WebFormSubmissionListenerProxy.h"
 #include "WebKitFormSubmissionRequestPrivate.h"
 #include "WebKitPrivate.h"
@@ -30,21 +30,25 @@
 
 using namespace WebKit;
 
-static void willSubmitForm(WKPageRef, WKFrameRef, WKFrameRef, WKDictionaryRef values, WKTypeRef /* userData */, WKFormSubmissionListenerRef listener, const void* clientInfo)
-{
-    GRefPtr<WebKitFormSubmissionRequest> request = adoptGRef(webkitFormSubmissionRequestCreate(toImpl(values), toImpl(listener)));
-    webkitWebViewSubmitFormRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
-}
+class FormClient final : public API::FormClient {
+public:
+    explicit FormClient(WebKitWebView* webView)
+        : m_webView(webView)
+    {
+    }
 
+private:
+    void willSubmitForm(WebPageProxy&, WebFrameProxy&, WebFrameProxy&, const Vector<std::pair<String, String>>& values, API::Object*, Ref<WebFormSubmissionListenerProxy>&& listener) override
+    {
+        GRefPtr<WebKitFormSubmissionRequest> request = adoptGRef(webkitFormSubmissionRequestCreate(values, WTFMove(listener)));
+        webkitWebViewSubmitFormRequest(m_webView, request.get());
+    }
+
+    WebKitWebView* m_webView;
+};
+
 void attachFormClientToView(WebKitWebView* webView)
 {
-    WKPageFormClientV0 wkFormClient = {
-        {
-            0, // version
-            webView, // clientInfo
-        },
-        willSubmitForm
-    };
-    WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)));
-    WKPageSetPageFormClient(wkPage, &wkFormClient.base);
+    auto* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    page->setFormClient(std::make_unique<FormClient>(webView));
 }

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp (217962 => 217963)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp	2017-06-09 05:26:41 UTC (rev 217963)
@@ -45,7 +45,6 @@
  */
 
 struct _WebKitFormSubmissionRequestPrivate {
-    RefPtr<API::Dictionary> webValues;
     RefPtr<WebFormSubmissionListenerProxy> listener;
     GRefPtr<GHashTable> values;
     bool handledRequest;
@@ -70,11 +69,15 @@
     objectClass->dispose = webkitFormSubmissionRequestDispose;
 }
 
-WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(API::Dictionary* values, WebFormSubmissionListenerProxy* listener)
+WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std::pair<String, String>>& values, Ref<WebFormSubmissionListenerProxy>&& listener)
 {
-    WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST(g_object_new(WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, NULL));
-    request->priv->webValues = values;
-    request->priv->listener = listener;
+    WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST(g_object_new(WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, nullptr));
+    if (values.size()) {
+        request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free));
+        for (const auto& pair : values)
+            g_hash_table_insert(request->priv->values.get(), g_strdup(pair.first.utf8().data()), g_strdup(pair.second.utf8().data()));
+    }
+    request->priv->listener = WTFMove(listener);
     return request;
 }
 
@@ -90,25 +93,8 @@
  */
 GHashTable* webkit_form_submission_request_get_text_fields(WebKitFormSubmissionRequest* request)
 {
-    g_return_val_if_fail(WEBKIT_IS_FORM_SUBMISSION_REQUEST(request), 0);
+    g_return_val_if_fail(WEBKIT_IS_FORM_SUBMISSION_REQUEST(request), nullptr);
 
-    if (request->priv->values)
-        return request->priv->values.get();
-
-    if (!request->priv->webValues->size())
-        return nullptr;
-
-    request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free));
-
-    const API::Dictionary::MapType& map = request->priv->webValues->map();
-    API::Dictionary::MapType::const_iterator end = map.end();
-    for (API::Dictionary::MapType::const_iterator it = map.begin(); it != end; ++it) {
-        API::String* value = static_cast<API::String*>(it->value.get());
-        g_hash_table_insert(request->priv->values.get(), g_strdup(it->key.utf8().data()), g_strdup(value->string().utf8().data()));
-    }
-
-    request->priv->webValues = nullptr;
-
     return request->priv->values.get();
 }
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h (217962 => 217963)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h	2017-06-09 05:26:41 UTC (rev 217963)
@@ -17,12 +17,9 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef WebKitFormSubmissionRequestPrivate_h
-#define WebKitFormSubmissionRequestPrivate_h
+#pragma once
 
 #include "WebKitFormSubmissionRequest.h"
 #include "WebKitPrivate.h"
 
-WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(API::Dictionary* values, WebKit::WebFormSubmissionListenerProxy*);
-
-#endif // WebKitFormSubmissionRequestPrivate_h
+WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std::pair<String, String>>&, Ref<WebKit::WebFormSubmissionListenerProxy>&&);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (217962 => 217963)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2017-06-09 05:26:41 UTC (rev 217963)
@@ -341,9 +341,9 @@
     WebKitWebPage* m_webPage;
 };
 
-class FormClient final : public API::InjectedBundle::FormClient {
+class PageFormClient final : public API::InjectedBundle::FormClient {
 public:
-    explicit FormClient(WebKitWebPage* webPage)
+    explicit PageFormClient(WebKitWebPage* webPage)
         : m_webPage(webPage)
     {
     }
@@ -595,7 +595,7 @@
 
     webPage->setInjectedBundleContextMenuClient(std::make_unique<PageContextMenuClient>(page));
     webPage->setInjectedBundleUIClient(std::make_unique<PageUIClient>(page));
-    webPage->setInjectedBundleFormClient(std::make_unique<FormClient>(page));
+    webPage->setInjectedBundleFormClient(std::make_unique<PageFormClient>(page));
 
     return page;
 }

Modified: trunk/Tools/ChangeLog (217962 => 217963)


--- trunk/Tools/ChangeLog	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Tools/ChangeLog	2017-06-09 05:26:41 UTC (rev 217963)
@@ -1,3 +1,17 @@
+2017-06-08  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Use API::FormClient instead of the C API in WebKitFormClient
+        https://bugs.webkit.org/show_bug.cgi?id=173098
+
+        Reviewed by Žan Doberšek.
+
+        Fix memory leak and runtime warning when running /webkit2/WebKitWebView/submit-form. The web extension is
+        assuming that all tests containing forms define ids for the form elements like
+        /webkit2/WebKitWebExtension/form-controls-associated-signal does.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
+        (formControlsAssociatedCallback):
+
 2017-06-08  Jonathan Bedard  <[email protected]>
 
         webkitpy: Run sample/spindump on iOS devices

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp (217962 => 217963)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp	2017-06-09 05:25:02 UTC (rev 217962)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp	2017-06-09 05:26:41 UTC (rev 217963)
@@ -262,8 +262,14 @@
     for (int i = 0; i < formElements->len; ++i) {
         g_assert(WEBKIT_DOM_IS_ELEMENT(g_ptr_array_index(formElements, i)));
         auto domElement = WEBKIT_DOM_ELEMENT(g_ptr_array_index(formElements, i));
-        g_string_append(formIdsBuilder, webkit_dom_element_get_id(domElement));
+        GUniquePtr<char> elementID(webkit_dom_element_get_id(domElement));
+        if (elementID)
+            g_string_append(formIdsBuilder, elementID.get());
     }
+    if (!formIdsBuilder->len) {
+        g_string_free(formIdsBuilder, TRUE);
+        return;
+    }
     GUniquePtr<char> formIds(g_string_free(formIdsBuilder, FALSE));
     gpointer data = "" "dbus-connection");
     if (data)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to