imseng-capybara-webkit 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +2 -0
  3. data/Appraisals +7 -0
  4. data/CONTRIBUTING.md +47 -0
  5. data/ChangeLog +70 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +19 -0
  8. data/NEWS.md +36 -0
  9. data/README.md +114 -0
  10. data/Rakefile +65 -0
  11. data/bin/Info.plist +22 -0
  12. data/capybara-webkit.gemspec +28 -0
  13. data/extconf.rb +2 -0
  14. data/gemfiles/1.0.gemfile +7 -0
  15. data/gemfiles/1.0.gemfile.lock +70 -0
  16. data/gemfiles/1.1.gemfile +7 -0
  17. data/gemfiles/1.1.gemfile.lock +70 -0
  18. data/lib/capybara/driver/webkit/browser.rb +164 -0
  19. data/lib/capybara/driver/webkit/connection.rb +120 -0
  20. data/lib/capybara/driver/webkit/cookie_jar.rb +55 -0
  21. data/lib/capybara/driver/webkit/node.rb +118 -0
  22. data/lib/capybara/driver/webkit/socket_debugger.rb +43 -0
  23. data/lib/capybara/driver/webkit/version.rb +7 -0
  24. data/lib/capybara/driver/webkit.rb +136 -0
  25. data/lib/capybara/webkit/matchers.rb +37 -0
  26. data/lib/capybara/webkit.rb +13 -0
  27. data/lib/capybara-webkit.rb +1 -0
  28. data/lib/capybara_webkit_builder.rb +68 -0
  29. data/spec/browser_spec.rb +173 -0
  30. data/spec/capybara_webkit_builder_spec.rb +37 -0
  31. data/spec/connection_spec.rb +54 -0
  32. data/spec/cookie_jar_spec.rb +48 -0
  33. data/spec/driver_rendering_spec.rb +80 -0
  34. data/spec/driver_resize_window_spec.rb +59 -0
  35. data/spec/driver_spec.rb +1552 -0
  36. data/spec/integration/driver_spec.rb +20 -0
  37. data/spec/integration/session_spec.rb +137 -0
  38. data/spec/self_signed_ssl_cert.rb +42 -0
  39. data/spec/spec_helper.rb +46 -0
  40. data/src/Body.h +12 -0
  41. data/src/ClearCookies.cpp +15 -0
  42. data/src/ClearCookies.h +11 -0
  43. data/src/Command.cpp +19 -0
  44. data/src/Command.h +31 -0
  45. data/src/CommandFactory.cpp +37 -0
  46. data/src/CommandFactory.h +16 -0
  47. data/src/CommandParser.cpp +76 -0
  48. data/src/CommandParser.h +33 -0
  49. data/src/Connection.cpp +71 -0
  50. data/src/Connection.h +37 -0
  51. data/src/ConsoleMessages.cpp +10 -0
  52. data/src/ConsoleMessages.h +12 -0
  53. data/src/CurrentUrl.cpp +68 -0
  54. data/src/CurrentUrl.h +16 -0
  55. data/src/Evaluate.cpp +84 -0
  56. data/src/Evaluate.h +22 -0
  57. data/src/Execute.cpp +16 -0
  58. data/src/Execute.h +12 -0
  59. data/src/Find.cpp +19 -0
  60. data/src/Find.h +13 -0
  61. data/src/FrameFocus.cpp +66 -0
  62. data/src/FrameFocus.h +28 -0
  63. data/src/GetCookies.cpp +20 -0
  64. data/src/GetCookies.h +14 -0
  65. data/src/Header.cpp +18 -0
  66. data/src/Header.h +11 -0
  67. data/src/Headers.cpp +10 -0
  68. data/src/Headers.h +12 -0
  69. data/src/IgnoreSslErrors.cpp +12 -0
  70. data/src/IgnoreSslErrors.h +12 -0
  71. data/src/JavascriptInvocation.cpp +14 -0
  72. data/src/JavascriptInvocation.h +19 -0
  73. data/src/NetworkAccessManager.cpp +29 -0
  74. data/src/NetworkAccessManager.h +19 -0
  75. data/src/NetworkCookieJar.cpp +101 -0
  76. data/src/NetworkCookieJar.h +15 -0
  77. data/src/Node.cpp +14 -0
  78. data/src/Node.h +13 -0
  79. data/src/NullCommand.cpp +10 -0
  80. data/src/NullCommand.h +11 -0
  81. data/src/PageLoadingCommand.cpp +46 -0
  82. data/src/PageLoadingCommand.h +40 -0
  83. data/src/Render.cpp +18 -0
  84. data/src/Render.h +12 -0
  85. data/src/RequestedUrl.cpp +12 -0
  86. data/src/RequestedUrl.h +12 -0
  87. data/src/Reset.cpp +29 -0
  88. data/src/Reset.h +15 -0
  89. data/src/ResizeWindow.cpp +16 -0
  90. data/src/ResizeWindow.h +12 -0
  91. data/src/Response.cpp +24 -0
  92. data/src/Response.h +15 -0
  93. data/src/Server.cpp +24 -0
  94. data/src/Server.h +21 -0
  95. data/src/SetCookie.cpp +16 -0
  96. data/src/SetCookie.h +11 -0
  97. data/src/SetProxy.cpp +22 -0
  98. data/src/SetProxy.h +11 -0
  99. data/src/Source.cpp +18 -0
  100. data/src/Source.h +19 -0
  101. data/src/Status.cpp +12 -0
  102. data/src/Status.h +12 -0
  103. data/src/UnsupportedContentHandler.cpp +32 -0
  104. data/src/UnsupportedContentHandler.h +18 -0
  105. data/src/Url.cpp +12 -0
  106. data/src/Url.h +12 -0
  107. data/src/Visit.cpp +12 -0
  108. data/src/Visit.h +12 -0
  109. data/src/WebPage.cpp +239 -0
  110. data/src/WebPage.h +58 -0
  111. data/src/body.cpp +10 -0
  112. data/src/capybara.js +315 -0
  113. data/src/find_command.h +29 -0
  114. data/src/main.cpp +33 -0
  115. data/src/webkit_server.pro +85 -0
  116. data/src/webkit_server.qrc +5 -0
  117. data/templates/Command.cpp +10 -0
  118. data/templates/Command.h +12 -0
  119. data/webkit_server.pro +4 -0
  120. metadata +298 -0
