зеркало из https://github.com/mozilla/gecko-dev.git
Bug 775354 - Add a static method to be able to compute the origin based on nsPrincipal algorithm. r=mrbkap
This commit is contained in:
Родитель
f293eab524
Коммит
a809017de5
|
@ -153,6 +153,11 @@ public:
|
|||
virtual void GetScriptLocation(nsACString& aStr) MOZ_OVERRIDE;
|
||||
void SetURI(nsIURI* aURI);
|
||||
|
||||
/**
|
||||
* Computes the puny-encoded origin of aURI.
|
||||
*/
|
||||
static nsresult GetOriginForURI(nsIURI* aURI, char **aOrigin);
|
||||
|
||||
nsCOMPtr<nsIURI> mDomain;
|
||||
nsCOMPtr<nsIURI> mCodebase;
|
||||
// If mCodebaseImmutable is true, mCodebase is non-null and immutable
|
||||
|
|
|
@ -656,18 +656,17 @@ nsPrincipal::GetScriptLocation(nsACString &aStr)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrincipal::GetOrigin(char **aOrigin)
|
||||
/* static */ nsresult
|
||||
nsPrincipal::GetOriginForURI(nsIURI* aURI, char **aOrigin)
|
||||
{
|
||||
if (!aURI) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aOrigin = nsnull;
|
||||
|
||||
nsCOMPtr<nsIURI> origin;
|
||||
if (mCodebase) {
|
||||
origin = NS_GetInnermostURI(mCodebase);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
|
||||
if (!origin) {
|
||||
NS_ASSERTION(mCert, "No Domain or Codebase for a non-cert principal");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -683,8 +682,9 @@ nsPrincipal::GetOrigin(char **aOrigin)
|
|||
rv = origin->GetAsciiHost(hostPort);
|
||||
// Some implementations return an empty string, treat it as no support
|
||||
// for asciiHost by that implementation.
|
||||
if (hostPort.IsEmpty())
|
||||
if (hostPort.IsEmpty()) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 port;
|
||||
|
@ -701,6 +701,7 @@ nsPrincipal::GetOrigin(char **aOrigin)
|
|||
nsCAutoString scheme;
|
||||
rv = origin->GetScheme(scheme);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aOrigin = ToNewCString(scheme + NS_LITERAL_CSTRING("://") + hostPort);
|
||||
}
|
||||
else {
|
||||
|
@ -711,12 +712,19 @@ nsPrincipal::GetOrigin(char **aOrigin)
|
|||
// both fall back to GetSpec. That needs to be fixed.
|
||||
rv = origin->GetAsciiSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aOrigin = ToNewCString(spec);
|
||||
}
|
||||
|
||||
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrincipal::GetOrigin(char **aOrigin)
|
||||
{
|
||||
return GetOriginForURI(mCodebase, aOrigin);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrincipal::Equals(nsIPrincipal *aOther, bool *aResult)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче