From bec2be57891f87f2b8bc046bb212be4788f96033 Mon Sep 17 00:00:00 2001
From: Szabolcs David <davidsz@inf.u-szeged.hu>
Date: Wed, 1 Jun 2016 08:56:09 -0700
Subject: [PATCH] Make QQuickWebEngineScript a publicly exported class

Now the users can create user scripts when they are working
with QQuickWebEngineProfiles in C++.

Change-Id: I6ada78b1fc44c3f93589eb468578c330a1be9c6f
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
---
 src/webengine/api/qquickwebengineprofile.cpp  |   4 +-
 src/webengine/api/qquickwebenginescript.cpp   | 171 +++++++++++++++---
 src/webengine/api/qquickwebenginescript.h     | 114 ++++++++++++
 src/webengine/api/qquickwebenginescript_p.h   |  83 +++------
 src/webengine/api/qquickwebenginescript_p_p.h |  87 ---------
 src/webengine/api/qquickwebengineview.cpp     |   2 +-
 src/webengine/api/qquickwebengineview_p.h     |   2 +-
 src/webengine/webengine.pro                   |   1 +
 tests/auto/quick/publicapi/tst_publicapi.cpp  |   2 +-
 9 files changed, 285 insertions(+), 181 deletions(-)
 create mode 100644 src/webengine/api/qquickwebenginescript.h
 delete mode 100644 src/webengine/api/qquickwebenginescript_p_p.h

diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index c88c7faf8..162dbe1d7 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -42,7 +42,7 @@
 #include "qquickwebenginedownloaditem_p.h"
 #include "qquickwebenginedownloaditem_p_p.h"
 #include "qquickwebengineprofile_p.h"
-#include "qquickwebenginescript_p_p.h"
+#include "qquickwebenginescript_p.h"
 #include "qquickwebenginesettings_p.h"
 #include "qwebenginecookiestore.h"
 
@@ -901,6 +901,8 @@ QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
 
     \brief the collection of scripts that are injected into all pages that share
     this profile.
