diff --git a/browser/base/content/sanitize.js b/browser/base/content/sanitize.js index 0eaa57e9f66f..ee9fb81ce71a 100644 --- a/browser/base/content/sanitize.js +++ b/browser/base/content/sanitize.js @@ -249,7 +249,7 @@ Sanitizer.prototype = { if (cookie.creationTime > range[0]) { // This cookie was created after our cutoff, clear it cookieMgr.remove(cookie.host, cookie.name, cookie.path, - cookie.originAttributes, false); + false, cookie.originAttributes); if (++yieldCounter % YIELD_PERIOD == 0) { yield new Promise(resolve => setTimeout(resolve, 0)); // Don't block the main thread too long diff --git a/browser/components/migration/MSMigrationUtils.jsm b/browser/components/migration/MSMigrationUtils.jsm index 5b52ce86bacf..3727e25d3d18 100644 --- a/browser/components/migration/MSMigrationUtils.jsm +++ b/browser/components/migration/MSMigrationUtils.jsm @@ -623,7 +623,7 @@ Cookies.prototype = { // a domain cookie. See bug 222343. if (host.length > 0) { // Fist delete any possible extant matching host cookie. - Services.cookies.remove(host, name, path, {}, false); + Services.cookies.remove(host, name, path, false, {}); // Now make it a domain cookie. if (host[0] != "." && !hostIsIPAddress(host)) host = "." + host; diff --git a/browser/components/preferences/cookies.js b/browser/components/preferences/cookies.js index 827a059707fb..8f2740c27595 100644 --- a/browser/components/preferences/cookies.js +++ b/browser/components/preferences/cookies.js @@ -591,7 +591,7 @@ var gCookiesWindow = { for (var i = 0; i < deleteItems.length; ++i) { var item = deleteItems[i]; this._cm.remove(item.host, item.name, item.path, - item.originAttributes, blockFutureCookies); + blockFutureCookies, item.originAttributes); } }, diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index 67d339a403a1..dcd20140f738 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -851,7 +851,7 @@ var cookieHelpers = { case "path": // Remove the edited cookie. Services.cookies.remove(origHost, origName, origPath, - cookie.originAttributes, false); + false, cookie.originAttributes); break; } @@ -894,8 +894,8 @@ var cookieHelpers = { cookie.host, cookie.name, cookie.path, - cookie.originAttributes, - false + false, + cookie.originAttributes ); } } diff --git a/devtools/shared/gcli/commands/cookie.js b/devtools/shared/gcli/commands/cookie.js index e4fbe728f946..698743e0c439 100644 --- a/devtools/shared/gcli/commands/cookie.js +++ b/devtools/shared/gcli/commands/cookie.js @@ -133,7 +133,7 @@ exports.items = [ if (isCookieAtHost(cookie, host)) { if (cookie.name == args.name) { cookieMgr.remove(cookie.host, cookie.name, cookie.path, - cookie.originAttributes, false); + false, cookie.originAttributes); } } } diff --git a/extensions/cookie/test/unit/test_bug526789.js b/extensions/cookie/test/unit/test_bug526789.js index 12a962a4f5f5..7e4384dcdf84 100644 --- a/extensions/cookie/test/unit/test_bug526789.js +++ b/extensions/cookie/test/unit/test_bug526789.js @@ -28,9 +28,9 @@ function run_test() { do_check_throws(function() { cm.countCookiesFromHost("..baz.com"); }, Cr.NS_ERROR_ILLEGAL_VALUE); - cm.remove("BAZ.com.", "foo", "/", {}, false); + cm.remove("BAZ.com.", "foo", "/", false, {}); do_check_eq(cm.countCookiesFromHost("baz.com"), 1); - cm.remove("baz.com", "foo", "/", {}, false); + cm.remove("baz.com", "foo", "/", false, {}); do_check_eq(cm.countCookiesFromHost("baz.com"), 0); // Test that 'baz.com' and 'baz.com.' are treated differently @@ -40,9 +40,9 @@ function run_test() { do_check_eq(cm.countCookiesFromHost(".baz.com"), 0); do_check_eq(cm.countCookiesFromHost("baz.com."), 1); do_check_eq(cm.countCookiesFromHost(".baz.com."), 1); - cm.remove("baz.com", "foo", "/", {}, false); + cm.remove("baz.com", "foo", "/", false, {}); do_check_eq(cm.countCookiesFromHost("baz.com."), 1); - cm.remove("baz.com.", "foo", "/", {}, false); + cm.remove("baz.com.", "foo", "/", false, {}); do_check_eq(cm.countCookiesFromHost("baz.com."), 0); // test that domain cookies are illegal for IP addresses, aliases such as @@ -174,10 +174,10 @@ function run_test() { }, Cr.NS_ERROR_ILLEGAL_VALUE); do_check_eq(getCookieCount(), 1); - cm.remove("", "foo2", "/", {}, false); + cm.remove("", "foo2", "/", false, {}); do_check_eq(getCookieCount(), 0); do_check_throws(function() { - cm.remove(".", "foo3", "/", {}, false); + cm.remove(".", "foo3", "/", false, {}); }, Cr.NS_ERROR_ILLEGAL_VALUE); // test that the 'domain' attribute accepts a leading dot for IP addresses, diff --git a/extensions/cookie/test/unit/test_cookies_profile_close.js b/extensions/cookie/test/unit/test_cookies_profile_close.js index 833dd3f2da88..b1a3dec785d0 100644 --- a/extensions/cookie/test/unit/test_cookies_profile_close.js +++ b/extensions/cookie/test/unit/test_cookies_profile_close.js @@ -58,7 +58,7 @@ function do_run_test() { }, Cr.NS_ERROR_NOT_AVAILABLE); do_check_throws(function() { - Services.cookiemgr.remove("foo.com", "", "oh4", {}, false); + Services.cookiemgr.remove("foo.com", "", "oh4", false, {}); }, Cr.NS_ERROR_NOT_AVAILABLE); do_check_throws(function() { diff --git a/extensions/cookie/test/unit/test_cookies_read.js b/extensions/cookie/test/unit/test_cookies_read.js index 185931e4a490..b389ad8cc280 100644 --- a/extensions/cookie/test/unit/test_cookies_read.js +++ b/extensions/cookie/test/unit/test_cookies_read.js @@ -86,11 +86,11 @@ function do_run_test() { // remove some of the cookies, in both reverse and forward order for (let i = 100; i-- > 0; ) { let host = i.toString() + ".com"; - Services.cookiemgr.remove(host, "oh", "/", {}, false); + Services.cookiemgr.remove(host, "oh", "/", false, {}); } for (let i = CMAX - 100; i < CMAX; ++i) { let host = i.toString() + ".com"; - Services.cookiemgr.remove(host, "oh", "/", {}, false); + Services.cookiemgr.remove(host, "oh", "/", false, {}); } // check the count diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index a04afc11e052..f2564ec17c6c 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -12,11 +12,13 @@ #include "mozilla/net/NeckoCommon.h" #include "nsCookieService.h" +#include "nsContentUtils.h" #include "nsIServiceManager.h" #include "nsIIOService.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" +#include "nsIScriptError.h" #include "nsICookiePermission.h" #include "nsIURI.h" #include "nsIURL.h" @@ -2366,21 +2368,35 @@ NS_IMETHODIMP nsCookieService::Remove(const nsACString &aHost, const nsACString &aName, const nsACString &aPath, - JS::HandleValue aOriginAttributes, bool aBlocked, - JSContext* aCx) + JS::HandleValue aOriginAttributes, + JSContext* aCx, + uint8_t aArgc) { + MOZ_ASSERT(aArgc == 0 || aArgc == 1); + if (aArgc == 0) { + // This is supposed to be temporary and in 1 or 2 releases we want to + // have originAttributes param as mandatory. But for now, we don't want to + // break existing addons, so we write a console message to inform the addon + // developers about it. + nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, + NS_LITERAL_CSTRING("Cookie Manager"), + nullptr, + nsContentUtils::eNECKO_PROPERTIES, + "nsICookieManagerRemoveDeprecated"); + } + NeckoOriginAttributes attrs; MOZ_ASSERT(attrs.Init(aCx, aOriginAttributes)); - return RemoveNative(aHost, aName, aPath, &attrs, aBlocked); + return RemoveNative(aHost, aName, aPath, aBlocked, &attrs); } NS_IMETHODIMP_(nsresult) nsCookieService::RemoveNative(const nsACString &aHost, const nsACString &aName, const nsACString &aPath, - NeckoOriginAttributes* aOriginAttributes, - bool aBlocked) + bool aBlocked, + NeckoOriginAttributes* aOriginAttributes) { if (NS_WARN_IF(!aOriginAttributes)) { return NS_ERROR_FAILURE; diff --git a/netwerk/cookie/nsICookieManager.idl b/netwerk/cookie/nsICookieManager.idl index c1f39bf51ee6..7670b36a340f 100644 --- a/netwerk/cookie/nsICookieManager.idl +++ b/netwerk/cookie/nsICookieManager.idl @@ -47,21 +47,24 @@ interface nsICookieManager : nsISupports * dot must be present. * @param aName The name specified in the cookie * @param aPath The path for which the cookie was set - * @param aOriginAttributes The originAttributes of this cookie - * @param aBlocked Indicates if cookies from this host should be permanently blocked + * @param aOriginAttributes The originAttributes of this cookie. This + * attribute is optional to avoid breaking add-ons. + * In 1 or 2 releases it will be mandatory: bug 1260399. + * @param aBlocked Indicates if cookies from this host should be permanently + * blocked. * */ - [implicit_jscontext] + [implicit_jscontext, optional_argc] void remove(in AUTF8String aHost, in ACString aName, in AUTF8String aPath, - in jsval aOriginAttributes, - in boolean aBlocked); + in boolean aBlocked, + [optional] in jsval aOriginAttributes); [notxpcom] nsresult removeNative(in AUTF8String aHost, in ACString aName, in AUTF8String aPath, - in NeckoOriginAttributesPtr aOriginAttributes, - in boolean aBlocked); + in boolean aBlocked, + in NeckoOriginAttributesPtr aOriginAttributes); }; diff --git a/netwerk/locales/en-US/necko.properties b/netwerk/locales/en-US/necko.properties index 8ed0e3757eb2..8283cd65f2a6 100644 --- a/netwerk/locales/en-US/necko.properties +++ b/netwerk/locales/en-US/necko.properties @@ -43,3 +43,6 @@ TrackingUriBlocked=The resource at "%1$S" was blocked because tracking protectio # LOCALIZATION NOTE (APIDeprecationWarning): # %1$S is the deprected API; %2$S is the API function that should be used. APIDeprecationWarning=Warning: '%1$S' deprecated, please use '%2$S' + +# LOCALIZATION NOTE (nsICookieManagerRemoveDeprecated): don't localize nsICookieManager.remove() and originAttributes. +nsICookieManagerRemoveDeprecated="'nsICookieManager.remove()' is changed. Update your code and pass the correct originAttributes. Read more on MDN: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsICookieManager' diff --git a/netwerk/test/TestCookie.cpp b/netwerk/test/TestCookie.cpp index b35e51ee8b51..2225b0c3771c 100644 --- a/netwerk/test/TestCookie.cpp +++ b/netwerk/test/TestCookie.cpp @@ -665,8 +665,8 @@ main(int32_t argc, char *argv[]) rv[10] = NS_SUCCEEDED(cookieMgr->RemoveNative(NS_LITERAL_CSTRING("new.domain"), // domain NS_LITERAL_CSTRING("test3"), // name NS_LITERAL_CSTRING("/rabbit"), // path - &attrs, // originAttributes - true)); // is blocked + true, // is blocked + &attrs)); // originAttributes rv[11] = NS_SUCCEEDED(cookieMgr2->CookieExists(newDomainCookie, &found)) && !found; rv[12] = NS_SUCCEEDED(cookieMgr2->Add(NS_LITERAL_CSTRING("new.domain"), // domain NS_LITERAL_CSTRING("/rabbit"), // path diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index dcf1682e7a12..3011d070902a 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -2285,8 +2285,8 @@ GeckoDriver.prototype.deleteAllCookies = function*(cmd, resp) { cookie.host, cookie.name, cookie.path, - cookie.originAttributes, - false); + false, + cookie.originAttributes); return true; }; this.mm.addMessageListener("Marionette:deleteCookie", cb); @@ -2303,8 +2303,8 @@ GeckoDriver.prototype.deleteCookie = function*(cmd, resp) { cookie.host, cookie.name, cookie.path, - cookie.originAttributes, - false); + false, + cookie.originAttributes); return true; }; this.mm.addMessageListener("Marionette:deleteCookie", cb); diff --git a/toolkit/components/extensions/ext-cookies.js b/toolkit/components/extensions/ext-cookies.js index a25399101fda..09afe121ffb2 100644 --- a/toolkit/components/extensions/ext-cookies.js +++ b/toolkit/components/extensions/ext-cookies.js @@ -295,7 +295,7 @@ extensions.registerSchemaAPI("cookies", "cookies", (extension, context) => { remove: function(details) { for (let cookie of query(details, ["url", "name", "storeId"], extension)) { - Services.cookies.remove(cookie.host, cookie.name, cookie.path, cookie.originAttributes, false); + Services.cookies.remove(cookie.host, cookie.name, cookie.path, false, cookie.originAttributes); // Todo: could there be multiple per subdomain? return Promise.resolve({ url: details.url, diff --git a/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions.html b/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions.html index c5e132281e93..fc6fd9b5dac7 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions.html @@ -117,7 +117,7 @@ function* testCookies(options) { yield extension.awaitMessage("change-cookies"); cookieSvc.add(domain, "/", "x", "y", options.secure, false, false, options.expiry); cookieSvc.add(domain, "/", "x", "z", options.secure, false, false, options.expiry); - cookieSvc.remove(domain, "x", "/", {}, false); + cookieSvc.remove(domain, "x", "/", false, {}); extension.sendMessage("cookies-changed"); yield extension.awaitFinish("cookie-permissions"); @@ -168,7 +168,7 @@ function* testCookies(options) { } for (let cookie of cookies) { - cookieSvc.remove(cookie.host, cookie.name, "/", {}, false); + cookieSvc.remove(cookie.host, cookie.name, "/", false, {}); } // Make sure we don't silently poison subsequent tests if something goes wrong. is(getCookies(options.domain).length, 0, "cookies cleared"); diff --git a/toolkit/forgetaboutsite/ForgetAboutSite.jsm b/toolkit/forgetaboutsite/ForgetAboutSite.jsm index 9c7199c7bfcd..dae1be8c1f89 100644 --- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm +++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm @@ -77,7 +77,7 @@ this.ForgetAboutSite = { let enumerator = cm.getCookiesFromHost(aDomain); while (enumerator.hasMoreElements()) { let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie); - cm.remove(cookie.host, cookie.name, cookie.path, cookie.originAttributes, false); + cm.remove(cookie.host, cookie.name, cookie.path, false, cookie.originAttributes); } // EME diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies2.js b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies2.js index 1b1b5cfb8e07..3bfda22d954c 100644 --- a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies2.js +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies2.js @@ -31,7 +31,7 @@ function finish_test(count) { var cm = Components.classes["@mozilla.org/cookiemanager;1"] .getService(Components.interfaces.nsICookieManager2); - cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, {}, false); + cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, false, {}); Services.perms.remove(makeURI("http://example.com"), "install"); diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies3.js b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies3.js index 66e77e856d56..48aed5cbf882 100644 --- a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies3.js +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies3.js @@ -33,7 +33,7 @@ function finish_test(count) { var cm = Components.classes["@mozilla.org/cookiemanager;1"] .getService(Components.interfaces.nsICookieManager2); - cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, {}, false); + cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, false, {}); Services.prefs.clearUserPref("network.cookie.cookieBehavior"); diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js index 31116211b4f5..b42b279ba198 100644 --- a/toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js @@ -33,7 +33,7 @@ function finish_test(count) { is(count, 0, "No add-ons should have been installed"); var cm = Components.classes["@mozilla.org/cookiemanager;1"] .getService(Components.interfaces.nsICookieManager2); - cm.remove("example.org", "xpinstall", "/browser/" + RELATIVE_DIR, {}, false); + cm.remove("example.org", "xpinstall", "/browser/" + RELATIVE_DIR, false, {}); Services.prefs.clearUserPref("network.cookie.cookieBehavior"); Services.perms.remove(makeURI("http://example.com"), "install");