Skip to content

Commit

Permalink
Bug 1448058 - Remove nsIMutable from URI implementations r=mayhemer
Browse files Browse the repository at this point in the history
* Also removes NS_TryToMakeImmutable, NS_TryToSetImmutable, URIIsImmutable
* NS_EnsureSafeToReturn, nsINetUtil.toImmutableURI

MozReview-Commit-ID: 5eFtFm2CQt7
  • Loading branch information
valenting committed May 9, 2018
1 parent 0b7c368 commit 00570be
Show file tree
Hide file tree
Showing 27 changed files with 39 additions and 347 deletions.
43 changes: 6 additions & 37 deletions caps/ContentPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@

using namespace mozilla;

static bool URIIsImmutable(nsIURI* aURI)
{
nsCOMPtr<nsIMutable> mutableObj(do_QueryInterface(aURI));
bool isMutable;
return
mutableObj &&
NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
!isMutable;
}

static inline ExtensionPolicyService&
EPS()
{
Expand All @@ -63,8 +53,6 @@ NS_IMPL_CI_INTERFACE_GETTER(ContentPrincipal,

ContentPrincipal::ContentPrincipal()
: BasePrincipal(eCodebasePrincipal)
, mCodebaseImmutable(false)
, mDomainImmutable(false)
{
}

Expand Down Expand Up @@ -96,9 +84,7 @@ ContentPrincipal::Init(nsIURI *aCodebase,
&hasFlag)) &&
!hasFlag);

mCodebase = NS_TryToMakeImmutable(aCodebase);
mCodebaseImmutable = URIIsImmutable(mCodebase);

mCodebase = aCodebase;
FinishInit(aOriginNoSuffix, aOriginAttributes);

return NS_OK;
Expand Down Expand Up @@ -278,17 +264,8 @@ ContentPrincipal::SubsumesInternal(nsIPrincipal* aOther,
NS_IMETHODIMP
ContentPrincipal::GetURI(nsIURI** aURI)
{
if (mCodebaseImmutable) {
NS_ADDREF(*aURI = mCodebase);
return NS_OK;
}

if (!mCodebase) {
*aURI = nullptr;
return NS_OK;
}

return NS_EnsureSafeToReturn(mCodebase, aURI);
NS_ADDREF(*aURI = mCodebase);
return NS_OK;
}

bool
Expand Down Expand Up @@ -344,19 +321,14 @@ ContentPrincipal::GetDomain(nsIURI** aDomain)
return NS_OK;
}

if (mDomainImmutable) {
NS_ADDREF(*aDomain = mDomain);
return NS_OK;
}

return NS_EnsureSafeToReturn(mDomain, aDomain);
NS_ADDREF(*aDomain = mDomain);
return NS_OK;
}

NS_IMETHODIMP
ContentPrincipal::SetDomain(nsIURI* aDomain)
{
mDomain = NS_TryToMakeImmutable(aDomain);
mDomainImmutable = URIIsImmutable(mDomain);
mDomain = aDomain;
SetHasExplicitDomain();

// Recompute all wrappers between compartments using this principal and other
Expand Down Expand Up @@ -516,8 +488,5 @@ ContentPrincipal::Write(nsIObjectOutputStream* aStream)
return rv;
}

// mCodebaseImmutable and mDomainImmutable will be recomputed based
// on the deserialized URIs in Read().

return NS_OK;
}
3 changes: 0 additions & 3 deletions caps/ContentPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class ContentPrincipal final : public mozilla::BasePrincipal

nsCOMPtr<nsIURI> mDomain;
nsCOMPtr<nsIURI> mCodebase;
// If mCodebaseImmutable is true, mCodebase is non-null and immutable
bool mCodebaseImmutable;
bool mDomainImmutable;

protected:
virtual ~ContentPrincipal();
Expand Down
8 changes: 6 additions & 2 deletions caps/NullPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ NullPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
NS_IMETHODIMP
NullPrincipal::GetURI(nsIURI** aURI)
{
return NS_EnsureSafeToReturn(mURI, aURI);
nsCOMPtr<nsIURI> uri = mURI;
uri.forget(aURI);
return NS_OK;
}

NS_IMETHODIMP
NullPrincipal::GetDomain(nsIURI** aDomain)
{
return NS_EnsureSafeToReturn(mURI, aDomain);
nsCOMPtr<nsIURI> uri = mURI;
uri.forget(aDomain);
return NS_OK;
}

