diff options
Diffstat (limited to 'src/webengine/api')
32 files changed, 2899 insertions, 438 deletions
diff --git a/src/webengine/api/qquickwebenginecertificateerror.cpp b/src/webengine/api/qquickwebenginecertificateerror.cpp new file mode 100644 index 000000000..010c66be5 --- /dev/null +++ b/src/webengine/api/qquickwebenginecertificateerror.cpp @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qquickwebenginecertificateerror_p.h> +#include "certificate_error_controller.h" +QT_BEGIN_NAMESPACE + +class QQuickWebEngineCertificateErrorPrivate { +public: + QQuickWebEngineCertificateErrorPrivate(const QSharedPointer<CertificateErrorController> &controller) + : weakRefCertErrorController(controller), + error(static_cast<QQuickWebEngineCertificateError::Error>(static_cast<int>(controller->error()))), + description(controller->errorString()), + overridable(controller->overridable()), + async(false), + answered(false) + { + } + + const QWeakPointer<CertificateErrorController> weakRefCertErrorController; + QQuickWebEngineCertificateError::Error error; + QString description; + bool overridable; + bool async; + bool answered; +}; + +/*! + \qmltype WebEngineCertificateError + \instantiates QQuickWebEngineCertificateError + \inqmlmodule QtWebEngine 1.1 + \since QtWebEngine 1.1 + + \brief A utility class for accepting or denying certificate exceptions when a certificate error occurs. + + This class contains information about a certificate error that happened and provides a way to accept or + deny a certificate exception. + + \sa WebEngineCertificateError::certificateError +*/ +QQuickWebEngineCertificateError::QQuickWebEngineCertificateError(const QSharedPointer<CertificateErrorController> &controller, QObject *parent) + : QObject(parent) + , d_ptr(new QQuickWebEngineCertificateErrorPrivate(controller)) +{ +} + +QQuickWebEngineCertificateError::~QQuickWebEngineCertificateError() +{ + rejectCertificate(); +} + + +/*! + \qmlmethod void WebEngineCertificateError::defer() + + This function should be called when there is a need to postpone the decision to ignore or not the certificate error. This is useful to + wait for user input. When called it will pause the url request until WebEngineCertificateError::ignoreCertificateError() or + WebEngineCertificateError::rejectCertificate() is called. + */ +void QQuickWebEngineCertificateError::defer() +{ + Q_D(QQuickWebEngineCertificateError); + d->async = true; +} +/*! + \qmlmethod void WebEngineCertificateError::ignoreCertificateError() + + The certificate error is ignored and the WebEngineView continues to load the requested url. + */ +void QQuickWebEngineCertificateError::ignoreCertificateError() +{ + Q_D(QQuickWebEngineCertificateError); + + d->answered = true; + + QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); + if (strongRefCert) + strongRefCert->accept(true); +} + +/*! + \qmlmethod void WebEngineCertificateError::rejectCertificate() + + The WebEngineView stops loading the requested url. + */ +void QQuickWebEngineCertificateError::rejectCertificate() +{ + Q_D(QQuickWebEngineCertificateError); + + d->answered = true; + + QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); + if (strongRefCert) + strongRefCert->accept(false); +} + +/*! + \qmlproperty url WebEngineCertificateError::url + \readonly + + The URL that triggered the error. + */ +QUrl QQuickWebEngineCertificateError::url() const +{ + Q_D(const QQuickWebEngineCertificateError); + QSharedPointer<CertificateErrorController> strongRefCert = d->weakRefCertErrorController.toStrongRef(); + if (strongRefCert) + return strongRefCert->url(); + return QUrl(); +} + +/*! + \qmlproperty enumeration WebEngineCertificateError::error + \readonly + + The type of the error. + + \value SslPinnedKeyNotInCertificateChain The certificate did not match the built-in public key pins for the host name. + \value CertificateCommonNameInvalid The certificate's common name did not match the host name. + \value CertificateDateInvalid The certificate is not valid at the current date and time. + \value CertificateAuthorityInvalid The certificate is not signed by a trusted authority. + \value CertificateContainsErrors The certificate contains errors. + \value CertificateNoRevocationMechanism The certificate has no mechanism for determining if it has been revoked. + \value CertificateUnableToCheckRevocation Revocation information for the certificate is not available. + \value CertificateRevoked The certificate has been revoked. + \value CertificateInvalid The certificate is invalid. + \value CertificateWeakSignatureAlgorithm The certificate is signed using a weak signature algorithm. + \value CertificateNonUniqueName The host name specified in the certificate is not unique. + \value CertificateWeakKey The certificate contains a weak key. + \value CertificateNameConstraintViolation The certificate claimed DNS names that are in violation of name constraints. +*/ +QQuickWebEngineCertificateError::Error QQuickWebEngineCertificateError::error() const +{ + Q_D(const QQuickWebEngineCertificateError); + return d->error; +} + +/*! + \qmlproperty string WebEngineCertificateError::description + \readonly + + A short localized human-readable description of the error. +*/ +QString QQuickWebEngineCertificateError::description() const +{ + Q_D(const QQuickWebEngineCertificateError); + return d->description; +} + +/*! + \qmlproperty bool WebEngineCertificateError::overridable + \readonly + + A boolean that indicates if the certificate error can be overridden and accepted. +*/ +bool QQuickWebEngineCertificateError::overridable() const +{ + Q_D(const QQuickWebEngineCertificateError); + return d->overridable; +} + +bool QQuickWebEngineCertificateError::deferred() const +{ + Q_D(const QQuickWebEngineCertificateError); + return d->async; +} + +bool QQuickWebEngineCertificateError::answered() const +{ + Q_D(const QQuickWebEngineCertificateError); + return d->answered; +} + +QT_END_NAMESPACE + diff --git a/src/webengine/api/qquickwebenginecertificateerror_p.h b/src/webengine/api/qquickwebenginecertificateerror_p.h new file mode 100644 index 000000000..18a1f90e5 --- /dev/null +++ b/src/webengine/api/qquickwebenginecertificateerror_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINECERTIFICATEERROR_P_H +#define QQUICKWEBENGINECERTIFICATEERROR_P_H + +#include <QObject> +#include "qquickwebengineview_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineCertificateErrorPrivate; +class CertificateErrorController; + +class Q_WEBENGINE_EXPORT QQuickWebEngineCertificateError : public QObject { + Q_OBJECT + Q_PROPERTY(QUrl url READ url) + Q_PROPERTY(Error error READ error) + Q_PROPERTY(QString description READ description) + Q_PROPERTY(bool overridable READ overridable) + Q_ENUMS(Error) + +public: + + // Keep this identical to CertificateErrorController::CertificateError, or add mapping layer. + enum Error { + SslPinnedKeyNotInCertificateChain = -150, + CertificateCommonNameInvalid = -200, + CertificateDateInvalid = -201, + CertificateAuthorityInvalid = -202, + CertificateContainsErrors = -203, + CertificateNoRevocationMechanism = -204, + CertificateUnableToCheckRevocation = -205, + CertificateRevoked = -206, + CertificateInvalid = -207, + CertificateWeakSignatureAlgorithm = -208, + CertificateNonUniqueName = -210, + CertificateWeakKey = -211, + CertificateNameConstraintViolation = -212, + }; + + QQuickWebEngineCertificateError(const QSharedPointer<CertificateErrorController> &controller, QObject *parent = 0); + ~QQuickWebEngineCertificateError(); + + Q_INVOKABLE void defer(); + Q_INVOKABLE void ignoreCertificateError(); + Q_INVOKABLE void rejectCertificate(); + QUrl url() const; + Error error() const; + QString description() const; + bool overridable() const; + bool deferred() const; + bool answered() const; + +private: + Q_DISABLE_COPY(QQuickWebEngineCertificateError) + Q_DECLARE_PRIVATE(QQuickWebEngineCertificateError) + QScopedPointer<QQuickWebEngineCertificateErrorPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickWebEngineCertificateError) + +#endif // QQUICKWEBENGINECERTIFICATEERROR_P_H diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp new file mode 100644 index 000000000..64e75a086 --- /dev/null +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebenginedownloaditem_p.h" +#include "qquickwebenginedownloaditem_p_p.h" +#include "qquickwebengineprofile_p_p.h" + +using QtWebEngineCore::BrowserContextAdapterClient; + +QT_BEGIN_NAMESPACE + +static inline QQuickWebEngineDownloadItem::DownloadState toDownloadState(int state) { + switch (state) { + case BrowserContextAdapterClient::DownloadInProgress: + return QQuickWebEngineDownloadItem::DownloadInProgress; + case BrowserContextAdapterClient::DownloadCompleted: + return QQuickWebEngineDownloadItem::DownloadCompleted; + case BrowserContextAdapterClient::DownloadCancelled: + return QQuickWebEngineDownloadItem::DownloadCancelled; + case BrowserContextAdapterClient::DownloadInterrupted: + return QQuickWebEngineDownloadItem::DownloadInterrupted; + default: + Q_UNREACHABLE(); + return QQuickWebEngineDownloadItem::DownloadCancelled; + } +} + +QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfilePrivate *p) + : profile(p) + , downloadId(-1) + , downloadState(QQuickWebEngineDownloadItem::DownloadCancelled) + , totalBytes(-1) + , receivedBytes(0) +{ +} + +QQuickWebEngineDownloadItemPrivate::~QQuickWebEngineDownloadItemPrivate() +{ + profile->downloadDestroyed(downloadId); +} + +/*! + \qmltype WebEngineDownloadItem + \instantiates QQuickWebEngineDownloadItem + \inqmlmodule QtWebEngine 1.1 + \since QtWebEngine 1.1 + \brief A WebEngineDownloadItem provides information about a download. + + WebEngineDownloadItem stores the state of a download to be used to manage requested downloads. + + By default the download is rejected unless the user explicitly accepts it with + WebEngineDownloadItem::accept(). +*/ + +void QQuickWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClient::DownloadItemInfo &info) +{ + Q_Q(QQuickWebEngineDownloadItem); + + updateState(toDownloadState(info.state)); + + if (info.receivedBytes != receivedBytes) { + receivedBytes = info.receivedBytes; + Q_EMIT q->receivedBytesChanged(); + } + + if (info.totalBytes != totalBytes) { + totalBytes = info.totalBytes; + Q_EMIT q->totalBytesChanged(); + } +} + +void QQuickWebEngineDownloadItemPrivate::updateState(QQuickWebEngineDownloadItem::DownloadState newState) +{ + Q_Q(QQuickWebEngineDownloadItem); + + if (downloadState != newState) { + downloadState = newState; + Q_EMIT q->stateChanged(); + } +} + +/*! + \qmlmethod void WebEngineDownloadItem::accept() + + Accepts the download request, which will start the download. + + \sa WebEngineDownloadItem::cancel() +*/ + +void QQuickWebEngineDownloadItem::accept() +{ + Q_D(QQuickWebEngineDownloadItem); + + if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) + return; + + d->updateState(QQuickWebEngineDownloadItem::DownloadInProgress); +} + +/*! + \qmlmethod void WebEngineDownloadItem::cancel() + + Cancels the download. +*/ + +void QQuickWebEngineDownloadItem::cancel() +{ + Q_D(QQuickWebEngineDownloadItem); + + QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (state == QQuickWebEngineDownloadItem::DownloadCompleted + || state == QQuickWebEngineDownloadItem::DownloadCancelled) + return; + + d->updateState(QQuickWebEngineDownloadItem::DownloadCancelled); + + // We directly cancel the download if the user cancels before + // it even started, so no need to notify the profile here. + if (state == QQuickWebEngineDownloadItem::DownloadInProgress) + d->profile->cancelDownload(d->downloadId); +} + +/*! + \qmlproperty quint32 WebEngineDownloadItem::id + + The download item's id. +*/ + +quint32 QQuickWebEngineDownloadItem::id() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadId; +} + +/*! + \qmlproperty enumeration WebEngineDownloadItem::state + + This property describes the state in which the download is in. + + The state can be one of: + + \table + + \header + \li Constant + \li Description + + \row + \li DownloadRequested + \li The download has been requested, but has not been accepted yet. + + \row + \li DownloadInProgress + \li The download is in progress. + + \row + \li DownloadCompleted + \li The download completed successfully. + + \row + \li DownloadInterrupted + \li The download has been interrupted (by the server or because of lost connectivity). + + \endtable +*/ + +QQuickWebEngineDownloadItem::DownloadState QQuickWebEngineDownloadItem::state() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadState; +} + +/*! + \qmlproperty int WebEngineDownloadItem::totalBytes + + The download's total size in bytes. + + -1 means the total size is unknown. +*/ + +qint64 QQuickWebEngineDownloadItem::totalBytes() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->totalBytes; +} + +/*! + \qmlproperty int WebEngineDownloadItem::receivedBytes + + The download's bytes that have been received so far. +*/ + +qint64 QQuickWebEngineDownloadItem::receivedBytes() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->receivedBytes; +} + +/*! + \qmlproperty QString WebEngineDownloadItem::path + + The download item's full target path where it is being downloaded to. + + The path includes the file name. The default suggested path is the standard + download location and file name is deduced not to overwrite already existing files. + + The download path can only be set in the \c WebEngineProfile.onDownloadRequested + handler before the download is accepted. + + \sa WebEngineProfile::downloadRequested(WebEngineDownloadItem download), WebEngineDownloadItem::accept() +*/ + +QString QQuickWebEngineDownloadItem::path() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadPath; +} + +void QQuickWebEngineDownloadItem::setPath(QString path) +{ + Q_D(QQuickWebEngineDownloadItem); + if (d->downloadState != QQuickWebEngineDownloadItem::DownloadRequested) { + qWarning("Setting the download path is not allowed after the download has been accepted."); + return; + } + if (d->downloadPath != path) { + d->downloadPath = path; + Q_EMIT pathChanged(); + } +} + +QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent) + : QObject(parent) + , d_ptr(p) +{ + p->q_ptr = this; +} + +QQuickWebEngineDownloadItem::~QQuickWebEngineDownloadItem() +{ +} + +QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h new file mode 100644 index 000000000..63048557f --- /dev/null +++ b/src/webengine/api/qquickwebenginedownloaditem_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEDOWNLOADITEM_P_H +#define QQUICKWEBENGINEDOWNLOADITEM_P_H + +#include <private/qtwebengineglobal_p.h> +#include <QObject> +#include <QScopedPointer> +#include <QString> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineDownloadItemPrivate; +class QQuickWebEngineProfilePrivate; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineDownloadItem: public QObject { + Q_OBJECT +public: + ~QQuickWebEngineDownloadItem(); + enum DownloadState { + DownloadRequested, + DownloadInProgress, + DownloadCompleted, + DownloadCancelled, + DownloadInterrupted + }; + Q_ENUMS(DownloadState) + + Q_PROPERTY(quint32 id READ id() CONSTANT FINAL) + Q_PROPERTY(DownloadState state READ state NOTIFY stateChanged) + Q_PROPERTY(qint64 totalBytes READ totalBytes NOTIFY totalBytesChanged) + Q_PROPERTY(qint64 receivedBytes READ receivedBytes NOTIFY receivedBytesChanged) + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) + + Q_INVOKABLE void accept(); + Q_INVOKABLE void cancel(); + + quint32 id() const; + DownloadState state() const; + qint64 totalBytes() const; + qint64 receivedBytes() const; + QString path() const; + void setPath(QString path); + +Q_SIGNALS: + void stateChanged(); + void receivedBytesChanged(); + void totalBytesChanged(); + void pathChanged(); + +private: + QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate*, QObject *parent = 0); + Q_DISABLE_COPY(QQuickWebEngineDownloadItem) + Q_DECLARE_PRIVATE(QQuickWebEngineDownloadItem) + friend class QQuickWebEngineProfilePrivate; + + QScopedPointer<QQuickWebEngineDownloadItemPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEDOWNLOADITEM_P_H diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h new file mode 100644 index 000000000..fe45ca2a3 --- /dev/null +++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEDOWNLOADITEM_P_P_H +#define QQUICKWEBENGINEDOWNLOADITEM_P_P_H + +#include "browser_context_adapter_client.h" +#include "qquickwebenginedownloaditem_p.h" +#include <private/qtwebengineglobal_p.h> +#include <QString> + +QT_BEGIN_NAMESPACE +class QQuickWebEngineProfilePrivate; + +class QQuickWebEngineDownloadItemPrivate { + QQuickWebEngineDownloadItem *q_ptr; + QQuickWebEngineProfilePrivate* profile; + friend class QQuickWebEngineProfilePrivate; +public: + Q_DECLARE_PUBLIC(QQuickWebEngineDownloadItem) + QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfilePrivate *p); + ~QQuickWebEngineDownloadItemPrivate(); + + quint32 downloadId; + QQuickWebEngineDownloadItem::DownloadState downloadState; + qint64 totalBytes; + qint64 receivedBytes; + QString downloadPath; + + void update(const QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info); + void updateState(QQuickWebEngineDownloadItem::DownloadState newState); +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEDOWNLOADITEM_P_P_H diff --git a/src/webengine/api/qquickwebenginehistory.cpp b/src/webengine/api/qquickwebenginehistory.cpp index ffb857791..9a737fbbe 100644 --- a/src/webengine/api/qquickwebenginehistory.cpp +++ b/src/webengine/api/qquickwebenginehistory.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -51,7 +51,24 @@ QQuickWebEngineHistoryListModelPrivate::~QQuickWebEngineHistoryListModelPrivate( { } -WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const +int QQuickWebEngineHistoryListModelPrivate::count() const +{ + if (!adapter()) + return -1; + return adapter()->navigationEntryCount(); +} + +int QQuickWebEngineHistoryListModelPrivate::index(int index) const +{ + return index; +} + +int QQuickWebEngineHistoryListModelPrivate::offsetForIndex(int index) const +{ + return index - adapter()->currentNavigationEntryIndex(); +} + +QtWebEngineCore::WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const { return view->adapter.data(); } @@ -63,6 +80,8 @@ QQuickWebEngineBackHistoryListModelPrivate::QQuickWebEngineBackHistoryListModelP int QQuickWebEngineBackHistoryListModelPrivate::count() const { + if (!adapter()) + return -1; return adapter()->currentNavigationEntryIndex(); } @@ -72,6 +91,11 @@ int QQuickWebEngineBackHistoryListModelPrivate::index(int i) const return count() - 1 - i; } +int QQuickWebEngineBackHistoryListModelPrivate::offsetForIndex(int index) const +{ + return - index - 1; +} + QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate *view) : QQuickWebEngineHistoryListModelPrivate(view) { @@ -79,6 +103,8 @@ QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryList int QQuickWebEngineForwardHistoryListModelPrivate::count() const { + if (!adapter()) + return -1; return adapter()->navigationEntryCount() - adapter()->currentNavigationEntryIndex() - 1; } @@ -87,6 +113,11 @@ int QQuickWebEngineForwardHistoryListModelPrivate::index(int i) const return adapter()->currentNavigationEntryIndex() + i + 1; } +int QQuickWebEngineForwardHistoryListModelPrivate::offsetForIndex(int index) const +{ + return index + 1; +} + QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel() : QAbstractListModel() { @@ -107,6 +138,7 @@ QHash<int, QByteArray> QQuickWebEngineHistoryListModel::roleNames() const QHash<int, QByteArray> roles; roles[QQuickWebEngineHistory::UrlRole] = "url"; roles[QQuickWebEngineHistory::TitleRole] = "title"; + roles[QQuickWebEngineHistory::OffsetRole] = "offset"; return roles; } @@ -124,7 +156,7 @@ QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int rol if (!index.isValid()) return QVariant(); - if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::TitleRole) + if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::OffsetRole) return QVariant(); if (role == QQuickWebEngineHistory::UrlRole) @@ -133,6 +165,8 @@ QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int rol if (role == QQuickWebEngineHistory::TitleRole) return QString(d->adapter()->getNavigationEntryTitle(d->index(index.row()))); + if (role == QQuickWebEngineHistory::OffsetRole) + return d->offsetForIndex(index.row()); return QVariant(); } @@ -143,8 +177,7 @@ void QQuickWebEngineHistoryListModel::reset() } QQuickWebEngineHistoryPrivate::QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate *view) - : m_backNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(view))) - , m_forwardNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(view))) + : m_view(view) { } @@ -161,23 +194,39 @@ QQuickWebEngineHistory::~QQuickWebEngineHistory() { } +QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::items() const +{ + Q_D(const QQuickWebEngineHistory); + if (!d->m_navigationModel) + d->m_navigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineHistoryListModelPrivate(d->m_view))); + return d->m_navigationModel.data(); +} + QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::backItems() const { Q_D(const QQuickWebEngineHistory); + if (!d->m_backNavigationModel) + d->m_backNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(d->m_view))); return d->m_backNavigationModel.data(); } QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::forwardItems() const { Q_D(const QQuickWebEngineHistory); + if (!d->m_forwardNavigationModel) + d->m_forwardNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(d->m_view))); return d->m_forwardNavigationModel.data(); } void QQuickWebEngineHistory::reset() { Q_D(QQuickWebEngineHistory); - d->m_backNavigationModel->reset(); - d->m_forwardNavigationModel->reset(); + if (d->m_navigationModel) + d->m_navigationModel->reset(); + if (d->m_backNavigationModel) + d->m_backNavigationModel->reset(); + if (d->m_forwardNavigationModel) + d->m_forwardNavigationModel->reset(); } diff --git a/src/webengine/api/qquickwebenginehistory_p.h b/src/webengine/api/qquickwebenginehistory_p.h index ebd3efbb9..cb6aff2bc 100644 --- a/src/webengine/api/qquickwebenginehistory_p.h +++ b/src/webengine/api/qquickwebenginehistory_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -37,7 +37,7 @@ #ifndef QQUICKWEBENGINEHISTORY_P_H #define QQUICKWEBENGINEHISTORY_P_H -#include <qtwebengineglobal_p.h> +#include <qtwebengineglobal.h> #include <QAbstractListModel> #include <QtCore/qshareddata.h> #include <QQuickItem> @@ -46,15 +46,13 @@ QT_BEGIN_NAMESPACE -class WebEngineHistory; -class WebEngineHistoryItem; class QQuickWebEngineHistory; class QQuickWebEngineHistoryPrivate; class QQuickWebEngineHistoryListModelPrivate; class QQuickWebEngineLoadRequest; class QQuickWebEngineViewPrivate; -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineHistoryListModel : public QAbstractListModel { +class Q_WEBENGINE_EXPORT QQuickWebEngineHistoryListModel : public QAbstractListModel { Q_OBJECT public: @@ -75,8 +73,9 @@ private: friend class QQuickWebEngineHistory; }; -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineHistory : public QQuickItem { +class Q_WEBENGINE_EXPORT QQuickWebEngineHistory : public QQuickItem { Q_OBJECT + Q_PROPERTY(QQuickWebEngineHistoryListModel *items READ items CONSTANT FINAL) Q_PROPERTY(QQuickWebEngineHistoryListModel *backItems READ backItems CONSTANT FINAL) Q_PROPERTY(QQuickWebEngineHistoryListModel *forwardItems READ forwardItems CONSTANT FINAL) @@ -86,9 +85,11 @@ public: enum NavigationHistoryRoles { UrlRole = Qt::UserRole + 1, - TitleRole = Qt::UserRole + 2 + TitleRole = Qt::UserRole + 2, + OffsetRole = Qt::UserRole + 3, }; + QQuickWebEngineHistoryListModel *items() const; QQuickWebEngineHistoryListModel *backItems() const; QQuickWebEngineHistoryListModel *forwardItems() const; diff --git a/src/webengine/api/qquickwebenginehistory_p_p.h b/src/webengine/api/qquickwebenginehistory_p_p.h index 2b0396fd9..0d714b1b6 100644 --- a/src/webengine/api/qquickwebenginehistory_p_p.h +++ b/src/webengine/api/qquickwebenginehistory_p_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -37,21 +37,24 @@ #ifndef QQUICKWEBENGINEHISTORY_P_P_H #define QQUICKWEBENGINEHISTORY_P_P_H +namespace QtWebEngineCore { class WebContentsAdapter; -class QQuickWebEngineHistoryListModel; -class QQuickWebEngineViewPrivate; +} QT_BEGIN_NAMESPACE +class QQuickWebEngineHistoryListModel; +class QQuickWebEngineViewPrivate; class QQuickWebEngineHistoryListModelPrivate { public: QQuickWebEngineHistoryListModelPrivate(QQuickWebEngineViewPrivate*); virtual ~QQuickWebEngineHistoryListModelPrivate(); - virtual int count() const = 0; - virtual int index(int) const = 0; + virtual int count() const; + virtual int index(int) const; + virtual int offsetForIndex(int) const; - WebContentsAdapter *adapter() const; + QtWebEngineCore::WebContentsAdapter *adapter() const; QQuickWebEngineViewPrivate *view; }; @@ -60,16 +63,18 @@ class QQuickWebEngineBackHistoryListModelPrivate : public QQuickWebEngineHistory public: QQuickWebEngineBackHistoryListModelPrivate(QQuickWebEngineViewPrivate*); - int count() const; - int index(int) const; + int count() const override; + int index(int) const override; + int offsetForIndex(int) const override; }; class QQuickWebEngineForwardHistoryListModelPrivate : public QQuickWebEngineHistoryListModelPrivate { public: QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate*); - int count() const; - int index(int) const; + int count() const override; + int index(int) const override; + int offsetForIndex(int) const override; }; class QQuickWebEngineHistoryPrivate { @@ -77,8 +82,10 @@ public: QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate*); ~QQuickWebEngineHistoryPrivate(); - QScopedPointer<QQuickWebEngineHistoryListModel> m_backNavigationModel; - QScopedPointer<QQuickWebEngineHistoryListModel> m_forwardNavigationModel; + QQuickWebEngineViewPrivate *m_view; + mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_navigationModel; + mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_backNavigationModel; + mutable QScopedPointer<QQuickWebEngineHistoryListModel> m_forwardNavigationModel; }; QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebengineloadrequest.cpp b/src/webengine/api/qquickwebengineloadrequest.cpp index a29381af6..c85d0d76f 100644 --- a/src/webengine/api/qquickwebengineloadrequest.cpp +++ b/src/webengine/api/qquickwebengineloadrequest.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qquickwebengineloadrequest_p.h b/src/webengine/api/qquickwebengineloadrequest_p.h index 38b0a4174..5aae6b81f 100644 --- a/src/webengine/api/qquickwebengineloadrequest_p.h +++ b/src/webengine/api/qquickwebengineloadrequest_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qquickwebenginenavigationrequest.cpp b/src/webengine/api/qquickwebenginenavigationrequest.cpp index ab00ab205..d50991b21 100644 --- a/src/webengine/api/qquickwebenginenavigationrequest.cpp +++ b/src/webengine/api/qquickwebenginenavigationrequest.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qquickwebenginenavigationrequest_p.h b/src/webengine/api/qquickwebenginenavigationrequest_p.h index 8ae9acd80..ab39ed13a 100644 --- a/src/webengine/api/qquickwebenginenavigationrequest_p.h +++ b/src/webengine/api/qquickwebenginenavigationrequest_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qquickwebenginenewviewrequest.cpp b/src/webengine/api/qquickwebenginenewviewrequest.cpp index f2a361f55..36c5e44e1 100644 --- a/src/webengine/api/qquickwebenginenewviewrequest.cpp +++ b/src/webengine/api/qquickwebenginenewviewrequest.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -39,6 +39,18 @@ #include "qquickwebengineview_p_p.h" #include "web_contents_adapter.h" +/*! + \qmltype WebEngineNewViewRequest + \instantiates QQuickWebEngineNewViewRequest + \inqmlmodule QtWebEngine 1.1 + \since QtWebEngine 1.1 + + \brief A utility class for the WebEngineView::newViewRequested signal. + + This class contains information about the request of a page to open a new window. + + \sa WebEngineView::newViewRequested +*/ QQuickWebEngineNewViewRequest::QQuickWebEngineNewViewRequest() { } @@ -47,20 +59,48 @@ QQuickWebEngineNewViewRequest::~QQuickWebEngineNewViewRequest() { } +/*! + \qmlproperty WebEngineView::NewViewDestination WebEngineNewViewRequest::destination + \brief The type of view that is requested by the page. + */ QQuickWebEngineView::NewViewDestination QQuickWebEngineNewViewRequest::destination() const { return m_destination; } +/*! + \qmlproperty bool WebEngineNewViewRequest::isUserInitiated + \brief Whether this window request was directly triggered as the result of a keyboard or mouse event. + + Use this property to block possibly unwanted "popups". + */ bool QQuickWebEngineNewViewRequest::isUserInitiated() const { return m_isUserInitiated; } +/*! + \qmlmethod WebEngineNewViewRequest::openIn(WebEngineView view) + + Call this method to fulfill the request and determine which WebEngineView + should be used to contain the new page. Any state, history or loaded page + within \a view will be lost as result of this. + + \sa WebEngineView::newViewRequested + */ void QQuickWebEngineNewViewRequest::openIn(QQuickWebEngineView *view) { - if (view) { - view->d_func()->adoptWebContents(m_adapter.data()); - m_adapter.reset(); + if (!m_adapter) { + qWarning("Trying to open an empty request, it was either already used or was invalidated." + "\nYou must complete the request synchronously within the newViewRequested signal handler." + " If a view hasn't been adopted before returning, the request will be invalidated."); + return; + } + + if (!view) { + qWarning("Trying to open a WebEngineNewViewRequest in an invalid WebEngineView."); + return; } + view->d_func()->adoptWebContents(m_adapter.data()); + m_adapter.reset(); } diff --git a/src/webengine/api/qquickwebenginenewviewrequest_p.h b/src/webengine/api/qquickwebenginenewviewrequest_p.h index f17bce24a..062a2fa33 100644 --- a/src/webengine/api/qquickwebenginenewviewrequest_p.h +++ b/src/webengine/api/qquickwebenginenewviewrequest_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -40,7 +40,9 @@ #include "qtwebengineglobal_p.h" #include "qquickwebengineview_p.h" +namespace QtWebEngineCore { class WebContentsAdapter; +} QT_BEGIN_NAMESPACE @@ -59,7 +61,7 @@ private: QQuickWebEngineNewViewRequest(); QQuickWebEngineView::NewViewDestination m_destination; bool m_isUserInitiated; - QExplicitlySharedDataPointer<WebContentsAdapter> m_adapter; + QExplicitlySharedDataPointer<QtWebEngineCore::WebContentsAdapter> m_adapter; friend class QQuickWebEngineViewPrivate; }; diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp new file mode 100644 index 000000000..69c524356 --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -0,0 +1,413 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebengineprofile_p.h" + +#include "qquickwebenginedownloaditem_p.h" +#include "qquickwebenginedownloaditem_p_p.h" +#include "qquickwebengineprofile_p_p.h" +#include "qquickwebenginesettings_p.h" + +#include <QQmlEngine> + +#include "browser_context_adapter.h" +#include "web_engine_settings.h" + +using QtWebEngineCore::BrowserContextAdapter; + +QT_BEGIN_NAMESPACE + +QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext) + : m_settings(new QQuickWebEngineSettings()) + , m_browserContextRef(browserContext) +{ + m_browserContextRef->addClient(this); + m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord()); +} + +QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate() +{ + m_browserContextRef->removeClient(this); + + Q_FOREACH (QQuickWebEngineDownloadItem* download, m_ongoingDownloads) { + if (download) + download->cancel(); + } + + m_ongoingDownloads.clear(); +} + +void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId) +{ + browserContext()->cancelDownload(downloadId); +} + +void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) +{ + m_ongoingDownloads.remove(downloadId); +} + +void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) +{ + Q_Q(QQuickWebEngineProfile); + + Q_ASSERT(!m_ongoingDownloads.contains(info.id)); + QQuickWebEngineDownloadItemPrivate *itemPrivate = new QQuickWebEngineDownloadItemPrivate(this); + itemPrivate->downloadId = info.id; + itemPrivate->downloadState = QQuickWebEngineDownloadItem::DownloadRequested; + itemPrivate->totalBytes = info.totalBytes; + itemPrivate->downloadPath = info.path; + + QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q); + + m_ongoingDownloads.insert(info.id, download); + + QQmlEngine::setObjectOwnership(download, QQmlEngine::JavaScriptOwnership); + Q_EMIT q->downloadRequested(download); + + QQuickWebEngineDownloadItem::DownloadState state = download->state(); + info.path = download->path(); + info.accepted = state != QQuickWebEngineDownloadItem::DownloadCancelled + && state != QQuickWebEngineDownloadItem::DownloadRequested; +} + +void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) +{ + if (!m_ongoingDownloads.contains(info.id)) + return; + + Q_Q(QQuickWebEngineProfile); + + QQuickWebEngineDownloadItem* download = m_ongoingDownloads.value(info.id).data(); + + if (!download) { + downloadDestroyed(info.id); + return; + } + + download->d_func()->update(info); + + if (info.state != BrowserContextAdapterClient::DownloadInProgress) { + Q_EMIT q->downloadFinished(download); + m_ongoingDownloads.remove(info.id); + } +} + +/*! + \qmltype WebEngineProfile + \instantiates QQuickWebEngineProfile + \inqmlmodule QtWebEngine 1.1 + \since QtWebEngine 1.1 + \brief A WebEngineProfile contains common settings for multiple WebEngineView. + + WebEngineProfile contains settings and history shared by all WebEngineView that belong + to the profile. + + A default profile is built-in that all web pages not specifically created with another profile + belongs to. +*/ + +/*! + \qmlsignal WebEngineProfile::downloadRequested(WebEngineDownloadItem download) + + This signal is emitted whenever a download has been triggered. + The \a download argument holds the state of the download. + The \a download has to be explicitly accepted with WebEngineDownloadItem::accept(), + else the download will be cancelled by default. +*/ + +/*! + \qmlsignal WebEngineProfile::downloadFinished(WebEngineDownloadItem download) + + This signal is emitted whenever a download finishes downloading. + This can be due to the download finishing successfully, being cancelled or + interrupted by lost connectivity for example. + The \a download argument holds the state of the finished download instance. +*/ + +QQuickWebEngineProfile::QQuickWebEngineProfile() + : d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false))) +{ + d_ptr->q_ptr = this; +} + +QQuickWebEngineProfile::QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *privatePtr, QObject *parent) + : QObject(parent) + , d_ptr(privatePtr) +{ + d_ptr->q_ptr = this; +} + +QQuickWebEngineProfile::~QQuickWebEngineProfile() +{ +} + +/*! + \qmlproperty QString WebEngineProfile::storageName + + The storage name is used to give each profile that uses the disk separate subdirectories for persistent data and cache. +*/ + +QString QQuickWebEngineProfile::storageName() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->storageName(); +} + +void QQuickWebEngineProfile::setStorageName(const QString &name) +{ + Q_D(QQuickWebEngineProfile); + if (d->browserContext()->storageName() == name) + return; + BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType(); + BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy(); + d->browserContext()->setStorageName(name); + emit storageNameChanged(); + emit persistentStoragePathChanged(); + emit cachePathChanged(); + if (d->browserContext()->httpCacheType() != oldCacheType) + emit httpCacheTypeChanged(); + if (d->browserContext()->persistentCookiesPolicy() != oldPolicy) + emit persistentCookiesPolicyChanged(); +} + +/*! + \qmlproperty bool WebEngineProfile::offTheRecord + + An offTheRecord profile forces cookies and HTTP cache to be in memory, but also force + all other normally persistent data to be stored in memory. +*/ +bool QQuickWebEngineProfile::isOffTheRecord() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->isOffTheRecord(); +} + +void QQuickWebEngineProfile::setOffTheRecord(bool offTheRecord) +{ + Q_D(QQuickWebEngineProfile); + if (d->browserContext()->isOffTheRecord() == offTheRecord) + return; + BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType(); + BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy(); + d->browserContext()->setOffTheRecord(offTheRecord); + emit offTheRecordChanged(); + if (d->browserContext()->httpCacheType() != oldCacheType) + emit httpCacheTypeChanged(); + if (d->browserContext()->persistentCookiesPolicy() != oldPolicy) + emit persistentCookiesPolicyChanged(); +} + +/*! + \qmlproperty QString WebEngineProfile::persistentStoragePath + + The persistent storage path is where persistent data for the browser and web content is stored. + Persistent data includes persistent cookies, HTML5 local storage and visited links. + + By default this is below QStandardPaths::writableLocation(QStandardPaths::DataLocation) in a storageName specific directory. +*/ +QString QQuickWebEngineProfile::persistentStoragePath() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->dataPath(); +} + +void QQuickWebEngineProfile::setPersistentStoragePath(const QString &path) +{ + Q_D(QQuickWebEngineProfile); + if (persistentStoragePath() == path) + return; + d->browserContext()->setDataPath(path); + emit persistentStoragePathChanged(); +} + +/*! + \qmlproperty QString WebEngineProfile::cachePath + + By default this is below QStandardPaths::writableLocation(QStandardPaths::CacheLocation) in a storageName specific directory. +*/ +QString QQuickWebEngineProfile::cachePath() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->cachePath(); +} + +void QQuickWebEngineProfile::setCachePath(const QString &path) +{ + Q_D(QQuickWebEngineProfile); + if (cachePath() == path) + return; + d->browserContext()->setCachePath(path); + emit cachePathChanged(); +} + +/*! + \qmlproperty QString WebEngineProfile::httpUserAgent + + The user-agent string send with HTTP to identify the browser. +*/ +QString QQuickWebEngineProfile::httpUserAgent() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->httpUserAgent(); +} + +void QQuickWebEngineProfile::setHttpUserAgent(const QString &userAgent) +{ + Q_D(QQuickWebEngineProfile); + if (d->browserContext()->httpUserAgent() == userAgent) + return; + d->browserContext()->setHttpUserAgent(userAgent); + emit httpUserAgentChanged(); +} + + +/*! + \qmlproperty enumeration WebEngineProfile::httpCacheType + + The type of the HTTP cache. + + \table + + \header + \li Constant + \li Description + + \row + \li MemoryHttpCache + \li Use a in-memory cache. This is the only setting possible if offTheRecord is set or no cachePath is available. + + \row + \li DiskHttpCache + \li DiskHttpCache Use a disk cache. This is the default. + + \endtable +*/ + +QQuickWebEngineProfile::HttpCacheType QQuickWebEngineProfile::httpCacheType() const +{ + const Q_D(QQuickWebEngineProfile); + return QQuickWebEngineProfile::HttpCacheType(d->browserContext()->httpCacheType()); +} + +void QQuickWebEngineProfile::setHttpCacheType(QQuickWebEngineProfile::HttpCacheType httpCacheType) +{ + Q_D(QQuickWebEngineProfile); + BrowserContextAdapter::HttpCacheType oldCacheType = d->browserContext()->httpCacheType(); + d->browserContext()->setHttpCacheType(BrowserContextAdapter::HttpCacheType(httpCacheType)); + if (d->browserContext()->httpCacheType() != oldCacheType) + emit httpCacheTypeChanged(); +} + +/*! + \qmlproperty enumeration WebEngineProfile::persistentCookiesPolicy + + The policy of cookie persistency. + + \table + + \header + \li Constant + \li Description + + \row + \li NoPersistentCookies + \li Both session and persistent cookies are stored in memory. This is the only setting possible if offTheRecord is set or no persistentStoragePath is available. + + \row + \li AllowPersistentCookies + \li Cookies marked persistent are save and restored from disk, session cookies are only stored to disk for crash recovery. This is the default setting. + + \row + \li ForcePersistentCookies + \li Both session and persistent cookies are save and restored from disk. + + \endtable +*/ + +QQuickWebEngineProfile::PersistentCookiesPolicy QQuickWebEngineProfile::persistentCookiesPolicy() const +{ + const Q_D(QQuickWebEngineProfile); + return QQuickWebEngineProfile::PersistentCookiesPolicy(d->browserContext()->persistentCookiesPolicy()); +} + +void QQuickWebEngineProfile::setPersistentCookiesPolicy(QQuickWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy) +{ + Q_D(QQuickWebEngineProfile); + BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = d->browserContext()->persistentCookiesPolicy(); + d->browserContext()->setPersistentCookiesPolicy(BrowserContextAdapter::PersistentCookiesPolicy(newPersistentCookiesPolicy)); + if (d->browserContext()->persistentCookiesPolicy() != oldPolicy) + emit persistentCookiesPolicyChanged(); +} + +/*! + \qmlproperty int WebEngineProfile::httpCacheMaximumSize + + The maximum size of the HTTP cache. If 0 it means the size will be controlled automatically by QtWebEngine. + The default value is 0. + + \sa httpCacheType +*/ +int QQuickWebEngineProfile::httpCacheMaximumSize() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->httpCacheMaxSize(); +} + +void QQuickWebEngineProfile::setHttpCacheMaximumSize(int maximumSize) +{ + Q_D(QQuickWebEngineProfile); + if (d->browserContext()->httpCacheMaxSize() == maximumSize) + return; + d->browserContext()->setHttpCacheMaxSize(maximumSize); + emit httpCacheMaximumSizeChanged(); +} + +QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile() +{ + static QQuickWebEngineProfile *profile = new QQuickWebEngineProfile( + new QQuickWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()), + BrowserContextAdapter::globalQObjectRoot()); + return profile; +} + +QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const +{ + const Q_D(QQuickWebEngineProfile); + return d->settings(); +} + +QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h new file mode 100644 index 000000000..3978fc5e0 --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile_p.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEPROFILE_P_H +#define QQUICKWEBENGINEPROFILE_P_H + +#include <private/qtwebengineglobal_p.h> + +#include <QObject> +#include <QScopedPointer> +#include <QString> + +namespace QtWebEngineCore { +class BrowserContextAdapter; +} + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineDownloadItem; +class QQuickWebEngineProfilePrivate; +class QQuickWebEngineSettings; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineProfile : public QObject { + Q_OBJECT + Q_ENUMS(HttpCacheType); + Q_ENUMS(PersistentCookiesPolicy); + Q_PROPERTY(QString storageName READ storageName WRITE setStorageName NOTIFY storageNameChanged FINAL) + Q_PROPERTY(bool offTheRecord READ isOffTheRecord WRITE setOffTheRecord NOTIFY offTheRecordChanged FINAL) + Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY persistentStoragePathChanged FINAL) + Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged FINAL) + Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY httpUserAgentChanged FINAL) + Q_PROPERTY(HttpCacheType httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY httpCacheTypeChanged FINAL) + Q_PROPERTY(PersistentCookiesPolicy persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY persistentCookiesPolicyChanged FINAL) + Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged FINAL) +public: + QQuickWebEngineProfile(); + ~QQuickWebEngineProfile(); + + enum HttpCacheType { + MemoryHttpCache, + DiskHttpCache + }; + + enum PersistentCookiesPolicy { + NoPersistentCookies, + AllowPersistentCookies, + ForcePersistentCookies + }; + + QString storageName() const; + void setStorageName(const QString &name); + + bool isOffTheRecord() const; + void setOffTheRecord(bool offTheRecord); + + QString persistentStoragePath() const; + void setPersistentStoragePath(const QString &path); + + QString cachePath() const; + void setCachePath(const QString &path); + + QString httpUserAgent() const; + void setHttpUserAgent(const QString &userAgent); + + HttpCacheType httpCacheType() const; + void setHttpCacheType(QQuickWebEngineProfile::HttpCacheType); + + PersistentCookiesPolicy persistentCookiesPolicy() const; + void setPersistentCookiesPolicy(QQuickWebEngineProfile::PersistentCookiesPolicy); + + int httpCacheMaximumSize() const; + void setHttpCacheMaximumSize(int maxSize); + + static QQuickWebEngineProfile *defaultProfile(); + +signals: + void storageNameChanged(); + void offTheRecordChanged(); + void persistentStoragePathChanged(); + void cachePathChanged(); + void httpUserAgentChanged(); + void httpCacheTypeChanged(); + void persistentCookiesPolicyChanged(); + void httpCacheMaximumSizeChanged(); + + void downloadRequested(QQuickWebEngineDownloadItem *download); + void downloadFinished(QQuickWebEngineDownloadItem *download); + +private: + Q_DECLARE_PRIVATE(QQuickWebEngineProfile) + QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *, QObject *parent = 0); + QQuickWebEngineSettings *settings() const; + + friend class QQuickWebEngineSettings; + friend class QQuickWebEngineSingleton; + friend class QQuickWebEngineViewPrivate; + QScopedPointer<QQuickWebEngineProfilePrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEPROFILE_P_H diff --git a/src/webengine/api/qquickwebengineprofile_p_p.h b/src/webengine/api/qquickwebengineprofile_p_p.h new file mode 100644 index 000000000..a702a8a1d --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile_p_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEPROFILE_P_P_H +#define QQUICKWEBENGINEPROFILE_P_P_H + +#include "browser_context_adapter_client.h" +#include "qquickwebengineprofile_p.h" + +#include <QExplicitlySharedDataPointer> +#include <QMap> +#include <QPointer> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineDownloadItem; +class QQuickWebEngineSettings; + +class QQuickWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient { +public: + Q_DECLARE_PUBLIC(QQuickWebEngineProfile) + QQuickWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext); + ~QQuickWebEngineProfilePrivate(); + + QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContextRef.data(); } + QQuickWebEngineSettings *settings() const { return m_settings.data(); } + + void cancelDownload(quint32 downloadId); + void downloadDestroyed(quint32 downloadId); + + void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE; + void downloadUpdated(const DownloadItemInfo &info) Q_DECL_OVERRIDE; + +private: + friend class QQuickWebEngineViewPrivate; + QQuickWebEngineProfile *q_ptr; + QScopedPointer<QQuickWebEngineSettings> m_settings; + QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef; + QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEPROFILE_P_P_H diff --git a/src/webengine/api/qquickwebenginescript.cpp b/src/webengine/api/qquickwebenginescript.cpp new file mode 100644 index 000000000..affffbf46 --- /dev/null +++ b/src/webengine/api/qquickwebenginescript.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebenginescript_p.h" +#include "qquickwebenginescript_p_p.h" + +#include <QtCore/QDebug> +#include <QtCore/QFile> +#include <QtCore/QStringBuilder> +#include <QtCore/QTimerEvent> +#include "user_script_controller_host.h" + +using QtWebEngineCore::UserScript; + +QQuickWebEngineScript::QQuickWebEngineScript() + : d_ptr(new QQuickWebEngineScriptPrivate) +{ + d_ptr->q_ptr = this; +} + +QQuickWebEngineScript::~QQuickWebEngineScript() +{ +} + +QString QQuickWebEngineScript::toString() const +{ + Q_D(const QQuickWebEngineScript); + if (d->coreScript.isNull()) + return QStringLiteral("QWebEngineScript()"); + QString ret = QStringLiteral("QWebEngineScript(") % d->coreScript.name() % QStringLiteral(", "); + switch (d->coreScript.injectionPoint()) { + case UserScript::DocumentElementCreation: + ret.append(QStringLiteral("WebEngineScript::DocumentCreation, ")); + break; + case UserScript::DocumentLoadFinished: + ret.append(QStringLiteral("WebEngineScript::DocumentReady, ")); + break; + case UserScript::AfterLoad: + ret.append(QStringLiteral("WebEngineScript::Deferred, ")); + break; + } + ret.append(QString::number(d->coreScript.worldId()) % QStringLiteral(", ") + % (d->coreScript.runsOnSubFrames() ? QStringLiteral("true") : QStringLiteral("false")) + % QStringLiteral(", ") % d->coreScript.sourceCode() % QLatin1Char(')')); + return ret; +} + +QString QQuickWebEngineScript::name() const +{ + Q_D(const QQuickWebEngineScript); + return d->coreScript.name(); +} + +/*! + \qmlproperty url WebEngineScript::sourceUrl + + This property holds the remote source location of the user script (if any). + + Unlike \l sourceCode, this property allows referring to user scripts that + are not already loaded in memory, for instance, when stored on disk. + + Setting this property will change the \l sourceCode of the script. + + \note At present, only file-based sources are supported. + + \sa sourceCode +*/ +QUrl QQuickWebEngineScript::sourceUrl() const +{ + Q_D(const QQuickWebEngineScript); + return d->m_sourceUrl; +} + +/*! + \qmlproperty string WebEngineScript::sourceCode + + This property holds the JavaScript source code of the user script. + + \sa sourceUrl +*/ +QString QQuickWebEngineScript::sourceCode() const +{ + Q_D(const QQuickWebEngineScript); + return d->coreScript.sourceCode(); +} + +ASSERT_ENUMS_MATCH(QQuickWebEngineScript::Deferred, UserScript::AfterLoad) +ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentReady, UserScript::DocumentLoadFinished) +ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentCreation, UserScript::DocumentElementCreation) + +QQuickWebEngineScript::InjectionPoint QQuickWebEngineScript::injectionPoint() const +{ + Q_D(const QQuickWebEngineScript); + return static_cast<QQuickWebEngineScript::InjectionPoint>(d->coreScript.injectionPoint()); +} + + +QQuickWebEngineScript::ScriptWorldId QQuickWebEngineScript::worldId() const +{ + Q_D(const QQuickWebEngineScript); + return static_cast<QQuickWebEngineScript::ScriptWorldId>(d->coreScript.worldId()); +} + + +bool QQuickWebEngineScript::runOnSubframes() const +{ + Q_D(const QQuickWebEngineScript); + return d->coreScript.runsOnSubFrames(); +} + + +void QQuickWebEngineScript::setName(QString arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == name()) + return; + d->aboutToUpdateUnderlyingScript(); + d->coreScript.setName(arg); + Q_EMIT nameChanged(arg); +} + +void QQuickWebEngineScript::setSourceCode(QString arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == sourceCode()) + return; + + // setting the source directly resets the sourceUrl + if (d->m_sourceUrl != QUrl()) { + d->m_sourceUrl = QUrl(); + Q_EMIT sourceUrlChanged(d->m_sourceUrl); + } + + d->aboutToUpdateUnderlyingScript(); + d->coreScript.setSourceCode(arg); + Q_EMIT sourceCodeChanged(arg); +} + +void QQuickWebEngineScript::setSourceUrl(QUrl arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == sourceUrl()) + return; + + d->m_sourceUrl = arg; + Q_EMIT sourceUrlChanged(d->m_sourceUrl); + + QFile f(arg.toLocalFile()); + if (!f.open(QIODevice::ReadOnly)) { + qWarning() << "Can't open user script " << arg; + return; + } + + d->aboutToUpdateUnderlyingScript(); + QString source = QString::fromUtf8(f.readAll()); + d->coreScript.setSourceCode(source); + Q_EMIT sourceCodeChanged(source); +} + +void QQuickWebEngineScript::setInjectionPoint(QQuickWebEngineScript::InjectionPoint arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == injectionPoint()) + return; + d->aboutToUpdateUnderlyingScript(); + d->coreScript.setInjectionPoint(static_cast<UserScript::InjectionPoint>(arg)); + Q_EMIT injectionPointChanged(arg); +} + + +void QQuickWebEngineScript::setWorldId(QQuickWebEngineScript::ScriptWorldId arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == worldId()) + return; + d->aboutToUpdateUnderlyingScript(); + d->coreScript.setWorldId(arg); + Q_EMIT worldIdChanged(arg); +} + + +void QQuickWebEngineScript::setRunOnSubframes(bool arg) +{ + Q_D(QQuickWebEngineScript); + if (arg == runOnSubframes()) + return; + d->aboutToUpdateUnderlyingScript(); + d->coreScript.setRunsOnSubFrames(arg); + Q_EMIT runOnSubframesChanged(arg); +} + +void QQuickWebEngineScript::timerEvent(QTimerEvent *e) +{ + Q_D(QQuickWebEngineScript); + if (e->timerId() != d->m_basicTimer.timerId()) { + QObject::timerEvent(e); + return; + } + if (!d->m_controllerHost) + return; + d->m_basicTimer.stop(); + d->m_controllerHost->addUserScript(d->coreScript, d->m_adapter); +} + +void QQuickWebEngineScriptPrivate::bind(QtWebEngineCore::UserScriptControllerHost *scriptController, QtWebEngineCore::WebContentsAdapter *adapter) +{ + aboutToUpdateUnderlyingScript(); + m_adapter = adapter; + m_controllerHost = scriptController; +} + +QQuickWebEngineScriptPrivate::QQuickWebEngineScriptPrivate() + :m_controllerHost(0) + , m_adapter(0) + +{ +} + +void QQuickWebEngineScriptPrivate::aboutToUpdateUnderlyingScript() +{ + Q_Q(QQuickWebEngineScript); + if (m_controllerHost) + m_controllerHost->removeUserScript(coreScript, m_adapter); + // Defer updates to the next event loop + m_basicTimer.start(0, q); +} diff --git a/src/webengine/api/qquickwebenginescript_p.h b/src/webengine/api/qquickwebenginescript_p.h new file mode 100644 index 000000000..f1d7a01dc --- /dev/null +++ b/src/webengine/api/qquickwebenginescript_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINESCRIPT_P_H +#define QQUICKWEBENGINESCRIPT_P_H + +#include <private/qtwebengineglobal_p.h> +#include <QtCore/QObject> +#include <QtCore/QUrl> + +QT_BEGIN_NAMESPACE +class QQuickWebEngineScriptPrivate; +class QQuickWebEngineView; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineScript : public QObject +{ + Q_OBJECT + Q_ENUMS(InjectionPoint) + Q_ENUMS(ScriptWorldId) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QUrl sourceUrl READ sourceUrl WRITE setSourceUrl NOTIFY sourceUrlChanged) + Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged) + Q_PROPERTY(InjectionPoint injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged) + Q_PROPERTY(ScriptWorldId worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged) + Q_PROPERTY(bool runOnSubframes READ runOnSubframes WRITE setRunOnSubframes NOTIFY runOnSubframesChanged) + + +public: + enum InjectionPoint { + Deferred, + DocumentReady, + DocumentCreation + }; + + enum ScriptWorldId { + MainWorld = 0, + ApplicationWorld, + UserWorld + }; + + QQuickWebEngineScript(); + ~QQuickWebEngineScript(); + Q_INVOKABLE QString toString() const; + + QString name() const; + QUrl sourceUrl() const; + QString sourceCode() const; + InjectionPoint injectionPoint() const; + ScriptWorldId worldId() const; + bool runOnSubframes() const; + +public Q_SLOTS: + void setName(QString arg); + void setSourceUrl(QUrl arg); + void setSourceCode(QString arg); + void setInjectionPoint(InjectionPoint arg); + void setWorldId(ScriptWorldId arg); + void setRunOnSubframes(bool arg); + +Q_SIGNALS: + void nameChanged(QString arg); + void sourceUrlChanged(QUrl arg); + void sourceCodeChanged(QString arg); + void injectionPointChanged(InjectionPoint arg); + void worldIdChanged(ScriptWorldId arg); + void runOnSubframesChanged(bool arg); + +protected: + void timerEvent(QTimerEvent *e) override; + +private: + friend class QQuickWebEngineViewPrivate; + Q_DECLARE_PRIVATE(QQuickWebEngineScript) + QScopedPointer<QQuickWebEngineScriptPrivate> d_ptr; +}; +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINESCRIPT_P_H diff --git a/src/webengine/api/qquickwebenginescript_p_p.h b/src/webengine/api/qquickwebenginescript_p_p.h new file mode 100644 index 000000000..f8a957579 --- /dev/null +++ b/src/webengine/api/qquickwebenginescript_p_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINESCRIPT_P_P_H +#define QQUICKWEBENGINESCRIPT_P_P_H + +#include "qquickwebenginescript_p.h" + +#include <QtCore/QBasicTimer> +#include "user_script.h" +#include "web_contents_adapter.h" + +namespace QtWebEngineCore { +class UserScriptControllerHost; +class WebContentsAdapter; +} // namespace + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineScriptPrivate { +public: + Q_DECLARE_PUBLIC(QQuickWebEngineScript) + QQuickWebEngineScriptPrivate(); + void aboutToUpdateUnderlyingScript(); + void bind(QtWebEngineCore::UserScriptControllerHost *, QtWebEngineCore::WebContentsAdapter * = 0); + + QtWebEngineCore::UserScript coreScript; + QBasicTimer m_basicTimer; + QtWebEngineCore::UserScriptControllerHost *m_controllerHost; + QtWebEngineCore::WebContentsAdapter *m_adapter; + QUrl m_sourceUrl; + +private: + QQuickWebEngineScript *q_ptr; + +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINESCRIPT_P_P_H diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp index 743d22d81..8a88bac68 100644 --- a/src/webengine/api/qquickwebenginesettings.cpp +++ b/src/webengine/api/qquickwebenginesettings.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -35,238 +35,295 @@ ****************************************************************************/ #include "qquickwebenginesettings_p.h" -#include "qquickwebenginesettings_p_p.h" + +#include "qquickwebengineprofile_p.h" +#include "web_engine_settings.h" #include <QtCore/QList> QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QList<QQuickWebEngineSettingsPrivate*>, allSettings) +using QtWebEngineCore::WebEngineSettings; -QQuickWebEngineSettingsPrivate::QQuickWebEngineSettingsPrivate() - : coreSettings(new WebEngineSettings(this)) -{ - allSettings->append(this); -} +QQuickWebEngineSettings::QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings) + : d_ptr(new WebEngineSettings(parentSettings ? parentSettings->d_ptr.data() : 0)) +{ } -void QQuickWebEngineSettingsPrivate::apply() -{ - coreSettings->scheduleApply(); - QQuickWebEngineSettingsPrivate *globals = QQuickWebEngineSettings::globalSettings()->d_func(); - Q_ASSERT((this == globals) != (allSettings->contains(this))); - if (this == globals) - Q_FOREACH (QQuickWebEngineSettingsPrivate *settings, *allSettings) - settings->coreSettings->scheduleApply(); -} +/*! + \qmltype WebEngineSettings + \instantiates QQuickWebEngineSettings + \inqmlmodule QtWebEngine + \since QtWebEngine 1.1 + \brief WebEngineSettings allows configuration of browser properties and attributes. -WebEngineSettings *QQuickWebEngineSettingsPrivate::fallbackSettings() const -{ - return QQuickWebEngineSettings::globalSettings()->d_func()->coreSettings.data(); -} + WebEngineSettings allows configuration of browser properties and generic attributes like for example + JavaScript, focus behavior and access to remote content. + Each WebEngineView can have individual settings. + +*/ -QQuickWebEngineSettings *QQuickWebEngineSettings::globalSettings() -{ - static QQuickWebEngineSettings *globals = 0; - if (!globals) { - globals = new QQuickWebEngineSettings; - allSettings->removeAll(globals->d_func()); - globals->d_func()->coreSettings->initDefaults(); - } - return globals; -} QQuickWebEngineSettings::~QQuickWebEngineSettings() -{ - allSettings->removeAll(this->d_func()); -} +{ } + +/*! + \qmlproperty bool WebEngineSettings::autoLoadImages + Specifies whether images are automatically loaded in web pages. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::autoLoadImages() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::AutoLoadImages); + return d_ptr->testAttribute(WebEngineSettings::AutoLoadImages); } +/*! + \qmlproperty bool WebEngineSettings::javascriptEnabled + + Enables or disables the running of JavaScript programs. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::javascriptEnabled() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::JavascriptEnabled); + return d_ptr->testAttribute(WebEngineSettings::JavascriptEnabled); } +/*! + \qmlproperty bool WebEngineSettings::javascriptCanOpenWindows + + Specifies whether JavaScript programs can open new windows. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::javascriptCanOpenWindows() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); + return d_ptr->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); } +/*! + \qmlproperty bool WebEngineSettings::javascriptCanAccessClipboard + + Specifies whether JavaScript programs can read or write to the clipboard. + + This is disabled by default. +*/ bool QQuickWebEngineSettings::javascriptCanAccessClipboard() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); + return d_ptr->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); } +/*! + \qmlproperty bool WebEngineSettings::linksIncludedInFocusChain + + Specifies whether hyperlinks should be included in the keyboard focus chain. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::linksIncludedInFocusChain() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); + return d_ptr->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); } +/*! + \qmlproperty bool WebEngineSettings::localStorageEnabled + + Specifies whether support for the HTML 5 local storage feature is enabled or not. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::localStorageEnabled() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::LocalStorageEnabled); + return d_ptr->testAttribute(WebEngineSettings::LocalStorageEnabled); } +/*! + \qmlproperty bool WebEngineSettings::localContentCanAccessRemoteUrls + + Specifies whether locally loaded documents are allowed to access remote urls. + For more information about security origins and local vs. remote content see QWebEngineSecurityOrigin. + + This is disabled by default. +*/ bool QQuickWebEngineSettings::localContentCanAccessRemoteUrls() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); + return d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); } +/*! + \qmlproperty bool WebEngineSettings::spatialNavigationEnabled + + Enables or disables the Spatial Navigation feature, which consists in the + ability to navigate between focusable elements in a Web page, such as hyperlinks + and form controls, by using Left, Right, Up and Down arrow keys. + + For example, if a user presses the Right key, heuristics determine whether there + is an element they might be trying to reach towards the right and which element + they probably want. + + This is disabled by default. + +*/ bool QQuickWebEngineSettings::spatialNavigationEnabled() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::SpatialNavigationEnabled); + return d_ptr->testAttribute(WebEngineSettings::SpatialNavigationEnabled); } +/*! + \qmlproperty bool WebEngineSettings::localContentCanAccessFileUrls + + Specifies whether locally loaded documents are allowed to access other local urls. + For more information about security origins and local vs. remote content see QWebEngineSecurityOrigin. + + This is enabled by default. +*/ bool QQuickWebEngineSettings::localContentCanAccessFileUrls() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); + return d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); } +/*! + \qmlproperty bool WebEngineSettings::hyperlinkAuditingEnabled + + This setting enables support for the ping attribute for hyperlinks. + + It is disabled by default. +*/ bool QQuickWebEngineSettings::hyperlinkAuditingEnabled() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); + return d_ptr->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); } +/*! + \qmlproperty bool WebEngineSettings::errorPageEnabled + + This setting enables built-in error pages of Chromium. + + It is enabled by default. +*/ bool QQuickWebEngineSettings::errorPageEnabled() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->testAttribute(WebEngineSettings::ErrorPageEnabled); + return d_ptr->testAttribute(WebEngineSettings::ErrorPageEnabled); } +/*! + \qmlproperty QString WebEngineSettings::defaultTextEncoding + + The \a encoding, must be a string describing an encoding such as "utf-8", + "iso-8859-1", etc. + + If left empty a default value will be used. +*/ QString QQuickWebEngineSettings::defaultTextEncoding() const { - Q_D(const QQuickWebEngineSettings); - return d->coreSettings->defaultTextEncoding(); + return d_ptr->defaultTextEncoding(); } void QQuickWebEngineSettings::setAutoLoadImages(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::AutoLoadImages); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::AutoLoadImages); // Set unconditionally as it sets the override for the current settings while the current setting // could be from the fallback and is prone to changing later on. - d->coreSettings->setAttribute(WebEngineSettings::AutoLoadImages, on); - if (wasOn ^ on) - Q_EMIT autoLoadImagesChanged(on); + d_ptr->setAttribute(WebEngineSettings::AutoLoadImages, on); + if (wasOn != on) + Q_EMIT autoLoadImagesChanged(); } void QQuickWebEngineSettings::setJavascriptEnabled(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::JavascriptEnabled); - d->coreSettings->setAttribute(WebEngineSettings::JavascriptEnabled, on); - if (wasOn ^ on) - Q_EMIT javascriptEnabledChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptEnabled); + d_ptr->setAttribute(WebEngineSettings::JavascriptEnabled, on); + if (wasOn != on) + Q_EMIT javascriptEnabledChanged(); } void QQuickWebEngineSettings::setJavascriptCanOpenWindows(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); - d->coreSettings->setAttribute(WebEngineSettings::JavascriptCanOpenWindows, on); - if (wasOn ^ on) - Q_EMIT javascriptCanOpenWindowsChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptCanOpenWindows); + d_ptr->setAttribute(WebEngineSettings::JavascriptCanOpenWindows, on); + if (wasOn != on) + Q_EMIT javascriptCanOpenWindowsChanged(); } void QQuickWebEngineSettings::setJavascriptCanAccessClipboard(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); - d->coreSettings->setAttribute(WebEngineSettings::JavascriptCanAccessClipboard, on); - if (wasOn ^ on) - Q_EMIT javascriptCanAccessClipboardChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::JavascriptCanAccessClipboard); + d_ptr->setAttribute(WebEngineSettings::JavascriptCanAccessClipboard, on); + if (wasOn != on) + Q_EMIT javascriptCanAccessClipboardChanged(); } void QQuickWebEngineSettings::setLinksIncludedInFocusChain(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); - d->coreSettings->setAttribute(WebEngineSettings::LinksIncludedInFocusChain, on); - if (wasOn ^ on) - Q_EMIT linksIncludedInFocusChainChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::LinksIncludedInFocusChain); + d_ptr->setAttribute(WebEngineSettings::LinksIncludedInFocusChain, on); + if (wasOn != on) + Q_EMIT linksIncludedInFocusChainChanged(); } void QQuickWebEngineSettings::setLocalStorageEnabled(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::LocalStorageEnabled); - d->coreSettings->setAttribute(WebEngineSettings::LocalStorageEnabled, on); - if (wasOn ^ on) - Q_EMIT localStorageEnabledChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalStorageEnabled); + d_ptr->setAttribute(WebEngineSettings::LocalStorageEnabled, on); + if (wasOn != on) + Q_EMIT localStorageEnabledChanged(); } void QQuickWebEngineSettings::setLocalContentCanAccessRemoteUrls(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); - d->coreSettings->setAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls, on); - if (wasOn ^ on) - Q_EMIT localContentCanAccessRemoteUrlsChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls); + d_ptr->setAttribute(WebEngineSettings::LocalContentCanAccessRemoteUrls, on); + if (wasOn != on) + Q_EMIT localContentCanAccessRemoteUrlsChanged(); } void QQuickWebEngineSettings::setSpatialNavigationEnabled(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::SpatialNavigationEnabled); - d->coreSettings->setAttribute(WebEngineSettings::SpatialNavigationEnabled, on); - if (wasOn ^ on) - Q_EMIT spatialNavigationEnabledChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::SpatialNavigationEnabled); + d_ptr->setAttribute(WebEngineSettings::SpatialNavigationEnabled, on); + if (wasOn != on) + Q_EMIT spatialNavigationEnabledChanged(); } void QQuickWebEngineSettings::setLocalContentCanAccessFileUrls(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); - d->coreSettings->setAttribute(WebEngineSettings::LocalContentCanAccessFileUrls, on); - if (wasOn ^ on) - Q_EMIT localContentCanAccessFileUrlsChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::LocalContentCanAccessFileUrls); + d_ptr->setAttribute(WebEngineSettings::LocalContentCanAccessFileUrls, on); + if (wasOn != on) + Q_EMIT localContentCanAccessFileUrlsChanged(); } void QQuickWebEngineSettings::setHyperlinkAuditingEnabled(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); - d->coreSettings->setAttribute(WebEngineSettings::HyperlinkAuditingEnabled, on); - if (wasOn ^ on) - Q_EMIT hyperlinkAuditingEnabledChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::HyperlinkAuditingEnabled); + d_ptr->setAttribute(WebEngineSettings::HyperlinkAuditingEnabled, on); + if (wasOn != on) + Q_EMIT hyperlinkAuditingEnabledChanged(); } void QQuickWebEngineSettings::setErrorPageEnabled(bool on) { - Q_D(QQuickWebEngineSettings); - bool wasOn = d->coreSettings->testAttribute(WebEngineSettings::ErrorPageEnabled); - d->coreSettings->setAttribute(WebEngineSettings::ErrorPageEnabled, on); - if (wasOn ^ on) - Q_EMIT errorPageEnabledChanged(on); + bool wasOn = d_ptr->testAttribute(WebEngineSettings::ErrorPageEnabled); + d_ptr->setAttribute(WebEngineSettings::ErrorPageEnabled, on); + if (wasOn != on) + Q_EMIT errorPageEnabledChanged(); } void QQuickWebEngineSettings::setDefaultTextEncoding(QString encoding) { - Q_D(QQuickWebEngineSettings); - const QString oldDefaultTextEncoding = d->coreSettings->defaultTextEncoding(); - d->coreSettings->setDefaultTextEncoding(encoding); + const QString oldDefaultTextEncoding = d_ptr->defaultTextEncoding(); + d_ptr->setDefaultTextEncoding(encoding); if (oldDefaultTextEncoding.compare(encoding)) - Q_EMIT defaultTextEncodingChanged(encoding); + Q_EMIT defaultTextEncodingChanged(); } -QQuickWebEngineSettings::QQuickWebEngineSettings() - : d_ptr(new QQuickWebEngineSettingsPrivate) +void QQuickWebEngineSettings::setParentSettings(QQuickWebEngineSettings *parentSettings) { + d_ptr->setParentSettings(parentSettings->d_ptr.data()); + d_ptr->scheduleApplyRecursively(); } QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h index 4a7c2f834..68c85ea7f 100644 --- a/src/webengine/api/qquickwebenginesettings_p.h +++ b/src/webengine/api/qquickwebenginesettings_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -41,9 +41,11 @@ #include <QObject> #include <QScopedPointer> -QT_BEGIN_NAMESPACE +namespace QtWebEngineCore { +class WebEngineSettings; +} -class QQuickWebEngineSettingsPrivate; +QT_BEGIN_NAMESPACE class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject { Q_OBJECT @@ -61,8 +63,6 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject { Q_PROPERTY(QString defaultTextEncoding READ defaultTextEncoding WRITE setDefaultTextEncoding NOTIFY defaultTextEncodingChanged) public: - static QQuickWebEngineSettings *globalSettings(); - ~QQuickWebEngineSettings(); bool autoLoadImages() const; @@ -92,26 +92,28 @@ public: void setDefaultTextEncoding(QString encoding); signals: - void autoLoadImagesChanged(bool on); - void javascriptEnabledChanged(bool on); - void javascriptCanOpenWindowsChanged(bool on); - void javascriptCanAccessClipboardChanged(bool on); - void linksIncludedInFocusChainChanged(bool on); - void localStorageEnabledChanged(bool on); - void localContentCanAccessRemoteUrlsChanged(bool on); - void spatialNavigationEnabledChanged(bool on); - void localContentCanAccessFileUrlsChanged(bool on); - void hyperlinkAuditingEnabledChanged(bool on); - void errorPageEnabledChanged(bool on); - void defaultTextEncodingChanged(QString encoding); + void autoLoadImagesChanged(); + void javascriptEnabledChanged(); + void javascriptCanOpenWindowsChanged(); + void javascriptCanAccessClipboardChanged(); + void linksIncludedInFocusChainChanged(); + void localStorageEnabledChanged(); + void localContentCanAccessRemoteUrlsChanged(); + void spatialNavigationEnabledChanged(); + void localContentCanAccessFileUrlsChanged(); + void hyperlinkAuditingEnabledChanged(); + void errorPageEnabledChanged(); + void defaultTextEncodingChanged(); private: - QQuickWebEngineSettings(); + explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = 0); Q_DISABLE_COPY(QQuickWebEngineSettings) - Q_DECLARE_PRIVATE(QQuickWebEngineSettings) + friend class QQuickWebEngineProfilePrivate; friend class QQuickWebEngineViewPrivate; - QScopedPointer<QQuickWebEngineSettingsPrivate> d_ptr; + void setParentSettings(QQuickWebEngineSettings *parentSettings); + + QScopedPointer<QtWebEngineCore::WebEngineSettings> d_ptr; }; QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesingleton.cpp b/src/webengine/api/qquickwebenginesingleton.cpp index bf4951f3b..3f0c8cb65 100644 --- a/src/webengine/api/qquickwebenginesingleton.cpp +++ b/src/webengine/api/qquickwebenginesingleton.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -37,12 +37,18 @@ #include "qquickwebenginesingleton_p.h" #include "qquickwebenginesettings_p.h" +#include "qquickwebengineprofile_p.h" QT_BEGIN_NAMESPACE QQuickWebEngineSettings *QQuickWebEngineSingleton::settings() const { - return QQuickWebEngineSettings::globalSettings(); + return defaultProfile()->settings(); +} + +QQuickWebEngineProfile *QQuickWebEngineSingleton::defaultProfile() const +{ + return QQuickWebEngineProfile::defaultProfile(); } QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginesingleton_p.h b/src/webengine/api/qquickwebenginesingleton_p.h index 23205e2df..a653116e4 100644 --- a/src/webengine/api/qquickwebenginesingleton_p.h +++ b/src/webengine/api/qquickwebenginesingleton_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -41,14 +41,16 @@ #include <qtwebengineglobal_p.h> QT_BEGIN_NAMESPACE +class QQuickWebEngineProfile; class QQuickWebEngineSettings; - class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSingleton : public QObject { Q_OBJECT Q_PROPERTY(QQuickWebEngineSettings* settings READ settings CONSTANT FINAL) + Q_PROPERTY(QQuickWebEngineProfile* defaultProfile READ defaultProfile CONSTANT FINAL REVISION 1) public: QQuickWebEngineSettings *settings() const; + QQuickWebEngineProfile *defaultProfile() const; }; QT_END_NAMESPACE diff --git a/src/webengine/api/qquickwebenginetestsupport.cpp b/src/webengine/api/qquickwebenginetestsupport.cpp new file mode 100644 index 000000000..d85e56e59 --- /dev/null +++ b/src/webengine/api/qquickwebenginetestsupport.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebenginetestsupport_p.h" + +#include "qquickwebengineloadrequest_p.h" + +QT_BEGIN_NAMESPACE + +QQuickWebEngineErrorPage::QQuickWebEngineErrorPage() +{ +} + +void QQuickWebEngineErrorPage::loadFinished(bool success, const QUrl &url) +{ + // Loading of the error page should not fail. + Q_ASSERT(success); + + QQuickWebEngineLoadRequest loadRequest(url, QQuickWebEngineView::LoadSucceededStatus); + Q_EMIT loadingChanged(&loadRequest); + return; +} + +void QQuickWebEngineErrorPage::loadStarted(const QUrl &provisionalUrl) +{ + QQuickWebEngineLoadRequest loadRequest(provisionalUrl, QQuickWebEngineView::LoadStartedStatus); + Q_EMIT loadingChanged(&loadRequest); +} + +QQuickWebEngineTestSupport::QQuickWebEngineTestSupport() + : m_errorPage(new QQuickWebEngineErrorPage()) +{ +} + +QQuickWebEngineErrorPage *QQuickWebEngineTestSupport::errorPage() const +{ + return m_errorPage.data(); +} + +QT_END_NAMESPACE + +#include "moc_qquickwebenginetestsupport_p.cpp" diff --git a/src/webengine/api/qquickwebenginesettings_p_p.h b/src/webengine/api/qquickwebenginetestsupport_p.h index 8f3e95eea..832ac2803 100644 --- a/src/webengine/api/qquickwebenginesettings_p_p.h +++ b/src/webengine/api/qquickwebenginetestsupport_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -34,24 +34,43 @@ ** ****************************************************************************/ -#ifndef QQUICKWEBENGINESETTINGS_P_P_H -#define QQUICKWEBENGINESETTINGS_P_P_H +#ifndef QQUICKWEBENGINETESTSUPPORT_P_H +#define QQUICKWEBENGINETESTSUPPORT_P_H -#include "web_engine_settings.h" +#include <private/qtwebengineglobal_p.h> + +#include <QObject> +#include <QUrl> QT_BEGIN_NAMESPACE -class QQuickWebEngineSettingsPrivate : public WebEngineSettingsDelegate { +class QQuickWebEngineLoadRequest; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineErrorPage : public QObject { + Q_OBJECT + public: - QQuickWebEngineSettingsPrivate(); - QQuickWebEngineSettingsPrivate(WebContentsAdapter *adapter); + QQuickWebEngineErrorPage(); + + void loadFinished(bool success, const QUrl &url); + void loadStarted(const QUrl &provisionalUrl); - void apply() Q_DECL_OVERRIDE; - WebEngineSettings *fallbackSettings() const Q_DECL_OVERRIDE; +Q_SIGNALS: + void loadingChanged(QQuickWebEngineLoadRequest *loadRequest); +}; + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineTestSupport : public QObject { + Q_OBJECT + Q_PROPERTY(QQuickWebEngineErrorPage *errorPage READ errorPage) + +public: + QQuickWebEngineTestSupport(); + QQuickWebEngineErrorPage *errorPage() const; - QScopedPointer<WebEngineSettings> coreSettings; +private: + QScopedPointer<QQuickWebEngineErrorPage> m_errorPage; }; QT_END_NAMESPACE -#endif // QQUICKWEBENGINESETTINGS_P_P_H +#endif // QQUICKWEBENGINETESTSUPPORT_P_H diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index a35cfc3c3..bc58e2526 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -37,17 +37,27 @@ #include "qquickwebengineview_p.h" #include "qquickwebengineview_p_p.h" +#include "browser_context_adapter.h" #include "certificate_error_controller.h" #include "javascript_dialog_controller.h" #include "qquickwebenginehistory_p.h" +#include "qquickwebenginecertificateerror_p.h" #include "qquickwebengineloadrequest_p.h" #include "qquickwebenginenavigationrequest_p.h" #include "qquickwebenginenewviewrequest_p.h" +#include "qquickwebengineprofile_p.h" +#include "qquickwebengineprofile_p_p.h" #include "qquickwebenginesettings_p.h" -#include "qquickwebenginesettings_p_p.h" +#include "qquickwebenginescript_p_p.h" + +#ifdef ENABLE_QML_TESTSUPPORT_API +#include "qquickwebenginetestsupport_p.h" +#endif + #include "render_widget_host_view_qt_delegate_quick.h" #include "render_widget_host_view_qt_delegate_quickwindow.h" #include "ui_delegates_manager.h" +#include "user_script_controller_host.h" #include "web_contents_adapter.h" #include "web_engine_error.h" #include "web_engine_settings.h" @@ -58,6 +68,7 @@ #include <QQmlContext> #include <QQmlEngine> #include <QQmlProperty> +#include <QQmlWebChannel> #include <QScreen> #include <QStringBuilder> #include <QUrl> @@ -66,6 +77,7 @@ #endif // QT_NO_ACCESSIBILITY QT_BEGIN_NAMESPACE +using namespace QtWebEngineCore; #ifndef QT_NO_ACCESSIBILITY static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *object) @@ -77,14 +89,17 @@ static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *obje #endif // QT_NO_ACCESSIBILITY QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() - : adapter(new WebContentsAdapter) + : adapter(0) , e(new QQuickWebEngineViewExperimental(this)) , v(new QQuickWebEngineViewport(this)) , m_history(new QQuickWebEngineHistory(this)) - , m_settings(new QQuickWebEngineSettings) + , m_profile(QQuickWebEngineProfile::defaultProfile()) + , m_settings(new QQuickWebEngineSettings(m_profile->settings())) +#ifdef ENABLE_QML_TESTSUPPORT_API + , m_testSupport(0) +#endif , contextMenuExtraItems(0) , loadProgress(0) - , inspectable(false) , m_isFullScreen(false) , isLoading(false) , devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio()) @@ -217,10 +232,23 @@ void QQuickWebEngineViewPrivate::javascriptDialog(QSharedPointer<JavaScriptDialo ui()->showDialog(dialog); } -void QQuickWebEngineViewPrivate::allowCertificateError(const QExplicitlySharedDataPointer<CertificateErrorController> &errorController) +void QQuickWebEngineViewPrivate::allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) +{ + Q_Q(QQuickWebEngineView); + + QQuickWebEngineCertificateError *quickController = new QQuickWebEngineCertificateError(errorController); + QQmlEngine::setObjectOwnership(quickController, QQmlEngine::JavaScriptOwnership); + Q_EMIT q->certificateError(quickController); + if (!quickController->deferred() && !quickController->answered()) + quickController->rejectCertificate(); + else + m_certificateErrorControllers.append(errorController); +} + +void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url) { - // ### Implement a way to export this to QML - Q_UNUSED(errorController); + Q_Q(QQuickWebEngineView); + Q_EMIT q->featurePermissionRequested(url, QQuickWebEngineView::Geolocation); } void QQuickWebEngineViewPrivate::runFileChooser(FileChooserMode mode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) @@ -282,11 +310,20 @@ qreal QQuickWebEngineViewPrivate::dpiScale() const return m_dpiScale; } -void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl) +void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage) { Q_Q(QQuickWebEngineView); + if (isErrorPage) { +#ifdef ENABLE_QML_TESTSUPPORT_API + if (m_testSupport) + m_testSupport->errorPage()->loadStarted(provisionalUrl); +#endif + return; + } + isLoading = true; m_history->reset(); + m_certificateErrorControllers.clear(); QQuickWebEngineLoadRequest loadRequest(provisionalUrl, QQuickWebEngineView::LoadStartedStatus); Q_EMIT q->loadingChanged(&loadRequest); } @@ -305,9 +342,18 @@ Q_STATIC_ASSERT(static_cast<int>(WebEngineError::NoErrorDomain) == static_cast<i Q_STATIC_ASSERT(static_cast<int>(WebEngineError::CertificateErrorDomain) == static_cast<int>(QQuickWebEngineView::CertificateErrorDomain)); Q_STATIC_ASSERT(static_cast<int>(WebEngineError::DnsErrorDomain) == static_cast<int>(QQuickWebEngineView::DnsErrorDomain)); -void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, int errorCode, const QString &errorDescription) +void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) { Q_Q(QQuickWebEngineView); + + if (isErrorPage) { +#ifdef ENABLE_QML_TESTSUPPORT_API + if (m_testSupport) + m_testSupport->errorPage()->loadFinished(success, url); +#endif + return; + } + isLoading = false; m_history->reset(); if (errorCode == WebEngineError::UserAbortedError) { @@ -339,8 +385,16 @@ void QQuickWebEngineViewPrivate::focusContainer() q->forceActiveFocus(); } +void QQuickWebEngineViewPrivate::unhandledKeyEvent(QKeyEvent *event) +{ + Q_Q(QQuickWebEngineView); + if (q->parentItem()) + q->window()->sendEvent(q->parentItem(), event); +} + void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) { + Q_Q(QQuickWebEngineView); QQuickWebEngineNewViewRequest request; // This increases the ref-count of newWebContents and will tell Chromium // to start loading it and possibly return it to its parent page window.open(). @@ -349,9 +403,11 @@ void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebConten switch (disposition) { case WebContentsAdapterClient::NewForegroundTabDisposition: - case WebContentsAdapterClient::NewBackgroundTabDisposition: request.m_destination = QQuickWebEngineView::NewViewInTab; break; + case WebContentsAdapterClient::NewBackgroundTabDisposition: + request.m_destination = QQuickWebEngineView::NewViewInBackgroundTab; + break; case WebContentsAdapterClient::NewPopupDisposition: request.m_destination = QQuickWebEngineView::NewViewInDialog; break; @@ -362,7 +418,7 @@ void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebConten Q_UNREACHABLE(); } - emit e->newViewRequested(&request); + Q_EMIT q->newViewRequested(&request); } void QQuickWebEngineViewPrivate::close() @@ -372,33 +428,44 @@ void QQuickWebEngineViewPrivate::close() void QQuickWebEngineViewPrivate::requestFullScreen(bool fullScreen) { - Q_EMIT e->fullScreenRequested(fullScreen); + Q_Q(QQuickWebEngineView); + QQuickWebEngineFullScreenRequest request(this, fullScreen); + Q_EMIT q->fullScreenRequested(request); } bool QQuickWebEngineViewPrivate::isFullScreen() const { - return e->isFullScreen(); + return m_isFullScreen; } void QQuickWebEngineViewPrivate::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) { Q_Q(QQuickWebEngineView); - Q_UNUSED(level); Q_EMIT q->javaScriptConsoleMessage(static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(level), message, lineNumber, sourceID); } void QQuickWebEngineViewPrivate::runMediaAccessPermissionRequest(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags requestFlags) { - if (!requestFlags) - return; - QQuickWebEngineViewExperimental::Feature feature; - if (requestFlags.testFlag(WebContentsAdapterClient::MediaAudioCapture) && requestFlags.testFlag(WebContentsAdapterClient::MediaVideoCapture)) - feature = QQuickWebEngineViewExperimental::MediaAudioVideoDevices; - else if (requestFlags.testFlag(WebContentsAdapterClient::MediaAudioCapture)) - feature = QQuickWebEngineViewExperimental::MediaAudioDevices; - else // WebContentsAdapterClient::MediaVideoCapture - feature = QQuickWebEngineViewExperimental::MediaVideoDevices; - Q_EMIT e->featurePermissionRequested(securityOrigin, feature); + Q_Q(QQuickWebEngineView); + if (!requestFlags) + return; + QQuickWebEngineView::Feature feature; + if (requestFlags.testFlag(WebContentsAdapterClient::MediaAudioCapture) && requestFlags.testFlag(WebContentsAdapterClient::MediaVideoCapture)) + feature = QQuickWebEngineView::MediaAudioVideoCapture; + else if (requestFlags.testFlag(WebContentsAdapterClient::MediaAudioCapture)) + feature = QQuickWebEngineView::MediaAudioCapture; + else // WebContentsAdapterClient::MediaVideoCapture + feature = QQuickWebEngineView::MediaVideoCapture; + Q_EMIT q->featurePermissionRequested(securityOrigin, feature); +} + +void QQuickWebEngineViewPrivate::runMouseLockPermissionRequest(const QUrl &securityOrigin) +{ + + Q_UNUSED(securityOrigin); + + // TODO: Add mouse lock support + adapter->grantMouseLockPermission(false); } #ifndef QT_NO_ACCESSIBILITY @@ -409,9 +476,14 @@ QObject *QQuickWebEngineViewPrivate::accessibilityParentObject() } #endif // QT_NO_ACCESSIBILITY +BrowserContextAdapter *QQuickWebEngineViewPrivate::browserContextAdapter() +{ + return m_profile->d_ptr->browserContext(); +} + WebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const { - return m_settings->d_func()->coreSettings.data(); + return m_settings->d_ptr.data(); } void QQuickWebEngineViewPrivate::setDevicePixelRatio(qreal devicePixelRatio) @@ -480,6 +552,11 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent return; } + if (webContents->browserContextAdapter() && browserContextAdapter() != webContents->browserContextAdapter()) { + qWarning("Can not adopt content from a different WebEngineProfile."); + return; + } + Q_Q(QQuickWebEngineView); // This throws away the WebContentsAdapter that has been used until now. // All its states, particularly the loading URL, are replaced by the adopted WebContentsAdapter. @@ -503,7 +580,6 @@ QQuickWebEngineView::QQuickWebEngineView(QQuickItem *parent) { Q_D(QQuickWebEngineView); d->e->q_ptr = d->q_ptr = this; - d->adapter->initialize(d); this->setActiveFocusOnTab(true); this->setFlag(QQuickItem::ItemIsFocusScope); @@ -517,10 +593,23 @@ QQuickWebEngineView::~QQuickWebEngineView() { } +void QQuickWebEngineViewPrivate::ensureContentsAdapter() +{ + if (!adapter) { + adapter = new WebContentsAdapter(); + adapter->initialize(this); + if (explicitUrl.isValid()) + adapter->load(explicitUrl); + // push down the page's user scripts + Q_FOREACH (QQuickWebEngineScript *script, m_userScripts) + script->d_func()->bind(browserContextAdapter()->userScriptController(), adapter.data()); + } +} + QUrl QQuickWebEngineView::url() const { Q_D(const QQuickWebEngineView); - return d->explicitUrl.isValid() ? d->explicitUrl : d->adapter->activeUrl(); + return d->explicitUrl.isValid() ? d->explicitUrl : (d->adapter ? d->adapter->activeUrl() : QUrl()); } void QQuickWebEngineView::setUrl(const QUrl& url) @@ -530,7 +619,10 @@ void QQuickWebEngineView::setUrl(const QUrl& url) Q_D(QQuickWebEngineView); d->explicitUrl = url; - d->adapter->load(url); + if (d->adapter) + d->adapter->load(url); + if (!qmlEngine(this)) + d->ensureContentsAdapter(); } QUrl QQuickWebEngineView::icon() const @@ -542,33 +634,125 @@ QUrl QQuickWebEngineView::icon() const void QQuickWebEngineView::loadHtml(const QString &html, const QUrl &baseUrl) { Q_D(QQuickWebEngineView); - d->adapter->setContent(html.toUtf8(), QStringLiteral("text/html;charset=UTF-8"), baseUrl); + d->explicitUrl = QUrl(); + if (!qmlEngine(this)) + d->ensureContentsAdapter(); + if (d->adapter) + d->adapter->setContent(html.toUtf8(), QStringLiteral("text/html;charset=UTF-8"), baseUrl); } void QQuickWebEngineView::goBack() { Q_D(QQuickWebEngineView); + if (!d->adapter) + return; d->adapter->navigateToOffset(-1); } void QQuickWebEngineView::goForward() { Q_D(QQuickWebEngineView); + if (!d->adapter) + return; d->adapter->navigateToOffset(1); } void QQuickWebEngineView::reload() { Q_D(QQuickWebEngineView); + if (!d->adapter) + return; d->adapter->reload(); } +void QQuickWebEngineView::reloadAndBypassCache() +{ + Q_D(QQuickWebEngineView); + if (!d->adapter) + return; + d->adapter->reloadAndBypassCache(); +} + void QQuickWebEngineView::stop() { Q_D(QQuickWebEngineView); + if (!d->adapter) + return; d->adapter->stop(); } +void QQuickWebEngineView::setZoomFactor(qreal arg) +{ + Q_D(QQuickWebEngineView); + if (!d->adapter) + return; + qreal oldFactor = d->adapter->currentZoomFactor(); + d->adapter->setZoomFactor(arg); + if (qFuzzyCompare(oldFactor, d->adapter->currentZoomFactor())) + return; + + emit zoomFactorChanged(arg); +} + +QQuickWebEngineProfile *QQuickWebEngineView::profile() const +{ + Q_D(const QQuickWebEngineView); + return d->m_profile; +} + +void QQuickWebEngineView::setProfile(QQuickWebEngineProfile *profile) +{ + Q_D(QQuickWebEngineView); + d->setProfile(profile); +} + +QQuickWebEngineSettings *QQuickWebEngineView::settings() const +{ + Q_D(const QQuickWebEngineView); + return d->m_settings.data(); +} + +QQmlListProperty<QQuickWebEngineScript> QQuickWebEngineView::userScripts() +{ + Q_D(QQuickWebEngineView); + return QQmlListProperty<QQuickWebEngineScript>(this, d, + d->userScripts_append, + d->userScripts_count, + d->userScripts_at, + d->userScripts_clear); +} + +void QQuickWebEngineViewPrivate::setProfile(QQuickWebEngineProfile *profile) +{ + if (profile == m_profile) + return; + m_profile = profile; + m_settings->setParentSettings(profile->settings()); + + if (adapter && adapter->browserContext() != browserContextAdapter()->browserContext()) { + // When the profile changes we need to create a new WebContentAdapter and reload the active URL. + QUrl activeUrl = adapter->activeUrl(); + adapter = 0; + ensureContentsAdapter(); + if (!explicitUrl.isValid() && activeUrl.isValid()) + adapter->load(activeUrl); + } +} + +#ifdef ENABLE_QML_TESTSUPPORT_API +QQuickWebEngineTestSupport *QQuickWebEngineView::testSupport() const +{ + Q_D(const QQuickWebEngineView); + return d->m_testSupport; +} + +void QQuickWebEngineView::setTestSupport(QQuickWebEngineTestSupport *testSupport) +{ + Q_D(QQuickWebEngineView); + d->m_testSupport = testSupport; +} +#endif + void QQuickWebEngineViewPrivate::didRunJavaScript(quint64 requestId, const QVariant &result) { Q_Q(QQuickWebEngineView); @@ -585,6 +769,20 @@ void QQuickWebEngineViewPrivate::didFindText(quint64 requestId, int matchCount) args.append(QJSValue(matchCount)); callback.call(args); } +void QQuickWebEngineViewPrivate::showValidationMessage(const QRect &anchor, const QString &mainText, const QString &subText) +{ + ui()->showMessageBubble(anchor, mainText, subText); +} + +void QQuickWebEngineViewPrivate::hideValidationMessage() +{ + ui()->hideMessageBubble(); +} + +void QQuickWebEngineViewPrivate::moveValidationMessage(const QRect &anchor) +{ + ui()->moveMessageBubble(anchor); +} bool QQuickWebEngineView::isLoading() const { @@ -601,24 +799,32 @@ int QQuickWebEngineView::loadProgress() const QString QQuickWebEngineView::title() const { Q_D(const QQuickWebEngineView); + if (!d->adapter) + return QString(); return d->adapter->pageTitle(); } bool QQuickWebEngineView::canGoBack() const { Q_D(const QQuickWebEngineView); + if (!d->adapter) + return false; return d->adapter->canGoBack(); } bool QQuickWebEngineView::canGoForward() const { Q_D(const QQuickWebEngineView); + if (!d->adapter) + return false; return d->adapter->canGoForward(); } void QQuickWebEngineView::runJavaScript(const QString &script, const QJSValue &callback) { Q_D(QQuickWebEngineView); + if (!d->adapter) + return; if (!callback.isUndefined()) { quint64 requestId = d_ptr->adapter->runJavaScriptCallbackResult(script); d->m_callbacks.insert(requestId, callback); @@ -632,28 +838,19 @@ QQuickWebEngineViewExperimental *QQuickWebEngineView::experimental() const return d->e.data(); } -bool QQuickWebEngineViewExperimental::inspectable() const +qreal QQuickWebEngineView::zoomFactor() const { Q_D(const QQuickWebEngineView); - return d->inspectable; -} - -void QQuickWebEngineViewExperimental::setInspectable(bool enable) -{ - Q_D(QQuickWebEngineView); - d->inspectable = enable; - d->adapter->enableInspector(enable); + if (!d->adapter) + return 1.0; + return d->adapter->currentZoomFactor(); } -void QQuickWebEngineViewExperimental::setIsFullScreen(bool fullscreen) -{ - d_ptr->m_isFullScreen = fullscreen; - emit isFullScreenChanged(); -} -bool QQuickWebEngineViewExperimental::isFullScreen() const +bool QQuickWebEngineView::isFullScreen() const { - return d_ptr->m_isFullScreen; + Q_D(const QQuickWebEngineView); + return d->m_isFullScreen; } void QQuickWebEngineViewExperimental::setExtraContextMenuEntriesComponent(QQmlComponent *contextMenuExtras) @@ -669,69 +866,115 @@ QQmlComponent *QQuickWebEngineViewExperimental::extraContextMenuEntriesComponent return d_ptr->contextMenuExtraItems; } -QQuickWebEngineSettings *QQuickWebEngineViewExperimental::settings() const -{ - return d_ptr->m_settings.data(); -} - -void QQuickWebEngineViewExperimental::findText(const QString &subString, FindFlags options, const QJSValue &callback) +void QQuickWebEngineView::findText(const QString &subString, FindFlags options, const QJSValue &callback) { + Q_D(QQuickWebEngineView); + if (!d->adapter) + return; if (subString.isEmpty()) { - d_ptr->adapter->stopFinding(); + d->adapter->stopFinding(); if (!callback.isUndefined()) { QJSValueList args; args.append(QJSValue(0)); const_cast<QJSValue&>(callback).call(args); } } else { - quint64 requestId = d_ptr->adapter->findText(subString, options & FindCaseSensitively, options & FindBackward); + quint64 requestId = d->adapter->findText(subString, options & FindCaseSensitively, options & FindBackward); if (!callback.isUndefined()) - d_ptr->m_callbacks.insert(requestId, callback); + d->m_callbacks.insert(requestId, callback); + } +} + +QQuickWebEngineHistory *QQuickWebEngineView::navigationHistory() const +{ + Q_D(const QQuickWebEngineView); + return d->m_history.data(); +} + +/*! + * \qmlproperty QQmlWebChannel WebEngineView::webChannel + * \since QtWebEngine 1.1 + * + * The web channel instance used by this view. + * This channel is automatically using the internal QtWebEngine transport mechanism over Chromium IPC, + * and exposed in the javascript context of the page it is rendering as \c qt.webChannelTransport. + * This transport object is used when instantiating the JavaScript counterpart of QWebChannel using + * the \l{Qt WebChannel JavaScript API}. + * + * \note The view does not take ownership when explicitly setting a webChannel object. + */ + +QQmlWebChannel *QQuickWebEngineView::webChannel() +{ + Q_D(QQuickWebEngineView); + d->ensureContentsAdapter(); + QQmlWebChannel *qmlWebChannel = qobject_cast<QQmlWebChannel *>(d->adapter->webChannel()); + Q_ASSERT(!d->adapter->webChannel() || qmlWebChannel); + if (!qmlWebChannel) { + qmlWebChannel = new QQmlWebChannel(this); + d->adapter->setWebChannel(qmlWebChannel); } + return qmlWebChannel; } -QQuickWebEngineHistory *QQuickWebEngineViewExperimental::navigationHistory() const +void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel) { - return d_ptr->m_history.data(); + Q_D(QQuickWebEngineView); + bool notify = (d->adapter->webChannel() == webChannel); + d->adapter->setWebChannel(webChannel); + if (notify) + Q_EMIT webChannelChanged(); } -void QQuickWebEngineViewExperimental::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineViewExperimental::Feature feature, bool granted) +void QQuickWebEngineView::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineView::Feature feature, bool granted) { - if (!granted && feature >= MediaAudioDevices && feature <= MediaAudioVideoDevices) { + if (!d_ptr->adapter) + return; + if (!granted && feature >= MediaAudioCapture && feature <= MediaAudioVideoCapture) { d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaNone); return; } switch (feature) { - case MediaAudioDevices: + case MediaAudioCapture: d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaAudioCapture); break; - case MediaVideoDevices: + case MediaVideoCapture: d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaVideoCapture); break; - case MediaAudioVideoDevices: - d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaRequestFlags(WebContentsAdapterClient::MediaAudioCapture - | WebContentsAdapterClient::MediaVideoCapture)); + case MediaAudioVideoCapture: + d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaRequestFlags(WebContentsAdapterClient::MediaAudioCapture | WebContentsAdapterClient::MediaVideoCapture)); + break; + case Geolocation: + d_ptr->adapter->runGeolocationRequestCallback(securityOrigin, granted); break; + default: + Q_UNREACHABLE(); } } -void QQuickWebEngineViewExperimental::goBackTo(int index) +void QQuickWebEngineView::goBackOrForward(int offset) { - int count = d_ptr->adapter->currentNavigationEntryIndex(); + Q_D(QQuickWebEngineView); + if (!d->adapter) + return; + const int current = d->adapter->currentNavigationEntryIndex(); + const int count = d->adapter->navigationEntryCount(); + const int index = current + offset; + if (index < 0 || index >= count) return; - d_ptr->adapter->navigateToIndex(count - 1 - index); + d->adapter->navigateToIndex(index); } -void QQuickWebEngineViewExperimental::goForwardTo(int index) +void QQuickWebEngineView::fullScreenCancelled() { - int count = d_ptr->adapter->navigationEntryCount() - d_ptr->adapter->currentNavigationEntryIndex() - 1; - if (index < 0 || index >= count) - return; - - d_ptr->adapter->navigateToIndex(d_ptr->adapter->currentNavigationEntryIndex() + 1 + index); + Q_D(QQuickWebEngineView); + if (d->m_isFullScreen) { + d->m_isFullScreen = false; + Q_EMIT isFullScreenChanged(); + } } void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -746,7 +989,7 @@ void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRect void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &value) { Q_D(QQuickWebEngineView); - if (change == ItemSceneChange || change == ItemVisibleHasChanged) { + if (d->adapter && (change == ItemSceneChange || change == ItemVisibleHasChanged)) { if (window() && isVisible()) d->adapter->wasShown(); else @@ -755,6 +998,68 @@ void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &va QQuickItem::itemChange(change, value); } +void QQuickWebEngineViewPrivate::userScripts_append(QQmlListProperty<QQuickWebEngineScript> *p, QQuickWebEngineScript *script) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineViewPrivate *d = static_cast<QQuickWebEngineViewPrivate*>(p->data); + UserScriptControllerHost *scriptController = d->browserContextAdapter()->userScriptController(); + d->m_userScripts.append(script); + // If the adapter hasn't been instantiated, we'll bind the scripts in ensureContentsAdapter() + if (!d->adapter) + return; + script->d_func()->bind(scriptController, d->adapter.data()); +} + +int QQuickWebEngineViewPrivate::userScripts_count(QQmlListProperty<QQuickWebEngineScript> *p) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineViewPrivate *d = static_cast<QQuickWebEngineViewPrivate*>(p->data); + return d->m_userScripts.count(); +} + +QQuickWebEngineScript *QQuickWebEngineViewPrivate::userScripts_at(QQmlListProperty<QQuickWebEngineScript> *p, int idx) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineViewPrivate *d = static_cast<QQuickWebEngineViewPrivate*>(p->data); + return d->m_userScripts.at(idx); +} + +void QQuickWebEngineViewPrivate::userScripts_clear(QQmlListProperty<QQuickWebEngineScript> *p) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineViewPrivate *d = static_cast<QQuickWebEngineViewPrivate*>(p->data); + UserScriptControllerHost *scriptController = d->browserContextAdapter()->userScriptController(); + scriptController->clearAllScripts(d->adapter.data()); + d->m_userScripts.clear(); +} + +void QQuickWebEngineView::componentComplete() +{ + Q_D(QQuickWebEngineView); + QQuickItem::componentComplete(); + d->ensureContentsAdapter(); +} + +QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest() + : viewPrivate(0) + , m_toggleOn(false) +{ +} + +QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest(QQuickWebEngineViewPrivate *viewPrivate, bool toggleOn) + : viewPrivate(viewPrivate) + , m_toggleOn(toggleOn) +{ +} + +void QQuickWebEngineFullScreenRequest::accept() +{ + if (viewPrivate && viewPrivate->m_isFullScreen != m_toggleOn) { + viewPrivate->m_isFullScreen = m_toggleOn; + Q_EMIT viewPrivate->q_ptr->isFullScreenChanged(); + } +} + QQuickWebEngineViewExperimental::QQuickWebEngineViewExperimental(QQuickWebEngineViewPrivate *viewPrivate) : q_ptr(0) , d_ptr(viewPrivate) @@ -786,6 +1091,8 @@ void QQuickWebEngineViewport::setDevicePixelRatio(qreal devicePixelRatio) if (d->devicePixelRatio == devicePixelRatio) return; d->setDevicePixelRatio(devicePixelRatio); + if (!d->adapter) + return; d->adapter->dpiScaleChanged(); Q_EMIT devicePixelRatioChanged(); } diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index f3ceb2c69..4539ad34b 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -38,14 +38,40 @@ #define QQUICKWEBENGINEVIEW_P_H #include <private/qtwebengineglobal_p.h> +#include "qquickwebenginescript_p.h" #include <QQuickItem> QT_BEGIN_NAMESPACE -class QQuickWebEngineViewExperimental; -class QQuickWebEngineViewPrivate; +class QQmlWebChannel; +class QQuickWebEngineCertificateError; +class QQuickWebEngineHistory; class QQuickWebEngineLoadRequest; class QQuickWebEngineNavigationRequest; +class QQuickWebEngineNewViewRequest; +class QQuickWebEngineProfile; +class QQuickWebEngineSettings; +class QQuickWebEngineViewExperimental; +class QQuickWebEngineViewPrivate; + +#ifdef ENABLE_QML_TESTSUPPORT_API +class QQuickWebEngineTestSupport; +#endif + +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineFullScreenRequest { + Q_GADGET + Q_PROPERTY(bool toggleOn READ toggleOn) +public: + QQuickWebEngineFullScreenRequest(); + QQuickWebEngineFullScreenRequest(QQuickWebEngineViewPrivate *viewPrivate, bool toggleOn); + + Q_INVOKABLE void accept(); + bool toggleOn() { return m_toggleOn; } + +private: + QQuickWebEngineViewPrivate *viewPrivate; + bool m_toggleOn; +}; class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_OBJECT @@ -56,12 +82,26 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY urlChanged) Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY urlChanged) + Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged REVISION 1) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged REVISION 1) + Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile FINAL REVISION 1) + Q_PROPERTY(QQuickWebEngineSettings *settings READ settings REVISION 1) + Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL REVISION 1) + Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel NOTIFY webChannelChanged REVISION 1) + Q_PROPERTY(QQmlListProperty<QQuickWebEngineScript> userScripts READ userScripts FINAL) + +#ifdef ENABLE_QML_TESTSUPPORT_API + Q_PROPERTY(QQuickWebEngineTestSupport *testSupport READ testSupport WRITE setTestSupport FINAL) +#endif + Q_ENUMS(NavigationRequestAction); Q_ENUMS(NavigationType); Q_ENUMS(LoadStatus); Q_ENUMS(ErrorDomain); Q_ENUMS(NewViewDestination); + Q_ENUMS(Feature); Q_ENUMS(JavaScriptConsoleMessageLevel); + Q_FLAGS(FindFlags); public: QQuickWebEngineView(QQuickItem *parent = 0); @@ -75,6 +115,9 @@ public: QString title() const; bool canGoBack() const; bool canGoForward() const; + bool isFullScreen() const; + qreal zoomFactor() const; + void setZoomFactor(qreal arg); QQuickWebEngineViewExperimental *experimental() const; @@ -116,7 +159,15 @@ public: enum NewViewDestination { NewViewInWindow, NewViewInTab, - NewViewInDialog + NewViewInDialog, + NewViewInBackgroundTab + }; + + enum Feature { + MediaAudioCapture, + MediaVideoCapture, + MediaAudioVideoCapture, + Geolocation }; // must match WebContentsAdapterClient::JavaScriptConsoleMessageLevel @@ -126,13 +177,41 @@ public: ErrorMessageLevel }; + enum FindFlag { + FindBackward = 1, + FindCaseSensitively = 2, + }; + Q_DECLARE_FLAGS(FindFlags, FindFlag) + + // QmlParserStatus + virtual void componentComplete() Q_DECL_OVERRIDE; + + QQuickWebEngineProfile *profile() const; + void setProfile(QQuickWebEngineProfile *); + QQmlListProperty<QQuickWebEngineScript> userScripts(); + + QQuickWebEngineSettings *settings() const; + QQmlWebChannel *webChannel(); + void setWebChannel(QQmlWebChannel *); + QQuickWebEngineHistory *navigationHistory() const; + +#ifdef ENABLE_QML_TESTSUPPORT_API + QQuickWebEngineTestSupport *testSupport() const; + void setTestSupport(QQuickWebEngineTestSupport *testSupport); +#endif + public Q_SLOTS: void runJavaScript(const QString&, const QJSValue & = QJSValue()); void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()); void goBack(); void goForward(); + void goBackOrForward(int index); void reload(); + void reloadAndBypassCache(); void stop(); + Q_REVISION(1) void findText(const QString &subString, FindFlags options = 0, const QJSValue &callback = QJSValue()); + Q_REVISION(1) void fullScreenCancelled(); + Q_REVISION(1) void grantFeaturePermission(const QUrl &securityOrigin, Feature, bool granted); Q_SIGNALS: void titleChanged(); @@ -143,6 +222,14 @@ Q_SIGNALS: void linkHovered(const QUrl &hoveredUrl); void navigationRequested(QQuickWebEngineNavigationRequest *request); void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID); + Q_REVISION(1) void certificateError(QQuickWebEngineCertificateError *error); + Q_REVISION(1) void fullScreenRequested(const QQuickWebEngineFullScreenRequest &request); + Q_REVISION(1) void isFullScreenChanged(); + Q_REVISION(1) void featurePermissionRequested(const QUrl &securityOrigin, Feature feature); + Q_REVISION(1) void newViewRequested(QQuickWebEngineNewViewRequest *request); + Q_REVISION(1) void zoomFactorChanged(qreal arg); + Q_REVISION(1) void webChannelChanged(); + protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -163,5 +250,6 @@ private: QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickWebEngineView) +Q_DECLARE_METATYPE(QQuickWebEngineFullScreenRequest) #endif // QQUICKWEBENGINEVIEW_P_H diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 3ab95c64d..edc8c1a92 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** @@ -46,17 +46,21 @@ #include <QtCore/qcompilerdetection.h> #include <QtGui/qaccessibleobject.h> +namespace QtWebEngineCore { class WebContentsAdapter; class UIDelegatesManager; +} QT_BEGIN_NAMESPACE -class QQuickWebEngineHistory; -class QQuickWebEngineNewViewRequest; class QQuickWebEngineView; class QQmlComponent; class QQmlContext; class QQuickWebEngineSettings; +#ifdef ENABLE_QML_TESTSUPPORT_API +class QQuickWebEngineTestSupport; +#endif + class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewport : public QObject { Q_OBJECT Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged) @@ -79,48 +83,13 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewExperimental : public QObjec Q_OBJECT Q_PROPERTY(QQuickWebEngineViewport *viewport READ viewport) Q_PROPERTY(QQmlComponent *extraContextMenuEntriesComponent READ extraContextMenuEntriesComponent WRITE setExtraContextMenuEntriesComponent NOTIFY extraContextMenuEntriesComponentChanged) - Q_PROPERTY(bool inspectable READ inspectable WRITE setInspectable) - Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setIsFullScreen NOTIFY isFullScreenChanged) - Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL) - Q_PROPERTY(QQuickWebEngineSettings *settings READ settings) - Q_ENUMS(Feature) - Q_FLAGS(FindFlags) -public: - enum Feature { - MediaAudioDevices, - MediaVideoDevices, - MediaAudioVideoDevices - }; - - enum FindFlag { - FindBackward = 1, - FindCaseSensitively = 2, - }; - Q_DECLARE_FLAGS(FindFlags, FindFlag) - - bool inspectable() const; - void setInspectable(bool); - void setIsFullScreen(bool fullscreen); - bool isFullScreen() const; QQuickWebEngineViewport *viewport() const; void setExtraContextMenuEntriesComponent(QQmlComponent *); QQmlComponent *extraContextMenuEntriesComponent() const; - QQuickWebEngineHistory *navigationHistory() const; - QQuickWebEngineSettings *settings() const; - -public Q_SLOTS: - void goBackTo(int index); - void goForwardTo(int index); - void findText(const QString&, FindFlags, const QJSValue & = QJSValue()); - void grantFeaturePermission(const QUrl &securityOrigin, Feature, bool granted); Q_SIGNALS: - void newViewRequested(QQuickWebEngineNewViewRequest *request); - void fullScreenRequested(bool fullScreen); - void isFullScreenChanged(); void extraContextMenuEntriesComponentChanged(); - void featurePermissionRequested(const QUrl &securityOrigin, Feature feature); void loadVisuallyCommitted(); private: @@ -132,7 +101,7 @@ private: Q_DECLARE_PUBLIC(QQuickWebEngineView) }; -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewPrivate : public WebContentsAdapterClient +class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewPrivate : public QtWebEngineCore::WebContentsAdapterClient { public: Q_DECLARE_PUBLIC(QQuickWebEngineView) @@ -142,10 +111,10 @@ public: QQuickWebEngineViewExperimental *experimental() const; QQuickWebEngineViewport *viewport() const; - UIDelegatesManager *ui(); + QtWebEngineCore::UIDelegatesManager *ui(); - virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client) Q_DECL_OVERRIDE; - virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client) Q_DECL_OVERRIDE; + virtual QtWebEngineCore::RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) Q_DECL_OVERRIDE; + virtual QtWebEngineCore::RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) Q_DECL_OVERRIDE; virtual void titleChanged(const QString&) Q_DECL_OVERRIDE; virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE; virtual void iconChanged(const QUrl&) Q_DECL_OVERRIDE; @@ -154,18 +123,19 @@ public: virtual void selectionChanged() Q_DECL_OVERRIDE { } virtual QRectF viewportRect() const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; - virtual void loadStarted(const QUrl &provisionalUrl) Q_DECL_OVERRIDE; + virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; virtual void loadVisuallyCommitted() Q_DECL_OVERRIDE; - virtual void loadFinished(bool success, const QUrl &url, int errorCode = 0, const QString &errorDescription = QString()) Q_DECL_OVERRIDE; + virtual void loadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()) Q_DECL_OVERRIDE; virtual void focusContainer() Q_DECL_OVERRIDE; - virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) Q_DECL_OVERRIDE; + virtual void unhandledKeyEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + virtual void adoptNewWindow(QtWebEngineCore::WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) Q_DECL_OVERRIDE; virtual void close() Q_DECL_OVERRIDE; virtual void requestFullScreen(bool) Q_DECL_OVERRIDE; virtual bool isFullScreen() const Q_DECL_OVERRIDE; - virtual bool contextMenuRequested(const WebEngineContextMenuData &) Q_DECL_OVERRIDE; + 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<JavaScriptDialogController>) Q_DECL_OVERRIDE; + virtual void javascriptDialog(QSharedPointer<QtWebEngineCore::JavaScriptDialogController>) Q_DECL_OVERRIDE; virtual void runFileChooser(FileChooserMode, const QString &defaultFileName, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE; virtual void didRunJavaScript(quint64, const QVariant&) Q_DECL_OVERRIDE; virtual void didFetchDocumentMarkup(quint64, const QString&) Q_DECL_OVERRIDE { } @@ -175,32 +145,52 @@ public: virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE; virtual void authenticationRequired(const QUrl&, const QString&, bool, const QString&, QString*, QString*) Q_DECL_OVERRIDE { } virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) Q_DECL_OVERRIDE; + virtual void runMouseLockPermissionRequest(const QUrl &securityOrigin) Q_DECL_OVERRIDE; #ifndef QT_NO_ACCESSIBILITY virtual QObject *accessibilityParentObject() Q_DECL_OVERRIDE; #endif // QT_NO_ACCESSIBILITY - virtual WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; - virtual void allowCertificateError(const QExplicitlySharedDataPointer<CertificateErrorController> &errorController); + virtual QtWebEngineCore::WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; + virtual void allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController); + virtual void runGeolocationPermissionRequest(QUrl const&) Q_DECL_OVERRIDE; + virtual void showValidationMessage(const QRect &anchor, const QString &mainText, const QString &subText) Q_DECL_OVERRIDE; + virtual void hideValidationMessage() Q_DECL_OVERRIDE; + virtual void moveValidationMessage(const QRect &anchor) Q_DECL_OVERRIDE; + + virtual QtWebEngineCore::BrowserContextAdapter *browserContextAdapter() Q_DECL_OVERRIDE; void setDevicePixelRatio(qreal); - void adoptWebContents(WebContentsAdapter *webContents); + void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents); + void setProfile(QQuickWebEngineProfile *profile); + void ensureContentsAdapter(); + + // QQmlListPropertyHelpers + static void userScripts_append(QQmlListProperty<QQuickWebEngineScript> *p, QQuickWebEngineScript *script); + static int userScripts_count(QQmlListProperty<QQuickWebEngineScript> *p); + static QQuickWebEngineScript *userScripts_at(QQmlListProperty<QQuickWebEngineScript> *p, int idx); + static void userScripts_clear(QQmlListProperty<QQuickWebEngineScript> *p); - QExplicitlySharedDataPointer<WebContentsAdapter> adapter; + QExplicitlySharedDataPointer<QtWebEngineCore::WebContentsAdapter> adapter; QScopedPointer<QQuickWebEngineViewExperimental> e; QScopedPointer<QQuickWebEngineViewport> v; QScopedPointer<QQuickWebEngineHistory> m_history; + QQuickWebEngineProfile *m_profile; QScopedPointer<QQuickWebEngineSettings> m_settings; +#ifdef ENABLE_QML_TESTSUPPORT_API + QQuickWebEngineTestSupport *m_testSupport; +#endif QQmlComponent *contextMenuExtraItems; QUrl explicitUrl; QUrl icon; int loadProgress; - bool inspectable; bool m_isFullScreen; bool isLoading; qreal devicePixelRatio; QMap<quint64, QJSValue> m_callbacks; + QList<QSharedPointer<CertificateErrorController> > m_certificateErrorControllers; private: - QScopedPointer<UIDelegatesManager> m_uIDelegatesManager; + QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; + QList<QQuickWebEngineScript *> m_userScripts; qreal m_dpiScale; }; diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp index b179da2fe..1c67e710e 100644 --- a/src/webengine/api/qtwebengineglobal.cpp +++ b/src/webengine/api/qtwebengineglobal.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qtwebengineglobal.h b/src/webengine/api/qtwebengineglobal.h index eddd3847a..ad549fae1 100644 --- a/src/webengine/api/qtwebengineglobal.h +++ b/src/webengine/api/qtwebengineglobal.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** diff --git a/src/webengine/api/qtwebengineglobal_p.h b/src/webengine/api/qtwebengineglobal_p.h index 397898cfe..e929c93ce 100644 --- a/src/webengine/api/qtwebengineglobal_p.h +++ b/src/webengine/api/qtwebengineglobal_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** @@ -10,15 +10,15 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 included in the -** packaging of this file. Please review the following information to +** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** @@ -26,7 +26,7 @@ ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to +** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** |