phantomjs/src/cookiejar.cpp

508 lines
17 KiB
C++
Raw Permalink Normal View History

2011-07-19 21:32:42 +04:00
/*
This file is part of the PhantomJS project from Ofi Labs.
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2012 Ivan De Marino <ivan.de.marino@gmail.com>
2011-07-19 21:32:42 +04:00
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "phantom.h"
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
#include "config.h"
2011-07-19 21:32:42 +04:00
#include "cookiejar.h"
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
#include <QDateTime>
2011-07-19 21:32:42 +04:00
#include <QSettings>
#include <QTimer>
2011-07-19 21:32:42 +04:00
#define COOKIE_JAR_VERSION 1
// Operators needed for Cookie Serialization
QT_BEGIN_NAMESPACE
QDataStream &operator<<(QDataStream &stream, const QList<QNetworkCookie> &list)
{
stream << COOKIE_JAR_VERSION;
stream << quint32(list.size());
for (int i = 0; i < list.size(); ++i)
stream << list.at(i).toRawForm();
return stream;
}
2011-07-19 21:32:42 +04:00
QDataStream &operator>>(QDataStream &stream, QList<QNetworkCookie> &list)
{
list.clear();
quint32 version;
stream >> version;
if (version != COOKIE_JAR_VERSION)
return stream;
quint32 count;
stream >> count;
for(quint32 i = 0; i < count; ++i)
{
QByteArray value;
stream >> value;
QList<QNetworkCookie> newCookies = QNetworkCookie::parseCookies(value);
if (newCookies.count() == 0 && value.length() != 0) {
qWarning() << "CookieJar: Unable to parse saved cookie:" << value;
}
for (int j = 0; j < newCookies.count(); ++j)
list.append(newCookies.at(j));
if (stream.atEnd())
break;
}
return stream;
}
QT_END_NAMESPACE
// public:
CookieJar::CookieJar(QString cookiesFile, QObject *parent)
: QNetworkCookieJar(parent)
, m_enabled(true)
{
if (cookiesFile == "") {
m_cookieStorage = 0;
qDebug() << "CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)";
} else {
m_cookieStorage = new QSettings(cookiesFile, QSettings::IniFormat, this);
load();
qDebug() << "CookieJar - Created and will store cookies in:" << cookiesFile;
2011-07-19 21:32:42 +04:00
}
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
// private:
CookieJar::~CookieJar()
{
// On destruction, before saving, clear all the session cookies
purgeSessionCookies();
save();
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> & cookieList, const QUrl &url)
{
// Update cookies in memory
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (isEnabled()) {
QNetworkCookieJar::setCookiesFromUrl(cookieList, url);
save();
}
// No changes occurred
return false;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl &url) const
{
if (isEnabled()) {
return QNetworkCookieJar::cookiesForUrl(url);
}
// The CookieJar is disabled: don't return any cookie
return QList<QNetworkCookie>();
2011-07-19 21:32:42 +04:00
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::addCookie(const QNetworkCookie &cookie, const QString &url)
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (isEnabled() && (!url.isEmpty() || !cookie.domain().isEmpty())) {
// Save a single cookie
setCookiesFromUrl(
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
QList<QNetworkCookie>() << cookie, //< unfortunately, "setCookiesFromUrl" requires a list
!url.isEmpty() ?
url : //< use given URL
QString( //< mock-up a URL
(cookie.isSecure() ? "https://" : "http://") + //< URL protocol
QString(cookie.domain().startsWith('.') ? "www" : "") + cookie.domain() + //< URL domain
(cookie.path().isEmpty() ? "/" : cookie.path()))); //< URL path
// Return "true" if the cookie was really set
if (contains(cookie)) {
return true;
}
qDebug() << "CookieJar - Rejected Cookie" << cookie.toRawForm();
return false;
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return false;
}
2011-07-19 21:32:42 +04:00
void CookieJar::addCookie(const QVariantMap &cookie)
{
addCookieFromMap(cookie);
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::addCookieFromMap(const QVariantMap &cookie, const QString &url)
{
QNetworkCookie newCookie;
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// The cookie must have a non-empty "name" and a "value"
if (!cookie["name"].isNull() && !cookie["name"].toString().isEmpty() && !cookie["value"].isNull()) {
// Name & Value
newCookie.setName(cookie["name"].toByteArray());
newCookie.setValue(cookie["value"].toByteArray());
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Domain, if provided
if (!cookie["domain"].isNull() && !cookie["domain"].toString().isEmpty()) {
newCookie.setDomain(cookie["domain"].toString());
}
// Path, if provided
if (!cookie["path"].isNull() || !cookie["path"].toString().isEmpty()) {
newCookie.setPath(cookie["path"].toString());
}
// HttpOnly, false by default
newCookie.setHttpOnly(cookie["httponly"].isNull() ? false : cookie["httponly"].toBool());
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Secure, false by default
newCookie.setSecure(cookie["secure"].isNull() ? false : cookie["secure"].toBool());
2011-07-19 21:32:42 +04:00
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Expiration Date, if provided, giving priority to "expires" over "expiry"
QVariant expiresVar;
if (!cookie["expires"].isNull()) {
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
expiresVar = cookie["expires"];
} else if (!cookie["expiry"].isNull()) {
expiresVar = cookie["expiry"];
}
if (expiresVar.isValid()) {
QDateTime expirationDate;
if (expiresVar.type() == QVariant::String) {
// Set cookie expire date via "classic" string format
QString datetime = expiresVar.toString().replace(" GMT", "");
expirationDate = QDateTime::fromString(datetime, "ddd, dd MMM yyyy hh:mm:ss");
} else if (expiresVar.type() == QVariant::Double){
// Set cookie expire date via "number of seconds since epoch"
// NOTE: Every JS number is a Double.
// @see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
expirationDate = QDateTime::fromMSecsSinceEpoch(expiresVar.toLongLong());
}
if (expirationDate.isValid()) {
newCookie.setExpirationDate(expirationDate);
}
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return addCookie(newCookie, url);
2011-07-19 21:32:42 +04:00
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return false;
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::addCookies(const QList<QNetworkCookie> &cookiesList, const QString &url)
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool added = false;
for (int i = cookiesList.length() -1; i >=0; --i) {
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (addCookie(cookiesList.at(i), url)) {
// change it to "true" if at least 1 cookie was set
added = true;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return added;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::addCookiesFromMap(const QVariantList &cookiesList, const QString &url)
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool added = false;
for (int i = cookiesList.length() -1; i >= 0; --i) {
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (addCookieFromMap(cookiesList.at(i).toMap(), url)) {
// change it to "true" if at least 1 cookie was set
added = true;
}
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return added;
2011-07-19 21:32:42 +04:00
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
QList<QNetworkCookie> CookieJar::cookies(const QString &url) const
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
{
if (url.isEmpty()) {
// No url provided: return all the cookies in this CookieJar
return allCookies();
} else {
// Return ONLY the cookies that match this URL
return cookiesForUrl(url);
}
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
QVariantList CookieJar::cookiesToMap(const QString &url) const
{
QVariantList result;
QNetworkCookie c;
QVariantMap cookie;
QList<QNetworkCookie> cookiesList = cookies(url);
for (int i = cookiesList.length() -1; i >= 0; --i) {
c = cookiesList.at(i);
cookie["domain"] = QVariant(c.domain());
cookie["name"] = QVariant(QString(c.name()));
cookie["value"] = QVariant(QString(c.value()));
cookie["path"] = (c.path().isNull() || c.path().isEmpty()) ? QVariant("/") : QVariant(c.path());
cookie["httponly"] = QVariant(c.isHttpOnly());
cookie["secure"] = QVariant(c.isSecure());
if (c.expirationDate().isValid()) {
cookie["expires"] = QVariant(QString(c.expirationDate().toString("ddd, dd MMM yyyy hh:mm:ss")).append(" GMT"));
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
cookie["expiry"] = QVariant(c.expirationDate().toMSecsSinceEpoch() / 1000);
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
result.append(cookie);
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
return result;
}
QNetworkCookie CookieJar::cookie(const QString &name, const QString &url) const
{
QList<QNetworkCookie> cookiesList = cookies(url);
for (int i = cookiesList.length() -1; i >= 0; --i) {
if (cookiesList.at(i).name() == name) {
return cookiesList.at(i);
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
return QNetworkCookie();
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
QVariantMap CookieJar::cookieToMap(const QString &name, const QString &url) const
{
QVariantMap cookie;
QVariantList cookiesList = cookiesToMap(url);
for (int i = cookiesList.length() -1; i >= 0; --i) {
cookie = cookiesList.at(i).toMap();
if (cookie["name"].toString() == name) {
return cookie;
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
return QVariantMap();
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::deleteCookie(const QString &name, const QString &url)
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool deleted = false;
if (isEnabled()) {
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// NOTE: This code has been written in an "extended form" to make it
// easy to understand. Surely this could be "shrinked", but it
// would probably look uglier.
QList<QNetworkCookie> cookiesListAll;
if (url.isEmpty()) {
if (name.isEmpty()) { //< Neither "name" or "url" provided
// This method has been used wrong:
// "redirecting" to the right method for the job
clearCookies();
} else { //< Only "name" provided
// Delete all cookies with the given name from the CookieJar
cookiesListAll = allCookies();
for (int i = cookiesListAll.length() -1; i >= 0; --i) {
if (cookiesListAll.at(i).name() == name) {
// Remove this cookie
qDebug() << "CookieJar - Deleted" << cookiesListAll.at(i).toRawForm();
cookiesListAll.removeAt(i);
deleted = true;
}
}
}
} else {
// Delete cookie(s) from the ones visible to the given "url".
// Use the "name" to delete only the right one, otherwise all of them.
QList<QNetworkCookie> cookiesListUrl = cookies(url);
cookiesListAll = allCookies();
for (int i = cookiesListAll.length() -1; i >= 0; --i) {
if (cookiesListUrl.contains(cookiesListAll.at(i)) && //< if it part of the set of cookies visible at URL
(cookiesListAll.at(i).name() == name || name.isEmpty())) { //< and if the name matches, or no name provided
// Remove this cookie
qDebug() << "CookieJar - Deleted" << cookiesListAll.at(i).toRawForm();
cookiesListAll.removeAt(i);
deleted = true;
if (!name.isEmpty()) {
// Only one cookie was supposed to be deleted: we are done here!
break;
}
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Put back the remaining cookies
setAllCookies(cookiesListAll);
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return deleted;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::deleteCookies(const QString &url)
{
if (isEnabled()) {
if (url.isEmpty()) {
// No URL provided: delete ALL the cookies in the CookieJar
clearCookies();
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return true;
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// No cookie name provided: delete all the cookies visible by this URL
qDebug() << "Delete all cookies for URL:" << url;
return deleteCookie("", url);
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
return false;
}
void CookieJar::clearCookies()
{
if (isEnabled()) {
setAllCookies(QList<QNetworkCookie>());
}
}
void CookieJar::enable()
{
m_enabled = true;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
void CookieJar::disable()
{
m_enabled = false;
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
bool CookieJar::isEnabled() const
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
{
return m_enabled;
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
void CookieJar::close()
{
deleteLater();
}
// private:
bool CookieJar::purgeExpiredCookies()
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
QList<QNetworkCookie> cookiesList = allCookies();
// If empty, there is nothing to purge
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (cookiesList.isEmpty()) {
return false;
}
// Check if any cookie has expired
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
int prePurgeCookiesCount = cookiesList.count();
QDateTime now = QDateTime::currentDateTime();
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
for (int i = cookiesList.count() - 1; i >= 0; --i) {
if (!cookiesList.at(i).isSessionCookie() && cookiesList.at(i).expirationDate() < now) {
qDebug() << "CookieJar - Purged (expired)" << cookiesList.at(i).toRawForm();
cookiesList.removeAt(i);
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Set cookies and returns "true" if at least 1 cookie expired and has been removed
if (prePurgeCookiesCount != cookiesList.count()) {
setAllCookies(cookiesList);
return true;
}
return false;
}
bool CookieJar::purgeSessionCookies()
{
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
QList<QNetworkCookie> cookiesList = allCookies();
// If empty, there is nothing to purge
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
if (cookiesList.isEmpty()) {
return false;
}
// Check if any cookie has expired
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
int prePurgeCookiesCount = cookiesList.count();
for (int i = cookiesList.count() - 1; i >= 0; --i) {
if (cookiesList.at(i).isSessionCookie() || !cookiesList.at(i).expirationDate().isValid() || cookiesList.at(i).expirationDate().isNull()) {
qDebug() << "CookieJar - Purged (session)" << cookiesList.at(i).toRawForm();
cookiesList.removeAt(i);
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Set cookies and returns "true" if at least 1 session cookie was found and removed
if (prePurgeCookiesCount != cookiesList.count()) {
setAllCookies(cookiesList);
return true;
}
return false;
}
void CookieJar::save()
{
if (isEnabled()) {
// Get rid of all the Cookies that have expired
purgeExpiredCookies();
#ifndef QT_NO_DEBUG_OUTPUT
foreach (QNetworkCookie cookie, allCookies()) {
qDebug() << "CookieJar - Saved" << cookie.toRawForm();
}
#endif
// Store cookies
if (m_cookieStorage) {
m_cookieStorage->setValue(QLatin1String("cookies"), QVariant::fromValue<QList<QNetworkCookie> >(allCookies()));
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
}
void CookieJar::load()
{
if (isEnabled()) {
// Register a "StreamOperator" for this Meta Type, so we can easily serialize/deserialize the cookies
qRegisterMetaTypeStreamOperators<QList<QNetworkCookie> >("QList<QNetworkCookie>");
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
// Load all the cookies
if (m_cookieStorage) {
setAllCookies(qvariant_cast<QList<QNetworkCookie> >(m_cookieStorage->value(QLatin1String("cookies"))));
}
// If any cookie has expired since last execution, purge and save before going any further
if (purgeExpiredCookies()) {
save();
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
#ifndef QT_NO_DEBUG_OUTPUT
foreach (QNetworkCookie cookie, allCookies()) {
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
qDebug() << "CookieJar - Loaded" << cookie.toRawForm();
}
#endif
Implement in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603 Squashed commit of the following: commit 2087320b9549aa2bba53d73e8a681133e5b4fe96 Author: neraliu <neraliu@gmail.com> Date: Sat Jul 14 20:55:17 2012 +0800 Improve the readability of the function CookieJar::setCookies and CookieJar::cookies. commit 7ef076e9df488c8f82863cb9c6e31350af5eaad8 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:08:07 2012 +0800 Fix the indentation problem in the file cookiejar.cpp. Remove some commented code segment in cookiejar.cpp. commit d8fd7f49eb1ba0fb47c27aec9b3dcd36ca14f301 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 18:04:41 2012 +0800 Simplify the implementation of CookieJar::setCookiesFromUrl to use the same security policy of QNetworkCookieJar::setCookiesFromUrl in QtWebkit commit f5e34d2b787bb9714c45a8ad0baff8b5282d3249 Author: neraliu <neraliu@gmail.com> Date: Fri Jul 13 17:20:38 2012 +0800 Simplify the implementation of CookieJar::cookiesForUrl to use the same security policy of QNetworkCookieJar::cookiesForUrl in QtWebkit. commit 5b10e3788cce7bd69bb71c7ee06f0b49e1e92228 Author: Nera Liu <neraliu@gmail.com> Date: Mon Jun 25 10:56:32 2012 +0800 Remove the clearAllCookies() api by allowing to clear cookies by page.cookies = [] Javascript syntax. commit a1f12b2913b6f3a3f11a2d22b5eb8c35bf62bf48 Author: Nera Liu <neraliu@gmail.com> Date: Sun Jun 24 21:48:49 2012 +0800 Implement in-memory cookies storage for CookieJar allowing dynamic cookie manipulation via Javascript for issue 603. Add sanity check for the in-memory cookies storage for CookieJar. http://code.google.com/p/phantomjs/issues/detail?id=603
2012-09-03 15:27:46 +04:00
}
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool CookieJar::contains(const QNetworkCookie &cookie) const
{
QList<QNetworkCookie> cookiesList = allCookies();
for (int i = cookiesList.length() -1; i >= 0; --i) {
if (cookie.name() == cookiesList.at(i).name() &&
cookie.value() == cookiesList.at(i).value() &&
(cookie.domain().isEmpty() || cookiesList.at(i).domain().prepend('.').endsWith(cookie.domain())) &&
(cookie.path().isEmpty() || cookiesList.at(i).path() == cookie.path()) &&
cookie.isSecure() == cookiesList.at(i).isSecure() &&
cookie.isHttpOnly() == cookiesList.at(i).isHttpOnly() &&
cookie.expirationDate().toMSecsSinceEpoch() == cookiesList.at(i).expirationDate().toMSecsSinceEpoch()
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
) {
return true;
}
}
return false;
}