2012-08-23 23:33:46 +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/. */
|
|
|
|
|
|
|
|
#include "URIUtils.h"
|
|
|
|
|
|
|
|
#include "nsIIPCSerializableURI.h"
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsJARURI.h"
|
2015-02-13 02:41:21 +03:00
|
|
|
#include "nsIIconURI.h"
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "nsHostObjectURI.h"
|
2015-02-24 23:54:40 +03:00
|
|
|
#include "nsNullPrincipalURI.h"
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "nsJSProtocolHandler.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "nsSimpleNestedURI.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using mozilla::ArrayLength;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
|
|
|
NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
|
|
|
NS_DEFINE_CID(kJARURICID, NS_JARURI_CID);
|
2015-02-13 02:41:21 +03:00
|
|
|
NS_DEFINE_CID(kIconURICID, NS_MOZICONURI_CID);
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
void
|
|
|
|
SerializeURI(nsIURI* aURI,
|
|
|
|
URIParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aURI);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIPCSerializableURI> serializable = do_QueryInterface(aURI);
|
2015-02-13 02:41:21 +03:00
|
|
|
if (!serializable) {
|
2015-02-24 23:54:40 +03:00
|
|
|
MOZ_CRASH("All IPDL URIs must be serializable!");
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
serializable->Serialize(aParams);
|
|
|
|
if (aParams.type() == URIParams::T__None) {
|
|
|
|
MOZ_CRASH("Serialize failed!");
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SerializeURI(nsIURI* aURI,
|
|
|
|
OptionalURIParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (aURI) {
|
|
|
|
URIParams params;
|
|
|
|
SerializeURI(aURI, params);
|
|
|
|
aParams = params;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aParams = mozilla::void_t();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
DeserializeURI(const URIParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
nsCOMPtr<nsIIPCSerializableURI> serializable;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
switch (aParams.type()) {
|
|
|
|
case URIParams::TSimpleURIParams:
|
|
|
|
serializable = do_CreateInstance(kSimpleURICID);
|
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TStandardURLParams:
|
|
|
|
serializable = do_CreateInstance(kStandardURLCID);
|
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TJARURIParams:
|
|
|
|
serializable = do_CreateInstance(kJARURICID);
|
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::TJSURIParams:
|
|
|
|
serializable = new nsJSURI();
|
|
|
|
break;
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TIconURIParams:
|
|
|
|
serializable = do_CreateInstance(kIconURICID);
|
|
|
|
break;
|
|
|
|
|
2015-02-24 23:54:40 +03:00
|
|
|
case URIParams::TNullPrincipalURIParams:
|
|
|
|
serializable = new nsNullPrincipalURI();
|
|
|
|
break;
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::TSimpleNestedURIParams:
|
|
|
|
serializable = new nsSimpleNestedURI();
|
|
|
|
break;
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::THostObjectURIParams:
|
|
|
|
serializable = new nsHostObjectURI();
|
|
|
|
break;
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown params!");
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
MOZ_ASSERT(serializable);
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
if (!serializable->Deserialize(aParams)) {
|
|
|
|
MOZ_ASSERT(false, "Deserialize failed!");
|
2012-08-23 23:33:46 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(serializable);
|
|
|
|
MOZ_ASSERT(uri);
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
DeserializeURI(const OptionalURIParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
switch (aParams.type()) {
|
|
|
|
case OptionalURIParams::Tvoid_t:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OptionalURIParams::TURIParams:
|
|
|
|
uri = DeserializeURI(aParams.get_URIParams());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("Unknown params!");
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|