summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_adapter.cpp
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2013-11-25 15:38:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-15 18:26:51 +0100
commitc34b72183e85e7c615ca65381d8591cdca23faf2 (patch)
treed5359c75cc8178e1f0e07c56aa52f88daba3fa23 /src/core/web_contents_adapter.cpp
parent0b611c393e8208af717bd1c5e6c1aed1379d03ca (diff)
[Widgets] wire the file pickers
Introduce a new version of chooseFiles in QWebEnginePage. The existing API in WebKit1 seemed a bit dusty in any case (multiple only supported via extensions). Changes are: * oldFile becomes oldFiles, so that we could at a later stage expose the already selected files in the "multiple" case. * a type is introduced, for now limited to multiple selection, but over time, we might consider additions such as directory upload. Change-Id: I14cfea64ce95e892a0a1877c8cb914c5a421409f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r--src/core/web_contents_adapter.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index f3caa7478..7542f35bd 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -55,8 +55,10 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_zoom.h"
#include "content/public/common/renderer_preferences.h"
+#include "ui/shell_dialogs/selected_file_info.h"
#include <QGuiApplication>
+#include <QStringList>
#include <QStyleHints>
#include <QVariant>
@@ -146,6 +148,19 @@ static void callbackOnEvaluateJS(JSCallbackBase *callback, const base::Value *re
delete callback;
}
+static QStringList listRecursively(const QDir& dir) {
+ QStringList ret;
+ QFileInfoList infoList(dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot |QDir::Hidden));
+ Q_FOREACH (const QFileInfo &fileInfo, infoList) {
+ if (fileInfo.isDir()) {
+ ret.append(fileInfo.absolutePath() + QStringLiteral("/.")); // Match chromium's behavior. See chrome/browser/file_select_helper.cc
+ ret.append(listRecursively(QDir(fileInfo.absoluteFilePath())));
+ } else
+ ret.append(fileInfo.absoluteFilePath());
+ }
+ return ret;
+}
+
class WebContentsAdapterPrivate {
public:
WebContentsAdapterPrivate(WebContentsAdapterClient::RenderingMode renderingMode);
@@ -355,3 +370,15 @@ void WebContentsAdapter::dpiScaleChanged()
if (impl)
impl->NotifyScreenInfoChanged();
}
+
+void WebContentsAdapter::filesSelectedInChooser(const QStringList &fileList, WebContentsAdapterClient::FileChooserMode mode)
+{
+ Q_D(WebContentsAdapter);
+ content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
+ Q_ASSERT(rvh);
+ QStringList files(fileList);
+ if (mode == WebContentsAdapterClient::UploadFolder && !fileList.isEmpty()
+ && QFileInfo(fileList.first()).isDir()) // Enumerate the directory
+ files = listRecursively(QDir(fileList.first()));
+ rvh->FilesSelectedInChooser(toVector<ui::SelectedFileInfo>(files), static_cast<content::FileChooserParams::Mode>(mode));
+}