diff options
author | Michal Klocek <michal.klocek@qt.io> | 2020-08-25 11:37:34 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2020-09-24 15:14:59 +0200 |
commit | f613095208911cfa6b8609f8b87b4984dc55e69c (patch) | |
tree | 09a25473d27a2b7d174966fb28594c07de8db510 /src/core/api/qwebenginescript.cpp | |
parent | e2e249b8bb399ef7bcf6fe3be0b4f2fc9fa18182 (diff) | |
download | qtwebengine-f613095208911cfa6b8609f8b87b4984dc55e69c.tar.gz |
Reuse qwebenginescript in qml
Reuse core class and adopt api:
* add missing setUrlSource to c++ class
* fix typing for setRunsOnSubFrames
* remove all invokable from setters in qml,
we use properties for that anyway.
* remove invokable toString , since we have debug
stream operator in c++
[ChangeLog] In qml websetttings.runOnSubframes is now
websettings.runsOnSubFrames
Change-Id: Iba822a7aa6a59940484c972726d710a1b66cb20d
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/api/qwebenginescript.cpp')
-rw-r--r-- | src/core/api/qwebenginescript.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/api/qwebenginescript.cpp b/src/core/api/qwebenginescript.cpp index e56017166..e3917566a 100644 --- a/src/core/api/qwebenginescript.cpp +++ b/src/core/api/qwebenginescript.cpp @@ -41,9 +41,12 @@ #include "user_script.h" #include <QtCore/QDebug> +#include <QtCore/QFile> using QtWebEngineCore::UserScript; +QT_BEGIN_NAMESPACE + /*! \class QWebEngineScript \inmodule QtWebEngineCore @@ -172,6 +175,37 @@ void QWebEngineScript::setName(const QString &scriptName) d->setName(scriptName); } + +QUrl QWebEngineScript::sourceUrl() const +{ + return d->sourceUrl(); +} + +void QWebEngineScript::setSourceUrl(const QUrl &url) +{ + if (url == sourceUrl()) + return; + + d->setSourceUrl(url); + + QFile file; + if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) { + if (url.authority().isEmpty()) + file.setFileName(QLatin1Char(':') + url.path()); + return; + } else { + file.setFileName(url.toLocalFile()); + } + + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Can't open user script " << url; + return; + } + + QString source = QString::fromUtf8(file.readAll()); + setSourceCode(source); +} + /*! Returns the source of the script. */ @@ -291,3 +325,5 @@ QDebug operator<<(QDebug d, const QWebEngineScript &script) return d.space(); } #endif + +QT_END_NAMESPACE |