Bug 1269361 - Add mPrivateBrowsingId to OriginAttributes r=ehsan,jdm

This commit is contained in:
James Andreou 2016-06-02 17:02:29 -04:00 коммит произвёл Ehsan Akhgari
Родитель 25d63511b6
Коммит 1d32e86b9c
20 изменённых файлов: 153 добавлений и 14 удалений

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

@ -45,6 +45,8 @@ PrincipalOriginAttributes::InheritFromDocShellToDoc(const DocShellOriginAttribut
// Bug 1225349 - PrincipalOriginAttributes should inherit mSignedPkg
// accordingly by URI
mSignedPkg = aAttrs.mSignedPkg;
mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
}
void
@ -56,6 +58,8 @@ PrincipalOriginAttributes::InheritFromNecko(const NeckoOriginAttributes& aAttrs)
// addonId is computed from the principal URI and never propagated
mUserContextId = aAttrs.mUserContextId;
mSignedPkg = aAttrs.mSignedPkg;
mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
}
void
@ -71,6 +75,8 @@ DocShellOriginAttributes::InheritFromDocToChildDocShell(const PrincipalOriginAtt
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
// mSignedPkg accordingly by mSignedPkgInBrowser
mSignedPkg = aAttrs.mSignedPkg;
mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
}
void
@ -85,6 +91,8 @@ NeckoOriginAttributes::InheritFromDocToNecko(const PrincipalOriginAttributes& aA
// TODO:
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
// mSignedPkg accordingly by mSignedPkgInBrowser
mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
}
void
@ -99,6 +107,8 @@ NeckoOriginAttributes::InheritFromDocShellToNecko(const DocShellOriginAttributes
// TODO:
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
// mSignedPkg accordingly by mSignedPkgInBrowser
mPrivateBrowsingId = aAttrs.mPrivateBrowsingId;
}
void
@ -145,6 +155,12 @@ OriginAttributes::CreateSuffix(nsACString& aStr) const
params->Set(NS_LITERAL_STRING("signedPkg"), mSignedPkg);
}
if (mPrivateBrowsingId) {
value.Truncate();
value.AppendInt(mPrivateBrowsingId);
params->Set(NS_LITERAL_STRING("privateBrowsingId"), value);
}
aStr.Truncate();
params->Serialize(value);
@ -171,6 +187,10 @@ public:
: mOriginAttributes(aOriginAttributes)
{
MOZ_ASSERT(aOriginAttributes);
// If mPrivateBrowsingId is passed in as >0 and is not present in the suffix,
// then it will remain >0 when it should be 0 according to the suffix. Set to 0 before
// iterating to fix this.
mOriginAttributes->mPrivateBrowsingId = 0;
}
bool URLParamsIterator(const nsString& aName,
@ -217,6 +237,16 @@ public:
return true;
}
if (aName.EqualsLiteral("privateBrowsingId")) {
nsresult rv;
int64_t val = aValue.ToInteger64(&rv);
NS_ENSURE_SUCCESS(rv, false);
NS_ENSURE_TRUE(val >= 0 && val <= UINT32_MAX, false);
mOriginAttributes->mPrivateBrowsingId = static_cast<uint32_t>(val);
return true;
}
// No other attributes are supported.
return false;
}
@ -262,6 +292,12 @@ OriginAttributes::PopulateFromOrigin(const nsACString& aOrigin,
return PopulateFromSuffix(Substring(origin, pos));
}
void
OriginAttributes::SyncAttributesWithPrivateBrowsing(bool aInPrivateBrowsing)
{
mPrivateBrowsingId = aInPrivateBrowsing ? 1 : 0;
}
BasePrincipal::BasePrincipal()
{}

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

@ -33,7 +33,8 @@ public:
mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser &&
mAddonId == aOther.mAddonId &&
mUserContextId == aOther.mUserContextId &&
mSignedPkg == aOther.mSignedPkg;
mSignedPkg == aOther.mSignedPkg &&
mPrivateBrowsingId == aOther.mPrivateBrowsingId;
}
bool operator!=(const OriginAttributes& aOther) const
{
@ -51,6 +52,10 @@ public:
bool PopulateFromOrigin(const nsACString& aOrigin,
nsACString& aOriginNoSuffix);
// Helper function to match mIsPrivateBrowsing to existing private browsing
// flags. Once all other flags are removed, this can be removed too.
void SyncAttributesWithPrivateBrowsing(bool aInPrivateBrowsing);
protected:
OriginAttributes() {}
explicit OriginAttributes(const OriginAttributesDictionary& aOther)
@ -175,6 +180,10 @@ public:
return false;
}
if (mPrivateBrowsingId.WasPassed() && mPrivateBrowsingId.Value() != aAttrs.mPrivateBrowsingId) {
return false;
}
return true;
}
};

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

@ -52,7 +52,7 @@ LoadContext::LoadContext(nsIPrincipal* aPrincipal,
{
PrincipalOriginAttributes poa = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
mOriginAttributes.InheritFromDocToChildDocShell(poa);
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mUsePrivateBrowsing);
if (!aOptionalBase) {
return;
}

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

@ -54,6 +54,7 @@ public:
, mIsNotNull(aToCopy.mIsNotNull)
#endif
{
MOZ_ASSERT(aToCopy.mUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
// appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
@ -71,6 +72,7 @@ public:
, mIsNotNull(aToCopy.mIsNotNull)
#endif
{
MOZ_ASSERT(aToCopy.mUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
LoadContext(dom::Element* aTopFrameElement,
@ -88,6 +90,7 @@ public:
, mIsNotNull(true)
#endif
{
MOZ_ASSERT(aUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId != 0));
}
// Constructor taking reserved appId for the safebrowsing cookie.

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

@ -41,6 +41,7 @@ SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
mUsePrivateBrowsing = isPrivate;
mIsPrivateBitValid = true;
}
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mUsePrivateBrowsing);
}
}
@ -61,6 +62,7 @@ SerializedLoadContext::Init(nsILoadContext* aLoadContext)
mIsPrivateBitValid = true;
aLoadContext->GetIsContent(&mIsContent);
aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing);
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mUsePrivateBrowsing);
aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
if (!aLoadContext->GetOriginAttributes(mOriginAttributes)) {
NS_WARNING("GetOriginAttributes failed");

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

@ -814,6 +814,7 @@ nsDocShell::nsDocShell()
, mParentCharsetSource(0)
, mJSRunToCompletionDepth(0)
{
AssertOriginAttributesMatchPrivateBrowsing();
mHistoryID = ++gDocshellIDCounter;
if (gDocShellCount++ == 0) {
NS_ASSERTION(sURIFixup == nullptr,
@ -2182,7 +2183,7 @@ NS_IMETHODIMP
nsDocShell::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
{
NS_ENSURE_ARG_POINTER(aUsePrivateBrowsing);
AssertOriginAttributesMatchPrivateBrowsing();
*aUsePrivateBrowsing = mInPrivateBrowsing;
return NS_OK;
}
@ -2205,6 +2206,9 @@ nsDocShell::SetPrivateBrowsing(bool aUsePrivateBrowsing)
bool changed = aUsePrivateBrowsing != mInPrivateBrowsing;
if (changed) {
mInPrivateBrowsing = aUsePrivateBrowsing;
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mInPrivateBrowsing);
if (mAffectPrivateSessionLifetime) {
if (aUsePrivateBrowsing) {
IncreasePrivateDocShellCount();
@ -2274,6 +2278,7 @@ nsDocShell::SetAffectPrivateSessionLifetime(bool aAffectLifetime)
{
bool change = aAffectLifetime != mAffectPrivateSessionLifetime;
if (change && mInPrivateBrowsing) {
AssertOriginAttributesMatchPrivateBrowsing();
if (aAffectLifetime) {
IncreasePrivateDocShellCount();
} else {
@ -2966,6 +2971,7 @@ nsDocShell::GetSessionStorageForPrincipal(nsIPrincipal* aPrincipal,
nsCOMPtr<nsPIDOMWindowOuter> domWin = GetWindow();
AssertOriginAttributesMatchPrivateBrowsing();
if (aCreate) {
return manager->CreateStorage(domWin->GetCurrentInnerWindow(), aPrincipal,
aDocumentURI, mInPrivateBrowsing, aStorage);
@ -3660,6 +3666,11 @@ nsDocShell::FindItemWithName(const char16_t* aName,
}
}
void
nsDocShell::AssertOriginAttributesMatchPrivateBrowsing(){
MOZ_ASSERT((mOriginAttributes.mPrivateBrowsingId != 0) == mInPrivateBrowsing);
}
nsresult
nsDocShell::DoFindItemWithName(const char16_t* aName,
nsISupports* aRequestor,
@ -5763,6 +5774,7 @@ nsDocShell::Destroy()
if (mInPrivateBrowsing) {
mInPrivateBrowsing = false;
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mInPrivateBrowsing);
if (mAffectPrivateSessionLifetime) {
DecreasePrivateDocShellCount();
}
@ -6420,6 +6432,7 @@ nsDocShell::SetTitle(const char16_t* aTitle)
}
}
AssertOriginAttributesMatchPrivateBrowsing();
if (mCurrentURI && mLoadType != LOAD_ERROR_PAGE && mUseGlobalHistory &&
!mInPrivateBrowsing) {
nsCOMPtr<IHistory> history = services::GetHistoryService();

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

@ -1034,6 +1034,10 @@ private:
nsIDocShellTreeItem* aOriginalRequestor,
nsIDocShellTreeItem** aResult);
// Helper assertion to enforce that mInPrivateBrowsing is in sync with
// OriginAttributes.mPrivateBrowsingId
void AssertOriginAttributesMatchPrivateBrowsing();
// Notify consumers of a search being loaded through the observer service:
void MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
const nsString& aKeyword);

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

@ -179,7 +179,8 @@ ChromeUtils::IsOriginAttributesEqual(dom::GlobalObject& aGlobal,
aA.mAppId == aB.mAppId &&
aA.mInIsolatedMozBrowser == aB.mInIsolatedMozBrowser &&
aA.mSignedPkg == aB.mSignedPkg &&
aA.mUserContextId == aB.mUserContextId;
aA.mUserContextId == aB.mUserContextId &&
aA.mPrivateBrowsingId == aB.mPrivateBrowsingId;
}
} // namespace dom

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

@ -2146,6 +2146,16 @@ nsFrameLoader::MaybeCreateDocShell()
return rv;
}
bool isPrivate = false;
nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(docShell);
NS_ENSURE_STATE(parentContext);
rv = parentContext->GetUsePrivateBrowsing(&isPrivate);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
attrs.SyncAttributesWithPrivateBrowsing(isPrivate);
nsDocShell::Cast(mDocShell)->SetOriginAttributes(attrs);
if (OwnerIsMozBrowserOrAppFrame()) {
@ -3391,6 +3401,9 @@ nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
nsGkAtoms::mozpresentation,
presentationURLStr);
bool isPrivate = mOwnerContent->HasAttr(kNameSpaceID_None, nsGkAtoms::mozprivatebrowsing);
attrs.SyncAttributesWithPrivateBrowsing(isPrivate);
bool tabContextUpdated =
aTabContext->SetTabContext(OwnerIsMozBrowserFrame(),
mIsPrerendered,

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

@ -812,6 +812,8 @@ TabChild::Init()
baseWindow->InitWindow(0, mPuppetWidget, 0, 0, 0, 0);
baseWindow->Create();
// Set the tab context attributes then pass to docShell
SetPrivateBrowsingAttributes(mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW);
NotifyTabContextUpdated();
// IPC uses a WebBrowser object for which DNS prefetching is turned off

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

@ -160,6 +160,12 @@ TabContext::SetTabContext(const TabContext& aContext)
return true;
}
void
TabContext::SetPrivateBrowsingAttributes(bool aIsPrivateBrowsing)
{
mOriginAttributes.SyncAttributesWithPrivateBrowsing(aIsPrivateBrowsing);
}
bool
TabContext::UpdateTabContextAfterSwap(const TabContext& aContext)
{

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

@ -153,6 +153,11 @@ protected:
*/
bool SetTabContext(const TabContext& aContext);
/**
* Set the tab context's origin attributes to a private browsing value.
*/
void SetPrivateBrowsingAttributes(bool aIsPrivateBrowsing);
/**
* Set the TabContext for this frame. This can either be:
* - an app frame (with the given own app) inside the given owner app. Either

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

@ -2774,9 +2774,11 @@ TabParent::GetLoadContext()
if (mLoadContext) {
loadContext = mLoadContext;
} else {
bool isPrivate = mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
SetPrivateBrowsingAttributes(isPrivate);
loadContext = new LoadContext(GetOwnerElement(),
true /* aIsContent */,
mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW,
isPrivate,
mChromeFlags & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW,
OriginAttributesRef());
mLoadContext = loadContext;

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

@ -138,7 +138,11 @@ function onMessageReceived(event, aWindow) {
// Just fall through...
// Indication of successfully finished step of a test
case "perf":
slave.postMessage("step", slaveOrigin);
// postMessage should send to the slaveOrigin. However with the addition of private
// browsing flags in origin attributes this will cause postMessage to fail. The origin of this
// window has false privatebrowsing, while the recipient is in a private window.
// To fix this issue and preserve the integrity of the test a * is passed to get around origin equality.
slave.postMessage("step", "*");
break;
// Indication of all test parts finish (from any of the frames)
case "done":

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

@ -80,6 +80,7 @@ dictionary OriginAttributesDictionary {
boolean inIsolatedMozBrowser = false;
DOMString addonId = "";
DOMString signedPkg = "";
unsigned long privateBrowsingId = 0;
};
dictionary OriginAttributesPatternDictionary {
unsigned long appId;
@ -87,4 +88,5 @@ dictionary OriginAttributesPatternDictionary {
boolean inIsolatedMozBrowser;
DOMString addonId;
DOMString signedPkg;
unsigned long privateBrowsingId;
};

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

@ -103,6 +103,30 @@ LogToConsole(const nsAString& aMsg)
namespace {
nsresult
GetOriginFromPrincipal(nsIPrincipal* aPrincipal, nsACString& aOrigin)
{
nsresult rv = aPrincipal->GetOriginNoSuffix(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString suffix;
rv = aPrincipal->GetOriginSuffix(suffix);
NS_ENSURE_SUCCESS(rv, rv);
mozilla::PrincipalOriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_FAILURE;
}
// mPrivateBrowsingId must be set to false because PermissionManager is not supposed to have
// any knowledge of private browsing. Allowing it to be true changes the suffix being hashed.
attrs.mPrivateBrowsingId = 0;
attrs.CreateSuffix(suffix);
aOrigin.Append(suffix);
return NS_OK;
}
nsresult
GetPrincipalFromOrigin(const nsACString& aOrigin, nsIPrincipal** aPrincipal)
{
@ -394,7 +418,7 @@ UpgradeHostToOriginAndInsert(const nsACString& aHost, const nsAFlatCString& aTyp
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString origin;
rv = principal->GetOrigin(origin);
rv = GetOriginFromPrincipal(principal, origin);
NS_ENSURE_SUCCESS(rv, rv);
return aHelper->Insert(origin, aType, aPermission,
@ -502,7 +526,7 @@ UpgradeHostToOriginAndInsert(const nsACString& aHost, const nsAFlatCString& aTyp
if (NS_WARN_IF(NS_FAILED(rv))) continue;
nsAutoCString origin;
rv = principal->GetOrigin(origin);
rv = GetOriginFromPrincipal(principal, origin);
if (NS_WARN_IF(NS_FAILED(rv))) continue;
// Ensure that we don't insert the same origin repeatedly
@ -547,7 +571,7 @@ UpgradeHostToOriginAndInsert(const nsACString& aHost, const nsAFlatCString& aTyp
rv = GetPrincipal(uri, aAppId, aIsInIsolatedMozBrowserElement, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
rv = principal->GetOrigin(origin);
rv = GetOriginFromPrincipal(principal, origin);
NS_ENSURE_SUCCESS(rv, rv);
aHelper->Insert(origin, aType, aPermission,
@ -560,7 +584,7 @@ UpgradeHostToOriginAndInsert(const nsACString& aHost, const nsAFlatCString& aTyp
rv = GetPrincipal(uri, aAppId, aIsInIsolatedMozBrowserElement, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
rv = principal->GetOrigin(origin);
rv = GetOriginFromPrincipal(principal, origin);
NS_ENSURE_SUCCESS(rv, rv);
aHelper->Insert(origin, aType, aPermission,
@ -583,7 +607,7 @@ IsExpandedPrincipal(nsIPrincipal* aPrincipal)
nsPermissionManager::PermissionKey::PermissionKey(nsIPrincipal* aPrincipal)
{
MOZ_ALWAYS_SUCCEEDS(aPrincipal->GetOrigin(mOrigin));
MOZ_ALWAYS_SUCCEEDS(GetOriginFromPrincipal(aPrincipal, mOrigin));
}
/**
@ -1542,7 +1566,7 @@ nsPermissionManager::AddInternal(nsIPrincipal* aPrincipal,
const bool aIgnoreSessionPermissions)
{
nsAutoCString origin;
nsresult rv = aPrincipal->GetOrigin(origin);
nsresult rv = GetOriginFromPrincipal(aPrincipal, origin);
NS_ENSURE_SUCCESS(rv, rv);
if (!IsChildProcess()) {

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

@ -23,6 +23,7 @@ LoadContextInfo::LoadContextInfo(bool aIsPrivate, bool aIsAnonymous, NeckoOrigin
, mIsAnonymous(aIsAnonymous)
, mOriginAttributes(aOriginAttributes)
{
mOriginAttributes.SyncAttributesWithPrivateBrowsing(mIsPrivate);
}
LoadContextInfo::~LoadContextInfo()
@ -68,7 +69,9 @@ NS_IMETHODIMP LoadContextInfoFactory::GetDefault(nsILoadContextInfo * *aDefault)
NS_IMETHODIMP LoadContextInfoFactory::GetPrivate(nsILoadContextInfo * *aPrivate)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(true, false, NeckoOriginAttributes());
NeckoOriginAttributes attrs;
attrs.SyncAttributesWithPrivateBrowsing(aPrivate);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(true, false, attrs);
info.forget(aPrivate);
return NS_OK;
}
@ -143,6 +146,8 @@ GetLoadContextInfo(nsILoadContext *aLoadContext, bool aIsAnonymous)
DocShellOriginAttributes doa;
aLoadContext->GetOriginAttributes(doa);
doa.SyncAttributesWithPrivateBrowsing(pb);
NeckoOriginAttributes noa;
noa.InheritFromDocShellToNecko(doa);

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

@ -1274,6 +1274,7 @@ NS_GetOriginAttributes(nsIChannel *aChannel,
DocShellOriginAttributes doa;
loadContext->GetOriginAttributes(doa);
aAttributes.InheritFromDocShellToNecko(doa);
aAttributes.SyncAttributesWithPrivateBrowsing(NS_UsePrivateBrowsing(aChannel));
return true;
}

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

@ -152,6 +152,7 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
aAttrs.mInIsolatedMozBrowser = inBrowserElement;
aAttrs.mSignedPkg = aSerialized.mOriginAttributes.mSignedPkg;
aAttrs.mUserContextId = aSerialized.mOriginAttributes.mUserContextId;
aAttrs.mPrivateBrowsingId = aSerialized.mOriginAttributes.mPrivateBrowsingId;
return nullptr;
}
@ -188,6 +189,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);
switch (aBrowser.type()) {
case PBrowserOrId::TPBrowserParent:
{
@ -904,6 +906,7 @@ NeckoParent::RecvPredPredict(const ipc::OptionalURIParams& aTargetURI,
DocShellOriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mUsePrivateBrowsing);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}
@ -936,6 +939,7 @@ NeckoParent::RecvPredLearn(const ipc::URIParams& aTargetURI,
DocShellOriginAttributes attrs(NECKO_UNKNOWN_APP_ID, false);
nsCOMPtr<nsILoadContext> loadContext;
if (aLoadContext.IsNotNull()) {
attrs.SyncAttributesWithPrivateBrowsing(aLoadContext.mUsePrivateBrowsing);
loadContext = new LoadContext(aLoadContext, nestedFrameId, attrs);
}

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

@ -748,5 +748,8 @@ main(int32_t argc, char *argv[])
// Stubs to make this test happy
mozilla::dom::OriginAttributesDictionary::OriginAttributesDictionary()
: mAppId(0), mInIsolatedMozBrowser(false), mUserContextId(0)
: mAppId(0),
mInIsolatedMozBrowser(false),
mPrivateBrowsingId(0),
mUserContextId(0)
{}