diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index cc32b9ca22788..a1372f4584bc9 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -71,6 +71,17 @@ BasePrincipal::GetHostPort(nsACString& aRes) { return prinURI->GetHostPort(aRes); } +NS_IMETHODIMP +BasePrincipal::GetHost(nsACString& aRes) { + aRes.Truncate(); + nsCOMPtr prinURI; + nsresult rv = GetURI(getter_AddRefs(prinURI)); + if (NS_FAILED(rv) || !prinURI) { + return NS_OK; + } + return prinURI->GetHost(aRes); +} + NS_IMETHODIMP BasePrincipal::GetOriginNoSuffix(nsACString& aOrigin) { MOZ_ASSERT(mInitialized); diff --git a/caps/BasePrincipal.h b/caps/BasePrincipal.h index c1fbb2f78f58f..e62174629b0fa 100644 --- a/caps/BasePrincipal.h +++ b/caps/BasePrincipal.h @@ -129,6 +129,7 @@ class BasePrincipal : public nsJSPrincipals { NS_IMETHOD GetAsciiSpec(nsACString& aSpec) override; NS_IMETHOD GetExposablePrePath(nsACString& aResult) override; NS_IMETHOD GetHostPort(nsACString& aRes) override; + NS_IMETHOD GetHost(nsACString& aRes) override; NS_IMETHOD GetPrepath(nsACString& aResult) override; NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final; NS_IMETHOD GetIsOnion(bool* aIsOnion) override; diff --git a/caps/nsIPrincipal.idl b/caps/nsIPrincipal.idl index 205b31b9ac988..51fd6c9d749dd 100644 --- a/caps/nsIPrincipal.idl +++ b/caps/nsIPrincipal.idl @@ -230,6 +230,12 @@ interface nsIPrincipal : nsISerializable [noscript] readonly attribute ACString asciiHost; + /** + * Returns the "host" portion of the + * Principals URI, if any. + */ + [noscript] readonly attribute ACString host; + /** * Returns the prepath of the principals uri * follows the format scheme: diff --git a/dom/storage/StorageObserver.cpp b/dom/storage/StorageObserver.cpp index e68b1704062d1..65fcb35d6ed35 100644 --- a/dom/storage/StorageObserver.cpp +++ b/dom/storage/StorageObserver.cpp @@ -265,14 +265,8 @@ StorageObserver::Observe(nsISupports* aSubject, const char* aTopic, BasePrincipal::Cast(principal)->OriginAttributesRef().CreateSuffix( originSuffix); - nsCOMPtr origin; - principal->GetURI(getter_AddRefs(origin)); - if (!origin) { - return NS_OK; - } - nsAutoCString host; - origin->GetHost(host); + principal->GetHost(host); if (host.IsEmpty()) { return NS_OK; }