[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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148005 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8b4f9604
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
......@@ -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
......@@ -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
......
......@@ -56,3 +56,8 @@ WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters
return 0;
#endif
}
WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef)
{
return toAPI(toImpl(parametersRef)->selectedFileNames().leakRef());
}
......@@ -45,6 +45,8 @@ WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParam
WK_EXPORT WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters);
WK_EXPORT WKArrayRef WKOpenPanelParametersCopySelectedFileNames(WKOpenPanelParametersRef parametersRef);
#ifdef __cplusplus
}
#endif
......
......@@ -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()));
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment