2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2006-06-20 01:02:12 +04:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "base/basictypes.h"
|
2010-10-11 15:35:10 +04:00
|
|
|
|
2015-07-31 23:48:26 +03:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsNetUtil.h"
|
2006-06-20 01:02:12 +04:00
|
|
|
#include "nsSimpleNestedURI.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
|
2006-06-20 01:02:12 +04:00
|
|
|
|
|
|
|
nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) : mInnerURI(innerURI) {
|
|
|
|
NS_ASSERTION(innerURI, "Must have inner URI");
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-05-12 17:30:07 +03:00
|
|
|
nsresult nsSimpleNestedURI::SetPathQueryRef(const nsACString& aPathQueryRef) {
|
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-12 17:30:07 +03:00
|
|
|
nsCOMPtr<nsIURI> inner;
|
|
|
|
nsresult rv =
|
|
|
|
NS_MutateURI(mInnerURI).SetPathQueryRef(aPathQueryRef).Finalize(inner);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = nsSimpleURI::SetPathQueryRef(aPathQueryRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// If the regular SetPathQueryRef worked, also set it on the inner URI
|
|
|
|
mInnerURI = inner;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsSimpleNestedURI::SetQuery(const nsACString& aQuery) {
|
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-12 17:30:07 +03:00
|
|
|
nsCOMPtr<nsIURI> inner;
|
|
|
|
nsresult rv = NS_MutateURI(mInnerURI).SetQuery(aQuery).Finalize(inner);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = nsSimpleURI::SetQuery(aQuery);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// If the regular SetQuery worked, also set it on the inner URI
|
|
|
|
mInnerURI = inner;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsSimpleNestedURI::SetRef(const nsACString& aRef) {
|
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-12 17:30:07 +03:00
|
|
|
nsCOMPtr<nsIURI> inner;
|
|
|
|
nsresult rv = NS_MutateURI(mInnerURI).SetRef(aRef).Finalize(inner);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = nsSimpleURI::SetRef(aRef);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// If the regular SetRef worked, also set it on the inner URI
|
|
|
|
mInnerURI = inner;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
// nsISerializable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-03-19 22:22:32 +03:00
|
|
|
nsSimpleNestedURI::Read(nsIObjectInputStream* aStream) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead");
|
2018-03-19 22:22:32 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsSimpleNestedURI::ReadPrivate(nsIObjectInputStream* aStream) {
|
|
|
|
nsresult rv = nsSimpleURI::ReadPrivate(aStream);
|
2006-06-20 01:02:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mInnerURI = do_QueryInterface(supports, &rv);
|
2006-06-20 01:02:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) {
|
|
|
|
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
|
|
|
|
if (!serializable) {
|
|
|
|
// We can't serialize ourselves
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
nsresult rv = nsSimpleURI::Write(aStream);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI), true);
|
|
|
|
return rv;
|
2015-03-07 00:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIIPCSerializableURI
|
|
|
|
void nsSimpleNestedURI::Serialize(mozilla::ipc::URIParams& aParams) {
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
SimpleNestedURIParams params;
|
|
|
|
URIParams simpleParams;
|
|
|
|
|
|
|
|
nsSimpleURI::Serialize(simpleParams);
|
|
|
|
params.simpleParams() = simpleParams;
|
|
|
|
|
|
|
|
SerializeURI(mInnerURI, params.innerURI());
|
|
|
|
|
|
|
|
aParams = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsSimpleNestedURI::Deserialize(const mozilla::ipc::URIParams& aParams) {
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
if (aParams.type() != URIParams::TSimpleNestedURIParams) {
|
|
|
|
NS_ERROR("Received unknown parameters from the other process!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SimpleNestedURIParams& params = aParams.get_SimpleNestedURIParams();
|
|
|
|
if (!nsSimpleURI::Deserialize(params.simpleParams())) return false;
|
|
|
|
|
|
|
|
mInnerURI = DeserializeURI(params.innerURI());
|
|
|
|
return true;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
// nsINestedURI
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-05-09 19:21:24 +03:00
|
|
|
nsSimpleNestedURI::GetInnerURI(nsIURI** aURI) {
|
2006-06-20 01:02:12 +04:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-05-09 19:21:24 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = mInnerURI;
|
|
|
|
uri.forget(aURI);
|
|
|
|
return NS_OK;
|
2006-06-20 01:02:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::GetInnermostURI(nsIURI** uri) {
|
|
|
|
return NS_ImplGetInnermostURI(this, uri);
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
// nsSimpleURI overrides
|
|
|
|
/* virtual */ nsresult nsSimpleNestedURI::EqualsInternal(
|
|
|
|
nsIURI* other, nsSimpleURI::RefHandlingEnum refHandlingMode, bool* result) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2006-06-20 01:02:12 +04:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
if (other) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool correctScheme;
|
2006-06-20 01:02:12 +04:00
|
|
|
nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
if (correctScheme) {
|
|
|
|
nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
|
|
|
|
if (nest) {
|
|
|
|
nsCOMPtr<nsIURI> otherInner;
|
|
|
|
rv = nest->GetInnerURI(getter_AddRefs(otherInner));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
return (refHandlingMode == eHonorRef)
|
|
|
|
? otherInner->Equals(mInnerURI, result)
|
|
|
|
: otherInner->EqualsExceptRef(mInnerURI, result);
|
2006-06-20 01:02:12 +04:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-06-20 01:02:12 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSimpleURI* nsSimpleNestedURI::StartClone(
|
2016-07-27 01:38:46 +03:00
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode, const nsACString& newRef) {
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, nullptr);
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
nsCOMPtr<nsIURI> innerClone;
|
2018-06-14 14:05:43 +03:00
|
|
|
nsresult rv = NS_OK;
|
2016-07-27 01:38:46 +03:00
|
|
|
if (refHandlingMode == eHonorRef) {
|
2018-06-14 14:05:43 +03:00
|
|
|
innerClone = mInnerURI;
|
2016-07-27 01:38:46 +03:00
|
|
|
} else if (refHandlingMode == eReplaceRef) {
|
2018-07-23 14:28:47 +03:00
|
|
|
rv = NS_GetURIWithNewRef(mInnerURI, newRef, getter_AddRefs(innerClone));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-07-23 14:28:47 +03:00
|
|
|
rv = NS_GetURIWithoutRef(mInnerURI, getter_AddRefs(innerClone));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-06-20 01:02:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
|
2016-07-27 01:38:46 +03:00
|
|
|
SetRefOnClone(url, refHandlingMode, newRef);
|
2006-06-20 01:02:12 +04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIClassInfo overrides
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2006-06-20 01:02:12 +04:00
|
|
|
nsSimpleNestedURI::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
|
|
|
|
static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
|
|
|
|
|
|
|
|
*aClassIDNoAlloc = kSimpleNestedURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-05-19 05:02:57 +03:00
|
|
|
|
2018-03-19 22:22:32 +03:00
|
|
|
// Queries this list of interfaces. If none match, it queries mURI.
|
|
|
|
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsSimpleNestedURI::Mutator, nsIURISetters,
|
2018-03-21 01:23:31 +03:00
|
|
|
nsIURIMutator, nsISerializable,
|
|
|
|
nsINestedURIMutator)
|
2017-11-20 19:11:30 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::Mutate(nsIURIMutator** aMutator) {
|
|
|
|
RefPtr<nsSimpleNestedURI::Mutator> mutator = new nsSimpleNestedURI::Mutator();
|
|
|
|
nsresult rv = mutator->InitFromURI(this);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mutator.forget(aMutator);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|