Bug 1164292 - Switch nsIPrincipal::origin to ACString. r=gabor

This commit is contained in:
Bobby Holley 2015-05-12 15:08:20 -07:00
Родитель 93d7d50247
Коммит e61971d74b
16 изменённых файлов: 35 добавлений и 55 удалений

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

@ -20,7 +20,7 @@ interface nsIContentSecurityPolicy;
[ptr] native JSPrincipals(JSPrincipals);
[ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
[scriptable, builtinclass, uuid(264fe8ca-c382-11e4-95a6-782bcbaebb28)]
[scriptable, builtinclass, uuid(7e024afa-afd4-48e7-ba11-1c7b9620b1b2)]
interface nsIPrincipal : nsISerializable
{
/**
@ -72,7 +72,7 @@ interface nsIPrincipal : nsISerializable
// XXXcaa this should probably be turned into an nsIURI.
// The system principal's origin should be some caps namespace
// with a chrome URI. All of chrome should probably be the same.
readonly attribute string origin;
readonly attribute ACString origin;
/**
* Returns whether the other principal is equal to or weaker than this

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

@ -121,19 +121,10 @@ nsNullPrincipal::SetDomain(nsIURI* aDomain)
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsNullPrincipal::GetOrigin(char** aOrigin)
NS_IMETHODIMP
nsNullPrincipal::GetOrigin(nsACString& aOrigin)
{
*aOrigin = nullptr;
nsAutoCString str;
nsresult rv = mURI->GetSpec(str);
NS_ENSURE_SUCCESS(rv, rv);
*aOrigin = ToNewCString(str);
NS_ENSURE_TRUE(*aOrigin, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
return mURI->GetSpec(aOrigin);
}
NS_IMETHODIMP

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

@ -46,7 +46,7 @@ public:
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
NS_IMETHOD GetOrigin(char** aOrigin) override;
NS_IMETHOD GetOrigin(nsACString& aOrigin) override;
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;

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

@ -105,14 +105,12 @@ nsPrincipal::GetScriptLocation(nsACString &aStr)
}
/* static */ nsresult
nsPrincipal::GetOriginForURI(nsIURI* aURI, char **aOrigin)
nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
{
if (!aURI) {
return NS_ERROR_FAILURE;
}
*aOrigin = nullptr;
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
if (!origin) {
return NS_ERROR_FAILURE;
@ -146,29 +144,21 @@ nsPrincipal::GetOriginForURI(nsIURI* aURI, char **aOrigin)
hostPort.AppendInt(port, 10);
}
nsAutoCString scheme;
rv = origin->GetScheme(scheme);
rv = origin->GetScheme(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
*aOrigin = ToNewCString(scheme + NS_LITERAL_CSTRING("://") + hostPort);
aOrigin.AppendLiteral("://");
aOrigin.Append(hostPort);
}
else {
// Some URIs (e.g., nsSimpleURI) don't support asciiHost. Just
// get the full spec.
nsAutoCString spec;
// XXX nsMozIconURI and nsJARURI don't implement this correctly, they
// both fall back to GetSpec. That needs to be fixed.
rv = origin->GetAsciiSpec(spec);
rv = origin->GetAsciiSpec(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
*aOrigin = ToNewCString(spec);
}
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsPrincipal::GetOrigin(char **aOrigin)
nsPrincipal::GetOrigin(nsACString& aOrigin)
{
return GetOriginForURI(mCodebase, aOrigin);
}
@ -752,10 +742,10 @@ nsExpandedPrincipal::SetDomain(nsIURI* aDomain)
}
NS_IMETHODIMP
nsExpandedPrincipal::GetOrigin(char** aOrigin)
nsExpandedPrincipal::GetOrigin(nsACString& aOrigin)
{
*aOrigin = ToNewCString(NS_LITERAL_CSTRING(EXPANDED_PRINCIPAL_SPEC));
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aOrigin.AssignLiteral(EXPANDED_PRINCIPAL_SPEC);
return NS_OK;
}
typedef nsresult (NS_STDCALL nsIPrincipal::*nsIPrincipalMemFn)(nsIPrincipal* aOther,

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

@ -28,7 +28,7 @@ public:
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
NS_IMETHOD GetOrigin(char** aOrigin) override;
NS_IMETHOD GetOrigin(nsACString& aOrigin) override;
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;
@ -70,7 +70,7 @@ public:
/**
* Computes the puny-encoded origin of aURI.
*/
static nsresult GetOriginForURI(nsIURI* aURI, char **aOrigin);
static nsresult GetOriginForURI(nsIURI* aURI, nsACString& aOrigin);
/**
* Called at startup to setup static data, e.g. about:config pref-observers.
@ -116,7 +116,7 @@ public:
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
NS_IMETHOD GetOrigin(char** aOrigin) override;
NS_IMETHOD GetOrigin(nsACString& aOrigin) override;
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;

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

@ -281,7 +281,7 @@ nsScriptSecurityManager::AppStatusForPrincipal(nsIPrincipal *aPrin)
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
nsAutoCString origin;
NS_ENSURE_SUCCESS(aPrin->GetOrigin(getter_Copies(origin)),
NS_ENSURE_SUCCESS(aPrin->GetOrigin(origin),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
nsString appOrigin;
NS_ENSURE_SUCCESS(app->GetOrigin(appOrigin),
@ -294,7 +294,7 @@ nsScriptSecurityManager::AppStatusForPrincipal(nsIPrincipal *aPrin)
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
nsAutoCString appOriginPunned;
NS_ENSURE_SUCCESS(nsPrincipal::GetOriginForURI(appURI, getter_Copies(appOriginPunned)),
NS_ENSURE_SUCCESS(nsPrincipal::GetOriginForURI(appURI, appOriginPunned),
nsIPrincipal::APP_STATUS_NOT_INSTALLED);
if (!appOriginPunned.Equals(origin)) {
@ -724,10 +724,10 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
auto themeOrigin = Preferences::GetCString("b2g.theme.origin");
if (themeOrigin) {
nsAutoCString targetOrigin;
nsPrincipal::GetOriginForURI(targetBaseURI, getter_Copies(targetOrigin));
nsPrincipal::GetOriginForURI(targetBaseURI, targetOrigin);
if (targetOrigin.Equals(themeOrigin)) {
nsAutoCString pOrigin;
aPrincipal->GetOrigin(getter_Copies(pOrigin));
aPrincipal->GetOrigin(pOrigin);
return nsContentUtils::IsExactSitePermAllow(aPrincipal, "themeable") ||
pOrigin.Equals(themeOrigin)
? NS_OK : NS_ERROR_DOM_BAD_URI;

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

@ -89,10 +89,10 @@ nsSystemPrincipal::GetURI(nsIURI** aURI)
}
NS_IMETHODIMP
nsSystemPrincipal::GetOrigin(char** aOrigin)
nsSystemPrincipal::GetOrigin(nsACString& aOrigin)
{
*aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC));
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aOrigin.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
return NS_OK;
}
NS_IMETHODIMP

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

@ -31,7 +31,7 @@ public:
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
NS_IMETHOD GetOrigin(char** aOrigin) override;
NS_IMETHOD GetOrigin(nsACString& aOrigin) override;
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;

2
dom/cache/ManagerId.cpp поставляемый
Просмотреть файл

@ -33,7 +33,7 @@ ManagerId::Create(nsIPrincipal* aPrincipal, ManagerId** aManagerIdOut)
// TODO: consider using QuotaManager's modified origin here (bug 1112071)
nsAutoCString origin;
nsresult rv = aPrincipal->GetOrigin(getter_Copies(origin));
nsresult rv = aPrincipal->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
uint32_t appId;

2
dom/cache/PrincipalVerifier.cpp поставляемый
Просмотреть файл

@ -150,7 +150,7 @@ PrincipalVerifier::VerifyOnMainThread()
// is a synthetic [System Principal] string.
if (!ssm->IsSystemPrincipal(principal)) {
nsAutoCString origin;
rv = principal->GetOrigin(getter_Copies(origin));
rv = principal->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
DispatchToInitiatingThread(rv);
return;

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

@ -4283,7 +4283,7 @@ ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
if (!principal) {
return true;
}
principal->GetOrigin(getter_Copies(origin));
principal->GetOrigin(origin);
nsRefPtr<nsGeolocationSettings> gs = nsGeolocationSettings::GetGeolocationSettings();
if (gs) {
gs->PutWatchOrigin(mGeolocationWatchID, origin);

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

@ -2033,8 +2033,7 @@ MediaManager::GetUserMediaDevices(nsPIDOMWindow* aWindow,
Preferences::GetBool("media.navigator.streams.fake", false);
nsCString origin;
nsPrincipal::GetOriginForURI(aWindow->GetDocumentURI(),
getter_Copies(origin));
nsPrincipal::GetOriginForURI(aWindow->GetDocumentURI(), origin);
bool inPrivateBrowsing;
{
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();

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

@ -2606,7 +2606,7 @@ QuotaManager::GetInfoFromPrincipal(nsIPrincipal* aPrincipal,
}
nsCString origin;
rv = aPrincipal->GetOrigin(getter_Copies(origin));
rv = aPrincipal->GetOrigin(origin);
NS_ENSURE_SUCCESS(rv, rv);
if (origin.EqualsLiteral(kChromeOrigin)) {

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

@ -156,7 +156,7 @@ GetHostForPrincipal(nsIPrincipal* aPrincipal, nsACString& aHost)
}
// Some entries like "file://" uses the origin.
rv = aPrincipal->GetOrigin(getter_Copies(aHost));
rv = aPrincipal->GetOrigin(aHost);
if (NS_SUCCEEDED(rv) && !aHost.IsEmpty()) {
return NS_OK;
}

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

@ -603,7 +603,7 @@ NeckoParent::AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized
bool themeWhitelist = false;
if (Preferences::GetBool("dom.mozApps.themable") && appUri) {
nsAutoCString origin;
nsPrincipal::GetOriginForURI(appUri, getter_Copies(origin));
nsPrincipal::GetOriginForURI(appUri, origin);
nsAutoCString themeOrigin;
themeOrigin = Preferences::GetCString("b2g.theme.origin");
themeWhitelist = origin.Equals(themeOrigin);

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

@ -387,7 +387,7 @@ AppProtocolHandler::NewChannel2(nsIURI* aUri,
if (Preferences::GetBool("dom.mozApps.themable")) {
nsAutoCString origin;
nsPrincipal::GetOriginForURI(aUri, getter_Copies(origin));
nsPrincipal::GetOriginForURI(aUri, origin);
nsAdoptingCString themeOrigin;
themeOrigin = Preferences::GetCString("b2g.theme.origin");
if (themeOrigin.Equals(origin)) {