mirror of https://github.com/vitalif/phantomjs
Migrate page settings to PhantomConfig
parent
a445b2d7b9
commit
f5f436160c
|
@ -55,10 +55,6 @@ Phantom::Phantom(QObject *parent)
|
|||
m_page = new WebPage(this);
|
||||
m_pages.append(m_page);
|
||||
|
||||
bool autoLoadImages = true;
|
||||
bool pluginsEnabled = false;
|
||||
bool localAccessRemote = false;
|
||||
|
||||
// second argument: script name
|
||||
QStringList args = QApplication::arguments();
|
||||
|
||||
|
@ -75,19 +71,19 @@ Phantom::Phantom(QObject *parent)
|
|||
return;
|
||||
}
|
||||
if (arg == "--load-images=yes") {
|
||||
autoLoadImages = true;
|
||||
m_config.setAutoLoadImages(true);
|
||||
continue;
|
||||
}
|
||||
if (arg == "--load-images=no") {
|
||||
autoLoadImages = false;
|
||||
m_config.setAutoLoadImages(false);
|
||||
continue;
|
||||
}
|
||||
if (arg == "--load-plugins=yes") {
|
||||
pluginsEnabled = true;
|
||||
m_config.setPluginsEnabled(true);
|
||||
continue;
|
||||
}
|
||||
if (arg == "--load-plugins=no") {
|
||||
pluginsEnabled = false;
|
||||
m_config.setPluginsEnabled(false);
|
||||
continue;
|
||||
}
|
||||
if (arg == "--disk-cache=yes") {
|
||||
|
@ -107,11 +103,11 @@ Phantom::Phantom(QObject *parent)
|
|||
continue;
|
||||
}
|
||||
if (arg == "--local-access-remote=no") {
|
||||
localAccessRemote = false;
|
||||
m_config.setLocalAccessRemote(false);
|
||||
continue;
|
||||
}
|
||||
if (arg == "--local-access-remote=yes") {
|
||||
localAccessRemote = true;
|
||||
m_config.setLocalAccessRemote(true);
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--proxy=")) {
|
||||
|
@ -171,12 +167,12 @@ Phantom::Phantom(QObject *parent)
|
|||
connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)),
|
||||
SLOT(printConsoleMessage(QString, int, QString)));
|
||||
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOAD_IMAGES] = QVariant::fromValue(autoLoadImages);
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOAD_PLUGINS] = QVariant::fromValue(pluginsEnabled);
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOAD_IMAGES] = QVariant::fromValue(m_config.autoLoadImages());
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOAD_PLUGINS] = QVariant::fromValue(m_config.pluginsEnabled());
|
||||
m_defaultPageSettings[PAGE_SETTINGS_JS_ENABLED] = QVariant::fromValue(true);
|
||||
m_defaultPageSettings[PAGE_SETTINGS_XSS_AUDITING] = QVariant::fromValue(false);
|
||||
m_defaultPageSettings[PAGE_SETTINGS_USER_AGENT] = QVariant::fromValue(m_page->userAgent());
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE] = QVariant::fromValue(localAccessRemote);
|
||||
m_defaultPageSettings[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE] = QVariant::fromValue(m_config.localAccessRemote());
|
||||
m_page->applySettings(m_defaultPageSettings);
|
||||
|
||||
setLibraryPath(QFileInfo(m_scriptFile).dir().absolutePath());
|
||||
|
|
|
@ -41,6 +41,16 @@ void PhantomConfig::load()
|
|||
resetToDefaults();
|
||||
}
|
||||
|
||||
bool PhantomConfig::autoLoadImages() const
|
||||
{
|
||||
return m_autoLoadImages;
|
||||
}
|
||||
|
||||
void PhantomConfig::setAutoLoadImages(const bool value)
|
||||
{
|
||||
m_autoLoadImages = value;
|
||||
}
|
||||
|
||||
QString PhantomConfig::cookieFile() const
|
||||
{
|
||||
return m_cookieFile;
|
||||
|
@ -71,6 +81,16 @@ void PhantomConfig::setIgnoreSslErrors(const bool value)
|
|||
m_ignoreSslErrors = value;
|
||||
}
|
||||
|
||||
bool PhantomConfig::localAccessRemote() const
|
||||
{
|
||||
return m_localAccessRemote;
|
||||
}
|
||||
|
||||
void PhantomConfig::setLocalAccessRemote(const bool value)
|
||||
{
|
||||
m_localAccessRemote = value;
|
||||
}
|
||||
|
||||
QString PhantomConfig::outputEncoding() const
|
||||
{
|
||||
return m_outputEncoding;
|
||||
|
@ -85,6 +105,16 @@ void PhantomConfig::setOutputEncoding(const QString &value)
|
|||
m_outputEncoding = value;
|
||||
}
|
||||
|
||||
bool PhantomConfig::pluginsEnabled() const
|
||||
{
|
||||
return m_pluginsEnabled;
|
||||
}
|
||||
|
||||
void PhantomConfig::setPluginsEnabled(const bool value)
|
||||
{
|
||||
m_pluginsEnabled = value;
|
||||
}
|
||||
|
||||
void PhantomConfig::setProxy(const QString &value)
|
||||
{
|
||||
QString proxyHost = value;
|
||||
|
@ -130,10 +160,13 @@ void PhantomConfig::setScriptEncoding(const QString &value)
|
|||
// private:
|
||||
void PhantomConfig::resetToDefaults()
|
||||
{
|
||||
m_autoLoadImages = true;
|
||||
m_cookieFile = QString();
|
||||
m_diskCacheEnabled = false;
|
||||
m_ignoreSslErrors = false;
|
||||
m_localAccessRemote = false;
|
||||
m_outputEncoding = "UTF-8";
|
||||
m_pluginsEnabled = false;
|
||||
m_proxyHost = QString();
|
||||
m_proxyPort = 1080;
|
||||
m_scriptEncoding = "UTF-8";
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
|
||||
void load();
|
||||
|
||||
bool autoLoadImages() const;
|
||||
void setAutoLoadImages(const bool value);
|
||||
|
||||
QString cookieFile() const;
|
||||
void setCookieFile(const QString &cookieFile);
|
||||
|
||||
|
@ -49,9 +52,15 @@ public:
|
|||
bool ignoreSslErrors() const;
|
||||
void setIgnoreSslErrors(const bool value);
|
||||
|
||||
bool localAccessRemote() const;
|
||||
void setLocalAccessRemote(const bool value);
|
||||
|
||||
QString outputEncoding() const;
|
||||
void setOutputEncoding(const QString &value);
|
||||
|
||||
bool pluginsEnabled() const;
|
||||
void setPluginsEnabled(const bool value);
|
||||
|
||||
void setProxy(const QString &value);
|
||||
QString proxyHost() const;
|
||||
int proxyPort() const;
|
||||
|
@ -64,10 +73,13 @@ private:
|
|||
void setProxyHost(const QString &value);
|
||||
void setProxyPort(const int value);
|
||||
|
||||
bool m_autoLoadImages;
|
||||
QString m_cookieFile;
|
||||
bool m_diskCacheEnabled;
|
||||
bool m_ignoreSslErrors;
|
||||
bool m_localAccessRemote;
|
||||
QString m_outputEncoding;
|
||||
bool m_pluginsEnabled;
|
||||
QString m_proxyHost;
|
||||
int m_proxyPort;
|
||||
QString m_scriptEncoding;
|
||||
|
|
Loading…
Reference in New Issue