Changeset 131756 in webkit


Ignore:
Timestamp:
Oct 18, 2012 8:49:19 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Don't use the C API internally in WebKitFormSubmissionRequest
https://bugs.webkit.org/show_bug.cgi?id=96777

Reviewed by Xan Lopez.

Using the C++ classes directly instead of the C API wrappers we
avoid a lot of toImpl/toAPI casts, string conversions and
allocations. The code is also a lot simpler and easier to read.

  • UIProcess/API/gtk/WebKitFormClient.cpp:

(willSubmitForm):

  • UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp:

(_WebKitFormSubmissionRequestPrivate):
(webkitFormSubmissionRequestCreate):
(webkit_form_submission_request_get_text_fields):
(webkit_form_submission_request_submit):

  • UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h:
Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r131750 r131756  
     12012-10-18  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Don't use the C API internally in WebKitFormSubmissionRequest
     4        https://bugs.webkit.org/show_bug.cgi?id=96777
     5
     6        Reviewed by Xan Lopez.
     7
     8        Using the C++ classes directly instead of the C API wrappers we
     9        avoid a lot of toImpl/toAPI casts, string conversions and
     10        allocations. The code is also a lot simpler and easier to read.
     11
     12        * UIProcess/API/gtk/WebKitFormClient.cpp:
     13        (willSubmitForm):
     14        * UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp:
     15        (_WebKitFormSubmissionRequestPrivate):
     16        (webkitFormSubmissionRequestCreate):
     17        (webkit_form_submission_request_get_text_fields):
     18        (webkit_form_submission_request_submit):
     19        * UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h:
     20
    1212012-10-18  Carlos Garcia Campos  <cgarcia@igalia.com>
    222
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp

    r122961 r131756  
    3131static void willSubmitForm(WKPageRef page, WKFrameRef frame, WKFrameRef sourceFrame, WKDictionaryRef values, WKTypeRef userData, WKFormSubmissionListenerRef listener, const void* clientInfo)
    3232{
    33     GRefPtr<WebKitFormSubmissionRequest> request = adoptGRef(webkitFormSubmissionRequestCreate(values, listener));
     33    GRefPtr<WebKitFormSubmissionRequest> request = adoptGRef(webkitFormSubmissionRequestCreate(toImpl(values), toImpl(listener)));
    3434    webkitWebViewSubmitFormRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
    3535}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequest.cpp

    r122961 r131756  
    2121#include "WebKitFormSubmissionRequest.h"
    2222
     23#include "ImmutableDictionary.h"
     24#include "WebFormSubmissionListenerProxy.h"
    2325#include "WebKitFormSubmissionRequestPrivate.h"
    2426#include <wtf/gobject/GRefPtr.h>
    2527#include <wtf/text/CString.h>
    2628
    27 using namespace WebKit;
    28 
    2929G_DEFINE_TYPE(WebKitFormSubmissionRequest, webkit_form_submission_request, G_TYPE_OBJECT)
    3030
    3131struct _WebKitFormSubmissionRequestPrivate {
    32     WKRetainPtr<WKDictionaryRef> wkValues;
    33     WKRetainPtr<WKFormSubmissionListenerRef> wkListener;
     32    RefPtr<ImmutableDictionary> webValues;
     33    RefPtr<WebFormSubmissionListenerProxy> listener;
    3434    GRefPtr<GHashTable> values;
    3535    bool handledRequest;
     
    6262}
    6363
    64 WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(WKDictionaryRef wkValues, WKFormSubmissionListenerRef wkListener)
     64WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(ImmutableDictionary* values, WebFormSubmissionListenerProxy* listener)
    6565{
    6666    WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST(g_object_new(WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, NULL));
    67     request->priv->wkValues = wkValues;
    68     request->priv->wkListener = wkListener;
     67    request->priv->webValues = values;
     68    request->priv->listener = listener;
    6969    return request;
    7070}
     
    8787        return request->priv->values.get();
    8888
    89     if (!WKDictionaryGetSize(request->priv->wkValues.get()))
     89    if (!request->priv->webValues->size())
    9090        return 0;
    9191
    9292    request->priv->values = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free));
    9393
    94     WKRetainPtr<WKArrayRef> wkKeys(AdoptWK, WKDictionaryCopyKeys(request->priv->wkValues.get()));
    95     for (size_t i = 0; i < WKArrayGetSize(wkKeys.get()); ++i) {
    96         WKStringRef wkKey = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkKeys.get(), i));
    97         WKStringRef wkValue = static_cast<WKStringRef>(WKDictionaryGetItemForKey(request->priv->wkValues.get(), wkKey));
    98         g_hash_table_insert(request->priv->values.get(), g_strdup(toImpl(wkKey)->string().utf8().data()), g_strdup(toImpl(wkValue)->string().utf8().data()));
     94    const ImmutableDictionary::MapType& map = request->priv->webValues->map();
     95    ImmutableDictionary::MapType::const_iterator end = map.end();
     96    for (ImmutableDictionary::MapType::const_iterator it = map.begin(); it != end; ++it) {
     97        WebString* value = static_cast<WebString*>(it->value.get());
     98        g_hash_table_insert(request->priv->values.get(), g_strdup(it->key.utf8().data()), g_strdup(value->string().utf8().data()));
    9999    }
    100100
    101     request->priv->wkValues = 0;
     101    request->priv->webValues = 0;
    102102
    103103    return request->priv->values.get();
     
    114114    g_return_if_fail(WEBKIT_IS_FORM_SUBMISSION_REQUEST(request));
    115115
    116     WKFormSubmissionListenerContinue(request->priv->wkListener.get());
     116    request->priv->listener->continueSubmission();
    117117    request->priv->handledRequest = true;
    118118}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h

    r122961 r131756  
    2424#include "WebKitPrivate.h"
    2525
    26 WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(WKDictionaryRef, WKFormSubmissionListenerRef);
     26using namespace WebKit;
     27
     28WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(ImmutableDictionary* values, WebFormSubmissionListenerProxy*);
    2729
    2830#endif // WebKitFormSubmissionRequestPrivate_h
Note: See TracChangeset for help on using the changeset viewer.