Bug 1547114 - Part 5: Remove nsICookiePermission::CanAccess(); r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 26 Apr 2019 15:41:07 +0000
changeset 530370 e28229a014fa7884169dfc22dfc949bef16540a1
parent 530369 daeba572395db4aa51076a85d1b908405152d50a
child 530371 246b613845d3879b528ddd789ce10a6fd67e4772
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1547114
milestone68.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 1547114 - Part 5: Remove nsICookiePermission::CanAccess(); r=baku Differential Revision: https://phabricator.services.mozilla.com/D28996
extensions/cookie/nsCookiePermission.cpp
netwerk/cookie/nsICookiePermission.idl
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/extensions/cookie/nsCookiePermission.cpp
+++ b/extensions/cookie/nsCookiePermission.cpp
@@ -73,34 +73,16 @@ nsCookiePermission::SetAccess(nsIURI *aU
   //       the permission codes used by nsIPermissionManager.
   //       this is nice because it avoids conversion code.
   //
   return mPermMgr->Add(aURI, kPermissionType, aAccess,
                        nsIPermissionManager::EXPIRE_NEVER, 0);
 }
 
 NS_IMETHODIMP
-nsCookiePermission::CanAccess(nsIPrincipal *aPrincipal,
-                              nsCookieAccess *aResult) {
-  // Lazily initialize ourselves
-  if (!EnsureInitialized()) return NS_ERROR_UNEXPECTED;
-
-  // finally, check with permission manager...
-  nsresult rv = mPermMgr->TestPermissionFromPrincipal(
-      aPrincipal, kPermissionType, (uint32_t *)aResult);
-  if (NS_SUCCEEDED(rv)) {
-    if (*aResult == nsICookiePermission::ACCESS_SESSION) {
-      *aResult = nsICookiePermission::ACCESS_ALLOW;
-    }
-  }
-
-  return rv;
-}
-
-NS_IMETHODIMP
 nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
                                  nsICookie2 *aCookie, bool *aIsSession,
                                  int64_t *aExpiry, bool *aResult) {
   NS_ASSERTION(aURI, "null uri");
 
   *aResult = kDefaultPolicy;
 
   // Lazily initialize ourselves
--- a/netwerk/cookie/nsICookiePermission.idl
+++ b/netwerk/cookie/nsICookiePermission.idl
@@ -49,31 +49,16 @@ interface nsICookiePermission : nsISuppo
    *        the URI to block
    * @param aAccess
    *        the new cookie access for the URI.
    */
   void setAccess(in nsIURI         aURI,
                  in nsCookieAccess aAccess);
 
   /**
-   * canAccess
-   *
-   * this method is called to test whether or not the given principal may
-   * access the cookie database, either to set or get cookies.
-   *
-   * @param aPrincipal
-   *        the principal trying to access cookies.
-   *
-   * @return one of the following nsCookieAccess values:
-   *         ACCESS_DEFAULT, ACCESS_ALLOW, ACCESS_DENY, or
-   *         ACCESS_ALLOW_FIRST_PARTY_ONLY
-   */
-  nsCookieAccess canAccess(in nsIPrincipal aPrincipal);
-
-  /**
    * canSetCookie
    *
    * this method is called to test whether or not the given URI/channel may
    * set a specific cookie.  this method is always preceded by a call to
    * canAccess. it may modify the isSession and expiry attributes of the
    * cookie via the aIsSession and aExpiry parameters, in order to limit
    * or extend the lifetime of the cookie. this is useful, for instance, to
    * downgrade a cookie to session-only if it fails to meet certain criteria.
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -13,17 +13,17 @@
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Logging.h"
 #include "mozilla/MruCache.h"
 #include "mozilla/Pair.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozIThirdPartyUtil.h"
 #include "nsContentUtils.h"
 #include "nsGlobalWindowInner.h"
-#include "nsCookiePermission.h"
+#include "nsICookiePermission.h"
 #include "nsICookieService.h"
 #include "nsIDocShell.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIIOService.h"
 #include "nsIParentChannel.h"
 #include "nsIPermission.h"
 #include "nsPermissionManager.h"
 #include "nsIPrincipal.h"
@@ -1523,20 +1523,23 @@ bool AntiTrackingCommon::IsFirstPartySto
 
   return true;
 }
 
 bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
     nsIPrincipal* aPrincipal) {
   MOZ_ASSERT(aPrincipal);
 
-  nsCookieAccess access = nsICookiePermission::ACCESS_DEFAULT;
+  uint32_t access = nsICookiePermission::ACCESS_DEFAULT;
   if (aPrincipal->GetIsCodebasePrincipal()) {
-    nsCOMPtr<nsICookiePermission> cps = nsCookiePermission::GetOrCreate();
-    Unused << NS_WARN_IF(NS_FAILED(cps->CanAccess(aPrincipal, &access)));
+    nsPermissionManager* permManager = nsPermissionManager::GetInstance();
+    if (permManager) {
+      Unused << NS_WARN_IF(NS_FAILED(permManager->TestPermissionFromPrincipal(
+          aPrincipal, NS_LITERAL_CSTRING("cookie"), &access)));
+    }
   }
 
   if (access != nsICookiePermission::ACCESS_DEFAULT) {
     return access != nsICookiePermission::ACCESS_DENY;
   }
 
   int32_t behavior = CookiesBehavior(aPrincipal);
   return behavior != nsICookieService::BEHAVIOR_REJECT;