Bug 1608862 : refactor GetURI usage in BlobURLProtocolHandler.cpp r=ckerschb
authorSebastian Streich <sstreich@mozilla.com>
Wed, 12 Feb 2020 16:13:19 +0000
changeset 513571 f710854f4d46464196d9db682a8353c8013cf7b9
parent 513570 adb2a59a7d2a8858a17ed29506fe9bd93c068d51
child 513572 d403fec7dda7c4c9daaf21f711c83e73d57249cc
push id37118
push userrmaries@mozilla.com
push dateThu, 13 Feb 2020 03:57:45 +0000
treeherdermozilla-central@2f6870dd1b99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1608862
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 1608862 : refactor GetURI usage in BlobURLProtocolHandler.cpp r=ckerschb *** Add get Prepath Differential Revision: https://phabricator.services.mozilla.com/D59731
caps/BasePrincipal.cpp
caps/BasePrincipal.h
caps/nsIPrincipal.idl
dom/file/uri/BlobURLProtocolHandler.cpp
--- a/caps/BasePrincipal.cpp
+++ b/caps/BasePrincipal.cpp
@@ -522,16 +522,26 @@ BasePrincipal::GetExposablePrePath(nsACS
   nsCOMPtr<nsIURI> fixedURI;
   rv = fixup->CreateExposableURI(prinURI, getter_AddRefs(fixedURI));
 
   if (NS_FAILED(rv) || NS_WARN_IF(!fixedURI)) {
     return NS_OK;
   }
   return fixedURI->GetDisplayPrePath(aPrepath);
 }
+NS_IMETHODIMP
+BasePrincipal::GetPrepath(nsACString& aPath) {
+  aPath.Truncate();
+  nsCOMPtr<nsIURI> prinURI;
+  nsresult rv = GetURI(getter_AddRefs(prinURI));
+  if (NS_FAILED(rv) || !prinURI) {
+    return NS_OK;
+  }
+  return prinURI->GetPrePath(aPath);
+}
 
 NS_IMETHODIMP
 BasePrincipal::GetIsSystemPrincipal(bool* aResult) {
   *aResult = IsSystemPrincipal();
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- 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 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;
   NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
--- a/caps/nsIPrincipal.idl
+++ b/caps/nsIPrincipal.idl
@@ -220,16 +220,23 @@ interface nsIPrincipal : nsISerializable
     /**
      * Returns the "host:port" portion of the 
      * Principals URI, if any.
      */
     [noscript] readonly attribute ACString hostPort;
 
 
     /**
+        * 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.
       * Might return the empty string, e.g. for the case of
       * a SystemPrincipal or an EpxandedPrincipal.
       *
       * WARNING: DO NOT USE FOR SECURITY CHECKS.
       * just for logging purposes!
      */
     [noscript] readonly attribute ACString asciiSpec;
--- a/dom/file/uri/BlobURLProtocolHandler.cpp
+++ b/dom/file/uri/BlobURLProtocolHandler.cpp
@@ -298,21 +298,18 @@ class BlobURLsReporter final : public ns
 
     if (maxFrames == 0) {
       return;
     }
 
     nsCOMPtr<nsIStackFrame> frame = dom::GetCurrentJSStack(maxFrames);
 
     nsAutoCString origin;
-    nsCOMPtr<nsIURI> principalURI;
-    if (NS_SUCCEEDED(aInfo->mPrincipal->GetURI(getter_AddRefs(principalURI))) &&
-        principalURI) {
-      principalURI->GetPrePath(origin);
-    }
+
+    aInfo->mPrincipal->GetPrepath(origin);
 
     // If we got a frame, we better have a current JSContext.  This is cheating
     // a bit; ideally we'd have our caller pass in a JSContext, or have
     // GetCurrentJSStack() hand out the JSContext it found.
     JSContext* cx = frame ? nsContentUtils::GetCurrentJSContext() : nullptr;
 
     for (uint32_t i = 0; frame; ++i) {
       nsString fileNameUTF16;
@@ -349,21 +346,19 @@ class BlobURLsReporter final : public ns
     }
   }
 
  private:
   ~BlobURLsReporter() {}
 
   static void BuildPath(nsAutoCString& path, nsCStringHashKey::KeyType aKey,
                         DataInfo* aInfo, bool anonymize) {
-    nsCOMPtr<nsIURI> principalURI;
     nsAutoCString url, owner;
-    if (NS_SUCCEEDED(aInfo->mPrincipal->GetURI(getter_AddRefs(principalURI))) &&
-        principalURI != nullptr && NS_SUCCEEDED(principalURI->GetSpec(owner)) &&
-        !owner.IsEmpty()) {
+    aInfo->mPrincipal->GetAsciiSpec(owner);
+    if (!owner.IsEmpty()) {
       owner.ReplaceChar('/', '\\');
       path += "owner(";
       if (anonymize) {
         path += "<anonymized>";
       } else {
         path += owner;
       }
       path += ")";