Bug 1615321 - Remove GetUri call in StorageObserver r=ckerschb
authorSebastian Streich <sstreich@mozilla.com>
Mon, 24 Feb 2020 16:57:40 +0000
changeset 515286 98507d0b439e9f1ceedb33e50da868e0ea74a890
parent 515285 2ef93285bdc103fa4e4d2ce5b11833aac4e8454f
child 515287 198b3e4d5e996b59f6c37a9ba4358068227e706c
push id37155
push userccoroiu@mozilla.com
push dateTue, 25 Feb 2020 04:23:07 +0000
treeherdermozilla-central@7d59549f2fda [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1615321
milestone75.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1615321 - Remove GetUri call in StorageObserver r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D62765
caps/BasePrincipal.cpp
caps/BasePrincipal.h
caps/nsIPrincipal.idl
dom/storage/StorageObserver.cpp
--- a/caps/BasePrincipal.cpp
+++ b/caps/BasePrincipal.cpp
@@ -67,16 +67,27 @@ BasePrincipal::GetHostPort(nsACString& a
   nsresult rv = GetURI(getter_AddRefs(prinURI));
   if (NS_FAILED(rv) || !prinURI) {
     return NS_OK;
   }
   return prinURI->GetHostPort(aRes);
 }
 
 NS_IMETHODIMP
+BasePrincipal::GetHost(nsACString& aRes) {
+  aRes.Truncate();
+  nsCOMPtr<nsIURI> 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);
   mOriginNoSuffix->ToUTF8String(aOrigin);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 BasePrincipal::GetSiteOrigin(nsACString& aSiteOrigin) {
--- a/caps/BasePrincipal.h
+++ b/caps/BasePrincipal.h
@@ -124,16 +124,17 @@ class BasePrincipal : public nsJSPrincip
   NS_IMETHOD IsURIInPrefList(const char* aPref, bool* aResult) override;
   NS_IMETHOD GetAboutModuleFlags(uint32_t* flags) override;
   NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override;
   NS_IMETHOD GetOriginAttributes(JSContext* aCx,
                                  JS::MutableHandle<JS::Value> aVal) final;
   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;
   NS_IMETHOD GetIsInIsolatedMozBrowserElement(
       bool* aIsInIsolatedMozBrowserElement) final;
   NS_IMETHOD GetUserContextId(uint32_t* aUserContextId) final;
   NS_IMETHOD GetPrivateBrowsingId(uint32_t* aPrivateBrowsingId) final;
   NS_IMETHOD GetSiteOrigin(nsACString& aOrigin) override;
--- a/caps/nsIPrincipal.idl
+++ b/caps/nsIPrincipal.idl
@@ -226,16 +226,22 @@ interface nsIPrincipal : nsISerializable
         /**
      * Returns the "host:port" portion of the 
      * Principals URI, if any.
      */
     [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:
         * "scheme://username:password@hostname:portnumber/"
     */
         [noscript] readonly attribute ACString prepath;
 
     /**
       * Returns the ASCII Spec from the Principals URI.
--- a/dom/storage/StorageObserver.cpp
+++ b/dom/storage/StorageObserver.cpp
@@ -260,24 +260,18 @@ StorageObserver::Observe(nsISupports* aS
     if (!principal) {
       return NS_OK;
     }
 
     nsAutoCString originSuffix;
     BasePrincipal::Cast(principal)->OriginAttributesRef().CreateSuffix(
         originSuffix);
 
-    nsCOMPtr<nsIURI> 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;
     }
 
     nsAutoCString originScope;
     rv = CreateReversedDomain(host, originScope);
     NS_ENSURE_SUCCESS(rv, rv);