Title: [131757] trunk/Source/WebKit2
Revision
131757
Author
carlo...@webkit.org
Date
2012-10-18 08:55:26 -0700 (Thu, 18 Oct 2012)

Log Message

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

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/WebKitFileChooserRequest.cpp:
(_WebKitFileChooserRequestPrivate):
(webkitFileChooserRequestCreate):
(webkit_file_chooser_request_get_mime_types):
(webkit_file_chooser_request_get_mime_types_filter):
(webkit_file_chooser_request_get_select_multiple):
(webkit_file_chooser_request_select_files):
(webkit_file_chooser_request_get_selected_files):
(webkit_file_chooser_request_cancel):
* UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h:
* UIProcess/API/gtk/WebKitUIClient.cpp:
(runOpenPanel):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (131756 => 131757)


--- trunk/Source/WebKit2/ChangeLog	2012-10-18 15:49:19 UTC (rev 131756)
+++ trunk/Source/WebKit2/ChangeLog	2012-10-18 15:55:26 UTC (rev 131757)
@@ -1,5 +1,29 @@
 2012-10-18  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        [GTK] Don't use the C API internally in WebKitFileChooserRequest
+        https://bugs.webkit.org/show_bug.cgi?id=96774
+
+        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/WebKitFileChooserRequest.cpp:
+        (_WebKitFileChooserRequestPrivate):
+        (webkitFileChooserRequestCreate):
+        (webkit_file_chooser_request_get_mime_types):
+        (webkit_file_chooser_request_get_mime_types_filter):
+        (webkit_file_chooser_request_get_select_multiple):
+        (webkit_file_chooser_request_select_files):
+        (webkit_file_chooser_request_get_selected_files):
+        (webkit_file_chooser_request_cancel):
+        * UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h:
+        * UIProcess/API/gtk/WebKitUIClient.cpp:
+        (runOpenPanel):
+
+2012-10-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
         [GTK] Don't use the C API internally in WebKitFormSubmissionRequest
         https://bugs.webkit.org/show_bug.cgi?id=96777
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp (131756 => 131757)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp	2012-10-18 15:49:19 UTC (rev 131756)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp	2012-10-18 15:55:26 UTC (rev 131757)
@@ -20,8 +20,10 @@
 #include "config.h"
 #include "WebKitFileChooserRequest.h"
 
+#include "ImmutableArray.h"
 #include "WebKitFileChooserRequestPrivate.h"
 #include "WebOpenPanelParameters.h"
+#include "WebOpenPanelResultListenerProxy.h"
 #include <WebCore/FileSystem.h>
 #include <glib/gi18n-lib.h>
 #include <wtf/gobject/GOwnPtr.h>
@@ -29,7 +31,6 @@
 #include <wtf/text/CString.h>
 
 using namespace WebCore;
