Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsSupportsPrimitives.h" |
michael@0 | 7 | #include "nsMemory.h" |
michael@0 | 8 | #include "prprf.h" |
michael@0 | 9 | |
michael@0 | 10 | using mozilla::fallible_t; |
michael@0 | 11 | |
michael@0 | 12 | /***************************************************************************/ |
michael@0 | 13 | |
michael@0 | 14 | NS_IMPL_ISUPPORTS(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive) |
michael@0 | 15 | |
michael@0 | 16 | nsSupportsIDImpl::nsSupportsIDImpl() |
michael@0 | 17 | : mData(nullptr) |
michael@0 | 18 | { |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | NS_IMETHODIMP nsSupportsIDImpl::GetType(uint16_t *aType) |
michael@0 | 22 | { |
michael@0 | 23 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 24 | *aType = TYPE_ID; |
michael@0 | 25 | |
michael@0 | 26 | return NS_OK; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | NS_IMETHODIMP nsSupportsIDImpl::GetData(nsID **aData) |
michael@0 | 30 | { |
michael@0 | 31 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 32 | if(mData) |
michael@0 | 33 | { |
michael@0 | 34 | *aData = (nsID*) nsMemory::Clone(mData, sizeof(nsID)); |
michael@0 | 35 | return *aData ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 36 | } |
michael@0 | 37 | *aData = nullptr; |
michael@0 | 38 | return NS_OK; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHODIMP nsSupportsIDImpl::SetData(const nsID *aData) |
michael@0 | 42 | { |
michael@0 | 43 | if(mData) |
michael@0 | 44 | nsMemory::Free(mData); |
michael@0 | 45 | if(aData) |
michael@0 | 46 | mData = (nsID*) nsMemory::Clone(aData, sizeof(nsID)); |
michael@0 | 47 | else |
michael@0 | 48 | mData = nullptr; |
michael@0 | 49 | return NS_OK; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | NS_IMETHODIMP nsSupportsIDImpl::ToString(char **_retval) |
michael@0 | 53 | { |
michael@0 | 54 | char* result; |
michael@0 | 55 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 56 | if(mData) |
michael@0 | 57 | { |
michael@0 | 58 | result = mData->ToString(); |
michael@0 | 59 | } |
michael@0 | 60 | else |
michael@0 | 61 | { |
michael@0 | 62 | static const char nullStr[] = "null"; |
michael@0 | 63 | result = (char*) nsMemory::Clone(nullStr, sizeof(nullStr)); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | *_retval = result; |
michael@0 | 67 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /***************************************************************************** |
michael@0 | 71 | * nsSupportsCStringImpl |
michael@0 | 72 | *****************************************************************************/ |
michael@0 | 73 | |
michael@0 | 74 | NS_IMPL_ISUPPORTS(nsSupportsCStringImpl, nsISupportsCString, |
michael@0 | 75 | nsISupportsPrimitive) |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP nsSupportsCStringImpl::GetType(uint16_t *aType) |
michael@0 | 78 | { |
michael@0 | 79 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 80 | |
michael@0 | 81 | *aType = TYPE_CSTRING; |
michael@0 | 82 | return NS_OK; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | NS_IMETHODIMP nsSupportsCStringImpl::GetData(nsACString& aData) |
michael@0 | 86 | { |
michael@0 | 87 | aData = mData; |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP nsSupportsCStringImpl::ToString(char **_retval) |
michael@0 | 92 | { |
michael@0 | 93 | *_retval = ToNewCString(mData); |
michael@0 | 94 | |
michael@0 | 95 | if (!*_retval) |
michael@0 | 96 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 97 | |
michael@0 | 98 | return NS_OK; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | NS_IMETHODIMP nsSupportsCStringImpl::SetData(const nsACString& aData) |
michael@0 | 102 | { |
michael@0 | 103 | bool ok = mData.Assign(aData, fallible_t()); |
michael@0 | 104 | if (!ok) |
michael@0 | 105 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 106 | return NS_OK; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | /***************************************************************************** |
michael@0 | 110 | * nsSupportsStringImpl |
michael@0 | 111 | *****************************************************************************/ |
michael@0 | 112 | |
michael@0 | 113 | NS_IMPL_ISUPPORTS(nsSupportsStringImpl, nsISupportsString, |
michael@0 | 114 | nsISupportsPrimitive) |
michael@0 | 115 | |
michael@0 | 116 | NS_IMETHODIMP nsSupportsStringImpl::GetType(uint16_t *aType) |
michael@0 | 117 | { |
michael@0 | 118 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 119 | |
michael@0 | 120 | *aType = TYPE_STRING; |
michael@0 | 121 | return NS_OK; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | NS_IMETHODIMP nsSupportsStringImpl::GetData(nsAString& aData) |
michael@0 | 125 | { |
michael@0 | 126 | aData = mData; |
michael@0 | 127 | return NS_OK; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | NS_IMETHODIMP nsSupportsStringImpl::ToString(char16_t **_retval) |
michael@0 | 131 | { |
michael@0 | 132 | *_retval = ToNewUnicode(mData); |
michael@0 | 133 | |
michael@0 | 134 | if (!*_retval) |
michael@0 | 135 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 136 | |
michael@0 | 137 | return NS_OK; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP nsSupportsStringImpl::SetData(const nsAString& aData) |
michael@0 | 141 | { |
michael@0 | 142 | bool ok = mData.Assign(aData, fallible_t()); |
michael@0 | 143 | if (!ok) |
michael@0 | 144 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 145 | return NS_OK; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | /***************************************************************************/ |
michael@0 | 149 | |
michael@0 | 150 | NS_IMPL_ISUPPORTS(nsSupportsPRBoolImpl, nsISupportsPRBool, |
michael@0 | 151 | nsISupportsPrimitive) |
michael@0 | 152 | |
michael@0 | 153 | nsSupportsPRBoolImpl::nsSupportsPRBoolImpl() |
michael@0 | 154 | : mData(false) |
michael@0 | 155 | { |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | NS_IMETHODIMP nsSupportsPRBoolImpl::GetType(uint16_t *aType) |
michael@0 | 159 | { |
michael@0 | 160 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 161 | *aType = TYPE_PRBOOL; |
michael@0 | 162 | |
michael@0 | 163 | return NS_OK; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | NS_IMETHODIMP nsSupportsPRBoolImpl::GetData(bool *aData) |
michael@0 | 167 | { |
michael@0 | 168 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 169 | *aData = mData; |
michael@0 | 170 | return NS_OK; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | NS_IMETHODIMP nsSupportsPRBoolImpl::SetData(bool aData) |
michael@0 | 174 | { |
michael@0 | 175 | mData = aData; |
michael@0 | 176 | return NS_OK; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | NS_IMETHODIMP nsSupportsPRBoolImpl::ToString(char **_retval) |
michael@0 | 180 | { |
michael@0 | 181 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 182 | const char * str = mData ? "true" : "false"; |
michael@0 | 183 | char* result = (char*) nsMemory::Clone(str, |
michael@0 | 184 | (strlen(str)+1)*sizeof(char)); |
michael@0 | 185 | *_retval = result; |
michael@0 | 186 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | /***************************************************************************/ |
michael@0 | 190 | |
michael@0 | 191 | NS_IMPL_ISUPPORTS(nsSupportsPRUint8Impl, nsISupportsPRUint8, |
michael@0 | 192 | nsISupportsPrimitive) |
michael@0 | 193 | |
michael@0 | 194 | nsSupportsPRUint8Impl::nsSupportsPRUint8Impl() |
michael@0 | 195 | : mData(0) |
michael@0 | 196 | { |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | NS_IMETHODIMP nsSupportsPRUint8Impl::GetType(uint16_t *aType) |
michael@0 | 200 | { |
michael@0 | 201 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 202 | *aType = TYPE_PRUINT8; |
michael@0 | 203 | |
michael@0 | 204 | return NS_OK; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | NS_IMETHODIMP nsSupportsPRUint8Impl::GetData(uint8_t *aData) |
michael@0 | 208 | { |
michael@0 | 209 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 210 | *aData = mData; |
michael@0 | 211 | return NS_OK; |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | NS_IMETHODIMP nsSupportsPRUint8Impl::SetData(uint8_t aData) |
michael@0 | 215 | { |
michael@0 | 216 | mData = aData; |
michael@0 | 217 | return NS_OK; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | NS_IMETHODIMP nsSupportsPRUint8Impl::ToString(char **_retval) |
michael@0 | 221 | { |
michael@0 | 222 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 223 | static const int size = 8; |
michael@0 | 224 | char buf[size]; |
michael@0 | 225 | |
michael@0 | 226 | PR_snprintf(buf, size, "%u", (uint16_t) mData); |
michael@0 | 227 | |
michael@0 | 228 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 229 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 230 | *_retval = result; |
michael@0 | 231 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | /***************************************************************************/ |
michael@0 | 235 | |
michael@0 | 236 | NS_IMPL_ISUPPORTS(nsSupportsPRUint16Impl, nsISupportsPRUint16, |
michael@0 | 237 | nsISupportsPrimitive) |
michael@0 | 238 | |
michael@0 | 239 | nsSupportsPRUint16Impl::nsSupportsPRUint16Impl() |
michael@0 | 240 | : mData(0) |
michael@0 | 241 | { |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | NS_IMETHODIMP nsSupportsPRUint16Impl::GetType(uint16_t *aType) |
michael@0 | 245 | { |
michael@0 | 246 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 247 | *aType = TYPE_PRUINT16; |
michael@0 | 248 | |
michael@0 | 249 | return NS_OK; |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | NS_IMETHODIMP nsSupportsPRUint16Impl::GetData(uint16_t *aData) |
michael@0 | 253 | { |
michael@0 | 254 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 255 | *aData = mData; |
michael@0 | 256 | return NS_OK; |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | NS_IMETHODIMP nsSupportsPRUint16Impl::SetData(uint16_t aData) |
michael@0 | 260 | { |
michael@0 | 261 | mData = aData; |
michael@0 | 262 | return NS_OK; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | NS_IMETHODIMP nsSupportsPRUint16Impl::ToString(char **_retval) |
michael@0 | 266 | { |
michael@0 | 267 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 268 | static const int size = 8; |
michael@0 | 269 | char buf[size]; |
michael@0 | 270 | |
michael@0 | 271 | PR_snprintf(buf, size, "%u", (int) mData); |
michael@0 | 272 | |
michael@0 | 273 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 274 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 275 | *_retval = result; |
michael@0 | 276 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | /***************************************************************************/ |
michael@0 | 280 | |
michael@0 | 281 | NS_IMPL_ISUPPORTS(nsSupportsPRUint32Impl, nsISupportsPRUint32, |
michael@0 | 282 | nsISupportsPrimitive) |
michael@0 | 283 | |
michael@0 | 284 | nsSupportsPRUint32Impl::nsSupportsPRUint32Impl() |
michael@0 | 285 | : mData(0) |
michael@0 | 286 | { |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | NS_IMETHODIMP nsSupportsPRUint32Impl::GetType(uint16_t *aType) |
michael@0 | 290 | { |
michael@0 | 291 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 292 | *aType = TYPE_PRUINT32; |
michael@0 | 293 | |
michael@0 | 294 | return NS_OK; |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | NS_IMETHODIMP nsSupportsPRUint32Impl::GetData(uint32_t *aData) |
michael@0 | 298 | { |
michael@0 | 299 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 300 | *aData = mData; |
michael@0 | 301 | return NS_OK; |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | NS_IMETHODIMP nsSupportsPRUint32Impl::SetData(uint32_t aData) |
michael@0 | 305 | { |
michael@0 | 306 | mData = aData; |
michael@0 | 307 | return NS_OK; |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | NS_IMETHODIMP nsSupportsPRUint32Impl::ToString(char **_retval) |
michael@0 | 311 | { |
michael@0 | 312 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 313 | static const int size = 16; |
michael@0 | 314 | char buf[size]; |
michael@0 | 315 | |
michael@0 | 316 | PR_snprintf(buf, size, "%lu", mData); |
michael@0 | 317 | |
michael@0 | 318 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 319 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 320 | *_retval = result; |
michael@0 | 321 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | /***************************************************************************/ |
michael@0 | 325 | |
michael@0 | 326 | NS_IMPL_ISUPPORTS(nsSupportsPRUint64Impl, nsISupportsPRUint64, |
michael@0 | 327 | nsISupportsPrimitive) |
michael@0 | 328 | |
michael@0 | 329 | nsSupportsPRUint64Impl::nsSupportsPRUint64Impl() |
michael@0 | 330 | : mData(0) |
michael@0 | 331 | { |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | NS_IMETHODIMP nsSupportsPRUint64Impl::GetType(uint16_t *aType) |
michael@0 | 335 | { |
michael@0 | 336 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 337 | *aType = TYPE_PRUINT64; |
michael@0 | 338 | |
michael@0 | 339 | return NS_OK; |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | NS_IMETHODIMP nsSupportsPRUint64Impl::GetData(uint64_t *aData) |
michael@0 | 343 | { |
michael@0 | 344 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 345 | *aData = mData; |
michael@0 | 346 | return NS_OK; |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | NS_IMETHODIMP nsSupportsPRUint64Impl::SetData(uint64_t aData) |
michael@0 | 350 | { |
michael@0 | 351 | mData = aData; |
michael@0 | 352 | return NS_OK; |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | NS_IMETHODIMP nsSupportsPRUint64Impl::ToString(char **_retval) |
michael@0 | 356 | { |
michael@0 | 357 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 358 | static const int size = 32; |
michael@0 | 359 | char buf[size]; |
michael@0 | 360 | |
michael@0 | 361 | PR_snprintf(buf, size, "%llu", mData); |
michael@0 | 362 | |
michael@0 | 363 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 364 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 365 | *_retval = result; |
michael@0 | 366 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | /***************************************************************************/ |
michael@0 | 370 | |
michael@0 | 371 | NS_IMPL_ISUPPORTS(nsSupportsPRTimeImpl, nsISupportsPRTime, |
michael@0 | 372 | nsISupportsPrimitive) |
michael@0 | 373 | |
michael@0 | 374 | nsSupportsPRTimeImpl::nsSupportsPRTimeImpl() |
michael@0 | 375 | : mData(0) |
michael@0 | 376 | { |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | NS_IMETHODIMP nsSupportsPRTimeImpl::GetType(uint16_t *aType) |
michael@0 | 380 | { |
michael@0 | 381 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 382 | *aType = TYPE_PRTIME; |
michael@0 | 383 | |
michael@0 | 384 | return NS_OK; |
michael@0 | 385 | } |
michael@0 | 386 | |
michael@0 | 387 | NS_IMETHODIMP nsSupportsPRTimeImpl::GetData(PRTime *aData) |
michael@0 | 388 | { |
michael@0 | 389 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 390 | *aData = mData; |
michael@0 | 391 | return NS_OK; |
michael@0 | 392 | } |
michael@0 | 393 | |
michael@0 | 394 | NS_IMETHODIMP nsSupportsPRTimeImpl::SetData(PRTime aData) |
michael@0 | 395 | { |
michael@0 | 396 | mData = aData; |
michael@0 | 397 | return NS_OK; |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | NS_IMETHODIMP nsSupportsPRTimeImpl::ToString(char **_retval) |
michael@0 | 401 | { |
michael@0 | 402 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 403 | static const int size = 32; |
michael@0 | 404 | char buf[size]; |
michael@0 | 405 | |
michael@0 | 406 | PR_snprintf(buf, size, "%llu", mData); |
michael@0 | 407 | |
michael@0 | 408 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 409 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 410 | *_retval = result; |
michael@0 | 411 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | /***************************************************************************/ |
michael@0 | 415 | |
michael@0 | 416 | NS_IMPL_ISUPPORTS(nsSupportsCharImpl, nsISupportsChar, |
michael@0 | 417 | nsISupportsPrimitive) |
michael@0 | 418 | |
michael@0 | 419 | nsSupportsCharImpl::nsSupportsCharImpl() |
michael@0 | 420 | : mData(0) |
michael@0 | 421 | { |
michael@0 | 422 | } |
michael@0 | 423 | |
michael@0 | 424 | NS_IMETHODIMP nsSupportsCharImpl::GetType(uint16_t *aType) |
michael@0 | 425 | { |
michael@0 | 426 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 427 | *aType = TYPE_CHAR; |
michael@0 | 428 | |
michael@0 | 429 | return NS_OK; |
michael@0 | 430 | } |
michael@0 | 431 | |
michael@0 | 432 | NS_IMETHODIMP nsSupportsCharImpl::GetData(char *aData) |
michael@0 | 433 | { |
michael@0 | 434 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 435 | *aData = mData; |
michael@0 | 436 | return NS_OK; |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | NS_IMETHODIMP nsSupportsCharImpl::SetData(char aData) |
michael@0 | 440 | { |
michael@0 | 441 | mData = aData; |
michael@0 | 442 | return NS_OK; |
michael@0 | 443 | } |
michael@0 | 444 | |
michael@0 | 445 | NS_IMETHODIMP nsSupportsCharImpl::ToString(char **_retval) |
michael@0 | 446 | { |
michael@0 | 447 | char* result; |
michael@0 | 448 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 449 | |
michael@0 | 450 | if(nullptr != (result = (char*) nsMemory::Alloc(2*sizeof(char)))) |
michael@0 | 451 | { |
michael@0 | 452 | result[0] = mData; |
michael@0 | 453 | result[1] = '\0'; |
michael@0 | 454 | } |
michael@0 | 455 | *_retval = result; |
michael@0 | 456 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | /***************************************************************************/ |
michael@0 | 460 | |
michael@0 | 461 | NS_IMPL_ISUPPORTS(nsSupportsPRInt16Impl, nsISupportsPRInt16, |
michael@0 | 462 | nsISupportsPrimitive) |
michael@0 | 463 | |
michael@0 | 464 | nsSupportsPRInt16Impl::nsSupportsPRInt16Impl() |
michael@0 | 465 | : mData(0) |
michael@0 | 466 | { |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | NS_IMETHODIMP nsSupportsPRInt16Impl::GetType(uint16_t *aType) |
michael@0 | 470 | { |
michael@0 | 471 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 472 | *aType = TYPE_PRINT16; |
michael@0 | 473 | |
michael@0 | 474 | return NS_OK; |
michael@0 | 475 | } |
michael@0 | 476 | |
michael@0 | 477 | NS_IMETHODIMP nsSupportsPRInt16Impl::GetData(int16_t *aData) |
michael@0 | 478 | { |
michael@0 | 479 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 480 | *aData = mData; |
michael@0 | 481 | return NS_OK; |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | NS_IMETHODIMP nsSupportsPRInt16Impl::SetData(int16_t aData) |
michael@0 | 485 | { |
michael@0 | 486 | mData = aData; |
michael@0 | 487 | return NS_OK; |
michael@0 | 488 | } |
michael@0 | 489 | |
michael@0 | 490 | NS_IMETHODIMP nsSupportsPRInt16Impl::ToString(char **_retval) |
michael@0 | 491 | { |
michael@0 | 492 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 493 | static const int size = 8; |
michael@0 | 494 | char buf[size]; |
michael@0 | 495 | |
michael@0 | 496 | PR_snprintf(buf, size, "%d", mData); |
michael@0 | 497 | |
michael@0 | 498 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 499 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 500 | *_retval = result; |
michael@0 | 501 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 502 | } |
michael@0 | 503 | |
michael@0 | 504 | /***************************************************************************/ |
michael@0 | 505 | |
michael@0 | 506 | NS_IMPL_ISUPPORTS(nsSupportsPRInt32Impl, nsISupportsPRInt32, |
michael@0 | 507 | nsISupportsPrimitive) |
michael@0 | 508 | |
michael@0 | 509 | nsSupportsPRInt32Impl::nsSupportsPRInt32Impl() |
michael@0 | 510 | : mData(0) |
michael@0 | 511 | { |
michael@0 | 512 | } |
michael@0 | 513 | |
michael@0 | 514 | NS_IMETHODIMP nsSupportsPRInt32Impl::GetType(uint16_t *aType) |
michael@0 | 515 | { |
michael@0 | 516 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 517 | *aType = TYPE_PRINT32; |
michael@0 | 518 | |
michael@0 | 519 | return NS_OK; |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | NS_IMETHODIMP nsSupportsPRInt32Impl::GetData(int32_t *aData) |
michael@0 | 523 | { |
michael@0 | 524 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 525 | *aData = mData; |
michael@0 | 526 | return NS_OK; |
michael@0 | 527 | } |
michael@0 | 528 | |
michael@0 | 529 | NS_IMETHODIMP nsSupportsPRInt32Impl::SetData(int32_t aData) |
michael@0 | 530 | { |
michael@0 | 531 | mData = aData; |
michael@0 | 532 | return NS_OK; |
michael@0 | 533 | } |
michael@0 | 534 | |
michael@0 | 535 | NS_IMETHODIMP nsSupportsPRInt32Impl::ToString(char **_retval) |
michael@0 | 536 | { |
michael@0 | 537 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 538 | static const int size = 16; |
michael@0 | 539 | char buf[size]; |
michael@0 | 540 | |
michael@0 | 541 | PR_snprintf(buf, size, "%ld", mData); |
michael@0 | 542 | |
michael@0 | 543 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 544 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 545 | *_retval = result; |
michael@0 | 546 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 547 | } |
michael@0 | 548 | |
michael@0 | 549 | /***************************************************************************/ |
michael@0 | 550 | |
michael@0 | 551 | NS_IMPL_ISUPPORTS(nsSupportsPRInt64Impl, nsISupportsPRInt64, |
michael@0 | 552 | nsISupportsPrimitive) |
michael@0 | 553 | |
michael@0 | 554 | nsSupportsPRInt64Impl::nsSupportsPRInt64Impl() |
michael@0 | 555 | : mData(0) |
michael@0 | 556 | { |
michael@0 | 557 | } |
michael@0 | 558 | |
michael@0 | 559 | NS_IMETHODIMP nsSupportsPRInt64Impl::GetType(uint16_t *aType) |
michael@0 | 560 | { |
michael@0 | 561 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 562 | *aType = TYPE_PRINT64; |
michael@0 | 563 | |
michael@0 | 564 | return NS_OK; |
michael@0 | 565 | } |
michael@0 | 566 | |
michael@0 | 567 | NS_IMETHODIMP nsSupportsPRInt64Impl::GetData(int64_t *aData) |
michael@0 | 568 | { |
michael@0 | 569 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 570 | *aData = mData; |
michael@0 | 571 | return NS_OK; |
michael@0 | 572 | } |
michael@0 | 573 | |
michael@0 | 574 | NS_IMETHODIMP nsSupportsPRInt64Impl::SetData(int64_t aData) |
michael@0 | 575 | { |
michael@0 | 576 | mData = aData; |
michael@0 | 577 | return NS_OK; |
michael@0 | 578 | } |
michael@0 | 579 | |
michael@0 | 580 | NS_IMETHODIMP nsSupportsPRInt64Impl::ToString(char **_retval) |
michael@0 | 581 | { |
michael@0 | 582 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 583 | static const int size = 32; |
michael@0 | 584 | char buf[size]; |
michael@0 | 585 | |
michael@0 | 586 | PR_snprintf(buf, size, "%lld", mData); |
michael@0 | 587 | |
michael@0 | 588 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 589 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 590 | *_retval = result; |
michael@0 | 591 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 592 | } |
michael@0 | 593 | |
michael@0 | 594 | /***************************************************************************/ |
michael@0 | 595 | |
michael@0 | 596 | NS_IMPL_ISUPPORTS(nsSupportsFloatImpl, nsISupportsFloat, |
michael@0 | 597 | nsISupportsPrimitive) |
michael@0 | 598 | |
michael@0 | 599 | nsSupportsFloatImpl::nsSupportsFloatImpl() |
michael@0 | 600 | : mData(float(0.0)) |
michael@0 | 601 | { |
michael@0 | 602 | } |
michael@0 | 603 | |
michael@0 | 604 | NS_IMETHODIMP nsSupportsFloatImpl::GetType(uint16_t *aType) |
michael@0 | 605 | { |
michael@0 | 606 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 607 | *aType = TYPE_FLOAT; |
michael@0 | 608 | |
michael@0 | 609 | return NS_OK; |
michael@0 | 610 | } |
michael@0 | 611 | |
michael@0 | 612 | NS_IMETHODIMP nsSupportsFloatImpl::GetData(float *aData) |
michael@0 | 613 | { |
michael@0 | 614 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 615 | *aData = mData; |
michael@0 | 616 | return NS_OK; |
michael@0 | 617 | } |
michael@0 | 618 | |
michael@0 | 619 | NS_IMETHODIMP nsSupportsFloatImpl::SetData(float aData) |
michael@0 | 620 | { |
michael@0 | 621 | mData = aData; |
michael@0 | 622 | return NS_OK; |
michael@0 | 623 | } |
michael@0 | 624 | |
michael@0 | 625 | NS_IMETHODIMP nsSupportsFloatImpl::ToString(char **_retval) |
michael@0 | 626 | { |
michael@0 | 627 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 628 | static const int size = 32; |
michael@0 | 629 | char buf[size]; |
michael@0 | 630 | |
michael@0 | 631 | PR_snprintf(buf, size, "%f", (double) mData); |
michael@0 | 632 | |
michael@0 | 633 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 634 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 635 | *_retval = result; |
michael@0 | 636 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | /***************************************************************************/ |
michael@0 | 640 | |
michael@0 | 641 | NS_IMPL_ISUPPORTS(nsSupportsDoubleImpl, nsISupportsDouble, |
michael@0 | 642 | nsISupportsPrimitive) |
michael@0 | 643 | |
michael@0 | 644 | nsSupportsDoubleImpl::nsSupportsDoubleImpl() |
michael@0 | 645 | : mData(double(0.0)) |
michael@0 | 646 | { |
michael@0 | 647 | } |
michael@0 | 648 | |
michael@0 | 649 | NS_IMETHODIMP nsSupportsDoubleImpl::GetType(uint16_t *aType) |
michael@0 | 650 | { |
michael@0 | 651 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 652 | *aType = TYPE_DOUBLE; |
michael@0 | 653 | |
michael@0 | 654 | return NS_OK; |
michael@0 | 655 | } |
michael@0 | 656 | |
michael@0 | 657 | NS_IMETHODIMP nsSupportsDoubleImpl::GetData(double *aData) |
michael@0 | 658 | { |
michael@0 | 659 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 660 | *aData = mData; |
michael@0 | 661 | return NS_OK; |
michael@0 | 662 | } |
michael@0 | 663 | |
michael@0 | 664 | NS_IMETHODIMP nsSupportsDoubleImpl::SetData(double aData) |
michael@0 | 665 | { |
michael@0 | 666 | mData = aData; |
michael@0 | 667 | return NS_OK; |
michael@0 | 668 | } |
michael@0 | 669 | |
michael@0 | 670 | NS_IMETHODIMP nsSupportsDoubleImpl::ToString(char **_retval) |
michael@0 | 671 | { |
michael@0 | 672 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 673 | static const int size = 32; |
michael@0 | 674 | char buf[size]; |
michael@0 | 675 | |
michael@0 | 676 | PR_snprintf(buf, size, "%f", mData); |
michael@0 | 677 | |
michael@0 | 678 | char* result = (char*) nsMemory::Clone(buf, |
michael@0 | 679 | (strlen(buf)+1)*sizeof(char)); |
michael@0 | 680 | *_retval = result; |
michael@0 | 681 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 682 | } |
michael@0 | 683 | |
michael@0 | 684 | /***************************************************************************/ |
michael@0 | 685 | |
michael@0 | 686 | |
michael@0 | 687 | NS_IMPL_ISUPPORTS(nsSupportsVoidImpl, nsISupportsVoid, |
michael@0 | 688 | nsISupportsPrimitive) |
michael@0 | 689 | |
michael@0 | 690 | nsSupportsVoidImpl::nsSupportsVoidImpl() |
michael@0 | 691 | : mData(nullptr) |
michael@0 | 692 | { |
michael@0 | 693 | } |
michael@0 | 694 | |
michael@0 | 695 | NS_IMETHODIMP nsSupportsVoidImpl::GetType(uint16_t *aType) |
michael@0 | 696 | { |
michael@0 | 697 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 698 | *aType = TYPE_VOID; |
michael@0 | 699 | |
michael@0 | 700 | return NS_OK; |
michael@0 | 701 | } |
michael@0 | 702 | |
michael@0 | 703 | NS_IMETHODIMP nsSupportsVoidImpl::GetData(void * *aData) |
michael@0 | 704 | { |
michael@0 | 705 | NS_ASSERTION(aData, "Bad pointer"); |
michael@0 | 706 | *aData = mData; |
michael@0 | 707 | return NS_OK; |
michael@0 | 708 | } |
michael@0 | 709 | |
michael@0 | 710 | NS_IMETHODIMP nsSupportsVoidImpl::SetData(void * aData) |
michael@0 | 711 | { |
michael@0 | 712 | mData = aData; |
michael@0 | 713 | return NS_OK; |
michael@0 | 714 | } |
michael@0 | 715 | |
michael@0 | 716 | NS_IMETHODIMP nsSupportsVoidImpl::ToString(char **_retval) |
michael@0 | 717 | { |
michael@0 | 718 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 719 | |
michael@0 | 720 | static const char str[] = "[raw data]"; |
michael@0 | 721 | char* result = (char*) nsMemory::Clone(str, sizeof(str)); |
michael@0 | 722 | *_retval = result; |
michael@0 | 723 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 724 | } |
michael@0 | 725 | |
michael@0 | 726 | /***************************************************************************/ |
michael@0 | 727 | |
michael@0 | 728 | |
michael@0 | 729 | NS_IMPL_ISUPPORTS(nsSupportsInterfacePointerImpl, |
michael@0 | 730 | nsISupportsInterfacePointer, |
michael@0 | 731 | nsISupportsPrimitive) |
michael@0 | 732 | |
michael@0 | 733 | nsSupportsInterfacePointerImpl::nsSupportsInterfacePointerImpl() |
michael@0 | 734 | : mIID(nullptr) |
michael@0 | 735 | { |
michael@0 | 736 | } |
michael@0 | 737 | |
michael@0 | 738 | nsSupportsInterfacePointerImpl::~nsSupportsInterfacePointerImpl() |
michael@0 | 739 | { |
michael@0 | 740 | if (mIID) { |
michael@0 | 741 | nsMemory::Free(mIID); |
michael@0 | 742 | } |
michael@0 | 743 | } |
michael@0 | 744 | |
michael@0 | 745 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetType(uint16_t *aType) |
michael@0 | 746 | { |
michael@0 | 747 | NS_ASSERTION(aType, "Bad pointer"); |
michael@0 | 748 | *aType = TYPE_INTERFACE_POINTER; |
michael@0 | 749 | |
michael@0 | 750 | return NS_OK; |
michael@0 | 751 | } |
michael@0 | 752 | |
michael@0 | 753 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetData(nsISupports **aData) |
michael@0 | 754 | { |
michael@0 | 755 | NS_ASSERTION(aData,"Bad pointer"); |
michael@0 | 756 | |
michael@0 | 757 | *aData = mData; |
michael@0 | 758 | NS_IF_ADDREF(*aData); |
michael@0 | 759 | |
michael@0 | 760 | return NS_OK; |
michael@0 | 761 | } |
michael@0 | 762 | |
michael@0 | 763 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetData(nsISupports * aData) |
michael@0 | 764 | { |
michael@0 | 765 | mData = aData; |
michael@0 | 766 | |
michael@0 | 767 | return NS_OK; |
michael@0 | 768 | } |
michael@0 | 769 | |
michael@0 | 770 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::GetDataIID(nsID **aIID) |
michael@0 | 771 | { |
michael@0 | 772 | NS_ASSERTION(aIID,"Bad pointer"); |
michael@0 | 773 | |
michael@0 | 774 | if(mIID) |
michael@0 | 775 | { |
michael@0 | 776 | *aIID = (nsID*) nsMemory::Clone(mIID, sizeof(nsID)); |
michael@0 | 777 | return *aIID ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 778 | } |
michael@0 | 779 | *aIID = nullptr; |
michael@0 | 780 | return NS_OK; |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::SetDataIID(const nsID *aIID) |
michael@0 | 784 | { |
michael@0 | 785 | if(mIID) |
michael@0 | 786 | nsMemory::Free(mIID); |
michael@0 | 787 | if(aIID) |
michael@0 | 788 | mIID = (nsID*) nsMemory::Clone(aIID, sizeof(nsID)); |
michael@0 | 789 | else |
michael@0 | 790 | mIID = nullptr; |
michael@0 | 791 | |
michael@0 | 792 | return NS_OK; |
michael@0 | 793 | } |
michael@0 | 794 | |
michael@0 | 795 | NS_IMETHODIMP nsSupportsInterfacePointerImpl::ToString(char **_retval) |
michael@0 | 796 | { |
michael@0 | 797 | NS_ASSERTION(_retval, "Bad pointer"); |
michael@0 | 798 | |
michael@0 | 799 | static const char str[] = "[interface pointer]"; |
michael@0 | 800 | |
michael@0 | 801 | // jband sez: think about asking nsIInterfaceInfoManager whether |
michael@0 | 802 | // the interface has a known human-readable name |
michael@0 | 803 | char* result = (char*) nsMemory::Clone(str, sizeof(str)); |
michael@0 | 804 | *_retval = result; |
michael@0 | 805 | return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 806 | } |
michael@0 | 807 | |
michael@0 | 808 | /***************************************************************************/ |
michael@0 | 809 | |
michael@0 | 810 | NS_IMPL_ISUPPORTS(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive) |
michael@0 | 811 | |
michael@0 | 812 | nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr) |
michael@0 | 813 | : mData(aStr) |
michael@0 | 814 | { } |
michael@0 | 815 | |
michael@0 | 816 | NS_IMETHODIMP |
michael@0 | 817 | nsSupportsDependentCString::GetType(uint16_t *aType) |
michael@0 | 818 | { |
michael@0 | 819 | if (NS_WARN_IF(!aType)) |
michael@0 | 820 | return NS_ERROR_INVALID_ARG; |
michael@0 | 821 | |
michael@0 | 822 | *aType = TYPE_CSTRING; |
michael@0 | 823 | return NS_OK; |
michael@0 | 824 | } |
michael@0 | 825 | |
michael@0 | 826 | NS_IMETHODIMP |
michael@0 | 827 | nsSupportsDependentCString::GetData(nsACString& aData) |
michael@0 | 828 | { |
michael@0 | 829 | aData = mData; |
michael@0 | 830 | return NS_OK; |
michael@0 | 831 | } |
michael@0 | 832 | |
michael@0 | 833 | NS_IMETHODIMP |
michael@0 | 834 | nsSupportsDependentCString::ToString(char **_retval) |
michael@0 | 835 | { |
michael@0 | 836 | if (NS_WARN_IF(!_retval)) |
michael@0 | 837 | return NS_ERROR_INVALID_ARG; |
michael@0 | 838 | |
michael@0 | 839 | *_retval = ToNewCString(mData); |
michael@0 | 840 | if (!*_retval) |
michael@0 | 841 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 842 | |
michael@0 | 843 | return NS_OK; |
michael@0 | 844 | } |
michael@0 | 845 | |
michael@0 | 846 | NS_IMETHODIMP |
michael@0 | 847 | nsSupportsDependentCString::SetData(const nsACString& aData) |
michael@0 | 848 | { |
michael@0 | 849 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 850 | } |