From 7b365eb352780dc0d939e918b0aa58d0458fd9da Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Mon, 17 Oct 2016 07:00:26 -0700 Subject: Support Quota Management API Expose navigator.webkitPersistentStorage.requestQuota() calls to the API layer as a permission API. It allows the users to accept these requests and specify a quota for persistent storage. https://developer.chrome.com/apps/offline_storage#managing_quota [ChangeLog] navigator.webkitPersistentStorage.requestQuota() calls were rejected by default and now they will emit signal quotaPermissionRequested in both WebEngineView and QWebEnginePage. Task-number: QTBUG-56354 Change-Id: Id192577ffb403694d3051414744ded89bbfd2aa8 Reviewed-by: Allan Sandfeld Jensen --- src/core/content_browser_client_qt.cpp | 12 +-- src/core/core_chromium.pri | 5 + src/core/quota_permission_context_qt.cpp | 107 +++++++++++++++++++++ src/core/quota_permission_context_qt.h | 61 ++++++++++++ src/core/quota_permission_controller.cpp | 98 +++++++++++++++++++ src/core/quota_permission_controller.h | 70 ++++++++++++++ src/core/quota_permission_controller_p.h | 66 +++++++++++++ src/core/web_contents_adapter_client.h | 2 + src/webengine/api/qquickwebengineview.cpp | 37 +++++++ src/webengine/api/qquickwebengineview_p.h | 28 ++++++ src/webengine/api/qquickwebengineview_p_p.h | 1 + src/webengine/doc/src/webengineview.qdoc | 58 +++++++++++ src/webengine/plugin/plugin.cpp | 2 + src/webenginewidgets/api/qwebenginepage.cpp | 19 ++++ src/webenginewidgets/api/qwebenginepage.h | 2 + src/webenginewidgets/api/qwebenginepage_p.h | 1 + .../api/qwebenginequotapermissionrequest.cpp | 98 +++++++++++++++++++ .../api/qwebenginequotapermissionrequest.h | 71 ++++++++++++++ src/webenginewidgets/webenginewidgets.pro | 2 + 19 files changed, 729 insertions(+), 11 deletions(-) create mode 100644 src/core/quota_permission_context_qt.cpp create mode 100644 src/core/quota_permission_context_qt.h create mode 100644 src/core/quota_permission_controller.cpp create mode 100644 src/core/quota_permission_controller.h create mode 100644 src/core/quota_permission_controller_p.h create mode 100644 src/webenginewidgets/api/qwebenginequotapermissionrequest.cpp create mode 100644 src/webenginewidgets/api/qwebenginequotapermissionrequest.h (limited to 'src') diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 5bce81f25..42c3f8951 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -54,7 +54,6 @@ #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/media_observer.h" -#include "content/public/browser/quota_permission_context.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -97,6 +96,7 @@ #include "printing_message_filter_qt.h" #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) #include "qrc_protocol_handler_qt.h" +#include "quota_permission_context_qt.h" #include "renderer_host/resource_dispatcher_host_delegate_qt.h" #include "renderer_host/user_resource_controller_host.h" #include "web_contents_delegate_qt.h" @@ -374,16 +374,6 @@ void ShareGroupQtQuick::AboutToAddFirstContext() #endif } -class QuotaPermissionContextQt : public content::QuotaPermissionContext { -public: - void RequestQuotaPermission(const content::StorageQuotaParams ¶ms, int render_process_id, const PermissionCallback &callback) override - { - Q_UNUSED(params); - Q_UNUSED(render_process_id); - callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); - } -}; - ContentBrowserClientQt::ContentBrowserClientQt() : m_browserMainParts(0) { diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri index f13095bfe..7b55394a4 100644 --- a/src/core/core_chromium.pri +++ b/src/core/core_chromium.pri @@ -77,6 +77,8 @@ SOURCES = \ process_main.cpp \ proxy_config_service_qt.cpp \ qrc_protocol_handler_qt.cpp \ + quota_permission_context_qt.cpp \ + quota_permission_controller.cpp \ render_view_observer_host_qt.cpp \ render_widget_host_view_qt.cpp \ render_widget_host_view_qt_delegate.cpp \ @@ -153,6 +155,9 @@ HEADERS = \ process_main.h \ proxy_config_service_qt.h \ qrc_protocol_handler_qt.h \ + quota_permission_context_qt.h \ + quota_permission_controller.h \ + quota_permission_controller_p.h \ render_view_observer_host_qt.h \ render_widget_host_view_qt.h \ render_widget_host_view_qt_delegate.h \ diff --git a/src/core/quota_permission_context_qt.cpp b/src/core/quota_permission_context_qt.cpp new file mode 100644 index 000000000..10249bbf0 --- /dev/null +++ b/src/core/quota_permission_context_qt.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 "quota_permission_context_qt.h" + +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/web_contents.h" +#include "quota_permission_controller.h" +#include "quota_permission_controller_p.h" +#include "web_contents_delegate_qt.h" +#include "web_contents_view_qt.h" + +using content::QuotaPermissionContext; +using content::RenderFrameHost; +using content::StorageQuotaParams; +using content::WebContents; + +namespace QtWebEngineCore { + +void QuotaPermissionContextQt::RequestQuotaPermission(const StorageQuotaParams ¶ms, int render_process_id, const PermissionCallback &callback) +{ + if (params.storage_type != storage::kStorageTypePersistent) { + // For now we only support requesting quota with this interface + // for Persistent storage type. + callback.Run(QUOTA_PERMISSION_RESPONSE_DISALLOW); + return; + } + + if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&QuotaPermissionContextQt::RequestQuotaPermission, this, + params, render_process_id, callback)); + return; + } + + RenderFrameHost *renderFrameHost = RenderFrameHost::FromID(render_process_id, params.render_frame_id); + if (!renderFrameHost) + return; + + WebContents *webContents = WebContents::FromRenderFrameHost(renderFrameHost); + if (!webContents) + return; + + WebContentsAdapterClient *client = WebContentsViewQt::from(static_cast(webContents)->GetView())->client(); + if (!client) + return; + + QSharedPointer controller(new QuotaPermissionController(new QuotaPermissionControllerPrivate(this, params, callback))); + client->runQuotaPermissionRequest(controller); +} + +void QuotaPermissionContextQt::dispatchCallbackOnIOThread(const PermissionCallback &callback, + QuotaPermissionContext::QuotaPermissionResponse response) +{ + if (callback.is_null()) + return; + + if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { + content::BrowserThread::PostTask( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&QuotaPermissionContextQt::dispatchCallbackOnIOThread, + this, callback, response)); + return; + } + + callback.Run(response); +} + +} // namespace QtWebEngineCore diff --git a/src/core/quota_permission_context_qt.h b/src/core/quota_permission_context_qt.h new file mode 100644 index 000000000..68d768ac6 --- /dev/null +++ b/src/core/quota_permission_context_qt.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 QUOTA_PERMISSION_CONTEXT_QT_H +#define QUOTA_PERMISSION_CONTEXT_QT_H + +#include "content/public/browser/quota_permission_context.h" + +#include // Needed for Q_DECL_OVERRIDE + +namespace QtWebEngineCore { + +class QuotaPermissionContextQt : public content::QuotaPermissionContext { +public: + void RequestQuotaPermission(const content::StorageQuotaParams ¶ms, + int render_process_id, + const PermissionCallback &callback) Q_DECL_OVERRIDE; + + void dispatchCallbackOnIOThread(const PermissionCallback &callback, + QuotaPermissionContext::QuotaPermissionResponse response); +}; + +} // namespace QtWebEngineCore + +#endif // QUOTA_PERMISSION_CONTEXT_QT_H diff --git a/src/core/quota_permission_controller.cpp b/src/core/quota_permission_controller.cpp new file mode 100644 index 000000000..59fc6198d --- /dev/null +++ b/src/core/quota_permission_controller.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 "quota_permission_controller.h" +#include "quota_permission_controller_p.h" + +#include "quota_permission_context_qt.h" +#include "type_conversion.h" + +namespace QtWebEngineCore { + +QuotaPermissionControllerPrivate::QuotaPermissionControllerPrivate(QuotaPermissionContextQt *context, + const content::StorageQuotaParams ¶ms, + const content::QuotaPermissionContext::PermissionCallback &callback) + : m_context(context), + m_originUrl(toQt(params.origin_url)), + m_requestedSize(params.requested_size), + m_callback(callback) +{ +} + +QuotaPermissionControllerPrivate::~QuotaPermissionControllerPrivate() +{ +} + +QuotaPermissionController::QuotaPermissionController(QuotaPermissionControllerPrivate *controllerPrivate) + : d(controllerPrivate) + , m_answered(false) +{ +} + +QuotaPermissionController::~QuotaPermissionController() +{ +} + +void QuotaPermissionController::accept() +{ + if (!m_answered) { + d->m_context->dispatchCallbackOnIOThread(d->m_callback, QuotaPermissionContextQt::QUOTA_PERMISSION_RESPONSE_ALLOW); + m_answered = true; + } +} + +void QuotaPermissionController::cancel() +{ + if (!m_answered) { + d->m_context->dispatchCallbackOnIOThread(d->m_callback, QuotaPermissionContextQt::QUOTA_PERMISSION_RESPONSE_DISALLOW); + m_answered = true; + } +} + +QUrl QuotaPermissionController::origin() +{ + return d->m_originUrl; +} + +qint64 QuotaPermissionController::requestedSize() +{ + return d->m_requestedSize; +} + +} // namespace QtWebEngineCore diff --git a/src/core/quota_permission_controller.h b/src/core/quota_permission_controller.h new file mode 100644 index 000000000..36f751c2c --- /dev/null +++ b/src/core/quota_permission_controller.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 QUOTA_PERMISSION_CONTROLLER_H +#define QUOTA_PERMISSION_CONTROLLER_H + +#include "qtwebenginecoreglobal.h" +#include +#include + +namespace QtWebEngineCore { + +class QuotaPermissionContextQt; +class QuotaPermissionControllerPrivate; + +class QWEBENGINE_EXPORT QuotaPermissionController { +public: + QuotaPermissionController(QuotaPermissionControllerPrivate *controllerPrivate); + ~QuotaPermissionController(); + + void accept(); + void cancel(); + + QUrl origin(); + qint64 requestedSize(); + +private: + QScopedPointer d; + bool m_answered; +}; + +} // namespace QtWebEngineCore + +#endif // QUOTA_PERMISSION_CONTROLLER_H diff --git a/src/core/quota_permission_controller_p.h b/src/core/quota_permission_controller_p.h new file mode 100644 index 000000000..c00ae42c9 --- /dev/null +++ b/src/core/quota_permission_controller_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 QUOTA_PERMISSION_CONTROLLER_P_H +#define QUOTA_PERMISSION_CONTROLLER_P_H + +#include "quota_permission_context_qt.h" +#include + +namespace QtWebEngineCore { + +class QuotaPermissionControllerPrivate { +public: + QuotaPermissionControllerPrivate(QuotaPermissionContextQt *context, + const content::StorageQuotaParams ¶ms, + const content::QuotaPermissionContext::PermissionCallback &callback); + ~QuotaPermissionControllerPrivate(); + +private: + scoped_refptr m_context; + QUrl m_originUrl; + qint64 m_requestedSize; + content::QuotaPermissionContext::PermissionCallback m_callback; + + friend class QuotaPermissionController; +}; + +} // namespace QtWebEngineCore + +#endif // QUOTA_PERMISSION_CONTROLLER_P_H diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 8b7365342..075f0a84b 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -64,6 +64,7 @@ class BrowserContextAdapter; class ColorChooserController; class FilePickerController; class JavaScriptDialogController; +class QuotaPermissionController; class RenderWidgetHostViewQt; class RenderWidgetHostViewQtDelegate; class RenderWidgetHostViewQtDelegateClient; @@ -367,6 +368,7 @@ public: virtual void runGeolocationPermissionRequest(const QUrl &securityOrigin) = 0; virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) = 0; virtual void runMouseLockPermissionRequest(const QUrl &securityOrigin) = 0; + virtual void runQuotaPermissionRequest(QSharedPointer) = 0; virtual WebEngineSettings *webEngineSettings() const = 0; virtual void showValidationMessage(const QRect &anchor, const QString &mainText, const QString &subText) = 0; virtual void hideValidationMessage() = 0; diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 123acb20c..f8fcb5793 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -45,6 +45,7 @@ #include "certificate_error_controller.h" #include "file_picker_controller.h" #include "javascript_dialog_controller.h" +#include "quota_permission_controller.h" #include "qquickwebenginehistory_p.h" #include "qquickwebenginecertificateerror_p.h" #include "qquickwebenginecontextmenurequest_p.h" @@ -722,6 +723,13 @@ void QQuickWebEngineViewPrivate::runMouseLockPermissionRequest(const QUrl &secur adapter->grantMouseLockPermission(false); } +void QQuickWebEngineViewPrivate::runQuotaPermissionRequest(QSharedPointer controller) +{ + Q_Q(QQuickWebEngineView); + QQuickWebEngineQuotaPermissionRequest request(controller); + Q_EMIT q->quotaPermissionRequested(request); +} + QObject *QQuickWebEngineViewPrivate::accessibilityParentObject() { Q_Q(QQuickWebEngineView); @@ -1854,5 +1862,34 @@ void QQuickWebEngineFullScreenRequest::reject() m_viewPrivate->setFullScreenMode(!m_toggleOn); } +QQuickWebEngineQuotaPermissionRequest::QQuickWebEngineQuotaPermissionRequest(QSharedPointer controller) + : d_ptr(controller) +{ +} + +QQuickWebEngineQuotaPermissionRequest::~QQuickWebEngineQuotaPermissionRequest() +{ +} + +void QQuickWebEngineQuotaPermissionRequest::accept() +{ + d_ptr->accept(); +} + +void QQuickWebEngineQuotaPermissionRequest::reject() +{ + d_ptr->cancel(); +} + +QUrl QQuickWebEngineQuotaPermissionRequest::origin() const +{ + return d_ptr->origin(); +} + +qint64 QQuickWebEngineQuotaPermissionRequest::requestedSize() const +{ + return d_ptr->requestedSize(); +} + QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index ae0523460..57f74ad01 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -56,6 +56,12 @@ #include #include + +namespace QtWebEngineCore { + class QuotaPermissionController; +} + + QT_BEGIN_NAMESPACE class QQmlWebChannel; @@ -98,6 +104,26 @@ private: const bool m_toggleOn; }; +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineQuotaPermissionRequest { + Q_GADGET + Q_PROPERTY(QUrl origin READ origin CONSTANT FINAL) + Q_PROPERTY(qint64 requestedSize READ requestedSize CONSTANT FINAL) +public: + QQuickWebEngineQuotaPermissionRequest() {} + QQuickWebEngineQuotaPermissionRequest(QSharedPointer controller); + ~QQuickWebEngineQuotaPermissionRequest(); + + Q_INVOKABLE void accept(); + Q_INVOKABLE void reject(); + QUrl origin() const; + qint64 requestedSize() const; + +private: + QSharedPointer d_ptr; +}; + +#define LATEST_WEBENGINEVIEW_REVISION 7 + class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_OBJECT Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged FINAL) @@ -529,6 +555,7 @@ Q_SIGNALS: Q_REVISION(4) void fileDialogRequested(QQuickWebEngineFileDialogRequest *request); Q_REVISION(4) void formValidationMessageRequested(QQuickWebEngineFormValidationMessageRequest *request); Q_REVISION(5) void pdfPrintingFinished(const QString &filePath, bool success); + Q_REVISION(7) void quotaPermissionRequested(const QQuickWebEngineQuotaPermissionRequest &request); #ifdef ENABLE_QML_TESTSUPPORT_API void testSupportChanged(); @@ -557,5 +584,6 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickWebEngineView) Q_DECLARE_METATYPE(QQuickWebEngineFullScreenRequest) +Q_DECLARE_METATYPE(QQuickWebEngineQuotaPermissionRequest) #endif // QQUICKWEBENGINEVIEW_P_H diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 19ecf5e1f..af19c7765 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -129,6 +129,7 @@ public: virtual void authenticationRequired(QSharedPointer) Q_DECL_OVERRIDE; virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) Q_DECL_OVERRIDE; virtual void runMouseLockPermissionRequest(const QUrl &securityOrigin) Q_DECL_OVERRIDE; + virtual void runQuotaPermissionRequest(QSharedPointer) Q_DECL_OVERRIDE; virtual QObject *accessibilityParentObject() Q_DECL_OVERRIDE; virtual QtWebEngineCore::WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; virtual void allowCertificateError(const QSharedPointer &errorController) Q_DECL_OVERRIDE; diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc index e14448aa4..fead1b443 100644 --- a/src/webengine/doc/src/webengineview.qdoc +++ b/src/webengine/doc/src/webengineview.qdoc @@ -1297,3 +1297,61 @@ /*! \qmlsignal WebEngineView::navigationRequested(WebEngineNavigationRequest request) This signal is emitted when the navigation request \a request is issued. */ + +/*! + \qmlsignal WebEngineView::quotaPermissionRequested(QuotaPermissionRequest request) + \since QtWebEngine 1.7 + + This signal is emitted when the web page requests larger persistent storage + than the application's current allocation in File System API. The default quota + is 0 bytes. + + \sa QuotaPermissionRequest +*/ + +/*! + \qmltype QuotaPermissionRequest + \instantiates QQuickWebEngineQuotaPermissionRequest + \inqmlmodule QtWebEngine + \since QtWebEngine 1.7 + + \brief A utility type for the WebEngineView::quotaPermissionRequested() signal. + + \sa WebEngineView::quotaPermissionRequested() +*/ + +/*! + \qmlproperty url QuotaPermissionRequest::origin + \readonly + + The URL of the web page that issued the quota permission request. +*/ + +/*! + \qmlproperty qint64 QuotaPermissionRequest::requestedSize + \readonly + + Contains the size of the requested disk space in bytes. +*/ + +/*! + \qmlmethod void QuotaPermissionRequest::accept() + + Accepts the quota permission request. + + \qml + WebEngineView { + onQuotaPermissionRequested: function(request) { + if (request.requestedSize <= 5 * 1024 * 1024) + request.accept(); + else + request.reject(); + } + } + \endqml +*/ + +/*! + \qmlmethod void QuotaPermissionRequest::reject() + Rejects a quota permission request. +*/ diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index 5ab792699..ddd748f41 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -133,6 +133,8 @@ public: msgUncreatableType("FileDialogRequest")); qmlRegisterUncreatableType(uri, 1, 4, "FormValidationMessageRequest", msgUncreatableType("FormValidationMessageRequest")); + qmlRegisterUncreatableType(uri, 1, 7, "QuotaPermissionRequest", + tr("Cannot create a separate instance of QuotaPermissionRequest")); } private: diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 178f6ec98..41034e43c 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -53,6 +53,7 @@ #include "qwebenginehistory_p.h" #include "qwebengineprofile.h" #include "qwebengineprofile_p.h" +#include "qwebenginequotapermissionrequest.h" #include "qwebenginescriptcollection_p.h" #include "qwebenginesettings.h" #include "qwebengineview.h" @@ -579,6 +580,13 @@ void QWebEnginePagePrivate::runMouseLockPermissionRequest(const QUrl &securityOr Q_EMIT q->featurePermissionRequested(securityOrigin, QWebEnginePage::MouseLock); } +void QWebEnginePagePrivate::runQuotaPermissionRequest(QSharedPointer controller) +{ + Q_Q(QWebEnginePage); + QWebEngineQuotaPermissionRequest request(controller); + Q_EMIT q->quotaPermissionRequested(request); +} + QObject *QWebEnginePagePrivate::accessibilityParentObject() { return view; @@ -739,6 +747,17 @@ QWebEnginePage::QWebEnginePage(QObject* parent) \sa QWebEngineSettings::FullScreenSupportEnabled */ +/*! + \fn QWebEnginePage::quotaPermissionRequested(QWebEngineQuotaPermissionRequest request) + \since 5.11 + + This signal is emitted when the web page requests larger persistent storage + than the application's current allocation in File System API. The default quota + is 0 bytes. + + The request object \a request can be used to accept or reject the request. +*/ + /*! \fn void QWebEnginePage::pdfPrintingFinished(const QString &filePath, bool success) \since 5.9 diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 295527e74..3fad6ca09 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -64,6 +64,7 @@ class QWebEngineHistory; class QWebEnginePage; class QWebEnginePagePrivate; class QWebEngineProfile; +class QWebEngineQuotaPermissionRequest; class QWebEngineScriptCollection; class QWebEngineSettings; @@ -330,6 +331,7 @@ Q_SIGNALS: void featurePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature); void featurePermissionRequestCanceled(const QUrl &securityOrigin, QWebEnginePage::Feature feature); void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); + void quotaPermissionRequested(QWebEngineQuotaPermissionRequest quotaPermissionRequest); void authenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator); void proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator, const QString &proxyHost); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index ec84f05e1..0f18f8d8a 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -126,6 +126,7 @@ public: virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) Q_DECL_OVERRIDE; virtual void runGeolocationPermissionRequest(const QUrl &securityOrigin) Q_DECL_OVERRIDE; virtual void runMouseLockPermissionRequest(const QUrl &securityOrigin) Q_DECL_OVERRIDE; + virtual void runQuotaPermissionRequest(QSharedPointer) Q_DECL_OVERRIDE; virtual QObject *accessibilityParentObject() Q_DECL_OVERRIDE; virtual QtWebEngineCore::WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; virtual void allowCertificateError(const QSharedPointer &controller) Q_DECL_OVERRIDE; diff --git a/src/webenginewidgets/api/qwebenginequotapermissionrequest.cpp b/src/webenginewidgets/api/qwebenginequotapermissionrequest.cpp new file mode 100644 index 000000000..0841854ea --- /dev/null +++ b/src/webenginewidgets/api/qwebenginequotapermissionrequest.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 "qwebenginequotapermissionrequest.h" + +#include "quota_permission_controller.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineQuotaPermissionRequest + \brief The QWebEngineQuotaPermissionRequest class enables accepting or rejecting + requests for larger persistent storage than the application's current allocation + in File System API. + + \since 5.11 + + \inmodule QtWebEngineWidgets +*/ + +QWebEngineQuotaPermissionRequest::QWebEngineQuotaPermissionRequest(QSharedPointer controller) + : d_ptr(controller) +{ +} + +/*! + Rejects a request for larger persistent storage. +*/ +void QWebEngineQuotaPermissionRequest::reject() +{ + d_ptr->cancel(); +} + +/*! + Accepts a request for larger persistent storage. +*/ +void QWebEngineQuotaPermissionRequest::accept() +{ + d_ptr->accept(); +} + +/*! + \property QWebEngineQuotaPermissionRequest::origin + \brief The URL of the web page that issued the quota permission request. +*/ + +QUrl QWebEngineQuotaPermissionRequest::origin() const +{ + return d_ptr->origin(); +} + +/*! + \property QWebEngineQuotaPermissionRequest::requestedSize + \brief Contains the size of the requested disk space in bytes. +*/ + +qint64 QWebEngineQuotaPermissionRequest::requestedSize() const +{ + return d_ptr->requestedSize(); +} + +QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginequotapermissionrequest.h b/src/webenginewidgets/api/qwebenginequotapermissionrequest.h new file mode 100644 index 000000000..aa0184fad --- /dev/null +++ b/src/webenginewidgets/api/qwebenginequotapermissionrequest.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 QWEBENGINEQUOTAPERMISSIONREQUEST_H +#define QWEBENGINEQUOTAPERMISSIONREQUEST_H + +#include +#include +#include + +namespace QtWebEngineCore { + class QuotaPermissionController; +} + +QT_BEGIN_NAMESPACE + +class QWEBENGINEWIDGETS_EXPORT QWebEngineQuotaPermissionRequest { + Q_GADGET + Q_PROPERTY(QUrl origin READ origin) + Q_PROPERTY(qint64 requestedSize READ requestedSize) +public: + Q_INVOKABLE void accept(); + Q_INVOKABLE void reject(); + QUrl origin() const; + qint64 requestedSize() const; + +private: + QWebEngineQuotaPermissionRequest(QSharedPointer controller); + QSharedPointer d_ptr; + friend class QWebEnginePagePrivate; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEQUOTAPERMISSIONREQUEST_H diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index ad79c1ef9..96341d58c 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -17,6 +17,7 @@ SOURCES = \ api/qwebenginehistory.cpp \ api/qwebenginepage.cpp \ api/qwebengineprofile.cpp \ + api/qwebenginequotapermissionrequest.cpp \ api/qwebenginescript.cpp \ api/qwebenginescriptcollection.cpp \ api/qwebenginesettings.cpp \ @@ -35,6 +36,7 @@ HEADERS = \ api/qwebenginepage_p.h \ api/qwebengineprofile.h \ api/qwebengineprofile_p.h \ + api/qwebenginequotapermissionrequest.h \ api/qwebenginescriptcollection.h \ api/qwebenginescriptcollection_p.h \ api/qwebenginesettings.h \ -- cgit v1.2.3