Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shared cookie jar for all windows

  • Loading branch information...
commit 58e6a2539841d5a0cb9361db537fb2853ded9a58 1 parent 5b5067f
@mhoran mhoran authored
View
29 spec/driver_spec.rb
@@ -1672,6 +1672,35 @@ def which_for(character)
end
end
+ context "javascript new window cookie app" do
+ let(:session_id) { '12345' }
+
+ before(:all) do
+ @app = lambda do |env|
+ request = ::Rack::Request.new(env)
+ response = ::Rack::Response.new
+ case request.path
+ when '/new_window'
+ response.write <<-HTML
+ <html>
+ <script type="text/javascript">
+ window.open('http://#{request.host_with_port}/set_cookie');
+ </script>
+ </html>
+ HTML
+ when '/set_cookie'
+ response.set_cookie('session_id', session_id)
+ end
+ response
+ end
+ end
+
+ it "should preserve cookies across windows" do
+ subject.visit("/new_window")
+ subject.cookies['session_id'].should == session_id
+ end
+ end
+
context "timers app" do
before(:all) do
@app = lambda do |env|
View
5 src/ClearCookies.cpp
@@ -8,9 +8,6 @@ ClearCookies::ClearCookies(WebPageManager *manager, QStringList &arguments, QObj
void ClearCookies::start()
{
- NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
- ->networkAccessManager()
- ->cookieJar());
- jar->clearCookies();
+ manager()->cookieJar()->clearCookies();
emit finished(new Response(true));
}
View
4 src/GetCookies.cpp
@@ -10,9 +10,7 @@ GetCookies::GetCookies(WebPageManager *manager, QStringList &arguments, QObject
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
4 src/SetCookie.cpp
@@ -9,9 +9,7 @@ SetCookie::SetCookie(WebPageManager *manager, QStringList &arguments, QObject *p
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
2  src/WebPage.cpp
@@ -43,7 +43,7 @@ void WebPage::resetWindowSize() {
void WebPage::setCustomNetworkAccessManager() {
NetworkAccessManager *manager = new NetworkAccessManager(this);
- manager->setCookieJar(new NetworkCookieJar(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>)),
View
7 src/WebPageManager.cpp
@@ -1,9 +1,11 @@
#include "WebPageManager.h"
#include "WebPage.h"
+#include "NetworkCookieJar.h"
#include <stdio.h>
WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
m_ignoreSslErrors = false;
+ m_cookieJar = new NetworkCookieJar(this);
createPage(this)->setFocus();
}
@@ -48,7 +50,12 @@ bool WebPageManager::ignoreSslErrors() {
}
void WebPageManager::reset() {
+ m_cookieJar->clearCookies();
m_pages.first()->deleteLater();
m_pages.clear();
createPage(this)->setFocus();
}
+
+NetworkCookieJar *WebPageManager::cookieJar() {
+ return m_cookieJar;
+}
View
3  src/WebPageManager.h
@@ -4,6 +4,7 @@
#include <QObject>
class WebPage;
+class NetworkCookieJar;
class WebPageManager : public QObject {
Q_OBJECT
@@ -18,6 +19,7 @@ class WebPageManager : public QObject {
void setIgnoreSslErrors(bool);
bool ignoreSslErrors();
void reset();
+ NetworkCookieJar *cookieJar();
public slots:
void emitPageFinished(bool);
@@ -31,6 +33,7 @@ class WebPageManager : public QObject {
QList<WebPage *> m_pages;
WebPage *m_currentPage;
bool m_ignoreSslErrors;
+ NetworkCookieJar *m_cookieJar;
};
#endif // _WEBPAGEMANAGER_H
Please sign in to comment.
Something went wrong with that request. Please try again.