Skip to content

Commit

Permalink
Bug 1608862 : refactor GetURI usage in BlobURLProtocolHandler.cpp r=c…
Browse files Browse the repository at this point in the history
…kerschb

***
 Add get Prepath

Differential Revision: https://phabricator.services.mozilla.com/D59731

--HG--
extra : moz-landing-system : lando
  • Loading branch information
strseb committed Feb 12, 2020
1 parent f5bedf7 commit 0c4f11b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
10 changes: 10 additions & 0 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ BasePrincipal::GetExposablePrePath(nsACString& aPrepath) {
}
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) {
Expand Down
1 change: 1 addition & 0 deletions caps/BasePrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 GetPrepath(nsACString& aResult) override;
NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final;
NS_IMETHOD GetIsOnion(bool* aIsOnion) override;
NS_IMETHOD GetIsInIsolatedMozBrowserElement(
Expand Down
7 changes: 7 additions & 0 deletions caps/nsIPrincipal.idl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ interface nsIPrincipal : nsISerializable
[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
Expand Down
13 changes: 4 additions & 9 deletions dom/file/uri/BlobURLProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,8 @@ class BlobURLsReporter final : public nsIMemoryReporter {
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
Expand Down Expand Up @@ -354,11 +351,9 @@ class BlobURLsReporter final : public nsIMemoryReporter {

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) {
Expand Down

0 comments on commit 0c4f11b

Please sign in to comment.