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