Bug 606655 - delete cookies UI option AskMeEveryTime and its related comments and tests. r=mak

This commit is contained in:
M Hamdy 2015-10-08 09:13:00 +02:00
parent 13401e0dbd
commit 72753aa511
15 changed files with 29 additions and 353 deletions

View File

@ -274,8 +274,13 @@ var gPrivacyPane = {
// adjust the cookie controls status
this.readAcceptCookies();
document.getElementById("keepCookiesUntil").value = disabled ? 2 :
document.getElementById("network.cookie.lifetimePolicy").value;
let lifetimePolicy = document.getElementById("network.cookie.lifetimePolicy").value;
if (lifetimePolicy != Ci.nsICookieService.ACCEPT_NORMALLY &&
lifetimePolicy != Ci.nsICookieService.ACCEPT_SESSION &&
lifetimePolicy != Ci.nsICookieService.ACCEPT_FOR_N_DAYS) {
lifetimePolicy = Ci.nsICookieService.ACCEPT_NORMALLY;
}
document.getElementById("keepCookiesUntil").value = disabled ? 2 : lifetimePolicy;
// adjust the checked state of the sanitizeOnShutdown checkbox
document.getElementById("alwaysClear").checked = disabled ? false :
@ -408,7 +413,6 @@ var gPrivacyPane = {
* network.cookie.lifetimePolicy
* - determines how long cookies are stored:
* 0 means keep cookies until they expire
* 1 means ask how long to keep each cookie
* 2 means keep cookies until the browser is closed
*/

View File

@ -226,7 +226,6 @@
<menupopup>
<menuitem label="&expire.label;" value="0"/>
<menuitem label="&close.label;" value="2"/>
<menuitem label="&askEachTime.label;" value="1"/>
</menupopup>
</menulist>
<spacer flex="1"/>

View File

@ -2,7 +2,6 @@
skip-if = buildapp == "mulet"
support-files =
browser_privatebrowsing_concurrent_page.html
browser_privatebrowsing_cookieacceptdialog.html
browser_privatebrowsing_geoprompt_page.html
browser_privatebrowsing_localStorage_before_after_page.html
browser_privatebrowsing_localStorage_before_after_page2.html
@ -23,7 +22,6 @@ tags = trackingprotection
[browser_privatebrowsing_cache.js]
[browser_privatebrowsing_certexceptionsui.js]
[browser_privatebrowsing_concurrent.js]
[browser_privatebrowsing_cookieacceptdialog.js]
[browser_privatebrowsing_crh.js]
[browser_privatebrowsing_downloadLastDir.js]
[browser_privatebrowsing_downloadLastDir_c.js]

View File

@ -1,11 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>browser_privatebrowsing_cookieacceptdialog.html</title>
<script type="application/javascript">
document.cookie = "foo=bar";
</script>
</head>
<body>
</body>
</html>

View File

@ -1,128 +0,0 @@
/* 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/. */
// This test makes sure that private browsing mode disables the "remember"
// option in the cookie accept dialog.
add_task(function* test() {
// initialization
const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
"privatebrowsing/test/browser/" +
"browser_privatebrowsing_cookieacceptdialog.html";
const BLANK_URL = "http://mochi.test:8888/";
let cp = Cc["@mozilla.org/embedcomp/cookieprompt-service;1"].
getService(Ci.nsICookiePromptService);
function openCookieDialog(aWindow) {
let remember = {};
const time = (new Date("Jan 1, 2030")).getTime() / 1000;
let cookie = {
name: "foo",
value: "bar",
isDomain: true,
host: "mozilla.org",
path: "/baz",
isSecure: false,
expires: time,
status: 0,
policy: 0,
isSession: false,
expiry: time,
isHttpOnly: true,
QueryInterface: function(iid) {
const validIIDs = [Ci.nsISupports, Ci.nsICookie, Ci.nsICookie2];
for (var i = 0; i < validIIDs.length; ++i)
if (iid == validIIDs[i])
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
executeSoon(function () {
cp.cookieDialog(aWindow, cookie, "mozilla.org", 10, false, remember);
});
return BrowserTestUtils.domWindowOpened();
};
function checkRememberOption(expectedDisabled, aWindow) {
return Task.spawn(function* () {
let dialogWin = yield openCookieDialog(aWindow);
yield new Promise(resolve => {
dialogWin.addEventListener("load", function onLoad(event) {
dialogWin.removeEventListener("load", onLoad, false);
resolve();
}, false);
});
let doc = dialogWin.document;
let remember = doc.getElementById("persistDomainAcceptance");
ok(remember, "The remember checkbox should exist");
if (expectedDisabled)
is(remember.getAttribute("disabled"), "true",
"The checkbox should be disabled");
else
ok(!remember.hasAttribute("disabled"),
"The checkbox should not be disabled");
yield BrowserTestUtils.closeWindow(dialogWin);
});
};
function checkSettingDialog(aIsPrivateWindow, aWindow) {
return Task.spawn(function* () {
let dialogOpened = false;
let promiseDialogClosed = null;
function observer(subject, topic, data) {
if (topic != "domwindowopened") { return; }
Services.ww.unregisterNotification(observer);
dialogOpened = true;
promiseDialogClosed = BrowserTestUtils.closeWindow(
subject.QueryInterface(Ci.nsIDOMWindow));
}
Services.ww.registerNotification(observer);
let selectedBrowser = aWindow.gBrowser.selectedBrowser;
selectedBrowser.loadURI(TEST_URL);
yield BrowserTestUtils.browserLoaded(selectedBrowser);;
if (dialogOpened) {
ok(!aIsPrivateWindow,
"Setting dialog shown, confirm normal window");
} else {
Services.ww.unregisterNotification(observer);
ok(aIsPrivateWindow,
"Confirm setting dialog is not displayed for private window");
}
yield promiseDialogClosed;
});
};
// Ask all cookies
Services.prefs.setIntPref("network.cookie.lifetimePolicy", 1);
let win = yield BrowserTestUtils.openNewBrowserWindow();
info("Test on public window");
yield checkRememberOption(false, win);
yield checkSettingDialog(false, win);
let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private: true});
info("Test on private window");
yield checkRememberOption(true, privateWin);
yield checkSettingDialog(true, privateWin);
// Cleanup
Services.prefs.clearUserPref("network.cookie.lifetimePolicy");
yield BrowserTestUtils.closeWindow(win);
yield BrowserTestUtils.closeWindow(privateWin);
});

View File

@ -47,7 +47,6 @@
<!ENTITY expire.label "they expire">
<!ENTITY close.label "I close &brandShortName;">
<!ENTITY askEachTime.label "ask me every time">
<!ENTITY cookieExceptions.label "Exceptions…">
<!ENTITY cookieExceptions.accesskey "E">

View File

@ -8233,10 +8233,8 @@ nsContentUtils::InternalStorageAllowedForPrincipal(nsIPrincipal* aPrincipal,
return access;
}
// We don't want to prompt for every attempt to access permissions, so we
// treat the cookie ASK_BEFORE_ACCEPT as though it was a reject.
if (sCookiesBehavior == nsICookieService::BEHAVIOR_REJECT ||
sCookiesLifetimePolicy == nsICookieService::ASK_BEFORE_ACCEPT) {
// We don't want to prompt for every attempt to access permissions.
if (sCookiesBehavior == nsICookieService::BEHAVIOR_REJECT) {
return StorageAccess::eDeny;
}

View File

@ -232,8 +232,6 @@ DOMStorage::BroadcastChangeNotification(const nsSubstring& aKey,
static const char kPermissionType[] = "cookie";
static const char kStorageEnabled[] = "dom.storage.enabled";
static const char kCookiesBehavior[] = "network.cookie.cookieBehavior";
static const char kCookiesLifetimePolicy[] = "network.cookie.lifetimePolicy";
// static, public
bool

View File

@ -27,21 +27,6 @@ function test1() {
is(ex.name, "SecurityError");
}
// Set cookies behavior to "ask every time".
SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy", 1]],
"clear": [["network.cookie.cookieBehavior"]]},
test2);
}
function test2() {
try {
localStorage.setItem("contentkey", "test-value");
ok(false, "Setting localStorageItem should throw a security exception");
}
catch(ex) {
is(ex.name, "SecurityError");
}
// Set cookies behavior to "reject 3rd party"
SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 1]],
"clear": [["network.cookie.lifetimePolicy"]]},