NS_IMETHODIMP
Expand Down
2 changes: 0 additions & 2 deletions chrome/nsChromeProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ nsChromeProtocolHandler::NewURI(const nsACString &aSpec,
if (NS_FAILED(rv))
return rv;

NS_TryToSetImmutable(surl);

surl.forget(result);
return NS_OK;
}
Expand Down
9 changes: 3 additions & 6 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
return false;
}

mCurrentURI = NS_TryToMakeImmutable(aURI);
mCurrentURI = aURI;

if (!NS_IsAboutBlank(mCurrentURI)) {
mHasLoadedNonBlankURI = true;
Expand Down Expand Up @@ -5192,11 +5192,8 @@ nsDocShell::GetCurrentURI(nsIURI** aURI)
{
NS_ENSURE_ARG_POINTER(aURI);

if (mCurrentURI) {
return NS_EnsureSafeToReturn(mCurrentURI, aURI);
}

*aURI = nullptr;
nsCOMPtr<nsIURI> uri = mCurrentURI;
uri.forget(aURI);
return NS_OK;
}

Expand Down
3 changes: 0 additions & 3 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3695,9 +3695,6 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsINode* aContext,
NS_ASSERTION(loadGroup || IsFontTableURI(documentURI),
"Could not get loadgroup; onload may fire too early");

// Make the URI immutable so people won't change it under us
NS_TryToSetImmutable(aURI);

// XXXbz using "documentURI" for the initialDocumentURI is not quite
// right, but the best we can do here...
return imgLoader->LoadImage(aURI, /* uri to load */
Expand Down
8 changes: 2 additions & 6 deletions dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,7 @@ void
nsIDocument::SetDocumentURI(nsIURI* aURI)
{
nsCOMPtr<nsIURI> oldBase = GetDocBaseURI();
mDocumentURI = NS_TryToMakeImmutable(aURI);
mDocumentURI = aURI;
nsIURI* newBase = GetDocBaseURI();

bool equalBases = false;
Expand Down Expand Up @@ -3629,11 +3629,7 @@ nsIDocument::SetBaseURI(nsIURI* aURI)
}
}

if (aURI) {
mDocumentBaseURI = NS_TryToMakeImmutable(aURI);
} else {
mDocumentBaseURI = nullptr;
}
mDocumentBaseURI = aURI;
RefreshLinkHrefs();
}

Expand Down
9 changes: 2 additions & 7 deletions dom/base/nsImageLoadingContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,8 @@ nsImageLoadingContent::GetCurrentURI(ErrorResult& aError)
nsCOMPtr<nsIURI> uri;
if (mCurrentRequest) {
mCurrentRequest->GetURI(getter_AddRefs(uri));
} else if (mCurrentURI) {
nsresult rv = NS_EnsureSafeToReturn(mCurrentURI, getter_AddRefs(uri));
if (NS_FAILED(rv)) {
aError.Throw(rv);
}
} else {
uri = mCurrentURI;
}

return uri.forget();
Expand Down Expand Up @@ -872,8 +869,6 @@ nsImageLoadingContent::LoadImage(const nsAString& aNewURI,
NS_ENSURE_SUCCESS(rv, rv);
// XXXbiesi fire onerror if that failed?

NS_TryToSetImmutable(imageURI);

return LoadImage(imageURI, aForce, aNotify, aImageLoadType, false, doc,
nsIRequest::LOAD_NORMAL, aTriggeringPrincipal);
}
Expand Down
8 changes: 2 additions & 6 deletions dom/base/nsObjectLoadingContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,9 +1603,7 @@ nsObjectLoadingContent::UpdateObjectParameters()
codebaseStr,
thisElement->OwnerDoc(),
docBaseURI);
if (NS_SUCCEEDED(rv)) {
NS_TryToSetImmutable(newBaseURI);
} else {
if (NS_FAILED(rv)) {
// Malformed URI
LOG(("OBJLC [%p]: Could not parse plugin's codebase as a URI, "
"will use document baseURI instead", this));
Expand Down Expand Up @@ -1656,9 +1654,7 @@ nsObjectLoadingContent::UpdateObjectParameters()
newMime = NS_LITERAL_CSTRING("text/html");
}

if (NS_SUCCEEDED(rv)) {
NS_TryToSetImmutable(newURI);
} else {
if (NS_FAILED(rv)) {
stateInvalid = true;
}
}
Expand Down
1 change: 0 additions & 1 deletion dom/html/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv)
return;
}

