Backed out 4 changesets (bug 1547114) for multiple failures e.g. xpcshell at test_SitePermissions.js on a CLOSED TREE
authorAndreea Pavel <apavel@mozilla.com>
Fri, 26 Apr 2019 18:35:28 +0300
changeset 533409 f13945ab88b10a0ab3fbbef21d667d30caebba8a
parent 533408 4f70b98aa8705b6906b6bd2a3de66d374addb177
child 533410 b19746e81434e5461b91286e93c0918f49c9fae6
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1547114
milestone68.0a1
backs out4167117f548f41a9755a6710fc543674c8b2cc6b
0a4180b074ea47170eab34224cd5db2979a00263
c92df939a4d67e91075c44997687e0ffdb5dcac0
fc4e5936eeae0683cb1c8db8d369100e07e1b37e
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
Backed out 4 changesets (bug 1547114) for multiple failures e.g. xpcshell at test_SitePermissions.js on a CLOSED TREE Backed out changeset 4167117f548f (bug 1547114) Backed out changeset 0a4180b074ea (bug 1547114) Backed out changeset c92df939a4d6 (bug 1547114) Backed out changeset fc4e5936eeae (bug 1547114)
dom/base/nsContentUtils.h
extensions/cookie/nsCookiePermission.cpp
extensions/cookie/nsCookiePermission.h
netwerk/cookie/nsICookiePermission.idl
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3355,21 +3355,16 @@ class nsContentUtils {
   /**
    * Returns true if the top level ancestor content document of aDocument hasn't
    * yet had the first contentful paint and there is a high priority event
    * pending in the main thread.
    */
   static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
       Document* aDocument);
 
-  /**
-   * Gets the global cookie lifetime policy.
-   */
-  static uint32_t GetCookieLifetimePolicy() { return sCookiesLifetimePolicy; }
-
  private:
   static bool InitializeEventTable();
 
   static nsresult EnsureStringBundle(PropertiesFile aFile);
 
   static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
                               nsIPrincipal* aPrincipal);
 
--- a/extensions/cookie/nsCookiePermission.cpp
+++ b/extensions/cookie/nsCookiePermission.cpp
@@ -1,50 +1,59 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et: */
 /* 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/. */
 
 #include "nsCookiePermission.h"
 
+#include "mozIThirdPartyUtil.h"
 #include "nsICookie2.h"
 #include "nsIServiceManager.h"
 #include "nsICookieManager.h"
-#include "nsICookieService.h"
 #include "nsNetUtil.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIProtocolHandler.h"
 #include "nsIURI.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIDOMWindow.h"
 #include "nsIPrincipal.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "nsILoadContext.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsNetCID.h"
 #include "prtime.h"
 #include "mozilla/StaticPtr.h"
-#include "nsContentUtils.h"
 
 /****************************************************************
  ************************ nsCookiePermission ********************
  ****************************************************************/
 
+// values for mCookiesLifetimePolicy
+// 0 == accept normally
+// 1 == ask before accepting, no more supported, treated like ACCEPT_NORMALLY
+// (Bug 606655). 2 == downgrade to session 3 == limit lifetime to N days
+static const uint32_t ACCEPT_NORMALLY = 0;
+static const uint32_t ACCEPT_SESSION = 2;
+
 static const bool kDefaultPolicy = true;
+static const char kCookiesLifetimePolicy[] = "network.cookie.lifetimePolicy";
 
 static const nsLiteralCString kPermissionType(NS_LITERAL_CSTRING("cookie"));
 
 namespace {
 mozilla::StaticRefPtr<nsCookiePermission> gSingleton;
 }
 
-NS_IMPL_ISUPPORTS(nsCookiePermission, nsICookiePermission)
+NS_IMPL_ISUPPORTS(nsCookiePermission, nsICookiePermission, nsIObserver)
 
 // static
 already_AddRefed<nsICookiePermission> nsCookiePermission::GetOrCreate() {
   if (!gSingleton) {
     gSingleton = new nsCookiePermission();
   }
   return do_AddRef(gSingleton);
 }
