diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index ff0b1db03..532619be8 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -89,6 +89,7 @@ set( libGuiSources resolvers/JSResolver.cpp resolvers/JSResolverHelper.cpp resolvers/ScriptEngine.cpp + resolvers/JSPlugin.cpp utils/DpiScaler.cpp utils/ImageRegistry.cpp diff --git a/src/libtomahawk/resolvers/JSInfoPlugin.cpp b/src/libtomahawk/resolvers/JSInfoPlugin.cpp index 77f034c39..f18ae105d 100644 --- a/src/libtomahawk/resolvers/JSInfoPlugin.cpp +++ b/src/libtomahawk/resolvers/JSInfoPlugin.cpp @@ -26,7 +26,7 @@ using namespace Tomahawk; -JSInfoPlugin::JSInfoPlugin( int id, JSResolver *resolver ) +JSInfoPlugin::JSInfoPlugin( int id, JSPlugin *resolver ) : d_ptr( new JSInfoPluginPrivate( this, id, resolver ) ) { Q_ASSERT( resolver ); @@ -35,7 +35,7 @@ JSInfoPlugin::JSInfoPlugin( int id, JSResolver *resolver ) m_supportedGetTypes = parseSupportedTypes( callMethodOnInfoPluginWithResult( "supportedGetTypes" ) ); m_supportedPushTypes = parseSupportedTypes( callMethodOnInfoPluginWithResult( "supportedPushTypes" ) ); - setFriendlyName( QString( "JSInfoPlugin: %1" ).arg( resolver->name() ) ); + setFriendlyName( QString( "JSInfoPlugin: %1" ) ); // TODO: .arg( resolver->name() ) } @@ -70,8 +70,6 @@ JSInfoPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) void JSInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) { - Q_D( JSInfoPlugin ); - QString eval = QString( "pushInfo({ type: %1, pushFlags: %2, input: %3, additionalInput: %4})" ) .arg( pushData.type ) .arg( pushData.pushFlags ) @@ -239,7 +237,7 @@ JSInfoPlugin::serializeQVariantMap( const QVariantMap& map ) QByteArray serialized = TomahawkUtils::toJson( localMap ); - return QString( "JSON.parse('%1')" ).arg( JSResolver::escape( QString::fromUtf8( serialized ) ) ); + return QString( "JSON.parse('%1')" ).arg( JSPlugin::escape( QString::fromUtf8( serialized ) ) ); } diff --git a/src/libtomahawk/resolvers/JSInfoPlugin.h b/src/libtomahawk/resolvers/JSInfoPlugin.h index faf20e146..dafe57fa7 100644 --- a/src/libtomahawk/resolvers/JSInfoPlugin.h +++ b/src/libtomahawk/resolvers/JSInfoPlugin.h @@ -27,7 +27,7 @@ namespace Tomahawk { -class JSResolver; +class JSPlugin; class JSInfoPluginPrivate; @@ -39,7 +39,7 @@ public: /** * @param id unique identifier to identify an infoplugin in its scope */ - JSInfoPlugin( int id, JSResolver* resolver ); + JSInfoPlugin( int id, JSPlugin* resolver ); virtual ~JSInfoPlugin(); diff --git a/src/libtomahawk/resolvers/JSInfoPlugin_p.h b/src/libtomahawk/resolvers/JSInfoPlugin_p.h index 6f9743848..1ae81b634 100644 --- a/src/libtomahawk/resolvers/JSInfoPlugin_p.h +++ b/src/libtomahawk/resolvers/JSInfoPlugin_p.h @@ -28,7 +28,7 @@ class JSInfoPluginPrivate { friend class JSInfoPlugin; public: - JSInfoPluginPrivate( JSInfoPlugin* q, int id, JSResolver* resolver ) + JSInfoPluginPrivate( JSInfoPlugin* q, int id, JSPlugin* resolver ) : q_ptr ( q ) , id( id ) , resolver( resolver ) @@ -39,7 +39,8 @@ public: private: int id; - JSResolver* resolver; + // HACK: JSInfoPlugin needs to be refactored to track a ScriptObject + JSPlugin* resolver; QMap< int, Tomahawk::InfoSystem::InfoRequestData > requestDataCache; QMap< int, Tomahawk::InfoSystem::InfoStringHash > criteriaCache; diff --git a/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp b/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp index 5cfd053f9..0d8b07a40 100644 --- a/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp +++ b/src/libtomahawk/resolvers/JSInfoSystemHelper.cpp @@ -23,7 +23,7 @@ using namespace Tomahawk; -JSInfoSystemHelper::JSInfoSystemHelper( JSResolver* parent ) +JSInfoSystemHelper::JSInfoSystemHelper( JSPlugin* parent ) : QObject( parent ) , d_ptr( new JSInfoSystemHelperPrivate( this, parent ) ) { @@ -48,7 +48,7 @@ JSInfoSystemHelper::nativeAddInfoPlugin( int id ) Q_D( JSInfoSystemHelper ); // create infoplugin instance - JSInfoPlugin* jsInfoPlugin = new JSInfoPlugin( id, d->resolver ); + JSInfoPlugin* jsInfoPlugin = new JSInfoPlugin( id, d->scriptPlugin ); Tomahawk::InfoSystem::InfoPluginPtr infoPlugin( jsInfoPlugin ); // move it to infosystem thread diff --git a/src/libtomahawk/resolvers/JSInfoSystemHelper.h b/src/libtomahawk/resolvers/JSInfoSystemHelper.h index 78ca758e6..86f8eaa6f 100644 --- a/src/libtomahawk/resolvers/JSInfoSystemHelper.h +++ b/src/libtomahawk/resolvers/JSInfoSystemHelper.h @@ -24,7 +24,7 @@ namespace Tomahawk { -class JSResolver; +class JSPlugin; class JSInfoSystemHelperPrivate; class JSInfoSystemHelper : public QObject @@ -32,7 +32,7 @@ class JSInfoSystemHelper : public QObject Q_OBJECT public: - JSInfoSystemHelper( JSResolver* parent ); + JSInfoSystemHelper( JSPlugin* parent ); ~JSInfoSystemHelper(); QStringList requiredScriptPaths() const; diff --git a/src/libtomahawk/resolvers/JSInfoSystemHelper_p.h b/src/libtomahawk/resolvers/JSInfoSystemHelper_p.h index 644d53170..888c759d0 100644 --- a/src/libtomahawk/resolvers/JSInfoSystemHelper_p.h +++ b/src/libtomahawk/resolvers/JSInfoSystemHelper_p.h @@ -29,9 +29,9 @@ class JSInfoSystemHelperPrivate { friend class JSInfoSystemHelper; public: - JSInfoSystemHelperPrivate( JSInfoSystemHelper* q, JSResolver* resolver ) + JSInfoSystemHelperPrivate( JSInfoSystemHelper* q, JSPlugin* scriptPlugin ) : q_ptr ( q ) - , resolver ( resolver ) + , scriptPlugin ( scriptPlugin ) { } @@ -39,7 +39,7 @@ public: Q_DECLARE_PUBLIC ( JSInfoSystemHelper ) private: - JSResolver* resolver; + JSPlugin* scriptPlugin; QMap infoPlugins; }; diff --git a/src/libtomahawk/resolvers/JSPlugin.cpp b/src/libtomahawk/resolvers/JSPlugin.cpp new file mode 100644 index 000000000..eb76d5663 --- /dev/null +++ b/src/libtomahawk/resolvers/JSPlugin.cpp @@ -0,0 +1,29 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "JSResolver.h" +#include + + +using namespace Tomahawk; + +void +JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object ) +{ + m_engine->mainFrame()->addToJavaScriptWindowObject( name, object ); +}; diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index fa3ce7816..24a674b36 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -63,7 +63,7 @@ JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, con Q_D( JSResolver ); tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath; - d->engine = new ScriptEngine( this ); + d->scriptPlugin = new JSPlugin(); d->name = QFileInfo( filePath() ).baseName(); // set the icon, if we launch properly we'll get the icon the resolver reports @@ -87,7 +87,7 @@ JSResolver::~JSResolver() if ( !d->stopped ) stop(); - delete d->engine; + delete d->scriptPlugin; } @@ -205,20 +205,17 @@ JSResolver::init() } const QByteArray scriptContents = scriptFile.readAll(); - d->engine->mainFrame()->setHtml( "", QUrl( "file:///invalid/file/for/security/policy" ) ); - - // tomahawk.js { // add c++ part of tomahawk javascript library - d->engine->mainFrame()->addToJavaScriptWindowObject( "Tomahawk", d->resolverHelper ); + d->scriptPlugin->addToJavaScriptWindowObject( "Tomahawk", d->resolverHelper ); // load es6-promises shim - loadScript( RESPATH "js/es6-promise-2.0.0.min.js" ); + d->scriptPlugin->loadScript( RESPATH "js/es6-promise-2.0.0.min.js" ); // Load CrytoJS core - loadScript( RESPATH "js/cryptojs-core.js" ); + d->scriptPlugin->loadScript( RESPATH "js/cryptojs-core.js" ); // Load CryptoJS modules QStringList jsfiles; @@ -226,29 +223,30 @@ JSResolver::init() QDir cryptojs( RESPATH "js/cryptojs" ); foreach ( QString jsfile, cryptojs.entryList( jsfiles ) ) { - loadScript( RESPATH "js/cryptojs/" + jsfile ); + d->scriptPlugin->loadScript( RESPATH "js/cryptojs/" + jsfile ); } // Load tomahawk.js - loadScript( RESPATH "js/tomahawk.js" ); + d->scriptPlugin->loadScript( RESPATH "js/tomahawk.js" ); } // tomahawk-infosystem.js { // add c++ part of tomahawk infosystem bindings as Tomahawk.InfoSystem - d->engine->mainFrame()->addToJavaScriptWindowObject( "_TomahawkInfoSystem", d->infoSystemHelper ); - d->engine->mainFrame()->evaluateJavaScript( "Tomahawk.InfoSystem = _TomahawkInfoSystem;" ); + d->infoSystemHelper = new JSInfoSystemHelper( d->scriptPlugin ); + d->scriptPlugin->addToJavaScriptWindowObject( "_TomahawkInfoSystem", d->infoSystemHelper ); + d->scriptPlugin->evaluateJavaScript( "Tomahawk.InfoSystem = _TomahawkInfoSystem;" ); // add deps - loadScripts( d->infoSystemHelper->requiredScriptPaths() ); + d->scriptPlugin->loadScripts( d->infoSystemHelper->requiredScriptPaths() ); } // add resolver dependencies, if any - loadScripts( d->requiredScriptPaths ); + d->scriptPlugin->loadScripts( d->requiredScriptPaths ); // add resolver - loadScript( filePath() ); + d->scriptPlugin->loadScript( filePath() ); // init resolver resolverInit(); @@ -327,7 +325,7 @@ JSResolver::artists( const Tomahawk::collection_ptr& collection ) } QString eval = QString( "artists( '%1' )" ) - .arg( escape( collection->name() ) ); + .arg( JSPlugin::escape( collection->name() ) ); QVariantMap m = callOnResolver( eval ).toMap(); if ( m.isEmpty() ) @@ -363,8 +361,8 @@ JSResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk:: } QString eval = QString( "albums( '%1', '%2' )" ) - .arg( escape( collection->name() ) ) - .arg( escape( artist->name() ) ); + .arg( JSPlugin::escape( collection->name() ) ) + .arg( JSPlugin::escape( artist->name() ) ); QVariantMap m = callOnResolver( eval ).toMap(); if ( m.isEmpty() ) @@ -400,9 +398,9 @@ JSResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk:: } QString eval = QString( "tracks( '%1', '%2', '%3' )" ) - .arg( escape( collection->name() ) ) - .arg( escape( album->artist()->name() ) ) - .arg( escape( album->name() ) ); + .arg( JSPlugin::escape( collection->name() ) ) + .arg( JSPlugin::escape( album->artist()->name() ) ) + .arg( JSPlugin::escape( album->name() ) ); QVariantMap m = callOnResolver( eval ).toMap(); if ( m.isEmpty() ) @@ -433,7 +431,7 @@ JSResolver::canParseUrl( const QString& url, UrlType type ) if ( d->capabilities.testFlag( UrlLookup ) ) { QString eval = QString( "canParseUrl( '%1', %2 )" ) - .arg( escape( QString( url ) ) ) + .arg( JSPlugin::escape( QString( url ) ) ) .arg( (int) type ); return callOnResolver( eval ).toBool(); } @@ -464,7 +462,7 @@ JSResolver::lookupUrl( const QString& url ) } QString eval = QString( "lookupUrl( '%1' )" ) - .arg( escape( QString( url ) ) ); + .arg( JSPlugin::escape( QString( url ) ) ); QVariantMap m = callOnResolver( eval ).toMap(); if ( m.isEmpty() ) @@ -480,16 +478,14 @@ JSResolver::lookupUrl( const QString& url ) QVariant -JSResolver::evaluateJavaScriptInternal(const QString& scriptSource) +JSPlugin::evaluateJavaScriptInternal( const QString& scriptSource ) { - Q_D( JSResolver ); - - return d->engine->mainFrame()->evaluateJavaScript( scriptSource ); + return m_engine->mainFrame()->evaluateJavaScript( scriptSource ); } void -JSResolver::evaluateJavaScript( const QString& scriptSource ) +JSPlugin::evaluateJavaScript( const QString& scriptSource ) { if ( QThread::currentThread() != thread() ) { @@ -502,7 +498,7 @@ JSResolver::evaluateJavaScript( const QString& scriptSource ) QVariant -JSResolver::evaluateJavaScriptWithResult( const QString& scriptSource ) +JSPlugin::evaluateJavaScriptWithResult( const QString& scriptSource ) { Q_ASSERT( QThread::currentThread() == thread() ); @@ -532,16 +528,16 @@ JSResolver::resolve( const Tomahawk::query_ptr& query ) if ( !query->isFullTextQuery() ) { eval = QString( "resolve( '%1', '%2', '%3', '%4' )" ) - .arg( escape( query->id() ) ) - .arg( escape( query->queryTrack()->artist() ) ) - .arg( escape( query->queryTrack()->album() ) ) - .arg( escape( query->queryTrack()->track() ) ); + .arg( JSPlugin::escape( query->id() ) ) + .arg( JSPlugin::escape( query->queryTrack()->artist() ) ) + .arg( JSPlugin::escape( query->queryTrack()->album() ) ) + .arg( JSPlugin::escape( query->queryTrack()->track() ) ); } else { eval = QString( "search( '%1', '%2' )" ) - .arg( escape( query->id() ) ) - .arg( escape( query->fullTextQuery() ) ); + .arg( JSPlugin::escape( query->id() ) ) + .arg( JSPlugin::escape( query->fullTextQuery() ) ); } QVariantMap m = callOnResolver( eval ).toMap(); @@ -964,10 +960,8 @@ JSResolver::resolverCollections() void -JSResolver::loadScript( const QString& path ) +JSPlugin::loadScript( const QString& path ) { - Q_D( JSResolver ); - QFile file( path ); if ( !file.open( QIODevice::ReadOnly ) ) @@ -979,15 +973,15 @@ JSResolver::loadScript( const QString& path ) const QByteArray contents = file.readAll(); - d->engine->setScriptPath( path ); - d->engine->mainFrame()->evaluateJavaScript( contents ); + m_engine->setScriptPath( path ); + m_engine->mainFrame()->evaluateJavaScript( contents ); file.close(); } void -JSResolver::loadScripts( const QStringList& paths ) +JSPlugin::loadScripts( const QStringList& paths ) { foreach ( const QString& path, paths ) { @@ -1003,7 +997,9 @@ JSResolver::callOnResolver( const QString& scriptSource ) QString propertyName = scriptSource.split('(').first(); - return d->engine->mainFrame()->evaluateJavaScript( QString( + tLog() << "JAVASCRIPT: run: " << scriptSource; + + return d->scriptPlugin->evaluateJavaScriptWithResult( QString( "if(Tomahawk.resolver.instance['_adapter_%1']) {" " Tomahawk.resolver.instance._adapter_%2;" "} else {" @@ -1014,7 +1010,7 @@ JSResolver::callOnResolver( const QString& scriptSource ) QString -JSResolver::escape( const QString& source ) +JSPlugin::JSPlugin::escape( const QString& source ) { QString copy = source; return copy.replace( "\\", "\\\\" ).replace( "'", "\\'" ); diff --git a/src/libtomahawk/resolvers/JSResolver.h b/src/libtomahawk/resolvers/JSResolver.h index 916457ac5..b90c5215d 100644 --- a/src/libtomahawk/resolvers/JSResolver.h +++ b/src/libtomahawk/resolvers/JSResolver.h @@ -27,6 +27,10 @@ #include "ExternalResolverGui.h" #include "Typedefs.h" + +#include // unique_ptr +#include "ScriptEngine.h" // hack, also should be renamed to JSEngine + namespace Tomahawk { @@ -34,6 +38,54 @@ class JSInfoPlugin; class JSResolverHelper; class JSResolverPrivate; class ScriptEngine; +class ScriptJob; +class ScriptObject; +class ScriptPlugin; + +class DLLEXPORT ScriptPlugin +{ +public: + virtual ~ScriptPlugin() {} +}; + +class DLLEXPORT JSPlugin : public QObject, public ScriptPlugin +{ + Q_OBJECT + +public: + JSPlugin() + : m_engine( new ScriptEngine( this ) ) + { + } + + /** + * Evaluate JavaScript on the WebKit thread + */ + Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource ); + + /** + * This method must be called from the WebKit thread + */ + QVariant evaluateJavaScriptWithResult( const QString& scriptSource ); + + /** + * Escape \ and ' in strings so they are safe to use in JavaScript + */ + static QString escape( const QString& source ); + + + void loadScript( const QString& path ); + void loadScripts( const QStringList& paths ); + void addToJavaScriptWindowObject( const QString& name, QObject* object ); +private: + /** + * Wrap the pure evaluateJavaScript call in here, while the threadings guards are in public methods + */ + QVariant evaluateJavaScriptInternal( const QString& scriptSource ); + + std::unique_ptr m_engine; + +}; class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui { @@ -64,20 +116,6 @@ public: bool canParseUrl( const QString& url, UrlType type ) override; - /** - * Evaluate JavaScript on the WebKit thread - */ - Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource ); - - /** - * This method must be called from the WebKit thread - */ - QVariant evaluateJavaScriptWithResult( const QString& scriptSource ); - - /** - * Escape \ and ' in strings so they are safe to use in JavaScript - */ - static QString escape( const QString& source ); public slots: void resolve( const Tomahawk::query_ptr& query ) override; @@ -110,13 +148,6 @@ private: void fillDataInWidgets( const QVariantMap& data ); void onCapabilitiesChanged( Capabilities capabilities ); void loadCollections(); - void loadScript( const QString& path ); - void loadScripts( const QStringList& paths ); - - /** - * Wrap the pure evaluateJavaScript call in here, while the threadings guards are in public methods - */ - QVariant evaluateJavaScriptInternal( const QString& scriptSource ); // encapsulate javascript calls QVariantMap resolverSettings(); diff --git a/src/libtomahawk/resolvers/JSResolverHelper.cpp b/src/libtomahawk/resolvers/JSResolverHelper.cpp index ae371c482..f325bc85c 100644 --- a/src/libtomahawk/resolvers/JSResolverHelper.cpp +++ b/src/libtomahawk/resolvers/JSResolverHelper.cpp @@ -484,14 +484,14 @@ JSResolverHelper::customIODeviceFactory( const Tomahawk::result_ptr&, const QStr .arg( url ); m_streamCallbacks.insert( qid, callback ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( getUrl ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( getUrl ); } else { QString getUrl = QString( "Tomahawk.resolver.instance.%1( '%2' );" ).arg( m_urlCallback ) .arg( url ); - QString urlStr = m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( getUrl ).toString(); + QString urlStr = m_resolver->d_func()->scriptPlugin->evaluateJavaScriptWithResult( getUrl ).toString(); returnStreamUrl( urlStr, QMap(), callback ); } @@ -528,7 +528,7 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Supplied size is not (yet) supported');" ) .arg( metadataId ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); return; } @@ -595,7 +595,7 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Unknown mime type for tagging: %2');" ) .arg( metadataId ).arg( mime_type ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); return; } @@ -610,7 +610,7 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Could not read tag information.');" ) .arg( metadataId ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); return; } @@ -624,7 +624,7 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Empty track returnd');" ) .arg( metadataId ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); return; } @@ -632,7 +632,7 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Empty artist returnd');" ) .arg( metadataId ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); return; } @@ -647,13 +647,13 @@ JSResolverHelper::nativeRetrieveMetadata( int metadataId, const QString& url, QString javascript = QString( "Tomahawk.retrievedMetadata( %1, %2 );" ) .arg( metadataId ) .arg( QString::fromLatin1( TomahawkUtils::toJson( m ) ) ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); } else { QString javascript = QString( "Tomahawk.retrievedMetadata( %1, null, 'Protocol not supported');" ) .arg( metadataId ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); } } @@ -717,7 +717,7 @@ JSResolverHelper::nativeAsyncRequestDone( int requestId, NetworkReply* reply ) QString javascript = QString( "Tomahawk.nativeAsyncRequestDone( %1, %2 );" ) .arg( QString::number( requestId ) ) .arg( json ); - m_resolver->d_func()->engine->mainFrame()->evaluateJavaScript( javascript ); + m_resolver->d_func()->scriptPlugin->evaluateJavaScript( javascript ); } diff --git a/src/libtomahawk/resolvers/JSResolver_p.h b/src/libtomahawk/resolvers/JSResolver_p.h index 9cf837673..0434ce693 100644 --- a/src/libtomahawk/resolvers/JSResolver_p.h +++ b/src/libtomahawk/resolvers/JSResolver_p.h @@ -43,7 +43,7 @@ public: , error( Tomahawk::ExternalResolver::NoError ) , resolverHelper( new JSResolverHelper( scriptPath, q ) ) // TODO: be smarter about this, only instantiate this if the resolver supports infoplugins - , infoSystemHelper( new JSInfoSystemHelper( q ) ) + , infoSystemHelper( nullptr ) , requiredScriptPaths( additionalScriptPaths ) { } @@ -51,8 +51,6 @@ public: Q_DECLARE_PUBLIC ( JSResolver ) private: - ScriptEngine* engine; - QString accountId; QString name; QPixmap icon; @@ -69,6 +67,8 @@ private: QPointer< AccountConfigWidget > configWidget; QList< QVariant > dataWidgets; QStringList requiredScriptPaths; + + JSPlugin* scriptPlugin; }; } // ns: Tomahawk diff --git a/src/libtomahawk/resolvers/ScriptEngine.cpp b/src/libtomahawk/resolvers/ScriptEngine.cpp index 28d9af9d2..ed14bb6ae 100644 --- a/src/libtomahawk/resolvers/ScriptEngine.cpp +++ b/src/libtomahawk/resolvers/ScriptEngine.cpp @@ -35,7 +35,7 @@ using namespace Tomahawk; -ScriptEngine::ScriptEngine( JSResolver* parent ) +ScriptEngine::ScriptEngine( JSPlugin* parent ) : QWebPage( (QObject*) parent ) , m_parent( parent ) { @@ -54,6 +54,8 @@ ScriptEngine::ScriptEngine( JSResolver* parent ) , "" ); tLog( LOGVERBOSE ) << "JSResolver Using header" << m_header; + mainFrame()->setHtml( "", QUrl( "file:///invalid/file/for/security/policy" ) ); + connect( networkAccessManager(), SIGNAL( sslErrors( QNetworkReply*, QList ) ), SLOT( sslErrorHandler( QNetworkReply*, QList ) ) ); } diff --git a/src/libtomahawk/resolvers/ScriptEngine.h b/src/libtomahawk/resolvers/ScriptEngine.h index 33efecec7..de9fb59d9 100644 --- a/src/libtomahawk/resolvers/ScriptEngine.h +++ b/src/libtomahawk/resolvers/ScriptEngine.h @@ -32,14 +32,14 @@ class QNetworkReply; namespace Tomahawk { -class JSResolver; +class JSPlugin; class DLLEXPORT ScriptEngine : public QWebPage { Q_OBJECT public: - explicit ScriptEngine( JSResolver* parent ); + explicit ScriptEngine( JSPlugin* parent ); QString userAgentForUrl( const QUrl& url ) const; void setScriptPath( const QString& scriptPath ); @@ -54,7 +54,7 @@ private slots: void sslErrorHandler( QNetworkReply* qnr, const QList& errlist ); private: - JSResolver* m_parent; + JSPlugin* m_parent; QString m_scriptPath; QString m_header; };