Merge lp:~mardy/webbrowser-app/cookie-domain2 into lp:webbrowser-app

Proposed by Alberto Mardegan
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 718
Merged at revision: 745
Proposed branch: lp:~mardy/webbrowser-app/cookie-domain2
Merge into: lp:webbrowser-app
Prerequisite: lp:~mardy/webbrowser-app/cookie-domain
Diff against target: 145 lines (+56/-19)
2 files modified
src/app/webcontainer/oxide-cookie-helper.cpp (+46/-18)
tests/unittests/oxide-cookie-helper/tst_OxideCookieHelper.cpp (+10/-1)
To merge this branch: bzr merge lp:~mardy/webbrowser-app/cookie-domain2
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Olivier Tilloy Approve
Review via email: mp+237055@code.launchpad.net

Commit message

Fix handling of host cookies

Oxide (and chromium) expect host cookies to be treated in a special way: the domain in the cookie must be left empty, or an initial "." will always be added to the cookie domain.

Description of the change

Fix handling of host cookies

Oxide (and chromium) expect host cookies to be treated in a special way: the domain in the cookie must be left empty, or an initial "." will always be added to the cookie domain.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:718
http://jenkins.qa.ubuntu.com/job/webbrowser-app-ci/1127/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/5473/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/3910
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-utopic-amd64-ci/326
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-utopic-armhf-ci/326
        deb: http://jenkins.qa.ubuntu.com/job/webbrowser-app-utopic-armhf-ci/326/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-utopic-i386-ci/326
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/5174/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/6725
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/6725/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/14115
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/3286
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/4227
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/4227/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/webbrowser-app-ci/1127/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webcontainer/oxide-cookie-helper.cpp'
2--- src/app/webcontainer/oxide-cookie-helper.cpp 2014-10-03 12:49:16 +0000
3+++ src/app/webcontainer/oxide-cookie-helper.cpp 2014-10-03 12:49:16 +0000
4@@ -22,7 +22,6 @@
5 #include <QDebug>
6 #include <QMap>
7 #include <QMetaMethod>
8-#include <QSet>
9 #include <QUrl>
10
11 typedef QList<QNetworkCookie> Cookies;
12@@ -36,13 +35,15 @@
13 OxideCookieHelperPrivate(OxideCookieHelper* q);
14
15 void setCookies(const QList<QNetworkCookie>& cookies);
16+ QList<QNetworkCookie> cookiesWithDomain(const QList<QNetworkCookie>& cookies,
17+ const QString& domain);
18
19 private Q_SLOTS:
20- void oxideCookiesUpdated(int requestId, const QVariant& failedCookies);
21+ void oxideCookiesUpdated(int requestId, const QVariant& failedCookiesVariant);
22
23 private:
24 QObject* m_backend;
25- QSet<int> m_pendingCalls;
26+ QMap<int, QString> m_pendingCalls;
27 QList<QNetworkCookie> m_failedCookies;
28 mutable OxideCookieHelper* q_ptr;
29 };
30@@ -81,29 +82,38 @@
31 /* Since Oxide does not support setting cookies for different domains in a
32 * single call to setCookies(), we group the cookies by their domain, and
33 * perform a separate call to Oxide's setCookies() for each domain.
34+ *
35+ * Cookies whose domain doesn't start with a "." are host cookies, and need
36+ * to be treated specially: we will use their domain as host (that is, we
37+ * will pass it as first argument in the setNetworkCookies() call), and
38+ * will unset their domain in the cookie.
39 */
40- QMap<QString, Cookies> cookiesPerDomain;
41+ QMap<QString, Cookies> cookiesPerHost;
42 Q_FOREACH(const QNetworkCookie &cookie, cookies) {
43- /* This creates an empty list if the domain is new in the map */
44+ QNetworkCookie c(cookie);
45+ /* We use the domain (without any starting dot) as host */
46+ QString host = c.domain();
47+ if (host.startsWith('.')) {
48+ host = host.mid(1);
49+ } else {
50+ /* No starting dot => this is a host cookie */
51+ c.setDomain(QString());
52+ }
53+ /* This creates an empty list if the host is new in the map */
54 QList<QNetworkCookie> &domainCookies =
55- cookiesPerDomain[cookie.domain()];
56+ cookiesPerHost[host];
57
58- domainCookies.append(cookie);
59+ domainCookies.append(c);
60 }
61
62 /* Grouping done, perform the calls */
63- QMapIterator<QString, Cookies> it(cookiesPerDomain);
64+ QMapIterator<QString, Cookies> it(cookiesPerHost);
65 while (it.hasNext()) {
66 it.next();
67
68- QString domain = it.key();
69- if (domain.startsWith('.')) {
70- domain = domain.mid(1);
71- }
72-
73 QUrl url;
74 url.setScheme("http");
75- url.setHost(domain);
76+ url.setHost(it.key());
77
78 int requestId = -1;
79 QMetaObject::invokeMethod(m_backend, "setNetworkCookies",
80@@ -112,9 +122,9 @@
81 Q_ARG(const QUrl&, url),
82 Q_ARG(const QList<QNetworkCookie>&, it.value()));
83 if (Q_UNLIKELY(requestId == -1)) {
84- m_failedCookies.append(it.value());
85+ m_failedCookies.append(cookiesWithDomain(it.value(), url.host()));
86 } else {
87- m_pendingCalls.insert(requestId);
88+ m_pendingCalls.insert(requestId, url.host());
89 }
90 }
91
92@@ -127,12 +137,30 @@
93 }
94 }
95
96+QList<QNetworkCookie>
97+OxideCookieHelperPrivate::cookiesWithDomain(const QList<QNetworkCookie>& cookies,
98+ const QString& domain)
99+{
100+ QList<QNetworkCookie> restoredCookies;
101+ Q_FOREACH(const QNetworkCookie& cookie, cookies) {
102+ QNetworkCookie c(cookie);
103+ if (c.domain().isEmpty()) {
104+ c.setDomain(domain);
105+ }
106+ restoredCookies.append(c);
107+ }
108+ return restoredCookies;
109+}
110+
111 void OxideCookieHelperPrivate::oxideCookiesUpdated(int requestId,
112- const QVariant& failedCookies)
113+ const QVariant& failedCookiesVariant)
114 {
115 Q_Q(OxideCookieHelper);
116
117- m_failedCookies.append(OxideCookieHelper::cookiesFromVariant(failedCookies));
118+ QString host = m_pendingCalls.value(requestId);
119+ QList<QNetworkCookie> failedCookies =
120+ OxideCookieHelper::cookiesFromVariant(failedCookiesVariant);
121+ m_failedCookies.append(cookiesWithDomain(failedCookies, host));
122 m_pendingCalls.remove(requestId);
123
124 if (m_pendingCalls.isEmpty()) {
125
126=== modified file 'tests/unittests/oxide-cookie-helper/tst_OxideCookieHelper.cpp'
127--- tests/unittests/oxide-cookie-helper/tst_OxideCookieHelper.cpp 2014-10-03 12:49:16 +0000
128+++ tests/unittests/oxide-cookie-helper/tst_OxideCookieHelper.cpp 2014-10-03 12:49:16 +0000
129@@ -53,7 +53,16 @@
130 int setNetworkCookies(const QUrl& url, const QList<QNetworkCookie>& cookies) {
131 if (m_failUrls.contains(url)) return -1;
132 m_lastRequestId++;
133- Q_EMIT setNetworkCookiesCalled(m_lastRequestId, url, cookies);
134+ /* Handle host cookies */
135+ QList<QNetworkCookie> restoredCookies;
136+ Q_FOREACH(const QNetworkCookie& cookie, cookies) {
137+ QNetworkCookie c(cookie);
138+ if (c.domain().isEmpty()) {
139+ c.setDomain(url.host());
140+ }
141+ restoredCookies.append(c);
142+ }
143+ Q_EMIT setNetworkCookiesCalled(m_lastRequestId, url, restoredCookies);
144 return m_lastRequestId;
145 }
146

Subscribers

People subscribed via source and target branches

to status/vote changes: