2016-05-28 00:54:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2018-06-02 16:51:42 +03:00
|
|
|
#include "mozilla/dom/BlobURL.h"
|
2018-07-17 22:37:48 +03:00
|
|
|
#include "mozilla/NullPrincipalURI.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#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 "nsJSProtocolHandler.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsNetCID.h"
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "nsSimpleNestedURI.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2017-11-20 19:11:30 +03:00
|
|
|
#include "nsIURIMutator.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using mozilla::ArrayLength;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-20 19:11:30 +03:00
|
|
|
NS_DEFINE_CID(kSimpleURIMutatorCID, NS_SIMPLEURIMUTATOR_CID);
|
|
|
|
NS_DEFINE_CID(kStandardURLMutatorCID, NS_STANDARDURLMUTATOR_CID);
|
|
|
|
NS_DEFINE_CID(kJARURIMutatorCID, NS_JARURIMUTATOR_CID);
|
|
|
|
NS_DEFINE_CID(kIconURIMutatorCID, NS_MOZICONURIMUTATOR_CID);
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
void SerializeURI(nsIURI* aURI, URIParams& aParams) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aURI);
|
|
|
|
|
2019-01-25 16:32:36 +03:00
|
|
|
aURI->Serialize(aParams);
|
2015-02-13 02:41:21 +03:00
|
|
|
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());
|
|
|
|
|
2017-11-20 19:11:30 +03:00
|
|
|
nsCOMPtr<nsIURIMutator> mutator;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
switch (aParams.type()) {
|
|
|
|
case URIParams::TSimpleURIParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = do_CreateInstance(kSimpleURIMutatorCID);
|
2015-02-13 02:41:21 +03:00
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TStandardURLParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = do_CreateInstance(kStandardURLMutatorCID);
|
2015-02-13 02:41:21 +03:00
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TJARURIParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = do_CreateInstance(kJARURIMutatorCID);
|
2015-02-13 02:41:21 +03:00
|
|
|
break;
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::TJSURIParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = new nsJSURI::Mutator();
|
2015-03-07 00:33:00 +03:00
|
|
|
break;
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
case URIParams::TIconURIParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = do_CreateInstance(kIconURIMutatorCID);
|
2015-02-13 02:41:21 +03:00
|
|
|
break;
|
|
|
|
|
2015-02-24 23:54:40 +03:00
|
|
|
case URIParams::TNullPrincipalURIParams:
|
2017-11-20 19:11:30 +03:00
|
|
|
mutator = new NullPrincipalURI::Mutator();
|
2015-02-24 23:54:40 +03:00
|
|
|
break;
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::TSimpleNestedURIParams:
|
2018-05-30 22:21:17 +03:00
|
|
|
mutator = new net::nsSimpleNestedURI::Mutator();
|
2015-03-07 00:33:00 +03:00
|
|
|
break;
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
case URIParams::THostObjectURIParams:
|
2018-06-02 16:51:42 +03:00
|
|
|
mutator = new mozilla::dom::BlobURL::Mutator();
|
2015-03-07 00:33:00 +03:00
|
|
|
break;
|
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown params!");
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
2017-11-20 19:11:30 +03:00
|
|
|
MOZ_ASSERT(mutator);
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2017-11-20 19:11:30 +03:00
|
|
|
nsresult rv = mutator->Deserialize(aParams);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-02-13 02:41:21 +03:00
|
|
|
MOZ_ASSERT(false, "Deserialize failed!");
|
2012-08-23 23:33:46 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-20 19:11:30 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
DebugOnly<nsresult> rv2 = mutator->Finalize(getter_AddRefs(uri));
|
2015-02-13 02:41:21 +03:00
|
|
|
MOZ_ASSERT(uri);
|
2017-11-20 19:11:30 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv2));
|
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
|