Bug 1812356 - Part 1. Add SubstitutingJARURIParams to serialize SubstitutingJARURI. r=nika,necko-reviewers,valentin

GeckoView supports resource://android/ URL to access package root. But when
using this URL, `nsDocShellLoadState::ValidateWithOriginalState` returns URI
mismatch because `SubstitutingJARURI` is serialized to other type.

So `SubstitutingJARURI` should be serialized to same type.

To serialize this via IPC, we return Mutator type. But this doesn't allow
to modify properties except for IPC serialization. But some Set* can return
`NS_OK` when having same value for `ContentPrincipal::GetSiteOriginNoSuffix`.

Differential Revision: https://phabricator.services.mozilla.com/D175765
This commit is contained in:
Makoto Kato 2023-04-28 05:40:41 +00:00
Родитель aa38e7e12e
Коммит e6c76d4fee
4 изменённых файлов: 178 добавлений и 5 удалений

Просмотреть файл

@ -86,6 +86,7 @@ union URIParams
HostObjectURIParams;
DefaultURIParams;
NestedAboutURIParams;
SubstitutingJARURIParams;
};
struct JSURIParams
@ -106,5 +107,11 @@ struct NestedAboutURIParams
URIParams? baseURI;
};
struct SubstitutingJARURIParams
{
URIParams source;
JARURIParams resolved;
};
} // namespace ipc
} // namespace mozilla

Просмотреть файл

@ -10,6 +10,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/dom/BlobURL.h"
#include "mozilla/net/DefaultURI.h"
#include "mozilla/net/SubstitutingJARURI.h"
#include "mozilla/net/SubstitutingURL.h"
#include "nsAboutProtocolHandler.h"
#include "nsComponentManagerUtils.h"
@ -101,6 +102,10 @@ already_AddRefed<nsIURI> DeserializeURI(const URIParams& aParams) {
mutator = new net::nsNestedAboutURI::Mutator();
break;
case URIParams::TSubstitutingJARURIParams:
mutator = new net::SubstitutingJARURI::Mutator();
break;
default:
MOZ_CRASH("Unknown params!");
}

Просмотреть файл

