From e01dc0556f72da94e8a310959f3ad0471d063bcb Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Wed, 1 Jun 2016 08:54:03 -0700 Subject: Add profile-wide user scripts to the Quick API Add API tests in order to try how it works in C++ and QML. Task-number: QTBUG-51034 Change-Id: I1680297e2dafba39dbd4b161f0dbdb14fb6d4243 Reviewed-by: Allan Sandfeld Jensen --- src/webengine/api/qquickwebengineprofile.cpp | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/webengine/api/qquickwebengineprofile.cpp') diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 871428f33..c88c7faf8 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -42,6 +42,7 @@ #include "qquickwebenginedownloaditem_p.h" #include "qquickwebenginedownloaditem_p_p.h" #include "qquickwebengineprofile_p.h" +#include "qquickwebenginescript_p_p.h" #include "qquickwebenginesettings_p.h" #include "qwebenginecookiestore.h" @@ -49,6 +50,7 @@ #include "browser_context_adapter.h" #include +#include "renderer_host/user_resource_controller_host.h" #include "web_engine_settings.h" using QtWebEngineCore::BrowserContextAdapter; @@ -229,6 +231,38 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info } } +void QQuickWebEngineProfilePrivate::userScripts_append(QQmlListProperty *p, QQuickWebEngineScript *script) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineProfilePrivate *d = static_cast(p->data); + QtWebEngineCore::UserResourceControllerHost *resourceController = d->browserContext()->userResourceController(); + d->m_userScripts.append(script); + script->d_func()->bind(resourceController); +} + +int QQuickWebEngineProfilePrivate::userScripts_count(QQmlListProperty *p) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineProfilePrivate *d = static_cast(p->data); + return d->m_userScripts.count(); +} + +QQuickWebEngineScript *QQuickWebEngineProfilePrivate::userScripts_at(QQmlListProperty *p, int idx) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineProfilePrivate *d = static_cast(p->data); + return d->m_userScripts.at(idx); +} + +void QQuickWebEngineProfilePrivate::userScripts_clear(QQmlListProperty *p) +{ + Q_ASSERT(p && p->data); + QQuickWebEngineProfilePrivate *d = static_cast(p->data); + QtWebEngineCore::UserResourceControllerHost *resourceController = d->browserContext()->userResourceController(); + resourceController->clearAllScripts(NULL); + d->m_userScripts.clear(); +} + /*! \qmltype WebEngineProfile \instantiates QQuickWebEngineProfile @@ -851,4 +885,31 @@ QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const return d->settings(); } +/*! + \qmlproperty list WebEngineProfile::userScripts + \since 1.5 + + Returns the collection of WebEngineScripts that are injected into all pages that share + this profile. + + \sa WebEngineScript +*/ + +/*! + \property QQuickWebEngineProfile::userScripts + \since 5.9 + + \brief the collection of scripts that are injected into all pages that share + this profile. +*/ +QQmlListProperty QQuickWebEngineProfile::userScripts() +{ + Q_D(QQuickWebEngineProfile); + return QQmlListProperty(this, d, + d->userScripts_append, + d->userScripts_count, + d->userScripts_at, + d->userScripts_clear); +} + QT_END_NAMESPACE -- cgit v1.2.3