From 10a3d932aba2220fcae506ad840d10d4739bdef0 Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Fri, 29 Nov 2019 22:39:09 -0800 Subject: [PATCH] Adjust some API for the latest QtWebKit (#15341) --- src/bootstrap.js | 3 ++- src/config.cpp | 2 +- src/modules/webpage.js | 3 ++- src/phantom.cpp | 5 ++--- src/repl.cpp | 7 +++---- src/utils.cpp | 6 +++--- src/webpage.cpp | 9 ++++----- src/webpage.h | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/bootstrap.js b/src/bootstrap.js index 788d452028..1042ceb6ae 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -73,7 +73,8 @@ phantom.__defineErrorSignalHandler__ = function(obj, page, handlers) { return (!!handlerObj && typeof handlerObj.callback === "function" && typeof handlerObj.connector === "function") ? handlers[handlerName].callback : undefined; - } + }, + configurable: true }); }; diff --git a/src/config.cpp b/src/config.cpp index a81be2f366..661d6c8c98 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -177,7 +177,7 @@ void Config::loadJsonFile(const QString& filePath) // Add this object to the global scope webPage.mainFrame()->addToJavaScriptWindowObject("config", this); // Apply the JSON config settings to this very object - webPage.mainFrame()->evaluateJavaScript(configurator.arg(jsonConfig), QString()); + webPage.mainFrame()->evaluateJavaScript(configurator.arg(jsonConfig)); } QString Config::helpText() const diff --git a/src/modules/webpage.js b/src/modules/webpage.js index 20eae9a85d..0760a74b4e 100644 --- a/src/modules/webpage.js +++ b/src/modules/webpage.js @@ -115,7 +115,8 @@ function definePageSignalHandler(page, handlers, handlerName, signalName) { return !!handlers[handlerName] && typeof handlers[handlerName].callback === "function" ? handlers[handlerName].callback : undefined; - } + }, + configurable: true }); } diff --git a/src/phantom.cpp b/src/phantom.cpp index 5417b9beb9..9565a89ea4 100644 --- a/src/phantom.cpp +++ b/src/phantom.cpp @@ -386,7 +386,7 @@ void Phantom::loadModule(const QString& moduleSource, const QString& filename) "require.cache['" + filename + "'].exports," + "require.cache['" + filename + "']" + "));"; - m_page->mainFrame()->evaluateJavaScript(scriptSource, QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg(QFileInfo(filename).fileName())); + m_page->mainFrame()->evaluateJavaScript(scriptSource); } bool Phantom::injectJs(const QString& jsFilePath) @@ -483,8 +483,7 @@ void Phantom::onInitialized() // Bootstrap the PhantomJS scope m_page->mainFrame()->evaluateJavaScript( - Utils::readResourceFileUtf8(":/bootstrap.js"), - QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg("bootstrap.js") + Utils::readResourceFileUtf8(":/bootstrap.js") ); } diff --git a/src/repl.cpp b/src/repl.cpp index 45a475bc1d..7f25a22b0e 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -147,7 +147,7 @@ REPL::REPL(QWebFrame* webframe, Phantom* parent) linenoiseSetCompletionCallback(REPL::offerCompletion); // Inject REPL utility functions - m_webframe->evaluateJavaScript(Utils::readResourceFileUtf8(":/repl.js"), QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg("repl.js")); + m_webframe->evaluateJavaScript(Utils::readResourceFileUtf8(":/repl.js")); // Add self to JavaScript world m_webframe->addToJavaScriptWindowObject("_repl", this); @@ -184,8 +184,7 @@ void REPL::offerCompletion(const char* buf, linenoiseCompletions* lc) QStringList completions = REPL::getInstance()->m_webframe->evaluateJavaScript( QString(JS_RETURN_POSSIBLE_COMPLETIONS).arg( toInspect, - toComplete), - QString() + toComplete) ).toStringList(); foreach(QString c, completions) { @@ -210,7 +209,7 @@ void REPL::startLoop() // Send the user input to the main Phantom frame for evaluation m_webframe->evaluateJavaScript( QString(JS_EVAL_USER_INPUT).arg( - QString(userInput).replace('"', "\\\"")), QString("phantomjs://repl-input")); + QString(userInput).replace('"', "\\\""))); // Save command in the REPL history linenoiseHistoryAdd(userInput); diff --git a/src/utils.cpp b/src/utils.cpp index 16d933ef95..9970e1cc07 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -132,7 +132,7 @@ bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, c return false; } // Execute JS code in the context of the document - targetFrame->evaluateJavaScript(scriptBody, QString(JAVASCRIPT_SOURCE_CODE_URL).arg(QFileInfo(scriptPath).fileName())); + targetFrame->evaluateJavaScript(scriptBody); return true; } @@ -147,10 +147,10 @@ bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, co QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc); scriptBody = QString("function __run() {\n%1\n}").arg(scriptBody); - targetFrame->evaluateJavaScript(scriptBody, QString(JAVASCRIPT_SOURCE_CODE_URL).arg(QFileInfo(scriptPath).fileName())); + targetFrame->evaluateJavaScript(scriptBody); if (autorun) { - targetFrame->evaluateJavaScript("__run()", QString()); + targetFrame->evaluateJavaScript("__run()"); } return true; diff --git a/src/webpage.cpp b/src/webpage.cpp index f69b530405..897f6dd025 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -769,8 +769,7 @@ QVariant WebPage::evaluateJavaScript(const QString& code) qDebug() << "WebPage - evaluateJavaScript" << function; evalResult = m_currentFrame->evaluateJavaScript( - function, //< function evaluated - QString("phantomjs://webpage.evaluate()")); //< reference source file + function); qDebug() << "WebPage - evaluateJavaScript result" << evalResult; @@ -942,7 +941,7 @@ void WebPage::openUrl(const QString& address, const QVariant& op, const QVariant } if (networkOp == QNetworkAccessManager::UnknownOperation) { - m_mainFrame->evaluateJavaScript("console.error('Unknown network operation: " + operation + "');", QString()); + m_mainFrame->evaluateJavaScript("console.error('Unknown network operation: " + operation + "');"); return; } @@ -1350,7 +1349,7 @@ QString getHeaderFooter(const QVariantMap& map, const QString& key, QWebFrame* f } } } - frame->evaluateJavaScript("console.error('Bad header callback given, use phantom.callback);", QString()); + frame->evaluateJavaScript("console.error('Bad header callback given, use phantom.callback);"); return QString(); } @@ -1389,7 +1388,7 @@ bool WebPage::injectJs(const QString& jsFilePath) void WebPage::_appendScriptElement(const QString& scriptUrl) { - m_currentFrame->evaluateJavaScript(QString(JS_APPEND_SCRIPT_ELEMENT).arg(scriptUrl), scriptUrl); + m_currentFrame->evaluateJavaScript(QString(JS_APPEND_SCRIPT_ELEMENT).arg(scriptUrl)); } QObject* WebPage::_getGenericCallback() diff --git a/src/webpage.h b/src/webpage.h index 55920e718d..4a3e67efde 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -46,7 +46,7 @@ class NetworkAccessManager; class QWebInspector; class Phantom; -class WebPage : public QObject, public QWebFrame::PrintCallback +class WebPage : public QObject { Q_OBJECT Q_PROPERTY(QString title READ title)