Skip to content

Commit 10ee377

Browse files
[WPE][GTK] Deprecate and replace webkit_form_submission_request_get_text_fields
https://bugs.webkit.org/show_bug.cgi?id=176725 Reviewed by Carlos Garcia Campos. Source/WebKit: The problem is this function returns results in a GHashTable, but many fields can have the same name, or no name at all, and those fields are currently just dropped. It's impossible to fix, since the GHashTable is part of the API, so deprecate it and add a new function that returns two GPtrArrays instead. * UIProcess/API/glib/WebKitFormSubmissionRequest.cpp: (webkitFormSubmissionRequestCreate): (webkit_form_submission_request_get_text_fields): (webkit_form_submission_request_list_text_fields): * UIProcess/API/gtk/WebKitFormSubmissionRequest.h: * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: * UIProcess/API/wpe/WebKitFormSubmissionRequest.h: Tools: Test the new function. * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp: (testWebViewSubmitForm): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@226264 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a673d7f commit 10ee377

File tree

7 files changed

+155
-26
lines changed

7 files changed

+155
-26
lines changed

Source/WebKit/ChangeLog

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2017-12-21 Michael Catanzaro <[email protected]>
2+
3+
[WPE][GTK] Deprecate and replace webkit_form_submission_request_get_text_fields
4+
https://bugs.webkit.org/show_bug.cgi?id=176725
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
The problem is this function returns results in a GHashTable, but many fields can have the
9+
same name, or no name at all, and those fields are currently just dropped. It's impossible
10+
to fix, since the GHashTable is part of the API, so deprecate it and add a new function that
11+
returns two GPtrArrays instead.
12+
13+
* UIProcess/API/glib/WebKitFormSubmissionRequest.cpp:
14+
(webkitFormSubmissionRequestCreate):
15+
(webkit_form_submission_request_get_text_fields):
16+
(webkit_form_submission_request_list_text_fields):
17+
* UIProcess/API/gtk/WebKitFormSubmissionRequest.h:
18+
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
19+
* UIProcess/API/wpe/WebKitFormSubmissionRequest.h:
20+
121
2017-12-21 Youenn Fablet <[email protected]>
222

323
ServiceWorkerThreadProxy should set the correct cookie and cache partitioning options

Source/WebKit/UIProcess/API/glib/WebKitFormSubmissionRequest.cpp

+59-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "WebFormSubmissionListenerProxy.h"
2626
#include "WebKitFormSubmissionRequestPrivate.h"
2727
#include <wtf/glib/GRefPtr.h>
28+
#include <wtf/glib/GUniquePtr.h>
2829
#include <wtf/glib/WTFGType.h>
2930
#include <wtf/text/CString.h>
3031

@@ -38,15 +39,15 @@ using namespace WebKit;
3839
* When a form is about to be submitted in a #WebKitWebView, the
3940
* #WebKitWebView::submit-form signal is emitted. Its request argument
4041
* contains information about the text fields of the form, that are
41-
* typically used to store login information, returned in a
42-
* #GHashTable by the webkit_form_submission_request_get_text_fields()
43-
* method, and you can finally submit the form with
44-
* webkit_form_submission_request_submit().
45-
*
42+
* typically used to store login information, returned as lists by
43+
* webkit_form_submission_request_list_text_fields(). You can submit the
44+
* form with webkit_form_submission_request_submit().
4645
*/
4746

4847
struct _WebKitFormSubmissionRequestPrivate {
4948
RefPtr<WebFormSubmissionListenerProxy> listener;
49+
GRefPtr<GPtrArray> textFieldNames;
50+
GRefPtr<GPtrArray> textFieldValues;
5051
GRefPtr<GHashTable> values;
5152
bool handledRequest;
5253
};
@@ -74,9 +75,12 @@ WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std:
7475
{
7576
WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST(g_object_new(WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, nullptr));
7677
if (values.size()) {
77-
request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free));
78-
for (const auto& pair : values)
79-
g_hash_table_insert(request->priv->values.get(), g_strdup(pair.first.utf8().data()), g_strdup(pair.second.utf8().data()));
78+
request->priv->textFieldNames = adoptGRef(g_ptr_array_new_full(values.size(), g_free));
79+
request->priv->textFieldValues = adoptGRef(g_ptr_array_new_full(values.size(), g_free));
80+
for (size_t i = 0; i < values.size(); i++) {
81+
g_ptr_array_add(request->priv->textFieldNames.get(), g_strdup(values[i].first.utf8().data()));
82+
g_ptr_array_add(request->priv->textFieldValues.get(), g_strdup(values[i].second.utf8().data()));
83+
}
8084
}
8185
request->priv->listener = WTFMove(listener);
8286
return request;
@@ -87,18 +91,62 @@ WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std:
8791
* @request: a #WebKitFormSubmissionRequest
8892
*
8993
* Get a #GHashTable with the values of the text fields contained in the form
90-
* associated to @request.
94+
* associated to @request. Note that fields will be missing if the form
95+
* contains multiple text input elements with the same name, so this
96+
* function does not reliably return all text fields.
97+
*
98+
* Returns: (allow-none) (transfer none): a #GHashTable with the form
99+
* text fields, or %NULL if the form doesn't contain text fields.
91100
*
92-
* Returns: (transfer none): a #GHashTable with the form text fields, or %NULL if the
93-
* form doesn't contain text fields.
101+
* Deprecated: 2.20. Use webkit_form_submission_request_list_text_fields() instead.
94102
*/
95103
GHashTable* webkit_form_submission_request_get_text_fields(WebKitFormSubmissionRequest* request)
96104
{
97105
g_return_val_if_fail(WEBKIT_IS_FORM_SUBMISSION_REQUEST(request), nullptr);
98106

107+
if (!request->priv->values && request->priv->textFieldNames->len) {
108+
request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free));
109+
for (unsigned i = 0; i < request->priv->textFieldNames->len; i++) {
110+
GUniquePtr<char> name(g_strdup(static_cast<char*>(request->priv->textFieldNames->pdata[i])));
111+
GUniquePtr<char> value(g_strdup(static_cast<char*>(request->priv->textFieldValues->pdata[i])));
112+
g_hash_table_insert(request->priv->values.get(), name.release(), value.release());
113+
}
114+
}
115+
99116
return request->priv->values.get();
100117
}
101118

