mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Merge branch 'Falkon/3.1'
This commit is contained in:
commit
3137cdfca2
|
@ -30,6 +30,7 @@ class QmlExtensionSchemeHandler;
|
||||||
class QmlExtensionScheme : public QObject, public QQmlParserStatus
|
class QmlExtensionScheme : public QObject, public QQmlParserStatus
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(QQmlParserStatus)
|
||||||
/**
|
/**
|
||||||
* @brief extension scheme handle name
|
* @brief extension scheme handle name
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,12 +16,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmluserscript.h"
|
#include "qmluserscript.h"
|
||||||
|
#include "../../qmlstaticdata.h"
|
||||||
|
|
||||||
QmlUserScript::QmlUserScript(QObject *parent)
|
QmlUserScript::QmlUserScript(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QmlUserScript::~QmlUserScript()
|
||||||
|
{
|
||||||
|
QmlStaticData::instance().getUserScriptsSingleton()->remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
QWebEngineScript QmlUserScript::webEngineScript() const
|
QWebEngineScript QmlUserScript::webEngineScript() const
|
||||||
{
|
{
|
||||||
return m_webEngineScript;
|
return m_webEngineScript;
|
||||||
|
@ -46,6 +52,7 @@ void QmlUserScript::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_webEngineScript.setName(name);
|
m_webEngineScript.setName(name);
|
||||||
emit nameChanged(name);
|
emit nameChanged(name);
|
||||||
|
aboutToUpdateUnderlyingScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlUserScript::runsOnSubFrames() const
|
bool QmlUserScript::runsOnSubFrames() const
|
||||||
|
@ -57,6 +64,7 @@ void QmlUserScript::setRunsOnSubFrames(bool runsOnSubFrames)
|
||||||
{
|
{
|
||||||
m_webEngineScript.setRunsOnSubFrames(runsOnSubFrames);
|
m_webEngineScript.setRunsOnSubFrames(runsOnSubFrames);
|
||||||
emit runsOnSubFramesChanged(runsOnSubFrames);
|
emit runsOnSubFramesChanged(runsOnSubFrames);
|
||||||
|
aboutToUpdateUnderlyingScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QmlUserScript::worldId() const
|
int QmlUserScript::worldId() const
|
||||||
|
@ -80,6 +88,7 @@ void QmlUserScript::setWorldId(int worldId)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emit worldIdChanged(worldId);
|
emit worldIdChanged(worldId);
|
||||||
|
aboutToUpdateUnderlyingScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlUserScript::sourceCode() const
|
QString QmlUserScript::sourceCode() const
|
||||||
|
@ -91,6 +100,7 @@ void QmlUserScript::setSourceCode(const QString &sourceCode)
|
||||||
{
|
{
|
||||||
m_webEngineScript.setSourceCode(sourceCode);
|
m_webEngineScript.setSourceCode(sourceCode);
|
||||||
emit sourceCodeChanged(sourceCode);
|
emit sourceCodeChanged(sourceCode);
|
||||||
|
aboutToUpdateUnderlyingScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlUserScript::InjectionPoint QmlUserScript::injectionPoint() const
|
QmlUserScript::InjectionPoint QmlUserScript::injectionPoint() const
|
||||||
|
@ -114,4 +124,24 @@ void QmlUserScript::setInjectionPoint(InjectionPoint injectionPoint)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emit injectionPointChanged(injectionPoint);
|
emit injectionPointChanged(injectionPoint);
|
||||||
|
aboutToUpdateUnderlyingScript();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScript::timerEvent(QTimerEvent *e)
|
||||||
|
{
|
||||||
|
if (e->timerId() != m_basicTimer.timerId()) {
|
||||||
|
QObject::timerEvent(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_basicTimer.stop();
|
||||||
|
QmlStaticData::instance().getUserScriptsSingleton()->insert(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlUserScript::aboutToUpdateUnderlyingScript()
|
||||||
|
{
|
||||||
|
if (!m_basicTimer.isActive()) {
|
||||||
|
QmlStaticData::instance().getUserScriptsSingleton()->remove(this);
|
||||||
|
}
|
||||||
|
// Defer updates to the next event loop
|
||||||
|
m_basicTimer.start(0, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QBasicTimer>
|
||||||
#include <QWebEngineScript>
|
#include <QWebEngineScript>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +74,7 @@ public:
|
||||||
Q_ENUM(ScriptWorldId)
|
Q_ENUM(ScriptWorldId)
|
||||||
|
|
||||||
explicit QmlUserScript(QObject *parent = nullptr);
|
explicit QmlUserScript(QObject *parent = nullptr);
|
||||||
|
~QmlUserScript();
|
||||||
QWebEngineScript webEngineScript() const;
|
QWebEngineScript webEngineScript() const;
|
||||||
void setWebEngineScript(const QWebEngineScript &script);
|
void setWebEngineScript(const QWebEngineScript &script);
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
@ -98,6 +100,7 @@ Q_SIGNALS:
|
||||||
void injectionPointChanged(int injectionPoint);
|
void injectionPointChanged(int injectionPoint);
|
||||||
private:
|
private:
|
||||||
QWebEngineScript m_webEngineScript;
|
QWebEngineScript m_webEngineScript;
|
||||||
|
QBasicTimer m_basicTimer;
|
||||||
|
|
||||||
bool null() const;
|
bool null() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
@ -110,4 +113,7 @@ private:
|
||||||
void setSourceCode(const QString &sourceCode);
|
void setSourceCode(const QString &sourceCode);
|
||||||
InjectionPoint injectionPoint() const;
|
InjectionPoint injectionPoint() const;
|
||||||
void setInjectionPoint(InjectionPoint injectionPoint);
|
void setInjectionPoint(InjectionPoint injectionPoint);
|
||||||
|
|
||||||
|
void timerEvent(QTimerEvent *e) override;
|
||||||
|
void aboutToUpdateUnderlyingScript();
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,14 +26,6 @@ QmlUserScripts::QmlUserScripts(QObject *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlUserScripts::~QmlUserScripts()
|
|
||||||
{
|
|
||||||
// remove scripts added by the plugin
|
|
||||||
for (const QWebEngineScript &webEngineScript : qAsConst(m_webEngineScripts)) {
|
|
||||||
mApp->webProfile()->scripts()->remove(webEngineScript);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int QmlUserScripts::count() const
|
int QmlUserScripts::count() const
|
||||||
{
|
{
|
||||||
return mApp->webProfile()->scripts()->count();
|
return mApp->webProfile()->scripts()->count();
|
||||||
|
@ -85,30 +77,6 @@ QList<QObject*> QmlUserScripts::findScripts(const QString &name) const
|
||||||
return toQObjectList(list);
|
return toQObjectList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlUserScripts::insert(QObject *object)
|
|
||||||
{
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
mApp->webProfile()->scripts()->insert(webEngineScript);
|
|
||||||
m_webEngineScripts.append(webEngineScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScripts::insert(const QList<QObject*> &list)
|
|
||||||
{
|
|
||||||
for (QObject *object : list) {
|
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
|
||||||
if (!userScript) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
|
||||||
mApp->webProfile()->scripts()->insert(webEngineScript);
|
|
||||||
m_webEngineScripts.append(webEngineScript);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlUserScripts::remove(QObject *object) const
|
void QmlUserScripts::remove(QObject *object) const
|
||||||
{
|
{
|
||||||
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
||||||
|
@ -124,3 +92,13 @@ QList<QObject*> QmlUserScripts::toList() const
|
||||||
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
|
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
|
||||||
return toQObjectList(list);
|
return toQObjectList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlUserScripts::insert(QObject *object)
|
||||||
|
{
|
||||||
|
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
|
||||||
|
if (!userScript) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QWebEngineScript webEngineScript = userScript->webEngineScript();
|
||||||
|
mApp->webProfile()->scripts()->insert(webEngineScript);
|
||||||
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ class FALKON_EXPORT QmlUserScripts : public QObject
|
||||||
Q_PROPERTY(bool empty READ empty CONSTANT)
|
Q_PROPERTY(bool empty READ empty CONSTANT)
|
||||||
public:
|
public:
|
||||||
explicit QmlUserScripts(QObject *parent = nullptr);
|
explicit QmlUserScripts(QObject *parent = nullptr);
|
||||||
~QmlUserScripts();
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if the script is in collection
|
* @brief Checks if the script is in collection
|
||||||
* @param object of type QmlUserScript
|
* @param object of type QmlUserScript
|
||||||
|
@ -58,16 +57,6 @@ public:
|
||||||
* @return list of objects, each of type QmlUserScript, representing the script of given name
|
* @return list of objects, each of type QmlUserScript, representing the script of given name
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE QList<QObject*> findScripts(const QString &name) const;
|
Q_INVOKABLE QList<QObject*> findScripts(const QString &name) const;
|
||||||
/**
|
|
||||||
* @brief Inserts a script into collection
|
|
||||||
* @param object of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void insert(QObject *object);
|
|
||||||
/**
|
|
||||||
* @brief Inserts a list of scripts into collection
|
|
||||||
* @param list of objects, each of type QmlUserScript
|
|
||||||
*/
|
|
||||||
Q_INVOKABLE void insert(const QList<QObject*> &list);
|
|
||||||
/**
|
/**
|
||||||
* @brief Removes a script from collection
|
* @brief Removes a script from collection
|
||||||
* @param object of type QmlUserScript
|
* @param object of type QmlUserScript
|
||||||
|
@ -78,11 +67,12 @@ public:
|
||||||
* @return list of objects, each of type QmlUserScript
|
* @return list of objects, each of type QmlUserScript
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE QList<QObject*> toList() const;
|
Q_INVOKABLE QList<QObject*> toList() const;
|
||||||
|
|
||||||
|
void insert(QObject *object);
|
||||||
private:
|
private:
|
||||||
int count() const;
|
int count() const;
|
||||||
int size() const;
|
int size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
QList<QWebEngineScript> m_webEngineScripts;
|
|
||||||
|
|
||||||
QList<QObject*> toQObjectList(const QList<QWebEngineScript> &list) const;
|
QList<QObject*> toQObjectList(const QList<QWebEngineScript> &list) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ void QmlPlugin::initPlugin(Plugins::Plugin *plugin)
|
||||||
}
|
}
|
||||||
qmlPluginLoader->createComponent();
|
qmlPluginLoader->createComponent();
|
||||||
if (!qmlPluginLoader->instance()) {
|
if (!qmlPluginLoader->instance()) {
|
||||||
qWarning().noquote() << "Falied to create component for" << name << "plugin:" << qmlPluginLoader->component()->errorString();
|
qWarning().noquote() << "Failed to create component for" << name << "plugin:" << qmlPluginLoader->component()->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "api/fileutils/qmlfileutils.h"
|
#include "api/fileutils/qmlfileutils.h"
|
||||||
#include "pluginproxy.h"
|
#include "pluginproxy.h"
|
||||||
|
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
QmlStaticData::QmlStaticData(QObject *parent)
|
QmlStaticData::QmlStaticData(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -138,53 +140,62 @@ QIcon QmlStaticData::getIcon(const QString &iconPath, const QString &pluginPath)
|
||||||
QmlBookmarks *QmlStaticData::getBookmarksSingleton()
|
QmlBookmarks *QmlStaticData::getBookmarksSingleton()
|
||||||
{
|
{
|
||||||
static QmlBookmarks *bookmarks = new QmlBookmarks(this);
|
static QmlBookmarks *bookmarks = new QmlBookmarks(this);
|
||||||
|
QQmlEngine::setObjectOwnership(bookmarks, QQmlEngine::CppOwnership);
|
||||||
return bookmarks;
|
return bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlHistory *QmlStaticData::getHistorySingleton()
|
QmlHistory *QmlStaticData::getHistorySingleton()
|
||||||
{
|
{
|
||||||
static QmlHistory *history = new QmlHistory(this);
|
static QmlHistory *history = new QmlHistory(this);
|
||||||
|
QQmlEngine::setObjectOwnership(history, QQmlEngine::CppOwnership);
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlCookies *QmlStaticData::getCookiesSingleton()
|
QmlCookies *QmlStaticData::getCookiesSingleton()
|
||||||
{
|
{
|
||||||
static QmlCookies *cookies = new QmlCookies(this);
|
static QmlCookies *cookies = new QmlCookies(this);
|
||||||
|
QQmlEngine::setObjectOwnership(cookies, QQmlEngine::CppOwnership);
|
||||||
return cookies;
|
return cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlTopSites *QmlStaticData::getTopSitesSingleton()
|
QmlTopSites *QmlStaticData::getTopSitesSingleton()
|
||||||
{
|
{
|
||||||
static QmlTopSites *topSites = new QmlTopSites(this);
|
static QmlTopSites *topSites = new QmlTopSites(this);
|
||||||
|
QQmlEngine::setObjectOwnership(topSites, QQmlEngine::CppOwnership);
|
||||||
return topSites;
|
return topSites;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlTabs *QmlStaticData::getTabsSingleton()
|
QmlTabs *QmlStaticData::getTabsSingleton()
|
||||||
{
|
{
|
||||||
static QmlTabs *tabs = new QmlTabs(this);
|
static QmlTabs *tabs = new QmlTabs(this);
|
||||||
|
QQmlEngine::setObjectOwnership(tabs, QQmlEngine::CppOwnership);
|
||||||
return tabs;
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlClipboard *QmlStaticData::getClipboardSingleton()
|
QmlClipboard *QmlStaticData::getClipboardSingleton()
|
||||||
{
|
{
|
||||||
static QmlClipboard *clipboard = new QmlClipboard(this);
|
static QmlClipboard *clipboard = new QmlClipboard(this);
|
||||||
|
QQmlEngine::setObjectOwnership(clipboard, QQmlEngine::CppOwnership);
|
||||||
return clipboard;
|
return clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlWindows *QmlStaticData::getWindowsSingleton()
|
QmlWindows *QmlStaticData::getWindowsSingleton()
|
||||||
{
|
{
|
||||||
static QmlWindows *windows = new QmlWindows(this);
|
static QmlWindows *windows = new QmlWindows(this);
|
||||||
|
QQmlEngine::setObjectOwnership(windows, QQmlEngine::CppOwnership);
|
||||||
return windows;
|
return windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlExternalJsObject *QmlStaticData::getExternalJsObjectSingleton()
|
QmlExternalJsObject *QmlStaticData::getExternalJsObjectSingleton()
|
||||||
{
|
{
|
||||||
static QmlExternalJsObject *externalJsObject = new QmlExternalJsObject(this);
|
static QmlExternalJsObject *externalJsObject = new QmlExternalJsObject(this);
|
||||||
|
QQmlEngine::setObjectOwnership(externalJsObject, QQmlEngine::CppOwnership);
|
||||||
return externalJsObject;
|
return externalJsObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlUserScripts *QmlStaticData::getUserScriptsSingleton()
|
QmlUserScripts *QmlStaticData::getUserScriptsSingleton()
|
||||||
{
|
{
|
||||||
static QmlUserScripts *userScripts = new QmlUserScripts(this);
|
static QmlUserScripts *userScripts = new QmlUserScripts(this);
|
||||||
|
QQmlEngine::setObjectOwnership(userScripts, QQmlEngine::CppOwnership);
|
||||||
return userScripts;
|
return userScripts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ Falkon.PluginInterface {
|
||||||
id: 'helloQmlObject',
|
id: 'helloQmlObject',
|
||||||
object: helloQmlObject
|
object: helloQmlObject
|
||||||
})
|
})
|
||||||
Falkon.UserScripts.insert(testingHelloQmlUserScript)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testPlugin: function() {
|
testPlugin: function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user