Permalink
Browse files

Merge in upstream changes.

  • Loading branch information...
1 parent 8d90b32 commit 360f0ec83a677fbf2a94b4e49ea7baa71988eade @tristandunn committed Jul 15, 2012
Showing with 1,038 additions and 326 deletions.
  1. +18 −0 src/Authenticate.cpp
  2. +12 −0 src/Authenticate.h
  3. +3 −5 src/Body.h
  4. +3 −5 src/ClearCookies.cpp
  5. +3 −5 src/ClearCookies.h
  6. +11 −0 src/ClearPromptText.cpp
  7. +9 −0 src/ClearPromptText.h
  8. +4 −15 src/Command.cpp
  9. +3 −14 src/Command.h
  10. +19 −6 src/CommandFactory.cpp
  11. +3 −2 src/CommandFactory.h
  12. +1 −1 src/CommandParser.cpp
  13. +22 −11 src/Connection.cpp
  14. +4 −2 src/Connection.h
  15. +2 −1 src/ConsoleMessages.cpp
  16. +3 −5 src/ConsoleMessages.h
  17. +2 −1 src/CurrentUrl.cpp
  18. +3 −5 src/CurrentUrl.h
  19. +10 −0 src/EnableLogging.cpp
  20. +12 −0 src/EnableLogging.h
  21. +2 −1 src/Evaluate.cpp
  22. +3 −5 src/Evaluate.h
  23. +2 −1 src/Execute.cpp
  24. +3 −5 src/Execute.h
  25. +7 −4 src/Find.cpp
  26. +3 −5 src/Find.h
  27. +3 −2 src/FrameFocus.cpp
  28. +3 −4 src/FrameFocus.h
  29. +3 −4 src/GetCookies.cpp
  30. +3 −5 src/GetCookies.h
  31. +11 −0 src/GetWindowHandle.cpp
  32. +10 −0 src/GetWindowHandle.h
  33. +20 −0 src/GetWindowHandles.cpp
  34. +10 −0 src/GetWindowHandles.h
  35. +2 −1 src/Header.cpp
  36. +3 −5 src/Header.h
  37. +2 −1 src/Headers.cpp
  38. +3 −5 src/Headers.h
  39. +13 −0 src/IgnoreSslErrors.cpp
  40. +10 −0 src/IgnoreSslErrors.h
  41. +10 −0 src/JavascriptAlertMessages.cpp
  42. +9 −0 src/JavascriptAlertMessages.h
  43. +10 −0 src/JavascriptConfirmMessages.cpp
  44. +9 −0 src/JavascriptConfirmMessages.h
  45. +1 −1 src/JavascriptInvocation.cpp
  46. +1 −1 src/JavascriptInvocation.h
  47. +10 −0 src/JavascriptPromptMessages.cpp
  48. +9 −0 src/JavascriptPromptMessages.h
  49. +19 −1 src/NetworkAccessManager.cpp
  50. +10 −0 src/NetworkAccessManager.h
  51. +6 −1 src/Node.cpp
  52. +4 −5 src/Node.h
  53. +5 −2 src/NullCommand.cpp
  54. +4 −3 src/NullCommand.h
  55. +12 −7 src/PageLoadingCommand.cpp
  56. +6 −9 src/PageLoadingCommand.h
  57. +2 −1 src/Render.cpp
  58. +3 −5 src/Render.h
  59. +2 −1 src/RequestedUrl.cpp
  60. +3 −5 src/RequestedUrl.h
  61. +3 −17 src/Reset.cpp
  62. +3 −8 src/Reset.h
  63. +2 −1 src/ResizeWindow.cpp
  64. +3 −5 src/ResizeWindow.h
  65. +3 −5 src/Server.cpp
  66. +1 −3 src/Server.h
  67. +11 −0 src/SetConfirmAction.cpp
  68. +9 −0 src/SetConfirmAction.h
  69. +3 −4 src/SetCookie.cpp
  70. +3 −5 src/SetCookie.h
  71. +11 −0 src/SetPromptAction.cpp
  72. +9 −0 src/SetPromptAction.h
  73. +11 −0 src/SetPromptText.cpp
  74. +9 −0 src/SetPromptText.h
  75. +2 −1 src/SetProxy.cpp
  76. +3 −5 src/SetProxy.h
  77. +12 −0 src/SetSkipImageLoading.cpp
  78. +9 −0 src/SetSkipImageLoading.h
  79. +21 −0 src/SocketCommand.cpp
  80. +29 −0 src/SocketCommand.h
  81. +2 −1 src/Source.cpp
  82. +3 −4 src/Source.h
  83. +2 −1 src/Status.cpp
  84. +3 −5 src/Status.h
  85. +6 −11 src/UnsupportedContentHandler.cpp
  86. +2 −2 src/UnsupportedContentHandler.h
  87. +2 −1 src/Url.cpp
  88. +3 −5 src/Url.h
  89. +3 −2 src/Visit.cpp
  90. +3 −5 src/Visit.h
  91. +138 −46 src/WebPage.cpp
  92. +37 −10 src/WebPage.h
  93. +117 −0 src/WebPageManager.cpp
  94. +56 −0 src/WebPageManager.h
  95. +32 −0 src/WindowFocus.cpp
  96. +15 −0 src/WindowFocus.h
  97. +2 −1 src/body.cpp
  98. +15 −2 src/find_command.h
  99. +1 −4 src/main.cpp
  100. +9 −4 src/webkit_server.js
  101. +32 −0 src/webkit_server.pro
