Bug 1510275 - Make sure that we only ever dispatch a single STATE_COOKIES_LOADED notification per top-level document r=baku

Differential Revision: https://phabricator.services.mozilla.com/D13849

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-12-08 20:19:16 +00:00
Родитель 7995f88e40
Коммит 7040d79ff9
2 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -156,6 +156,10 @@ class ContentBlockingLog final {
}
bool HasBlockedAnyOfType(uint32_t aType) {
// Note: nothing inside this loop should return false, the goal for the
// loop is to scan the log to see if we find a matching entry, and if so
// we would return true, otherwise in the end of the function outside of
// the loop we take the common `return false;` statement.
for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
if (!iter.UserData()) {
continue;
@ -166,10 +170,10 @@ class ContentBlockingLog final {
return true;
}
} else if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
if (Get<1>(*iter.UserData()).isSome()) {
return Get<1>(*iter.UserData()).value();
if (Get<1>(*iter.UserData()).isSome() &&
Get<1>(*iter.UserData()).value()) {
return true;
}
return false; // false means not blocked, aka not loaded any cookies
} else {
for (auto& item : Get<2>(*iter.UserData())) {
if ((item.mType & aType) != 0) {

Просмотреть файл

@ -5031,6 +5031,7 @@ void nsGlobalWindowOuter::NotifyContentBlockingState(unsigned aState,
nsAutoString origin;
nsContentUtils::GetUTFOrigin(aURIHint, origin);
bool blockedValue = aBlocked;
bool unblocked = false;
if (aState == nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT) {
doc->SetHasTrackingContentBlocked(aBlocked, origin);
@ -5069,14 +5070,16 @@ void nsGlobalWindowOuter::NotifyContentBlockingState(unsigned aState,
// Note that the logic in this branch is the logical negation of the logic
// in other branches, since the nsIDocument API we have is phrased in
// "loaded" terms as opposed to "blocked" terms.
doc->SetHasCookiesLoaded(!aBlocked, origin);
aBlocked = true;
unblocked = false;
blockedValue = !aBlocked;
doc->SetHasCookiesLoaded(blockedValue, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCookiesLoaded();
}
} else {
// Ignore nsIWebProgressListener::STATE_BLOCKED_UNSAFE_CONTENT;
}
const uint32_t oldState = state;
if (aBlocked) {
if (blockedValue) {
state |= aState;
} else if (unblocked) {
state &= ~aState;