1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsNSSCertHelper.h"
9 #include "ScopedNSSTypes.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Casting.h"
12 #include "mozilla/NotNull.h"
13 #include "mozilla/Sprintf.h"
14 #include "mozilla/UniquePtr.h"
15 #include "mozilla/Utf8.h"
16 #include "mozilla/net/DNS.h"
18 #include "nsIStringBundle.h"
19 #include "nsNSSCertificate.h"
20 #include "nsReadableUtils.h"
21 #include "nsServiceManagerUtils.h"
22 #include "nsThreadUtils.h"
27 using namespace mozilla
;
29 static nsresult
GetPIPNSSBundle(nsIStringBundle
** pipnssBundle
) {
30 nsCOMPtr
<nsIStringBundleService
> bundleService(
31 do_GetService(NS_STRINGBUNDLE_CONTRACTID
));
33 return NS_ERROR_NOT_AVAILABLE
;
35 return bundleService
->CreateBundle("chrome://pipnss/locale/pipnss.properties",
39 nsresult
GetPIPNSSBundleString(const char* stringName
, nsAString
& result
) {
40 MOZ_ASSERT(NS_IsMainThread());
41 if (!NS_IsMainThread()) {
42 return NS_ERROR_NOT_SAME_THREAD
;
44 MOZ_ASSERT(stringName
);
46 return NS_ERROR_INVALID_ARG
;
48 nsCOMPtr
<nsIStringBundle
> pipnssBundle
;
49 nsresult rv
= GetPIPNSSBundle(getter_AddRefs(pipnssBundle
));
54 return pipnssBundle
->GetStringFromName(stringName
, result
);
57 nsresult
GetPIPNSSBundleString(const char* stringName
, nsACString
& result
) {
59 nsresult rv
= GetPIPNSSBundleString(stringName
, tmp
);
63 result
.Assign(NS_ConvertUTF16toUTF8(tmp
));
67 nsresult
PIPBundleFormatStringFromName(const char* stringName
,
68 const nsTArray
<nsString
>& params
,
70 MOZ_ASSERT(stringName
);
71 MOZ_ASSERT(!params
.IsEmpty());
72 if (!stringName
|| params
.IsEmpty()) {
73 return NS_ERROR_INVALID_ARG
;
75 nsCOMPtr
<nsIStringBundle
> pipnssBundle
;
76 nsresult rv
= GetPIPNSSBundle(getter_AddRefs(pipnssBundle
));
81 return pipnssBundle
->FormatStringFromName(stringName
, params
, result
);
84 void LossyUTF8ToUTF16(const char* str
, uint32_t len
,
85 /*out*/ nsAString
& result
) {
86 auto span
= Span(str
, len
);
88 CopyUTF8toUTF16(span
, result
);
90 // Actually Latin1 despite ASCII in the legacy name
91 CopyASCIItoUTF16(span
, result
);