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 #ifndef nsAboutProtocolUtils_h
6 #define nsAboutProtocolUtils_h
8 #include "mozilla/Try.h"
11 #include "nsReadableUtils.h"
12 #include "nsIAboutModule.h"
13 #include "nsServiceManagerUtils.h"
16 [[nodiscard
]] inline nsresult
NS_GetAboutModuleName(nsIURI
* aAboutURI
,
18 NS_ASSERTION(aAboutURI
->SchemeIs("about"),
19 "should be used only on about: URIs");
21 MOZ_TRY(aAboutURI
->GetPathQueryRef(aModule
));
23 int32_t f
= aModule
.FindCharInSet("#?"_ns
);
28 // convert to lowercase, as all about: modules are lowercase
33 [[nodiscard
]] inline bool NS_IsContentAccessibleAboutURI(nsIURI
* aURI
) {
34 MOZ_ASSERT(aURI
->SchemeIs("about"), "Should be used only on about: URIs");
36 if (NS_WARN_IF(NS_FAILED(NS_GetAboutModuleName(aURI
, name
)))) {
39 return name
.EqualsLiteral("blank") || name
.EqualsLiteral("srcdoc");
42 inline nsresult
NS_GetAboutModule(nsIURI
* aAboutURI
, nsIAboutModule
** aModule
) {
43 MOZ_ASSERT(aAboutURI
, "Must have URI");
45 nsAutoCString contractID
;
46 MOZ_TRY(NS_GetAboutModuleName(aAboutURI
, contractID
));
48 // look up a handler to deal with "what"
49 contractID
.InsertLiteral(NS_ABOUT_MODULE_CONTRACTID_PREFIX
, 0);
51 return CallGetService(contractID
.get(), aModule
);
54 inline PRTime
SecondsToPRTime(uint32_t t_sec
) {
55 return (PRTime
)t_sec
* PR_USEC_PER_SEC
;
58 inline void PrintTimeString(char* buf
, uint32_t bufsize
, uint32_t t_sec
) {
60 PRTime t_usec
= SecondsToPRTime(t_sec
);
61 PR_ExplodeTime(t_usec
, PR_LocalTimeParameters
, &et
);
62 PR_FormatTime(buf
, bufsize
, "%Y-%m-%d %H:%M:%S", &et
);