Bug 1131406 - Fix IPC serialization for nsSimpleNestedURI. r=billm

This commit is contained in:
Blake Kaplan 2015-03-06 22:33:00 +01:00
parent fdaa97571f
commit b9a37d66b1
5 changed files with 57 additions and 0 deletions

View File

@ -77,6 +77,7 @@ union URIParams
IconURIParams;
NullPrincipalURIParams;
JSURIParams;
SimpleNestedURIParams;
};
union OptionalURIParams
@ -91,5 +92,11 @@ struct JSURIParams
OptionalURIParams baseURI;
};
struct SimpleNestedURIParams
{
SimpleURIParams simpleParams;
URIParams innerURI;
};
} // namespace ipc
} // namespace mozilla

View File

@ -17,6 +17,7 @@
#include "nsJSProtocolHandler.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsSimpleNestedURI.h"
#include "nsThreadUtils.h"
using namespace mozilla::ipc;
@ -100,6 +101,10 @@ DeserializeURI(const URIParams& aParams)
serializable = new nsNullPrincipalURI();
break;
case URIParams::TSimpleNestedURIParams:
serializable = new nsSimpleNestedURI();
break;
default:
MOZ_CRASH("Unknown params!");
}

View File

@ -146,6 +146,7 @@ EXPORTS += [
'nsMIMEInputStream.h',
'nsNetUtil.h',
'nsReadLine.h',
'nsSimpleNestedURI.h',
'nsSimpleURI.h',
'nsStreamListenerWrapper.h',
'nsTemporaryFileInputStream.h',

View File

@ -10,6 +10,8 @@
#include "nsIObjectOutputStream.h"
#include "nsNetUtil.h"
#include "mozilla/ipc/URIUtils.h"
NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
@ -58,6 +60,43 @@ nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
return rv;
}
// 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;
}
// nsINestedURI
NS_IMETHODIMP

View File

@ -20,6 +20,8 @@
#include "nsSimpleURI.h"
#include "nsINestedURI.h"
#include "nsIIPCSerializableURI.h"
class nsSimpleNestedURI : public nsSimpleURI,
public nsINestedURI
{
@ -52,6 +54,9 @@ public:
NS_IMETHOD Read(nsIObjectInputStream* aStream) MOZ_OVERRIDE;
NS_IMETHOD Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE;
// nsIIPCSerializableURI overrides
NS_DECL_NSIIPCSERIALIZABLEURI
// Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
// nsISerializable impl works right.
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) MOZ_OVERRIDE;