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

Commit

Permalink
Format the code using clang-format (#15404)
Browse files Browse the repository at this point in the history
clang-format -i --style=WebKit src/*.h src/*.cpp
  • Loading branch information
ariya committed Jan 8, 2020
1 parent 07243f4 commit 699510f
Show file tree
Hide file tree
Showing 30 changed files with 313 additions and 334 deletions.
3 changes: 1 addition & 2 deletions src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include <QObject>
#include <QVariant>

class Callback : public QObject
{
class Callback : public QObject {
Q_OBJECT

Q_PROPERTY(QVariant returnValue READ returnValue WRITE setReturnValue)
Expand Down
9 changes: 4 additions & 5 deletions src/childprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ bool ChildProcessContext::_start(const QString& cmd, const QStringList& args)
return m_proc.waitForStarted(1000);
}

qint64 ChildProcessContext::_write(const QString &chunk, const QString &encoding)
qint64 ChildProcessContext::_write(const QString& chunk, const QString& encoding)
{
// Try to get codec for encoding
QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1());
QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1());

// If unavailable, attempt UTF-8 codec
if ((QTextCodec *)NULL == codec) {
if ((QTextCodec*)NULL == codec) {
codec = QTextCodec::codecForName("UTF-8");

// Don't even try to write if UTF-8 codec is unavailable
if ((QTextCodec *)NULL == codec) {
if ((QTextCodec*)NULL == codec) {
return -1;
}
}
Expand Down Expand Up @@ -139,7 +139,6 @@ void ChildProcessContext::_error(const QProcess::ProcessError error)
emit exit(m_proc.exitCode());
}


//
// ChildProcess
//
Expand Down
8 changes: 3 additions & 5 deletions src/childprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
/**
* This class wraps a QProcess and facilitates emulation of node.js's ChildProcess
*/
class ChildProcessContext : public QObject
{
class ChildProcessContext : public QObject {
Q_OBJECT
Q_PROPERTY(qint64 pid READ pid)

Expand All @@ -57,7 +56,7 @@ class ChildProcessContext : public QObject
Q_INVOKABLE void _setEncoding(const QString& encoding);
Q_INVOKABLE bool _start(const QString& cmd, const QStringList& args);

Q_INVOKABLE qint64 _write(const QString &chunk, const QString &encoding);
Q_INVOKABLE qint64 _write(const QString& chunk, const QString& encoding);
Q_INVOKABLE void _close();

signals:
Expand Down Expand Up @@ -86,8 +85,7 @@ private slots:
/**
* Helper class for child_process module
*/
class ChildProcess : public QObject
{
class ChildProcess : public QObject {
Q_OBJECT

public:
Expand Down
14 changes: 5 additions & 9 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@

#include <QDir>
#include <QFileInfo>
#include <QtWebKitWidgets/QWebPage>
#include <QtWebKitWidgets/QWebFrame>
#include <QNetworkProxy>
#include <QtWebKitWidgets/QWebFrame>
#include <QtWebKitWidgets/QWebPage>

#include "terminal.h"
#include "consts.h"
#include "qcommandline.h"
#include "terminal.h"
#include "utils.h"
#include "consts.h"

#include <iostream>


static const struct QCommandLineConfigEntry flags[] = {
{ QCommandLine::Option, '\0', "cookies-file", "Sets the file name to store the persistent cookies", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "config", "Specifies JSON-formatted configuration file", QCommandLine::Optional },
Expand Down Expand Up @@ -76,7 +75,7 @@ static const struct QCommandLineConfigEntry flags[] = {
{ QCommandLine::Option, '\0', "ssl-client-certificate-file", "Sets the location of a client certificate", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-client-key-file", "Sets the location of a clients' private key", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "ssl-client-key-passphrase", "Sets the passphrase for the clients' private key", QCommandLine::Optional },
{ QCommandLine::Param, '\0', "script", "Script", QCommandLine::Flags(QCommandLine::Optional | QCommandLine::ParameterFence)},
{ QCommandLine::Param, '\0', "script", "Script", QCommandLine::Flags(QCommandLine::Optional | QCommandLine::ParameterFence) },
{ QCommandLine::Param, '\0', "argument", "Script argument", QCommandLine::OptionalMultiple },
{ QCommandLine::Switch, 'h', "help", "Shows this message and quits", QCommandLine::Optional },
{ QCommandLine::Switch, 'v', "version", "Prints out PhantomJS version", QCommandLine::Optional },
Expand Down Expand Up @@ -117,7 +116,6 @@ void Config::processArgs(const QStringList& args)
m_cmdLine->setArguments(args);
m_cmdLine->setConfig(flags);
m_cmdLine->parse();

}

void Config::loadJsonFile(const QString& filePath)
Expand Down Expand Up @@ -198,7 +196,6 @@ void Config::setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota)
m_offlineStorageDefaultQuota = offlineStorageDefaultQuota * 1024;
}


QString Config::localStoragePath() const
{
return m_localStoragePath;
Expand Down Expand Up @@ -478,7 +475,6 @@ bool Config::javascriptCanCloseWindows() const
return m_javascriptCanCloseWindows;
}


// private:
void Config::resetToDefaults()
{
Expand Down
5 changes: 2 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <QNetworkProxy>
#include <QString>
#include <QStringList>
#include <QNetworkProxy>
#include <QVariant>

class QCommandLine;

class Config: public QObject
{
class Config : public QObject {
Q_OBJECT
Q_PROPERTY(QString cookiesFile READ cookiesFile WRITE setCookiesFile)
Q_PROPERTY(bool diskCacheEnabled READ diskCacheEnabled WRITE setDiskCacheEnabled)
Expand Down
60 changes: 30 additions & 30 deletions src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@
#ifndef CONSTS_H
#define CONSTS_H

#define PHANTOMJS_VERSION_MAJOR 3
#define PHANTOMJS_VERSION_MINOR 0
#define PHANTOMJS_VERSION_PATCH 0
#define PHANTOMJS_VERSION_STRING "3.0.0-development"
#define PHANTOMJS_VERSION_MAJOR 3
#define PHANTOMJS_VERSION_MINOR 0
#define PHANTOMJS_VERSION_PATCH 0
#define PHANTOMJS_VERSION_STRING "3.0.0-development"

#define HTTP_HEADER_CONTENT_LENGTH "content-length"
#define HTTP_HEADER_CONTENT_TYPE "content-type"
#define HTTP_HEADER_CONTENT_LENGTH "content-length"
#define HTTP_HEADER_CONTENT_TYPE "content-type"

#define JAVASCRIPT_SOURCE_PLATFORM_URL "phantomjs://platform/%1"
#define JAVASCRIPT_SOURCE_CODE_URL "phantomjs://code/%1"
#define JAVASCRIPT_SOURCE_PLATFORM_URL "phantomjs://platform/%1"
#define JAVASCRIPT_SOURCE_CODE_URL "phantomjs://code/%1"

#define JS_ELEMENT_CLICK "(function (el) { " \
"var ev = document.createEvent('MouseEvents');" \
"ev.initEvent(\"click\", true, true);" \
"el.dispatchEvent(ev);" \
"})(this);"
#define JS_ELEMENT_CLICK "(function (el) { " \
"var ev = document.createEvent('MouseEvents');" \
"ev.initEvent(\"click\", true, true);" \
"el.dispatchEvent(ev);" \
"})(this);"

#define JS_APPEND_SCRIPT_ELEMENT "var el = document.createElement('script');" \
"el.onload = function() { alert('%1'); };" \
"el.src = '%1';" \
"document.body.appendChild(el);"
"el.onload = function() { alert('%1'); };" \
"el.src = '%1';" \
"document.body.appendChild(el);"

#define PAGE_SETTINGS_LOAD_IMAGES "loadImages"
#define PAGE_SETTINGS_JS_ENABLED "javascriptEnabled"
#define PAGE_SETTINGS_XSS_AUDITING "XSSAuditingEnabled"
#define PAGE_SETTINGS_USER_AGENT "userAgent"
#define PAGE_SETTINGS_PROXY "proxy"
#define PAGE_SETTINGS_LOCAL_ACCESS_REMOTE "localToRemoteUrlAccessEnabled"
#define PAGE_SETTINGS_USERNAME "userName"
#define PAGE_SETTINGS_PASSWORD "password"
#define PAGE_SETTINGS_MAX_AUTH_ATTEMPTS "maxAuthAttempts"
#define PAGE_SETTINGS_RESOURCE_TIMEOUT "resourceTimeout"
#define PAGE_SETTINGS_WEB_SECURITY_ENABLED "webSecurityEnabled"
#define PAGE_SETTINGS_JS_CAN_OPEN_WINDOWS "javascriptCanOpenWindows"
#define PAGE_SETTINGS_JS_CAN_CLOSE_WINDOWS "javascriptCanCloseWindows"
#define PAGE_SETTINGS_DPI "dpi"
#define PAGE_SETTINGS_LOAD_IMAGES "loadImages"
#define PAGE_SETTINGS_JS_ENABLED "javascriptEnabled"
#define PAGE_SETTINGS_XSS_AUDITING "XSSAuditingEnabled"
#define PAGE_SETTINGS_USER_AGENT "userAgent"
#define PAGE_SETTINGS_PROXY "proxy"
#define PAGE_SETTINGS_LOCAL_ACCESS_REMOTE "localToRemoteUrlAccessEnabled"
#define PAGE_SETTINGS_USERNAME "userName"
#define PAGE_SETTINGS_PASSWORD "password"
#define PAGE_SETTINGS_MAX_AUTH_ATTEMPTS "maxAuthAttempts"
#define PAGE_SETTINGS_RESOURCE_TIMEOUT "resourceTimeout"
#define PAGE_SETTINGS_WEB_SECURITY_ENABLED "webSecurityEnabled"
#define PAGE_SETTINGS_JS_CAN_OPEN_WINDOWS "javascriptCanOpenWindows"
#define PAGE_SETTINGS_JS_CAN_CLOSE_WINDOWS "javascriptCanCloseWindows"
#define PAGE_SETTINGS_DPI "dpi"

#endif // CONSTS_H
39 changes: 19 additions & 20 deletions src/cookiejar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "phantom.h"
#include "config.h"
#include "cookiejar.h"
#include "config.h"
#include "phantom.h"

#include <QDateTime>
#include <QDataStream>
#include <QDateTime>
#include <QSettings>
#include <QTimer>

#define COOKIE_JAR_VERSION 1
#define COOKIE_JAR_VERSION 1

// Operators needed for Cookie Serialization
QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -133,12 +133,11 @@ bool CookieJar::addCookie(const QNetworkCookie& cookie, const QString& url)
// Save a single cookie
isCookieAdded = setCookiesFromUrl(
QList<QNetworkCookie>() << cookie, //< unfortunately, "setCookiesFromUrl" requires a list
!url.isEmpty() ?
url : //< use given URL
QString( //< mock-up a URL
(cookie.isSecure() ? "https://" : "http://") + //< URL protocol
QString(cookie.domain().startsWith('.') ? "www" : "") + cookie.domain() + //< URL domain
(cookie.path().isEmpty() ? "/" : cookie.path()))); //< URL path
!url.isEmpty() ? url : //< use given URL
QString( //< mock-up a URL
(cookie.isSecure() ? "https://" : "http://") + //< URL protocol
QString(cookie.domain().startsWith('.') ? "www" : "") + cookie.domain() + //< URL domain
(cookie.path().isEmpty() ? "/" : cookie.path()))); //< URL path

// Return "true" if the cookie was really set
if (contains(cookie)) {
Expand Down Expand Up @@ -315,11 +314,11 @@ bool CookieJar::deleteCookie(const QString& name, const QString& url)
QList<QNetworkCookie> cookiesListAll;

if (url.isEmpty()) {
if (name.isEmpty()) { //< Neither "name" or "url" provided
if (name.isEmpty()) { //< Neither "name" or "url" provided
// This method has been used wrong:
// "redirecting" to the right method for the job
clearCookies();
} else { //< Only "name" provided
} else { //< Only "name" provided
// Delete all cookies with the given name from the CookieJar
cookiesListAll = allCookies();
for (int i = cookiesListAll.length() - 1; i >= 0; --i) {
Expand All @@ -337,8 +336,8 @@ bool CookieJar::deleteCookie(const QString& name, const QString& url)
QList<QNetworkCookie> cookiesListUrl = cookies(url);
cookiesListAll = allCookies();
for (int i = cookiesListAll.length() - 1; i >= 0; --i) {
if (cookiesListUrl.contains(cookiesListAll.at(i)) && //< if it part of the set of cookies visible at URL
(cookiesListAll.at(i).name() == name || name.isEmpty())) { //< and if the name matches, or no name provided
if (cookiesListUrl.contains(cookiesListAll.at(i)) && //< if it part of the set of cookies visible at URL
(cookiesListAll.at(i).name() == name || name.isEmpty())) { //< and if the name matches, or no name provided
// Remove this cookie
qDebug() << "CookieJar - Deleted" << cookiesListAll.at(i).toRawForm();
cookiesListAll.removeAt(i);
Expand Down Expand Up @@ -462,14 +461,14 @@ void CookieJar::save()
purgeExpiredCookies();

#ifndef QT_NO_DEBUG_OUTPUT
foreach(QNetworkCookie cookie, allCookies()) {
foreach (QNetworkCookie cookie, allCookies()) {
qDebug() << "CookieJar - Saved" << cookie.toRawForm();
}
#endif

// Store cookies
if (m_cookieStorage) {
m_cookieStorage->setValue(QLatin1String("cookies"), QVariant::fromValue<QList<QNetworkCookie> >(allCookies()));
m_cookieStorage->setValue(QLatin1String("cookies"), QVariant::fromValue<QList<QNetworkCookie>>(allCookies()));
}
}
}
Expand All @@ -478,11 +477,11 @@ void CookieJar::load()
{
if (isEnabled()) {
// Register a "StreamOperator" for this Meta Type, so we can easily serialize/deserialize the cookies
qRegisterMetaTypeStreamOperators<QList<QNetworkCookie> >("QList<QNetworkCookie>");
qRegisterMetaTypeStreamOperators<QList<QNetworkCookie>>("QList<QNetworkCookie>");

// Load all the cookies
if (m_cookieStorage) {
setAllCookies(qvariant_cast<QList<QNetworkCookie> >(m_cookieStorage->value(QLatin1String("cookies"))));
setAllCookies(qvariant_cast<QList<QNetworkCookie>>(m_cookieStorage->value(QLatin1String("cookies"))));
}

// If any cookie has expired since last execution, purge and save before going any further
Expand All @@ -491,7 +490,7 @@ void CookieJar::load()
}

#ifndef QT_NO_DEBUG_OUTPUT
foreach(QNetworkCookie cookie, allCookies()) {
foreach (QNetworkCookie cookie, allCookies()) {
qDebug() << "CookieJar - Loaded" << cookie.toRawForm();
}
#endif
Expand All @@ -501,7 +500,7 @@ void CookieJar::load()
bool CookieJar::contains(const QNetworkCookie& cookieToFind) const
{
QList<QNetworkCookie> cookiesList = allCookies();
foreach(QNetworkCookie cookie, cookiesList) {
foreach (QNetworkCookie cookie, cookiesList) {
if (cookieToFind == cookie) {
return true;
}
Expand Down
5 changes: 2 additions & 3 deletions src/cookiejar.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
#ifndef COOKIEJAR_H
#define COOKIEJAR_H

#include <QSettings>
#include <QNetworkCookie>
#include <QNetworkCookieJar>
#include <QSettings>
#include <QVariantList>
#include <QVariantMap>

class CookieJar: public QNetworkCookieJar
{
class CookieJar : public QNetworkCookieJar {
Q_OBJECT

Q_PROPERTY(QVariantList cookies READ cookiesToMap WRITE addCookiesFromMap)
Expand Down
Loading

0 comments on commit 699510f

Please sign in to comment.