-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
navigator.cookieEnabled should return false when cookies are actually…
… blocked https://bugs.webkit.org/show_bug.cgi?id=267789 rdar://121284878 Reviewed by Chris Dumez. According to https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-cookieenabled, cookieEnabled should return false when cookies cannot be set (i.e. cookies are blocked). However, in our current implementation, when cookies are blocked, cookieEnabled may return true. This is because WebCookieJar::cookiesEnabled returns true when cookie accept policy is not never, but WebKit does not rely on cookies accept policy to decide whether cookies should be blocked, see NetworkStorageSession::shouldBlockCookies, where network process decides whether to block cookies. Other cookies operations in WebCookieJar send sync messages to network process for answer. To make the result of cookieEnabled consistent with the other operations, WebCookieJar::cookiesEnabled now also fetches the result from network process. To avoid performance issues, instead of sending sync message, web process prefetches and cache the result in Document. The cache is updated on demand, like when document navigates to another URL or when cookie blocking policy changes. * LayoutTests/http/tests/resourceLoadStatistics/exemptDomains/managed-domains-cookieEnabled-expected.txt: Added. * LayoutTests/http/tests/resourceLoadStatistics/exemptDomains/managed-domains-cookieEnabled.html: Added. * LayoutTests/http/tests/resourceLoadStatistics/resources/managed-domains-cookieEnabled-iframe.html: Added. * Source/WebCore/dom/Document.cpp: (WebCore::Document::setCookieURL): (WebCore::Document::setFirstPartyForCookies): (WebCore::Document::updateCachedCookiesEnabled): * Source/WebCore/dom/Document.h: (WebCore::Document::cachedCookiesEnabled const): (WebCore::Document::setCachedCookiesEnabled): (WebCore::Document::setFirstPartyForCookies): Deleted. * Source/WebCore/loader/CookieJar.cpp: (WebCore::CookieJar::cookiesEnabled): (WebCore::CookieJar::remoteCookiesEnabled const): (WebCore::CookieJar::cookiesEnabled const): Deleted. * Source/WebCore/loader/CookieJar.h: * Source/WebCore/platform/network/NetworkStorageSession.cpp: (WebCore::NetworkStorageSession::setPrevalentDomainsToBlockAndDeleteCookiesFor): (WebCore::NetworkStorageSession::setPrevalentDomainsToBlockButKeepCookiesFor): (WebCore::NetworkStorageSession::setDomainsWithUserInteractionAsFirstParty): (WebCore::NetworkStorageSession::setAppBoundDomains): (WebCore::NetworkStorageSession::resetAppBoundDomains): (WebCore::NetworkStorageSession::setManagedDomains): (WebCore::NetworkStorageSession::resetManagedDomains): (WebCore::NetworkStorageSession::cookiesEnabled const): (WebCore::NetworkStorageSession::addCookiesEnabledStateObserver): (WebCore::NetworkStorageSession::removeCookiesEnabledStateObserver): (WebCore::NetworkStorageSession::cookieEnabledStateMayHaveChanged): * Source/WebCore/platform/network/NetworkStorageSession.h: (WebCore::CookiesEnabledStateObserver::~CookiesEnabledStateObserver): * Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess): (WebKit::NetworkConnectionToWebProcess::cookiesEnabledSync): (WebKit::NetworkConnectionToWebProcess::cookiesEnabled): (WebKit::NetworkConnectionToWebProcess::cookieEnabledStateMayHaveChanged): * Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h: (WebKit::NetworkConnectionToWebProcess::protectedConnection): * Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in: * Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp: (WebKit::NetworkProcessConnection::updateCachedCookiesEnabled): * Source/WebKit/WebProcess/Network/NetworkProcessConnection.h: * Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in: * Source/WebKit/WebProcess/WebPage/WebCookieJar.cpp: (WebKit::WebCookieJar::cookiesEnabled): (WebKit::WebCookieJar::remoteCookiesEnabledSync const): (WebKit::WebCookieJar::remoteCookiesEnabled const): (WebKit::WebCookieJar::cookiesEnabled const): Deleted. * Source/WebKit/WebProcess/WebPage/WebCookieJar.h: * Source/WebKit/WebProcess/WebProcess.cpp: (WebKit::WebProcess::setThirdPartyCookieBlockingMode): (WebKit::WebProcess::updateCachedCookiesEnabled): * Source/WebKit/WebProcess/WebProcess.h: Canonical link: https://commits.webkit.org/273522@main
- Loading branch information
Showing
19 changed files
with
269 additions
and
10 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ttp/tests/resourceLoadStatistics/exemptDomains/managed-domains-cookieEnabled-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Tests that navigator.cookieEnabled returns correct value when managed domains are added. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
Step 1: navigator.cookieEnabled is false | ||
Step 2: navigator.cookieEnabled is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
52 changes: 52 additions & 0 deletions
52
...tTests/http/tests/resourceLoadStatistics/exemptDomains/managed-domains-cookieEnabled.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<script src="/js-test-resources/js-test.js"></script> | ||
<script src="../resources/util.js"></script> | ||
</head> | ||
<body> | ||
<iframe id="iframe" src="http://localhost:8000/resourceLoadStatistics/resources/managed-domains-cookieEnabled-iframe.html" onload="runTest()"></iframe> | ||
<script> | ||
description("Tests that navigator.cookieEnabled returns correct value when managed domains are added."); | ||
jsTestIsAsync = true; | ||
var iframeElement = document.getElementById("iframe"); | ||
var currentStep = 1; | ||
|
||
function messageReceived(event) { | ||
debug("Step " + currentStep + ": " + event.data); | ||
++currentStep; | ||
runTest(); | ||
} | ||
|
||
function enableFeatures(enabled, callback) { | ||
setEnableFeature(enabled, () => { | ||
testRunner.setStatisticsShouldBlockThirdPartyCookies(enabled, callback); | ||
}); | ||
} | ||
|
||
function runTest() { | ||
switch(currentStep) { | ||
case 1: | ||
setEnableFeature(true, () => { | ||
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, () => { | ||
iframeElement.contentWindow.postMessage("getCookieEnabled", "*"); | ||
}); | ||
}); | ||
break; | ||
case 2: | ||
testRunner.setManagedDomains([ "http://127.0.0.1:8000" ], () => { | ||
iframeElement.contentWindow.postMessage("getCookieEnabled", "*"); | ||
}); | ||
break; | ||
case 3: | ||
testRunner.setStatisticsShouldBlockThirdPartyCookies(true, () => { | ||
setEnableFeature(false, finishJSTest); | ||
}); | ||
} | ||
} | ||
|
||
addEventListener("message", messageReceived); | ||
</script> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
...sts/http/tests/resourceLoadStatistics/resources/managed-domains-cookieEnabled-iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script> | ||
addEventListener("message", () => { | ||
parent.postMessage("navigator.cookieEnabled is " + navigator.cookieEnabled, "*"); | ||
}); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.