summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/about/nsAboutProtocolUtils.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/protocol/about/nsAboutProtocolUtils.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/protocol/about/nsAboutProtocolUtils.h')
-rw-r--r--netwerk/protocol/about/nsAboutProtocolUtils.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/netwerk/protocol/about/nsAboutProtocolUtils.h b/netwerk/protocol/about/nsAboutProtocolUtils.h
new file mode 100644
index 000000000..c5946412b
--- /dev/null
+++ b/netwerk/protocol/about/nsAboutProtocolUtils.h
@@ -0,0 +1,71 @@
+/* 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/. */
+
+#ifndef nsAboutProtocolUtils_h
+#define nsAboutProtocolUtils_h
+
+#include "nsIURI.h"
+#include "nsString.h"
+#include "nsReadableUtils.h"
+#include "nsIAboutModule.h"
+#include "nsServiceManagerUtils.h"
+#include "prtime.h"
+
+inline MOZ_MUST_USE nsresult
+NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule)
+{
+#ifdef DEBUG
+ {
+ bool isAbout;
+ NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) &&
+ isAbout,
+ "should be used only on about: URIs");
+ }
+#endif
+
+ nsresult rv = aAboutURI->GetPath(aModule);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ int32_t f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?"));
+ if (f != kNotFound) {
+ aModule.Truncate(f);
+ }
+
+ // convert to lowercase, as all about: modules are lowercase
+ ToLowerCase(aModule);
+ return NS_OK;
+}
+
+inline nsresult
+NS_GetAboutModule(nsIURI *aAboutURI, nsIAboutModule** aModule)
+{
+ NS_PRECONDITION(aAboutURI, "Must have URI");
+
+ nsAutoCString contractID;
+ nsresult rv = NS_GetAboutModuleName(aAboutURI, contractID);
+ if (NS_FAILED(rv)) return rv;
+
+ // look up a handler to deal with "what"
+ contractID.Insert(NS_LITERAL_CSTRING(NS_ABOUT_MODULE_CONTRACTID_PREFIX), 0);
+
+ return CallGetService(contractID.get(), aModule);
+}
+
+inline PRTime SecondsToPRTime(uint32_t t_sec)
+{
+ PRTime t_usec, usec_per_sec;
+ t_usec = t_sec;
+ usec_per_sec = PR_USEC_PER_SEC;
+ return t_usec *= usec_per_sec;
+}
+inline void PrintTimeString(char *buf, uint32_t bufsize, uint32_t t_sec)
+{
+ PRExplodedTime et;
+ PRTime t_usec = SecondsToPRTime(t_sec);
+ PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
+ PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et);
+}
+
+
+#endif