119+
/**
120+
* webkit_form_submission_request_list_text_fields:
121+
* @request: a #WebKitFormSubmissionRequest
122+
* @field_names: (out) (optional) (element-type utf8) (transfer none):
123+
* names of the text fields in the form
124+
* @field_values: (out) (optional) (element-type utf8) (transfer none):
125+
* values of the text fields in the form
126+
*
127+
* Get lists with the names and values of the text fields contained in
128+
* the form associated to @request. Note that names and values may be
129+
* %NULL.
130+
*
131+
* If this function returns %FALSE, then both @field_names and
132+
* @field_values will be empty.
133+
*
134+
* Returns: %TRUE if the form contains text fields, or %FALSE otherwise
135+
*
136+
* Since: 2.20
137+
*/
138+
gboolean webkit_form_submission_request_list_text_fields(WebKitFormSubmissionRequest* request, GPtrArray** fieldNames, GPtrArray** fieldValues)
139+
{
140+
g_return_val_if_fail(WEBKIT_IS_FORM_SUBMISSION_REQUEST(request), FALSE);
141+
142+
if (fieldNames)
143+
*fieldNames = request->priv->textFieldNames.get();
144+
if (fieldValues)
145+
*fieldValues = request->priv->textFieldValues.get();
146+
147+
return !!request->priv->textFieldNames->len;
148+
}
149+
102150
/**
103151
* webkit_form_submission_request_submit:
104152
* @request: a #WebKitFormSubmissionRequest

Source/WebKit/UIProcess/API/gtk/WebKitFormSubmissionRequest.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ struct _WebKitFormSubmissionRequestClass {
5757
};
5858

5959
WEBKIT_API GType
60-
webkit_form_submission_request_get_type (void);
60+
webkit_form_submission_request_get_type (void);
6161

62-
WEBKIT_API GHashTable *
63-
webkit_form_submission_request_get_text_fields (WebKitFormSubmissionRequest *request);
62+
WEBKIT_DEPRECATED_FOR(webkit_form_submission_request_list_text_fields) GHashTable *
63+
webkit_form_submission_request_get_text_fields (WebKitFormSubmissionRequest *request);
64+
65+
WEBKIT_API gboolean
66+
webkit_form_submission_request_list_text_fields (WebKitFormSubmissionRequest *request,
67+
GPtrArray **field_names,
68+
GPtrArray **field_values);
6469

6570
WEBKIT_API void
66-
webkit_form_submission_request_submit (WebKitFormSubmissionRequest *request);
71+
webkit_form_submission_request_submit (WebKitFormSubmissionRequest *request);
6772

6873
G_END_DECLS
6974

Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ webkit_option_menu_item_get_type
12381238
<FILE>WebKitFormSubmissionRequest</FILE>
12391239
WebKitFormSubmissionRequest
12401240
webkit_form_submission_request_get_text_fields
1241+
webkit_form_submission_request_list_text_fields
12411242
webkit_form_submission_request_submit
12421243

12431244
<SUBSECTION Standard>

Source/WebKit/UIProcess/API/wpe/WebKitFormSubmissionRequest.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ struct _WebKitFormSubmissionRequestClass {
5757
};
5858

5959
WEBKIT_API GType
60-
webkit_form_submission_request_get_type (void);
60+
webkit_form_submission_request_get_type (void);
6161

62-
WEBKIT_API GHashTable *
63-
webkit_form_submission_request_get_text_fields (WebKitFormSubmissionRequest *request);
62+
WEBKIT_DEPRECATED_FOR(webkit_form_submission_request_list_text_fields) GHashTable *
63+
webkit_form_submission_request_get_text_fields (WebKitFormSubmissionRequest *request);
64+
65+
WEBKIT_API gboolean
66+
webkit_form_submission_request_list_text_fields (WebKitFormSubmissionRequest *request,
67+
GPtrArray **field_names,
68+
GPtrArray **field_values);
6469

6570
WEBKIT_API void
66-
webkit_form_submission_request_submit (WebKitFormSubmissionRequest *request);
71+
webkit_form_submission_request_submit (WebKitFormSubmissionRequest *request);
6772

6873
G_END_DECLS
6974

Tools/ChangeLog

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2017-12-21 Michael Catanzaro <[email protected]>
2+
3+
[WPE][GTK] Deprecate and replace webkit_form_submission_request_get_text_fields
4+
https://bugs.webkit.org/show_bug.cgi?id=176725
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Test the new function.
9+
10+
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
11+
(testWebViewSubmitForm):
12+
113
2017-12-22 Jonathan Bedard <[email protected]>
214

315
webkitpy: Refactor simulator code (Part 1)

Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp

+45-7
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,26 @@ class FormClientTest: public WebViewTest {
475475
quitMainLoop();
476476
}
477477

478-
GHashTable* waitUntilFormSubmittedAndGetTextFields()
478+
GHashTable* getTextFieldsAsHashTable()
479479
{
480-
g_main_loop_run(m_mainLoop);
480+
#pragma GCC diagnostic push
481+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
481482
return webkit_form_submission_request_get_text_fields(m_request.get());
483+
#pragma GCC diagnostic pop
484+
}
485+
486+
GPtrArray* getTextFieldNames()
487+
{
488+
GPtrArray* names;
489+
webkit_form_submission_request_list_text_fields(m_request.get(), &names, nullptr);
490+
return names;
491+
}
492+
493+
GPtrArray* getTextFieldValues()
494+
{
495+
GPtrArray* values;
496+
webkit_form_submission_request_list_text_fields(m_request.get(), nullptr, &values);
497+
return values;
482498
}
483499

484500
static gboolean doClickIdleCallback(FormClientTest* test)
@@ -492,6 +508,7 @@ class FormClientTest: public WebViewTest {
492508
m_submitPositionX = x;
493509
m_submitPositionY = y;
494510
g_idle_add(reinterpret_cast<GSourceFunc>(doClickIdleCallback), this);
511+
g_main_loop_run(m_mainLoop);
495512
}
496513

497514
int m_submitPositionX;
@@ -508,6 +525,8 @@ static void testWebViewSubmitForm(FormClientTest* test, gconstpointer)
508525
" <form action='#'>"
509526
" <input type='text' name='text1' value='value1'>"
510527
" <input type='text' name='text2' value='value2'>"
528+
" <input type='text' value='value3'>"
529+
" <input type='text' name='text2'>"
511530
" <input type='password' name='password' value='secret'>"
512531
" <textarea cols='5' rows='5' name='textarea'>Text</textarea>"
513532
" <input type='hidden' name='hidden1' value='hidden1'>"
@@ -519,12 +538,31 @@ static void testWebViewSubmitForm(FormClientTest* test, gconstpointer)
519538
test->waitUntilLoadFinished();
520539

521540
test->submitFormAtPosition(5, 5);
522-
GHashTable* values = test->waitUntilFormSubmittedAndGetTextFields();
541+
GHashTable* tableValues = test->getTextFieldsAsHashTable();
542+
g_assert(tableValues);
543+
g_assert_cmpuint(g_hash_table_size(tableValues), ==, 4);
544+
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(tableValues, "text1")), ==, "value1");
545+
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(tableValues, "")), ==, "value3");
546+
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(tableValues, "text2")), ==, "");
547+
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(tableValues, "password")), ==, "secret");
548+
549+
GPtrArray* names = test->getTextFieldNames();
550+
g_assert(names);
551+
g_assert_cmpuint(names->len, ==, 5);
552+
g_assert_cmpstr(static_cast<char*>(names->pdata[0]), ==, "text1");
553+
g_assert_cmpstr(static_cast<char*>(names->pdata[1]), ==, "text2");
554+
g_assert_cmpstr(static_cast<char*>(names->pdata[2]), ==, "");
555+
g_assert_cmpstr(static_cast<char*>(names->pdata[3]), ==, "text2");
556+
g_assert_cmpstr(static_cast<char*>(names->pdata[4]), ==, "password");
557+
558+
GPtrArray* values = test->getTextFieldValues();
523559
g_assert(values);
524-
g_assert_cmpuint(g_hash_table_size(values), ==, 3);
525-
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "text1")), ==, "value1");
526-
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "text2")), ==, "value2");
527-
g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "password")), ==, "secret");
560+
g_assert_cmpuint(values->len, ==, 5);
561+
g_assert_cmpstr(static_cast<char*>(values->pdata[0]), ==, "value1");
562+
g_assert_cmpstr(static_cast<char*>(values->pdata[1]), ==, "value2");
563+
g_assert_cmpstr(static_cast<char*>(values->pdata[2]), ==, "value3");
564+
g_assert_cmpstr(static_cast<char*>(values->pdata[3]), ==, "");
565+
g_assert_cmpstr(static_cast<char*>(values->pdata[4]), ==, "secret");
528566
}
529567
#endif // PLATFORM(GTK)
530568

0 commit comments

Comments
 (0)