2011-02-19 03:53:06 +00:00
|
|
|
#include "WebPage.h"
|
2012-03-26 22:41:33 +00:00
|
|
|
#include "WebPageManager.h"
|
2011-02-26 03:57:55 +00:00
|
|
|
#include "JavascriptInvocation.h"
|
2011-06-08 09:36:45 +00:00
|
|
|
#include "NetworkAccessManager.h"
|
2011-09-24 21:25:15 +00:00
|
|
|
#include "NetworkCookieJar.h"
|
2011-09-15 15:22:10 +00:00
|
|
|
#include "UnsupportedContentHandler.h"
|
2013-01-20 23:57:04 +00:00
|
|
|
#include "InvocationResult.h"
|
2012-11-18 07:48:12 +00:00
|
|
|
#include "NetworkReplyProxy.h"
|
2011-02-26 03:32:22 +00:00
|
|
|
#include <QResource>
|
2011-02-26 18:02:43 +00:00
|
|
|
#include <iostream>
|
2012-03-30 01:38:34 +00:00
|
|
|
#include <QWebSettings>
|
2012-03-27 22:49:57 +00:00
|
|
|
#include <QUuid>
|
2013-11-09 20:12:16 +00:00
|
|
|
#include <QApplication>
|
2014-06-18 22:00:34 +00:00
|
|
|
#include <QWebView>
|
|
|
|
#include <QMainWindow>
|
2011-02-19 03:53:06 +00:00
|
|
|
|
2012-03-29 03:05:24 +00:00
|
|
|
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
2012-03-30 19:00:51 +00:00
|
|
|
m_loading = false;
|
2012-07-11 03:03:32 +00:00
|
|
|
m_failed = false;
|
2012-04-04 19:40:18 +00:00
|
|
|
m_manager = manager;
|
2012-03-30 19:00:51 +00:00
|
|
|
m_uuid = QUuid::createUuid().toString();
|
2014-07-03 22:21:21 +00:00
|
|
|
m_confirmAction = true;
|
|
|
|
m_promptAction = false;
|
2017-01-04 00:33:42 +00:00
|
|
|
m_currentFrameParent = 0;
|
2012-04-04 19:40:18 +00:00
|
|
|
|
2011-09-15 15:22:10 +00:00
|
|
|
setForwardUnsupportedContent(true);
|
2011-08-12 19:49:40 +00:00
|
|
|
loadJavascript();
|
2011-08-12 19:26:26 +00:00
|
|
|
setUserStylesheet();
|
2011-08-12 19:49:40 +00:00
|
|
|
|
2011-08-23 15:18:08 +00:00
|
|
|
this->setCustomNetworkAccessManager();
|
2011-08-12 19:49:40 +00:00
|
|
|
|
|
|
|
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
|
|
|
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
|
|
|
|
connect(this, SIGNAL(frameCreated(QWebFrame *)),
|
|
|
|
this, SLOT(frameCreated(QWebFrame *)));
|
2011-09-15 15:22:10 +00:00
|
|
|
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
|
|
|
|
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
2014-06-18 22:00:34 +00:00
|
|
|
connect(this, SIGNAL(windowCloseRequested()), this, SLOT(remove()));
|
2012-03-26 22:41:33 +00:00
|
|
|
|
|
|
|
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
|
2014-06-18 22:00:34 +00:00
|
|
|
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
|
|
|
|
settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
|
|
|
|
|
2013-05-02 07:54:09 +00:00
|
|
|
if(QFileInfo("tmp").isDir()) {
|
|
|
|
settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
|
|
|
|
settings()->setOfflineWebApplicationCachePath("tmp");
|
|
|
|
}
|
2014-06-18 22:00:34 +00:00
|
|
|
|
|
|
|
createWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::createWindow() {
|
|
|
|
QSize size(1680, 1050);
|
|
|
|
setViewportSize(size);
|
2012-03-29 17:01:02 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 22:00:34 +00:00
|
|
|
void WebPage::resize(int width, int height) {
|
|
|
|
QSize size(width, height);
|
|
|
|
setViewportSize(size);
|
2011-08-12 19:49:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 03:00:21 +00:00
|
|
|
void WebPage::resetLocalStorage() {
|
|
|
|
this->currentFrame()->evaluateJavaScript("localStorage.clear()");
|
|
|
|
}
|
|
|
|
|
2011-08-23 15:18:08 +00:00
|
|
|
void WebPage::setCustomNetworkAccessManager() {
|
2013-03-18 12:11:59 +00:00
|
|
|
setNetworkAccessManager(m_manager->networkAccessManager());
|
|
|
|
connect(networkAccessManager(), SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
|
|
|
|
SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
|
|
|
|
connect(networkAccessManager(), SIGNAL(requestCreated(QByteArray &, QNetworkReply *)),
|
2012-12-04 03:47:10 +00:00
|
|
|
SIGNAL(requestCreated(QByteArray &, QNetworkReply *)));
|
2013-03-18 12:11:59 +00:00
|
|
|
connect(networkAccessManager(), SIGNAL(finished(QUrl &, QNetworkReply *)),
|
|
|
|
SLOT(replyFinished(QUrl &, QNetworkReply *)));
|
2012-11-18 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::replyFinished(QUrl &requestedUrl, QNetworkReply *reply) {
|
|
|
|
NetworkReplyProxy *proxy = qobject_cast<NetworkReplyProxy *>(reply);
|
|
|
|
setFrameProperties(mainFrame(), requestedUrl, proxy);
|
|
|
|
foreach(QWebFrame *frame, mainFrame()->childFrames())
|
|
|
|
setFrameProperties(frame, requestedUrl, proxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::setFrameProperties(QWebFrame *frame, QUrl &requestedUrl, NetworkReplyProxy *reply) {
|
|
|
|
if (frame->requestedUrl() == requestedUrl) {
|
|
|
|
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
frame->setProperty("statusCode", statusCode);
|
2015-05-15 14:32:22 +00:00
|
|
|
if (statusCode != 304) {
|
|
|
|
QVariantMap headers;
|
|
|
|
foreach(QNetworkReply::RawHeaderPair header, reply->rawHeaderPairs())
|
|
|
|
headers[header.first] = QString(header.second);
|
|
|
|
frame->setProperty("headers", headers);
|
|
|
|
frame->setProperty("body", reply->data());
|
|
|
|
QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
|
|
|
|
frame->setProperty("contentType", contentMimeType);
|
|
|
|
}
|
2012-11-18 07:48:12 +00:00
|
|
|
}
|
2012-06-29 14:41:08 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 03:47:10 +00:00
|
|
|
void WebPage::unsupportedContentFinishedReply(QNetworkReply *reply) {
|
|
|
|
m_manager->replyFinished(reply);
|
2011-08-23 15:18:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 19:49:40 +00:00
|
|
|
void WebPage::loadJavascript() {
|
2011-02-26 03:32:22 +00:00
|
|
|
QResource javascript(":/capybara.js");
|
2011-05-03 22:12:10 +00:00
|
|
|
if (javascript.isCompressed()) {
|
|
|
|
QByteArray uncompressedBytes(qUncompress(javascript.data(), javascript.size()));
|
|
|
|
m_capybaraJavascript = QString(uncompressedBytes);
|
|
|
|
} else {
|
|
|
|
char * javascriptString = new char[javascript.size() + 1];
|
|
|
|
strcpy(javascriptString, (const char *)javascript.data());
|
|
|
|
javascriptString[javascript.size()] = 0;
|
|
|
|
m_capybaraJavascript = javascriptString;
|
|
|
|
}
|
2011-04-19 07:16:25 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 19:26:26 +00:00
|
|
|
void WebPage::setUserStylesheet() {
|
2013-01-13 21:08:30 +00:00
|
|
|
QString data = QString("*, :before, :after { font-family: 'Arial' ! important; }").toUtf8().toBase64();
|
2011-08-12 19:26:26 +00:00
|
|
|
QUrl url = QUrl(QString("data:text/css;charset=utf-8;base64,") + data);
|
|
|
|
settings()->setUserStyleSheetUrl(url);
|
|
|
|
}
|
|
|
|
|
2011-06-08 09:36:45 +00:00
|
|
|
QString WebPage::userAgentForUrl(const QUrl &url ) const {
|
2011-06-25 11:31:19 +00:00
|
|
|
if (!m_userAgent.isEmpty()) {
|
|
|
|
return m_userAgent;
|
2011-06-08 09:36:45 +00:00
|
|
|
} else {
|
|
|
|
return QWebPage::userAgentForUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-30 01:48:15 +00:00
|
|
|
QVariantList WebPage::consoleMessages() {
|
|
|
|
return m_consoleMessages;
|
2011-10-31 17:53:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 19:41:23 +00:00
|
|
|
QVariantList WebPage::alertMessages() {
|
|
|
|
return m_alertMessages;
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 19:28:45 +00:00
|
|
|
QVariantList WebPage::confirmMessages() {
|
|
|
|
return m_confirmMessages;
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 20:04:44 +00:00
|
|
|
QVariantList WebPage::promptMessages() {
|
|
|
|
return m_promptMessages;
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 11:31:19 +00:00
|
|
|
void WebPage::setUserAgent(QString userAgent) {
|
|
|
|
m_userAgent = userAgent;
|
2011-06-08 09:36:45 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:16:25 +00:00
|
|
|
void WebPage::frameCreated(QWebFrame * frame) {
|
|
|
|
connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
|
|
|
|
this, SLOT(injectJavascriptHelpers()));
|
2011-02-26 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::injectJavascriptHelpers() {
|
2011-04-19 07:16:25 +00:00
|
|
|
QWebFrame* frame = qobject_cast<QWebFrame *>(QObject::sender());
|
|
|
|
frame->evaluateJavaScript(m_capybaraJavascript);
|
2011-02-19 03:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPage::shouldInterruptJavaScript() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-06 15:43:17 +00:00
|
|
|
InvocationResult WebPage::invokeCapybaraFunction(const char *name, bool allowUnattached, const QStringList &arguments) {
|
2011-02-26 03:57:55 +00:00
|
|
|
QString qname(name);
|
2013-12-06 15:43:17 +00:00
|
|
|
JavascriptInvocation invocation(qname, allowUnattached, arguments, this);
|
2013-01-20 23:57:04 +00:00
|
|
|
return invocation.invoke(currentFrame());
|
2011-02-26 03:57:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 15:43:17 +00:00
|
|
|
InvocationResult WebPage::invokeCapybaraFunction(QString &name, bool allowUnattached, const QStringList &arguments) {
|
|
|
|
return invokeCapybaraFunction(name.toLatin1().data(), allowUnattached, arguments);
|
2011-02-26 04:39:29 +00:00
|
|
|
}
|
|
|
|
|
2011-02-26 18:02:43 +00:00
|
|
|
void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
|
2012-12-30 01:48:15 +00:00
|
|
|
QVariantMap m;
|
|
|
|
m["message"] = message;
|
2012-11-21 01:17:42 +00:00
|
|
|
QString fullMessage = QString(message);
|
2012-12-30 01:48:15 +00:00
|
|
|
if (!sourceID.isEmpty()) {
|
2012-11-21 01:17:42 +00:00
|
|
|
fullMessage = sourceID + "|" + QString::number(lineNumber) + "|" + fullMessage;
|
2012-12-30 01:48:15 +00:00
|
|
|
m["source"] = sourceID;
|
|
|
|
m["line_number"] = lineNumber;
|
|
|
|
}
|
|
|
|
m_consoleMessages.append(m);
|
2012-11-22 15:30:43 +00:00
|
|
|
m_manager->logger() << qPrintable(fullMessage);
|
2011-02-26 18:02:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 17:07:30 +00:00
|
|
|
void WebPage::javaScriptAlert(QWebFrame *frame, const QString &message) {
|
|
|
|
Q_UNUSED(frame);
|
2012-07-10 13:47:17 +00:00
|
|
|
m_alertMessages.append(message);
|
2014-07-03 22:21:21 +00:00
|
|
|
|
|
|
|
if (m_modalResponses.isEmpty()) {
|
|
|
|
m_modalMessages << QString();
|
|
|
|
} else {
|
|
|
|
QVariantMap alertResponse = m_modalResponses.takeLast();
|
|
|
|
bool expectedType = alertResponse["type"].toString() == "alert";
|
|
|
|
QRegExp expectedMessage = alertResponse["message"].toRegExp();
|
|
|
|
|
|
|
|
addModalMessage(expectedType, message, expectedMessage);
|
|
|
|
}
|
|
|
|
|
2012-11-22 15:30:43 +00:00
|
|
|
m_manager->logger() << "ALERT:" << qPrintable(message);
|
2011-03-11 17:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &message) {
|
|
|
|
Q_UNUSED(frame);
|
2012-07-10 13:47:17 +00:00
|
|
|
m_confirmMessages.append(message);
|
2014-07-03 22:21:21 +00:00
|
|
|
|
|
|
|
if (m_modalResponses.isEmpty()) {
|
|
|
|
m_modalMessages << QString();
|
|
|
|
return m_confirmAction;
|
|
|
|
} else {
|
|
|
|
QVariantMap confirmResponse = m_modalResponses.takeLast();
|
|
|
|
bool expectedType = confirmResponse["type"].toString() == "confirm";
|
|
|
|
QRegExp expectedMessage = confirmResponse["message"].toRegExp();
|
|
|
|
|
|
|
|
addModalMessage(expectedType, message, expectedMessage);
|
|
|
|
return expectedType &&
|
|
|
|
confirmResponse["action"].toBool() &&
|
|
|
|
message.contains(expectedMessage);
|
|
|
|
}
|
2011-03-11 17:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result) {
|
|
|
|
Q_UNUSED(frame)
|
2012-07-10 13:47:17 +00:00
|
|
|
m_promptMessages.append(message);
|
2014-07-03 22:21:21 +00:00
|
|
|
|
|
|
|
bool action = false;
|
|
|
|
QString response;
|
|
|
|
|
|
|
|
if (m_modalResponses.isEmpty()) {
|
|
|
|
action = m_promptAction;
|
|
|
|
response = m_prompt_text;
|
|
|
|
m_modalMessages << QString();
|
|
|
|
} else {
|
|
|
|
QVariantMap promptResponse = m_modalResponses.takeLast();
|
|
|
|
bool expectedType = promptResponse["type"].toString() == "prompt";
|
|
|
|
QRegExp expectedMessage = promptResponse["message"].toRegExp();
|
|
|
|
|
|
|
|
action = expectedType &&
|
|
|
|
promptResponse["action"].toBool() &&
|
|
|
|
message.contains(expectedMessage);
|
|
|
|
response = promptResponse["response"].toString();
|
|
|
|
addModalMessage(expectedType, message, expectedMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
if (response.isNull()) {
|
2012-07-10 13:47:17 +00:00
|
|
|
*result = defaultValue;
|
|
|
|
} else {
|
2014-07-03 22:21:21 +00:00
|
|
|
*result = response;
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-03 22:21:21 +00:00
|
|
|
|
|
|
|
return action;
|
2011-03-11 17:07:30 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 05:08:30 +00:00
|
|
|
void WebPage::loadStarted() {
|
|
|
|
m_loading = true;
|
2017-01-04 00:33:42 +00:00
|
|
|
m_currentFrameParent = currentFrame()->parentFrame();
|
2012-04-04 01:27:41 +00:00
|
|
|
m_errorPageMessage = QString();
|
2011-03-09 05:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::loadFinished(bool success) {
|
2012-07-11 03:03:32 +00:00
|
|
|
Q_UNUSED(success);
|
2011-03-09 05:08:30 +00:00
|
|
|
m_loading = false;
|
2012-07-11 03:03:32 +00:00
|
|
|
emit pageFinished(!m_failed);
|
|
|
|
m_failed = false;
|
2011-03-09 05:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPage::isLoading() const {
|
|
|
|
return m_loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebPage::failureString() {
|
2012-04-04 01:27:41 +00:00
|
|
|
QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
|
2012-04-26 20:05:19 +00:00
|
|
|
if (m_errorPageMessage.isEmpty())
|
2012-04-04 01:27:41 +00:00
|
|
|
return message;
|
|
|
|
else
|
2012-04-26 20:05:19 +00:00
|
|
|
return message + m_errorPageMessage;
|
2011-03-09 05:08:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 20:12:16 +00:00
|
|
|
void WebPage::mouseEvent(QEvent::Type type, const QPoint &position, Qt::MouseButton button) {
|
|
|
|
m_mousePosition = position;
|
|
|
|
QMouseEvent event(type, position, button, button, Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(this, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebPage::clickTest(QWebElement element, int absoluteX, int absoluteY) {
|
|
|
|
QPoint mousePos(absoluteX, absoluteY);
|
|
|
|
m_mousePosition = mousePos;
|
|
|
|
QWebHitTestResult res = mainFrame()->hitTestContent(mousePos);
|
|
|
|
return res.frame() == element.webFrame();
|
|
|
|
}
|
|
|
|
|
2013-01-13 22:19:46 +00:00
|
|
|
bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
|
2011-05-26 19:05:16 +00:00
|
|
|
QFileInfo fileInfo(fileName);
|
|
|
|
QDir dir;
|
|
|
|
dir.mkpath(fileInfo.absolutePath());
|
|
|
|
|
|
|
|
QSize viewportSize = this->viewportSize();
|
2013-01-13 22:19:46 +00:00
|
|
|
this->setViewportSize(minimumSize);
|
2011-05-26 19:05:16 +00:00
|
|
|
QSize pageSize = this->mainFrame()->contentsSize();
|
|
|
|
if (pageSize.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage buffer(pageSize, QImage::Format_ARGB32);
|
|
|
|
buffer.fill(qRgba(255, 255, 255, 0));
|
|
|
|
|
|
|
|
QPainter p(&buffer);
|
|
|
|
p.setRenderHint( QPainter::Antialiasing, true);
|
|
|
|
p.setRenderHint( QPainter::TextAntialiasing, true);
|
|
|
|
p.setRenderHint( QPainter::SmoothPixmapTransform, true);
|
|
|
|
|
|
|
|
this->setViewportSize(pageSize);
|
|
|
|
this->mainFrame()->render(&p);
|
2013-11-09 20:12:16 +00:00
|
|
|
|
|
|
|
QImage pointer = QImage(":/pointer.png");
|
|
|
|
p.drawImage(m_mousePosition, pointer);
|
|
|
|
|
2011-05-26 19:05:16 +00:00
|
|
|
p.end();
|
|
|
|
this->setViewportSize(viewportSize);
|
|
|
|
|
|
|
|
return buffer.save(fileName);
|
|
|
|
}
|
2011-07-18 21:16:57 +00:00
|
|
|
|
|
|
|
QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile) {
|
|
|
|
Q_UNUSED(parentFrame);
|
|
|
|
Q_UNUSED(suggestedFile);
|
|
|
|
|
2012-11-18 07:48:24 +00:00
|
|
|
return getAttachedFileNames().first();
|
2011-07-18 21:16:57 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 19:58:23 +00:00
|
|
|
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
|
|
|
|
if (extension == ChooseMultipleFilesExtension) {
|
2012-11-18 07:48:24 +00:00
|
|
|
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = getAttachedFileNames();
|
2011-07-20 19:58:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 01:27:41 +00:00
|
|
|
else if (extension == QWebPage::ErrorPageExtension) {
|
|
|
|
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
|
2012-04-26 20:05:19 +00:00
|
|
|
m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
|
2012-07-11 03:03:32 +00:00
|
|
|
m_failed = true;
|
2012-04-04 01:27:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-07-20 19:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-18 07:48:24 +00:00
|
|
|
QStringList WebPage::getAttachedFileNames() {
|
|
|
|
return currentFrame()->evaluateJavaScript(QString("Capybara.attachedFiles")).toStringList();
|
2011-07-20 19:58:23 +00:00
|
|
|
}
|
2011-08-12 20:50:43 +00:00
|
|
|
|
2012-05-04 17:56:21 +00:00
|
|
|
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
|
2012-11-18 07:48:12 +00:00
|
|
|
Q_UNUSED(errors);
|
2012-03-30 19:00:51 +00:00
|
|
|
if (m_manager->ignoreSslErrors())
|
2012-11-18 07:48:12 +00:00
|
|
|
reply->ignoreSslErrors();
|
2011-09-27 19:31:03 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 01:38:34 +00:00
|
|
|
void WebPage::setSkipImageLoading(bool skip) {
|
|
|
|
settings()->setAttribute(QWebSettings::AutoLoadImages, !skip);
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:50:43 +00:00
|
|
|
int WebPage::getLastStatus() {
|
2012-11-18 07:48:12 +00:00
|
|
|
return currentFrame()->property("statusCode").toInt();
|
|
|
|
}
|
|
|
|
|
2015-02-08 23:09:55 +00:00
|
|
|
QVariantMap WebPage::pageHeaders() {
|
|
|
|
return currentFrame()->property("headers").toMap();
|
2011-08-12 20:50:43 +00:00
|
|
|
}
|
2011-08-19 15:57:39 +00:00
|
|
|
|
2012-11-18 07:48:12 +00:00
|
|
|
QByteArray WebPage::body() {
|
|
|
|
return currentFrame()->property("body").toByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebPage::contentType() {
|
|
|
|
return currentFrame()->property("contentType").toString();
|
2012-11-22 05:21:40 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 15:22:10 +00:00
|
|
|
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
|
2012-07-11 03:03:32 +00:00
|
|
|
QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
|
|
|
|
if(!contentMimeType.isNull()) {
|
|
|
|
triggerAction(QWebPage::Stop);
|
|
|
|
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
|
2012-07-12 03:36:22 +00:00
|
|
|
if (reply->isFinished())
|
|
|
|
handler->renderNonHtmlContent();
|
|
|
|
else
|
|
|
|
handler->waitForReplyToFinish();
|
2012-07-11 03:03:32 +00:00
|
|
|
}
|
2011-09-15 15:22:10 +00:00
|
|
|
}
|
2012-03-26 22:41:33 +00:00
|
|
|
|
2012-04-26 20:05:19 +00:00
|
|
|
bool WebPage::supportsExtension(Extension extension) const {
|
|
|
|
if (extension == ErrorPageExtension)
|
|
|
|
return true;
|
|
|
|
else if (extension == ChooseMultipleFilesExtension)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-26 22:41:33 +00:00
|
|
|
QWebPage *WebPage::createWindow(WebWindowType type) {
|
|
|
|
Q_UNUSED(type);
|
2014-06-18 22:00:34 +00:00
|
|
|
return m_manager->createPage();
|
2012-03-26 22:41:33 +00:00
|
|
|
}
|
2012-03-27 22:49:57 +00:00
|
|
|
|
|
|
|
QString WebPage::uuid() {
|
|
|
|
return m_uuid;
|
|
|
|
}
|
2012-03-28 15:46:07 +00:00
|
|
|
|
|
|
|
QString WebPage::getWindowName() {
|
|
|
|
QVariant windowName = mainFrame()->evaluateJavaScript("window.name");
|
|
|
|
|
|
|
|
if (windowName.isValid())
|
|
|
|
return windowName.toString();
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
2012-03-28 19:20:32 +00:00
|
|
|
|
|
|
|
bool WebPage::matchesWindowSelector(QString selector) {
|
|
|
|
return (selector == getWindowName() ||
|
|
|
|
selector == mainFrame()->title() ||
|
|
|
|
selector == mainFrame()->url().toString() ||
|
|
|
|
selector == uuid());
|
|
|
|
}
|
2012-04-04 22:18:17 +00:00
|
|
|
|
|
|
|
void WebPage::setFocus() {
|
|
|
|
m_manager->setCurrentPage(this);
|
|
|
|
}
|
2012-07-10 13:47:17 +00:00
|
|
|
|
2014-06-18 22:00:34 +00:00
|
|
|
void WebPage::remove() {
|
|
|
|
m_manager->removePage(this);
|
|
|
|
}
|
|
|
|
|
2014-07-03 22:21:21 +00:00
|
|
|
QString WebPage::setConfirmAction(QString action, QString message) {
|
|
|
|
QVariantMap confirmResponse;
|
|
|
|
confirmResponse["type"] = "confirm";
|
|
|
|
confirmResponse["action"] = (action=="Yes");
|
|
|
|
confirmResponse["message"] = QRegExp(message);
|
|
|
|
m_modalResponses << confirmResponse;
|
|
|
|
return QString::number(m_modalResponses.length());
|
|
|
|
}
|
|
|
|
|
2012-07-10 13:47:17 +00:00
|
|
|
void WebPage::setConfirmAction(QString action) {
|
2014-07-03 22:21:21 +00:00
|
|
|
m_confirmAction = (action == "Yes");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebPage::setPromptAction(QString action, QString message, QString response) {
|
|
|
|
QVariantMap promptResponse;
|
|
|
|
promptResponse["type"] = "prompt";
|
|
|
|
promptResponse["action"] = (action == "Yes");
|
|
|
|
promptResponse["message"] = QRegExp(message);
|
|
|
|
promptResponse["response"] = response;
|
|
|
|
m_modalResponses << promptResponse;
|
|
|
|
return QString::number(m_modalResponses.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebPage::setPromptAction(QString action, QString message) {
|
|
|
|
return setPromptAction(action, message, QString());
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::setPromptAction(QString action) {
|
2014-07-03 22:21:21 +00:00
|
|
|
m_promptAction = (action == "Yes");
|
2012-07-10 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::setPromptText(QString text) {
|
|
|
|
m_prompt_text = text;
|
|
|
|
}
|
|
|
|
|
2014-07-03 22:21:21 +00:00
|
|
|
QString WebPage::acceptAlert(QString message) {
|
|
|
|
QVariantMap alertResponse;
|
|
|
|
alertResponse["type"] = "alert";
|
|
|
|
alertResponse["message"] = QRegExp(message);
|
|
|
|
m_modalResponses << alertResponse;
|
|
|
|
return QString::number(m_modalResponses.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebPage::modalCount() {
|
|
|
|
return m_modalMessages.length();
|
|
|
|
}
|
|
|
|
|
2014-10-03 02:47:43 +00:00
|
|
|
QString WebPage::modalMessage() {
|
|
|
|
return m_modalMessages.takeFirst();
|
2014-07-03 22:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::addModalMessage(bool expectedType, const QString &message, const QRegExp &expectedMessage) {
|
|
|
|
if (expectedType && message.contains(expectedMessage))
|
|
|
|
m_modalMessages << message;
|
|
|
|
else
|
|
|
|
m_modalMessages << QString();
|
2014-10-03 02:47:43 +00:00
|
|
|
emit modalReady();
|
2014-07-03 22:21:21 +00:00
|
|
|
}
|
2017-01-04 00:33:42 +00:00
|
|
|
|
|
|
|
QWebFrame* WebPage::currentFrameParent() {
|
|
|
|
return m_currentFrameParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPage::setCurrentFrameParent(QWebFrame* frame) {
|
|
|
|
m_currentFrameParent = frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|