diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2016-06-13 13:29:51 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2016-08-31 09:11:47 +0000 |
commit | 3cbe59e29a2702a2c184be10845b9bdd342c24d0 (patch) | |
tree | ef3b6555857028147b9b57948a15e18626e213da | |
parent | 4f3425c0d17f5f53deba78ccf6d357c1c83529f0 (diff) |
Add dialog requests to qml api
Introduce qml APIs to support custom dialogs:
* http and proxy authentication
* javascript dialogs
* file pickers
* color pickers
* form validation messages
[ChangeLog][QtWebEngine][QML] Added ability to provide custom dialogs
for HTTP and proxy authentication, JavaScript alerts, file and color
picking, and form validation messages.
Task-number: QTBUG-51190
Change-Id: I559ca59264750feb36ba7d3dba0bf0647509306d
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r-- | src/core/web_contents_adapter_client.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 5 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 1 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedialogrequests.cpp | 856 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedialogrequests_p.h | 265 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 65 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p.h | 11 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 2 | ||||
-rw-r--r-- | src/webengine/doc/src/webengineview.qdoc | 71 | ||||
-rw-r--r-- | src/webengine/plugin/plugin.cpp | 12 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.cpp | 8 | ||||
-rw-r--r-- | src/webengine/ui_delegates_manager.h | 2 | ||||
-rw-r--r-- | src/webengine/webengine.pro | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 2 | ||||
-rw-r--r-- | tests/auto/quick/publicapi/tst_publicapi.cpp | 6 |
16 files changed, 1291 insertions, 21 deletions
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 165d84e37..865fd55d7 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -227,7 +227,7 @@ public: virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) = 0; virtual bool isFullScreenMode() const = 0; virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) = 0; - virtual void runFileChooser(FilePickerController *controller) = 0; + virtual void runFileChooser(QSharedPointer<FilePickerController>) = 0; virtual void showColorDialog(QSharedPointer<ColorChooserController>) = 0; virtual void didRunJavaScript(quint64 requestId, const QVariant& result) = 0; virtual void didFetchDocumentMarkup(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 b96452093..6e7d1cddc 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -317,8 +317,9 @@ void WebContentsDelegateQt::RunFileChooser(content::WebContents *web_contents, c for (std::vector<base::string16>::const_iterator it = params.accept_types.begin(); it < params.accept_types.end(); ++it) acceptedMimeTypes.append(toQt(*it)); - FilePickerController *controller = new FilePickerController(static_cast<FilePickerController::FileChooserMode>(params.mode), web_contents, toQt(params.default_file_name.value()), acceptedMimeTypes); - m_viewClient->runFileChooser(controller); + m_filePickerController.reset(new FilePickerController(static_cast<FilePickerController::FileChooserMode>(params.mode), + web_contents, toQt(params.default_file_name.value()), acceptedMimeTypes)); + m_viewClient->runFileChooser(m_filePickerController); } bool WebContentsDelegateQt::AddMessageToConsole(content::WebContents *source, int32_t level, const base::string16 &message, int32_t line_no, const base::string16 &source_id) diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 9aa584369..d2459e79b 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -154,6 +154,7 @@ private: QVector<int64_t> m_loadingErrorFrameList; QScopedPointer<FaviconManager> m_faviconManager; SavePageInfo m_savePageInfo; + QSharedPointer<FilePickerController> m_filePickerController; }; } // namespace QtWebEngineCore diff --git a/src/webengine/api/qquickwebenginedialogrequests.cpp b/src/webengine/api/qquickwebenginedialogrequests.cpp new file mode 100644 index 000000000..d8111e62b --- /dev/null +++ b/src/webengine/api/qquickwebenginedialogrequests.cpp @@ -0,0 +1,856 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebenginedialogrequests_p.h" +#include "authentication_dialog_controller.h" +#include "javascript_dialog_controller.h" +#include "color_chooser_controller.h" +#include "file_picker_controller.h" +#include "web_contents_adapter_client.h" + +QT_BEGIN_NAMESPACE + +using namespace QtWebEngineCore; + +ASSERT_ENUMS_MATCH(WebContentsAdapterClient::AlertDialog, + QQuickWebEngineJavaScriptDialogRequest::DialogTypeAlert) +ASSERT_ENUMS_MATCH(WebContentsAdapterClient::ConfirmDialog, + QQuickWebEngineJavaScriptDialogRequest::DialogTypeConfirm) +ASSERT_ENUMS_MATCH(WebContentsAdapterClient::PromptDialog, + QQuickWebEngineJavaScriptDialogRequest::DialogTypePrompt) +ASSERT_ENUMS_MATCH(WebContentsAdapterClient::UnloadDialog, + QQuickWebEngineJavaScriptDialogRequest::DialogTypeBeforeUnload) + +ASSERT_ENUMS_MATCH(FilePickerController::Open, + QQuickWebEngineFileDialogRequest::FileModeOpen) +ASSERT_ENUMS_MATCH(FilePickerController::OpenMultiple, + QQuickWebEngineFileDialogRequest::FileModeOpenMultiple) +ASSERT_ENUMS_MATCH(FilePickerController::UploadFolder, + QQuickWebEngineFileDialogRequest::FileModeUploadFolder) +ASSERT_ENUMS_MATCH(FilePickerController::Save, + QQuickWebEngineFileDialogRequest::FileModeSave) + +/*! + \qmltype AuthenticationDialogRequest + \instantiates QQuickWebEngineAuthenticationDialogRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for providing authentication credentials required + by proxies or HTTP servers. + + An AuthenticationDialogRequest is passed as an argument of the + WebEngineView::authenticationDialogRequested signal. It is generated + when basic HTTP or proxy authentication is required. The type + of authentication can be checked with the \l type property. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default dialog should be displayed. + If you set the \l accepted property to \c true, make sure to call + either \l dialogAccept() or \l dialogReject() afterwards. + + The following code uses a custom dialog to handle the request: + \code + + WebEngineView { + // ... + onAuthenticationDialogRequested: function(request) { + request.accepted = true; + myDialog.request = request // keep the reference to the request + myDialog.accept.connect(request.dialogAccept); + myDialog.reject.connect(request.dialogReject); + myDialog.visible = true; + } + // ... + } + + \endcode +*/ + +QQuickWebEngineAuthenticationDialogRequest::QQuickWebEngineAuthenticationDialogRequest( + QSharedPointer<AuthenticationDialogController> controller, + QObject *parent): + QObject(parent) + , m_controller(controller.toWeakRef()) + , m_url(controller->url()) + , m_realm(controller->realm()) + , m_type(controller->isProxy() ? AuthenticationTypeProxy + : AuthenticationTypeHTTP) + , m_host(controller->host()) + , m_accepted(false) +{ + +} + +QQuickWebEngineAuthenticationDialogRequest::~QQuickWebEngineAuthenticationDialogRequest() +{ +} + +/*! + \qmlproperty url AuthenticationDialogRequest::url + \readonly + + The URL of the HTTP request for which authentication was requested. + In case of proxy authentication, this is a request URL which is proxied + via host. + + \sa proxyHost +*/ + +QUrl QQuickWebEngineAuthenticationDialogRequest::url() const +{ + return m_url; +} + +/*! + \qmlproperty string AuthenticationDialogRequest::realm + \readonly + + The HTTP authentication realm attribute value of the \c WWW-Authenticate + header. Empty if \l type is AuthenticationTypeProxy. +*/ + +QString QQuickWebEngineAuthenticationDialogRequest::realm() const +{ + return m_realm; +} + +/*! + \qmlproperty string AuthenticationDialogRequest::proxyHost + \readonly + + The hostname of the authentication proxy. + Empty if \l type is AuthenticationTypeHTTP. +*/ + +QString QQuickWebEngineAuthenticationDialogRequest::proxyHost() const +{ + return m_host; +} + +/*! + \qmlproperty AuthenticationType AuthenticationDialogRequest::type + \readonly + + The type of the authentication request. + + \value AuthenticationTypeHTTP + HTTP authentication. + \value AuthenticationTypeProxy + Proxy authentication. +*/ + +QQuickWebEngineAuthenticationDialogRequest::AuthenticationType +QQuickWebEngineAuthenticationDialogRequest::type() const +{ + return m_type; +} + +/*! + \qmlproperty bool AuthenticationDialogRequest::accepted + + Indicates whether the authentication dialog request has been + accepted by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::authenticationDialogRequested have been executed, + a default authentication dialog will be shown. + To prevent this, set \c{request.accepted} to \c true. + + The default is \c false. +*/ + +bool QQuickWebEngineAuthenticationDialogRequest::isAccepted() const +{ + return m_accepted; +} + +void QQuickWebEngineAuthenticationDialogRequest::setAccepted(bool accepted) +{ + m_accepted = accepted; +} + +/*! + \qmlmethod void AuthenticationDialogRequest::dialogAccept(string username, string password) + + This function notifies the engine that the user accepted the dialog, + providing the \a username and the \a password required for authentication. +*/ + +void QQuickWebEngineAuthenticationDialogRequest::dialogAccept(const QString &user, + const QString &password) +{ + m_accepted = true; + QSharedPointer<AuthenticationDialogController> controller + = m_controller.toStrongRef(); + if (controller) + controller->accept(user,password); +} + +/*! + \qmlmethod void AuthenticationDialogRequest::dialogReject() + + This function notifies the engine that the user rejected the dialog and the + authentication shall not proceed. +*/ + +void QQuickWebEngineAuthenticationDialogRequest::dialogReject() +{ + m_accepted = true; + QSharedPointer<AuthenticationDialogController> controller + = m_controller.toStrongRef(); + if (controller) + controller->reject(); +} + +/////////////////////////////////////////////////////////////////////////////// + +/*! + \qmltype JavaScriptDialogRequest + \instantiates QQuickWebEngineJavaScriptDialogRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for showing an alert, a confirmation, or a prompt dialog + from within JavaScript to the user. + + A JavaScriptDialogRequest is passed as an argument of the + WebEngineView::javaScriptDialogRequested signal. The request is emitted + if JavaScript on the page calls HTML5's + \l{https://www.w3.org/TR/html5/webappapis.html#simple-dialogs}{Simple Dialogs} + API, or in response to HTML5's + \l {https://www.w3.org/TR/html5/browsers.html#beforeunloadevent}{BeforeUnloadEvent}. + The type of a particular dialog can be checked with the \l type property. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default dialog should be displayed. + If you set the \l accepted property to \c true, make sure to call either + \l dialogAccept() or \l dialogReject() afterwards. The JavaScript call + causing the request will be blocked until then. + + The following code uses a custom dialog to handle the request: + + \code + WebEngineView { + // ... + onJavaScriptDialogRequested: function(request) { + request.accepted = true; + myDialog.request = request // keep the reference to the request + myDialog.accept.connect(request.dialogAccept); + myDialog.reject.connect(request.dialogReject); + myDialog.visible = true; + } + // ... + } + \endcode +*/ + +QQuickWebEngineJavaScriptDialogRequest::QQuickWebEngineJavaScriptDialogRequest( + QSharedPointer<JavaScriptDialogController> controller, QObject *parent): + QObject(parent) + , m_controller(controller.toWeakRef()) + , m_message(controller->message()) + , m_defaultPrompt(controller->defaultPrompt()) + , m_title(controller->title()) + , m_type(static_cast<QQuickWebEngineJavaScriptDialogRequest::DialogType>(controller->type())) + , m_securityOrigin(controller->securityOrigin()) + , m_accepted(false) +{ +} + +QQuickWebEngineJavaScriptDialogRequest::~QQuickWebEngineJavaScriptDialogRequest() +{ + +} + +/*! + \qmlproperty string JavaScriptDialogRequest::message + \readonly + + The message to be shown to the user. +*/ + +QString QQuickWebEngineJavaScriptDialogRequest::message() const +{ + return m_message; +} + +/*! + \qmlproperty string JavaScriptDialogRequest::defaultPrompt + \readonly + + The default text if the requested dialog box is of + the \l type PromptDialog. +*/ + + +QString QQuickWebEngineJavaScriptDialogRequest::defaultText() const +{ + return m_defaultPrompt; +} + +/*! + \qmlproperty string JavaScriptDialogRequest::title + \readonly + + A default title for the dialog. +*/ + +QString QQuickWebEngineJavaScriptDialogRequest::title() const +{ + return m_title; +} + +/*! + \qmlproperty enumeration JavaScriptDialogRequest::type + \readonly + + Returns the type of the requested dialog box, see HTML5's + + \l{https://www.w3.org/TR/html5/webappapis.html#simple-dialogs}{Simple Dialogs}. + + \value JavaScriptDialogRequest.DialogTypeAlert + A JavaScript alert dialog. + \value JavaScriptDialogRequest.DialogTypeConfirm + A JavaScript confirmation dialog. + \value JavaScriptDialogRequest.DialogTypePrompt + A JavaScript prompt dialog. + \value JavaScriptDialogRequest.DialogTypeUnload + The users should be asked if they want to leave the page. +*/ + +QQuickWebEngineJavaScriptDialogRequest::DialogType QQuickWebEngineJavaScriptDialogRequest::type() const +{ + return m_type; +} + +/*! + \qmlproperty url JavaScriptDialogRequest::securityOrigin + \readonly + + The URL of the security origin. +*/ + +QUrl QQuickWebEngineJavaScriptDialogRequest::securityOrigin() const +{ + return m_securityOrigin; +} + +/*! + \qmlproperty bool JavaScriptDialogRequest::accepted + + Indicates whether the JavaScript dialog request has been + accepted by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::javaScriptDialogRequested have been executed, + a default dialog will be shown. + To prevent this, set \c{request.accepted} to \c true. + + The default is \c false. +*/ + +bool QQuickWebEngineJavaScriptDialogRequest::isAccepted() const +{ + return m_accepted; +} + +void QQuickWebEngineJavaScriptDialogRequest::setAccepted(bool accepted) +{ + m_accepted = accepted; +} + +/*! + \qmlmethod void JavaScriptDialogRequest::dialogAccept() + + This function notifies the engine that the user accepted the dialog. +*/ + +/*! + \qmlmethod void JavaScriptDialogRequest::dialogAccept(string text) + + This function notifies the engine that the user accepted the dialog, + providing the \a text in case of a prompt message box. +*/ + +void QQuickWebEngineJavaScriptDialogRequest::dialogAccept(const QString& text) +{ + m_accepted = true; + QSharedPointer<JavaScriptDialogController> controller + = m_controller.toStrongRef(); + if (controller) { + controller->textProvided(text); + controller->accept(); + } +} + +/*! + \qmlmethod void JavaScriptDialogRequest::dialogReject() + + This function notifies the engine that the user rejected the dialog. +*/ + +void QQuickWebEngineJavaScriptDialogRequest::dialogReject() +{ + m_accepted = true; + QSharedPointer<JavaScriptDialogController> controller + = m_controller.toStrongRef(); + if (controller) + controller->reject(); +} + +/////////////////////////////////////////////////////////////////////////////// + +/*! + \qmltype ColorDialogRequest + \instantiates QQuickWebEngineColorDialogRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for selecting a color by the user. + + A ColorDialogRequest is passed as an argument of the + WebEngineView::colorDialogRequested signal. It is generated when + a color picker dialog is requested. See + \l { https://www.w3.org/TR/html5/forms.html#color-state-(type=color)} + {HTML5 Color State}. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default dialog should be displayed. + If you set the \l accepted property to \c true, make sure to call either + \l dialogAccept() or \l dialogReject() afterwards. + + The following code uses a custom dialog to handle the request: + + \code + WebEngineView { + // ... + onColorDialogRequested: function(request) { + request.accepted = true; + myDialog.request = request // keep the reference to the request + myDialog.accept.connect(request.dialogAccept); + myDialog.reject.connect(request.dialogReject); + myDialog.visible = true; + } + // ... + } + \endcode +*/ + +QQuickWebEngineColorDialogRequest::QQuickWebEngineColorDialogRequest( + QSharedPointer<ColorChooserController> controller, QObject *parent): + QObject(parent) + , m_controller(controller.toWeakRef()) + , m_color(controller->initialColor()) + , m_accepted(false) +{ + +} + +QQuickWebEngineColorDialogRequest::~QQuickWebEngineColorDialogRequest() +{ + +} + +/*! + \qmlproperty color ColorDialogRequest::color + \readonly + + The default color to be selected in the dialog. +*/ + +QColor QQuickWebEngineColorDialogRequest::color() const +{ + return m_color; +} + +/*! + \qmlproperty bool ColorDialogRequest::accepted + + Indicates whether the color picker dialog request has been + accepted by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::colorDialogRequested have been executed, + a default color picker dialog will be shown. + To prevent this, set \c{request.accepted} to \c true. + + The default is \c false. +*/ + +bool QQuickWebEngineColorDialogRequest::isAccepted() const +{ + return m_accepted; +} + +void QQuickWebEngineColorDialogRequest::setAccepted(bool accepted) +{ + m_accepted = accepted; +} + + +/*! + \qmlmethod void ColorDialogRequest::dialogAccept(color color) + + This function notifies the engine that the user accepted the dialog, + providing the \a color. +*/ + +void QQuickWebEngineColorDialogRequest::dialogAccept(const QColor &color) +{ + m_accepted = true; + QSharedPointer<ColorChooserController> controller = m_controller.toStrongRef(); + if (controller) + controller->accept(color); +} + +/*! + \qmlmethod void ColorDialogRequest::dialogReject() + + This function notifies the engine that the user rejected the dialog. +*/ + +void QQuickWebEngineColorDialogRequest::dialogReject() +{ + m_accepted = true; + QSharedPointer<ColorChooserController> controller = m_controller.toStrongRef(); + if (controller) + controller->reject(); +} + +/////////////////////////////////////////////////////////////////////////////// + +/*! + \qmltype FileDialogRequest + \instantiates QQuickWebEngineFileDialogRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for letting the user choose a (new or existing) file or + directory. + + A FileDialogRequest is passed as an argument of the + WebEngineView::fileDialogRequested signal. It is generated + when the file dialog is requested by the input element. + See \l {https://www.w3.org/TR/html5/forms.html#file-upload-state-(type=file)}{File Upload state}. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default dialog should be displayed. + If you set the \l accepted property to \c true, make sure to call either + \l dialogAccept() or \l dialogReject() afterwards. + + The following code uses a custom dialog to handle the request: + + \code + WebEngineView { + // ... + onFileDialogRequested: function(request) { + request.accepted = true; + myDialog.request = request // keep the reference to the request + myDialog.accept.connect(request.dialogAccept); + myDialog.reject.connect(request.dialogReject); + myDialog.visible = true; + } + // ... + } + \endcode +*/ + +QQuickWebEngineFileDialogRequest::QQuickWebEngineFileDialogRequest( + QSharedPointer<FilePickerController> controller, QObject *parent): + QObject(parent) + , m_controller(controller.toWeakRef()) + , m_filename(controller->defaultFileName()) + , m_acceptedMimeTypes(controller->acceptedMimeTypes()) + , m_mode(static_cast<QQuickWebEngineFileDialogRequest::FileMode>(controller->mode())) + , m_accepted(false) +{ + +} + +QQuickWebEngineFileDialogRequest::~QQuickWebEngineFileDialogRequest() +{ + +} + +/*! + \qmlproperty stringlist FileDialogRequest::acceptedMimeTypes + \readonly + + A list of MIME types specified in the input element. The selection + should be restricted to only these types of files. +*/ + +QStringList QQuickWebEngineFileDialogRequest::acceptedMimeTypes() const +{ + return m_acceptedMimeTypes; +} + +/*! + \qmlproperty string FileDialogRequest::defaultFileName + \readonly + + The default name of the file to be selected in the dialog. +*/ + +QString QQuickWebEngineFileDialogRequest::defaultFileName() const +{ + return m_filename; +} + +/*! + \qmlproperty enumeration FileDialogRequest::mode + \readonly + + The mode of the file dialog. + + \value FileDialogRequest.FileModeOpen + Allows users to specify a single existing file. + \value FileDialogRequest.FileModeOpenMultiple + Allows users to specify multiple existing files. + \value FileDialogRequest.FileModeUploadFolder + Allows users to specify a single existing folder for upload. + \value FileDialogRequest.FileModeSave + Allows users to specify a non-existing file. If an existing file + is selected, the users should be informed that the file is going + to be overwritten. +*/ + +QQuickWebEngineFileDialogRequest::FileMode QQuickWebEngineFileDialogRequest::mode() const +{ + return m_mode; +} + +/*! + \qmlproperty bool FileDialogRequest::accepted + + Indicates whether the file picker dialog request has been + handled by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::fileDialogRequested have been executed, + a default file picker dialog will be shown. + To prevent this, set \c{request.accepted} to \c true. + + The default is \c false. +*/ + +bool QQuickWebEngineFileDialogRequest::isAccepted() const +{ + return m_accepted; +} + +void QQuickWebEngineFileDialogRequest::setAccepted(bool accepted) +{ + m_accepted = accepted; +} + +/*! + \qmlmethod void FileDialogRequest::dialogAccept(stringlist files) + + This function needs to be called when the user accepted the dialog with + \a files. +*/ + +void QQuickWebEngineFileDialogRequest::dialogAccept(const QStringList &files) +{ + m_accepted = true; + QSharedPointer<FilePickerController> controller = m_controller.toStrongRef(); + if (controller) + controller->accepted(files); +} + +/*! + \qmlmethod void FileDialogRequest::dialogReject() + + This function needs to be called when the user did not accepted the dialog. +*/ + +void QQuickWebEngineFileDialogRequest::dialogReject() +{ + m_accepted = true; + QSharedPointer<FilePickerController> controller = m_controller.toStrongRef(); + if (controller) + controller->rejected(); +} + +/////////////////////////////////////////////////////////////////////////////// + +/*! + \qmltype FormValidationMessageRequest + \instantiates QQuickWebEngineFormValidationMessageRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.4 + + \brief A request for showing a HTML5 form validation message to the user. + + A FormValidationMessageRequest is passed as an argument of the + WebEngineView::formValidationMessageRequested signal. It is generated when + the handling of the validation message is requested. + + The \l accepted property of the request indicates whether the request + is handled by the user code or the default message should be displayed. + + The following code uses a custom message to handle the request: + + \code + WebEngineView { + // ... + onFormValidationMessageRequested: function(request) { + request.accepted = true; + switch (request.type) { + case FormValidationMessageRequest.RequestTypeShow: + validationMessgae.text = request.text; + validationMessgae.x = request.x; + validationMessage.y = request.y + validationMessgae.visible = true; + break; + case FormValidationMessageRequest.RequestTypeMove: + break; + case FormValidationMessageRequest.RequestTypeHide: + validationMessgae.visible = false; + break; + } + } + // ... + } + \endcode +*/ + +QQuickWebEngineFormValidationMessageRequest::QQuickWebEngineFormValidationMessageRequest( + QQuickWebEngineFormValidationMessageRequest::RequestType type, const QRect& anchor, + const QString &mainText, const QString &subText, QObject *parent): + QObject(parent) + , m_anchor(anchor) + , m_mainText(mainText) + , m_subText(subText) + , m_type(type) + , m_accepted(false) +{ + +} + +QQuickWebEngineFormValidationMessageRequest::~QQuickWebEngineFormValidationMessageRequest() +{ + +} + +/*! + \qmlproperty rectangle FormValidationMessageRequest::anchor + \readonly + + An anchor of an element in the viewport for which the form + validation message should be displayed. +*/ + +QRect QQuickWebEngineFormValidationMessageRequest::anchor() const +{ + return m_anchor; +} + +/*! + \qmlproperty bool FormValidationMessageRequest::text + \readonly + + The text of the form validation message. +*/ + + +QString QQuickWebEngineFormValidationMessageRequest::text() const +{ + return m_mainText; +} + +/*! + \qmlproperty bool FormValidationMessageRequest::subText + \readonly + + The subtext of the form validation message. +*/ + + +QString QQuickWebEngineFormValidationMessageRequest::subText() const +{ + return m_subText; +} + +/*! + \qmlproperty enumeration ValidationMessageRequest::type + \readonly + + The type of the form validation message request. + + \value ValidationMessageRequest.RequestTypeShow + The form validation message should be shown. + \value ValidationMessageRequest.RequestTypeHide + The form validation message should be hidden. + \value ValidationMessageRequest.RequestTypeMove + The form validation message should be moved. +*/ + +QQuickWebEngineFormValidationMessageRequest::RequestType QQuickWebEngineFormValidationMessageRequest::type() const +{ + return m_type; +} + +/*! + \qmlproperty bool FormValidationMessageRequest::accepted + + Indicates whether the form validation request has been + accepted by the signal handler. + + If the property is \c false after any signal handlers + for WebEngineView::validationMessageRequested have been executed, + a default file validation message will be shown. + To prevent this, set \c {request.accepted} to \c true. + + The default is \c false. +*/ + +bool QQuickWebEngineFormValidationMessageRequest::isAccepted() const +{ + return m_accepted; +} + +void QQuickWebEngineFormValidationMessageRequest::setAccepted(bool accepted) +{ + m_accepted = accepted; +} + +QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginedialogrequests_p.h b/src/webengine/api/qquickwebenginedialogrequests_p.h new file mode 100644 index 000000000..d1ddc6607 --- /dev/null +++ b/src/webengine/api/qquickwebenginedialogrequests_p.h @@ -0,0 +1,265 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINDIALOGREQUESTS_H +#define QQUICKWEBENGINDIALOGREQUESTS_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <private/qtwebengineglobal_p.h> +#include <QtCore/QUrl> +#include <QtCore/QWeakPointer> +#include <QtCore/QRect> +#include <QtGui/QColor> + +namespace QtWebEngineCore { + class AuthenticationDialogController; + class ColorChooserController; + class FilePickerController; + class JavaScriptDialogController; +} + +QT_BEGIN_NAMESPACE + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineAuthenticationDialogRequest : public QObject { + Q_OBJECT +public: + + enum AuthenticationType { + AuthenticationTypeHTTP, + AuthenticationTypeProxy + }; + + Q_ENUM(AuthenticationType) + + Q_PROPERTY(QUrl url READ url CONSTANT FINAL) + Q_PROPERTY(QString realm READ realm CONSTANT FINAL) + Q_PROPERTY(QString proxyHost READ proxyHost CONSTANT FINAL) + Q_PROPERTY(AuthenticationType type READ type CONSTANT FINAL) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) + + ~QQuickWebEngineAuthenticationDialogRequest(); + + QUrl url() const; + QString realm() const; + QString proxyHost() const; + AuthenticationType type() const; + bool isAccepted() const; + void setAccepted(bool accepted); + +public slots: + void dialogAccept(const QString &user, const QString &password); + void dialogReject(); + +private: + QQuickWebEngineAuthenticationDialogRequest(QSharedPointer<QtWebEngineCore::AuthenticationDialogController> controller, + QObject *parent = nullptr); + QWeakPointer<QtWebEngineCore::AuthenticationDialogController> m_controller; + QUrl m_url; + QString m_realm; + AuthenticationType m_type; + QString m_host; + bool m_accepted; + friend class QQuickWebEngineViewPrivate; + Q_DISABLE_COPY(QQuickWebEngineAuthenticationDialogRequest) +}; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineJavaScriptDialogRequest : public QObject { + Q_OBJECT +public: + + enum DialogType { + DialogTypeAlert, + DialogTypeConfirm, + DialogTypePrompt, + DialogTypeBeforeUnload, + }; + Q_ENUM(DialogType) + + Q_PROPERTY(QString message READ message CONSTANT FINAL) + Q_PROPERTY(QString defaultText READ defaultText CONSTANT FINAL) + Q_PROPERTY(QString title READ title CONSTANT FINAL) + Q_PROPERTY(DialogType type READ type CONSTANT FINAL) + Q_PROPERTY(QUrl securityOrigin READ securityOrigin CONSTANT FINAL) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) + + ~QQuickWebEngineJavaScriptDialogRequest(); + + QString message() const; + QString defaultText() const; + QString title() const; + DialogType type() const; + QUrl securityOrigin() const; + bool isAccepted() const; + void setAccepted(bool accepted); + +public slots: + void dialogAccept(const QString& text = QString()); + void dialogReject(); + +private: + QQuickWebEngineJavaScriptDialogRequest(QSharedPointer<QtWebEngineCore::JavaScriptDialogController> controller, + QObject *parent = nullptr); + QWeakPointer<QtWebEngineCore::JavaScriptDialogController> m_controller; + QString m_message; + QString m_defaultPrompt; + QString m_title; + DialogType m_type; + QUrl m_securityOrigin; + bool m_accepted; + friend class QQuickWebEngineViewPrivate; + Q_DISABLE_COPY(QQuickWebEngineJavaScriptDialogRequest) +}; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineColorDialogRequest : public QObject { + Q_OBJECT +public: + + Q_PROPERTY(QColor color READ color CONSTANT FINAL) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) + + ~QQuickWebEngineColorDialogRequest(); + + QColor color() const; + bool isAccepted() const; + void setAccepted(bool accepted); + +public slots: + void dialogAccept(const QColor &color); + void dialogReject(); + +private: + QQuickWebEngineColorDialogRequest(QSharedPointer<QtWebEngineCore::ColorChooserController> controller, + QObject *parent = nullptr); + QWeakPointer<QtWebEngineCore::ColorChooserController> m_controller; + QColor m_color; + bool m_accepted; + friend class QQuickWebEngineViewPrivate; + Q_DISABLE_COPY(QQuickWebEngineColorDialogRequest) +}; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineFileDialogRequest : public QObject { + Q_OBJECT +public: + + enum FileMode { + FileModeOpen, + FileModeOpenMultiple, + FileModeUploadFolder, + FileModeSave + }; + Q_ENUM(FileMode) + + Q_PROPERTY(QString defaultFileName READ defaultFileName CONSTANT FINAL) + Q_PROPERTY(QStringList acceptedMimeTypes READ acceptedMimeTypes CONSTANT FINAL) + Q_PROPERTY(FileMode mode READ mode CONSTANT FINAL) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) + + ~QQuickWebEngineFileDialogRequest(); + + QStringList acceptedMimeTypes() const; + QString defaultFileName() const; + FileMode mode() const; + bool isAccepted() const; + void setAccepted(bool accepted); + +public slots: + void dialogAccept(const QStringList &files); + void dialogReject(); + +private: + QQuickWebEngineFileDialogRequest(QSharedPointer<QtWebEngineCore::FilePickerController> controller, + QObject *parent = nullptr); + QWeakPointer<QtWebEngineCore::FilePickerController> m_controller; + QString m_filename; + QStringList m_acceptedMimeTypes; + FileMode m_mode; + bool m_accepted; + friend class QQuickWebEngineViewPrivate; + Q_DISABLE_COPY(QQuickWebEngineFileDialogRequest) +}; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineFormValidationMessageRequest : public QObject { + Q_OBJECT +public: + enum RequestType { + RequestTypeShow, + RequestTypeHide, + RequestTypeMove, + }; + Q_ENUM(RequestType) + Q_PROPERTY(QRect anchor READ anchor CONSTANT FINAL) + Q_PROPERTY(QString text READ text CONSTANT FINAL) + Q_PROPERTY(QString subText READ subText CONSTANT FINAL) + Q_PROPERTY(RequestType type READ type CONSTANT FINAL) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL) + + ~QQuickWebEngineFormValidationMessageRequest(); + QRect anchor() const; + QString text() const; + QString subText() const; + RequestType type() const; + bool isAccepted() const; + void setAccepted(bool accepted); + +private: + QQuickWebEngineFormValidationMessageRequest(RequestType type, const QRect &anchor = QRect(), + const QString &mainText = QString(), + const QString &subText = QString(), + QObject *parent = nullptr); + QRect m_anchor; + QString m_mainText; + QString m_subText; + RequestType m_type; + bool m_accepted; + friend class QQuickWebEngineViewPrivate; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINDIALOGREQUESTS_H diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index ad4d72d48..968c9787a 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -54,6 +54,7 @@ #include "qquickwebengineprofile_p.h" #include "qquickwebenginesettings_p.h" #include "qquickwebenginescript_p_p.h" +#include "qquickwebenginedialogrequests_p.h" #ifdef ENABLE_QML_TESTSUPPORT_API #include "qquickwebenginetestsupport_p.h" @@ -380,7 +381,13 @@ void QQuickWebEngineViewPrivate::navigationRequested(int navigationType, const Q void QQuickWebEngineViewPrivate::javascriptDialog(QSharedPointer<JavaScriptDialogController> dialog) { - ui()->showDialog(dialog); + Q_Q(QQuickWebEngineView); + QQuickWebEngineJavaScriptDialogRequest *request = new QQuickWebEngineJavaScriptDialogRequest(dialog); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->javaScriptDialogRequested(request); + if (!request->isAccepted()) + ui()->showDialog(dialog); } void QQuickWebEngineViewPrivate::allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) @@ -405,12 +412,24 @@ void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url void QQuickWebEngineViewPrivate::showColorDialog(QSharedPointer<ColorChooserController> controller) { - ui()->showColorDialog(controller); + Q_Q(QQuickWebEngineView); + QQuickWebEngineColorDialogRequest *request = new QQuickWebEngineColorDialogRequest(controller); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->colorDialogRequested(request); + if (!request->isAccepted()) + ui()->showColorDialog(controller); } -void QQuickWebEngineViewPrivate::runFileChooser(FilePickerController* controller) +void QQuickWebEngineViewPrivate::runFileChooser(QSharedPointer<FilePickerController> controller) { - ui()->showFilePicker(controller); + Q_Q(QQuickWebEngineView); + QQuickWebEngineFileDialogRequest *request = new QQuickWebEngineFileDialogRequest(controller); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->fileDialogRequested(request); + if (!request->isAccepted()) + ui()->showFilePicker(controller); } void QQuickWebEngineViewPrivate::passOnFocus(bool reverse) @@ -678,7 +697,13 @@ void QQuickWebEngineViewPrivate::javaScriptConsoleMessage(JavaScriptConsoleMessa void QQuickWebEngineViewPrivate::authenticationRequired(QSharedPointer<AuthenticationDialogController> controller) { - ui()->showDialog(controller); + Q_Q(QQuickWebEngineView); + QQuickWebEngineAuthenticationDialogRequest *request = new QQuickWebEngineAuthenticationDialogRequest(controller); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->authenticationDialogRequested(request); + if (!request->isAccepted()) + ui()->showDialog(controller); } void QQuickWebEngineViewPrivate::runMediaAccessPermissionRequest(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags requestFlags) @@ -1100,18 +1125,40 @@ void QQuickWebEngineViewPrivate::showValidationMessage(const QRect &anchor, cons if (m_testSupport) Q_EMIT m_testSupport->validationMessageShown(mainText, subText); #endif - - ui()->showMessageBubble(anchor, mainText, subText); + Q_Q(QQuickWebEngineView); + QQuickWebEngineFormValidationMessageRequest *request; + request = new QQuickWebEngineFormValidationMessageRequest(QQuickWebEngineFormValidationMessageRequest::RequestTypeShow, + anchor,mainText,subText); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->formValidationMessageRequested(request); + if (!request->isAccepted()) + ui()->showMessageBubble(anchor, mainText, subText); } void QQuickWebEngineViewPrivate::hideValidationMessage() { - ui()->hideMessageBubble(); + Q_Q(QQuickWebEngineView); + QQuickWebEngineFormValidationMessageRequest *request; + request = new QQuickWebEngineFormValidationMessageRequest(QQuickWebEngineFormValidationMessageRequest::RequestTypeHide); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->formValidationMessageRequested(request); + if (!request->isAccepted()) + ui()->hideMessageBubble(); } void QQuickWebEngineViewPrivate::moveValidationMessage(const QRect &anchor) { - ui()->moveMessageBubble(anchor); + Q_Q(QQuickWebEngineView); + QQuickWebEngineFormValidationMessageRequest *request; + request = new QQuickWebEngineFormValidationMessageRequest(QQuickWebEngineFormValidationMessageRequest::RequestTypeMove, + anchor); + // mark the object for gc by creating temporary jsvalue + qmlEngine(q)->newQObject(request); + Q_EMIT q->formValidationMessageRequested(request); + if (!request->isAccepted()) + ui()->moveMessageBubble(anchor); } void QQuickWebEngineViewPrivate::updateScrollPosition(const QPointF &position) diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index dc693a94c..99d0848ce 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -59,15 +59,20 @@ QT_BEGIN_NAMESPACE class QQmlWebChannel; +class QQuickWebEngineAuthenticationDialogRequest; class QQuickWebEngineCertificateError; +class QQuickWebEngineColorDialogRequest; class QQuickWebEngineContextMenuData; class QQuickWebEngineFaviconProvider; +class QQuickWebEngineFileDialogRequest; class QQuickWebEngineHistory; +class QQuickWebEngineJavaScriptDialogRequest; class QQuickWebEngineLoadRequest; class QQuickWebEngineNavigationRequest; class QQuickWebEngineNewViewRequest; class QQuickWebEngineProfile; class QQuickWebEngineSettings; +class QQuickWebEngineFormValidationMessageRequest; class QQuickWebEngineViewExperimental; class QQuickWebEngineViewPrivate; @@ -507,6 +512,12 @@ Q_SIGNALS: Q_REVISION(3) void recentlyAudibleChanged(bool recentlyAudible); Q_REVISION(3) void webChannelWorldChanged(uint); + Q_REVISION(4) void authenticationDialogRequested(QQuickWebEngineAuthenticationDialogRequest *request); + Q_REVISION(4) void javaScriptDialogRequested(QQuickWebEngineJavaScriptDialogRequest *request); + Q_REVISION(4) void colorDialogRequested(QQuickWebEngineColorDialogRequest *request); + Q_REVISION(4) void fileDialogRequested(QQuickWebEngineFileDialogRequest *request); + Q_REVISION(4) void formValidationMessageRequested(QQuickWebEngineFormValidationMessageRequest *request); + protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; void itemChange(ItemChange, const ItemChangeData &) Q_DECL_OVERRIDE; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 60692b8ae..3ba1f8ae1 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -161,7 +161,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(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; + virtual void runFileChooser(QSharedPointer<QtWebEngineCore::FilePickerController>) Q_DECL_OVERRIDE; virtual void showColorDialog(QSharedPointer<QtWebEngineCore::ColorChooserController>) Q_DECL_OVERRIDE; virtual void didRunJavaScript(quint64, const QVariant&) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64, const QString&) Q_DECL_OVERRIDE { } diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc index d2c239341..eaf7936d2 100644 --- a/src/webengine/doc/src/webengineview.qdoc +++ b/src/webengine/doc/src/webengineview.qdoc @@ -1160,3 +1160,74 @@ \sa viewSource() */ + +/*! + \qmlsignal WebEngineView::authenticationDialogRequested(AuthenticationDialogRequest request) + \since QtWebEngine 1.4 + + This signal is emitted when an authentication dialog is requested. + + The request can be handled by using the methods of the AuthenticationDialogRequest + type. + + \note Signal handlers need to call \c{request.accepted = true} to prevent a + default dialog from showing up. Make sure to call either + AuthenticationDialogRequest::dialogAccept() or AuthenticationDialogRequest::dialogReject() + afterwards. +*/ + +/*! + \qmlsignal WebEngineView::javaScriptDialogRequested(JavaScriptDialogRequest request) + \since QtWebEngine 1.4 + + This signal is emitted when a JavaScript dialog is requested. + + The request can be handled by using the methods of the JavaScriptDialogRequest + type. + + \note Signal handlers need to call \c{request.accepted = true} to prevent a + default dialog from showing up. Make sure to call either + JavaScriptDialogRequest::dialogAccept() or JavaScriptDialogRequest::dialogReject() + afterwards. +*/ + +/*! + \qmlsignal WebEngineView::colorDialogRequested(ColorDialogRequest request) + \since QtWebEngine 1.4 + + This signal is emitted when a color picker dialog is requested. + + The request can be handled by using the methods of the ColorDialogRequest + type. + + \note Signal handlers need to call \c{request.accepted = true} to prevent a + default dialog from showing up. Make sure to call either + ColorDialogRequest::dialogAccept() or ColorDialogRequest::dialogReject() afterwards. +*/ + +/*! + \qmlsignal WebEngineView::fileDialogRequested(FileDialogRequest request) + \since QtWebEngine 1.4 + + This signal is emitted when a file picker dialog is requested. + + The request error can be handled by using the methods of the FileDialogRequest + type. + + \note Signal handlers need to call \c{request.accepted = true} to prevent a + default dialog from showing up. Make sure to call either FileDialogRequest::dialogAccept() + or FileDialogRequest::dialogReject() afterwards. +*/ + +/*! + \qmlsignal WebEngineView::formValidationMessageRequested(FormValidationMessageRequest request) + \since QtWebEngine 1.4 + + This signal is emitted when a validation message is requested. + + The request can be handled by using the methods of the FormValidationMessageRequest + type. + + \note Signal handlers need to call \c{request.accepted = true} to prevent a + default dialog from showing up. +*/ diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index 5c33086c0..0bf2e3d8e 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -41,6 +41,7 @@ #include <QtWebEngine/QQuickWebEngineProfile> #include "qquickwebenginecertificateerror_p.h" +#include "qquickwebenginedialogrequests_p.h" #include "qquickwebenginedownloaditem_p.h" #include "qquickwebenginehistory_p.h" #include "qquickwebenginefaviconprovider_p_p.h" @@ -109,6 +110,17 @@ public: qmlRegisterUncreatableType<QQuickWebEngineFullScreenRequest>(uri, 1, 1, "FullScreenRequest", tr("Cannot create a separate instance of FullScreenRequest")); + qmlRegisterUncreatableType<QQuickWebEngineAuthenticationDialogRequest>(uri, 1, 4, "AuthenticationDialogRequest", + tr("Cannot create separate instance of AuthenticationDialogRequest")); + qmlRegisterUncreatableType<QQuickWebEngineJavaScriptDialogRequest>(uri, 1, 4, "JavaScriptDialogRequest", + tr("Cannot create separate instance of JavaScriptDialogRequest")); + qmlRegisterUncreatableType<QQuickWebEngineColorDialogRequest>(uri, 1, 4, "ColorDialogRequest", + tr("Cannot create separate instance of ColorDialogRequest")); + qmlRegisterUncreatableType<QQuickWebEngineFileDialogRequest>(uri, 1, 4, "FileDialogRequest", + tr("Cannot create separate instance of FileDialogRequest")); + qmlRegisterUncreatableType<QQuickWebEngineFormValidationMessageRequest>(uri, 1, 4, "FormValidationMessageRequest", + tr("Cannot create separate instance of FormValidationMessageRequest")); + // For now (1.x import), the latest revision matches the minor version of the import. qmlRegisterRevision<QQuickWebEngineView, LATEST_WEBENGINEVIEW_REVISION>(uri, 1, LATEST_WEBENGINEVIEW_REVISION); } diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp index 608ce2ab3..4ca4ba98c 100644 --- a/src/webengine/ui_delegates_manager.cpp +++ b/src/webengine/ui_delegates_manager.cpp @@ -445,7 +445,7 @@ void UIDelegatesManager::showDialog(QSharedPointer<AuthenticationDialogControlle QMetaObject::invokeMethod(authenticationDialog, "open"); } -void UIDelegatesManager::showFilePicker(FilePickerController *controller) +void UIDelegatesManager::showFilePicker(QSharedPointer<FilePickerController> controller) { if (!ensureComponentLoaded(FilePicker)) @@ -475,16 +475,14 @@ void UIDelegatesManager::showFilePicker(FilePickerController *controller) Q_UNREACHABLE(); } - controller->setParent(filePicker); - QQmlProperty filesPickedSignal(filePicker, QStringLiteral("onFilesSelected")); CHECK_QML_SIGNAL_PROPERTY(filesPickedSignal, filePickerComponent->url()); QQmlProperty rejectSignal(filePicker, QStringLiteral("onRejected")); CHECK_QML_SIGNAL_PROPERTY(rejectSignal, filePickerComponent->url()); static int acceptedIndex = controller->metaObject()->indexOfSlot("accepted(QVariant)"); - QObject::connect(filePicker, filesPickedSignal.method(), controller, controller->metaObject()->method(acceptedIndex)); + QObject::connect(filePicker, filesPickedSignal.method(), controller.data(), controller->metaObject()->method(acceptedIndex)); static int rejectedIndex = controller->metaObject()->indexOfSlot("rejected()"); - QObject::connect(filePicker, rejectSignal.method(), controller, controller->metaObject()->method(rejectedIndex)); + QObject::connect(filePicker, rejectSignal.method(), controller.data(), controller->metaObject()->method(rejectedIndex)); // delete when done. static int deleteLaterIndex = filePicker->metaObject()->indexOfSlot("deleteLater()"); diff --git a/src/webengine/ui_delegates_manager.h b/src/webengine/ui_delegates_manager.h index b1eb65513..54ecf0986 100644 --- a/src/webengine/ui_delegates_manager.h +++ b/src/webengine/ui_delegates_manager.h @@ -118,7 +118,7 @@ public: void showColorDialog(QSharedPointer<ColorChooserController>); void showDialog(QSharedPointer<JavaScriptDialogController>); void showDialog(QSharedPointer<AuthenticationDialogController>); - void showFilePicker(FilePickerController *controller); + void showFilePicker(QSharedPointer<FilePickerController>); virtual void showMenu(QObject *menu); void showMessageBubble(const QRect &anchor, const QString &mainText, const QString &subText); diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro index 236881958..1b361d6ae 100644 --- a/src/webengine/webengine.pro +++ b/src/webengine/webengine.pro @@ -13,6 +13,7 @@ INCLUDEPATH += $$PWD api ../core ../core/api SOURCES = \ api/qquickwebenginecertificateerror.cpp \ api/qquickwebenginecontextmenudata.cpp \ + api/qquickwebenginedialogrequests.cpp \ api/qquickwebenginedownloaditem.cpp \ api/qquickwebenginehistory.cpp \ api/qquickwebenginefaviconprovider.cpp \ @@ -34,6 +35,7 @@ HEADERS = \ api/qtwebengineglobal_p.h \ api/qquickwebenginecertificateerror_p.h \ api/qquickwebenginecontextmenudata_p.h \ + api/qquickwebenginedialogrequests_p.h \ api/qquickwebenginedownloaditem_p.h \ api/qquickwebenginedownloaditem_p_p.h \ api/qquickwebenginehistory_p.h \ diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 428cccd9a..ae933f01b 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -1542,7 +1542,7 @@ static inline QWebEnginePage::FileSelectionMode toPublic(FilePickerController::F return static_cast<QWebEnginePage::FileSelectionMode>(mode); } -void QWebEnginePagePrivate::runFileChooser(FilePickerController *controller) +void QWebEnginePagePrivate::runFileChooser(QSharedPointer<FilePickerController> controller) { Q_Q(QWebEnginePage); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 93ebdf6e6..8d78429d8 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -112,7 +112,7 @@ public: virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) Q_DECL_OVERRIDE; virtual bool isFullScreenMode() const Q_DECL_OVERRIDE; virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; - virtual void runFileChooser(QtWebEngineCore::FilePickerController *controller) Q_DECL_OVERRIDE; + virtual void runFileChooser(QSharedPointer<QtWebEngineCore::FilePickerController>) Q_DECL_OVERRIDE; virtual void showColorDialog(QSharedPointer<QtWebEngineCore::ColorChooserController>) 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; diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index af69a25de..92a96273c 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -36,6 +36,7 @@ #include <QtWebEngine/QQuickWebEngineProfile> #include <private/qquickwebengineview_p.h> #include <private/qquickwebenginecertificateerror_p.h> +#include <private/qquickwebenginedialogrequests_p.h> #include <private/qquickwebenginedownloaditem_p.h> #include <private/qquickwebenginehistory_p.h> #include <private/qquickwebengineloadrequest_p.h> @@ -65,6 +66,11 @@ static QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>() << &QQuickWebEngineSettings::staticMetaObject << &QQuickWebEngineFullScreenRequest::staticMetaObject << &QQuickWebEngineSingleton::staticMetaObject + << &QQuickWebEngineAuthenticationDialogRequest::staticMetaObject + << &QQuickWebEngineJavaScriptDialogRequest::staticMetaObject + << &QQuickWebEngineColorDialogRequest::staticMetaObject + << &QQuickWebEngineFileDialogRequest::staticMetaObject + << &QQuickWebEngineFormValidationMessageRequest::staticMetaObject ; static QList<const char *> knownEnumNames = QList<const char *>(); |