+
+    \sa QQuickWebEngineScript, QQmlListReference
 */
 QQmlListProperty<QQuickWebEngineScript> QQuickWebEngineProfile::userScripts()
 {
diff --git a/src/webengine/api/qquickwebenginescript.cpp b/src/webengine/api/qquickwebenginescript.cpp
index 5d5173144..590faf4f3 100644
--- a/src/webengine/api/qquickwebenginescript.cpp
+++ b/src/webengine/api/qquickwebenginescript.cpp
@@ -37,8 +37,8 @@
 **
 ****************************************************************************/
 
+#include "qquickwebenginescript.h"
 #include "qquickwebenginescript_p.h"
-#include "qquickwebenginescript_p_p.h"
 
 #include <QQmlFile>
 #include <QtCore/QDebug>
@@ -48,6 +48,58 @@
 
 using QtWebEngineCore::UserScript;
 
+QT_BEGIN_NAMESPACE
+
+/*!
+    \class QQuickWebEngineScript
+    \brief Enables the injection of scripts in the JavaScript engine.
+    \inmodule QtWebEngine
+    \since 5.9
+
+    The QQuickWebEngineScript type enables the programmatic injection of so called \e {user scripts} in
+    the JavaScript engine at different points, determined by injectionPoint, during the loading of
+    web content.
+
+    Scripts can be executed either in the main JavaScript \e world, along with the rest of the
+    JavaScript coming from the web contents, or in their own isolated world. While the DOM of the
+    page can be accessed from any world, JavaScript variables of a function defined in one world are
+    not accessible from a different one. The worldId property provides some predefined IDs for this
+    purpose.
+*/
+
+/*!
+    \enum QQuickWebEngineScript::InjectionPoint
+
+    The point in the loading process at which the script will be executed.
+
+    \value DocumentCreation
+           The script will be executed as soon as the document is created. This is not suitable for
+           any DOM operation.
+    \value DocumentReady
+           The script will run as soon as the DOM is ready. This is equivalent to the
+           \c DOMContentLoaded event firing in JavaScript.
+    \value Deferred
+           The script will run when the page load finishes, or 500 ms after the document is ready,
+           whichever comes first.
+*/
+
+/*!
+    \enum QQuickWebEngineScript::ScriptWorldId
+
+    The world ID defining which isolated world the script is executed in.
+
+    \value MainWorld
+           The world used by the page's web contents. It can be useful in order to expose custom
+           functionality to web contents in certain scenarios.
+    \value ApplicationWorld
+           The default isolated world used for application level functionality implemented in
+           JavaScript.
+    \value UserWorld
+           The first isolated world to be used by scripts set by users if the application is not
+           making use of more worlds. As a rule of thumb, if that functionality is exposed to the
+           application users, each individual script should probably get its own isolated world.
+*/
+
 /*!
     \qmltype WebEngineScript
     \instantiates QQuickWebEngineScript
@@ -72,16 +124,26 @@ using QtWebEngineCore::UserScript;
     attached to the web view.
 */
 
-QQuickWebEngineScript::QQuickWebEngineScript()
-    : d_ptr(new QQuickWebEngineScriptPrivate)
+/*!
+    Constructs a new QQuickWebEngineScript with the parent \a parent.
+*/
+QQuickWebEngineScript::QQuickWebEngineScript(QObject *parent)
+    : QObject(parent)
+    , d_ptr(new QQuickWebEngineScriptPrivate)
 {
     d_ptr->q_ptr = this;
 }
 
+/*!
+   \internal
+*/
 QQuickWebEngineScript::~QQuickWebEngineScript()
 {
 }
 
+/*!
+    Returns the script object as string.
+*/
 QString QQuickWebEngineScript::toString() const
 {
     Q_D(const QQuickWebEngineScript);
@@ -105,6 +167,14 @@ QString QQuickWebEngineScript::toString() const
     return ret;
 }
 
+/*!
+    \property QQuickWebEngineScript::name
+    \brief The name of the script.
+
+    Can be useful to retrieve a particular script from
+    QQuickWebEngineProfile::userScripts.
+*/
+
 /*!
     \qmlproperty string WebEngineScript::name
 
@@ -117,6 +187,20 @@ QString QQuickWebEngineScript::name() const
     return d->coreScript.name();
 }
 
+/*!
+    \property QQuickWebEngineScript::sourceUrl
+    \brief 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 QQuickWebEngineScript::sourceCode
+*/
+
 /*!
     \qmlproperty url WebEngineScript::sourceUrl
 
@@ -137,6 +221,13 @@ QUrl QQuickWebEngineScript::sourceUrl() const
     return d->m_sourceUrl;
 }
 
+/*!
+    \property QQuickWebEngineScript::sourceCode
+    \brief The JavaScript source code of the user script.
+
+    \sa QQuickWebEngineScript::sourceUrl
+*/
+
 /*!
     \qmlproperty string WebEngineScript::sourceCode
 
@@ -154,6 +245,13 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineScript::Deferred, UserScript::AfterLoad)
 ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentReady, UserScript::DocumentLoadFinished)
 ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentCreation, UserScript::DocumentElementCreation)
 
+/*!
+    \property QQuickWebEngineScript::injectionPoint
+    \brief  The point in the loading process at which the script will be executed.
+
+    The default value is \c Deferred.
+*/
+
 /*!
     \qmlproperty enumeration WebEngineScript::injectionPoint
 
@@ -176,6 +274,11 @@ QQuickWebEngineScript::InjectionPoint QQuickWebEngineScript::injectionPoint() co
     return static_cast<QQuickWebEngineScript::InjectionPoint>(d->coreScript.injectionPoint());
 }
 
+/*!
+    \property QQuickWebEngineScript::worldId
+    \brief The world ID defining which isolated world the script is executed in.
+*/
+
 /*!
     \qmlproperty enumeration WebEngineScript::worldId
 
@@ -198,6 +301,15 @@ QQuickWebEngineScript::ScriptWorldId QQuickWebEngineScript::worldId() const
     return static_cast<QQuickWebEngineScript::ScriptWorldId>(d->coreScript.worldId());
 }
 
+/*!
+    \property QQuickWebEngineScript::runOnSubframes
+    \brief Whether the script is executed on every frame or only on the main frame.
+
+    Set this property to \c true if the script is executed on every frame in the page, or \c false
+    if it is only run for the main frame.
+    The default value is \c{false}.
+*/
+
 /*!
     \qmlproperty int WebEngineScript::runOnSubframes
 
@@ -211,21 +323,20 @@ bool QQuickWebEngineScript::runOnSubframes() const
     return d->coreScript.runsOnSubFrames();
 }
 
-
-void QQuickWebEngineScript::setName(QString arg)
+void QQuickWebEngineScript::setName(const QString &name)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == name())
+    if (name == QQuickWebEngineScript::name())
         return;
     d->aboutToUpdateUnderlyingScript();
-    d->coreScript.setName(arg);
-    Q_EMIT nameChanged(arg);
+    d->coreScript.setName(name);
+    Q_EMIT nameChanged(name);
 }
 
-void QQuickWebEngineScript::setSourceCode(QString arg)
+void QQuickWebEngineScript::setSourceCode(const QString &code)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == sourceCode())
+    if (code == sourceCode())
         return;
 
     // setting the source directly resets the sourceUrl
@@ -235,22 +346,22 @@ void QQuickWebEngineScript::setSourceCode(QString arg)
     }
 
     d->aboutToUpdateUnderlyingScript();
-    d->coreScript.setSourceCode(arg);
-    Q_EMIT sourceCodeChanged(arg);
+    d->coreScript.setSourceCode(code);
+    Q_EMIT sourceCodeChanged(code);
 }
 
-void QQuickWebEngineScript::setSourceUrl(QUrl arg)
+void QQuickWebEngineScript::setSourceUrl(const QUrl &url)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == sourceUrl())
+    if (url == sourceUrl())
         return;
 
-    d->m_sourceUrl = arg;
+    d->m_sourceUrl = url;
     Q_EMIT sourceUrlChanged(d->m_sourceUrl);
 
-    QFile f(QQmlFile::urlToLocalFileOrQrc(arg));
+    QFile f(QQmlFile::urlToLocalFileOrQrc(url));
     if (!f.open(QIODevice::ReadOnly)) {
-        qWarning() << "Can't open user script " << arg;
+        qWarning() << "Can't open user script " << url;
         return;
     }
 
@@ -260,36 +371,36 @@ void QQuickWebEngineScript::setSourceUrl(QUrl arg)
     Q_EMIT sourceCodeChanged(source);
 }
 
-void QQuickWebEngineScript::setInjectionPoint(QQuickWebEngineScript::InjectionPoint arg)
+void QQuickWebEngineScript::setInjectionPoint(QQuickWebEngineScript::InjectionPoint injectionPoint)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == injectionPoint())
+    if (injectionPoint == QQuickWebEngineScript::injectionPoint())
         return;
     d->aboutToUpdateUnderlyingScript();
-    d->coreScript.setInjectionPoint(static_cast<UserScript::InjectionPoint>(arg));
-    Q_EMIT injectionPointChanged(arg);
+    d->coreScript.setInjectionPoint(static_cast<UserScript::InjectionPoint>(injectionPoint));
+    Q_EMIT injectionPointChanged(injectionPoint);
 }
 
 
-void QQuickWebEngineScript::setWorldId(QQuickWebEngineScript::ScriptWorldId arg)
+void QQuickWebEngineScript::setWorldId(QQuickWebEngineScript::ScriptWorldId scriptWorldId)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == worldId())
+    if (scriptWorldId == worldId())
         return;
     d->aboutToUpdateUnderlyingScript();
-    d->coreScript.setWorldId(arg);
-    Q_EMIT worldIdChanged(arg);
+    d->coreScript.setWorldId(scriptWorldId);
+    Q_EMIT worldIdChanged(scriptWorldId);
 }
 
 
-void QQuickWebEngineScript::setRunOnSubframes(bool arg)
+void QQuickWebEngineScript::setRunOnSubframes(bool on)
 {
     Q_D(QQuickWebEngineScript);
-    if (arg == runOnSubframes())
+    if (on == runOnSubframes())
         return;
     d->aboutToUpdateUnderlyingScript();
-    d->coreScript.setRunsOnSubFrames(arg);
-    Q_EMIT runOnSubframesChanged(arg);
+    d->coreScript.setRunsOnSubFrames(on);
+    Q_EMIT runOnSubframesChanged(on);
 }
 
 void QQuickWebEngineScript::timerEvent(QTimerEvent *e)
@@ -327,3 +438,5 @@ void QQuickWebEngineScriptPrivate::aboutToUpdateUnderlyingScript()
    // Defer updates to the next event loop
    m_basicTimer.start(0, q);
 }
+
+QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginescript.h b/src/webengine/api/qquickwebenginescript.h
new file mode 100644
index 000000000..2cd4fadf1
--- /dev/null
+++ b/src/webengine/api/qquickwebenginescript.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWEBENGINESCRIPT_H
+#define QQUICKWEBENGINESCRIPT_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qurl.h>
+#include <QtWebEngine/qtwebengineglobal.h>
+
+QT_BEGIN_NAMESPACE
+class QQuickWebEngineScriptPrivate;
+class QQuickWebEngineView;
+
+class Q_WEBENGINE_EXPORT QQuickWebEngineScript : public QObject
+{
+    Q_OBJECT
+    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
+    };
+    Q_ENUM(InjectionPoint)
+
+    enum ScriptWorldId {
+        MainWorld = 0,
+        ApplicationWorld,
+        UserWorld
+    };
+    Q_ENUM(ScriptWorldId)
+
+    QQuickWebEngineScript(QObject *parent = Q_NULLPTR);
+    ~QQuickWebEngineScript();
+    Q_INVOKABLE QString toString() const;
+
+    QString name() const;
+    QUrl sourceUrl() const;
+    QString sourceCode() const;
+    InjectionPoint injectionPoint() const;
+    ScriptWorldId worldId() const;
+    bool runOnSubframes() const;
+
+    void setName(const QString &name);
+    void setSourceUrl(const QUrl &url);
+    void setSourceCode(const QString &code);
+    void setInjectionPoint(InjectionPoint injectionPoint);
+    void setWorldId(ScriptWorldId scriptWorldId);
+    void setRunOnSubframes(bool on);
+
+Q_SIGNALS:
+    void nameChanged(const QString &name);
+    void sourceUrlChanged(const QUrl &url);
+    void sourceCodeChanged(const QString &code);
+    void injectionPointChanged(InjectionPoint injectionPoint);
+    void worldIdChanged(ScriptWorldId scriptWorldId);
+    void runOnSubframesChanged(bool on);
+
+protected:
+    void timerEvent(QTimerEvent *e) override;
+
+private:
+    friend class QQuickWebEngineProfilePrivate;
+    friend class QQuickWebEngineViewPrivate;
+    Q_DECLARE_PRIVATE(QQuickWebEngineScript)
+    QScopedPointer<QQuickWebEngineScriptPrivate> d_ptr;
+};
+QT_END_NAMESPACE
+
+#endif // QQUICKWEBENGINESCRIPT_H
diff --git a/src/webengine/api/qquickwebenginescript_p.h b/src/webengine/api/qquickwebenginescript_p.h
index c4368f1d5..30b47a654 100644
--- a/src/webengine/api/qquickwebenginescript_p.h
+++ b/src/webengine/api/qquickwebenginescript_p.h
@@ -51,76 +51,37 @@
 // We mean it.
 //
 
-#include <private/qtwebengineglobal_p.h>
-#include <QtCore/QObject>
-#include <QtCore/QUrl>
+#include "qquickwebenginescript.h"
 
-QT_BEGIN_NAMESPACE
-class QQuickWebEngineScriptPrivate;
-class QQuickWebEngineView;
+#include <QtCore/QBasicTimer>
+#include "user_script.h"
+#include "web_contents_adapter.h"
 
-class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineScript : public QObject
-{
-    Q_OBJECT
-    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
-    Q_PROPERTY(QUrl sourceUrl READ sourceUrl WRITE setSourceUrl NOTIFY sourceUrlChanged FINAL)
-    Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged FINAL)
-    Q_PROPERTY(InjectionPoint injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged FINAL)
-    Q_PROPERTY(ScriptWorldId worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged FINAL)
-    Q_PROPERTY(bool runOnSubframes READ runOnSubframes WRITE setRunOnSubframes NOTIFY runOnSubframesChanged FINAL)
+namespace QtWebEngineCore {
+class UserResourceControllerHost;
+class WebContentsAdapter;
+} // namespace
 
+QT_BEGIN_NAMESPACE
 
+class QQuickWebEngineScriptPrivate {
 public:
-    enum InjectionPoint {
-        Deferred,
-        DocumentReady,
-        DocumentCreation
-    };
-    Q_ENUM(InjectionPoint)
-
-    enum ScriptWorldId {
-        MainWorld = 0,
-        ApplicationWorld,
-        UserWorld
-    };
-    Q_ENUM(ScriptWorldId)
-
-    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;
+    Q_DECLARE_PUBLIC(QQuickWebEngineScript)
+    QQuickWebEngineScriptPrivate();
+    void aboutToUpdateUnderlyingScript();
+    void bind(QtWebEngineCore::UserResourceControllerHost *, QtWebEngineCore::WebContentsAdapter * = 0);
 
-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;
+    QtWebEngineCore::UserScript coreScript;
+    QBasicTimer m_basicTimer;
+    QtWebEngineCore::UserResourceControllerHost *m_controllerHost;
+    QtWebEngineCore::WebContentsAdapter *m_adapter;
+    QUrl m_sourceUrl;
 
 private:
-    friend class QQuickWebEngineProfilePrivate;
-    friend class QQuickWebEngineViewPrivate;
-    Q_DECLARE_PRIVATE(QQuickWebEngineScript)
-    QScopedPointer<QQuickWebEngineScriptPrivate> d_ptr;
+    QQuickWebEngineScript *q_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
deleted file mode 100644
index 4525505c6..000000000
--- a/src/webengine/api/qquickwebenginescript_p_p.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKWEBENGINESCRIPT_P_P_H
-#define QQUICKWEBENGINESCRIPT_P_P_H
-
-//
-//  W A R N I N G
-//  -------------
-//
-// This file is not part of the Qt API.  It exists purely as an
-// implementation detail.  This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qquickwebenginescript_p.h"
-
-#include <QtCore/QBasicTimer>
-#include "user_script.h"
-#include "web_contents_adapter.h"
-
-namespace QtWebEngineCore {
-class UserResourceControllerHost;
-class WebContentsAdapter;
-} // namespace
-
-QT_BEGIN_NAMESPACE
-
-class QQuickWebEngineScriptPrivate {
-public:
-    Q_DECLARE_PUBLIC(QQuickWebEngineScript)
-    QQuickWebEngineScriptPrivate();
-    void aboutToUpdateUnderlyingScript();
-    void bind(QtWebEngineCore::UserResourceControllerHost *, QtWebEngineCore::WebContentsAdapter * = 0);
-
-    QtWebEngineCore::UserScript coreScript;
-    QBasicTimer m_basicTimer;
-    QtWebEngineCore::UserResourceControllerHost *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/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index a19f0be53..b543d27b1 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -55,7 +55,7 @@
 #include "qquickwebenginenewviewrequest_p.h"
 #include "qquickwebengineprofile_p.h"
 #include "qquickwebenginesettings_p.h"
-#include "qquickwebenginescript_p_p.h"
+#include "qquickwebenginescript_p.h"
 
 #ifdef ENABLE_QML_TESTSUPPORT_API
 #include "qquickwebenginetestsupport_p.h"
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 27224fadd..92eb5d7de 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -52,7 +52,7 @@
 //
 
 #include <private/qtwebengineglobal_p.h>
-#include "qquickwebenginescript_p.h"
+#include "qquickwebenginescript.h"
 #include <QQuickItem>
 #include <QtGui/qcolor.h>
 
diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro
index 5fa49c77e..27239225b 100644
--- a/src/webengine/webengine.pro
+++ b/src/webengine/webengine.pro
@@ -45,6 +45,7 @@ HEADERS = \
         api/qquickwebenginenewviewrequest_p.h \
         api/qquickwebengineprofile.h \
         api/qquickwebengineprofile_p.h \
+        api/qquickwebenginescript.h \
         api/qquickwebenginescript_p.h \
         api/qquickwebenginesettings_p.h \
         api/qquickwebenginesingleton_p.h \
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index f9fd854cc..5cc0d18df 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -34,6 +34,7 @@
 #include <QQmlListProperty>
 #include <QtTest/QtTest>
 #include <QtWebEngine/QQuickWebEngineProfile>
+#include <QtWebEngine/QQuickWebEngineScript>
 #include <private/qquickwebengineview_p.h>
 #include <private/qquickwebenginecertificateerror_p.h>
 #include <private/qquickwebenginedialogrequests_p.h>
@@ -42,7 +43,6 @@
 #include <private/qquickwebengineloadrequest_p.h>
 #include <private/qquickwebenginenavigationrequest_p.h>
 #include <private/qquickwebenginenewviewrequest_p.h>
-#include <private/qquickwebenginescript_p.h>
 #include <private/qquickwebenginesettings_p.h>
 #include <private/qquickwebenginesingleton_p.h>
 #include <private/qquickwebenginecontextmenurequest_p.h>
-- 
GitLab