1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_contentblockingnotifier_h
8 #define mozilla_contentblockingnotifier_h
9 
10 #include "nsStringFwd.h"
11 #include "mozilla/Maybe.h"
12 
13 #define ANTITRACKING_CONSOLE_CATEGORY "Content Blocking"_ns
14 
15 class nsIChannel;
16 class nsPIDOMWindowInner;
17 class nsPIDOMWindowOuter;
18 
19 namespace mozilla {
20 namespace dom {
21 class BrowsingContext;
22 }  // namespace dom
23 
24 class ContentBlockingNotifier final {
25  public:
26   enum class BlockingDecision {
27     eBlock,
28     eAllow,
29   };
30   enum StorageAccessPermissionGrantedReason {
31     eStorageAccessAPI,
32     eOpenerAfterUserInteraction,
33     eOpener,
34     ePrivilegeStorageAccessForOriginAPI,
35   };
36 
37   // This method can be called on the parent process or on the content process.
38   // The notification is propagated to the child channel if aChannel is a parent
39   // channel proxy.
40   //
41   // aDecision can be eBlock if we have decided to block some content, or eAllow
42   // if we have decided to allow the content through.
43   //
44   // aRejectedReason must be one of these values:
45   //  * nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION
46   //  * nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER
47   //  * nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER
48   //  * nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL
49   //  * nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN
50   static void OnDecision(nsIChannel* aChannel, BlockingDecision aDecision,
51                          uint32_t aRejectedReason);
52 
53   static void OnDecision(nsPIDOMWindowInner* aWindow,
54                          BlockingDecision aDecision, uint32_t aRejectedReason);
55 
56   static void OnDecision(dom::BrowsingContext* aBrowsingContext,
57                          BlockingDecision aDecision, uint32_t aRejectedReason);
58 
59   static void OnEvent(nsIChannel* aChannel, uint32_t aRejectedReason,
60                       bool aBlocked = true);
61 
62   static void OnEvent(
63       nsIChannel* aChannel, bool aBlocked, uint32_t aRejectedReason,
64       const nsACString& aTrackingOrigin,
65       const Maybe<StorageAccessPermissionGrantedReason>& aReason = Nothing());
66 
67   static void ReportUnblockingToConsole(
68       dom::BrowsingContext* aBrowsingContext, const nsAString& aTrackingOrigin,
69       StorageAccessPermissionGrantedReason aReason);
70 };
71 
72 }  // namespace mozilla
73 
74 #endif  // mozilla_contentblockingnotifier_h
75