On 10/11/15 21:38, Ximin Luo wrote:
>
> Attached is the patch, please review. I will tidy up the Debian package then
> file it upstream. I am unsure about certain things, for example:
>
> - The "webSecurity" option now has no effect, because it's not exposed in Qt
> 5.5. I'm not sure if this has any practical implications.
> - in cookiejar.cpp I replaced a quint32 with effectively a uint. Not sure if
> this is a security concern, I'm not a C++ guy.
>
> But hey at least it works. :)
>
Whoops, I've attached the patch for real this time. Also a second patch to make
the build script work. For some reason debhelper wants to set MAKEFLAGS=w...
X
--
GPG: 4096R/1318EFAC5FBBDBCE
git://github.com/infinity0/pubkeys.git
diff --git a/src/config.cpp b/src/config.cpp
index 1f38c1e..e056812 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -176,7 +176,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/cookiejar.cpp b/src/cookiejar.cpp
index 9f01ebf..16839b2 100644
--- a/src/cookiejar.cpp
+++ b/src/cookiejar.cpp
@@ -39,31 +39,31 @@
#define COOKIE_JAR_VERSION 1
// Operators needed for Cookie Serialization
-QT_BEGIN_NAMESPACE
-QDataStream& operator<<(QDataStream& stream, const QList<QNetworkCookie>& list)
+
+QDataStream &operator<<(QDataStream& stream, const QList<QNetworkCookie>& list)
{
- stream << COOKIE_JAR_VERSION;
- stream << quint32(list.size());
+ stream << QVariant(COOKIE_JAR_VERSION);
+ stream << QVariant(list.size());
for (int i = 0; i < list.size(); ++i) {
stream << list.at(i).toRawForm();
}
return stream;
}
-QDataStream& operator>>(QDataStream& stream, QList<QNetworkCookie>& list)
+QDataStream &operator>>(QDataStream& stream, QList<QNetworkCookie>& list)
{
list.clear();
- quint32 version;
+ QVariant version;
stream >> version;
- if (version != COOKIE_JAR_VERSION) {
+ if (version.toUInt() != COOKIE_JAR_VERSION) {
return stream;
}
- quint32 count;
+ QVariant count;
stream >> count;
- for (quint32 i = 0; i < count; ++i) {
+ for (quint32 i = 0; i < count.toUInt(); ++i) {
QByteArray value;
stream >> value;
QList<QNetworkCookie> newCookies = QNetworkCookie::parseCookies(value);
@@ -79,7 +79,6 @@ QDataStream& operator>>(QDataStream& stream, QList<QNetworkCookie>& list)
}
return stream;
}
-QT_END_NAMESPACE
// public:
CookieJar::CookieJar(QString cookiesFile, QObject* parent)
diff --git a/src/cookiejar.h b/src/cookiejar.h
index 1ced25a..f23bb9e 100644
--- a/src/cookiejar.h
+++ b/src/cookiejar.h
@@ -36,6 +36,12 @@
#include <QNetworkCookieJar>
#include <QVariantList>
#include <QVariantMap>
+#include <QDataStream>
+
+QT_BEGIN_NAMESPACE
+QDataStream& operator<<(QDataStream& stream, const QList<QNetworkCookie>& list);
+QDataStream& operator<<(QDataStream& stream, const QList<QNetworkCookie>& list);
+QT_END_NAMESPACE
class CookieJar: public QNetworkCookieJar
{
diff --git a/src/phantom.cpp b/src/phantom.cpp
index 08b836e..e7cb56d 100644
--- a/src/phantom.cpp
+++ b/src/phantom.cpp
@@ -377,7 +377,7 @@ void Phantom::loadModule(const QString& moduleSource, const QString& filename)
"require.cache['" + filename + "'].exports," +
"require.cache['" + filename + "']" +
"));";
- m_page->mainFrame()->evaluateJavaScript(scriptSource, "");
+ m_page->mainFrame()->evaluateJavaScript(scriptSource);
}
bool Phantom::injectJs(const QString& jsFilePath)
@@ -447,8 +447,7 @@ void Phantom::onInitialized()
// Bootstrap the PhantomJS scope
m_page->mainFrame()->evaluateJavaScript(
- Utils::readResourceFileUtf8(":/bootstrap.js"),
- QString("phantomjs://bootstrap.js")
+ Utils::readResourceFileUtf8(":/bootstrap.js")
);
}
diff --git a/src/phantomjs.pro b/src/phantomjs.pro
index a658803..8e1e919 100644
--- a/src/phantomjs.pro
+++ b/src/phantomjs.pro
@@ -1,11 +1,7 @@
-if(!equals(QT_MAJOR_VERSION, 5)|!equals(QT_MINOR_VERSION, 4)) {
- error("This program can only be compiled with Qt 5.4.x.")
-}
-
TEMPLATE = app
TARGET = phantomjs
-QT += network webkitwidgets
+QT += core network webkitwidgets printsupport
CONFIG += console
DESTDIR = ../bin
diff --git a/src/repl.cpp b/src/repl.cpp
index dfffff8..7f25a22 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("phantomjs://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 42de4d0..47ddec4 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -133,7 +133,7 @@ bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, c
return false;
}
// Execute JS code in the context of the document
- targetFrame->evaluateJavaScript(scriptBody, jsFilePath);
+ targetFrame->evaluateJavaScript(scriptBody);
return true;
}
@@ -151,7 +151,7 @@ bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, co
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 630774d..61a2394 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -360,13 +360,6 @@ WebPage::WebPage(QObject* parent, const QUrl& baseUrl)
m_customWebPage = new CustomPage(this);
Config* phantomCfg = Phantom::instance()->config();
- // To grant universal access to a web page
- // attribute "WebSecurityEnabled" must be applied during the initializing
- // security context for Document instance. Setting up it later will not cause any effect
- // see <qt\src\3rdparty\webkit\Source\WebCore\dom\Document.cpp:4468>
- QWebSettings* settings = m_customWebPage->settings();
- settings->setAttribute(QWebSettings::WebSecurityEnabled, phantomCfg->webSecurityEnabled());
-
m_mainFrame = m_customWebPage->mainFrame();
m_currentFrame = m_mainFrame;
m_mainFrame->setHtml(BLANK_HTML, baseUrl);
@@ -613,7 +606,6 @@ void WebPage::applySettings(const QVariantMap& def)
opt->setAttribute(QWebSettings::JavascriptEnabled, def[PAGE_SETTINGS_JS_ENABLED].toBool());
opt->setAttribute(QWebSettings::XSSAuditingEnabled, def[PAGE_SETTINGS_XSS_AUDITING].toBool());
opt->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, def[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE].toBool());
- opt->setAttribute(QWebSettings::WebSecurityEnabled, def[PAGE_SETTINGS_WEB_SECURITY_ENABLED].toBool());
opt->setAttribute(QWebSettings::JavascriptCanOpenWindows, def[PAGE_SETTINGS_JS_CAN_OPEN_WINDOWS].toBool());
opt->setAttribute(QWebSettings::JavascriptCanCloseWindows, def[PAGE_SETTINGS_JS_CAN_CLOSE_WINDOWS].toBool());
@@ -729,8 +721,8 @@ 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 //< function evaluated
+ ); //< reference source file
qDebug() << "WebPage - evaluateJavaScript result" << evalResult;
@@ -912,7 +904,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;
}
@@ -1243,7 +1235,7 @@ bool WebPage::renderPdf(const QString& fileName)
printer.setPageMargins(marginLeft, marginTop, marginRight, marginBottom, QPrinter::Point);
- m_mainFrame->print(&printer, this);
+ m_mainFrame->print(&printer);
return true;
}
@@ -1301,7 +1293,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();
}
@@ -1340,7 +1332,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 0873996..97ec1d3 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -45,7 +45,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)
--- a/build.sh
+++ b/build.sh
@@ -9,7 +9,7 @@
MAKEFLAGS_JOBS=''
if [[ "$MAKEFLAGS" != "" ]]; then
- MAKEFLAGS_JOBS=$(echo $MAKEFLAGS | egrep -o '\-j[0-9]+' | egrep -o '[0-9]+')
+ MAKEFLAGS_JOBS=$(echo $MAKEFLAGS | egrep -o '\-j[0-9]+' | egrep -o '[0-9]+' | cat)
fi
if [[ "$MAKEFLAGS_JOBS" != "" ]]; then