Bug 1483965 - Fix the checked selection in the RDM device pixel ratio menu. r=caliman
[gecko.git] / xpcom / ds / nsProperties.cpp
blob8b80166e9ddeab0ee1ab16531beafef78592165d
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/. */
7 #include "nsProperties.h"
9 ////////////////////////////////////////////////////////////////////////////////
11 NS_IMPL_AGGREGATED(nsProperties)
12 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties)
13 NS_INTERFACE_MAP_ENTRY(nsIProperties)
14 NS_INTERFACE_MAP_END
16 NS_IMETHODIMP
17 nsProperties::Get(const char* prop, const nsIID& uuid, void** result)
19 if (NS_WARN_IF(!prop)) {
20 return NS_ERROR_INVALID_ARG;
23 nsCOMPtr<nsISupports> value;
24 if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
25 return NS_ERROR_FAILURE;
27 return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE;
30 NS_IMETHODIMP
31 nsProperties::Set(const char* prop, nsISupports* value)
33 if (NS_WARN_IF(!prop)) {
34 return NS_ERROR_INVALID_ARG;
36 Put(prop, value);
37 return NS_OK;
40 NS_IMETHODIMP
41 nsProperties::Undefine(const char* prop)
43 if (NS_WARN_IF(!prop)) {
44 return NS_ERROR_INVALID_ARG;
47 return nsProperties_HashBase::Remove(prop) ? NS_OK : NS_ERROR_FAILURE;
50 NS_IMETHODIMP
51 nsProperties::Has(const char* prop, bool* result)
53 if (NS_WARN_IF(!prop)) {
54 return NS_ERROR_INVALID_ARG;
57 *result = nsProperties_HashBase::Contains(prop);
58 return NS_OK;
61 NS_IMETHODIMP
62 nsProperties::GetKeys(uint32_t* aCount, char*** aKeys)
64 if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) {
65 return NS_ERROR_INVALID_ARG;
68 uint32_t count = Count();
69 char** keys = (char**)moz_xmalloc(count * sizeof(char*));
70 uint32_t j = 0;
72 for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
73 const char* key = iter.Key();
74 keys[j] = strdup(key);
76 if (!keys[j]) {
77 // Free 'em all
78 for (uint32_t i = 0; i < j; i++) {
79 free(keys[i]);
81 free(keys);
82 return NS_ERROR_OUT_OF_MEMORY;
84 j++;
87 *aCount = count;
88 *aKeys = keys;
89 return NS_OK;
92 ////////////////////////////////////////////////////////////////////////////////