Bug 1214495 - Move CallerSubsumes checks in nsLocation into the WebIDL entry points. r=bz

This commit is contained in:
Bobby Holley 2015-10-14 14:38:52 -07:00
parent 9929cdaefa
commit 18d3239261
2 changed files with 31 additions and 68 deletions

View File

@ -279,9 +279,6 @@ nsLocation::SetURI(nsIURI* aURI, bool aReplace)
NS_IMETHODIMP
nsLocation::GetHash(nsAString& aHash)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHash.SetLength(0);
nsCOMPtr<nsIURI> uri;
@ -362,9 +359,6 @@ nsLocation::SetHash(const nsAString& aHash)
NS_IMETHODIMP
nsLocation::GetHost(nsAString& aHost)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHost.Truncate();
nsCOMPtr<nsIURI> uri;
@ -388,9 +382,6 @@ nsLocation::GetHost(nsAString& aHost)
NS_IMETHODIMP
nsLocation::SetHost(const nsAString& aHost)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
@ -408,9 +399,6 @@ nsLocation::SetHost(const nsAString& aHost)
NS_IMETHODIMP
nsLocation::GetHostname(nsAString& aHostname)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHostname.Truncate();
nsCOMPtr<nsIURI> uri;
@ -425,9 +413,6 @@ nsLocation::GetHostname(nsAString& aHostname)
NS_IMETHODIMP
nsLocation::SetHostname(const nsAString& aHostname)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
@ -445,9 +430,6 @@ nsLocation::SetHostname(const nsAString& aHostname)
NS_IMETHODIMP
nsLocation::GetHref(nsAString& aHref)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHref.Truncate();
nsCOMPtr<nsIURI> uri;
@ -563,9 +545,6 @@ nsLocation::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
NS_IMETHODIMP
nsLocation::GetOrigin(nsAString& aOrigin)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aOrigin.Truncate();
nsCOMPtr<nsIURI> uri;
@ -584,9 +563,6 @@ nsLocation::GetOrigin(nsAString& aOrigin)
NS_IMETHODIMP
nsLocation::GetPathname(nsAString& aPathname)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aPathname.Truncate();
nsCOMPtr<nsIURI> uri;
@ -611,9 +587,6 @@ nsLocation::GetPathname(nsAString& aPathname)
NS_IMETHODIMP
nsLocation::SetPathname(const nsAString& aPathname)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
@ -631,9 +604,6 @@ nsLocation::SetPathname(const nsAString& aPathname)
NS_IMETHODIMP
nsLocation::GetPort(nsAString& aPort)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aPort.SetLength(0);
nsCOMPtr<nsIURI> uri;
@ -661,9 +631,6 @@ nsLocation::GetPort(nsAString& aPort)
NS_IMETHODIMP
nsLocation::SetPort(const nsAString& aPort)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
@ -695,9 +662,6 @@ nsLocation::SetPort(const nsAString& aPort)
NS_IMETHODIMP
nsLocation::GetProtocol(nsAString& aProtocol)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aProtocol.SetLength(0);
nsCOMPtr<nsIURI> uri;
@ -722,9 +686,6 @@ nsLocation::GetProtocol(nsAString& aProtocol)
NS_IMETHODIMP
nsLocation::SetProtocol(const nsAString& aProtocol)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
@ -742,10 +703,7 @@ nsLocation::SetProtocol(const nsAString& aProtocol)
void
nsLocation::GetUsername(nsAString& aUsername, ErrorResult& aError)
{
if (!CallerSubsumes()) {
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aUsername.Truncate();
nsCOMPtr<nsIURI> uri;
@ -762,10 +720,7 @@ nsLocation::GetUsername(nsAString& aUsername, ErrorResult& aError)
void
nsLocation::SetUsername(const nsAString& aUsername, ErrorResult& aError)
{
if (!CallerSubsumes()) {
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
@ -790,10 +745,7 @@ nsLocation::SetUsername(const nsAString& aUsername, ErrorResult& aError)
void
nsLocation::GetPassword(nsAString& aPassword, ErrorResult& aError)
{
if (!CallerSubsumes()) {
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aPassword.Truncate();
nsCOMPtr<nsIURI> uri;
@ -810,10 +762,7 @@ nsLocation::GetPassword(nsAString& aPassword, ErrorResult& aError)
void
nsLocation::SetPassword(const nsAString& aPassword, ErrorResult& aError)
{
if (!CallerSubsumes()) {
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
@ -838,9 +787,6 @@ nsLocation::SetPassword(const nsAString& aPassword, ErrorResult& aError)
NS_IMETHODIMP
nsLocation::GetSearch(nsAString& aSearch)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aSearch.SetLength(0);
nsCOMPtr<nsIURI> uri;
@ -878,9 +824,6 @@ nsLocation::SetSearch(const nsAString& aSearch)
nsresult
nsLocation::SetSearchInternal(const nsAString& aSearch)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsCOMPtr<nsIURI> uri;
nsresult rv = GetWritableURI(getter_AddRefs(uri));
@ -900,9 +843,6 @@ nsLocation::SetSearchInternal(const nsAString& aSearch)
NS_IMETHODIMP
nsLocation::Reload(bool aForceget)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsresult rv;
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
@ -972,9 +912,6 @@ nsLocation::Replace(const nsAString& aUrl)
NS_IMETHODIMP
nsLocation::Assign(const nsAString& aUrl)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
nsAutoString oldHref;
nsresult result = NS_OK;
@ -996,7 +933,6 @@ nsLocation::Assign(const nsAString& aUrl)
NS_IMETHODIMP
nsLocation::ToString(nsAString& aReturn)
{
// NB: GetHref checks CallerSubsumes().
return GetHref(aReturn);
}

View File

@ -42,21 +42,33 @@ public:
// nsIDOMLocation
NS_DECL_NSIDOMLOCATION
#define THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME() { \
if (!CallerSubsumes()) { \
aError.Throw(NS_ERROR_DOM_SECURITY_ERR); \
return; \
} \
}
// WebIDL API:
void Assign(const nsAString& aUrl, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = Assign(aUrl);
}
void Replace(const nsAString& aUrl, ErrorResult& aError)
{
aError = Replace(aUrl);
}
void Reload(bool aForceget, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = Reload(aForceget);
}
void GetHref(nsAString& aHref, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetHref(aHref);
}
void SetHref(const nsAString& aHref, ErrorResult& aError)
@ -65,14 +77,17 @@ public:
}
void GetOrigin(nsAString& aOrigin, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetOrigin(aOrigin);
}
void GetProtocol(nsAString& aProtocol, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetProtocol(aProtocol);
}
void SetProtocol(const nsAString& aProtocol, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetProtocol(aProtocol);
}
void GetUsername(nsAString& aUsername, ErrorResult& aError);
@ -81,47 +96,58 @@ public:
void SetPassword(const nsAString& aPassword, ErrorResult& aError);
void GetHost(nsAString& aHost, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetHost(aHost);
}
void SetHost(const nsAString& aHost, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetHost(aHost);
}
void GetHostname(nsAString& aHostname, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetHostname(aHostname);
}
void SetHostname(const nsAString& aHostname, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetHostname(aHostname);
}
void GetPort(nsAString& aPort, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetPort(aPort);
}
void SetPort(const nsAString& aPort, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetPort(aPort);
}
void GetPathname(nsAString& aPathname, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetPathname(aPathname);
}
void SetPathname(const nsAString& aPathname, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetPathname(aPathname);
}
void GetSearch(nsAString& aSeach, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetSearch(aSeach);
}
void SetSearch(const nsAString& aSeach, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = SetSearch(aSeach);
}
void GetHash(nsAString& aHash, ErrorResult& aError)
{
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
aError = GetHash(aHash);
}
void SetHash(const nsAString& aHash, ErrorResult& aError)
@ -130,6 +156,7 @@ public:
}
void Stringify(nsAString& aRetval, ErrorResult& aError)
{
// GetHref checks CallerSubsumes.
GetHref(aRetval, aError);
}
nsPIDOMWindow* GetParentObject() const