mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
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)
This commit is contained in:
parent
8e221b7e30
commit
81b8902215
@ -3360,11 +3360,6 @@ class nsContentUtils {
|
||||
static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
|
||||
Document* aDocument);
|
||||
|
||||
/**
|
||||
* Gets the global cookie lifetime policy.
|
||||
*/
|
||||
static uint32_t GetCookieLifetimePolicy() { return sCookiesLifetimePolicy; }
|
||||
|
||||
private:
|
||||
static bool InitializeEventTable();
|
||||
|
||||
|
@ -6,14 +6,16 @@
|
||||
|
||||
#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"
|
||||
@ -25,13 +27,20 @@
|
||||
#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"));
|
||||
|
||||
@ -39,7 +48,7 @@ namespace {
|
||||
mozilla::StaticRefPtr<nsCookiePermission> gSingleton;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCookiePermission, nsICookiePermission)
|
||||
NS_IMPL_ISUPPORTS(nsCookiePermission, nsICookiePermission, nsIObserver)
|
||||
|
||||
// static
|
||||
already_AddRefed<nsICookiePermission> nsCookiePermission::GetOrCreate() {
|
||||
@ -59,10 +68,34 @@ bool nsCookiePermission::Init() {
|
||||
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
|
||||
@ -95,6 +128,23 @@ nsCookiePermission::CanAccess(nsIPrincipal *aPrincipal,
|
||||
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,
|
||||
@ -126,8 +176,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
|
||||
|
||||
// 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;
|
||||
}
|
||||
@ -139,8 +188,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
|
||||
// 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;
|
||||
}
|
||||
@ -149,3 +197,15 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -7,25 +7,40 @@
|
||||
|
||||
#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
|
||||
|
@ -14,7 +14,7 @@ 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
|
||||
{
|
||||
/**
|
||||
@ -68,6 +68,24 @@ interface nsICookiePermission : nsISupports
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user