View
18 src/Authenticate.cpp
@@ -0,0 +1,18 @@
+#include "Authenticate.h"
+#include "WebPage.h"
+#include "NetworkAccessManager.h"
+
+Authenticate::Authenticate(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
+}
+
+void Authenticate::start() {
+ QString username = arguments()[0];
+ QString password = arguments()[1];
+
+ NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
+ networkAccessManager->setUserName(username);
+ networkAccessManager->setPassword(password);
+
+ emit finished(new Response(true));
+}
+
View
12 src/Authenticate.h
@@ -0,0 +1,12 @@
+#include "SocketCommand.h"
+
+class WebPage;
+
+class Authenticate : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ Authenticate(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
+
View
8 src/Body.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Body : public Command {
+class Body : public SocketCommand {
Q_OBJECT
public:
- Body(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Body(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
8 src/ClearCookies.cpp
@@ -1,15 +1,13 @@
#include "ClearCookies.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include "NetworkCookieJar.h"
#include <QNetworkCookie>
-ClearCookies::ClearCookies(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
+ClearCookies::ClearCookies(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
void ClearCookies::start()
{
- NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
- ->networkAccessManager()
- ->cookieJar());
- jar->clearCookies();
+ manager()->cookieJar()->clearCookies();
emit finished(new Response(true));
}
View
8 src/ClearCookies.h
@@ -1,11 +1,9 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class ClearCookies : public Command {
+class ClearCookies : public SocketCommand {
Q_OBJECT;
public:
- ClearCookies(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ ClearCookies(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
11 src/ClearPromptText.cpp
@@ -0,0 +1,11 @@
+#include "ClearPromptText.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+ClearPromptText::ClearPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void ClearPromptText::start()
+{
+ page()->setPromptText(QString());
+ emit finished(new Response(true));
+}
View
9 src/ClearPromptText.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class ClearPromptText : public SocketCommand {
+ Q_OBJECT;
+
+ public:
+ ClearPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
19 src/Command.cpp
@@ -1,19 +1,8 @@
-#include "Command.h"
-#include "WebPage.h"
+#include "SocketCommand.h"
-Command::Command(WebPage *page, QStringList &arguments, QObject *parent) : QObject(parent) {
- m_page = page;
- m_arguments = arguments;
+Command::Command(QObject *parent) : QObject(parent) {
}
-void Command::start() {
+QString Command::toString() const {
+ return metaObject()->className();
}
-
-WebPage *Command::page() {
- return m_page;
-}
-
-QStringList &Command::arguments() {
- return m_arguments;
-}
-
View
17 src/Command.h
@@ -2,29 +2,18 @@
#define COMMAND_H
#include <QObject>
-#include <QStringList>
#include "Response.h"
-class WebPage;
-
class Command : public QObject {
Q_OBJECT
public:
- Command(WebPage *page, QStringList &arguments, QObject *parent = 0);
- virtual void start();
+ Command(QObject *parent = 0);
+ virtual void start() = 0;
+ virtual QString toString() const;
signals:
void finished(Response *response);
-
- protected:
- WebPage *page();
- QStringList &arguments();
-
- private:
- WebPage *m_page;
- QStringList m_arguments;
-
};
#endif
View
25 src/CommandFactory.cpp
@@ -1,8 +1,8 @@
#include "CommandFactory.h"
#include "NullCommand.h"
+#include "SocketCommand.h"
#include "Visit.h"
#include "Find.h"
-#include "Command.h"
#include "Reset.h"
#include "Node.h"
#include "Url.h"
@@ -23,14 +23,27 @@
#include "RequestedUrl.h"
#include "CurrentUrl.h"
#include "ResizeWindow.h"
+#include "IgnoreSslErrors.h"
+#include "SetSkipImageLoading.h"
+#include "WindowFocus.h"
+#include "GetWindowHandles.h"
+#include "GetWindowHandle.h"
+#include "WebPageManager.h"
+#include "Authenticate.h"
+#include "EnableLogging.h"
+#include "SetConfirmAction.h"
+#include "SetPromptAction.h"
+#include "SetPromptText.h"
+#include "ClearPromptText.h"
+#include "JavascriptAlertMessages.h"
+#include "JavascriptConfirmMessages.h"
+#include "JavascriptPromptMessages.h"
-CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
- m_page = page;
+CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) {
+ m_manager = manager;
}
Command *CommandFactory::createCommand(const char *name, QStringList &arguments) {
#include "find_command.h"
- arguments.clear();
- arguments.append(QString(name));
- return new NullCommand(m_page, arguments);
+ return new NullCommand(QString(name));
}
View
5 src/CommandFactory.h
@@ -2,15 +2,16 @@
class Command;
class WebPage;
+class WebPageManager;
class CommandFactory : public QObject {
Q_OBJECT
public:
- CommandFactory(WebPage *page, QObject *parent = 0);
+ CommandFactory(WebPageManager *, QObject *parent = 0);
Command *createCommand(const char *name, QStringList &arguments);
private:
- WebPage *m_page;
+ WebPageManager *m_manager;
};
View
2 src/CommandParser.cpp
@@ -1,6 +1,6 @@
#include "CommandParser.h"
#include "CommandFactory.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include <QIODevice>
View
33 src/Connection.cpp
@@ -1,37 +1,41 @@
#include "Connection.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include "CommandParser.h"
#include "CommandFactory.h"
#include "PageLoadingCommand.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include <QTcpSocket>
-Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
+Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *parent) :
QObject(parent) {
m_socket = socket;
- m_page = page;
- m_commandFactory = new CommandFactory(page, this);
+ m_manager = manager;
+ m_commandFactory = new CommandFactory(m_manager, this);
m_commandParser = new CommandParser(socket, m_commandFactory, this);
m_pageSuccess = true;
m_commandWaiting = false;
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
- connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
+ connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
void Connection::commandReady(Command *command) {
m_queuedCommand = command;
- if (m_page->isLoading())
+ m_manager->logger() << "Received" << command->toString();
+ if (m_manager->isLoading()) {
+ m_manager->logger() << command->toString() << "waiting for load to finish";
m_commandWaiting = true;
- else
+ } else {
startCommand();
+ }
}
void Connection::startCommand() {
m_commandWaiting = false;
if (m_pageSuccess) {
- m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_page, this);
+ m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this);
connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
m_runningCommand->start();
} else {
@@ -40,18 +44,20 @@ void Connection::startCommand() {
}
void Connection::pendingLoadFinished(bool success) {
- m_pageSuccess = success;
- if (m_commandWaiting)
+ m_pageSuccess = m_pageSuccess && success;
+ if (m_commandWaiting) {
startCommand();
+ }
}
void Connection::writePageLoadFailure() {
m_pageSuccess = true;
- QString message = m_page->failureString();
+ QString message = currentPage()->failureString();
writeResponse(new Response(false, message));
}
void Connection::finishCommand(Response *response) {
+ m_pageSuccess = true;
m_runningCommand->deleteLater();
writeResponse(response);
}
@@ -62,10 +68,15 @@ void Connection::writeResponse(Response *response) {
else
m_socket->write("failure\n");
+ m_manager->logger() << "Wrote response" << response->isSuccess() << response->message();
+
QByteArray messageUtf8 = response->message();
QString messageLength = QString::number(messageUtf8.size()) + "\n";
m_socket->write(messageLength.toAscii());
m_socket->write(messageUtf8);
delete response;
}
+WebPage *Connection::currentPage() {
+ return m_manager->currentPage();
+}
View
6 src/Connection.h
@@ -8,12 +8,13 @@ class Response;
class CommandParser;
class CommandFactory;
class PageLoadingCommand;
+class WebPageManager;
class Connection : public QObject {
Q_OBJECT
public:
- Connection(QTcpSocket *socket, WebPage *page, QObject *parent = 0);
+ Connection(QTcpSocket *socket, WebPageManager *manager, QObject *parent = 0);
public slots:
void commandReady(Command *command);
@@ -27,11 +28,12 @@ class Connection : public QObject {
QTcpSocket *m_socket;
Command *m_queuedCommand;
- WebPage *m_page;
+ WebPageManager *m_manager;
CommandParser *m_commandParser;
CommandFactory *m_commandFactory;
PageLoadingCommand *m_runningCommand;
bool m_pageSuccess;
bool m_commandWaiting;
+ WebPage *currentPage();
};
View
3 src/ConsoleMessages.cpp
@@ -1,7 +1,8 @@
#include "ConsoleMessages.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-ConsoleMessages::ConsoleMessages(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+ConsoleMessages::ConsoleMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void ConsoleMessages::start() {
View
8 src/ConsoleMessages.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class ConsoleMessages : public Command {
+class ConsoleMessages : public SocketCommand {
Q_OBJECT
public:
- ConsoleMessages(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ ConsoleMessages(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
3 src/CurrentUrl.cpp
@@ -1,7 +1,8 @@
#include "CurrentUrl.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-CurrentUrl::CurrentUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
/*
View
8 src/CurrentUrl.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class CurrentUrl : public Command {
+class CurrentUrl : public SocketCommand {
Q_OBJECT
public:
- CurrentUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
private:
View
10 src/EnableLogging.cpp
@@ -0,0 +1,10 @@
+#include "EnableLogging.h"
+#include "WebPageManager.h"
+
+EnableLogging::EnableLogging(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
+}
+
+void EnableLogging::start() {
+ manager()->enableLogging();
+ emit finished(new Response(true));
+}
View
12 src/EnableLogging.h
@@ -0,0 +1,12 @@
+#include "SocketCommand.h"
+
+class WebPageManager;
+
+class EnableLogging : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ EnableLogging(WebPageManager *, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
+
View
3 src/Evaluate.cpp
@@ -1,8 +1,9 @@
#include "Evaluate.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include <iostream>
-Evaluate::Evaluate(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Evaluate::Evaluate(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
m_buffer = "";
}
View
8 src/Evaluate.h
@@ -1,14 +1,12 @@
-#include "Command.h"
+#include "SocketCommand.h"
#include <QVariantList>
-class WebPage;
-
-class Evaluate : public Command {
+class Evaluate : public SocketCommand {
Q_OBJECT
public:
- Evaluate(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Evaluate(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
private:
View
3 src/Execute.cpp
@@ -1,7 +1,8 @@
#include "Execute.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Execute::Execute(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Execute::Execute(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Execute::start() {
View
8 src/Execute.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Execute : public Command {
+class Execute : public SocketCommand {
Q_OBJECT
public:
- Execute(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Execute(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
11 src/Find.cpp
@@ -1,17 +1,20 @@
#include "Find.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Find::Find(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Find::Find(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Find::start() {
+ QString message;
QVariant result = page()->invokeWebKitServerFunction("find", arguments());
if (result.isValid()) {
- emit finished(new Response(true, result.toString()));
+ message = result.toString();
+ emit finished(new Response(true, message));
} else {
- emit finished(new Response(false, QString("Invalid selector.")));
+ emit finished(new Response(false, QString("Invalid XPath expression")));
}
}
View
8 src/Find.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Find : public Command {
+class Find : public SocketCommand {
Q_OBJECT
public:
- Find(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Find(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
5 src/FrameFocus.cpp
@@ -1,8 +1,9 @@
#include "FrameFocus.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-FrameFocus::FrameFocus(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+FrameFocus::FrameFocus(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void FrameFocus::start() {
View
7 src/FrameFocus.h
@@ -1,13 +1,12 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
class QWebFrame;
-class FrameFocus : public Command {
+class FrameFocus : public SocketCommand {
Q_OBJECT
public:
- FrameFocus(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ FrameFocus(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
private:
View
7 src/GetCookies.cpp
@@ -1,17 +1,16 @@
#include "GetCookies.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include "NetworkCookieJar.h"
-GetCookies::GetCookies(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent)
+GetCookies::GetCookies(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent)
{
m_buffer = "";
}
void GetCookies::start()
{
- NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
- ->networkAccessManager()
- ->cookieJar());
+ NetworkCookieJar *jar = manager()->cookieJar();
foreach (QNetworkCookie cookie, jar->getAllCookies()) {
m_buffer.append(cookie.toRawForm());
m_buffer.append("\n");
View
8 src/GetCookies.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class GetCookies : public Command {
+class GetCookies : public SocketCommand {
Q_OBJECT;
public:
- GetCookies(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ GetCookies(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
private:
View
11 src/GetWindowHandle.cpp
@@ -0,0 +1,11 @@
+#include "GetWindowHandle.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+#include <QStringList>
+
+GetWindowHandle::GetWindowHandle(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
+}
+
+void GetWindowHandle::start() {
+ emit finished(new Response(true, page()->uuid()));
+}
View
10 src/GetWindowHandle.h
@@ -0,0 +1,10 @@
+#include "SocketCommand.h"
+
+class GetWindowHandle : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ GetWindowHandle(WebPageManager *, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
+
View
20 src/GetWindowHandles.cpp
@@ -0,0 +1,20 @@
+#include "GetWindowHandles.h"
+#include "WebPageManager.h"
+#include "CommandFactory.h"
+#include "WebPage.h"
+#include <QStringList>
+
+GetWindowHandles::GetWindowHandles(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
+}
+
+void GetWindowHandles::start() {
+ QString handles = "[";
+ QStringList stringList;
+
+ foreach(WebPage *page, manager()->pages())
+ stringList.append("\"" + page->uuid() + "\"");
+
+ handles += stringList.join(",") + "]";
+
+ emit finished(new Response(true, handles));
+}
View
10 src/GetWindowHandles.h
@@ -0,0 +1,10 @@
+#include "SocketCommand.h"
+
+class GetWindowHandles : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ GetWindowHandles(WebPageManager *, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
+
View
3 src/Header.cpp
@@ -1,8 +1,9 @@
#include "Header.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include "NetworkAccessManager.h"
-Header::Header(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Header::Header(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Header::start() {
View
8 src/Header.h
@@ -1,11 +1,9 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Header : public Command {
+class Header : public SocketCommand {
Q_OBJECT
public:
- Header(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Header(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
3 src/Headers.cpp
@@ -1,7 +1,8 @@
#include "Headers.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Headers::Headers(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Headers::Headers(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Headers::start() {
View
8 src/Headers.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Headers : public Command {
+class Headers : public SocketCommand {
Q_OBJECT
public:
- Headers(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Headers(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
13 src/IgnoreSslErrors.cpp
@@ -0,0 +1,13 @@
+#include "IgnoreSslErrors.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+IgnoreSslErrors::IgnoreSslErrors(WebPageManager *manager, QStringList &arguments, QObject *parent) :
+ SocketCommand(manager, arguments, parent) {
+}
+
+void IgnoreSslErrors::start() {
+ manager()->setIgnoreSslErrors(true);
+ emit finished(new Response(true));
+}
+
View
10 src/IgnoreSslErrors.h
@@ -0,0 +1,10 @@
+#include "SocketCommand.h"
+
+class IgnoreSslErrors : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ IgnoreSslErrors(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
+
View
10 src/JavascriptAlertMessages.cpp
@@ -0,0 +1,10 @@
+#include "JavascriptAlertMessages.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+JavascriptAlertMessages::JavascriptAlertMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void JavascriptAlertMessages::start()
+{
+ emit finished(new Response(true, page()->alertMessages()));
+}
View
9 src/JavascriptAlertMessages.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class JavascriptAlertMessages : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ JavascriptAlertMessages(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
10 src/JavascriptConfirmMessages.cpp
@@ -0,0 +1,10 @@
+#include "JavascriptConfirmMessages.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+JavascriptConfirmMessages::JavascriptConfirmMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void JavascriptConfirmMessages::start()
+{
+ emit finished(new Response(true, page()->confirmMessages()));
+}
View
9 src/JavascriptConfirmMessages.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class JavascriptConfirmMessages : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ JavascriptConfirmMessages(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
2 src/JavascriptInvocation.cpp
@@ -1,6 +1,6 @@
#include "JavascriptInvocation.h"
-JavascriptInvocation::JavascriptInvocation(QString &functionName, QStringList &arguments, QObject *parent) : QObject(parent) {
+JavascriptInvocation::JavascriptInvocation(const QString &functionName, const QStringList &arguments, QObject *parent) : QObject(parent) {
m_functionName = functionName;
m_arguments = arguments;
}
View
2 src/JavascriptInvocation.h
@@ -8,7 +8,7 @@ class JavascriptInvocation : public QObject {
Q_PROPERTY(QStringList arguments READ arguments)
public:
- JavascriptInvocation(QString &functionName, QStringList &arguments, QObject *parent = 0);
+ JavascriptInvocation(const QString &functionName, const QStringList &arguments, QObject *parent = 0);
QString &functionName();
QStringList &arguments();
View
10 src/JavascriptPromptMessages.cpp
@@ -0,0 +1,10 @@
+#include "JavascriptPromptMessages.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+JavascriptPromptMessages::JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void JavascriptPromptMessages::start()
+{
+ emit finished(new Response(true, page()->promptMessages()));
+}
View
9 src/JavascriptPromptMessages.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class JavascriptPromptMessages : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
20 src/NetworkAccessManager.cpp
@@ -1,9 +1,11 @@
#include "NetworkAccessManager.h"
#include "WebPage.h"
#include <iostream>
+#include <fstream>
NetworkAccessManager::NetworkAccessManager(QObject *parent):QNetworkAccessManager(parent) {
+ connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
}
QNetworkReply* NetworkAccessManager::createRequest(QNetworkAccessManager::Operation operation, const QNetworkRequest &request, QIODevice * outgoingData = 0) {
@@ -16,7 +18,9 @@ QNetworkReply* NetworkAccessManager::createRequest(QNetworkAccessManager::Operat
item.next();
new_request.setRawHeader(item.key().toAscii(), item.value().toAscii());
}
- return QNetworkAccessManager::createRequest(operation, new_request, outgoingData);
+ QNetworkReply *reply = QNetworkAccessManager::createRequest(operation, new_request, outgoingData);
+ emit requestCreated(reply);
+ return reply;
};
void NetworkAccessManager::addHeader(QString key, QString value) {
@@ -27,3 +31,17 @@ void NetworkAccessManager::resetHeaders() {
m_headers.clear();
};
+void NetworkAccessManager::setUserName(const QString &userName) {
+ m_userName = userName;
+}
+
+void NetworkAccessManager::setPassword(const QString &password) {
+ m_password = password;
+}
+
+
+void NetworkAccessManager::provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) {
+ Q_UNUSED(reply);
+ authenticator->setUser(m_userName);
+ authenticator->setPassword(m_password);
+}
View
10 src/NetworkAccessManager.h
@@ -10,10 +10,20 @@ class NetworkAccessManager : public QNetworkAccessManager {
NetworkAccessManager(QObject *parent = 0);
void addHeader(QString key, QString value);
void resetHeaders();
+ void setUserName(const QString &userName);
+ void setPassword(const QString &password);
protected:
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice * outgoingData);
+ QString m_userName;
+ QString m_password;
private:
QHash<QString, QString> m_headers;
+
+ private slots:
+ void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator);
+
+ signals:
+ void requestCreated(QNetworkReply *reply);
};
View
7 src/Node.cpp
@@ -1,7 +1,8 @@
#include "Node.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Node::Node(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Node::Node(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Node::start() {
@@ -12,3 +13,7 @@ void Node::start() {
emit finished(new Response(true, attributeValue));
}
+QString Node::toString() const {
+ QStringList functionArguments(arguments());
+ return QString("Node.") + functionArguments.takeFirst();
+}
View
9 src/Node.h
@@ -1,13 +1,12 @@
-#include "Command.h"
+#include "SocketCommand.h"
#include <QStringList>
-class WebPage;
-
-class Node : public Command {
+class Node : public SocketCommand {
Q_OBJECT
public:
- Node(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Node(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
virtual void start();
+ virtual QString toString() const;
};
View
7 src/NullCommand.cpp
@@ -1,10 +1,13 @@
#include "NullCommand.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-NullCommand::NullCommand(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
+NullCommand::NullCommand(QString name, QObject *parent) : Command(parent) {
+ m_name = name;
+}
void NullCommand::start() {
- QString failure = QString("Unknown command: ") + arguments()[0] + "\n";
+ QString failure = QString("Unknown command: ") + m_name + "\n";
emit finished(new Response(false, failure));
}
View
7 src/NullCommand.h
@@ -1,11 +1,12 @@
#include "Command.h"
-class WebPage;
-
class NullCommand : public Command {
Q_OBJECT
public:
- NullCommand(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ NullCommand(QString name, QObject *parent = 0);
virtual void start();
+
+ private:
+ QString m_name;
};
View
19 src/PageLoadingCommand.cpp
@@ -1,18 +1,20 @@
#include "PageLoadingCommand.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-PageLoadingCommand::PageLoadingCommand(Command *command, WebPage *page, QObject *parent) : QObject(parent) {
- m_page = page;
+PageLoadingCommand::PageLoadingCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
+ m_manager = manager;
m_command = command;
m_pageLoadingFromCommand = false;
m_pageSuccess = true;
m_pendingResponse = NULL;
- connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
- connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
+ connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
void PageLoadingCommand::start() {
+ m_manager->logger() << "Started" << m_command->toString();
connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
m_command->start();
};
@@ -22,22 +24,25 @@ void PageLoadingCommand::pendingLoadFinished(bool success) {
if (m_pageLoadingFromCommand) {
m_pageLoadingFromCommand = false;
if (m_pendingResponse) {
+ m_manager->logger() << "Page load from command finished";
if (m_pageSuccess) {
emit finished(m_pendingResponse);
} else {
- QString message = m_page->failureString();
+ QString message = m_manager->currentPage()->failureString();
emit finished(new Response(false, message));
}
}
}
}
void PageLoadingCommand::pageLoadingFromCommand() {
+ m_manager->logger() << m_command->toString() << "started page load";
m_pageLoadingFromCommand = true;
}
void PageLoadingCommand::commandFinished(Response *response) {
- disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ m_manager->logger() << "Finished" << m_command->toString();
m_command->deleteLater();
if (m_pageLoadingFromCommand)
m_pendingResponse = response;
View
15 src/PageLoadingCommand.h
@@ -1,9 +1,9 @@
#include <QObject>
#include <QStringList>
+#include "Command.h"
-class Command;
class Response;
-class WebPage;
+class WebPageManager;
/*
* Decorates a Command by deferring the finished() signal until any pending
@@ -15,23 +15,20 @@ class WebPage;
* If a pending page load fails, the command's response will be discarded and a
* failure response will be emitted instead.
*/
-class PageLoadingCommand : public QObject {
+class PageLoadingCommand : public Command {
Q_OBJECT
public:
- PageLoadingCommand(Command *command, WebPage *page, QObject *parent = 0);
- void start();
+ PageLoadingCommand(Command *command, WebPageManager *page, QObject *parent = 0);
+ virtual void start();
public slots:
void pageLoadingFromCommand();
void pendingLoadFinished(bool success);
void commandFinished(Response *response);
- signals:
- void finished(Response *response);
-
private:
- WebPage *m_page;
+ WebPageManager *m_manager;
Command *m_command;
Response *m_pendingResponse;
bool m_pageSuccess;
View
3 src/Render.cpp
@@ -1,7 +1,8 @@
#include "Render.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Render::Render(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Render::Render(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Render::start() {
View
8 src/Render.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
#include <QStringList>
-class WebPage;
-
-class Render : public Command {
+class Render : public SocketCommand {
Q_OBJECT
public:
- Render(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Render(WebPageManager *page, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
3 src/RequestedUrl.cpp
@@ -1,7 +1,8 @@
#include "RequestedUrl.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+RequestedUrl::RequestedUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void RequestedUrl::start() {
View
8 src/RequestedUrl.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class RequestedUrl : public Command {
+class RequestedUrl : public SocketCommand {
Q_OBJECT
public:
- RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ RequestedUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
20 src/Reset.cpp
@@ -1,29 +1,15 @@
#include "Reset.h"
#include "WebPage.h"
-#include "NetworkAccessManager.h"
-#include "NetworkCookieJar.h"
+#include "WebPageManager.h"
-Reset::Reset(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Reset::Reset(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Reset::start() {
page()->triggerAction(QWebPage::Stop);
- NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
- networkAccessManager->setCookieJar(new NetworkCookieJar());
- networkAccessManager->resetHeaders();
+ manager()->reset();
- page()->setUserAgent(NULL);
- page()->resetResponseHeaders();
- page()->resetConsoleMessages();
- page()->resetWindowSize();
- resetHistory();
emit finished(new Response(true));
}
-void Reset::resetHistory() {
- // Clearing the history preserves the current history item, so set it to blank first.
- page()->currentFrame()->setUrl(QUrl("about:blank"));
- page()->history()->clear();
-}
-
View
11 src/Reset.h
@@ -1,15 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Reset : public Command {
+class Reset : public SocketCommand {
Q_OBJECT
public:
- Reset(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Reset(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
-
- private:
- void resetHistory();
};
View
3 src/ResizeWindow.cpp
@@ -1,7 +1,8 @@
#include "ResizeWindow.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-ResizeWindow::ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+ResizeWindow::ResizeWindow(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void ResizeWindow::start() {
View
8 src/ResizeWindow.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class ResizeWindow : public Command {
+class ResizeWindow : public SocketCommand {
Q_OBJECT
public:
- ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ ResizeWindow(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
8 src/Server.cpp
@@ -1,13 +1,11 @@
#include "Server.h"
-#include "WebPage.h"
#include "Connection.h"
+#include "WebPageManager.h"
#include <QTcpServer>
-Server::Server(QObject *parent, bool ignoreSslErrors) : QObject(parent) {
+Server::Server(QObject *parent) : QObject(parent) {
m_tcp_server = new QTcpServer(this);
- m_page = new WebPage(this);
- m_page->setIgnoreSslErrors(ignoreSslErrors);
}
bool Server::start() {
@@ -21,5 +19,5 @@ quint16 Server::server_port() const {
void Server::handleConnection() {
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
- new Connection(socket, m_page, this);
+ new Connection(socket, new WebPageManager(this), this);
}
View
4 src/Server.h
@@ -1,13 +1,12 @@
#include <QObject>
class QTcpServer;
-class WebPage;
class Server : public QObject {
Q_OBJECT
public:
- Server(QObject *parent, bool ignoreSslErrors);
+ Server(QObject *parent);
bool start();
quint16 server_port() const;
@@ -16,6 +15,5 @@ class Server : public QObject {
private:
QTcpServer *m_tcp_server;
- WebPage *m_page;
};
View
11 src/SetConfirmAction.cpp
@@ -0,0 +1,11 @@
+#include "SetConfirmAction.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+SetConfirmAction::SetConfirmAction(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void SetConfirmAction::start()
+{
+ page()->setConfirmAction(arguments()[0]);
+ emit finished(new Response(true));
+}
View
9 src/SetConfirmAction.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class SetConfirmAction : public SocketCommand {
+ Q_OBJECT;
+
+ public:
+ SetConfirmAction(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
7 src/SetCookie.cpp
@@ -1,16 +1,15 @@
#include "SetCookie.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include "NetworkCookieJar.h"
#include <QNetworkCookie>
-SetCookie::SetCookie(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
+SetCookie::SetCookie(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
void SetCookie::start()
{
QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments()[0].toAscii());
- NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
- ->networkAccessManager()
- ->cookieJar());
+ NetworkCookieJar *jar = manager()->cookieJar();
jar->overwriteCookies(cookies);
emit finished(new Response(true));
}
View
8 src/SetCookie.h
@@ -1,11 +1,9 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class SetCookie : public Command {
+class SetCookie : public SocketCommand {
Q_OBJECT;
public:
- SetCookie(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ SetCookie(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
11 src/SetPromptAction.cpp
@@ -0,0 +1,11 @@
+#include "SetPromptAction.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+SetPromptAction::SetPromptAction(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void SetPromptAction::start()
+{
+ page()->setPromptAction(arguments()[0]);
+ emit finished(new Response(true));
+}
View
9 src/SetPromptAction.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class SetPromptAction : public SocketCommand {
+ Q_OBJECT;
+
+ public:
+ SetPromptAction(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
11 src/SetPromptText.cpp
@@ -0,0 +1,11 @@
+#include "SetPromptText.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+SetPromptText::SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
+
+void SetPromptText::start()
+{
+ page()->setPromptText(arguments()[0]);
+ emit finished(new Response(true));
+}
View
9 src/SetPromptText.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class SetPromptText : public SocketCommand {
+ Q_OBJECT;
+
+ public:
+ SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
3 src/SetProxy.cpp
@@ -1,9 +1,10 @@
#include "SetProxy.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include <QNetworkAccessManager>
#include <QNetworkProxy>
-SetProxy::SetProxy(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
+SetProxy::SetProxy(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
void SetProxy::start()
{
View
8 src/SetProxy.h
@@ -1,11 +1,9 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class SetProxy : public Command {
+class SetProxy : public SocketCommand {
Q_OBJECT;
public:
- SetProxy(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ SetProxy(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
12 src/SetSkipImageLoading.cpp
@@ -0,0 +1,12 @@
+#include "SetSkipImageLoading.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+SetSkipImageLoading::SetSkipImageLoading(WebPageManager *manager, QStringList &arguments, QObject *parent) :
+ SocketCommand(manager, arguments, parent) {
+}
+
+void SetSkipImageLoading::start() {
+ page()->setSkipImageLoading(arguments().contains("true"));
+ emit finished(new Response(true));
+}
View
9 src/SetSkipImageLoading.h
@@ -0,0 +1,9 @@
+#include "SocketCommand.h"
+
+class SetSkipImageLoading : public SocketCommand {
+ Q_OBJECT
+
+ public:
+ SetSkipImageLoading(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
+ virtual void start();
+};
View
21 src/SocketCommand.cpp
@@ -0,0 +1,21 @@
+#include "SocketCommand.h"
+#include "WebPage.h"
+#include "WebPageManager.h"
+
+SocketCommand::SocketCommand(WebPageManager *manager, QStringList &arguments, QObject *parent) : Command(parent) {
+ m_manager = manager;
+ m_arguments = arguments;
+}
+
+WebPage *SocketCommand::page() const {
+ return m_manager->currentPage();
+}
+
+const QStringList &SocketCommand::arguments() const {
+ return m_arguments;
+}
+
+WebPageManager *SocketCommand::manager() const {
+ return m_manager;
+}
+
View
29 src/SocketCommand.h
@@ -0,0 +1,29 @@
+#ifndef SOCKET_COMMAND_H
+#define SOCKET_COMMAND_H
+
+#include <QObject>
+#include <QStringList>
+#include "Command.h"
+
+class WebPage;
+class WebPageManager;
+class Response;
+
+class SocketCommand : public Command {
+ Q_OBJECT
+
+ public:
+ SocketCommand(WebPageManager *, QStringList &arguments, QObject *parent = 0);
+
+ protected:
+ WebPage *page() const;
+ const QStringList &arguments() const;
+ WebPageManager *manager() const;
+
+ private:
+ QStringList m_arguments;
+ WebPageManager *m_manager;
+
+};
+
+#endif
View
3 src/Source.cpp
@@ -1,7 +1,8 @@
#include "Source.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Source::Source(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Source::Source(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Source::start() {
View
7 src/Source.h
@@ -1,13 +1,12 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
class QNetworkReply;
-class Source : public Command {
+class Source : public SocketCommand {
Q_OBJECT
public:
- Source(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Source(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
public slots:
View
3 src/Status.cpp
@@ -1,8 +1,9 @@
#include "Status.h"
#include "WebPage.h"
+#include "WebPageManager.h"
#include <sstream>
-Status::Status(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Status::Status(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Status::start() {
View
8 src/Status.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Status : public Command {
+class Status : public SocketCommand {
Q_OBJECT
public:
- Status(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Status(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
17 src/UnsupportedContentHandler.cpp
@@ -10,23 +10,18 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
}
void UnsupportedContentHandler::handleUnsupportedContent() {
- QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
- if(contentMimeType.isNull()) {
- this->finish(false);
- } else {
- this->loadUnsupportedContent();
- this->finish(true);
- }
+ this->renderNonHtmlContent();
+ this->finish();
this->deleteLater();
}
-void UnsupportedContentHandler::loadUnsupportedContent() {
+void UnsupportedContentHandler::renderNonHtmlContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
}
-void UnsupportedContentHandler::finish(bool success) {
+void UnsupportedContentHandler::finish() {
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
- m_page->replyFinished(m_reply);
- m_page->loadFinished(success);
+ m_page->networkAccessManagerFinishedReply(m_reply);
+ m_page->loadFinished(true);
}
View
4 src/UnsupportedContentHandler.h
@@ -13,6 +13,6 @@ class UnsupportedContentHandler : public QObject {
private:
WebPage *m_page;
QNetworkReply *m_reply;
- void loadUnsupportedContent();
- void finish(bool success);
+ void renderNonHtmlContent();
+ void finish();
};
View
3 src/Url.cpp
@@ -1,7 +1,8 @@
#include "Url.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Url::Url(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Url::Url(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Url::start() {
View
8 src/Url.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Url : public Command {
+class Url : public SocketCommand {
Q_OBJECT
public:
- Url(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Url(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
5 src/Visit.cpp
@@ -1,8 +1,9 @@
#include "Visit.h"
-#include "Command.h"
+#include "SocketCommand.h"
#include "WebPage.h"
+#include "WebPageManager.h"
-Visit::Visit(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
+Visit::Visit(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Visit::start() {
View
8 src/Visit.h
@@ -1,12 +1,10 @@
-#include "Command.h"
+#include "SocketCommand.h"
-class WebPage;
-
-class Visit : public Command {
+class Visit : public SocketCommand {
Q_OBJECT
public:
- Visit(WebPage *page, QStringList &arguments, QObject *parent = 0);
+ Visit(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
virtual void start();
};
View
184 src/WebPage.cpp
@@ -1,17 +1,28 @@
#include "WebPage.h"
+#include "WebPageManager.h"
#include "JavascriptInvocation.h"
#include "NetworkAccessManager.h"
#include "NetworkCookieJar.h"
#include "UnsupportedContentHandler.h"
#include <QResource>
#include <iostream>
+#include <QWebSettings>
+#include <QUuid>
+
+WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
+ m_loading = false;
+ m_failed = false;
+ m_manager = manager;
+ m_uuid = QUuid::createUuid().toString();
+ m_lastStatus = 0;
-WebPage::WebPage(QObject *parent) : QWebPage(parent) {
setForwardUnsupportedContent(true);
loadJavascript();
setUserStylesheet();
- m_loading = false;
+ m_confirm = true;
+ m_prompt = false;
+ m_prompt_text = QString();
this->setCustomNetworkAccessManager();
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
@@ -21,18 +32,43 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
resetWindowSize();
+
+ settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
}
void WebPage::resetWindowSize() {
this->setViewportSize(QSize(1680, 1050));
+ this->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
}
void WebPage::setCustomNetworkAccessManager() {
- NetworkAccessManager *manager = new NetworkAccessManager();
- manager->setCookieJar(new NetworkCookieJar());
+ NetworkAccessManager *manager = new NetworkAccessManager(this);
+ manager->setCookieJar(m_manager->cookieJar());
this->setNetworkAccessManager(manager);
- connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
- connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply *, QList<QSslError>)));
+ connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkAccessManagerFinishedReply(QNetworkReply *)));
+ connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
+ this, SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
+ connect(manager, SIGNAL(requestCreated(QNetworkReply *)), this, SLOT(networkAccessManagerCreatedRequest(QNetworkReply *)));
+}
+
+void WebPage::networkAccessManagerCreatedRequest(QNetworkReply *reply) {
+ emit requestCreated(reply);
+}
+
+void WebPage::networkAccessManagerFinishedReply(QNetworkReply *reply) {
+ if (reply->url() == this->currentFrame()->url()) {
+ QStringList headers;
+ m_lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QList<QByteArray> list = reply->rawHeaderList();
+
+ int length = list.size();
+ for(int i = 0; i < length; i++) {
+ headers << list.at(i)+": "+reply->rawHeader(list.at(i));
+ }
+
+ m_pageHeaders = headers.join("\n");
+ }
+ emit replyFinished(reply);
}
void WebPage::loadJavascript() {
@@ -66,6 +102,18 @@ QString WebPage::consoleMessages() {
return m_consoleMessages.join("\n");
}
+QString WebPage::alertMessages() {
+ return m_alertMessages.join("\n");
+}
+
+QString WebPage::confirmMessages() {
+ return m_confirmMessages.join("\n");
+}
+
+QString WebPage::promptMessages() {
+ return m_promptMessages.join("\n");
+}
+
void WebPage::setUserAgent(QString userAgent) {
m_userAgent = userAgent;
}
@@ -84,7 +132,7 @@ bool WebPage::shouldInterruptJavaScript() {
return false;
}
-QVariant WebPage::invokeWebKitServerFunction(const char *name, QStringList &arguments) {
+QVariant WebPage::invokeWebKitServerFunction(const char *name, const QStringList &arguments) {
QString qname(name);
QString objectName("WebKitServerInvocation");
JavascriptInvocation invocation(qname, arguments);
@@ -93,7 +141,7 @@ QVariant WebPage::invokeWebKitServerFunction(const char *name, QStringList &argu
return currentFrame()->evaluateJavaScript(javascript);
}
-QVariant WebPage::invokeWebKitServerFunction(QString &name, QStringList &arguments) {
+QVariant WebPage::invokeWebKitServerFunction(QString &name, const QStringList &arguments) {
return invokeWebKitServerFunction(name.toAscii().data(), arguments);
}
@@ -107,38 +155,51 @@ void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, c
void WebPage::javaScriptAlert(QWebFrame *frame, const QString &message) {
Q_UNUSED(frame);
+ m_alertMessages.append(message);
std::cout << "ALERT: " << qPrintable(message) << std::endl;
}
bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &message) {
Q_UNUSED(frame);
- Q_UNUSED(message);
- return true;
+ m_confirmMessages.append(message);
+ return m_confirm;
}
bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result) {
Q_UNUSED(frame)
- Q_UNUSED(message)
- Q_UNUSED(defaultValue)
- Q_UNUSED(result)
- return false;
+ m_promptMessages.append(message);
+ if (m_prompt) {
+ if (m_prompt_text.isNull()) {
+ *result = defaultValue;
+ } else {
+ *result = m_prompt_text;
+ }
+ }
+ return m_prompt;
}
void WebPage::loadStarted() {
m_loading = true;
+ m_errorPageMessage = QString();
}
void WebPage::loadFinished(bool success) {
+ Q_UNUSED(success);
m_loading = false;
- emit pageFinished(success);
+ emit pageFinished(!m_failed);
+ m_failed = false;
}
bool WebPage::isLoading() const {
return m_loading;
}
QString WebPage::failureString() {
- return QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
+ QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
+ if (m_errorPageMessage.isEmpty())
+ return message;
+ else
+ return message + m_errorPageMessage;
}
bool WebPage::render(const QString &fileName) {
@@ -176,66 +237,97 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
}
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
- Q_UNUSED(option);
if (extension == ChooseMultipleFilesExtension) {
QStringList names = QStringList() << getLastAttachedFileName();
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
return true;
}
+ else if (extension == QWebPage::ErrorPageExtension) {
+ ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
+ m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
+ m_failed = true;
+ return false;
+ }
return false;
}
QString WebPage::getLastAttachedFileName() {
return currentFrame()->evaluateJavaScript(QString("WebKitServer.lastAttachedFile")).toString();
}
-void WebPage::replyFinished(QNetworkReply *reply) {
- if (reply->url() == this->currentFrame()->url()) {
- QStringList headers;
- m_lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- QList<QByteArray> list = reply->rawHeaderList();
+void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
+ if (m_manager->ignoreSslErrors())
+ reply->ignoreSslErrors(errors);
+}
- int length = list.size();
- for(int i = 0; i < length; i++) {
- headers << list.at(i)+": "+reply->rawHeader(list.at(i));
- }
+void WebPage::setSkipImageLoading(bool skip) {
+ settings()->setAttribute(QWebSettings::AutoLoadImages, !skip);
+}
- m_pageHeaders = headers.join("\n");
+int WebPage::getLastStatus() {
+ return m_lastStatus;
+}
+
+QString WebPage::pageHeaders() {
+ return m_pageHeaders;
+}
+
+void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
+ QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
+ if(!contentMimeType.isNull()) {
+ triggerAction(QWebPage::Stop);
+ UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
+ Q_UNUSED(handler);
}
}
-void WebPage::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) {
- if (m_ignoreSslErrors)
- reply->ignoreSslErrors(errors);
+bool WebPage::supportsExtension(Extension extension) const {
+ if (extension == ErrorPageExtension)
+ return true;
+ else if (extension == ChooseMultipleFilesExtension)
+ return true;
+ else
+ return false;
}
-void WebPage::setIgnoreSslErrors(bool ignore) {
- m_ignoreSslErrors = ignore;
+QWebPage *WebPage::createWindow(WebWindowType type) {
+ Q_UNUSED(type);
+ return m_manager->createPage(this);
}
-bool WebPage::ignoreSslErrors() {
- return m_ignoreSslErrors;
+QString WebPage::uuid() {
+ return m_uuid;
}
+QString WebPage::getWindowName() {
+ QVariant windowName = mainFrame()->evaluateJavaScript("window.name");
-int WebPage::getLastStatus() {
- return m_lastStatus;
+ if (windowName.isValid())
+ return windowName.toString();
+ else
+ return "";
}
-void WebPage::resetResponseHeaders() {
- m_lastStatus = 0;
- m_pageHeaders = QString();
+bool WebPage::matchesWindowSelector(QString selector) {
+ return (selector == getWindowName() ||
+ selector == mainFrame()->title() ||
+ selector == mainFrame()->url().toString() ||
+ selector == uuid());