Bug 1494476 - Part 0: Add the HasUserInteraction function r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 10 Oct 2018 15:46:31 +0000
changeset 498991 cc1d49fd799c50999eca236c3b965e27779d1440
parent 498990 73c8dbc2512cd89f694ca9fb3c9692459a6a1f13
child 498992 8c191b926a4395545612361cd38a9874d53a7bb5
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1494476
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494476 - Part 0: Add the HasUserInteraction function r=baku Differential Revision: https://phabricator.services.mozilla.com/D8238
toolkit/components/antitracking/AntiTrackingCommon.cpp
toolkit/components/antitracking/AntiTrackingCommon.h
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -1223,8 +1223,26 @@ AntiTrackingCommon::StoreUserInteraction
   MOZ_ASSERT(cc);
 
   nsCOMPtr<nsIURI> uri;
   Unused << aPrincipal->GetURI(getter_AddRefs(uri));
   LOG_SPEC(("Asking the parent process to save the user-interaction for us: %s",
             _spec), uri);
   cc->SendStoreUserInteractionAsPermission(IPC::Principal(aPrincipal));
 }
+
+/* static */ bool
+AntiTrackingCommon::HasUserInteraction(nsIPrincipal* aPrincipal)
+{
+  nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
+  if (NS_WARN_IF(!pm)) {
+    return false;
+  }
+
+  uint32_t result = 0;
+  nsresult rv =
+    pm->TestPermissionFromPrincipal(aPrincipal, USER_INTERACTION_PERM, &result);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return false;
+  }
+
+  return result == nsIPermissionManager::ALLOW_ACTION;
+}
--- a/toolkit/components/antitracking/AntiTrackingCommon.h
+++ b/toolkit/components/antitracking/AntiTrackingCommon.h
@@ -106,16 +106,19 @@ public:
   static MOZ_MUST_USE RefPtr<StorageAccessGrantPromise>
   AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin,
                                        nsPIDOMWindowInner* aParentWindow,
                                        StorageAccessGrantedReason aReason);
 
   static void
   StoreUserInteractionFor(nsIPrincipal* aPrincipal);
 
+  static bool
+  HasUserInteraction(nsIPrincipal* aPrincipal);
+
   // For IPC only.
   static void
   SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(nsIPrincipal* aPrincipal,
                                                              const nsCString& aParentOrigin,
                                                              const nsCString& aGrantedOrigin,
                                                              FirstPartyStorageAccessGrantedForOriginResolver&& aResolver);
 
   enum ContentBlockingAllowListPurpose {