Permalink
Browse files

Merge in webkit-server changes.

  • Loading branch information...
1 parent 02c8531 commit 210a525ca78522d61de08f11c81e46151f99ef32 @tristandunn committed Jan 4, 2013
Showing with 752 additions and 354 deletions.
  1. +2 −2 vendor/webkit-server/src/Authenticate.cpp
  2. +1 −1 vendor/webkit-server/src/ClearCookies.cpp
  3. +1 −1 vendor/webkit-server/src/ClearPromptText.cpp
  4. +13 −0 vendor/webkit-server/src/Command.cpp
  5. +6 −0 vendor/webkit-server/src/Command.h
  6. +3 −3 vendor/webkit-server/src/CommandFactory.cpp
  7. +10 −19 vendor/webkit-server/src/Connection.cpp
  8. +1 −4 vendor/webkit-server/src/Connection.h
  9. +4 −1 vendor/webkit-server/src/ConsoleMessages.cpp
  10. +4 −59 vendor/webkit-server/src/CurrentUrl.cpp
  11. +0 −4 vendor/webkit-server/src/CurrentUrl.h
  12. +1 −1 vendor/webkit-server/src/EnableLogging.cpp
  13. +3 −74 vendor/webkit-server/src/Evaluate.cpp
  14. +0 −8 vendor/webkit-server/src/Evaluate.h
  15. +2 −2 vendor/webkit-server/src/Execute.cpp
  16. +2 −2 vendor/webkit-server/src/Find.cpp
  17. +3 −3 vendor/webkit-server/src/FrameFocus.cpp
  18. +1 −1 vendor/webkit-server/src/GetCookies.cpp
  19. +9 −0 vendor/webkit-server/src/GetTimeout.cpp
  20. +11 −0 vendor/webkit-server/src/GetTimeout.h
  21. +1 −1 vendor/webkit-server/src/GetWindowHandle.cpp
  22. +6 −5 vendor/webkit-server/src/GetWindowHandles.cpp
  23. +2 −2 vendor/webkit-server/src/Header.cpp
  24. +6 −1 vendor/webkit-server/src/Headers.cpp
  25. +1 −1 vendor/webkit-server/src/IgnoreSslErrors.cpp
  26. +4 −1 vendor/webkit-server/src/JavascriptAlertMessages.cpp
  27. +4 −1 vendor/webkit-server/src/JavascriptConfirmMessages.cpp
  28. +4 −1 vendor/webkit-server/src/JavascriptPromptMessages.cpp
  29. +116 −0 vendor/webkit-server/src/JsonSerializer.cpp
  30. +20 −0 vendor/webkit-server/src/JsonSerializer.h
  31. +72 −16 vendor/webkit-server/src/NetworkAccessManager.cpp
  32. +17 −1 vendor/webkit-server/src/NetworkAccessManager.h
  33. +32 −0 vendor/webkit-server/src/NoOpReply.cpp
  34. +18 −0 vendor/webkit-server/src/NoOpReply.h
  35. +1 −1 vendor/webkit-server/src/Node.cpp
  36. +2 −2 vendor/webkit-server/src/NullCommand.cpp
  37. +6 −5 vendor/webkit-server/src/PageLoadingCommand.cpp
  38. +1 −1 vendor/webkit-server/src/Render.cpp
  39. +1 −1 vendor/webkit-server/src/Reset.cpp
  40. +1 −1 vendor/webkit-server/src/ResizeWindow.cpp
  41. +7 −3 vendor/webkit-server/src/Response.cpp
  42. +14 −4 vendor/webkit-server/src/Response.h
  43. +1 −1 vendor/webkit-server/src/SetConfirmAction.cpp
  44. +1 −1 vendor/webkit-server/src/SetCookie.cpp
  45. +1 −1 vendor/webkit-server/src/SetPromptAction.cpp
  46. +1 −1 vendor/webkit-server/src/SetPromptText.cpp
  47. +2 −2 vendor/webkit-server/src/SetProxy.cpp
  48. +1 −1 vendor/webkit-server/src/SetSkipImageLoading.cpp
  49. +19 −0 vendor/webkit-server/src/SetTimeout.cpp
  50. +9 −0 vendor/webkit-server/src/SetTimeout.h
  51. +15 −0 vendor/webkit-server/src/SetUrlBlacklist.cpp
  52. +11 −0 vendor/webkit-server/src/SetUrlBlacklist.h
  53. +1 −1 vendor/webkit-server/src/Status.cpp
  54. +69 −0 vendor/webkit-server/src/TimeoutCommand.cpp
  55. +38 −0 vendor/webkit-server/src/TimeoutCommand.h
  56. +8 −12 vendor/webkit-server/src/UnsupportedContentHandler.cpp
  57. +5 −3 vendor/webkit-server/src/UnsupportedContentHandler.h
  58. +1 −1 vendor/webkit-server/src/Visit.cpp
  59. +46 −45 vendor/webkit-server/src/WebPage.cpp
  60. +16 −15 vendor/webkit-server/src/WebPage.h
  61. +27 −12 vendor/webkit-server/src/WebPageManager.cpp
  62. +7 −3 vendor/webkit-server/src/WebPageManager.h
  63. +2 −2 vendor/webkit-server/src/WindowFocus.cpp
  64. +7 −2 vendor/webkit-server/src/body.cpp
  65. +4 −3 vendor/webkit-server/src/find_command.h
  66. +34 −8 vendor/webkit-server/src/webkit_server.js
  67. +13 −7 vendor/webkit-server/src/webkit_server.pro
