[WK2] Add C API to copy selected files from WebOpenPanelParameters.
authormichael.bruning@digia.com <michael.bruning@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2013 11:13:44 +0000 (11:13 +0000)
committermichael.bruning@digia.com <michael.bruning@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2013 11:13:44 +0000 (11:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112339

Reviewed by Andreas Kling.

Replaces the existing WebOpenPanelParameters::selectedFileNames() method
to return a copy of the selected file names and exposes it through the
C API. This is done in order to reduce the direct use of WebKit2 internal
classes. The implementation is very similar to the one in
WebOpenPanelParameters::acceptMIMETypes().

This also updates the GTK port, which is the other user of selectedFileNames.

* Shared/WebOpenPanelParameters.cpp:
(WebKit::WebOpenPanelParameters::selectedFileNames):
(WebKit):
* Shared/WebOpenPanelParameters.h:
(WebOpenPanelParameters):
* UIProcess/API/C/WKOpenPanelParameters.cpp:
(WKOpenPanelParametersCopySelectedFileNames):
* UIProcess/API/C/WKOpenPanelParameters.h:
* UIProcess/API/gtk/WebKitFileChooserRequest.cpp:
(webkit_file_chooser_request_get_selected_files):
* UIProcess/qt/QtWebPageUIClient.cpp:
(WebKit::QtWebPageUIClient::runOpenPanel):

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebOpenPanelParameters.cpp
Source/WebKit2/Shared/WebOpenPanelParameters.h
Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp
Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h
Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp
Source/WebKit2/UIProcess/qt/QtWebPageUIClient.cpp

index 5a39532..9a57e43 100644 (file)
@@ -1,3 +1,31 @@
+2013-04-09  Michael BrĂ¼ning  <michael.bruning@digia.com>
+
+        [WK2] Add C API to copy selected files from WebOpenPanelParameters.
+        https://bugs.webkit.org/show_bug.cgi?id=112339
+
+        Reviewed by Andreas Kling.
+
+        Replaces the existing WebOpenPanelParameters::selectedFileNames() method
+        to return a copy of the selected file names and exposes it through the
+        C API. This is done in order to reduce the direct use of WebKit2 internal
+        classes. The implementation is very similar to the one in 
+        WebOpenPanelParameters::acceptMIMETypes().
+
+        This also updates the GTK port, which is the other user of selectedFileNames.
+
+        * Shared/WebOpenPanelParameters.cpp:
+        (WebKit::WebOpenPanelParameters::selectedFileNames):
+        (WebKit):
+        * Shared/WebOpenPanelParameters.h:
+        (WebOpenPanelParameters):
+        * UIProcess/API/C/WKOpenPanelParameters.cpp:
+        (WKOpenPanelParametersCopySelectedFileNames):
+        * UIProcess/API/C/WKOpenPanelParameters.h:
+        * UIProcess/API/gtk/WebKitFileChooserRequest.cpp:
+        (webkit_file_chooser_request_get_selected_files):
+        * UIProcess/qt/QtWebPageUIClient.cpp:
+        (WebKit::QtWebPageUIClient::runOpenPanel):
+
 2013-04-09  Jinwoo Song  <jinwoo7.song@samsung.com>
 
         [WK2] Remove build warnings for unused parameters
index 7725040..a5a1468 100644 (file)
@@ -68,5 +68,17 @@ String WebOpenPanelParameters::capture() const
 }
 #endif
 
+PassRefPtr<ImmutableArray> WebOpenPanelParameters::selectedFileNames() const
+{    
+    size_t size = m_settings.selectedFiles.size();
+
+    Vector<RefPtr<APIObject> > vector;
+    vector.reserveInitialCapacity(size);
+
+    for (size_t i = 0; i < size; ++i)
+        vector.uncheckedAppend(WebString::create(m_settings.selectedFiles[i]));
+    return ImmutableArray::adopt(vector);
+}
+
 
 } // namespace WebCore
index 9077cf2..efb7a80 100644 (file)
@@ -43,7 +43,7 @@ public:
 
     bool allowMultipleFiles() const { return m_settings.allowsMultipleFiles; } 
     PassRefPtr<ImmutableArray> acceptMIMETypes() const;
-    Vector<String> selectedFileNames() const { return m_settings.selectedFiles; }
+    PassRefPtr<ImmutableArray> selectedFileNames() const;
 #if ENABLE(MEDIA_CAPTURE)
     String capture() const;
 #endif
index 6a7c53e..29ecf54 100644 (file)
@@ -56,3 +56,8 @@ WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters
     return 0;
 #endif
 }
+
+WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef)
+{
+    return toAPI(toImpl(parametersRef)->selectedFileNames().leakRef());
+}
index ddcaae2..3801c2f 100644 (file)
@@ -45,6 +45,8 @@ WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParam
 
 WK_EXPORT WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters);
 
+WK_EXPORT WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef);
+
 #ifdef __cplusplus
 }
 #endif
index 85ae0ef..0dccdfc 100644 (file)
@@ -345,14 +345,15 @@ const gchar* const* webkit_file_chooser_request_get_selected_files(WebKitFileCho
     if (request->priv->selectedFiles)
         return reinterpret_cast<gchar**>(request->priv->selectedFiles->pdata);
 
-    const Vector<String> selectedFileNames = request->priv->parameters->selectedFileNames();
-    size_t numOfFiles = selectedFileNames.size();
+    RefPtr<ImmutableArray> selectedFileNames = request->priv->parameters->selectedFileNames();
+    size_t numOfFiles = selectedFileNames->size();
     if (!numOfFiles)
         return 0;
 
     request->priv->selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free));
     for (size_t i = 0; i < numOfFiles; ++i) {
-        if (selectedFileNames[i].isEmpty())
+        WebString* webFileName = static_cast<WebString*>(selectedFileNames->at(i));
+        if (webFileName->isEmpty())
             continue;
         CString filename = fileSystemRepresentation(selectedFileNames[i]);
         g_ptr_array_add(request->priv->selectedFiles.get(), g_strdup(filename.data()));
index 39e1e3d..af88423 100644 (file)
@@ -26,7 +26,7 @@
 #include "qquickwebview_p.h"
 #include "qquickwebview_p_p.h"
 #include "qwebpermissionrequest_p.h"
-#include <WKAPICast.h>
+#include <WKArray.h>
 #include <WKHitTestResult.h>
 #include <WKOpenPanelParameters.h>
 #include <WKOpenPanelResultListener.h>
@@ -136,11 +136,13 @@ WKStringRef QtWebPageUIClient::runJavaScriptPrompt(WKPageRef, WKStringRef messag
 
 void QtWebPageUIClient::runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo)
 {
-    Vector<String> wkSelectedFileNames = toImpl(parameters)->selectedFileNames();
-
+    WKRetainPtr<WKArrayRef> wkSelectedFileNames = adoptWK(WKOpenPanelParametersCopySelectedFileNames(parameters));
     QStringList selectedFileNames;
-    for (size_t i = 0; i < wkSelectedFileNames.size(); ++i)
-        selectedFileNames += wkSelectedFileNames.at(i);
+    size_t selectedFilesSize = WKArrayGetSize(wkSelectedFileNames.get());
+    selectedFileNames.reserve(selectedFilesSize);
+
+    for (size_t i = 0; i < selectedFilesSize; ++i)
+        selectedFileNames += WKStringCopyQString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkSelectedFileNames.get(), i)));
 
     FileChooserType allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? MultipleFilesSelection : SingleFileSelection;
     toQtWebPageUIClient(clientInfo)->runOpenPanel(listener, selectedFileNames, allowMultipleFiles);