From e01dca10480ca47b03ed6d02dade15d83e933102 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 13 Aug 2018 15:54:55 -0400 Subject: [PATCH] Bug 1482988 - Handle null arguments in nsContentUtils::StorageDisabledByAntiTracking correctly; r=smaug --- dom/base/nsContentUtils.cpp | 26 +++++++++++++++++--------- dom/base/nsContentUtils.h | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 7ed02a9293a7..e066961b25ca 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -8902,16 +8902,24 @@ nsContentUtils::StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow, return false; } - // FIXME: this is wrong. This method is called also with aWindow and a null - // aChannel. - nsCOMPtr win; - nsresult rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, - getter_AddRefs(win)); - NS_ENSURE_SUCCESS(rv, false); - auto* pwin = nsPIDOMWindowOuter::From(win); + nsCOMPtr pwin; + if (aWindow) { + auto* outer = nsGlobalWindowOuter::Cast(aWindow->GetOuterWindow()); + if (outer) { + pwin = outer->GetTopOuter(); + } + } else if (aChannel) { + nsCOMPtr win; + nsresult rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, + getter_AddRefs(win)); + NS_ENSURE_SUCCESS(rv, false); + pwin = nsPIDOMWindowOuter::From(win); + } - pwin->NotifyContentBlockingState( - nsIWebProgressListener::STATE_BLOCKED_TRACKING_COOKIES, aChannel); + if (pwin) { + pwin->NotifyContentBlockingState( + nsIWebProgressListener::STATE_BLOCKED_TRACKING_COOKIES, aChannel); + } } return disabled; } diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 0ec54a945520..9334159c7626 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2953,6 +2953,7 @@ public: /* * Returns true if this window/channel/aPrincipal should disable storages * because of the anti-tracking feature. + * Note that either aWindow or aChannel may be null when calling this function. */ static bool StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow, nsIChannel* aChannel,