@@ -9,10 +9,10 @@ void Authenticate::start() {
QString username = arguments()[0];
QString password = arguments()[1];
- NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
+ NetworkAccessManager* networkAccessManager = page()->networkAccessManager();
networkAccessManager->setUserName(username);
networkAccessManager->setPassword(password);
- emit finished(new Response(true));
+ emitFinished(true);
}
@@ -9,5 +9,5 @@ ClearCookies::ClearCookies(WebPageManager *manager, QStringList &arguments, QObj
void ClearCookies::start()
{
manager()->cookieJar()->clearCookies();
- emit finished(new Response(true));
+ emitFinished(true);
}
@@ -7,5 +7,5 @@ ClearPromptText::ClearPromptText(WebPageManager *manager, QStringList &arguments
void ClearPromptText::start()
{
page()->setPromptText(QString());
- emit finished(new Response(true));
+ emitFinished(true);
}
@@ -6,3 +6,16 @@ Command::Command(QObject *parent) : QObject(parent) {
QString Command::toString() const {
return metaObject()->className();
}
+
+void Command::emitFinished(bool success) {
+ emit finished(new Response(success, this));
+}
+
+void Command::emitFinished(bool success, QString message) {
+ emit finished(new Response(success, message, this));
+}
+
+void Command::emitFinished(bool success, QByteArray message) {
+ emit finished(new Response(success, message, this));
+}
+
@@ -3,6 +3,7 @@
#include <QObject>
#include "Response.h"
+#include <QString>
class Command : public QObject {
Q_OBJECT
@@ -12,6 +13,11 @@ class Command : public QObject {
virtual void start() = 0;
virtual QString toString() const;
+ protected:
+ void emitFinished(bool success);
+ void emitFinished(bool success, QString message);
+ void emitFinished(bool success, QByteArray message);
+
signals:
void finished(Response *response);
};
@@ -5,8 +5,6 @@
#include "Find.h"
#include "Reset.h"
#include "Node.h"
-#include "Url.h"
-#include "Source.h"
#include "Evaluate.h"
#include "Execute.h"
#include "FrameFocus.h"
@@ -20,8 +18,9 @@
#include "GetCookies.h"
#include "SetProxy.h"
#include "ConsoleMessages.h"
-#include "RequestedUrl.h"
#include "CurrentUrl.h"
+#include "SetTimeout.h"
+#include "GetTimeout.h"
#include "ResizeWindow.h"
#include "IgnoreSslErrors.h"
#include "SetSkipImageLoading.h"
@@ -38,6 +37,7 @@
#include "JavascriptAlertMessages.h"
#include "JavascriptConfirmMessages.h"
#include "JavascriptPromptMessages.h"
+#include "SetUrlBlacklist.h"
CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) {
m_manager = manager;
@@ -4,6 +4,7 @@
#include "CommandParser.h"
#include "CommandFactory.h"
#include "PageLoadingCommand.h"
+#include "TimeoutCommand.h"
#include "SocketCommand.h"
#include <QTcpSocket>
@@ -15,51 +16,42 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
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_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}
void Connection::commandReady(Command *command) {
- m_queuedCommand = command;
m_manager->logger() << "Received" << command->toString();
- if (m_manager->isLoading()) {
- m_manager->logger() << command->toString() << "waiting for load to finish";
- m_commandWaiting = true;
- } else {
- startCommand();
- }
+ startCommand(command);
}
-void Connection::startCommand() {
- m_commandWaiting = false;
+void Connection::startCommand(Command *command) {
if (m_pageSuccess) {
- m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this);
- connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
- m_runningCommand->start();
+ command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
+ connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
+ command->start();
} else {
writePageLoadFailure();
}
}
void Connection::pendingLoadFinished(bool success) {
m_pageSuccess = m_pageSuccess && success;
- if (m_commandWaiting) {
- startCommand();
- }
}
void Connection::writePageLoadFailure() {
m_pageSuccess = true;
QString message = currentPage()->failureString();
- writeResponse(new Response(false, message));
+ Response *response = new Response(false, message, this);
+ writeResponse(response);
+ delete response;
}
void Connection::finishCommand(Response *response) {
m_pageSuccess = true;
- m_runningCommand->deleteLater();
writeResponse(response);
+ sender()->deleteLater();
}
void Connection::writeResponse(Response *response) {
@@ -74,7 +66,6 @@ void Connection::writeResponse(Response *response) {
QString messageLength = QString::number(messageUtf8.size()) + "\n";
m_socket->write(messageLength.toAscii());
m_socket->write(messageUtf8);
- delete response;
}
WebPage *Connection::currentPage() {
@@ -22,18 +22,15 @@ class Connection : public QObject {
void pendingLoadFinished(bool success);
private:
- void startCommand();
+ void startCommand(Command *);
void writeResponse(Response *response);
void writePageLoadFailure();
QTcpSocket *m_socket;
- Command *m_queuedCommand;
WebPageManager *m_manager;
CommandParser *m_commandParser;
CommandFactory *m_commandFactory;
- PageLoadingCommand *m_runningCommand;
bool m_pageSuccess;
- bool m_commandWaiting;
WebPage *currentPage();
};
@@ -1,11 +1,14 @@
#include "ConsoleMessages.h"
#include "WebPage.h"
#include "WebPageManager.h"
+#include "JsonSerializer.h"
ConsoleMessages::ConsoleMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void ConsoleMessages::start() {
- emit finished(new Response(true, page()->consoleMessages()));
+ JsonSerializer serializer;
+ QByteArray json = serializer.serialize(page()->consoleMessages());
+ emitFinished(true, json);
}
@@ -5,65 +5,10 @@
CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
-/*
- * This CurrentUrl command attempts to produce a current_url value consistent
- * with that returned by the Selenium WebDriver Capybara driver.
- *
- * It does not currently return the correct value in the case of an iframe whose
- * source URL results in a redirect because the loading of the iframe does not
- * generate a history item. This is most likely a rare case and is consistent
- * with the current behavior of the capybara-webkit driver.
- *
- * The following two values are *not* affected by Javascript pushState.
- *
- * QWebFrame->url()
- * QWebHistoryItem.originalUrl()
- *
- * The following two values *are* affected by Javascript pushState.
- *
- * QWebFrame->requestedUrl()
- * QWebHistoryItem.url()
- *
- * In the cases that we have access to both the QWebFrame values and the
- * correct history item for that frame, we can compare the values and determine
- * if a redirect occurred and if pushState was used. The table below describes
- * the various combinations of URL values that are possible.
- *
- * O -> originally requested URL
- * R -> URL after redirection
- * P -> URL set by pushState
- * * -> denotes the desired URL value from the frame
- *
- * frame history
- * case url requestedUrl url originalUrl
- * -----------------------------------------------------------------
- * regular load O O* O O
- *
- * redirect w/o R* O R O
- * pushState
- *
- * pushState O P* P O
- * only
- *
- * redirect w/ R P* P O
- * pushState
- *
- * Based on the above information, we only need to check for the case of a
- * redirect w/o pushState, in which case QWebFrame->url() will have the correct
- * current_url value. In all other cases QWebFrame->requestedUrl() is correct.
- */
void CurrentUrl::start() {
- QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
- page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
- QByteArray encodedBytes = humanUrl.toEncoded();
- emit finished(new Response(true, encodedBytes));
-}
-
-bool CurrentUrl::wasRegularLoad() {
- return page()->currentFrame()->url() == page()->currentFrame()->requestedUrl();
-}
-
-bool CurrentUrl::wasRedirectedAndNotModifiedByJavascript() {
- return !wasRegularLoad() && page()->currentFrame()->url() == page()->history()->currentItem().url();
+ QStringList arguments;
+ QVariant result = page()->invokeWebKitServerFunction("currentUrl", arguments);
+ QString url = result.toString();
+ emitFinished(true, url);
}
@@ -6,9 +6,5 @@ class CurrentUrl : public SocketCommand {
public:
CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
-
- private:
- bool wasRegularLoad();
- bool wasRedirectedAndNotModifiedByJavascript();
};
@@ -6,5 +6,5 @@ EnableLogging::EnableLogging(WebPageManager *manager, QStringList &arguments, QO
void EnableLogging::start() {
manager()->enableLogging();
- emit finished(new Response(true));
+ emitFinished(true);
}
@@ -1,85 +1,14 @@
#include "Evaluate.h"
#include "WebPage.h"
#include "WebPageManager.h"
+#include "JsonSerializer.h"
#include <iostream>
Evaluate::Evaluate(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
- m_buffer = "";
}
void Evaluate::start() {
QVariant result = page()->currentFrame()->evaluateJavaScript(arguments()[0]);
- addVariant(result);
- emit finished(new Response(true, m_buffer));
-}
-
-void Evaluate::addVariant(QVariant &object) {
- if (object.isValid()) {
- switch(object.type()) {
- case QMetaType::QString:
- {
- QString string = object.toString();
- addString(string);
- }
- break;
- case QMetaType::QVariantList:
- {
- QVariantList list = object.toList();
- addArray(list);
- }
- break;
- case QMetaType::Double:
- m_buffer.append(object.toString());
- break;
- case QMetaType::QVariantMap:
- {
- QVariantMap map = object.toMap();
- addMap(map);
- break;
- }
- case QMetaType::Bool:
- {
- m_buffer.append(object.toString());
- break;
- }
- default:
- m_buffer.append("null");
- }
- } else {
- m_buffer.append("null");
- }
-}
-
-void Evaluate::addString(QString &string) {
- QString escapedString(string);
- escapedString.replace("\"", "\\\"");
- m_buffer.append("\"");
- m_buffer.append(escapedString);
- m_buffer.append("\"");
-}
-
-void Evaluate::addArray(QVariantList &list) {
- m_buffer.append("[");
- for (int i = 0; i < list.length(); i++) {
- if (i > 0)
- m_buffer.append(",");
- addVariant(list[i]);
- }
- m_buffer.append("]");
-}
-
-void Evaluate::addMap(QVariantMap &map) {
- m_buffer.append("{");
- QMapIterator<QString, QVariant> iterator(map);
- while (iterator.hasNext()) {
- iterator.next();
- QString key = iterator.key();
- QVariant value = iterator.value();
- addString(key);
- m_buffer.append(":");
- addVariant(value);
- if (iterator.hasNext())
- m_buffer.append(",");
- }
- m_buffer.append("}");
+ JsonSerializer serializer;
+ emitFinished(true, serializer.serialize(result));
}
@@ -8,13 +8,5 @@ class Evaluate : public SocketCommand {
public:
Evaluate(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
-
- private:
- void addVariant(QVariant &object);
- void addString(QString &string);
- void addArray(QVariantList &list);
- void addMap(QVariantMap &map);
-
- QString m_buffer;
};
Oops, something went wrong.

0 comments on commit 210a525

Please sign in to comment.