View File

@ -34,7 +34,7 @@
// values for mCookiesLifetimePolicy
// 0 == accept normally
// 1 == ask before accepting
// 1 == ask before accepting, no more supported, treated like ACCEPT_NORMALLY (Bug 606655).
// 2 == downgrade to session
// 3 == limit lifetime to N days
static const uint32_t ACCEPT_NORMALLY = 0;
@ -51,7 +51,6 @@ static const char kCookiesPrefsMigrated[] = "network.cookie.prefsMigrated";
// obsolete pref names for migration
static const char kCookiesLifetimeEnabled[] = "network.cookie.lifetime.enabled";
static const char kCookiesLifetimeBehavior[] = "network.cookie.lifetime.behavior";
static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies";
static const char kPermissionType[] = "cookie";
@ -84,19 +83,11 @@ nsCookiePermission::Init()
bool migrated;
rv = prefBranch->GetBoolPref(kCookiesPrefsMigrated, &migrated);
if (NS_FAILED(rv) || !migrated) {
bool warnAboutCookies = false;
prefBranch->GetBoolPref(kCookiesAskPermission, &warnAboutCookies);
// if the user is using ask before accepting, we'll use that
if (warnAboutCookies)
prefBranch->SetIntPref(kCookiesLifetimePolicy, ASK_BEFORE_ACCEPT);
bool lifetimeEnabled = false;
prefBranch->GetBoolPref(kCookiesLifetimeEnabled, &lifetimeEnabled);
// if they're limiting lifetime and not using the prompts, use the
// appropriate limited lifetime pref
if (lifetimeEnabled && !warnAboutCookies) {
// if they're limiting lifetime, use the appropriate limited lifetime pref
if (lifetimeEnabled) {
int32_t lifetimeBehavior;
prefBranch->GetIntPref(kCookiesLifetimeBehavior, &lifetimeBehavior);
if (lifetimeBehavior)
@ -120,8 +111,12 @@ nsCookiePermission::PrefChanged(nsIPrefBranch *aPrefBranch,
#define PREF_CHANGED(_P) (!aPref || !strcmp(aPref, _P))
if (PREF_CHANGED(kCookiesLifetimePolicy) &&
NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookiesLifetimePolicy, &val)))
NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookiesLifetimePolicy, &val))) {
if (val != static_cast<int32_t>(ACCEPT_SESSION) && val != static_cast<int32_t>(ACCEPT_FOR_N_DAYS)) {
val = ACCEPT_NORMALLY;
}
mCookiesLifetimePolicy = val;
}
if (PREF_CHANGED(kCookiesLifetimeDays) &&
NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookiesLifetimeDays, &val)))
@ -253,112 +248,15 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
int64_t currentTime = PR_Now() / PR_USEC_PER_SEC;
int64_t delta = *aExpiry - currentTime;
// check whether the user wants to be prompted
if (mCookiesLifetimePolicy == ASK_BEFORE_ACCEPT) {
// if it's a session cookie and the user wants to accept these
// without asking, or if we are in private browsing mode, just
// accept the cookie and return
if ((*aIsSession && mCookiesAlwaysAcceptSession) ||
(aChannel && NS_UsePrivateBrowsing(aChannel))) {
*aResult = true;
return NS_OK;
}
// default to rejecting, in case the prompting process fails
*aResult = false;
nsAutoCString hostPort;
aURI->GetHostPort(hostPort);
if (!aCookie) {
return NS_ERROR_UNEXPECTED;
}
// If there is no host, use the scheme, and append "://",
// to make sure it isn't a host or something.
// This is done to make the dialog appear for javascript cookies from
// file:// urls, and make the text on it not too weird. (bug 209689)
if (hostPort.IsEmpty()) {
aURI->GetScheme(hostPort);
if (hostPort.IsEmpty()) {
// still empty. Just return the default.
return NS_OK;
}
hostPort = hostPort + NS_LITERAL_CSTRING("://");
}
// we don't cache the cookiePromptService - it's not used often, so not
// worth the memory.
nsresult rv;
nsCOMPtr<nsICookiePromptService> cookiePromptService =
do_GetService(NS_COOKIEPROMPTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
// get some useful information to present to the user:
// whether a previous cookie already exists, and how many cookies this host
// has set
bool foundCookie = false;
uint32_t countFromHost;
nsCOMPtr<nsICookieManager2> cookieManager = do_GetService(NS_COOKIEMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoCString rawHost;
aCookie->GetRawHost(rawHost);
rv = cookieManager->CountCookiesFromHost(rawHost, &countFromHost);
if (NS_SUCCEEDED(rv) && countFromHost > 0)
rv = cookieManager->CookieExists(aCookie, &foundCookie);
}
if (NS_FAILED(rv)) return rv;
// check if the cookie we're trying to set is already expired, and return;
// but only if there's no previous cookie, because then we need to delete the previous
// cookie. we need this check to avoid prompting the user for already-expired cookies.
if (!foundCookie && !*aIsSession && delta <= 0) {
// the cookie has already expired. accept it, and let the backend figure
// out it's expired, so that we get correct logging & notifications.
*aResult = true;
return rv;
}
bool rememberDecision = false;
int32_t dialogRes = nsICookiePromptService::DENY_COOKIE;
rv = cookiePromptService->CookieDialog(nullptr, aCookie, hostPort,
countFromHost, foundCookie,
&rememberDecision, &dialogRes);
if (NS_FAILED(rv)) return rv;
*aResult = !!dialogRes;
if (dialogRes == nsICookiePromptService::ACCEPT_SESSION_COOKIE)
// We are accepting the cookie, but,
// if it's not a session cookie, we may have to limit its lifetime.
if (!*aIsSession && delta > 0) {
if (mCookiesLifetimePolicy == ACCEPT_SESSION) {
// limit lifetime to session
*aIsSession = true;
if (rememberDecision) {
switch (dialogRes) {
case nsICookiePromptService::DENY_COOKIE:
mPermMgr->Add(aURI, kPermissionType, (uint32_t) nsIPermissionManager::DENY_ACTION,
nsIPermissionManager::EXPIRE_NEVER, 0);
break;
case nsICookiePromptService::ACCEPT_COOKIE:
mPermMgr->Add(aURI, kPermissionType, (uint32_t) nsIPermissionManager::ALLOW_ACTION,
nsIPermissionManager::EXPIRE_NEVER, 0);
break;
case nsICookiePromptService::ACCEPT_SESSION_COOKIE:
mPermMgr->Add(aURI, kPermissionType, nsICookiePermission::ACCESS_SESSION,
nsIPermissionManager::EXPIRE_NEVER, 0);
break;
default:
break;
}
}
} else {
// we're not prompting, so we must be limiting the lifetime somehow
// if it's a session cookie, we do nothing
if (!*aIsSession && delta > 0) {
if (mCookiesLifetimePolicy == ACCEPT_SESSION) {
// limit lifetime to session
*aIsSession = true;
} else if (delta > mCookiesLifetimeSec) {
// limit lifetime to specified time
*aExpiry = currentTime + mCookiesLifetimeSec;
}
} else if (delta > mCookiesLifetimeSec) {
// limit lifetime to specified time
*aExpiry = currentTime + mCookiesLifetimeSec;
}
}
}

View File

@ -38,4 +38,3 @@ support-files =
[test_same_base_domain_5.html]
[test_same_base_domain_6.html]
[test_samedomain.html]
[test_bug1041808.html]

View File

@ -1,61 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1041808
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1041808</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1041808 **/
SimpleTest.waitForExplicitFinish();
var dialogsOpened = 0;
var dialogsClosed = 0;
function dismissDialog(aSubject, aTopic, aData)
{
if (aTopic == "domwindowopened") {
var win = SpecialPowers.wrap(aSubject);
win.addEventListener("pageshow", function() {
win.removeEventListener("pageshow", arguments.callee, false);
sendKey("RETURN", aSubject);
}, false);
++dialogsOpened;
} else if (aTopic == "domwindowclosed") {
++dialogsClosed;
}
}
function runTest()
{
SpecialPowers.Services.ww.registerNotification(dismissDialog);
document.cookie = "test1=testValue";
document.cookie = "test2=testValue";
document.cookie = "test3=testValue";
SpecialPowers.Services.ww.unregisterNotification(dismissDialog);
is(dialogsOpened, 3, "Setting a cookie should have asked for permission");
is(dialogsOpened - dialogsClosed, 0,
"Setting a cookie shouldn't have left any additional windows open");
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy", 1]]},
runTest);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1041808">Mozilla Bug 1041808</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -1819,7 +1819,7 @@ pref("network.cookie.cookieBehavior", 0); // 0-Accept, 1-dontAcceptForeign
pref("network.cookie.cookieBehavior", 0); // Keep the old default of accepting all cookies
#endif
pref("network.cookie.thirdparty.sessionOnly", false);
pref("network.cookie.lifetimePolicy", 0); // accept normally, 1-askBeforeAccepting, 2-acceptForSession,3-acceptForNDays
pref("network.cookie.lifetimePolicy", 0); // 0-accept, 2-acceptForSession, 3-acceptForNDays
pref("network.cookie.alwaysAcceptSessionCookies", false);
pref("network.cookie.prefsMigrated", false);
pref("network.cookie.lifetime.days", 90);

View File

@ -71,7 +71,7 @@ interface nsIChannel;
* to set the cookie.
* data : the referrer, or "?" if unknown
*/
[scriptable, uuid(f5807c53-de48-461a-8117-bd156bc2dcf0)]
[scriptable, uuid(1e94e283-2811-4f43-b947-d22b1549d824)]
interface nsICookieService : nsISupports
{
/*
@ -87,7 +87,7 @@ interface nsICookieService : nsISupports
* Possible values for the "network.cookie.lifetimePolicy" preference.
*/
const uint32_t ACCEPT_NORMALLY = 0; // accept normally
const uint32_t ASK_BEFORE_ACCEPT = 1; // ask before accepting
// Value = 1 is considered the same as 0 (See Bug 606655).
const uint32_t ACCEPT_SESSION = 2; // downgrade to session
const uint32_t ACCEPT_FOR_N_DAYS = 3; // limit lifetime to N days

View File

@ -28,7 +28,6 @@ static const char kCookiesPermissions[] = "network.cookie.cookieBehavior";
static const char kCookiesLifetimeEnabled[] = "network.cookie.lifetime.enabled";
static const char kCookiesLifetimeDays[] = "network.cookie.lifetime.days";
static const char kCookiesLifetimeCurrentSession[] = "network.cookie.lifetime.behavior";
static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies";
static const char kCookiesMaxPerHost[] = "network.cookie.maxPerHost";
static char *sBuffer;
@ -183,7 +182,6 @@ InitPrefs(nsIPrefBranch *aPrefBranch)
aPrefBranch->SetBoolPref(kCookiesLifetimeEnabled, true);
aPrefBranch->SetIntPref(kCookiesLifetimeCurrentSession, 0);
aPrefBranch->SetIntPref(kCookiesLifetimeDays, 1);
aPrefBranch->SetBoolPref(kCookiesAskPermission, false);
// Set the base domain limit to 50 so we have a known value.
aPrefBranch->SetIntPref(kCookiesMaxPerHost, 50);
}