NS_TryToSetImmutable(newURI);
rv = NodePrincipal()->SetDomain(newURI);
}

Expand Down
2 changes: 0 additions & 2 deletions ipc/glue/URIParams.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct SimpleURIParams
nsCString path;
nsCString ref;
nsCString query;
bool isMutable;
};

struct StandardURLSegment
Expand All @@ -43,7 +42,6 @@ struct StandardURLParams
StandardURLSegment extension;
StandardURLSegment query;
StandardURLSegment ref;
bool isMutable;
bool supportsFileURL;
};

Expand Down
10 changes: 4 additions & 6 deletions modules/libjar/nsJARURI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ nsJARURI::SetSpecWithBase(const nsACString &aSpec, nsIURI* aBaseURL)
aBaseURL, getter_AddRefs(mJARFile));
if (NS_FAILED(rv)) return rv;

NS_TryToSetImmutable(mJARFile);

// skip over any extra '/' chars
while (*delim_end == '/')
++delim_end;
Expand Down Expand Up @@ -922,8 +920,6 @@ nsJARURI::CloneWithJARFileInternal(nsIURI *jarFile,
rv = jarFile->Clone(getter_AddRefs(newJARFile));
if (NS_FAILED(rv)) return rv;

NS_TryToSetImmutable(newJARFile);

nsCOMPtr<nsIURI> newJAREntryURI;
if (refHandlingMode == eHonorRef) {
rv = mJAREntry->Clone(getter_AddRefs(newJAREntryURI));
Expand All @@ -949,9 +945,11 @@ nsJARURI::CloneWithJARFileInternal(nsIURI *jarFile,
////////////////////////////////////////////////////////////////////////////////

NS_IMETHODIMP
nsJARURI::GetInnerURI(nsIURI **uri)
nsJARURI::GetInnerURI(nsIURI **aURI)
{
return NS_EnsureSafeToReturn(mJARFile, uri);
nsCOMPtr<nsIURI> uri = mJARFile;
uri.forget(aURI);
return NS_OK;
}

NS_IMETHODIMP
Expand Down
8 changes: 0 additions & 8 deletions netwerk/base/nsINetUtil.idl
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ interface nsINetUtil : nsISupports
*/
boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);

/**
* Take aURI and produce an immutable version of it for the caller. If aURI
* is immutable this will be aURI itself; otherwise this will be a clone,
* marked immutable if possible. Passing null to this method is allowed; in
* that case it will return null.
*/
nsIURI toImmutableURI(in nsIURI aURI);

/** Escape every character with its %XX-escaped equivalent */
const unsigned long ESCAPE_ALL = 0;

Expand Down
15 changes: 0 additions & 15 deletions netwerk/base/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,21 +1600,6 @@ nsIOService::URIChainHasFlags(nsIURI *uri,
return rv;
}

NS_IMETHODIMP
nsIOService::ToImmutableURI(nsIURI* uri, nsIURI** result)
{
if (!uri) {
*result = nullptr;
return NS_OK;
}

nsresult rv = NS_EnsureSafeToReturn(uri, result);
NS_ENSURE_SUCCESS(rv, rv);

NS_TryToSetImmutable(*result);
return NS_OK;
}

NS_IMETHODIMP
nsIOService::SetManageOfflineStatus(bool aManage)
{
Expand Down
4 changes: 2 additions & 2 deletions netwerk/base/nsIStandardURL.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsIMutable.idl"
#include "nsISupports.idl"

interface nsIURI;
interface nsIURIMutator;
Expand All @@ -15,7 +15,7 @@ interface nsIURIMutator;
* some customization on how URLs are normalized.
*/
[scriptable, builtinclass, uuid(babd6cca-ebe7-4329-967c-d6b9e33caa81)]
interface nsIStandardURL : nsIMutable
interface nsIStandardURL : nsISupports
{
/**
* blah:foo/bar => blah://foo/bar
Expand Down
Loading

0 comments on commit 00570be

Please sign in to comment.