mirror of https://github.com/vitalif/phantomjs
commit
3ef660466d
|
@ -48,4 +48,9 @@
|
||||||
"el.src = '%1';" \
|
"el.src = '%1';" \
|
||||||
"document.body.appendChild(el);"
|
"document.body.appendChild(el);"
|
||||||
|
|
||||||
|
#define PAGE_SETTINGS_LOAD_IMAGES "loadImages"
|
||||||
|
#define PAGE_SETTINGS_LOAD_PLUGINS "loadPlugins"
|
||||||
|
#define PAGE_SETTINGS_USER_AGENT "userAgent"
|
||||||
|
#define PAGE_SETTINGS_LOCAL_ACCESS_REMOTE "localAccessRemote"
|
||||||
|
|
||||||
#endif // CONSTS_H
|
#endif // CONSTS_H
|
||||||
|
|
|
@ -57,6 +57,7 @@ Phantom::Phantom(QObject *parent)
|
||||||
bool pluginsEnabled = false;
|
bool pluginsEnabled = false;
|
||||||
bool diskCacheEnabled = false;
|
bool diskCacheEnabled = false;
|
||||||
bool ignoreSslErrors = false;
|
bool ignoreSslErrors = false;
|
||||||
|
bool localAccessRemote = false;
|
||||||
|
|
||||||
// second argument: script name
|
// second argument: script name
|
||||||
QStringList args = QApplication::arguments();
|
QStringList args = QApplication::arguments();
|
||||||
|
@ -105,6 +106,14 @@ Phantom::Phantom(QObject *parent)
|
||||||
ignoreSslErrors = false;
|
ignoreSslErrors = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (arg == "--local-access-remote=no") {
|
||||||
|
localAccessRemote = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (arg == "--local-access-remote=yes") {
|
||||||
|
localAccessRemote = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (arg.startsWith("--proxy=")) {
|
if (arg.startsWith("--proxy=")) {
|
||||||
proxyHost = arg.mid(8).trimmed();
|
proxyHost = arg.mid(8).trimmed();
|
||||||
if (proxyHost.lastIndexOf(':') > 0) {
|
if (proxyHost.lastIndexOf(':') > 0) {
|
||||||
|
@ -154,9 +163,10 @@ Phantom::Phantom(QObject *parent)
|
||||||
connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)),
|
connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)),
|
||||||
SLOT(printConsoleMessage(QString, int, QString)));
|
SLOT(printConsoleMessage(QString, int, QString)));
|
||||||
|
|
||||||
m_defaultPageSettings["loadImages"] = QVariant::fromValue(autoLoadImages);
|
m_defaultPageSettings[PAGE_SETTINGS_LOAD_IMAGES] = QVariant::fromValue(autoLoadImages);
|
||||||
m_defaultPageSettings["loadPlugins"] = QVariant::fromValue(pluginsEnabled);
|
m_defaultPageSettings[PAGE_SETTINGS_LOAD_PLUGINS] = QVariant::fromValue(pluginsEnabled);
|
||||||
m_defaultPageSettings["userAgent"] = QVariant::fromValue(m_page->userAgent());
|
m_defaultPageSettings[PAGE_SETTINGS_USER_AGENT] = QVariant::fromValue(m_page->userAgent());
|
||||||
|
m_defaultPageSettings[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE] = QVariant::fromValue(localAccessRemote);
|
||||||
m_page->applySettings(m_defaultPageSettings);
|
m_page->applySettings(m_defaultPageSettings);
|
||||||
|
|
||||||
setLibraryPath(QFileInfo(m_scriptFile).dir().absolutePath());
|
setLibraryPath(QFileInfo(m_scriptFile).dir().absolutePath());
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
Usage: phantomjs [options] script.[js|coffee] [script argument [script argument ...]]
|
Usage: phantomjs [options] script.[js|coffee] [script argument [script argument ...]]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--load-images=[yes|no] Load all inlined images (default is 'yes').
|
--version Prints out PhantomJS version
|
||||||
--load-plugins=[yes|no] Load all plugins (i.e. 'Flash', 'Silverlight', ...) (default is 'no').
|
--load-images=[yes|no] Loads all inlined images (default is 'yes').
|
||||||
--proxy=address:port Set the network proxy.
|
--load-plugins=[yes|no] Loads all plugins (i.e. 'Flash', 'Silverlight', ...) (default is 'no').
|
||||||
--disk-cache=[yes|no] Enable disk cache (at desktop services cache storage location, default is 'no').
|
--proxy=address:port Sets the network proxy (e.g. "--proxy=http://192.168.1.42:8080").
|
||||||
--ignore-ssl-errors=[yes|no] Ignore SSL errors (i.e. expired or self-signed certificate errors).
|
--disk-cache=[yes|no] Enables disk cache (at desktop services cache storage location, default is 'no').
|
||||||
|
--ignore-ssl-errors=[yes|no] Ignores SSL errors (i.e. expired or self-signed certificate errors).
|
||||||
|
--local-access-remote=[yes|no] Local content can access remote URL (default is 'no').
|
||||||
|
|
|
@ -117,18 +117,28 @@ WebPage::WebPage(QObject *parent)
|
||||||
m_mainFrame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
|
m_mainFrame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
|
||||||
m_mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
|
m_mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
|
// Offline Storage Database
|
||||||
m_webPage->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
|
m_webPage->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
|
||||||
m_webPage->settings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
m_webPage->settings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||||
|
|
||||||
m_webPage->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
||||||
|
// OfflineWebApplicationCacheEnabled
|
||||||
|
m_webPage->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
|
||||||
|
m_webPage->settings()->setOfflineWebApplicationCachePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||||
|
#endif
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
|
||||||
|
// Frame Flattening
|
||||||
m_webPage->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true);
|
m_webPage->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
|
||||||
|
// Local Storage
|
||||||
m_webPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
|
m_webPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
|
||||||
m_webPage->settings()->setLocalStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
m_webPage->settings()->setLocalStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||||
|
#else
|
||||||
|
// Local Storage Database (deprecated /superseded in Qt >= 4.6.0)
|
||||||
|
m_webPage->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ensure we have at least document.body.
|
// Ensure we have at least document.body.
|
||||||
|
@ -176,11 +186,12 @@ void WebPage::applySettings(const QVariantMap &def)
|
||||||
{
|
{
|
||||||
QWebSettings *opt = m_webPage->settings();
|
QWebSettings *opt = m_webPage->settings();
|
||||||
|
|
||||||
opt->setAttribute(QWebSettings::AutoLoadImages, def["loadImages"].toBool());
|
opt->setAttribute(QWebSettings::AutoLoadImages, def[PAGE_SETTINGS_LOAD_IMAGES].toBool());
|
||||||
opt->setAttribute(QWebSettings::PluginsEnabled, def["loadPlugins"].toBool());
|
opt->setAttribute(QWebSettings::PluginsEnabled, def[PAGE_SETTINGS_LOAD_PLUGINS].toBool());
|
||||||
|
opt->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, def[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE].toBool());
|
||||||
|
|
||||||
if (def.contains("userAgent"))
|
if (def.contains(PAGE_SETTINGS_USER_AGENT))
|
||||||
m_webPage->m_userAgent = def["userAgent"].toString();
|
m_webPage->m_userAgent = def[PAGE_SETTINGS_USER_AGENT].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebPage::userAgent() const
|
QString WebPage::userAgent() const
|
||||||
|
|
Loading…
Reference in New Issue