Bug 1282882 - Remove LoadContextInfo and LoadContext private browsing flags; r=jdm,mayhemer

This commit is contained in:
James Andreou 2016-08-23 18:07:56 -04:00 коммит произвёл Ehsan Akhgari
Родитель d3a0737427
Коммит 4c787b8989
17 изменённых файлов: 48 добавлений и 73 удалений

Просмотреть файл

@ -169,12 +169,12 @@ function* test_cache_cleared() {
yield OpenCacheEntry("http://" + TEST_HOST + "/",
"disk",
Ci.nsICacheStorage.OPEN_NORMALLY,
LoadContextInfo.custom(false, false, {userContextId}));
LoadContextInfo.custom(false, {userContextId}));
yield OpenCacheEntry("http://" + TEST_HOST + "/",
"memory",
Ci.nsICacheStorage.OPEN_NORMALLY,
LoadContextInfo.custom(false, false, {userContextId}));
LoadContextInfo.custom(false, {userContextId}));
}

Просмотреть файл

@ -52,13 +52,11 @@ LoadContext::LoadContext(nsIPrincipal* aPrincipal,
{
PrincipalOriginAttributes poa = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
mOriginAttributes.InheritFromDocToChildDocShell(poa);
mUsePrivateBrowsing = (poa.mPrivateBrowsingId != 0);
if (!aOptionalBase) {
return;
}
MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetIsContent(&mIsContent));
MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUsePrivateBrowsing(&mUsePrivateBrowsing));
MOZ_ALWAYS_SUCCEEDS(aOptionalBase->GetUseRemoteTabs(&mUseRemoteTabs));
}
@ -127,7 +125,7 @@ LoadContext::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
*aUsePrivateBrowsing = mUsePrivateBrowsing;
*aUsePrivateBrowsing = mOriginAttributes.mPrivateBrowsingId > 0;
return NS_OK;
}
@ -209,7 +207,7 @@ LoadContext::IsTrackingProtectionOn(bool* aIsTrackingProtectionOn)
if (Preferences::GetBool("privacy.trackingprotection.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else if (mUsePrivateBrowsing &&
} else if ((mOriginAttributes.mPrivateBrowsingId > 0) &&
Preferences::GetBool("privacy.trackingprotection.pbmode.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else {

Просмотреть файл

@ -47,14 +47,12 @@ public:
: mTopFrameElement(do_GetWeakReference(aTopFrameElement))
, mNestedFrameId(0)
, mIsContent(aToCopy.mIsContent)
, mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing)
, mUseRemoteTabs(aToCopy.mUseRemoteTabs)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(aToCopy.mIsNotNull)
#endif
{
MOZ_ASSERT(aToCopy.mUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
// appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
@ -65,14 +63,12 @@ public:
: mTopFrameElement(nullptr)
, mNestedFrameId(aNestedFrameId)
, mIsContent(aToCopy.mIsContent)
, mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing)
, mUseRemoteTabs(aToCopy.mUseRemoteTabs)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(aToCopy.mIsNotNull)
#endif
{
MOZ_ASSERT(aToCopy.mUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
LoadContext(dom::Element* aTopFrameElement,
@ -83,14 +79,12 @@ public:
: mTopFrameElement(do_GetWeakReference(aTopFrameElement))
, mNestedFrameId(0)
, mIsContent(aIsContent)
, mUsePrivateBrowsing(aUsePrivateBrowsing)
, mUseRemoteTabs(aUseRemoteTabs)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
, mIsNotNull(true)
#endif
{
MOZ_ASSERT(aUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
// Constructor taking reserved origin attributes.
@ -98,7 +92,6 @@ public:
: mTopFrameElement(nullptr)
, mNestedFrameId(0)
, mIsContent(false)
, mUsePrivateBrowsing(aAttrs.mPrivateBrowsingId != 0)
, mUseRemoteTabs(false)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
@ -118,7 +111,6 @@ private:
nsWeakPtr mTopFrameElement;
uint64_t mNestedFrameId;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
DocShellOriginAttributes mOriginAttributes;
#ifdef DEBUG

Просмотреть файл

@ -38,10 +38,9 @@ SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate,
&isOverriden)) &&
isOverriden) {
mUsePrivateBrowsing = isPrivate;
mIsPrivateBitValid = true;
}
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mUsePrivateBrowsing);
mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
}
}
@ -61,8 +60,6 @@ SerializedLoadContext::Init(nsILoadContext* aLoadContext)
mIsNotNull = true;
mIsPrivateBitValid = true;
aLoadContext->GetIsContent(&mIsContent);
aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing);
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mUsePrivateBrowsing);
aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
if (!aLoadContext->GetOriginAttributes(mOriginAttributes)) {
NS_WARNING("GetOriginAttributes failed");
@ -73,7 +70,6 @@ SerializedLoadContext::Init(nsILoadContext* aLoadContext)
// none of below values really matter when mIsNotNull == false:
// we won't be GetInterfaced to nsILoadContext
mIsContent = true;
mUsePrivateBrowsing = false;
mUseRemoteTabs = false;
}
}

