diff options
Diffstat (limited to 'src/webengine/api')
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 210 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile_p.h | 123 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile_p_p.h | 61 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginesingleton.cpp | 6 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginesingleton_p.h | 3 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 105 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p.h | 12 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 3 |
8 files changed, 511 insertions, 12 deletions
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp new file mode 100644 index 000000000..64d9805d6 --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** 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 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 "qquickwebengineprofile_p.h" + +#include "qquickwebengineprofile_p_p.h" + +#include "browser_context_adapter.h" + +QT_BEGIN_NAMESPACE + +QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext, bool ownsContext) + : m_browserContext(browserContext) +{ + if (ownsContext) + m_browserContextRef = browserContext; +} + +QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate() +{ +} + +QQuickWebEngineProfile::QQuickWebEngineProfile() + : d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false), true)) +{ +} + +QQuickWebEngineProfile::QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *privatePtr) + : d_ptr(privatePtr) +{ +} + +QQuickWebEngineProfile::~QQuickWebEngineProfile() +{ +} + +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(); +} + +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(); +} + +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(); +} + +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(); +} + +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(); +} + +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(); +} + +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(); +} + +int QQuickWebEngineProfile::httpCacheMaxSize() const +{ + const Q_D(QQuickWebEngineProfile); + return d->browserContext()->httpCacheMaxSize(); +} + +void QQuickWebEngineProfile::setHttpCacheMaxSize(int maxSize) +{ + Q_D(QQuickWebEngineProfile); + if (d->browserContext()->httpCacheMaxSize() == maxSize) + return; + d->browserContext()->setHttpCacheMaxSize(maxSize); + emit httpCacheMaxSizeChanged(); +} + +QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile() +{ + static QQuickWebEngineProfile profile(new QQuickWebEngineProfilePrivate(BrowserContextAdapter::defaultContext(), false)); + return &profile; +} + +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..936573e8f --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile_p.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEPROFILE_P_H +#define QQUICKWEBENGINEPROFILE_P_H + +#include <private/qtwebengineglobal_p.h> + +#include <QObject> +#include <QScopedPointer> +#include <QString> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineProfilePrivate; + +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 httpCacheMaxSize READ httpCacheMaxSize WRITE setHttpCacheMaxSize NOTIFY httpCacheMaxSizeChanged 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 httpCacheMaxSize() const; + void setHttpCacheMaxSize(int maxSize); + + static QQuickWebEngineProfile *defaultProfile(); + +signals: + void storageNameChanged(); + void offTheRecordChanged(); + void persistentStoragePathChanged(); + void cachePathChanged(); + void httpUserAgentChanged(); + void httpCacheTypeChanged(); + void persistentCookiesPolicyChanged(); + void httpCacheMaxSizeChanged(); + +private: + Q_DECLARE_PRIVATE(QQuickWebEngineProfile); + QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *); + + 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..d71dcfda9 --- /dev/null +++ b/src/webengine/api/qquickwebengineprofile_p_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINEPROFILE_P_P_H +#define QQUICKWEBENGINEPROFILE_P_P_H + +class BrowserContextAdapter; + +#include <QExplicitlySharedDataPointer> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineProfilePrivate { +public: + QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext, bool ownsContext); + ~QQuickWebEngineProfilePrivate(); + + BrowserContextAdapter *browserContext() const { return m_browserContext; } + +private: + friend class QQuickWebEngineViewPrivate; + BrowserContextAdapter *m_browserContext; + QExplicitlySharedDataPointer<BrowserContextAdapter> m_browserContextRef; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEPROFILE_P_P_H diff --git a/src/webengine/api/qquickwebenginesingleton.cpp b/src/webengine/api/qquickwebenginesingleton.cpp index bf4951f3b..280f5b913 100644 --- a/src/webengine/api/qquickwebenginesingleton.cpp +++ b/src/webengine/api/qquickwebenginesingleton.cpp @@ -37,6 +37,7 @@ #include "qquickwebenginesingleton_p.h" #include "qquickwebenginesettings_p.h" +#include "qquickwebengineprofile_p.h" QT_BEGIN_NAMESPACE @@ -45,4 +46,9 @@ QQuickWebEngineSettings *QQuickWebEngineSingleton::settings() const return QQuickWebEngineSettings::globalSettings(); } +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..3bc1a9700 100644 --- a/src/webengine/api/qquickwebenginesingleton_p.h +++ b/src/webengine/api/qquickwebenginesingleton_p.h @@ -41,14 +41,17 @@ #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/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index dccbb5b9f..0edbc1539 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -44,6 +44,8 @@ #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 "render_widget_host_view_qt_delegate_quick.h" @@ -74,10 +76,11 @@ static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *obje } QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() - : adapter(new WebContentsAdapter) + : adapter(0) , e(new QQuickWebEngineViewExperimental(this)) , v(new QQuickWebEngineViewport(this)) , m_history(new QQuickWebEngineHistory(this)) + , m_profile(QQuickWebEngineProfile::defaultProfile()) , m_settings(new QQuickWebEngineSettings) , contextMenuExtraItems(0) , loadProgress(0) @@ -411,7 +414,7 @@ QObject *QQuickWebEngineViewPrivate::accessibilityParentObject() BrowserContextAdapter *QQuickWebEngineViewPrivate::browserContextAdapter() { - return BrowserContextAdapter::defaultContext(); + return m_profile->d_ptr->browserContext(); } WebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const @@ -506,7 +509,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); @@ -518,10 +520,21 @@ QQuickWebEngineView::~QQuickWebEngineView() { } +void QQuickWebEngineViewPrivate::ensureContentsAdapter() +{ + if (!adapter) { + adapter = new WebContentsAdapter(); + adapter->initialize(this); + adapter->enableInspector(inspectable); + if (explicitUrl.isValid()) + adapter->load(explicitUrl); + } +} + 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) @@ -531,7 +544,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 @@ -543,36 +559,50 @@ 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::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())) @@ -581,6 +611,31 @@ void QQuickWebEngineView::setZoomFactor(qreal arg) 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); +} + +void QQuickWebEngineViewPrivate::setProfile(QQuickWebEngineProfile *profile) +{ + m_profile = profile; + 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); + } +} + void QQuickWebEngineViewPrivate::didRunJavaScript(quint64 requestId, const QVariant &result) { Q_Q(QQuickWebEngineView); @@ -613,24 +668,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); @@ -647,6 +710,8 @@ QQuickWebEngineViewExperimental *QQuickWebEngineView::experimental() const qreal QQuickWebEngineView::zoomFactor() const { Q_D(const QQuickWebEngineView); + if (!d->adapter) + return 1.0; return d->adapter->currentZoomFactor(); } @@ -660,6 +725,8 @@ void QQuickWebEngineViewExperimental::setInspectable(bool enable) { Q_D(QQuickWebEngineView); d->inspectable = enable; + if (!d->adapter) + return; d->adapter->enableInspector(enable); } @@ -694,17 +761,20 @@ QQuickWebEngineSettings *QQuickWebEngineViewExperimental::settings() const void QQuickWebEngineViewExperimental::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); } } @@ -715,6 +785,8 @@ QQuickWebEngineHistory *QQuickWebEngineViewExperimental::navigationHistory() con void QQuickWebEngineViewExperimental::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineViewExperimental::Feature feature, bool granted) { + if (!d_ptr->adapter) + return; if (!granted && feature >= MediaAudioCapture && feature <= MediaAudioVideoCapture) { d_ptr->adapter->grantMediaAccessPermission(securityOrigin, WebContentsAdapterClient::MediaNone); return; @@ -740,6 +812,8 @@ void QQuickWebEngineViewExperimental::grantFeaturePermission(const QUrl &securit void QQuickWebEngineViewExperimental::goBackTo(int index) { + if (!d_ptr->adapter) + return; int count = d_ptr->adapter->currentNavigationEntryIndex(); if (index < 0 || index >= count) return; @@ -749,6 +823,8 @@ void QQuickWebEngineViewExperimental::goBackTo(int index) void QQuickWebEngineViewExperimental::goForwardTo(int index) { + if (!d_ptr->adapter) + return; int count = d_ptr->adapter->navigationEntryCount() - d_ptr->adapter->currentNavigationEntryIndex() - 1; if (index < 0 || index >= count) return; @@ -768,7 +844,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 @@ -777,6 +853,13 @@ void QQuickWebEngineView::itemChange(ItemChange change, const ItemChangeData &va QQuickItem::itemChange(change, value); } +void QQuickWebEngineView::componentComplete() +{ + Q_D(QQuickWebEngineView); + QQuickItem::componentComplete(); + d->ensureContentsAdapter(); +} + QQuickWebEngineViewExperimental::QQuickWebEngineViewExperimental(QQuickWebEngineViewPrivate *viewPrivate) : q_ptr(0) , d_ptr(viewPrivate) @@ -808,6 +891,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 9f6493022..f3ef133ae 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -42,10 +42,11 @@ QT_BEGIN_NAMESPACE -class QQuickWebEngineViewExperimental; -class QQuickWebEngineViewPrivate; class QQuickWebEngineLoadRequest; class QQuickWebEngineNavigationRequest; +class QQuickWebEngineProfile; +class QQuickWebEngineViewExperimental; +class QQuickWebEngineViewPrivate; class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_OBJECT @@ -57,6 +58,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY urlChanged) Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY urlChanged) Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile FINAL) Q_ENUMS(NavigationRequestAction); Q_ENUMS(NavigationType); Q_ENUMS(LoadStatus); @@ -129,6 +131,12 @@ public: ErrorMessageLevel }; + // QmlParserStatus + virtual void componentComplete() Q_DECL_OVERRIDE; + + QQuickWebEngineProfile *profile() const; + void setProfile(QQuickWebEngineProfile *); + public Q_SLOTS: void runJavaScript(const QString&, const QJSValue & = QJSValue()); void loadHtml(const QString &html, const QUrl &baseUrl = QUrl()); diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 46388bfbb..ea9d853ae 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -185,11 +185,14 @@ public: void setDevicePixelRatio(qreal); void adoptWebContents(WebContentsAdapter *webContents); + void setProfile(QQuickWebEngineProfile *profile); + void ensureContentsAdapter(); QExplicitlySharedDataPointer<WebContentsAdapter> adapter; QScopedPointer<QQuickWebEngineViewExperimental> e; QScopedPointer<QQuickWebEngineViewport> v; QScopedPointer<QQuickWebEngineHistory> m_history; + QQuickWebEngineProfile *m_profile; QScopedPointer<QQuickWebEngineSettings> m_settings; QQmlComponent *contextMenuExtraItems; QUrl explicitUrl; |