mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Move window change handling into WebPageManager
This commit is contained in:
parent
baf21c99ef
commit
bfbda84141
8 changed files with 26 additions and 17 deletions
|
@ -16,7 +16,6 @@ class Command : public QObject {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished(Response *response);
|
void finished(Response *response);
|
||||||
void windowChanged(WebPage *);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WebPage *page();
|
WebPage *page();
|
||||||
|
|
|
@ -19,7 +19,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
|
||||||
m_commandWaiting = false;
|
m_commandWaiting = false;
|
||||||
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
|
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
|
||||||
connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
|
connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
|
||||||
connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::commandReady(Command *command) {
|
void Connection::commandReady(Command *command) {
|
||||||
|
@ -35,7 +35,6 @@ void Connection::startCommand() {
|
||||||
if (m_pageSuccess) {
|
if (m_pageSuccess) {
|
||||||
m_runningCommand = new PageLoadingCommand(m_queuedCommand, currentPage(), this);
|
m_runningCommand = new PageLoadingCommand(m_queuedCommand, currentPage(), this);
|
||||||
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
|
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
|
||||||
connect(m_queuedCommand, SIGNAL(windowChanged(WebPage *)), this, SLOT(changeWindow(WebPage *)));
|
|
||||||
m_runningCommand->start();
|
m_runningCommand->start();
|
||||||
} else {
|
} else {
|
||||||
writePageLoadFailure();
|
writePageLoadFailure();
|
||||||
|
@ -72,12 +71,6 @@ void Connection::writeResponse(Response *response) {
|
||||||
delete response;
|
delete response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::changeWindow(WebPage *page) {
|
|
||||||
disconnect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
|
||||||
m_manager->setCurrentPage(page);
|
|
||||||
connect(currentPage(), SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
|
||||||
}
|
|
||||||
|
|
||||||
WebPage *Connection::currentPage() {
|
WebPage *Connection::currentPage() {
|
||||||
return m_manager->currentPage();
|
return m_manager->currentPage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ class Connection : public QObject {
|
||||||
void commandReady(Command *command);
|
void commandReady(Command *command);
|
||||||
void finishCommand(Response *response);
|
void finishCommand(Response *response);
|
||||||
void pendingLoadFinished(bool success);
|
void pendingLoadFinished(bool success);
|
||||||
void changeWindow(WebPage *);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startCommand();
|
void startCommand();
|
||||||
|
|
|
@ -19,5 +19,5 @@ quint16 Server::server_port() const {
|
||||||
|
|
||||||
void Server::handleConnection() {
|
void Server::handleConnection() {
|
||||||
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
|
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
|
||||||
new Connection(socket, new WebPageManager(), this);
|
new Connection(socket, new WebPageManager(this), this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
||||||
|
m_manager = manager;
|
||||||
|
|
||||||
setForwardUnsupportedContent(true);
|
setForwardUnsupportedContent(true);
|
||||||
loadJavascript();
|
loadJavascript();
|
||||||
setUserStylesheet();
|
setUserStylesheet();
|
||||||
|
@ -24,13 +26,13 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
||||||
this, SLOT(frameCreated(QWebFrame *)));
|
this, SLOT(frameCreated(QWebFrame *)));
|
||||||
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
|
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
|
||||||
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
||||||
|
connect(this, SIGNAL(pageFinished(bool)),
|
||||||
|
m_manager, SLOT(emitPageFinished(bool)));
|
||||||
resetWindowSize();
|
resetWindowSize();
|
||||||
|
|
||||||
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
|
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
|
||||||
|
|
||||||
m_uuid = QUuid::createUuid().toString();
|
m_uuid = QUuid::createUuid().toString();
|
||||||
|
|
||||||
m_manager = manager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::resetWindowSize() {
|
void WebPage::resetWindowSize() {
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
#include "WebPage.h"
|
#include "WebPage.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
WebPageManager::WebPageManager() {
|
WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
|
||||||
|
m_currentPage = NULL;
|
||||||
|
m_ignoreSslErrors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPageManager::append(WebPage *value) {
|
void WebPageManager::append(WebPage *value) {
|
||||||
|
@ -26,3 +28,8 @@ WebPage *WebPageManager::createPage(QObject *parent) {
|
||||||
append(page);
|
append(page);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPageManager::emitPageFinished(bool success) {
|
||||||
|
if (currentPage() == sender())
|
||||||
|
emit pageFinished(success);
|
||||||
|
}
|
||||||
|
|
|
@ -5,18 +5,27 @@
|
||||||
|
|
||||||
class WebPage;
|
class WebPage;
|
||||||
|
|
||||||
class WebPageManager {
|
class WebPageManager : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WebPageManager();
|
WebPageManager(QObject *parent = 0);
|
||||||
void append(WebPage *value);
|
void append(WebPage *value);
|
||||||
QListIterator<WebPage *> iterator();
|
QListIterator<WebPage *> iterator();
|
||||||
void setCurrentPage(WebPage *);
|
void setCurrentPage(WebPage *);
|
||||||
WebPage *currentPage();
|
WebPage *currentPage();
|
||||||
WebPage *createPage(QObject *);
|
WebPage *createPage(QObject *);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void emitPageFinished(bool);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void pageFinished(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<WebPage *> m_pages;
|
QList<WebPage *> m_pages;
|
||||||
WebPage *m_currentPage;
|
WebPage *m_currentPage;
|
||||||
|
bool m_ignoreSslErrors;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WEBPAGEMANAGER_H
|
#endif // _WEBPAGEMANAGER_H
|
||||||
|
|
|
@ -16,7 +16,7 @@ void WindowFocus::windowNotFound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowFocus::success(WebPage *page) {
|
void WindowFocus::success(WebPage *page) {
|
||||||
emit windowChanged(page);
|
((CommandFactory *) parent())->m_manager->setCurrentPage(page);
|
||||||
emit finished(new Response(true));
|
emit finished(new Response(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue