Skip to content

Commit

Permalink
Bug 1324115 - Part 2: replace the callers to use C++ helper. r=smaug
Browse files Browse the repository at this point in the history
  • Loading branch information
allstarschh committed Dec 21, 2016
1 parent 4f05757 commit a2b35c8
Show file tree
Hide file tree
Showing 24 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docshell/base/LoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LoadContext::LoadContext(nsIPrincipal* aPrincipal,
, mIsNotNull(true)
#endif
{
PrincipalOriginAttributes poa = BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
PrincipalOriginAttributes poa = aPrincipal->OriginAttributesRef();
mOriginAttributes.InheritFromDocToChildDocShell(poa);
if (!aOptionalBase) {
return;
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3576,7 +3576,7 @@ nsDocShell::CanAccessItem(nsIDocShellTreeItem* aTargetItem,
nsCOMPtr<nsIPrincipal> accessingPrincipal = accessingDoc->NodePrincipal();

accessingOA.mFirstPartyDomain =
BasePrincipal::Cast(accessingPrincipal)->OriginAttributesRef().mFirstPartyDomain;
accessingPrincipal->OriginAttributesRef().mFirstPartyDomain;
}
}

Expand All @@ -3590,7 +3590,7 @@ nsDocShell::CanAccessItem(nsIDocShellTreeItem* aTargetItem,
nsCOMPtr<nsIPrincipal> targetPrincipal = targetDoc->NodePrincipal();

targetOA.mFirstPartyDomain =
BasePrincipal::Cast(targetPrincipal)->OriginAttributesRef().mFirstPartyDomain;
targetPrincipal->OriginAttributesRef().mFirstPartyDomain;
}
}
}
Expand Down Expand Up @@ -7980,7 +7980,7 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
if (aPrincipal && !nsContentUtils::IsSystemPrincipal(aPrincipal) &&
mItemType != typeChrome) {
MOZ_ASSERT(ChromeUtils::IsOriginAttributesEqualIgnoringAddonId(
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
aPrincipal->OriginAttributesRef(),
mOriginAttributes));
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/PostMessageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ PostMessageEvent::Run()
NS_ENSURE_SUCCESS(rv, rv);

MOZ_DIAGNOSTIC_ASSERT(providedOrigin != targetOrigin ||
(BasePrincipal::Cast(mProvidedPrincipal)->OriginAttributesRef() ==
BasePrincipal::Cast(targetPrin)->OriginAttributesRef()),
(mProvidedPrincipal->OriginAttributesRef() ==
targetPrin->OriginAttributesRef()),
"Unexpected postMessage call to a window with mismatched "
"origin attributes");

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ nsFrameLoader::MaybeCreateDocShell()
if (parentType == nsIDocShellTreeItem::typeContent &&
!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()) &&
!OwnerIsMozBrowserFrame()) {
PrincipalOriginAttributes poa = BasePrincipal::Cast(doc->NodePrincipal())->OriginAttributesRef();
PrincipalOriginAttributes poa = doc->NodePrincipal()->OriginAttributesRef();

// Assert on the firstPartyDomain from top-level docshell should be empty
if (mIsTopLevelContent) {
Expand Down
6 changes: 2 additions & 4 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,8 +2464,7 @@ nsGlobalWindow::ComputeIsSecureContext(nsIDocument* aDocument)
// IsOriginPotentiallyTrustworthy doesn't care about origin attributes so
// it doesn't actually matter what we use here, but reusing the document
// principal's attributes is convenient.
const PrincipalOriginAttributes& attrs =
BasePrincipal::Cast(principal)->OriginAttributesRef();
const PrincipalOriginAttributes& attrs = principal->OriginAttributesRef();
// CreateCodebasePrincipal correctly gets a useful principal for blob: and
// other URI_INHERITS_SECURITY_CONTEXT URIs.
principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
Expand Down Expand Up @@ -8465,8 +8464,7 @@ nsGlobalWindow::PostMessageMozOuter(JSContext* aCx, JS::Handle<JS::Value> aMessa
return;
}

PrincipalOriginAttributes attrs =
BasePrincipal::Cast(&aSubjectPrincipal)->OriginAttributesRef();
PrincipalOriginAttributes attrs = aSubjectPrincipal.OriginAttributesRef();
if (aSubjectPrincipal.GetIsSystemPrincipal()) {
auto principal = BasePrincipal::Cast(GetPrincipal());

Expand Down
2 changes: 1 addition & 1 deletion dom/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ Console::MethodInternal(JSContext* aCx, MethodName aMethodName,
return;
}

oa = BasePrincipal::Cast(principal)->OriginAttributesRef();
oa = principal->OriginAttributesRef();

#ifdef DEBUG
if (!nsContentUtils::IsSystemPrincipal(principal)) {
Expand Down
2 changes: 1 addition & 1 deletion dom/quota/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4671,7 +4671,7 @@ QuotaManager::GetInfoFromPrincipal(nsIPrincipal* aPrincipal,
}

nsCString suffix;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(suffix);
aPrincipal->OriginAttributesRef().CreateSuffix(suffix);

if (aSuffix)
{
Expand Down
2 changes: 1 addition & 1 deletion dom/quota/QuotaManagerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ QuotaManagerService::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
MOZ_ASSERT(nsContentUtils::IsCallerChrome());

nsCString suffix;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(suffix);
aPrincipal->OriginAttributesRef().CreateSuffix(suffix);

if (NS_WARN_IF(aClearAll && !suffix.IsEmpty())) {
// The originAttributes should be default originAttributes when the
Expand Down
2 changes: 1 addition & 1 deletion dom/storage/DOMStorageCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ DOMStorageCache::Init(DOMStorageManager* aManager,

mInitialized = true;
mPrincipal = aPrincipal;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(mOriginSuffix);
aPrincipal->OriginAttributesRef().CreateSuffix(mOriginSuffix);
mPersistent = aPersistent;
if (aQuotaOriginScope.IsEmpty()) {
mQuotaOriginScope = Origin();
Expand Down
6 changes: 3 additions & 3 deletions dom/storage/DOMStorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ CreateQuotaDBKey(nsIPrincipal* aPrincipal,
NS_ENSURE_SUCCESS(rv, rv);

aKey.Truncate();
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(aKey);
aPrincipal->OriginAttributesRef().CreateSuffix(aKey);

nsAutoCString subdomainsDBKey;
CreateReversedDomain(eTLDplusOne, subdomainsDBKey);
Expand Down Expand Up @@ -315,7 +315,7 @@ DOMStorageManager::GetStorageInternal(bool aCreate,
nsresult rv;

nsAutoCString originAttrSuffix;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originAttrSuffix);
aPrincipal->OriginAttributesRef().CreateSuffix(originAttrSuffix);

nsAutoCString originKey;
rv = AppendOriginNoSuffix(aPrincipal, originKey);
Expand Down Expand Up @@ -441,7 +441,7 @@ DOMStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
}

nsAutoCString suffix;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(suffix);
aPrincipal->OriginAttributesRef().CreateSuffix(suffix);

nsAutoCString origin;
rv = AppendOriginNoSuffix(aPrincipal, origin);
Expand Down
2 changes: 1 addition & 1 deletion dom/workers/RuntimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx,
MOZ_ASSERT(aLoadInfo->mPrincipal);
nsAutoCString key;
GenerateSharedWorkerKey(scriptSpec, aName,
BasePrincipal::Cast(aLoadInfo->mPrincipal)->OriginAttributesRef(), key);
aLoadInfo->mPrincipal->OriginAttributesRef(), key);

if (mDomainMap.Get(aLoadInfo->mDomain, &domainInfo) &&
domainInfo->mSharedWorkerInfos.Get(key, &sharedWorkerInfo)) {
Expand Down
2 changes: 1 addition & 1 deletion dom/workers/ServiceWorkerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ServiceWorkerInfo::ServiceWorkerInfo(nsIPrincipal* aPrincipal,
{
MOZ_ASSERT(mPrincipal);
// cache origin attributes so we can use them off main thread
mOriginAttributes = BasePrincipal::Cast(mPrincipal)->OriginAttributesRef();
mOriginAttributes = mPrincipal->OriginAttributesRef();
MOZ_ASSERT(!mScope.IsEmpty());
MOZ_ASSERT(!mScriptSpec.IsEmpty());
MOZ_ASSERT(!mCacheName.IsEmpty());
Expand Down
5 changes: 2 additions & 3 deletions dom/workers/ServiceWorkerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,7 @@ ServiceWorkerManager::RemoveAllRegistrations(OriginAttributesPattern* aPattern)
MOZ_ASSERT(reg->mPrincipal);

bool matches =
aPattern->Matches(BasePrincipal::Cast(reg->mPrincipal)->OriginAttributesRef());
aPattern->Matches(reg->mPrincipal->OriginAttributesRef());
if (!matches) {
continue;
}
Expand Down Expand Up @@ -3892,8 +3892,7 @@ ServiceWorkerManager::UpdateTimerFired(nsIPrincipal* aPrincipal,
return;
}

PrincipalOriginAttributes attrs =
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
PrincipalOriginAttributes attrs = aPrincipal->OriginAttributesRef();

SoftUpdate(attrs, aScope);
}
Expand Down
1 change: 1 addition & 0 deletions dom/workers/ServiceWorkerScriptCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "nsIPrincipal.h"
#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h"
#include "nsNetUtil.h"
#include "nsScriptLoader.h"
Expand Down
2 changes: 1 addition & 1 deletion embedding/components/windowwatcher/nsWindowWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent,
!nsContentUtils::IsSystemOrExpandedPrincipal(subjectPrincipal) &&
docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
DocShellOriginAttributes attrs;
attrs.InheritFromDocToChildDocShell(BasePrincipal::Cast(subjectPrincipal)->OriginAttributesRef());
attrs.InheritFromDocToChildDocShell(subjectPrincipal->OriginAttributesRef());
isPrivateBrowsingWindow = !!attrs.mPrivateBrowsingId;
docShell->SetOriginAttributes(attrs);
} else {
Expand Down
4 changes: 2 additions & 2 deletions extensions/cookie/nsPermission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost, bool* aMatches)
}

// Compare their OriginAttributes
const mozilla::PrincipalOriginAttributes& theirAttrs = mozilla::BasePrincipal::Cast(principal)->OriginAttributesRef();
const mozilla::PrincipalOriginAttributes& ourAttrs = mozilla::BasePrincipal::Cast(mPrincipal)->OriginAttributesRef();
const mozilla::PrincipalOriginAttributes& theirAttrs = principal->OriginAttributesRef();
const mozilla::PrincipalOriginAttributes& ourAttrs = mPrincipal->OriginAttributesRef();

if (theirAttrs != ourAttrs) {
return NS_OK;
Expand Down
5 changes: 2 additions & 3 deletions extensions/cookie/nsPermissionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,8 +2208,7 @@ nsPermissionManager::GetPermissionHashKey(nsIPrincipal* aPrincipal,
}

// Copy the attributes over
mozilla::PrincipalOriginAttributes attrs =
mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
mozilla::PrincipalOriginAttributes attrs = aPrincipal->OriginAttributesRef();

// Disable userContext and firstParty isolation for permissions.
attrs.StripUserContextIdAndFirstPartyDomain();
Expand Down Expand Up @@ -2410,7 +2409,7 @@ nsPermissionManager::RemovePermissionsWithAttributes(mozilla::OriginAttributesPa
continue;
}

if (!aPattern.Matches(mozilla::BasePrincipal::Cast(principal)->OriginAttributesRef())) {
if (!aPattern.Matches(principal->OriginAttributesRef())) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions image/imgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ NewImageChannel(nsIChannel** aResult,
// loadingPrincipal as the channel's originAttributes. This allows the favicon
// loading from XUL will use the correct originAttributes.
NeckoOriginAttributes neckoAttrs;
neckoAttrs.InheritFromDocToNecko(BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef());
neckoAttrs.InheritFromDocToNecko(aLoadingPrincipal->OriginAttributesRef());

nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
rv = loadInfo->SetOriginAttributes(neckoAttrs);
Expand Down Expand Up @@ -783,7 +783,7 @@ NewImageChannel(nsIChannel** aResult,
// has asked us to perform.
NeckoOriginAttributes neckoAttrs;
if (aLoadingPrincipal) {
neckoAttrs.InheritFromDocToNecko(BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef());
neckoAttrs.InheritFromDocToNecko(aLoadingPrincipal->OriginAttributesRef());
}
neckoAttrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;

Expand Down Expand Up @@ -1352,7 +1352,7 @@ imgLoader::FindEntryProperties(nsIURI* uri,
if (doc) {
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
if (principal) {
attrs = BasePrincipal::Cast(principal)->OriginAttributesRef();
attrs = principal->OriginAttributesRef();
}
}

Expand Down Expand Up @@ -2114,7 +2114,7 @@ imgLoader::LoadImage(nsIURI* aURI,
// of post data.
PrincipalOriginAttributes attrs;
if (aLoadingPrincipal) {
attrs = BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
attrs = aLoadingPrincipal->OriginAttributesRef();
}
ImageCacheKey key(aURI, attrs, aLoadingDocument, rv);
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
7 changes: 3 additions & 4 deletions ipc/glue/BackgroundUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
}

*aPrincipalInfo =
NullPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
spec);
NullPrincipalInfo(aPrincipal->OriginAttributesRef(), spec);
return NS_OK;
}

Expand Down Expand Up @@ -198,7 +197,7 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
}

*aPrincipalInfo =
ExpandedPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
ExpandedPrincipalInfo(aPrincipal->OriginAttributesRef(),
Move(whitelistInfo));
return NS_OK;
}
Expand All @@ -221,7 +220,7 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
return rv;
}

*aPrincipalInfo = ContentPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
*aPrincipalInfo = ContentPrincipalInfo(aPrincipal->OriginAttributesRef(),
spec);
return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion js/xpconnect/src/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ GetExpandedPrincipal(JSContext* cx, HandleObject arrayObj,

if (!options.originAttributes) {
const PrincipalOriginAttributes prinAttrs =
BasePrincipal::Cast(principal)->OriginAttributesRef();
principal->OriginAttributesRef();
if (attrs.isNothing()) {
attrs.emplace(prinAttrs);
} else if (prinAttrs != attrs.ref()) {
Expand Down
2 changes: 1 addition & 1 deletion js/xpconnect/src/XPCWrappedNativeScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ XPCWrappedNativeScope::EnsureContentXBLScope(JSContext* cx)
principalAsArray.AppendElement(principal);
nsCOMPtr<nsIExpandedPrincipal> ep =
new nsExpandedPrincipal(principalAsArray,
BasePrincipal::Cast(principal)->OriginAttributesRef());
principal->OriginAttributesRef());

// Create the sandbox.
RootedValue v(cx);
Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/LoadInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void
InheritOriginAttributes(nsIPrincipal* aLoadingPrincipal, NeckoOriginAttributes& aAttrs)
{
const PrincipalOriginAttributes attrs =
BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
aLoadingPrincipal->OriginAttributesRef();
aAttrs.InheritFromDocToNecko(attrs);
}

Expand Down
5 changes: 2 additions & 3 deletions netwerk/protocol/http/nsHttpAuthManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ nsHttpAuthManager::GetAuthIdentity(const nsACString & aScheme,

nsAutoCString originSuffix;
if (aPrincipal) {
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originSuffix);
aPrincipal->OriginAttributesRef().CreateSuffix(originSuffix);
}

if (!aPath.IsEmpty())
Expand Down Expand Up @@ -118,10 +118,9 @@ nsHttpAuthManager::SetAuthIdentity(const nsACString & aScheme,

nsAutoCString originSuffix;
if (aPrincipal) {
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originSuffix);
aPrincipal->OriginAttributesRef().CreateSuffix(originSuffix);
}


nsHttpAuthCache* auth_cache = aIsPrivate ? mPrivateAuthCache : mAuthCache;
return auth_cache->SetAuthEntry(PromiseFlatCString(aScheme).get(),
PromiseFlatCString(aHost).get(),
Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/nsHttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@ nsHttpHandler::SpeculativeConnectInternal(nsIURI *aURI,
// loadContext.
if (aPrincipal) {
neckoOriginAttributes.InheritFromDocToNecko(
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef());
aPrincipal->OriginAttributesRef());
} else if (loadContext) {
DocShellOriginAttributes docshellOriginAttributes;
loadContext->GetOriginAttributes(docshellOriginAttributes);
Expand Down

0 comments on commit a2b35c8

Please sign in to comment.