Bug 1322514 - nsIPrincipal::GetOrigin should use the parent principal when dealing with blobURL, r=ehsan

This commit is contained in:
Andrea Marchesini 2016-12-08 10:44:59 -10:00
parent 76c7159be5
commit 912e678ea6

View File

@ -161,20 +161,31 @@ nsPrincipal::GetOriginInternal(nsACString& aOrigin)
NS_ENSURE_SUCCESS(rv, rv);
aOrigin.AppendLiteral("://");
aOrigin.Append(hostPort);
return NS_OK;
}
else {
// If we reached this branch, we can only create an origin if we have a nsIStandardURL.
// So, we query to a nsIStandardURL, and fail if we aren't an instance of an nsIStandardURL
// nsIStandardURLs have the good property of escaping the '^' character in their specs,
// which means that we can be sure that the caret character (which is reserved for delimiting
// the end of the spec, and the beginning of the origin attributes) is not present in the
// origin string
nsCOMPtr<nsIStandardURL> standardURL = do_QueryInterface(origin);
NS_ENSURE_TRUE(standardURL, NS_ERROR_FAILURE);
rv = origin->GetAsciiSpec(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
// This URL can be a blobURL. In this case, we should use the 'parent'
// principal instead.
nsCOMPtr<nsIURIWithPrincipal> uriWithPrincipal = do_QueryInterface(origin);
if (uriWithPrincipal) {
nsCOMPtr<nsIPrincipal> uriPrincipal;
if (uriWithPrincipal) {
return uriPrincipal->GetOriginNoSuffix(aOrigin);
}
}
// If we reached this branch, we can only create an origin if we have a
// nsIStandardURL. So, we query to a nsIStandardURL, and fail if we aren't
// an instance of an nsIStandardURL nsIStandardURLs have the good property
// of escaping the '^' character in their specs, which means that we can be
// sure that the caret character (which is reserved for delimiting the end
// of the spec, and the beginning of the origin attributes) is not present
// in the origin string
nsCOMPtr<nsIStandardURL> standardURL = do_QueryInterface(origin);
NS_ENSURE_TRUE(standardURL, NS_ERROR_FAILURE);
rv = origin->GetAsciiSpec(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}