summaryrefslogtreecommitdiffstats
path: root/rdf/util
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 /rdf/util
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 'rdf/util')
-rw-r--r--rdf/util/internal/moz.build11
-rw-r--r--rdf/util/moz.build26
-rw-r--r--rdf/util/nsRDFResource.cpp221
-rw-r--r--rdf/util/nsRDFResource.h59
-rw-r--r--rdf/util/objs.mozbuild9
5 files changed, 326 insertions, 0 deletions
diff --git a/rdf/util/internal/moz.build b/rdf/util/internal/moz.build
new file mode 100644
index 000000000..cb59eddc3
--- /dev/null
+++ b/rdf/util/internal/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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('../objs.mozbuild')
+
+SOURCES += rdf_util_src_cppsrcs
+
+FINAL_LIBRARY = 'xul'
diff --git a/rdf/util/moz.build b/rdf/util/moz.build
new file mode 100644
index 000000000..2fb13aef0
--- /dev/null
+++ b/rdf/util/moz.build
@@ -0,0 +1,26 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+# This file builds the rdfutil_external_s library which should be used
+# by frozen (dependent) linkage components. The internal-linkage code
+# should use rdfutil_s which is built in the internal/ subdirectory.
+
+DIRS += ['internal']
+
+EXPORTS += [
+ 'nsRDFResource.h',
+]
+
+include('objs.mozbuild')
+
+SOURCES += rdf_util_src_cppsrcs
+
+Library('rdfutil_external_s')
+
+# we don't want the shared lib, but we want to force the creation of a static lib.
+FORCE_STATIC_LIB = True
+
+DIST_INSTALL = True
diff --git a/rdf/util/nsRDFResource.cpp b/rdf/util/nsRDFResource.cpp
new file mode 100644
index 000000000..0e6f01f14
--- /dev/null
+++ b/rdf/util/nsRDFResource.cpp
@@ -0,0 +1,221 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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 "nsRDFResource.h"
+#include "nsIServiceManager.h"
+#include "nsIRDFDelegateFactory.h"
+#include "nsIRDFService.h"
+#include "nsRDFCID.h"
+#include "mozilla/Logging.h"
+#include "nsComponentManagerUtils.h"
+#include "nsServiceManagerUtils.h"
+
+static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
+
+nsIRDFService* nsRDFResource::gRDFService = nullptr;
+nsrefcnt nsRDFResource::gRDFServiceRefCnt = 0;
+
+////////////////////////////////////////////////////////////////////////////////
+
+nsRDFResource::nsRDFResource(void)
+ : mDelegates(nullptr)
+{
+}
+
+nsRDFResource::~nsRDFResource(void)
+{
+ // Release all of the delegate objects
+ while (mDelegates) {
+ DelegateEntry* doomed = mDelegates;
+ mDelegates = mDelegates->mNext;
+ delete doomed;
+ }
+
+ if (!gRDFService)
+ return;
+
+ gRDFService->UnregisterResource(this);
+
+ if (--gRDFServiceRefCnt == 0)
+ NS_RELEASE(gRDFService);
+}
+
+NS_IMPL_ISUPPORTS(nsRDFResource, nsIRDFResource, nsIRDFNode)
+
+////////////////////////////////////////////////////////////////////////////////
+// nsIRDFNode methods:
+
+NS_IMETHODIMP
+nsRDFResource::EqualsNode(nsIRDFNode* aNode, bool* aResult)
+{
+ NS_PRECONDITION(aNode != nullptr, "null ptr");
+ if (! aNode)
+ return NS_ERROR_NULL_POINTER;
+
+ nsresult rv;
+ nsIRDFResource* resource;
+ rv = aNode->QueryInterface(NS_GET_IID(nsIRDFResource), (void**)&resource);
+ if (NS_SUCCEEDED(rv)) {
+ *aResult = (static_cast<nsIRDFResource*>(this) == resource);
+ NS_RELEASE(resource);
+ return NS_OK;
+ }
+ else if (rv == NS_NOINTERFACE) {
+ *aResult = false;
+ return NS_OK;
+ }
+ else {
+ return rv;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// nsIRDFResource methods:
+
+NS_IMETHODIMP
+nsRDFResource::Init(const char* aURI)
+{
+ NS_PRECONDITION(aURI != nullptr, "null ptr");
+ if (! aURI)
+ return NS_ERROR_NULL_POINTER;
+
+ mURI = aURI;
+
+ if (gRDFServiceRefCnt++ == 0) {
+ nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ // don't replace an existing resource with the same URI automatically
+ return gRDFService->RegisterResource(this, true);
+}
+
+NS_IMETHODIMP
+nsRDFResource::GetValue(char* *aURI)
+{
+ NS_ASSERTION(aURI, "Null out param.");
+
+ *aURI = ToNewCString(mURI);
+
+ if (!*aURI)
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsRDFResource::GetValueUTF8(nsACString& aResult)
+{
+ aResult = mURI;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsRDFResource::GetValueConst(const char** aURI)
+{
+ *aURI = mURI.get();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsRDFResource::EqualsString(const char* aURI, bool* aResult)
+{
+ NS_PRECONDITION(aURI != nullptr, "null ptr");
+ if (! aURI)
+ return NS_ERROR_NULL_POINTER;
+
+ NS_PRECONDITION(aResult, "null ptr");
+
+ *aResult = mURI.Equals(aURI);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsRDFResource::GetDelegate(const char* aKey, REFNSIID aIID, void** aResult)
+{
+ NS_PRECONDITION(aKey != nullptr, "null ptr");
+ if (! aKey)
+ return NS_ERROR_NULL_POINTER;
+
+ nsresult rv;
+ *aResult = nullptr;
+
+ DelegateEntry* entry = mDelegates;
+ while (entry) {
+ if (entry->mKey.Equals(aKey)) {
+ rv = entry->mDelegate->QueryInterface(aIID, aResult);
+ return rv;
+ }
+
+ entry = entry->mNext;
+ }
+
+ // Construct a ContractID of the form "@mozilla.org/rdf/delegate/[key]/[scheme];1
+ nsAutoCString contractID(NS_RDF_DELEGATEFACTORY_CONTRACTID_PREFIX);
+ contractID.Append(aKey);
+ contractID.AppendLiteral("&scheme=");
+
+ int32_t i = mURI.FindChar(':');
+ contractID += StringHead(mURI, i);
+
+ nsCOMPtr<nsIRDFDelegateFactory> delegateFactory =
+ do_CreateInstance(contractID.get(), &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = delegateFactory->CreateDelegate(this, aKey, aIID, aResult);
+ if (NS_FAILED(rv)) return rv;
+
+ // Okay, we've successfully created a delegate. Let's remember it.
+ entry = new DelegateEntry;
+ if (! entry) {
+ NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult));
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
+ entry->mKey = aKey;
+ entry->mDelegate = do_QueryInterface(*reinterpret_cast<nsISupports**>(aResult), &rv);
+ if (NS_FAILED(rv)) {
+ NS_ERROR("nsRDFResource::GetDelegate(): can't QI to nsISupports!");
+
+ delete entry;
+ NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult));
+ return NS_ERROR_FAILURE;
+ }
+
+ entry->mNext = mDelegates;
+
+ mDelegates = entry;
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsRDFResource::ReleaseDelegate(const char* aKey)
+{
+ NS_PRECONDITION(aKey != nullptr, "null ptr");
+ if (! aKey)
+ return NS_ERROR_NULL_POINTER;
+
+ DelegateEntry* entry = mDelegates;
+ DelegateEntry** link = &mDelegates;
+
+ while (entry) {
+ if (entry->mKey.Equals(aKey)) {
+ *link = entry->mNext;
+ delete entry;
+ return NS_OK;
+ }
+
+ link = &(entry->mNext);
+ entry = entry->mNext;
+ }
+
+ NS_WARNING("nsRDFResource::ReleaseDelegate() no delegate found");
+ return NS_OK;
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
diff --git a/rdf/util/nsRDFResource.h b/rdf/util/nsRDFResource.h
new file mode 100644
index 000000000..7556b323c
--- /dev/null
+++ b/rdf/util/nsRDFResource.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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 nsRDFResource_h__
+#define nsRDFResource_h__
+
+#include "nsCOMPtr.h"
+#include "nsIRDFNode.h"
+#include "nsIRDFResource.h"
+#include "nscore.h"
+#include "nsStringGlue.h"
+#include "rdf.h"
+
+class nsIRDFService;
+
+/**
+ * This simple base class implements nsIRDFResource, and can be used as a
+ * superclass for more sophisticated resource implementations.
+ */
+class nsRDFResource : public nsIRDFResource {
+public:
+
+ NS_DECL_THREADSAFE_ISUPPORTS
+
+ // nsIRDFNode methods:
+ NS_IMETHOD EqualsNode(nsIRDFNode* aNode, bool* aResult) override;
+
+ // nsIRDFResource methods:
+ NS_IMETHOD Init(const char* aURI) override;
+ NS_IMETHOD GetValue(char* *aURI) override;
+ NS_IMETHOD GetValueUTF8(nsACString& aResult) override;
+ NS_IMETHOD GetValueConst(const char** aURI) override;
+ NS_IMETHOD EqualsString(const char* aURI, bool* aResult) override;
+ NS_IMETHOD GetDelegate(const char* aKey, REFNSIID aIID, void** aResult) override;
+ NS_IMETHOD ReleaseDelegate(const char* aKey) override;
+
+ // nsRDFResource methods:
+ nsRDFResource(void);
+
+protected:
+ virtual ~nsRDFResource(void);
+ static nsIRDFService* gRDFService;
+ static nsrefcnt gRDFServiceRefCnt;
+
+protected:
+ nsCString mURI;
+
+ struct DelegateEntry {
+ nsCString mKey;
+ nsCOMPtr<nsISupports> mDelegate;
+ DelegateEntry* mNext;
+ };
+
+ DelegateEntry* mDelegates;
+};
+
+#endif // nsRDFResource_h__
diff --git a/rdf/util/objs.mozbuild b/rdf/util/objs.mozbuild
new file mode 100644
index 000000000..01a8223b7
--- /dev/null
+++ b/rdf/util/objs.mozbuild
@@ -0,0 +1,9 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+rdf_util_src_cppsrcs = [
+ '/rdf/util/nsRDFResource.cpp',
+]