Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Use old method to find current URL in Qt < 4.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Oct 24, 2012
1 parent ecfa783 commit f95e4eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/CurrentUrl.cpp
Expand Up @@ -6,8 +6,24 @@ CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject
}

void CurrentUrl::start() {
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
QStringList arguments;
QVariant result = page()->invokeCapybaraFunction("currentUrl", arguments);
QString url = result.toString();
emit finished(new Response(true, url));
#else
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();
#endif
}

6 changes: 6 additions & 0 deletions src/CurrentUrl.h
Expand Up @@ -6,5 +6,11 @@ class CurrentUrl : public SocketCommand {
public:
CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0)

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

1 change: 1 addition & 0 deletions src/WebPageManager.cpp
Expand Up @@ -100,6 +100,7 @@ void WebPageManager::reset() {
m_pages.first()->deleteLater();
m_pages.clear();
createPage(this)->setFocus();
currentPage()->currentFrame()->setUrl(QUrl("about:blank"));
}

NetworkCookieJar *WebPageManager::cookieJar() {
Expand Down

0 comments on commit f95e4eb

Please sign in to comment.