-using namespace WebKit;
 
 /**
  * SECTION: WebKitFileChooserRequest
@@ -57,8 +58,8 @@
 G_DEFINE_TYPE(WebKitFileChooserRequest, webkit_file_chooser_request, G_TYPE_OBJECT)
 
 struct _WebKitFileChooserRequestPrivate {
-    WKRetainPtr<WKOpenPanelParametersRef> wkParameters;
-    WKRetainPtr<WKOpenPanelResultListenerRef> wkListener;
+    RefPtr<WebOpenPanelParameters> parameters;
+    RefPtr<WebOpenPanelResultListenerProxy> listener;
     GRefPtr<GtkFileFilter> filter;
     GRefPtr<GPtrArray> mimeTypes;
     GRefPtr<GPtrArray> selectedFiles;
@@ -179,11 +180,11 @@
                                                       WEBKIT_PARAM_READABLE));
 }
 
-WebKitFileChooserRequest* webkitFileChooserRequestCreate(WKOpenPanelParametersRef wkParameters, WKOpenPanelResultListenerRef wkListener)
+WebKitFileChooserRequest* webkitFileChooserRequestCreate(WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener)
 {
     WebKitFileChooserRequest* request = WEBKIT_FILE_CHOOSER_REQUEST(g_object_new(WEBKIT_TYPE_FILE_CHOOSER_REQUEST, NULL));
-    request->priv->wkParameters = wkParameters;
-    request->priv->wkListener = wkListener;
+    request->priv->parameters = parameters;
+    request->priv->listener = listener;
     return request;
 }
 
@@ -210,15 +211,15 @@
     if (request->priv->mimeTypes)
         return reinterpret_cast<gchar**>(request->priv->mimeTypes->pdata);
 
-    WKRetainPtr<WKArrayRef> wkMimeTypes(AdoptWK, WKOpenPanelParametersCopyAcceptedMIMETypes(request->priv->wkParameters.get()));
-    size_t numOfMimeTypes = WKArrayGetSize(wkMimeTypes.get());
+    RefPtr<ImmutableArray> mimeTypes = request->priv->parameters->acceptMIMETypes();
+    size_t numOfMimeTypes = mimeTypes->size();
     if (!numOfMimeTypes)
         return 0;
 
     request->priv->mimeTypes = adoptGRef(g_ptr_array_new_with_free_func(g_free));
     for (size_t i = 0; i < numOfMimeTypes; ++i) {
-        WKStringRef wkMimeType = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkMimeTypes.get(), i));
-        String mimeTypeString = toImpl(wkMimeType)->string();
+        WebString* webMimeType = static_cast<WebString*>(mimeTypes->at(i));
+        String mimeTypeString = webMimeType->string();
         if (mimeTypeString.isEmpty())
             continue;
         g_ptr_array_add(request->priv->mimeTypes.get(), g_strdup(mimeTypeString.utf8().data()));
@@ -251,8 +252,8 @@
     if (request->priv->filter)
         return request->priv->filter.get();
 
-    WKRetainPtr<WKArrayRef> wkMimeTypes(AdoptWK, WKOpenPanelParametersCopyAcceptedMIMETypes(request->priv->wkParameters.get()));
-    size_t numOfMimeTypes = WKArrayGetSize(wkMimeTypes.get());
+    RefPtr<ImmutableArray> mimeTypes = request->priv->parameters->acceptMIMETypes();
+    size_t numOfMimeTypes = mimeTypes->size();
     if (!numOfMimeTypes)
         return 0;
 
@@ -261,8 +262,8 @@
     // sure we keep the ownership during the lifetime of the request.
     request->priv->filter = gtk_file_filter_new();
     for (size_t i = 0; i < numOfMimeTypes; ++i) {
-        WKStringRef wkMimeType = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkMimeTypes.get(), i));
-        String mimeTypeString = toImpl(wkMimeType)->string();
+        WebString* webMimeType = static_cast<WebString*>(mimeTypes->at(i));
+        String mimeTypeString = webMimeType->string();
         if (mimeTypeString.isEmpty())
             continue;
         gtk_file_filter_add_mime_type(request->priv->filter.get(), mimeTypeString.utf8().data());
@@ -285,7 +286,7 @@
 gboolean webkit_file_chooser_request_get_select_multiple(WebKitFileChooserRequest* request)
 {
     g_return_val_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request), FALSE);
-    return WKOpenPanelParametersGetAllowsMultipleFiles(request->priv->wkParameters.get());
+    return request->priv->parameters->allowMultipleFiles();
 }
 
 /**
@@ -303,7 +304,7 @@
     g_return_if_fail(files);
 
     GRefPtr<GPtrArray> selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free));
-    WKRetainPtr<WKMutableArrayRef> wkChosenFiles(AdoptWK, WKMutableArrayCreate());
+    Vector<RefPtr<APIObject> > choosenFiles;
     for (int i = 0; files[i]; i++) {
         GRefPtr<GFile> filename = adoptGRef(g_file_new_for_path(files[i]));
 
@@ -311,8 +312,7 @@
         // string, with the 'file://' prefix) to WebCore otherwise the
         // FileChooser won't actually choose it.
         GOwnPtr<char> uri(g_file_get_uri(filename.get()));
-        WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKURLCreateWithUTF8CString(uri.get()));
-        WKArrayAppendItem(wkChosenFiles.get(), wkURL.get());
+        choosenFiles.append(WebURL::create(String::fromUTF8(uri.get())));
 
         // Do not use the URI here because this won't reach WebCore.
         g_ptr_array_add(selectedFiles.get(), g_strdup(files[i]));
@@ -320,7 +320,7 @@
     g_ptr_array_add(selectedFiles.get(), 0);
 
     // Select the files in WebCore and update local private attributes.
-    WKOpenPanelResultListenerChooseFiles(request->priv->wkListener.get(), wkChosenFiles.get());
+    request->priv->listener->chooseFiles(ImmutableArray::adopt(choosenFiles).get());
     request->priv->selectedFiles = selectedFiles;
     request->priv->handledRequest = true;
 }
@@ -351,7 +351,7 @@
     if (request->priv->selectedFiles)
         return reinterpret_cast<gchar**>(request->priv->selectedFiles->pdata);
 
-    const Vector<String> selectedFileNames = toImpl(request->priv->wkParameters.get())->selectedFileNames();
+    const Vector<String> selectedFileNames = request->priv->parameters->selectedFileNames();
     size_t numOfFiles = selectedFileNames.size();
     if (!numOfFiles)
         return 0;
@@ -380,6 +380,6 @@
 void webkit_file_chooser_request_cancel(WebKitFileChooserRequest* request)
 {
     g_return_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request));
-    WKOpenPanelResultListenerCancel(request->priv->wkListener.get());
+    request->priv->listener->cancel();
     request->priv->handledRequest = true;
 }

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h (131756 => 131757)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h	2012-10-18 15:49:19 UTC (rev 131756)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h	2012-10-18 15:55:26 UTC (rev 131757)
@@ -23,6 +23,8 @@
 #include "WebKitFileChooserRequest.h"
 #include "WebKitPrivate.h"
 
-WebKitFileChooserRequest* webkitFileChooserRequestCreate(WKOpenPanelParametersRef, WKOpenPanelResultListenerRef);
+using namespace WebKit;
 
+WebKitFileChooserRequest* webkitFileChooserRequestCreate(WebOpenPanelParameters*, WebOpenPanelResultListenerProxy*);
+
 #endif // WebKitFileChooserRequestPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp (131756 => 131757)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-10-18 15:49:19 UTC (rev 131756)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-10-18 15:55:26 UTC (rev 131757)
@@ -142,7 +142,7 @@
 
 static void runOpenPanel(WKPageRef page, WKFrameRef frame, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void *clientInfo)
 {
-    GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(parameters, listener));
+    GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(toImpl(parameters), toImpl(listener)));
     webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to