From 40be750cfd7e7e8cc5675518cc640203461a9e48 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Wed, 11 Dec 2019 15:00:53 +0000 Subject: [PATCH] Bug 1599043 - Part 5: Add an IPC message to allow content process to notify the OnContentBlockingEvent in the parent. r=dimi,Ehsan This patch adds an IPC message which allows content process to notify the OnContentBlockingEvent in the parent process. This is needed because there are some situations that the content blocking happens in content processes, so we need to tell the parent process to notify it. Such as, AntiTrackingCommon::AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(). Differential Revision: https://phabricator.services.mozilla.com/D55648 --HG-- extra : moz-landing-system : lando --- dom/ipc/BrowserChild.cpp | 19 ++++++++++++ dom/ipc/BrowserChild.h | 5 ++++ dom/ipc/BrowserParent.cpp | 29 +++++++++++++++++++ dom/ipc/BrowserParent.h | 7 +++++ dom/ipc/PBrowser.ipdl | 7 +++++ .../antitracking/AntiTrackingIPCUtils.h | 28 ++++++++++++++++++ toolkit/components/antitracking/moz.build | 1 + 7 files changed, 96 insertions(+) create mode 100644 toolkit/components/antitracking/AntiTrackingIPCUtils.h diff --git a/dom/ipc/BrowserChild.cpp b/dom/ipc/BrowserChild.cpp index 41a191f75f0f..e815a1474431 100644 --- a/dom/ipc/BrowserChild.cpp +++ b/dom/ipc/BrowserChild.cpp @@ -4008,6 +4008,25 @@ BrowserChild::DoesWindowSupportProtectedMedia() { } #endif +void BrowserChild::NotifyContentBlockingEvent( + uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, nsIURI* aHintURI, + const nsTArray& aTrackingFullHashes, + const Maybe& + aReason) { + if (!IPCOpen()) { + return; + } + + Maybe webProgressData; + RequestData requestData; + nsresult rv = PrepareProgressListenerData(nullptr, aChannel, webProgressData, + requestData); + NS_ENSURE_SUCCESS_VOID(rv); + + Unused << SendNotifyContentBlockingEvent( + aEvent, requestData, aBlocked, aHintURI, aTrackingFullHashes, aReason); +} + BrowserChildMessageManager::BrowserChildMessageManager( BrowserChild* aBrowserChild) : ContentFrameMessageManager(new nsFrameMessageManager(aBrowserChild)), diff --git a/dom/ipc/BrowserChild.h b/dom/ipc/BrowserChild.h index 020a5612b060..31d05fc2fa26 100644 --- a/dom/ipc/BrowserChild.h +++ b/dom/ipc/BrowserChild.h @@ -685,6 +685,11 @@ class BrowserChild final : public nsMessageManagerScriptExecutor, DoesWindowSupportProtectedMedia(); #endif + void NotifyContentBlockingEvent( + uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, nsIURI* aHintURI, + const nsTArray& aTrackingFullHashes, + const Maybe& aReason); + protected: virtual ~BrowserChild(); diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index 984f5f94adaf..35fa1de01c93 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -2702,6 +2702,35 @@ mozilla::ipc::IPCResult BrowserParent::RecvNavigationFinished() { return IPC_OK(); } +mozilla::ipc::IPCResult BrowserParent::RecvNotifyContentBlockingEvent( + const uint32_t& aEvent, const RequestData& aRequestData, + const bool aBlocked, nsIURI* aHintURI, + nsTArray&& aTrackingFullHashes, + const Maybe& + aReason) { + MOZ_ASSERT(aRequestData.elapsedLoadTimeMS().isNothing()); + + RefPtr bc = GetBrowsingContext(); + + if (!bc || bc->IsDiscarded()) { + return IPC_OK(); + } + + // Get the top-level browsing context. + bc = bc->Top(); + RefPtr wgp = + bc->Canonical()->GetCurrentWindowGlobal(); + + nsCOMPtr request = MakeAndAddRef( + aRequestData.requestURI(), aRequestData.originalRequestURI(), + aRequestData.matchedList(), aRequestData.elapsedLoadTimeMS()); + + wgp->NotifyContentBlockingEvent(aEvent, request, aBlocked, aHintURI, + aTrackingFullHashes, aReason); + + return IPC_OK(); +} + bool BrowserParent::GetWebProgressListener( nsIBrowser** aOutBrowser, nsIWebProgress** aOutManager, nsIWebProgressListener** aOutListener) { diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h index ed3e96679965..2e31527c4693 100644 --- a/dom/ipc/BrowserParent.h +++ b/dom/ipc/BrowserParent.h @@ -320,6 +320,13 @@ class BrowserParent final : public PBrowserParent, const Maybe& aWebProgressData, const RequestData& aRequestData, const uint32_t& aEvent); + mozilla::ipc::IPCResult RecvNotifyContentBlockingEvent( + const uint32_t& aEvent, const RequestData& aRequestData, + const bool aBlocked, nsIURI* aHintURI, + nsTArray&& aTrackingFullHashes, + const Maybe& + aReason); + mozilla::ipc::IPCResult RecvNavigationFinished(); bool GetWebProgressListener(nsIBrowser** aOutBrowser, diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index a717a4d0e396..91e6d3ce6d0a 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -30,6 +30,7 @@ include PPrintingTypes; include PTabContext; include PBackgroundSharedTypes; +include "mozilla/AntiTrackingIPCUtils.h"; include "mozilla/GfxMessageUtils.h"; include "mozilla/layers/LayersMessageUtils.h"; include "mozilla/ipc/TransportSecurityInfoUtils.h"; @@ -97,6 +98,7 @@ using mozilla::ScrollFlags from "mozilla/PresShellForwards.h"; using struct InputFormData from "mozilla/dom/SessionStoreMessageUtils.h"; using struct CollectedInputDataValue from "mozilla/dom/SessionStoreMessageUtils.h"; using refcounted class nsITransportSecurityInfo from "nsITransportSecurityInfo.h"; +using mozilla::AntiTrackingCommon::StorageAccessGrantedReason from "mozilla/AntiTrackingCommon.h"; namespace mozilla { namespace dom { @@ -624,6 +626,11 @@ parent: async OnContentBlockingEvent(WebProgressData? aWebProgressData, RequestData aRequestData, uint32_t aEvent); + async NotifyContentBlockingEvent(uint32_t aEvent, RequestData aRequestData, + bool aBlocked, nsIURI aHintURI, + nsCString[] aTrackingFullHashes, + StorageAccessGrantedReason? aReason); + async NavigationFinished(); async SessionStoreUpdate(nsCString? aDocShellCaps, bool? aPrivatedMode, diff --git a/toolkit/components/antitracking/AntiTrackingIPCUtils.h b/toolkit/components/antitracking/AntiTrackingIPCUtils.h new file mode 100644 index 000000000000..9faa13baad51 --- /dev/null +++ b/toolkit/components/antitracking/AntiTrackingIPCUtils.h @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_antitrackingipcutils_h +#define mozilla_antitrackingipcutils_h + +#include "ipc/IPCMessageUtils.h" + +#include "mozilla/AntiTrackingCommon.h" + +namespace IPC { + +// For allowing passing the enum AntiTrackingCommon::StorageAccessGrantedReason +// over IPC. +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive< + mozilla::AntiTrackingCommon::StorageAccessGrantedReason, + mozilla::AntiTrackingCommon::StorageAccessGrantedReason:: + eStorageAccessAPI, + mozilla::AntiTrackingCommon::StorageAccessGrantedReason::eOpener> {}; + +} // namespace IPC + +#endif // mozilla_antitrackingipcutils_h diff --git a/toolkit/components/antitracking/moz.build b/toolkit/components/antitracking/moz.build index 8efa1895cd7c..7624f29b620b 100644 --- a/toolkit/components/antitracking/moz.build +++ b/toolkit/components/antitracking/moz.build @@ -32,6 +32,7 @@ XPCOM_MANIFESTS += [ EXPORTS.mozilla = [ 'AntiTrackingCommon.h', + 'AntiTrackingIPCUtils.h', 'StorageAccess.h', 'StoragePrincipalHelper.h', 'URLDecorationStripper.h',