Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Adjust some API for the latest QtWebKit (#15341)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Dec 25, 2019
1 parent 974393e commit 10a3d93
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/modules/webpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function definePageSignalHandler(page, handlers, handlerName, signalName) {
return !!handlers[handlerName] && typeof handlers[handlerName].callback === "function" ?
handlers[handlerName].callback :
undefined;
}
},
configurable: true
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
);
}

Expand Down
7 changes: 3 additions & 4 deletions src/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/webpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 10a3d93

Please sign in to comment.