1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Merge branch 'Falkon/3.1'

This commit is contained in:
David Rosca 2019-04-20 12:10:35 +02:00
commit 3137cdfca2
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
8 changed files with 61 additions and 46 deletions

View File

@ -30,6 +30,7 @@ class QmlExtensionSchemeHandler;
class QmlExtensionScheme : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
/**
* @brief extension scheme handle name
*/

View File

@ -16,12 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qmluserscript.h"
#include "../../qmlstaticdata.h"
QmlUserScript::QmlUserScript(QObject *parent)
: QObject(parent)
{
}
QmlUserScript::~QmlUserScript()
{
QmlStaticData::instance().getUserScriptsSingleton()->remove(this);
}
QWebEngineScript QmlUserScript::webEngineScript() const
{
return m_webEngineScript;
@ -46,6 +52,7 @@ void QmlUserScript::setName(const QString &name)
{
m_webEngineScript.setName(name);
emit nameChanged(name);
aboutToUpdateUnderlyingScript();
}
bool QmlUserScript::runsOnSubFrames() const
@ -57,6 +64,7 @@ void QmlUserScript::setRunsOnSubFrames(bool runsOnSubFrames)
{
m_webEngineScript.setRunsOnSubFrames(runsOnSubFrames);
emit runsOnSubFramesChanged(runsOnSubFrames);
aboutToUpdateUnderlyingScript();
}
int QmlUserScript::worldId() const
@ -80,6 +88,7 @@ void QmlUserScript::setWorldId(int worldId)
break;
}
emit worldIdChanged(worldId);
aboutToUpdateUnderlyingScript();
}
QString QmlUserScript::sourceCode() const
@ -91,6 +100,7 @@ void QmlUserScript::setSourceCode(const QString &sourceCode)
{
m_webEngineScript.setSourceCode(sourceCode);
emit sourceCodeChanged(sourceCode);
aboutToUpdateUnderlyingScript();
}
QmlUserScript::InjectionPoint QmlUserScript::injectionPoint() const
@ -114,4 +124,24 @@ void QmlUserScript::setInjectionPoint(InjectionPoint injectionPoint)
break;
}
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);
}

View File

@ -20,6 +20,7 @@
#include "qzcommon.h"
#include <QObject>
#include <QBasicTimer>
#include <QWebEngineScript>
/**
@ -73,6 +74,7 @@ public:
Q_ENUM(ScriptWorldId)
explicit QmlUserScript(QObject *parent = nullptr);
~QmlUserScript();
QWebEngineScript webEngineScript() const;
void setWebEngineScript(const QWebEngineScript &script);
Q_SIGNALS:
@ -98,6 +100,7 @@ Q_SIGNALS:
void injectionPointChanged(int injectionPoint);
private:
QWebEngineScript m_webEngineScript;
QBasicTimer m_basicTimer;
bool null() const;
QString name() const;
@ -110,4 +113,7 @@ private:
void setSourceCode(const QString &sourceCode);
InjectionPoint injectionPoint() const;
void setInjectionPoint(InjectionPoint injectionPoint);
void timerEvent(QTimerEvent *e) override;
void aboutToUpdateUnderlyingScript();
};

View File

@ -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
{
return mApp->webProfile()->scripts()->count();
@ -85,30 +77,6 @@ QList<QObject*> QmlUserScripts::findScripts(const QString &name) const
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
{
QmlUserScript *userScript = qobject_cast<QmlUserScript*>(object);
@ -124,3 +92,13 @@ QList<QObject*> QmlUserScripts::toList() const
QList<QWebEngineScript> list = mApp->webProfile()->scripts()->toList();
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);
}

View File

@ -40,7 +40,6 @@ class FALKON_EXPORT QmlUserScripts : public QObject
Q_PROPERTY(bool empty READ empty CONSTANT)
public:
explicit QmlUserScripts(QObject *parent = nullptr);
~QmlUserScripts();
/**
* @brief Checks if the script is in collection
* @param object of type QmlUserScript
@ -58,16 +57,6 @@ public:
* @return list of objects, each of type QmlUserScript, representing the script of given name
*/
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
* @param object of type QmlUserScript
@ -78,11 +67,12 @@ public:
* @return list of objects, each of type QmlUserScript
*/
Q_INVOKABLE QList<QObject*> toList() const;
void insert(QObject *object);
private:
int count() const;
int size() const;
bool empty() const;
QList<QWebEngineScript> m_webEngineScripts;
QList<QObject*> toQObjectList(const QList<QWebEngineScript> &list) const;
};

View File

@ -70,7 +70,7 @@ void QmlPlugin::initPlugin(Plugins::Plugin *plugin)
}
qmlPluginLoader->createComponent();
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;
}

View File

@ -25,6 +25,8 @@
#include "api/fileutils/qmlfileutils.h"
#include "pluginproxy.h"
#include <QQmlEngine>
QmlStaticData::QmlStaticData(QObject *parent)
: QObject(parent)
{
@ -138,53 +140,62 @@ QIcon QmlStaticData::getIcon(const QString &iconPath, const QString &pluginPath)
QmlBookmarks *QmlStaticData::getBookmarksSingleton()
{
static QmlBookmarks *bookmarks = new QmlBookmarks(this);
QQmlEngine::setObjectOwnership(bookmarks, QQmlEngine::CppOwnership);
return bookmarks;
}
QmlHistory *QmlStaticData::getHistorySingleton()
{
static QmlHistory *history = new QmlHistory(this);
QQmlEngine::setObjectOwnership(history, QQmlEngine::CppOwnership);
return history;
}
QmlCookies *QmlStaticData::getCookiesSingleton()
{
static QmlCookies *cookies = new QmlCookies(this);
QQmlEngine::setObjectOwnership(cookies, QQmlEngine::CppOwnership);
return cookies;
}
QmlTopSites *QmlStaticData::getTopSitesSingleton()
{
static QmlTopSites *topSites = new QmlTopSites(this);
QQmlEngine::setObjectOwnership(topSites, QQmlEngine::CppOwnership);
return topSites;
}
QmlTabs *QmlStaticData::getTabsSingleton()
{
static QmlTabs *tabs = new QmlTabs(this);
QQmlEngine::setObjectOwnership(tabs, QQmlEngine::CppOwnership);
return tabs;
}
QmlClipboard *QmlStaticData::getClipboardSingleton()
{
static QmlClipboard *clipboard = new QmlClipboard(this);
QQmlEngine::setObjectOwnership(clipboard, QQmlEngine::CppOwnership);
return clipboard;
}
QmlWindows *QmlStaticData::getWindowsSingleton()
{
static QmlWindows *windows = new QmlWindows(this);
QQmlEngine::setObjectOwnership(windows, QQmlEngine::CppOwnership);
return windows;
}
QmlExternalJsObject *QmlStaticData::getExternalJsObjectSingleton()
{
static QmlExternalJsObject *externalJsObject = new QmlExternalJsObject(this);
QQmlEngine::setObjectOwnership(externalJsObject, QQmlEngine::CppOwnership);
return externalJsObject;
}
QmlUserScripts *QmlStaticData::getUserScriptsSingleton()
{
static QmlUserScripts *userScripts = new QmlUserScripts(this);
QQmlEngine::setObjectOwnership(userScripts, QQmlEngine::CppOwnership);
return userScripts;
}

View File

@ -25,7 +25,6 @@ Falkon.PluginInterface {
id: 'helloQmlObject',
object: helloQmlObject
})
Falkon.UserScripts.insert(testingHelloQmlUserScript)
}
testPlugin: function() {