Skip to content
This repository has been archived by the owner on Jan 6, 2018. It is now read-only.

Commit

Permalink
Merge in webkit-server changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Mar 14, 2012
1 parent 177f616 commit 5d8eaa5
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions vendor/webkit-server/src/CommandFactory.cpp
Expand Up @@ -20,6 +20,7 @@
#include "SetProxy.h" #include "SetProxy.h"
#include "ConsoleMessages.h" #include "ConsoleMessages.h"
#include "RequestedUrl.h" #include "RequestedUrl.h"
#include "CurrentUrl.h"


CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) { CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
m_page = page; m_page = page;
Expand Down
71 changes: 71 additions & 0 deletions vendor/webkit-server/src/CurrentUrl.cpp
@@ -0,0 +1,71 @@
#include "CurrentUrl.h"
#include "WebPage.h"

CurrentUrl::CurrentUrl(WebPage *page, QObject *parent) : Command(page, 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(QStringList &arguments) {
Q_UNUSED(arguments);

QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
QByteArray encodedBytes = humanUrl.toEncoded();
QString urlString = QString(encodedBytes);
emit finished(new Response(true, urlString));
}

bool CurrentUrl::wasRegularLoad() {
return page()->currentFrame()->url() == page()->currentFrame()->requestedUrl();
}

bool CurrentUrl::wasRedirectedAndNotModifiedByJavascript() {
return !wasRegularLoad() && page()->currentFrame()->url() == page()->history()->currentItem().url();
}

16 changes: 16 additions & 0 deletions vendor/webkit-server/src/CurrentUrl.h
@@ -0,0 +1,16 @@
#include "Command.h"

class WebPage;

class CurrentUrl : public Command {
Q_OBJECT

public:
CurrentUrl(WebPage *page, QObject *parent = 0);
virtual void start(QStringList &arguments);

private:
bool wasRegularLoad();
bool wasRedirectedAndNotModifiedByJavascript();
};

7 changes: 7 additions & 0 deletions vendor/webkit-server/src/Reset.cpp
Expand Up @@ -16,6 +16,13 @@ void Reset::start(QStringList &arguments) {
page()->setUserAgent(NULL); page()->setUserAgent(NULL);
page()->resetResponseHeaders(); page()->resetResponseHeaders();
page()->resetConsoleMessages(); page()->resetConsoleMessages();
resetHistory();
emit finished(new Response(true)); 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();
}

3 changes: 3 additions & 0 deletions vendor/webkit-server/src/Reset.h
Expand Up @@ -8,5 +8,8 @@ class Reset : public Command {
public: public:
Reset(WebPage *page, QObject *parent = 0); Reset(WebPage *page, QObject *parent = 0);
virtual void start(QStringList &arguments); virtual void start(QStringList &arguments);

private:
void resetHistory();
}; };


1 change: 1 addition & 0 deletions vendor/webkit-server/src/find_command.h
Expand Up @@ -24,3 +24,4 @@ CHECK_COMMAND(Headers)
CHECK_COMMAND(SetProxy) CHECK_COMMAND(SetProxy)
CHECK_COMMAND(ConsoleMessages) CHECK_COMMAND(ConsoleMessages)
CHECK_COMMAND(RequestedUrl) CHECK_COMMAND(RequestedUrl)
CHECK_COMMAND(CurrentUrl)
2 changes: 1 addition & 1 deletion vendor/webkit-server/src/webkit_server.js
Expand Up @@ -140,7 +140,7 @@ window.WebKitServer = {
node.value += value[offset]; node.value += value[offset];


this.trigger(index, "keydown"); this.trigger(index, "keydown");
this.keypress(index, false, false, false, false, 0, value[offset]); this.keypress(index, false, false, false, false, 0, value.charCodeAt(offset));
this.trigger(index, "keyup"); this.trigger(index, "keyup");
} }


Expand Down
2 changes: 2 additions & 0 deletions vendor/webkit-server/src/webkit_server.pro
Expand Up @@ -2,6 +2,7 @@ TEMPLATE = app
TARGET = webkit_server TARGET = webkit_server
DESTDIR = . DESTDIR = .
HEADERS = \ HEADERS = \
CurrentUrl.h \
RequestedUrl.h \ RequestedUrl.h \
ConsoleMessages.h \ ConsoleMessages.h \
WebPage.h \ WebPage.h \
Expand Down Expand Up @@ -35,6 +36,7 @@ HEADERS = \
SetProxy.h \ SetProxy.h \


SOURCES = \ SOURCES = \
CurrentUrl.cpp \
RequestedUrl.cpp \ RequestedUrl.cpp \
ConsoleMessages.cpp \ ConsoleMessages.cpp \
main.cpp \ main.cpp \
Expand Down

0 comments on commit 5d8eaa5

Please sign in to comment.