From 7040d79ff996b00091f09abceff37b85491d42b3 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sat, 8 Dec 2018 20:19:16 +0000 Subject: [PATCH] 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 --- dom/base/ContentBlockingLog.h | 10 +++++++--- dom/base/nsGlobalWindowOuter.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dom/base/ContentBlockingLog.h b/dom/base/ContentBlockingLog.h index c59ea1fb712a..2c3dfaf2ada1 100644 --- a/dom/base/ContentBlockingLog.h +++ b/dom/base/ContentBlockingLog.h @@ -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) { diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index ec3f466d6c0a..c58b5787eec3 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -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;