data/src/Node.cpp ADDED
@@ -0,0 +1,14 @@
1
+ #include "Node.h"
2
+ #include "WebPage.h"
3
+
4
+ Node::Node(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void Node::start() {
8
+ QStringList functionArguments(arguments());
9
+ QString functionName = functionArguments.takeFirst();
10
+ QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
11
+ QString attributeValue = result.toString();
12
+ emit finished(new Response(true, attributeValue));
13
+ }
14
+
data/src/Node.h ADDED
@@ -0,0 +1,13 @@
1
+ #include "Command.h"
2
+ #include <QStringList>
3
+
4
+ class WebPage;
5
+
6
+ class Node : public Command {
7
+ Q_OBJECT
8
+
9
+ public:
10
+ Node(WebPage *page, QStringList &arguments, QObject *parent = 0);
11
+ virtual void start();
12
+ };
13
+
@@ -0,0 +1,10 @@
1
+ #include "NullCommand.h"
2
+ #include "WebPage.h"
3
+
4
+ NullCommand::NullCommand(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
5
+
6
+ void NullCommand::start() {
7
+ QString failure = QString("[Capybara WebKit] Unknown command: ") + arguments()[0] + "\n";
8
+ emit finished(new Response(false, failure));
9
+ }
10
+
data/src/NullCommand.h ADDED
@@ -0,0 +1,11 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class NullCommand : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ NullCommand(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
@@ -0,0 +1,46 @@
1
+ #include "PageLoadingCommand.h"
2
+ #include "Command.h"
3
+ #include "WebPage.h"
4
+
5
+ PageLoadingCommand::PageLoadingCommand(Command *command, WebPage *page, QObject *parent) : QObject(parent) {
6
+ m_page = page;
7
+ m_command = command;
8
+ m_pageLoadingFromCommand = false;
9
+ m_pageSuccess = true;
10
+ m_pendingResponse = NULL;
11
+ connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
12
+ connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
13
+ }
14
+
15
+ void PageLoadingCommand::start() {
16
+ connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
17
+ m_command->start();
18
+ };
19
+
20
+ void PageLoadingCommand::pendingLoadFinished(bool success) {
21
+ m_pageSuccess = success;
22
+ if (m_pageLoadingFromCommand) {
23
+ m_pageLoadingFromCommand = false;
24
+ if (m_pendingResponse) {
25
+ if (m_pageSuccess) {
26
+ emit finished(m_pendingResponse);
27
+ } else {
28
+ QString message = m_page->failureString();
29
+ emit finished(new Response(false, message));
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ void PageLoadingCommand::pageLoadingFromCommand() {
36
+ m_pageLoadingFromCommand = true;
37
+ }
38
+
39
+ void PageLoadingCommand::commandFinished(Response *response) {
40
+ disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
41
+ m_command->deleteLater();
42
+ if (m_pageLoadingFromCommand)
43
+ m_pendingResponse = response;
44
+ else
45
+ emit finished(response);
46
+ }
@@ -0,0 +1,40 @@
1
+ #include <QObject>
2
+ #include <QStringList>
3
+
4
+ class Command;
5
+ class Response;
6
+ class WebPage;
7
+
8
+ /*
9
+ * Decorates a Command by deferring the finished() signal until any pending
10
+ * page loads are complete.
11
+ *
12
+ * If a Command starts a page load, no signal will be emitted until the page
13
+ * load is finished.
14
+ *
15
+ * If a pending page load fails, the command's response will be discarded and a
16
+ * failure response will be emitted instead.
17
+ */
18
+ class PageLoadingCommand : public QObject {
19
+ Q_OBJECT
20
+
21
+ public:
22
+ PageLoadingCommand(Command *command, WebPage *page, QObject *parent = 0);
23
+ void start();
24
+
25
+ public slots:
26
+ void pageLoadingFromCommand();
27
+ void pendingLoadFinished(bool success);
28
+ void commandFinished(Response *response);
29
+
30
+ signals:
31
+ void finished(Response *response);
32
+
33
+ private:
34
+ WebPage *m_page;
35
+ Command *m_command;
36
+ Response *m_pendingResponse;
37
+ bool m_pageSuccess;
38
+ bool m_pageLoadingFromCommand;
39
+ };
40
+
data/src/Render.cpp ADDED
@@ -0,0 +1,18 @@
1
+ #include "Render.h"
2
+ #include "WebPage.h"
3
+
4
+ Render::Render(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void Render::start() {
8
+ QString imagePath = arguments()[0];
9
+ int width = arguments()[1].toInt();
10
+ int height = arguments()[2].toInt();
11
+
12
+ QSize size(width, height);
13
+ page()->setViewportSize(size);
14
+
15
+ bool result = page()->render( imagePath );
16
+
17
+ emit finished(new Response(result));
18
+ }
data/src/Render.h ADDED
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+ #include <QStringList>
3
+
4
+ class WebPage;
5
+
6
+ class Render : public Command {
7
+ Q_OBJECT
8
+
9
+ public:
10
+ Render(WebPage *page, QStringList &arguments, QObject *parent = 0);
11
+ virtual void start();
12
+ };
@@ -0,0 +1,12 @@
1
+ #include "RequestedUrl.h"
2
+ #include "WebPage.h"
3
+
4
+ RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void RequestedUrl::start() {
8
+ QUrl humanUrl = page()->currentFrame()->requestedUrl();
9
+ QByteArray encodedBytes = humanUrl.toEncoded();
10
+ emit finished(new Response(true, encodedBytes));
11
+ }
12
+
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class RequestedUrl : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
12
+
data/src/Reset.cpp ADDED
@@ -0,0 +1,29 @@
1
+ #include "Reset.h"
2
+ #include "WebPage.h"
3
+ #include "NetworkAccessManager.h"
4
+ #include "NetworkCookieJar.h"
5
+
6
+ Reset::Reset(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
7
+ }
8
+
9
+ void Reset::start() {
10
+ page()->triggerAction(QWebPage::Stop);
11
+
12
+ NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
13
+ networkAccessManager->setCookieJar(new NetworkCookieJar());
14
+ networkAccessManager->resetHeaders();
15
+
16
+ page()->setUserAgent(NULL);
17
+ page()->resetResponseHeaders();
18
+ page()->resetConsoleMessages();
19
+ page()->resetWindowSize();
20
+ resetHistory();
21
+ emit finished(new Response(true));
22
+ }
23
+
24
+ void Reset::resetHistory() {
25
+ // Clearing the history preserves the current history item, so set it to blank first.
26
+ page()->currentFrame()->setUrl(QUrl("about:blank"));
27
+ page()->history()->clear();
28
+ }
29
+
data/src/Reset.h ADDED
@@ -0,0 +1,15 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class Reset : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ Reset(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+
12
+ private:
13
+ void resetHistory();
14
+ };
15
+
@@ -0,0 +1,16 @@
1
+ #include "ResizeWindow.h"
2
+ #include "WebPage.h"
3
+
4
+ ResizeWindow::ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void ResizeWindow::start() {
8
+ int width = arguments()[0].toInt();
9
+ int height = arguments()[1].toInt();
10
+
11
+ QSize size(width, height);
12
+ page()->setViewportSize(size);
13
+
14
+ emit finished(new Response(true));
15
+ }
16
+
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class ResizeWindow : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
12
+
data/src/Response.cpp ADDED
@@ -0,0 +1,24 @@
1
+ #include "Response.h"
2
+ #include <iostream>
3
+
4
+ Response::Response(bool success, QString message) {
5
+ m_success = success;
6
+ m_message = message.toUtf8();
7
+ }
8
+
9
+ Response::Response(bool success, QByteArray message) {
10
+ m_success = success;
11
+ m_message = message;
12
+ }
13
+
14
+ Response::Response(bool success) {
15
+ m_success = success;
16
+ }
17
+
18
+ bool Response::isSuccess() const {
19
+ return m_success;
20
+ }
21
+
22
+ QByteArray Response::message() const {
23
+ return m_message;
24
+ }
data/src/Response.h ADDED
@@ -0,0 +1,15 @@
1
+ #include <QString>
2
+ #include <QByteArray>
3
+
4
+ class Response {
5
+ public:
6
+ Response(bool success, QString message);
7
+ Response(bool success, QByteArray message);
8
+ Response(bool success);
9
+ bool isSuccess() const;
10
+ QByteArray message() const;
11
+
12
+ private:
13
+ bool m_success;
14
+ QByteArray m_message;
15
+ };
data/src/Server.cpp ADDED
@@ -0,0 +1,24 @@
1
+ #include "Server.h"
2
+ #include "WebPage.h"
3
+ #include "Connection.h"
4
+
5
+ #include <QTcpServer>
6
+
7
+ Server::Server(QObject *parent) : QObject(parent) {
8
+ m_tcp_server = new QTcpServer(this);
9
+ m_page = new WebPage(this);
10
+ }
11
+
12
+ bool Server::start() {
13
+ connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(handleConnection()));
14
+ return m_tcp_server->listen(QHostAddress::LocalHost, 0);
15
+ }
16
+
17
+ quint16 Server::server_port() const {
18
+ return m_tcp_server->serverPort();
19
+ }
20
+
21
+ void Server::handleConnection() {
22
+ QTcpSocket *socket = m_tcp_server->nextPendingConnection();
23
+ new Connection(socket, m_page, this);
24
+ }
data/src/Server.h ADDED
@@ -0,0 +1,21 @@
1
+ #include <QObject>
2
+
3
+ class QTcpServer;
4
+ class WebPage;
5
+
6
+ class Server : public QObject {
7
+ Q_OBJECT
8
+
9
+ public:
10
+ Server(QObject *parent);
11
+ bool start();
12
+ quint16 server_port() const;
13
+
14
+ public slots:
15
+ void handleConnection();
16
+
17
+ private:
18
+ QTcpServer *m_tcp_server;
19
+ WebPage *m_page;
20
+ };
21
+
data/src/SetCookie.cpp ADDED
@@ -0,0 +1,16 @@
1
+ #include "SetCookie.h"
2
+ #include "WebPage.h"
3
+ #include "NetworkCookieJar.h"
4
+ #include <QNetworkCookie>
5
+
6
+ SetCookie::SetCookie(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
7
+
8
+ void SetCookie::start()
9
+ {
10
+ QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments()[0].toAscii());
11
+ NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
12
+ ->networkAccessManager()
13
+ ->cookieJar());
14
+ jar->overwriteCookies(cookies);
15
+ emit finished(new Response(true));
16
+ }
data/src/SetCookie.h ADDED
@@ -0,0 +1,11 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class SetCookie : public Command {
6
+ Q_OBJECT;
7
+
8
+ public:
9
+ SetCookie(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
data/src/SetProxy.cpp ADDED
@@ -0,0 +1,22 @@
1
+ #include "SetProxy.h"
2
+ #include "WebPage.h"
3
+ #include <QNetworkAccessManager>
4
+ #include <QNetworkProxy>
5
+
6
+ SetProxy::SetProxy(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
7
+
8
+ void SetProxy::start()
9
+ {
10
+ // default to empty proxy
11
+ QNetworkProxy proxy;
12
+
13
+ if (arguments().size() > 0)
14
+ proxy = QNetworkProxy(QNetworkProxy::HttpProxy,
15
+ arguments()[0],
16
+ (quint16)(arguments()[1].toInt()),
17
+ arguments()[2],
18
+ arguments()[3]);
19
+
20
+ page()->networkAccessManager()->setProxy(proxy);
21
+ emit finished(new Response(true));
22
+ }
data/src/SetProxy.h ADDED
@@ -0,0 +1,11 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class SetProxy : public Command {
6
+ Q_OBJECT;
7
+
8
+ public:
9
+ SetProxy(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
data/src/Source.cpp ADDED
@@ -0,0 +1,18 @@
1
+ #include "Source.h"
2
+ #include "WebPage.h"
3
+
4
+ Source::Source(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void Source::start() {
8
+ QNetworkAccessManager* accessManager = page()->networkAccessManager();
9
+ QNetworkRequest request(page()->currentFrame()->url());
10
+ reply = accessManager->get(request);
11
+
12
+ connect(reply, SIGNAL(finished()), this, SLOT(sourceLoaded()));
13
+ }
14
+
15
+ void Source::sourceLoaded() {
16
+ emit finished(new Response(true, reply->readAll()));
17
+ }
18
+
data/src/Source.h ADDED
@@ -0,0 +1,19 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+ class QNetworkReply;
5
+
6
+ class Source : public Command {
7
+ Q_OBJECT
8
+
9
+ public:
10
+ Source(WebPage *page, QStringList &arguments, QObject *parent = 0);
11
+ virtual void start();
12
+
13
+ public slots:
14
+ void sourceLoaded();
15
+
16
+ private:
17
+ QNetworkReply *reply;
18
+ };
19
+
data/src/Status.cpp ADDED
@@ -0,0 +1,12 @@
1
+ #include "Status.h"
2
+ #include "WebPage.h"
3
+ #include <sstream>
4
+
5
+ Status::Status(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
6
+ }
7
+
8
+ void Status::start() {
9
+ int status = page()->getLastStatus();
10
+ emit finished(new Response(true, QString::number(status)));
11
+ }
12
+
data/src/Status.h ADDED
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class Status : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ Status(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
12
+
@@ -0,0 +1,32 @@
1
+ #include "UnsupportedContentHandler.h"
2
+ #include "WebPage.h"
3
+ #include <QNetworkReply>
4
+
5
+ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
6
+ m_page = page;
7
+ m_reply = reply;
8
+ connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
9
+ disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
10
+ }
11
+
12
+ void UnsupportedContentHandler::handleUnsupportedContent() {
13
+ QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
14
+ if(contentMimeType.isNull()) {
15
+ this->finish(false);
16
+ } else {
17
+ this->loadUnsupportedContent();
18
+ this->finish(true);
19
+ }
20
+ this->deleteLater();
21
+ }
22
+
23
+ void UnsupportedContentHandler::loadUnsupportedContent() {
24
+ QByteArray text = m_reply->readAll();
25
+ m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
26
+ }
27
+
28
+ void UnsupportedContentHandler::finish(bool success) {
29
+ connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
30
+ m_page->replyFinished(m_reply);
31
+ m_page->loadFinished(success);
32
+ }
@@ -0,0 +1,18 @@
1
+ #include <QObject>
2
+ class WebPage;
3
+ class QNetworkReply;
4
+ class UnsupportedContentHandler : public QObject {
5
+ Q_OBJECT
6
+
7
+ public:
8
+ UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent = 0);
9
+
10
+ public slots:
11
+ void handleUnsupportedContent();
12
+
13
+ private:
14
+ WebPage *m_page;
15
+ QNetworkReply *m_reply;
16
+ void loadUnsupportedContent();
17
+ void finish(bool success);
18
+ };
data/src/Url.cpp ADDED
@@ -0,0 +1,12 @@
1
+ #include "Url.h"
2
+ #include "WebPage.h"
3
+
4
+ Url::Url(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ }
6
+
7
+ void Url::start() {
8
+ QUrl humanUrl = page()->currentFrame()->url();
9
+ QByteArray encodedBytes = humanUrl.toEncoded();
10
+ emit finished(new Response(true, encodedBytes));
11
+ }
12
+
data/src/Url.h ADDED
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class Url : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ Url(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
12
+
data/src/Visit.cpp ADDED
@@ -0,0 +1,12 @@
1
+ #include "Visit.h"
2
+ #include "Command.h"
3
+ #include "WebPage.h"
4
+
5
+ Visit::Visit(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
6
+ }
7
+
8
+ void Visit::start() {
9
+ QUrl requestedUrl = QUrl::fromEncoded(arguments()[0].toUtf8(), QUrl::StrictMode);
10
+ page()->currentFrame()->load(QUrl(requestedUrl));
11
+ emit finished(new Response(true));
12
+ }
data/src/Visit.h ADDED
@@ -0,0 +1,12 @@
1
+ #include "Command.h"
2
+
3
+ class WebPage;
4
+
5
+ class Visit : public Command {
6
+ Q_OBJECT
7
+
8
+ public:
9
+ Visit(WebPage *page, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
+ };
12
+