2006-06-20 01:02:12 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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)
|
2010-06-13 00:40:05 +04:00
|
|
|
: mInnerURI(innerURI)
|
2006-06-20 01:02:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(innerURI, "Must have inner URI");
|
|
|
|
NS_TryToSetImmutable(innerURI);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
// nsISerializable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-03-19 22:19:26 +03:00
|
|
|
nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
|
2006-06-20 01:02:12 +04:00
|
|
|
{
|
2018-03-19 22:19:26 +03:00
|
|
|
nsresult rv = nsSimpleURI::Read(aStream);
|
2006-06-20 01:02:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!mMutable, "How did that happen?");
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
NS_TryToSetImmutable(mInnerURI);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsSimpleURI::Write(aStream);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2006-06-20 01:02:12 +04:00
|
|
|
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());
|
|
|
|
|
|
|
|
NS_TryToSetImmutable(mInnerURI);
|
|
|
|
return true;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
// nsINestedURI
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
return NS_EnsureSafeToReturn(mInnerURI, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* result)
|
2006-06-20 01:02:12 +04:00
|
|
|
{
|
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);
|
2017-07-06 15:00:35 +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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSimpleURI*
|
2016-07-27 01:38:46 +03:00
|
|
|
nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode,
|
|
|
|
const nsACString& newRef)
|
2006-06-20 01:02:12 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, nullptr);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-06-20 01:02:12 +04:00
|
|
|
nsCOMPtr<nsIURI> innerClone;
|
2016-07-27 01:38:46 +03:00
|
|
|
nsresult rv;
|
|
|
|
if (refHandlingMode == eHonorRef) {
|
|
|
|
rv = mInnerURI->Clone(getter_AddRefs(innerClone));
|
|
|
|
} else if (refHandlingMode == eReplaceRef) {
|
|
|
|
rv = mInnerURI->CloneWithNewRef(newRef, getter_AddRefs(innerClone));
|
|
|
|
} else {
|
|
|
|
rv = mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
|
|
|
|
}
|
2011-05-22 05:12:45 +04: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);
|
2011-10-17 18:59:28 +04:00
|
|
|
url->SetMutable(false);
|
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:19:26 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsSimpleNestedURI::Mutator, nsIURISetters, nsIURIMutator)
|
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;
|
|
|
|
}
|
2018-01-19 17:19:42 +03:00
|
|
|
// StartClone calls SetMutable(false) but we need the mutator clone
|
|
|
|
// to be mutable
|
|
|
|
mutator->ResetMutable();
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator.forget(aMutator);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|