diff --git a/browser/extensions/report-site-issue/background.js b/browser/extensions/report-site-issue/background.js index 610b22be8f4d..d5c4edcbd7f0 100644 --- a/browser/extensions/report-site-issue/background.js +++ b/browser/extensions/report-site-issue/background.js @@ -80,7 +80,7 @@ function checkForFrameworks(tabId) { ${hasFastClickPageScript}; ${hasMobifyPageScript}; ${hasMarfeelPageScript}; - + const result = { hasFastClick: hasFastClickPageScript(), hasMobify: hasMobifyPageScript(), diff --git a/browser/extensions/report-site-issue/experimentalAPIs/tabExtras.js b/browser/extensions/report-site-issue/experimentalAPIs/tabExtras.js index 9e4e0ebd0203..032d4bf8dd03 100644 --- a/browser/extensions/report-site-issue/experimentalAPIs/tabExtras.js +++ b/browser/extensions/report-site-issue/experimentalAPIs/tabExtras.js @@ -174,11 +174,13 @@ function getInfoFrameScript(messageName) { }); } - sendAsyncMessage(messageName, { - hasMixedActiveContentBlocked: docShell.hasMixedActiveContentBlocked, - hasMixedDisplayContentBlocked: docShell.hasMixedDisplayContentBlocked, - hasTrackingContentBlocked: docShell.hasTrackingContentBlocked, - log: getLoggedMessages(content), + docShell.getHasTrackingContentBlocked().then(hasTrackingContentBlocked => { + sendAsyncMessage(messageName, { + hasMixedActiveContentBlocked: docShell.hasMixedActiveContentBlocked, + hasMixedDisplayContentBlocked: docShell.hasMixedDisplayContentBlocked, + hasTrackingContentBlocked, + log: getLoggedMessages(content), + }); }); } diff --git a/browser/extensions/report-site-issue/test/browser/browser_report_site_issue.js b/browser/extensions/report-site-issue/test/browser/browser_report_site_issue.js index f5c3139a2daa..ed9b3e0332be 100644 --- a/browser/extensions/report-site-issue/test/browser/browser_report_site_issue.js +++ b/browser/extensions/report-site-issue/test/browser/browser_report_site_issue.js @@ -95,8 +95,8 @@ add_task(async function test_opened_page() { "docShell.hasMixedDisplayContentBlocked is available" ); is( - typeof docShell.hasTrackingContentBlocked, - "boolean", + typeof docShell.getHasTrackingContentBlocked, + "function", "docShell.hasTrackingContentBlocked is available" ); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d2ddb1a3f24e..40827243c024 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1402,9 +1402,37 @@ nsDocShell::GetHasMixedDisplayContentBlocked( } NS_IMETHODIMP -nsDocShell::GetHasTrackingContentBlocked(bool* aHasTrackingContentBlocked) { +nsDocShell::GetHasTrackingContentBlocked(Promise** aPromise) { + MOZ_ASSERT(aPromise); + + ErrorResult rv; RefPtr doc(GetDocument()); - *aHasTrackingContentBlocked = doc && doc->GetHasTrackingContentBlocked(); + RefPtr retPromise = Promise::Create(doc->GetOwnerGlobal(), rv); + if (NS_WARN_IF(rv.Failed())) { + return rv.StealNSResult(); + } + + // Retrieve the document's content blocking events from the parent process. + RefPtr promise = + doc->GetContentBlockingEvents(); + if (promise) { + promise->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [retPromise](const Document::GetContentBlockingEventsPromise:: + ResolveOrRejectValue& aValue) { + if (aValue.IsResolve()) { + bool has = aValue.ResolveValue() & + nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT; + retPromise->MaybeResolve(has); + } else { + retPromise->MaybeResolve(false); + } + }); + } else { + retPromise->MaybeResolve(false); + } + + retPromise.forget(aPromise); return NS_OK; } diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 267856626bdf..623ed5fa939a 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -512,12 +512,6 @@ interface nsIDocShell : nsIDocShellTreeItem */ [infallible] readonly attribute boolean hasMixedDisplayContentBlocked; - /** - * This attribute determines whether a document has Tracking Content - * that has been blocked from loading. - */ - [infallible] readonly attribute boolean hasTrackingContentBlocked; - /** * Disconnects this docshell's editor from its window, and stores the * editor data in the open document's session history entry. This @@ -1114,6 +1108,13 @@ interface nsIDocShell : nsIDocShellTreeItem */ Promise getContentBlockingLog(); + /** + * This returns a Promise which resolves to a boolean. True when the + * document has Tracking Content that has been blocked from loading, false + * otherwise. + */ + Promise getHasTrackingContentBlocked(); + /** * Return whether this docshell is "attempting to navigate" in the * sense that's relevant to document.open. diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index a04d283fa17d..577fedbfc720 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -15488,7 +15488,34 @@ already_AddRefed Document::HasStorageAccess( return promise.forget(); } -already_AddRefed Document::RequestStorageAccess(ErrorResult& aRv) { +RefPtr +Document::GetContentBlockingEvents() { + RefPtr inner = GetInnerWindow(); + if (!inner) { + return nullptr; + } + + RefPtr wgc = inner->GetWindowGlobalChild(); + if (!wgc) { + return nullptr; + } + + return wgc->SendGetContentBlockingEvents()->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [](const WindowGlobalChild::GetContentBlockingEventsPromise:: + ResolveOrRejectValue& aValue) { + if (aValue.IsResolve()) { + return Document::GetContentBlockingEventsPromise::CreateAndResolve( + aValue.ResolveValue(), __func__); + } + + return Document::GetContentBlockingEventsPromise::CreateAndReject( + false, __func__); + }); +} + +already_AddRefed Document::RequestStorageAccess( + mozilla::ErrorResult& aRv) { nsIGlobalObject* global = GetScopeObject(); if (!global) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); diff --git a/dom/base/Document.h b/dom/base/Document.h index 1ba97a738c1b..d4951519f105 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1109,6 +1109,13 @@ class Document : public nsINode, mHasUnsafeEvalCSP = aHasUnsafeEvalCSP; } + /** + * Return a promise which resolves to the content blocking events. + */ + typedef MozPromise GetContentBlockingEventsPromise; + MOZ_MUST_USE RefPtr + GetContentBlockingEvents(); + /** * Get the content blocking log. */ diff --git a/dom/ipc/PWindowGlobal.ipdl b/dom/ipc/PWindowGlobal.ipdl index 7e113d119108..170cb4dc5005 100644 --- a/dom/ipc/PWindowGlobal.ipdl +++ b/dom/ipc/PWindowGlobal.ipdl @@ -88,6 +88,9 @@ parent: // Attempts to perform a "Web Share". async Share(IPCWebShareData aData) returns (nsresult rv); + // Get content blocking events from the parent process. + async GetContentBlockingEvents() returns (uint32_t events); + async Destroy(); }; diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 550251e59859..481b4c6afe55 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -442,6 +442,14 @@ NS_IMPL_ISUPPORTS0(ShareHandler) } // namespace +mozilla::ipc::IPCResult WindowGlobalParent::RecvGetContentBlockingEvents( + WindowGlobalParent::GetContentBlockingEventsResolver&& aResolver) { + uint32_t events = GetContentBlockingLog()->GetContentBlockingEventsInLog(); + aResolver(events); + + return IPC_OK(); +} + mozilla::ipc::IPCResult WindowGlobalParent::RecvShare( IPCWebShareData&& aData, WindowGlobalParent::ShareResolver&& aResolver) { // Widget Layer handoff... diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index 1c20c0e4dada..a254e02d3d32 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -166,6 +166,9 @@ class WindowGlobalParent final : public WindowGlobalActor, const ClonedMessageData& aData, const ClonedMessageData& aStack); + mozilla::ipc::IPCResult RecvGetContentBlockingEvents( + GetContentBlockingEventsResolver&& aResolver); + void ActorDestroy(ActorDestroyReason aWhy) override; void DrawSnapshotInternal(gfx::CrossProcessPaint* aPaint,