@@ -54,20 +63,44 @@ void nsCookiePermission::Shutdown() { gS
 
 bool nsCookiePermission::Init() {
   // Initialize nsIPermissionManager and fetch relevant prefs. This is only
   // required for some methods on nsICookiePermission, so it should be done
   // lazily.
   nsresult rv;
   mPermMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return false;
+  mThirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
+  if (NS_FAILED(rv)) return false;
+
+  // failure to access the pref service is non-fatal...
+  nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
+  if (prefBranch) {
+    prefBranch->AddObserver(kCookiesLifetimePolicy, this, false);
+    PrefChanged(prefBranch, nullptr);
+  }
 
   return true;
 }
 
+void nsCookiePermission::PrefChanged(nsIPrefBranch *aPrefBranch,
+                                     const char *aPref) {
+  int32_t val;
+
+#define PREF_CHANGED(_P) (!aPref || !strcmp(aPref, _P))
+
+  if (PREF_CHANGED(kCookiesLifetimePolicy) &&
+      NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookiesLifetimePolicy, &val))) {
+    if (val != static_cast<int32_t>(ACCEPT_SESSION)) {
+      val = ACCEPT_NORMALLY;
+    }
+    mCookiesLifetimePolicy = val;
+  }
+}
+
 NS_IMETHODIMP
 nsCookiePermission::SetAccess(nsIURI *aURI, nsCookieAccess aAccess) {
   // Lazily initialize ourselves
   if (!EnsureInitialized()) return NS_ERROR_UNEXPECTED;
 
   //
   // NOTE: nsCookieAccess values conveniently match up with
   //       the permission codes used by nsIPermissionManager.
@@ -91,16 +124,33 @@ nsCookiePermission::CanAccess(nsIPrincip
       *aResult = nsICookiePermission::ACCESS_ALLOW;
     }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
+nsCookiePermission::CanAccessURI(nsIURI *aURI, nsCookieAccess *aResult) {
+  // Lazily initialize ourselves
+  if (!EnsureInitialized()) return NS_ERROR_UNEXPECTED;
+
+  // finally, check with permission manager...
+  nsresult rv =
+      mPermMgr->TestPermission(aURI, 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
@@ -121,31 +171,41 @@ nsCookiePermission::CanSetCookie(nsIURI 
       *aResult = false;
       break;
 
     default:
       // Here we can have any legacy permission value.
 
       // now we need to figure out what type of accept policy we're dealing with
       // if we accept cookies normally, just bail and return
-      if (nsContentUtils::GetCookieLifetimePolicy() ==
-          nsICookieService::ACCEPT_NORMALLY) {
+      if (mCookiesLifetimePolicy == ACCEPT_NORMALLY) {
         *aResult = true;
         return NS_OK;
       }
 
       // declare this here since it'll be used in all of the remaining cases
       int64_t currentTime = PR_Now() / PR_USEC_PER_SEC;
       int64_t delta = *aExpiry - currentTime;
 
       // We are accepting the cookie, but,
       // if it's not a session cookie, we may have to limit its lifetime.
       if (!*aIsSession && delta > 0) {
-        if (nsContentUtils::GetCookieLifetimePolicy() ==
-            nsICookieService::ACCEPT_SESSION) {
+        if (mCookiesLifetimePolicy == ACCEPT_SESSION) {
           // limit lifetime to session
           *aIsSession = true;
         }
       }
   }
 
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsCookiePermission::Observe(nsISupports *aSubject, const char *aTopic,
+                            const char16_t *aData) {
+  nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
+  NS_ASSERTION(!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic),
+               "unexpected topic - we only deal with pref changes!");
+
+  if (prefBranch)
+    PrefChanged(prefBranch, NS_LossyConvertUTF16toASCII(aData).get());
+  return NS_OK;
+}
--- a/extensions/cookie/nsCookiePermission.h
+++ b/extensions/cookie/nsCookiePermission.h
@@ -2,30 +2,45 @@
  * 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 nsCookiePermission_h__
 #define nsCookiePermission_h__
 
 #include "nsICookiePermission.h"
 #include "nsIPermissionManager.h"
+#include "nsIObserver.h"
 #include "nsCOMPtr.h"
+#include "mozIThirdPartyUtil.h"
 
-class nsCookiePermission final : public nsICookiePermission {
+class nsIPrefBranch;
+
+class nsCookiePermission final : public nsICookiePermission,
+                                 public nsIObserver {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICOOKIEPERMISSION
+  NS_DECL_NSIOBSERVER
 
   // Singleton accessor
   static already_AddRefed<nsICookiePermission> GetOrCreate();
   static void Shutdown();
 
   bool Init();
+  void PrefChanged(nsIPrefBranch *, const char *);
 
  private:
-  ~nsCookiePermission() = default;
+  nsCookiePermission()
+      : mCookiesLifetimePolicy(0)  // ACCEPT_NORMALLY
+  {}
+  virtual ~nsCookiePermission() {}
 
-  bool EnsureInitialized() { return (mPermMgr != nullptr) || Init(); };
+  bool EnsureInitialized() {
+    return (mPermMgr != nullptr && mThirdPartyUtil != nullptr) || Init();
+  };
 
   nsCOMPtr<nsIPermissionManager> mPermMgr;
+  nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
+
+  uint8_t mCookiesLifetimePolicy;  // pref for how long cookies are stored
 };
 
 #endif
--- a/netwerk/cookie/nsICookiePermission.idl
+++ b/netwerk/cookie/nsICookiePermission.idl
@@ -9,17 +9,17 @@ interface nsIURI;
 interface nsIChannel;
 interface nsIPrincipal;
 
 typedef long nsCookieAccess;
 
 /**
  * An interface to test for cookie permissions
  */
-[uuid(11ddd4ed-8f5b-40b3-b2a0-27c20ea1c88d)]
+[scriptable, uuid(11ddd4ed-8f5b-40b3-b2a0-27c20ea1c88d)]
 interface nsICookiePermission : nsISupports
 {
   /**
    * nsCookieAccess values
    */
   const nsCookieAccess ACCESS_DEFAULT = 0;
   const nsCookieAccess ACCESS_ALLOW   = 1;
   const nsCookieAccess ACCESS_DENY    = 2;
@@ -64,16 +64,34 @@ interface nsICookiePermission : nsISuppo
    *
    * @return one of the following nsCookieAccess values:
    *         ACCESS_DEFAULT, ACCESS_ALLOW, ACCESS_DENY, or
    *         ACCESS_ALLOW_FIRST_PARTY_ONLY
    */
   nsCookieAccess canAccess(in nsIPrincipal aPrincipal);
 
   /**
+   * canAccessURI
+   *
+   * this method is called to test whether or not the given principal may
+   * access the cookie database, either to set or get cookies.
+   *
+   * Be careful when calling this function, you probably want the principal
+   * based version instead of this one unless if performance is an issue.
+   *
+   * @param aURI
+   *        the URI trying to access cookies.
+   *
+   * @return one of the following nsCookieAccess values:
+   *         ACCESS_DEFAULT, ACCESS_ALLOW, ACCESS_DENY, or
+   *         ACCESS_ALLOW_FIRST_PARTY_ONLY
+   */
+  nsCookieAccess canAccessURI(in nsIURI aURI);
+
+  /**
    * 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.