@ -7,6 +7,7 @@
#ifndef SubstitutingJARURI_h
#define SubstitutingJARURI_h
#include "nsIStandardURL.h"
#include "nsIURL.h"
#include "nsJARURI.h"
#include "nsISerializable.h"
@ -143,13 +144,73 @@ class SubstitutingJARURI : public nsIJARURI,
return !mSource ? NS_ERROR_NULL_POINTER
: mSource->GetDisplayPrePath(aDisplayPrePath);
}
NS_IMETHOD Mutate(nsIURIMutator** _retval) override {
return !mSource ? NS_ERROR_NULL_POINTER : mSource->Mutate(_retval);
NS_IMETHOD Mutate(nsIURIMutator** _retval) override;
NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override;
private:
nsresult Clone(nsIURI** aURI);
nsresult SetSpecInternal(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override {
MOZ_ASSERT(mSource);
mSource->Serialize(aParams);
nsresult SetScheme(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetUserPass(const nsACString& aInput);
nsresult SetUsername(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetPassword(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetHostPort(const nsACString& aValue) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetHost(const nsACString& input) { return NS_ERROR_NOT_IMPLEMENTED; }
nsresult SetPort(int32_t aPort);
nsresult SetPathQueryRef(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetRef(const nsACString& input) { return NS_ERROR_NOT_IMPLEMENTED; }
nsresult SetFilePath(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetQuery(const nsACString& input) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult SetQueryWithEncoding(const nsACString& input,
const mozilla::Encoding* encoding) {
return NS_ERROR_NOT_IMPLEMENTED;
}
bool Deserialize(const mozilla::ipc::URIParams& aParams);
nsresult ReadPrivate(nsIObjectInputStream* aStream);
public:
class Mutator final : public nsIURIMutator,
public BaseURIMutator<SubstitutingJARURI>,
public nsISerializable {
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
// nsISerializable overrides
NS_IMETHOD
Write(nsIObjectOutputStream* aOutputStream) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
return InitFromInputStream(aStream);
}
explicit Mutator() = default;
private:
virtual ~Mutator() = default;
friend SubstitutingJARURI;
};
friend BaseURIMutator<SubstitutingJARURI>;
};
NS_DEFINE_STATIC_IID_ACCESSOR(SubstitutingJARURI,

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/Unused.h"
#include "mozilla/chrome/RegistryMessageUtils.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/ipc/URIUtils.h"
#include "SubstitutingProtocolHandler.h"
#include "SubstitutingURL.h"
@ -141,6 +142,32 @@ nsresult SubstitutingJARURI::EqualsInternal(nsIURI* aOther,
: mSource->EqualsExceptRef(other->mSource, aResult);
}
NS_IMETHODIMP
SubstitutingJARURI::Mutate(nsIURIMutator** aMutator) {
RefPtr<SubstitutingJARURI::Mutator> mutator =
new SubstitutingJARURI::Mutator();
nsresult rv = mutator->InitFromURI(this);
if (NS_FAILED(rv)) {
return rv;
}
mutator.forget(aMutator);
return NS_OK;
}
void SubstitutingJARURI::Serialize(mozilla::ipc::URIParams& aParams) {
using namespace mozilla::ipc;
SubstitutingJARURIParams params;
URIParams source;
URIParams resolved;
mSource->Serialize(source);
mResolved->Serialize(resolved);
params.source() = source;
params.resolved() = resolved;
aParams = params;
}
// SubstitutingJARURI::nsISerializable
NS_IMETHODIMP
@ -181,6 +208,76 @@ SubstitutingJARURI::Write(nsIObjectOutputStream* aStream) {
return NS_OK;
}
nsresult SubstitutingJARURI::Clone(nsIURI** aURI) {
RefPtr<SubstitutingJARURI> uri = new SubstitutingJARURI();
// SubstitutingJARURI's mSource/mResolved isn't mutable.
uri->mSource = mSource;
uri->mResolved = mResolved;
uri.forget(aURI);
return NS_OK;
}
nsresult SubstitutingJARURI::SetUserPass(const nsACString& aInput) {
// If setting same value in mSource, return NS_OK;
if (!mSource) {
return NS_ERROR_NULL_POINTER;
}
nsAutoCString sourceUserPass;
nsresult rv = mSource->GetUserPass(sourceUserPass);
if (NS_FAILED(rv)) {
return rv;
}
if (aInput.Equals(sourceUserPass)) {
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult SubstitutingJARURI::SetPort(int32_t aPort) {
// If setting same value in mSource, return NS_OK;
if (!mSource) {
return NS_ERROR_NULL_POINTER;
}
int32_t sourcePort = -1;
nsresult rv = mSource->GetPort(&sourcePort);
if (NS_FAILED(rv)) {
return rv;
}
if (aPort == sourcePort) {
return NS_OK;
}
return NS_ERROR_FAILURE;
}
bool SubstitutingJARURI::Deserialize(const mozilla::ipc::URIParams& aParams) {
using namespace mozilla::ipc;
if (aParams.type() != URIParams::TSubstitutingJARURIParams) {
NS_ERROR("Received unknown parameters from the other process!");
return false;
}
const SubstitutingJARURIParams& jarUriParams =
aParams.get_SubstitutingJARURIParams();
nsCOMPtr<nsIURI> source = DeserializeURI(jarUriParams.source());
nsresult rv;
mSource = do_QueryInterface(source, &rv);
if (NS_FAILED(rv)) {
return false;
}
nsCOMPtr<nsIURI> jarUri = DeserializeURI(jarUriParams.resolved());
mResolved = do_QueryInterface(jarUri, &rv);
return NS_SUCCEEDED(rv);
}
nsresult SubstitutingJARURI::ReadPrivate(nsIObjectInputStream* aStream) {
return Read(aStream);
}
NS_IMPL_CLASSINFO(SubstitutingJARURI, nullptr, 0, NS_SUBSTITUTINGJARURI_CID)
NS_IMPL_ADDREF(SubstitutingJARURI)
@ -202,6 +299,9 @@ NS_INTERFACE_MAP_END
NS_IMPL_CI_INTERFACE_GETTER(SubstitutingJARURI, nsIURI, nsIJARURI, nsIURL,
nsIStandardURL, nsISerializable)
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(SubstitutingJARURI::Mutator, nsIURISetters,
nsIURIMutator, nsISerializable)
SubstitutingProtocolHandler::SubstitutingProtocolHandler(const char* aScheme,
bool aEnforceFileOrJar)
: mScheme(aScheme),