Skip to content

Commit

Permalink
Bug 1282882 - Remove LoadContextInfo and LoadContext private browsing…
Browse files Browse the repository at this point in the history
… flags; r=jdm,mayhemer
  • Loading branch information
jamesandreou authored and ehsan committed Aug 26, 2016
1 parent d3a0737 commit 4c787b8
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
}


Expand Down
6 changes: 2 additions & 4 deletions docshell/base/LoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -127,7 +125,7 @@ LoadContext::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)

NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);

*aUsePrivateBrowsing = mUsePrivateBrowsing;
*aUsePrivateBrowsing = mOriginAttributes.mPrivateBrowsingId > 0;
return NS_OK;
}

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions docshell/base/LoadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ class LoadContext final
: 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
Expand All @@ -65,14 +63,12 @@ class LoadContext final
: 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,
Expand All @@ -83,22 +79,19 @@ class LoadContext final
: 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.
explicit LoadContext(DocShellOriginAttributes& aAttrs)
: mTopFrameElement(nullptr)
, mNestedFrameId(0)
, mIsContent(false)
, mUsePrivateBrowsing(aAttrs.mPrivateBrowsingId != 0)
, mUseRemoteTabs(false)
, mOriginAttributes(aAttrs)
#ifdef DEBUG
Expand All @@ -118,7 +111,6 @@ class LoadContext final
nsWeakPtr mTopFrameElement;
uint64_t mNestedFrameId;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
DocShellOriginAttributes mOriginAttributes;
#ifdef DEBUG
Expand Down
6 changes: 1 addition & 5 deletions docshell/base/SerializedLoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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");
Expand All @@ -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;
}
}
Expand Down
4 changes: 0 additions & 4 deletions docshell/base/SerializedLoadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SerializedLoadContext
: mIsNotNull(false)
, mIsPrivateBitValid(false)
, mIsContent(false)
, mUsePrivateBrowsing(false)
, mUseRemoteTabs(false)
{
Init(nullptr);
Expand All @@ -52,7 +51,6 @@ class SerializedLoadContext
// mIsNotNull is false, i.e., child LoadContext was null.
bool mIsPrivateBitValid;
bool mIsContent;
bool mUsePrivateBrowsing;
bool mUseRemoteTabs;
mozilla::DocShellOriginAttributes mOriginAttributes;
};
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down
43 changes: 19 additions & 24 deletions netwerk/base/LoadContextInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -32,7 +30,7 @@ LoadContextInfo::~LoadContextInfo()

NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate)
{
*aIsPrivate = mIsPrivate;
*aIsPrivate = mOriginAttributes.mPrivateBrowsingId > 0;
return NS_OK;
}

Expand Down Expand Up @@ -62,36 +60,36 @@ 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;
}

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)
{
NeckoOriginAttributes attrs;
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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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*
Expand All @@ -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);
}

Expand Down
6 changes: 2 additions & 4 deletions netwerk/base/LoadContextInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class LoadContextInfo : public nsILoadContextInfo
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;
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/Predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 2 additions & 3 deletions netwerk/base/nsILoadContextInfo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
%}
Expand All @@ -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);
};
6 changes: 2 additions & 4 deletions netwerk/cache2/CacheFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class KeyParser : protected Tokenizer
: 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)
Expand All @@ -46,7 +45,6 @@ class KeyParser : protected Tokenizer
private:
// Results
NeckoOriginAttributes originAttribs;
bool isPrivate;
bool isAnonymous;
nsCString idEnhance;
nsDependentCSubstring cacheKey;
Expand Down Expand Up @@ -92,7 +90,7 @@ class KeyParser : protected Tokenizer
break;
}
case 'p':
isPrivate = true;
originAttribs.SyncAttributesWithPrivateBrowsing(true);
break;
case 'b':
// Leaving to be able to read and understand oldformatted entries
Expand Down Expand Up @@ -166,7 +164,7 @@ class KeyParser : protected Tokenizer
{
RefPtr<LoadContextInfo> info;
if (ParseTags()) {
info = GetLoadContextInfo(isPrivate, isAnonymous, originAttribs);
info = GetLoadContextInfo(isAnonymous, originAttribs);
}

return info.forget();
Expand Down
Loading

0 comments on commit 4c787b8

Please sign in to comment.