2015-11-13 16:35:22 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2017-10-12 18:06:26 +03:00
|
|
|
const {interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2015-11-13 16:35:22 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2015-11-13 16:35:22 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
Cu.import("chrome://marionette/content/assert.js");
|
2017-10-28 13:37:40 +03:00
|
|
|
const {
|
|
|
|
InvalidCookieDomainError,
|
|
|
|
UnableToSetCookieError,
|
|
|
|
} = Cu.import("chrome://marionette/content/error.js", {});
|
2017-10-13 19:59:30 +03:00
|
|
|
const {pprint} = Cu.import("chrome://marionette/content/format.js", {});
|
2015-11-13 16:35:22 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
this.EXPORTED_SYMBOLS = ["cookie"];
|
2015-11-13 16:35:22 +03:00
|
|
|
|
|
|
|
const IPV4_PORT_EXPR = /:\d+$/;
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/** @namespace */
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
this.cookie = {
|
|
|
|
manager: Services.cookies,
|
|
|
|
};
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/**
|
|
|
|
* @name Cookie
|
|
|
|
*
|
|
|
|
* @return {Object.<string, (number|boolean|string)>
|
|
|
|
*/
|
|
|
|
|
2015-11-13 16:35:22 +03:00
|
|
|
/**
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Unmarshal a JSON Object to a cookie representation.
|
|
|
|
*
|
|
|
|
* Effectively this will run validation checks on |json|, which will
|
|
|
|
* produce the errors expected by WebDriver if the input is not valid.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Object.<string, (number|boolean|string)>} json
|
2017-10-28 13:37:40 +03:00
|
|
|
* Cookie to be deserialised. <var>name</var> and <var>value</var>
|
|
|
|
* are required fields which must be strings. The <var>path</var> and
|
2017-09-29 17:22:50 +03:00
|
|
|
* <var>domain</var> fields are optional, but must be a string if
|
|
|
|
* provided.
|
2017-10-28 13:37:40 +03:00
|
|
|
* The <var>secure</var>, and <var>httpOnly</var> are similarly
|
|
|
|
* optional, but must be booleans. Likewise, the <var>expiry</var> field
|
|
|
|
* is optional but must be unsigned integer.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @return {Cookie}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Valid cookie object.
|
|
|
|
*
|
|
|
|
* @throws {InvalidArgumentError}
|
|
|
|
* If any of the properties are invalid.
|
2015-11-13 16:35:22 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
cookie.fromJSON = function(json) {
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
let newCookie = {};
|
|
|
|
|
2017-08-29 19:33:38 +03:00
|
|
|
assert.object(json, pprint`Expected cookie object, got ${json}`);
|
2015-11-13 16:35:22 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
newCookie.name = assert.string(json.name, "Cookie name must be string");
|
|
|
|
newCookie.value = assert.string(json.value, "Cookie value must be string");
|
|
|
|
|
|
|
|
if (typeof json.path != "undefined") {
|
|
|
|
newCookie.path = assert.string(json.path, "Cookie path must be string");
|
|
|
|
}
|
2017-10-28 13:37:40 +03:00
|
|
|
if (typeof json.domain != "undefined") {
|
|
|
|
newCookie.domain = assert.string(json.domain, "Cookie domain must be string");
|
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
if (typeof json.secure != "undefined") {
|
|
|
|
newCookie.secure = assert.boolean(json.secure, "Cookie secure flag must be boolean");
|
2015-11-13 16:35:22 +03:00
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
if (typeof json.httpOnly != "undefined") {
|
|
|
|
newCookie.httpOnly = assert.boolean(json.httpOnly, "Cookie httpOnly flag must be boolean");
|
|
|
|
}
|
|
|
|
if (typeof json.expiry != "undefined") {
|
|
|
|
newCookie.expiry = assert.positiveInteger(json.expiry, "Cookie expiry must be a positive integer");
|
|
|
|
}
|
|
|
|
|
|
|
|
return newCookie;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert cookie to the cookie store.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Cookie} newCookie
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Cookie to add.
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {string=} restrictToHost
|
|
|
|
* Perform test that <var>newCookie</var>'s domain matches this.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
*
|
|
|
|
* @throws {TypeError}
|
2017-07-26 15:11:53 +03:00
|
|
|
* If <var>name</var>, <var>value</var>, or <var>domain</var> are
|
|
|
|
* not present and of the correct type.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* @throws {InvalidCookieDomainError}
|
2017-07-26 15:11:53 +03:00
|
|
|
* If <var>restrictToHost</var> is set and <var>newCookie</var>'s
|
|
|
|
* domain does not match.
|
2017-10-28 13:37:40 +03:00
|
|
|
* @throws {UnableToSetCookieError}
|
|
|
|
* If an error occurred while trying to save the cookie.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
*/
|
2017-07-26 15:11:53 +03:00
|
|
|
cookie.add = function(newCookie, {restrictToHost = null} = {}) {
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
assert.string(newCookie.name, "Cookie name must be string");
|
|
|
|
assert.string(newCookie.value, "Cookie value must be string");
|
2017-10-12 18:06:26 +03:00
|
|
|
|
2017-10-28 13:37:40 +03:00
|
|
|
if (typeof newCookie.path == "undefined") {
|
|
|
|
newCookie.path = "/";
|
|
|
|
}
|
|
|
|
|
2017-10-12 18:06:26 +03:00
|
|
|
let hostOnly = false;
|
|
|
|
if (typeof newCookie.domain == "undefined") {
|
|
|
|
hostOnly = true;
|
|
|
|
newCookie.domain = restrictToHost;
|
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
assert.string(newCookie.domain, "Cookie domain must be string");
|
2015-11-13 16:35:22 +03:00
|
|
|
|
2017-10-28 13:37:40 +03:00
|
|
|
if (typeof newCookie.secure == "undefined") {
|
|
|
|
newCookie.secure = false;
|
|
|
|
}
|
|
|
|
if (typeof newCookie.httpOnly == "undefined") {
|
|
|
|
newCookie.httpOnly = false;
|
2015-11-13 16:35:22 +03:00
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
if (typeof newCookie.expiry == "undefined") {
|
2017-10-28 13:37:40 +03:00
|
|
|
// The XPCOM interface requires the expiry field even for session cookies.
|
|
|
|
newCookie.expiry = Number.MAX_SAFE_INTEGER;
|
|
|
|
newCookie.session = true;
|
|
|
|
} else {
|
|
|
|
newCookie.session = false;
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
}
|
2015-11-13 16:35:22 +03:00
|
|
|
|
2017-10-12 18:06:26 +03:00
|
|
|
let isIpAddress = false;
|
|
|
|
try {
|
|
|
|
Services.eTLD.getPublicSuffixFromHost(newCookie.domain);
|
|
|
|
} catch (e) {
|
|
|
|
switch (e.result) {
|
|
|
|
case Cr.NS_ERROR_HOST_IS_IP_ADDRESS:
|
|
|
|
isIpAddress = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new InvalidCookieDomainError(newCookie.domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hostOnly && !isIpAddress) {
|
|
|
|
// only store this as a domain cookie if the domain was specified in the
|
|
|
|
// request and it wasn't an IP address.
|
|
|
|
newCookie.domain = "." + newCookie.domain;
|
|
|
|
}
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
if (restrictToHost) {
|
2017-09-29 17:22:50 +03:00
|
|
|
if (!restrictToHost.endsWith(newCookie.domain) &&
|
2017-10-12 18:06:26 +03:00
|
|
|
("." + restrictToHost) !== newCookie.domain &&
|
|
|
|
restrictToHost !== newCookie.domain) {
|
|
|
|
throw new InvalidCookieDomainError(`Cookies may only be set ` +
|
2017-09-29 17:22:50 +03:00
|
|
|
`for the current domain (${restrictToHost})`);
|
2015-11-13 16:35:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
// remove port from domain, if present.
|
|
|
|
// unfortunately this catches IPv6 addresses by mistake
|
|
|
|
// TODO: Bug 814416
|
|
|
|
newCookie.domain = newCookie.domain.replace(IPV4_PORT_EXPR, "");
|
|
|
|
|
2017-10-28 13:37:40 +03:00
|
|
|
try {
|
|
|
|
cookie.manager.add(
|
|
|
|
newCookie.domain,
|
|
|
|
newCookie.path,
|
|
|
|
newCookie.name,
|
|
|
|
newCookie.value,
|
|
|
|
newCookie.secure,
|
|
|
|
newCookie.httpOnly,
|
|
|
|
newCookie.session,
|
|
|
|
newCookie.expiry,
|
|
|
|
{} /* origin attributes */);
|
|
|
|
} catch (e) {
|
|
|
|
throw new UnableToSetCookieError(e);
|
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
};
|
2015-11-13 16:35:22 +03:00
|
|
|
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
/**
|
|
|
|
* Remove cookie from the cookie store.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Cookie} toDelete
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Cookie to remove.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
cookie.remove = function(toDelete) {
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
cookie.manager.remove(
|
|
|
|
toDelete.domain,
|
|
|
|
toDelete.name,
|
|
|
|
toDelete.path,
|
|
|
|
false,
|
|
|
|
{} /* originAttributes */);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-07-26 15:11:53 +03:00
|
|
|
* Iterates over the cookies for the current <var>host</var>. You may
|
|
|
|
* optionally filter for specific paths on that <var>host</var> by
|
|
|
|
* specifying a path in <var>currentPath</var>.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
*
|
|
|
|
* @param {string} host
|
|
|
|
* Hostname to retrieve cookies for.
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {string=} [currentPath="/"] currentPath
|
|
|
|
* Optionally filter the cookies for <var>host</var> for the
|
|
|
|
* specific path. Defaults to "<tt>/</tt>", meaning all cookies
|
|
|
|
* for <var>host</var> are included.
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @return {Iterable.<Cookie>}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
* Iterator.
|
|
|
|
*/
|
2017-09-04 07:49:32 +03:00
|
|
|
cookie.iter = function* (host, currentPath = "/") {
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
assert.string(host, "host must be string");
|
|
|
|
assert.string(currentPath, "currentPath must be string");
|
|
|
|
|
|
|
|
const isForCurrentPath = path => currentPath.indexOf(path) != -1;
|
|
|
|
|
|
|
|
let en = cookie.manager.getCookiesFromHost(host, {});
|
|
|
|
while (en.hasMoreElements()) {
|
|
|
|
let cookie = en.getNext().QueryInterface(Ci.nsICookie2);
|
|
|
|
// take the hostname and progressively shorten
|
|
|
|
let hostname = host;
|
|
|
|
do {
|
|
|
|
if ((cookie.host == "." + hostname || cookie.host == hostname) &&
|
|
|
|
isForCurrentPath(cookie.path)) {
|
2017-10-16 23:42:48 +03:00
|
|
|
let data = {
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
"name": cookie.name,
|
|
|
|
"value": cookie.value,
|
|
|
|
"path": cookie.path,
|
|
|
|
"domain": cookie.host,
|
|
|
|
"secure": cookie.isSecure,
|
|
|
|
"httpOnly": cookie.isHttpOnly,
|
|
|
|
};
|
2017-10-16 23:42:48 +03:00
|
|
|
|
|
|
|
if (!cookie.isSession) {
|
|
|
|
data.expiry = cookie.expiry;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield data;
|
2015-11-13 16:35:22 +03:00
|
|
|
}
|
Bug 1371733 - Move cookie service to chrome space; r=whimboo
The cookie service relies on the current document's
domain which is accessible from chrome space through
this.curBrowser.contentBrowser.contentURI.host.
As it is implemented currently, Marionette's cookie service jumps
between chrome- and content space more than necessary. This incurs
significant serialisation and IPC overhead, considering that the domain,
hostname, and current path information is readily available in chrome
space.
This patch removes all cookie-related functionality from
testing/marionette/listener.js, and implements a pure chrome-only
version of the service. It does, however, not try to fix conformance
issues with the WebDriver specification, of which there are many.
Some of the algorithms, especially to do with iteration over cookies,
implemented in cookie.iter, is also highly suboptimal. I have not
fundamentally changed any algorithms, and so my recommendation is to
address this later when addressing potential conformance bugs.
MozReview-Commit-ID: Fgs8ocbDJxb
--HG--
extra : rebase_source : 16470d5341459e40b1ceed12728451d517bbc490
2017-06-12 20:05:22 +03:00
|
|
|
hostname = hostname.replace(/^.*?\./, "");
|
|
|
|
} while (hostname.indexOf(".") != -1);
|
2015-11-13 16:35:22 +03:00
|
|
|
}
|
|
|
|
};
|