diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | src/core/core_gyp_generator.pro | 2 | ||||
-rw-r--r-- | src/core/file_picker_controller.cpp | 122 | ||||
-rw-r--r-- | src/core/file_picker_controller.h | 81 | ||||
-rw-r--r-- | src/core/web_contents_adapter.cpp | 31 | ||||
-rw-r--r-- | src/core/web_contents_adapter.h | 1 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 11 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 11 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 5 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 2 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.cpp | 60 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.h | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 28 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 2 |
15 files changed, 248 insertions, 115 deletions
diff --git a/.qmake.conf b/.qmake.conf index 0a6b62d97..fe1cde075 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ QMAKEPATH += $$PWD/tools/qmake load(qt_build_config) CONFIG += qt_example_installs -MODULE_VERSION = 5.5.0 +MODULE_VERSION = 5.6.0 diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index b5722d2d3..6f58ce032 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -48,6 +48,7 @@ SOURCES = \ desktop_screen_qt.cpp \ dev_tools_http_handler_delegate_qt.cpp \ download_manager_delegate_qt.cpp \ + file_picker_controller.cpp \ gl_context_qt.cpp \ gl_surface_qt.cpp \ javascript_dialog_controller.cpp \ @@ -110,6 +111,7 @@ HEADERS = \ dev_tools_http_handler_delegate_qt.h \ download_manager_delegate_qt.h \ chromium_gpu_helper.h \ + file_picker_controller.h \ gl_context_qt.h \ gl_surface_qt.h \ javascript_dialog_controller_p.h \ diff --git a/src/core/file_picker_controller.cpp b/src/core/file_picker_controller.cpp new file mode 100644 index 000000000..0fe6afdcf --- /dev/null +++ b/src/core/file_picker_controller.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "file_picker_controller.h" +#include "type_conversion.h" +#include "content/browser/renderer_host/render_view_host_impl.h" +#include "content/browser/web_contents/web_contents_impl.h" + +#include <QFileInfo> +#include <QDir> +#include <QVariant> +#include <QStringList> + +namespace QtWebEngineCore { + +FilePickerController::FilePickerController(FileChooserMode mode, content::WebContents *contents, const QString &defaultFileName, const QStringList &acceptedMimeTypes, QObject *parent) + : QObject(parent) + , m_acceptedMimeTypes(acceptedMimeTypes) + , m_contents(contents) + , m_defaultFileName(defaultFileName) + , m_mode(mode) +{ +} + +void FilePickerController::accepted(const QStringList &files) +{ + FilePickerController::filesSelectedInChooser(files, m_contents); +} + +void FilePickerController::accepted(const QVariant &files) +{ + QStringList stringList; + Q_FOREACH (const QUrl &url, files.value<QList<QUrl> >()) + stringList.append(url.toLocalFile()); + + FilePickerController::filesSelectedInChooser(stringList, m_contents); +} + +void FilePickerController::rejected() +{ + FilePickerController::filesSelectedInChooser(QStringList(), m_contents); +} + +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; +} + +ASSERT_ENUMS_MATCH(FilePickerController::Open, content::FileChooserParams::Open) +ASSERT_ENUMS_MATCH(FilePickerController::OpenMultiple, content::FileChooserParams::OpenMultiple) +ASSERT_ENUMS_MATCH(FilePickerController::UploadFolder, content::FileChooserParams::UploadFolder) +ASSERT_ENUMS_MATCH(FilePickerController::Save, content::FileChooserParams::Save) + +void FilePickerController::filesSelectedInChooser(const QStringList &filesList, content::WebContents *contents) +{ + content::RenderViewHost *rvh = contents->GetRenderViewHost(); + Q_ASSERT(rvh); + QStringList files(filesList); + if (this->m_mode == UploadFolder && !filesList.isEmpty() + && QFileInfo(filesList.first()).isDir()) // Enumerate the directory + files = listRecursively(QDir(filesList.first())); + rvh->FilesSelectedInChooser(toVector<content::FileChooserFileInfo>(files), static_cast<content::FileChooserParams::Mode>(this->m_mode)); +} + +QStringList FilePickerController::acceptedMimeTypes() +{ + return m_acceptedMimeTypes; +} + +FilePickerController::FileChooserMode FilePickerController::mode() +{ + return m_mode; +} + +QString FilePickerController::defaultFileName() +{ + return m_defaultFileName; +} + +} // namespace diff --git a/src/core/file_picker_controller.h b/src/core/file_picker_controller.h new file mode 100644 index 000000000..851dec174 --- /dev/null +++ b/src/core/file_picker_controller.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FILE_PICKER_CONTROLLER_H +#define FILE_PICKER_CONTROLLER_H + +#include "qtwebenginecoreglobal.h" +#include <QObject> + +namespace content { + class WebContents; +} + +namespace QtWebEngineCore { + +class QWEBENGINE_EXPORT FilePickerController : public QObject { + Q_OBJECT +public: + enum FileChooserMode { + Open, + OpenMultiple, + UploadFolder, + Save + }; + + FilePickerController(FileChooserMode mode, content::WebContents *contents, const QString &defaultFileName, const QStringList &acceptedMimeTypes, QObject * = 0); + +public Q_SLOTS: + void accepted(const QStringList &files); + void accepted(const QVariant &files); + void rejected(); + + QStringList acceptedMimeTypes(); + QString defaultFileName(); + FileChooserMode mode(); + void filesSelectedInChooser(const QStringList &filesList, content::WebContents *contents); + +private: + QString m_defaultFileName; + QStringList m_acceptedMimeTypes; + content::WebContents *m_contents; + FileChooserMode m_mode; + +}; + +} // namespace + +#endif // FILE_PICKER_CONTROLLER_H diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index c5cd83c6e..9f1000910 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -69,7 +69,6 @@ #include "content/public/common/renderer_preferences.h" #include "content/public/common/url_constants.h" #include "content/public/common/web_preferences.h" -#include "ui/shell_dialogs/selected_file_info.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include <QDir> @@ -168,19 +167,6 @@ static void callbackOnEvaluateJS(WebContentsAdapterClient *adapterClient, quint6 adapterClient->didRunJavaScript(requestId, fromJSValue(result)); } -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; -} - static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient, content::BrowserContext *browserContext) { content::WebContents::CreateParams create_params(browserContext, NULL); @@ -816,23 +802,6 @@ void WebContentsAdapter::dpiScaleChanged() impl->NotifyScreenInfoChanged(); } -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::Open, content::FileChooserParams::Open) -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::OpenMultiple, content::FileChooserParams::OpenMultiple) -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::UploadFolder, content::FileChooserParams::UploadFolder) -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::Save, content::FileChooserParams::Save) - -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<content::FileChooserFileInfo>(files), static_cast<content::FileChooserParams::Mode>(mode)); -} - content::WebContents *WebContentsAdapter::webContents() const { Q_D(const WebContentsAdapter); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index f4b434353..2973f9948 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -103,7 +103,6 @@ public: void serializeNavigationHistory(QDataStream &output); void setZoomFactor(qreal); qreal currentZoomFactor() const; - void filesSelectedInChooser(const QStringList &fileList, WebContentsAdapterClient::FileChooserMode); void runJavaScript(const QString &javaScript); quint64 runJavaScriptCallbackResult(const QString &javaScript); quint64 fetchDocumentMarkup(); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index d67accec2..9455572da 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -53,6 +53,7 @@ QT_FORWARD_DECLARE_CLASS(CertificateErrorController) namespace QtWebEngineCore { class BrowserContextAdapter; +class FilePickerController; class JavaScriptDialogController; class RenderWidgetHostViewQt; class RenderWidgetHostViewQtDelegate; @@ -104,14 +105,6 @@ public: InternalAuthorizationDialog = 0x10, }; - // Must match the ones in file_chooser_params.h - enum FileChooserMode { - Open, - OpenMultiple, - UploadFolder, - Save - }; - enum NavigationRequestAction { AcceptRequest, // Make room in the valid range of the enum for extra actions exposed in Experimental. @@ -165,7 +158,7 @@ public: virtual void requestFullScreen(bool) = 0; virtual bool isFullScreen() const = 0; virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) = 0; - virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) = 0; + virtual void runFileChooser(FilePickerController *controller) = 0; virtual void didRunJavaScript(quint64 requestId, const QVariant& result) = 0; virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) = 0; virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index f69b68af5..a2e6f192a 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -41,6 +41,7 @@ #include "web_contents_delegate_qt.h" #include "browser_context_adapter.h" +#include "file_picker_controller.h" #include "media_capture_devices_dispatcher.h" #include "type_conversion.h" #include "web_contents_adapter_client.h" @@ -243,18 +244,20 @@ bool WebContentsDelegateQt::IsFullscreenForTabOrPending(const content::WebConten return m_viewClient->isFullScreen(); } -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::Open, content::FileChooserParams::Open) -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::Save, content::FileChooserParams::Save) +ASSERT_ENUMS_MATCH(FilePickerController::Open, content::FileChooserParams::Open) +ASSERT_ENUMS_MATCH(FilePickerController::OpenMultiple, content::FileChooserParams::OpenMultiple) +ASSERT_ENUMS_MATCH(FilePickerController::UploadFolder, content::FileChooserParams::UploadFolder) +ASSERT_ENUMS_MATCH(FilePickerController::Save, content::FileChooserParams::Save) void WebContentsDelegateQt::RunFileChooser(content::WebContents *web_contents, const content::FileChooserParams ¶ms) { - Q_UNUSED(web_contents) QStringList acceptedMimeTypes; acceptedMimeTypes.reserve(params.accept_types.size()); for (std::vector<base::string16>::const_iterator it = params.accept_types.begin(); it < params.accept_types.end(); ++it) acceptedMimeTypes.append(toQt(*it)); - m_viewClient->runFileChooser(static_cast<WebContentsAdapterClient::FileChooserMode>(params.mode), toQt(params.default_file_name.value()), acceptedMimeTypes); + FilePickerController *controller = new FilePickerController(static_cast<FilePickerController::FileChooserMode>(params.mode), web_contents, toQt(params.default_file_name.value()), acceptedMimeTypes); + m_viewClient->runFileChooser(controller); } bool WebContentsDelegateQt::AddMessageToConsole(content::WebContents *source, int32 level, const base::string16 &message, int32 line_no, const base::string16 &source_id) diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 4bc6cd087..9a64b9ac6 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -39,6 +39,7 @@ #include "browser_context_adapter.h" #include "certificate_error_controller.h" +#include "file_picker_controller.h" #include "javascript_dialog_controller.h" #include "qquickwebenginehistory_p.h" #include "qquickwebenginecertificateerror_p.h" @@ -256,9 +257,9 @@ void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url Q_EMIT e->featurePermissionRequested(url, QQuickWebEngineViewExperimental::Geolocation); } -void QQuickWebEngineViewPrivate::runFileChooser(FileChooserMode mode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) +void QQuickWebEngineViewPrivate::runFileChooser(FilePickerController* controller) { - ui()->showFilePicker(mode, defaultFileName, acceptedMimeTypes, adapter); + ui()->showFilePicker(controller); } void QQuickWebEngineViewPrivate::passOnFocus(bool reverse) diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 36e590bff..b3907d3a4 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -149,7 +149,7 @@ public: virtual bool contextMenuRequested(const QtWebEngineCore::WebEngineContextMenuData &) Q_DECL_OVERRIDE; virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) Q_DECL_OVERRIDE; virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; - virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE; + virtual void runFileChooser(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; virtual void didRunJavaScript(quint64, const QVariant&) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64, const QString&) Q_DECL_OVERRIDE { } virtual void didFetchDocumentInnerText(quint64, const QString&) Q_DECL_OVERRIDE { } diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp index 615c6024d..44c763f37 100644 --- a/src/webengine/ui_delegates_manager.cpp +++ b/src/webengine/ui_delegates_manager.cpp @@ -37,6 +37,7 @@ #include "ui_delegates_manager.h" #include "api/qquickwebengineview_p.h" +#include "file_picker_controller.h" #include "javascript_dialog_controller.h" #include <QAbstractListModel> @@ -340,50 +341,8 @@ void UIDelegatesManager::showDialog(QSharedPointer<JavaScriptDialogController> d QMetaObject::invokeMethod(dialog, "open"); } -namespace { -class FilePickerController : public QObject { - Q_OBJECT -public: - FilePickerController(WebContentsAdapterClient::FileChooserMode, const QExplicitlySharedDataPointer<WebContentsAdapter> &, QObject * = 0); - -public Q_SLOTS: - void accepted(const QVariant &files); - void rejected(); - -private: - QExplicitlySharedDataPointer<WebContentsAdapter> m_adapter; - WebContentsAdapterClient::FileChooserMode m_mode; - -}; - - -FilePickerController::FilePickerController(WebContentsAdapterClient::FileChooserMode mode, const QExplicitlySharedDataPointer<WebContentsAdapter> &adapter, QObject *parent) - : QObject(parent) - , m_adapter(adapter) - , m_mode(mode) -{ -} - -void FilePickerController::accepted(const QVariant &files) +void UIDelegatesManager::showFilePicker(FilePickerController *controller) { - QStringList stringList; - Q_FOREACH (const QUrl &url, files.value<QList<QUrl> >()) - stringList.append(url.toLocalFile()); - m_adapter->filesSelectedInChooser(stringList, m_mode); -} - -void FilePickerController::rejected() -{ - m_adapter->filesSelectedInChooser(QStringList(), m_mode); -} - -} // namespace - - -void UIDelegatesManager::showFilePicker(WebContentsAdapterClient::FileChooserMode mode, const QString &defaultFileName, const QStringList &acceptedMimeTypes, const QExplicitlySharedDataPointer<WebContentsAdapter> &adapter) -{ - Q_UNUSED(defaultFileName); - Q_UNUSED(acceptedMimeTypes); if (!ensureComponentLoaded(FilePicker)) return; @@ -396,23 +355,24 @@ void UIDelegatesManager::showFilePicker(WebContentsAdapterClient::FileChooserMod filePickerComponent->completeCreate(); // Fine-tune some properties depending on the mode. - switch (mode) { - case WebContentsAdapterClient::Open: + switch (controller->mode()) { + case FilePickerController::Open: break; - case WebContentsAdapterClient::Save: + case FilePickerController::Save: filePicker->setProperty("selectExisting", false); break; - case WebContentsAdapterClient::OpenMultiple: + case FilePickerController::OpenMultiple: filePicker->setProperty("selectMultiple", true); break; - case WebContentsAdapterClient::UploadFolder: + case FilePickerController::UploadFolder: filePicker->setProperty("selectFolder", true); break; default: Q_UNREACHABLE(); } - FilePickerController *controller = new FilePickerController(mode, adapter, filePicker); + controller->setParent(filePicker); + QQmlProperty filesPickedSignal(filePicker, QStringLiteral("onFilesSelected")); CHECK_QML_SIGNAL_PROPERTY(filesPickedSignal, filePickerComponent->url()); QQmlProperty rejectSignal(filePicker, QStringLiteral("onRejected")); @@ -431,5 +391,3 @@ void UIDelegatesManager::showFilePicker(WebContentsAdapterClient::FileChooserMod } } // namespace QtWebEngineCore - -#include "ui_delegates_manager.moc" diff --git a/src/webengine/ui_delegates_manager.h b/src/webengine/ui_delegates_manager.h index b43006381..9367bff30 100644 --- a/src/webengine/ui_delegates_manager.h +++ b/src/webengine/ui_delegates_manager.h @@ -71,6 +71,7 @@ QT_END_NAMESPACE namespace QtWebEngineCore { class JavaScriptDialogController; +class FilePickerController; const char *defaultPropertyName(QObject *obj); @@ -122,8 +123,7 @@ public: QObject *addMenu(QObject *parentMenu, const QString &title, const QPoint &pos = QPoint()); QQmlContext *creationContextForComponent(QQmlComponent *); void showDialog(QSharedPointer<JavaScriptDialogController>); - void showFilePicker(WebContentsAdapterClient::FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes - , const QExplicitlySharedDataPointer<WebContentsAdapter> &); + void showFilePicker(FilePickerController *controller); private: bool ensureComponentLoaded(ComponentType); diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 7eab1dc71..08976a291 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -25,6 +25,7 @@ #include "browser_context_adapter.h" #include "certificate_error_controller.h" +#include "file_picker_controller.h" #include "javascript_dialog_controller.h" #include "qwebenginehistory.h" #include "qwebenginehistory_p.h" @@ -885,17 +886,22 @@ void QWebEnginePage::setFeaturePermission(const QUrl &securityOrigin, QWebEngine } } -static inline QWebEnginePage::FileSelectionMode toPublic(WebContentsAdapterClient::FileChooserMode mode) +static inline QWebEnginePage::FileSelectionMode toPublic(FilePickerController::FileChooserMode mode) { // Should the underlying values change, we'll need a switch here. return static_cast<QWebEnginePage::FileSelectionMode>(mode); } -void QWebEnginePagePrivate::runFileChooser(WebContentsAdapterClient::FileChooserMode mode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) +void QWebEnginePagePrivate::runFileChooser(FilePickerController *controller) { Q_Q(QWebEnginePage); - QStringList selectedFileNames = q->chooseFiles(toPublic(mode), (QStringList() << defaultFileName), acceptedMimeTypes); - adapter->filesSelectedInChooser(selectedFileNames, mode); + + QStringList selectedFileNames = q->chooseFiles(toPublic(controller->mode()), (QStringList() << controller->defaultFileName()), controller->acceptedMimeTypes()); + + if (!selectedFileNames.empty()) + controller->accepted(selectedFileNames); + else + controller->rejected(); } WebEngineSettings *QWebEnginePagePrivate::webEngineSettings() const @@ -1012,8 +1018,8 @@ QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type) return 0; } -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::Open, QWebEnginePage::FileSelectOpen) -ASSERT_ENUMS_MATCH(WebContentsAdapterClient::OpenMultiple, QWebEnginePage::FileSelectOpenMultiple) +ASSERT_ENUMS_MATCH(FilePickerController::Open, QWebEnginePage::FileSelectOpen) +ASSERT_ENUMS_MATCH(FilePickerController::OpenMultiple, QWebEnginePage::FileSelectOpenMultiple) QStringList QWebEnginePage::chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) { @@ -1021,19 +1027,19 @@ QStringList QWebEnginePage::chooseFiles(FileSelectionMode mode, const QStringLis // can work with) and mimetypes ranging from text/plain or images/* to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Q_UNUSED(acceptedMimeTypes); QStringList ret; - switch (static_cast<WebContentsAdapterClient::FileChooserMode>(mode)) { - case WebContentsAdapterClient::OpenMultiple: + switch (static_cast<FilePickerController::FileChooserMode>(mode)) { + case FilePickerController::OpenMultiple: ret = QFileDialog::getOpenFileNames(view(), QString()); break; // Chromium extension, not exposed as part of the public API for now. - case WebContentsAdapterClient::UploadFolder: + case FilePickerController::UploadFolder: ret << QFileDialog::getExistingDirectory(view(), tr("Select folder to upload")) + QLatin1Char('/'); break; - case WebContentsAdapterClient::Save: + case FilePickerController::Save: ret << QFileDialog::getSaveFileName(view(), QString(), (QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + oldFiles.first())); break; default: - case WebContentsAdapterClient::Open: + case FilePickerController::Open: ret << QFileDialog::getOpenFileName(view(), QString(), oldFiles.first()); break; } diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index f2067c6aa..63892d197 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -261,7 +261,6 @@ Q_SIGNALS: protected: virtual QWebEnginePage *createWindow(WebWindowType type); - virtual QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes); virtual void javaScriptAlert(const QUrl &securityOrigin, const QString& msg); virtual bool javaScriptConfirm(const QUrl &securityOrigin, const QString& msg); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 087137a78..ccfdd5d0e 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -131,7 +131,7 @@ public: virtual void requestFullScreen(bool) Q_DECL_OVERRIDE { } virtual bool isFullScreen() const Q_DECL_OVERRIDE { return false; } virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; - virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE; + virtual void runFileChooser(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; virtual void didRunJavaScript(quint64 requestId, const QVariant& result) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) Q_DECL_OVERRIDE; virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) Q_DECL_OVERRIDE; |