1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/ArrayUtils.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/dom/BlobURL.h"
12 #include "mozilla/net/DefaultURI.h"
13 #include "mozilla/net/SubstitutingJARURI.h"
14 #include "mozilla/net/SubstitutingURL.h"
15 #include "nsAboutProtocolHandler.h"
16 #include "nsComponentManagerUtils.h"
20 #include "nsIIconURI.h"
21 #include "nsJSProtocolHandler.h"
23 #include "nsSimpleNestedURI.h"
24 #include "nsThreadUtils.h"
25 #include "nsIURIMutator.h"
27 using namespace mozilla::ipc
;
28 using mozilla::ArrayLength
;
32 NS_DEFINE_CID(kSimpleURIMutatorCID
, NS_SIMPLEURIMUTATOR_CID
);
33 NS_DEFINE_CID(kStandardURLMutatorCID
, NS_STANDARDURLMUTATOR_CID
);
34 NS_DEFINE_CID(kJARURIMutatorCID
, NS_JARURIMUTATOR_CID
);
35 NS_DEFINE_CID(kIconURIMutatorCID
, NS_MOZICONURIMUTATOR_CID
);
42 void SerializeURI(nsIURI
* aURI
, URIParams
& aParams
) {
45 aURI
->Serialize(aParams
);
46 if (aParams
.type() == URIParams::T__None
) {
47 MOZ_CRASH("Serialize failed!");
51 void SerializeURI(nsIURI
* aURI
, Maybe
<URIParams
>& aParams
) {
54 SerializeURI(aURI
, params
);
55 aParams
= Some(std::move(params
));
61 already_AddRefed
<nsIURI
> DeserializeURI(const URIParams
& aParams
) {
62 nsCOMPtr
<nsIURIMutator
> mutator
;
64 switch (aParams
.type()) {
65 case URIParams::TSimpleURIParams
:
66 mutator
= do_CreateInstance(kSimpleURIMutatorCID
);
69 case URIParams::TStandardURLParams
:
70 if (aParams
.get_StandardURLParams().isSubstituting()) {
71 mutator
= new net::SubstitutingURL::Mutator();
73 mutator
= do_CreateInstance(kStandardURLMutatorCID
);
77 case URIParams::TJARURIParams
:
78 mutator
= do_CreateInstance(kJARURIMutatorCID
);
81 case URIParams::TJSURIParams
:
82 mutator
= new nsJSURI::Mutator();
85 case URIParams::TIconURIParams
:
86 mutator
= do_CreateInstance(kIconURIMutatorCID
);
89 case URIParams::TSimpleNestedURIParams
:
90 mutator
= new net::nsSimpleNestedURI::Mutator();
93 case URIParams::THostObjectURIParams
:
94 mutator
= new mozilla::dom::BlobURL::Mutator();
97 case URIParams::TDefaultURIParams
:
98 mutator
= new mozilla::net::DefaultURI::Mutator();
101 case URIParams::TNestedAboutURIParams
:
102 mutator
= new net::nsNestedAboutURI::Mutator();
105 case URIParams::TSubstitutingJARURIParams
:
106 mutator
= new net::SubstitutingJARURI::Mutator();
110 MOZ_CRASH("Unknown params!");
115 nsresult rv
= mutator
->Deserialize(aParams
);
117 MOZ_ASSERT(false, "Deserialize failed!");
121 nsCOMPtr
<nsIURI
> uri
;
122 DebugOnly
<nsresult
> rv2
= mutator
->Finalize(getter_AddRefs(uri
));
124 MOZ_ASSERT(NS_SUCCEEDED(rv2
));
129 already_AddRefed
<nsIURI
> DeserializeURI(const Maybe
<URIParams
>& aParams
) {
130 nsCOMPtr
<nsIURI
> uri
;
132 if (aParams
.isSome()) {
133 uri
= DeserializeURI(aParams
.ref());
140 } // namespace mozilla