Просмотреть файл

@ -31,7 +31,6 @@ public:
: mIsNotNull(false)
, mIsPrivateBitValid(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mUseRemoteTabs(false)
{
Init(nullptr);
@ -52,7 +51,6 @@ public:
// mIsNotNull is false, i.e., child LoadContext was null.
bool mIsPrivateBitValid;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
mozilla::DocShellOriginAttributes mOriginAttributes;
};
@ -71,7 +69,6 @@ struct ParamTraits<SerializedLoadContext>
WriteParam(aMsg, aParam.mIsNotNull);
WriteParam(aMsg, aParam.mIsContent);
WriteParam(aMsg, aParam.mIsPrivateBitValid);
WriteParam(aMsg, aParam.mUsePrivateBrowsing);
WriteParam(aMsg, aParam.mUseRemoteTabs);
WriteParam(aMsg, suffix);
}
@ -82,7 +79,6 @@ struct ParamTraits<SerializedLoadContext>
if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
!ReadParam(aMsg, aIter, &aResult->mIsContent) ||
!ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
!ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing) ||
!ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
!ReadParam(aMsg, aIter, &suffix)) {
return false;

Просмотреть файл

@ -18,12 +18,10 @@ namespace net {
NS_IMPL_ISUPPORTS(LoadContextInfo, nsILoadContextInfo)
LoadContextInfo::LoadContextInfo(bool aIsPrivate, bool aIsAnonymous, NeckoOriginAttributes aOriginAttributes)
: mIsPrivate(aIsPrivate)
, mIsAnonymous(aIsAnonymous)
LoadContextInfo::LoadContextInfo(bool aIsAnonymous, NeckoOriginAttributes aOriginAttributes)
: mIsAnonymous(aIsAnonymous)
, mOriginAttributes(aOriginAttributes)
{
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mIsPrivate);
}
LoadContextInfo::~LoadContextInfo()
@ -32,7 +30,7 @@ LoadContextInfo::~LoadContextInfo()
NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate)
{
*aIsPrivate = mIsPrivate;
*aIsPrivate = mOriginAttributes.mPrivateBrowsingId > 0;
return NS_OK;
}
@ -62,7 +60,7 @@ NS_IMPL_ISUPPORTS(LoadContextInfoFactory, nsILoadContextInfoFactory)
NS_IMETHODIMP LoadContextInfoFactory::GetDefault(nsILoadContextInfo * *aDefault)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, false, NeckoOriginAttributes());
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, NeckoOriginAttributes());
info.forget(aDefault);
return NS_OK;
}
@ -70,20 +68,20 @@ NS_IMETHODIMP LoadContextInfoFactory::GetDefault(nsILoadContextInfo * *aDefault)
NS_IMETHODIMP LoadContextInfoFactory::GetPrivate(nsILoadContextInfo * *aPrivate)
{
NeckoOriginAttributes attrs;
attrs.SyncAttributesWithPrivateBrowsing(aPrivate);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(true, false, attrs);
attrs.SyncAttributesWithPrivateBrowsing(true);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, attrs);
info.forget(aPrivate);
return NS_OK;
}
NS_IMETHODIMP LoadContextInfoFactory::GetAnonymous(nsILoadContextInfo * *aAnonymous)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, true, NeckoOriginAttributes());
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(true, NeckoOriginAttributes());
info.forget(aAnonymous);
return NS_OK;
}
NS_IMETHODIMP LoadContextInfoFactory::Custom(bool aPrivate, bool aAnonymous,
NS_IMETHODIMP LoadContextInfoFactory::Custom(bool aAnonymous,
JS::HandleValue aOriginAttributes, JSContext *cx,
nsILoadContextInfo * *_retval)
{
@ -91,7 +89,7 @@ NS_IMETHODIMP LoadContextInfoFactory::Custom(bool aPrivate, bool aAnonymous,
bool status = attrs.Init(cx, aOriginAttributes);
NS_ENSURE_TRUE(status, NS_ERROR_FAILURE);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(aPrivate, aAnonymous, attrs);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(aAnonymous, attrs);
info.forget(_retval);
return NS_OK;
}
@ -119,7 +117,7 @@ GetLoadContextInfo(nsIChannel * aChannel)
{
nsresult rv;
bool pb = NS_UsePrivateBrowsing(aChannel);
DebugOnly<bool> pb = NS_UsePrivateBrowsing(aChannel);
bool anon = false;
nsLoadFlags loadFlags;
@ -130,28 +128,28 @@ GetLoadContextInfo(nsIChannel * aChannel)
NeckoOriginAttributes oa;
NS_GetOriginAttributes(aChannel, oa);
MOZ_ASSERT(pb == (oa.mPrivateBrowsingId > 0));
return new LoadContextInfo(pb, anon, oa);
return new LoadContextInfo(anon, oa);
}
LoadContextInfo *
GetLoadContextInfo(nsILoadContext *aLoadContext, bool aIsAnonymous)
{
if (!aLoadContext) {
return new LoadContextInfo(false, aIsAnonymous,
return new LoadContextInfo(aIsAnonymous,
NeckoOriginAttributes(nsILoadContextInfo::NO_APP_ID, false));
}
bool pb = aLoadContext->UsePrivateBrowsing();
DebugOnly<bool> pb = aLoadContext->UsePrivateBrowsing();
DocShellOriginAttributes doa;
aLoadContext->GetOriginAttributes(doa);
doa.SyncAttributesWithPrivateBrowsing(pb);
MOZ_ASSERT(pb == (doa.mPrivateBrowsingId > 0));
NeckoOriginAttributes noa;
noa.InheritFromDocShellToNecko(doa);
return new LoadContextInfo(pb, aIsAnonymous, noa);
return new LoadContextInfo(aIsAnonymous, noa);
}
LoadContextInfo*
@ -167,18 +165,15 @@ GetLoadContextInfo(nsIDOMWindow *aWindow,
LoadContextInfo *
GetLoadContextInfo(nsILoadContextInfo *aInfo)
{
return new LoadContextInfo(aInfo->IsPrivate(),
aInfo->IsAnonymous(),
return new LoadContextInfo(aInfo->IsAnonymous(),
*aInfo->OriginAttributesPtr());
}
LoadContextInfo *
GetLoadContextInfo(bool const aIsPrivate,
bool const aIsAnonymous,
GetLoadContextInfo(bool const aIsAnonymous,
NeckoOriginAttributes const &aOriginAttributes)
{
return new LoadContextInfo(aIsPrivate,
aIsAnonymous,
return new LoadContextInfo(aIsAnonymous,
aOriginAttributes);
}

Просмотреть файл

@ -19,13 +19,12 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSILOADCONTEXTINFO
LoadContextInfo(bool aIsPrivate, bool aIsAnonymous, NeckoOriginAttributes aOriginAttributes);
LoadContextInfo(bool aIsAnonymous, NeckoOriginAttributes aOriginAttributes);
private:
virtual ~LoadContextInfo();
protected:
bool mIsPrivate : 1;
bool mIsAnonymous : 1;
NeckoOriginAttributes mOriginAttributes;
};
@ -53,8 +52,7 @@ LoadContextInfo*
GetLoadContextInfo(nsILoadContextInfo *aInfo);
LoadContextInfo*
GetLoadContextInfo(bool const aIsPrivate,
bool const aIsAnonymous,
GetLoadContextInfo(bool const aIsAnonymous,
NeckoOriginAttributes const &aOriginAttributes);
} // namespace net

Просмотреть файл

@ -620,7 +620,7 @@ Predictor::Init()
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<LoadContextInfo> lci =
new LoadContextInfo(false, false, NeckoOriginAttributes());
new LoadContextInfo(false, NeckoOriginAttributes());
rv = cacheStorageService->DiskCacheStorage(lci, false,
getter_AddRefs(mCacheDiskStorage));

Просмотреть файл

@ -64,8 +64,7 @@ interface nsILoadContextInfo : nsISupports
bool Equals(nsILoadContextInfo *aOther)
{
return IsPrivate() == aOther->IsPrivate() &&
IsAnonymous() == aOther->IsAnonymous() &&
return IsAnonymous() == aOther->IsAnonymous() &&
*OriginAttributesPtr() == *aOther->OriginAttributesPtr();
}
%}
@ -84,7 +83,7 @@ interface nsILoadContextInfoFactory : nsISupports
readonly attribute nsILoadContextInfo private;
readonly attribute nsILoadContextInfo anonymous;
[implicit_jscontext]
nsILoadContextInfo custom(in boolean aPrivate, in boolean aAnonymous, in jsval aOriginAttributes);
nsILoadContextInfo custom(in boolean aAnonymous, in jsval aOriginAttributes);
nsILoadContextInfo fromLoadContext(in nsILoadContext aLoadContext, in boolean aAnonymous);
nsILoadContextInfo fromWindow(in nsIDOMWindow aWindow, in boolean aAnonymous);
};

Просмотреть файл

@ -36,7 +36,6 @@ public:
: Tokenizer(aInput)
// Initialize attributes to their default values
, originAttribs(0, false)
, isPrivate(false)
, isAnonymous(false)
// Initialize the cache key to a zero length by default
, lastTag(0)
@ -46,7 +45,6 @@ public:
private:
// Results
NeckoOriginAttributes originAttribs;
bool isPrivate;
bool isAnonymous;
nsCString idEnhance;
nsDependentCSubstring cacheKey;
@ -92,7 +90,7 @@ private:
break;
}
case 'p':
isPrivate = true;
originAttribs.SyncAttributesWithPrivateBrowsing(true);
break;
case 'b':
// Leaving to be able to read and understand oldformatted entries
@ -166,7 +164,7 @@ public:
{
RefPtr<LoadContextInfo> info;
if (ParseTags()) {
info = GetLoadContextInfo(isPrivate, isAnonymous, originAttribs);
info = GetLoadContextInfo(isAnonymous, originAttribs);
}
return info.forget();

Просмотреть файл

@ -410,11 +410,12 @@ namespace CacheStorageEvictHelper {
nsresult ClearStorage(bool const aPrivate,
bool const aAnonymous,
NeckoOriginAttributes const &aOa)
NeckoOriginAttributes &aOa)
{
nsresult rv;
RefPtr<LoadContextInfo> info = GetLoadContextInfo(aPrivate, aAnonymous, aOa);
aOa.SyncAttributesWithPrivateBrowsing(aPrivate);
RefPtr<LoadContextInfo> info = GetLoadContextInfo(aAnonymous, aOa);
nsCOMPtr<nsICacheStorage> storage;
RefPtr<CacheStorageService> service = CacheStorageService::Self();
@ -435,7 +436,7 @@ nsresult ClearStorage(bool const aPrivate,
return NS_OK;
}
nsresult Run(NeckoOriginAttributes const &aOa)
nsresult Run(NeckoOriginAttributes &aOa)
{
nsresult rv;

Просмотреть файл

@ -90,7 +90,7 @@ CookieServiceParent::GetOriginAttributesFromParams(const IPC::SerializedLoadCont
}
if (aLoadContext.IsPrivateBitValid()) {
aIsPrivate = aLoadContext.mUsePrivateBrowsing;
aIsPrivate = aLoadContext.mOriginAttributes.mPrivateBrowsingId > 0;
}
aAttrs.InheritFromDocShellToNecko(docShellAttrs);

Просмотреть файл

@ -99,7 +99,7 @@ static PBOverrideStatus
PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized)
{
if (!aSerialized.IsNotNull() && aSerialized.IsPrivateBitValid()) {
return aSerialized.mUsePrivateBrowsing ?
return (aSerialized.mOriginAttributes.mPrivateBrowsingId > 0) ?
kPBOverride_Private :
kPBOverride_NotPrivate;
}
@ -184,7 +184,7 @@ NeckoParent::CreateChannelLoadContext(const PBrowserOrId& aBrowser,
// if !UsingNeckoIPCSecurity(), we may not have a LoadContext to set. This is
// the common case for most xpcshell tests.
if (aSerialized.IsNotNull()) {
attrs.SyncAttributesWithPrivateBrowsing(aSerialized.mUsePrivateBrowsing);
attrs.SyncAttributesWithPrivateBrowsing(aSerialized.mOriginAttributes.mPrivateBrowsingId > 0);
switch (aBrowser.type()) {
case PBrowserOrId::TPBrowserParent:
{
@ -825,7 +825,7 @@ NeckoParent::RecvPredPredict(const ipc::OptionalURIParams& aTargetURI,
DocShellOriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mUsePrivateBrowsing);
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mOriginAttributes.mPrivateBrowsingId > 0);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}
@ -858,7 +858,7 @@ NeckoParent::RecvPredLearn(const ipc::URIParams& aTargetURI,
DocShellOriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mUsePrivateBrowsing);
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mOriginAttributes.mPrivateBrowsingId > 0);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}

Просмотреть файл

@ -144,7 +144,7 @@ WyciwygChannelParent::SetupAppData(const IPC::SerializedLoadContext& loadContext
if (!mLoadContext && loadContext.IsPrivateBitValid()) {
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(mChannel);
if (pbChannel)
pbChannel->SetPrivate(loadContext.mUsePrivateBrowsing);
pbChannel->SetPrivate(loadContext.mOriginAttributes.mPrivateBrowsingId > 0);
}
mReceivedAppData = true;

Просмотреть файл

@ -788,8 +788,8 @@ nsWyciwygChannel::OpenCacheEntry(nsIURI *aURI,
NS_ENSURE_SUCCESS(rv, rv);
bool anonymous = mLoadFlags & LOAD_ANONYMOUS;
RefPtr<LoadContextInfo> loadInfo = mozilla::net::GetLoadContextInfo(
mPrivateBrowsing, anonymous, mOriginAttributes);
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mPrivateBrowsing);
RefPtr<LoadContextInfo> loadInfo = mozilla::net::GetLoadContextInfo(anonymous, mOriginAttributes);
nsCOMPtr<nsICacheStorage> cacheStorage;
if (mLoadFlags & INHIBIT_PERSISTENT_CACHING)

Просмотреть файл

@ -43,7 +43,7 @@ CacheCallback.prototype = {
};
function checkCacheEntry(url, exists, appId) {
var loadContext = appId ? LoadContextInfo.custom(false, false, {appId: appId}) : LoadContextInfo.default;
var loadContext = appId ? LoadContextInfo.custom(false, {appId: appId}) : LoadContextInfo.default;
var cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
var cache = cacheService.diskCacheStorage(loadContext, false);

Просмотреть файл

@ -47,7 +47,8 @@ function store_entries(cb)
asyncOpenCacheEntry(entries[store_idx][0],
entries[store_idx][2],
Ci.nsICacheStorage.OPEN_TRUNCATE,
LoadContextInfo.custom(!entries[store_idx][3], false, {}),
LoadContextInfo.custom(false,
{privateBrowsingId : entries[store_idx][3] ? 0 : 1}),
store_data,
appCache);
}
@ -87,7 +88,8 @@ function check_entries(cb, pbExited)
asyncOpenCacheEntry(entries[check_idx][0],
entries[check_idx][2],
Ci.nsICacheStorage.OPEN_READONLY,
LoadContextInfo.custom(!entries[check_idx][3], false, {}),
LoadContextInfo.custom(false,
{privateBrowsingId : entries[check_idx][3] ? 0 : 1}),
check_data,
appCache);
}