netwerk/base/src/nsSimpleURI.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; 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 "mozilla/DebugOnly.h"
michael@0 7
michael@0 8 #undef LOG
michael@0 9 #include "IPCMessageUtils.h"
michael@0 10
michael@0 11 #include "nsSimpleURI.h"
michael@0 12 #include "nscore.h"
michael@0 13 #include "nsString.h"
michael@0 14 #include "plstr.h"
michael@0 15 #include "nsURLHelper.h"
michael@0 16 #include "nsNetCID.h"
michael@0 17 #include "nsIObjectInputStream.h"
michael@0 18 #include "nsIObjectOutputStream.h"
michael@0 19 #include "nsEscape.h"
michael@0 20 #include "nsError.h"
michael@0 21 #include "nsIProgrammingLanguage.h"
michael@0 22 #include "nsIIPCSerializableURI.h"
michael@0 23 #include "mozilla/MemoryReporting.h"
michael@0 24 #include "mozilla/ipc/URIUtils.h"
michael@0 25
michael@0 26 using namespace mozilla::ipc;
michael@0 27
michael@0 28 static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
michael@0 29 NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
michael@0 30 static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
michael@0 31
michael@0 32 ////////////////////////////////////////////////////////////////////////////////
michael@0 33 // nsSimpleURI methods:
michael@0 34
michael@0 35 nsSimpleURI::nsSimpleURI()
michael@0 36 : mMutable(true),
michael@0 37 mIsRefValid(false)
michael@0 38 {
michael@0 39 }
michael@0 40
michael@0 41 nsSimpleURI::~nsSimpleURI()
michael@0 42 {
michael@0 43 }
michael@0 44
michael@0 45 NS_IMPL_ADDREF(nsSimpleURI)
michael@0 46 NS_IMPL_RELEASE(nsSimpleURI)
michael@0 47 NS_INTERFACE_TABLE_HEAD(nsSimpleURI)
michael@0 48 NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable, nsIClassInfo,
michael@0 49 nsIMutable, nsIIPCSerializableURI)
michael@0 50 NS_INTERFACE_TABLE_TO_MAP_SEGUE
michael@0 51 if (aIID.Equals(kThisSimpleURIImplementationCID))
michael@0 52 foundInterface = static_cast<nsIURI*>(this);
michael@0 53 else
michael@0 54 NS_INTERFACE_MAP_ENTRY(nsISizeOf)
michael@0 55 NS_INTERFACE_MAP_END
michael@0 56
michael@0 57 ////////////////////////////////////////////////////////////////////////////////
michael@0 58 // nsISerializable methods:
michael@0 59
michael@0 60 NS_IMETHODIMP
michael@0 61 nsSimpleURI::Read(nsIObjectInputStream* aStream)
michael@0 62 {
michael@0 63 nsresult rv;
michael@0 64
michael@0 65 bool isMutable;
michael@0 66 rv = aStream->ReadBoolean(&isMutable);
michael@0 67 if (NS_FAILED(rv)) return rv;
michael@0 68 mMutable = isMutable;
michael@0 69
michael@0 70 rv = aStream->ReadCString(mScheme);
michael@0 71 if (NS_FAILED(rv)) return rv;
michael@0 72
michael@0 73 rv = aStream->ReadCString(mPath);
michael@0 74 if (NS_FAILED(rv)) return rv;
michael@0 75
michael@0 76 bool isRefValid;
michael@0 77 rv = aStream->ReadBoolean(&isRefValid);
michael@0 78 if (NS_FAILED(rv)) return rv;
michael@0 79 mIsRefValid = isRefValid;
michael@0 80
michael@0 81 if (isRefValid) {
michael@0 82 rv = aStream->ReadCString(mRef);
michael@0 83 if (NS_FAILED(rv)) return rv;
michael@0 84 } else {
michael@0 85 mRef.Truncate(); // invariant: mRef should be empty when it's not valid
michael@0 86 }
michael@0 87
michael@0 88 return NS_OK;
michael@0 89 }
michael@0 90
michael@0 91 NS_IMETHODIMP
michael@0 92 nsSimpleURI::Write(nsIObjectOutputStream* aStream)
michael@0 93 {
michael@0 94 nsresult rv;
michael@0 95
michael@0 96 rv = aStream->WriteBoolean(mMutable);
michael@0 97 if (NS_FAILED(rv)) return rv;
michael@0 98
michael@0 99 rv = aStream->WriteStringZ(mScheme.get());
michael@0 100 if (NS_FAILED(rv)) return rv;
michael@0 101
michael@0 102 rv = aStream->WriteStringZ(mPath.get());
michael@0 103 if (NS_FAILED(rv)) return rv;
michael@0 104
michael@0 105 rv = aStream->WriteBoolean(mIsRefValid);
michael@0 106 if (NS_FAILED(rv)) return rv;
michael@0 107
michael@0 108 if (mIsRefValid) {
michael@0 109 rv = aStream->WriteStringZ(mRef.get());
michael@0 110 if (NS_FAILED(rv)) return rv;
michael@0 111 }
michael@0 112
michael@0 113 return NS_OK;
michael@0 114 }
michael@0 115
michael@0 116 ////////////////////////////////////////////////////////////////////////////////
michael@0 117 // nsIIPCSerializableURI methods:
michael@0 118
michael@0 119 void
michael@0 120 nsSimpleURI::Serialize(URIParams& aParams)
michael@0 121 {
michael@0 122 SimpleURIParams params;
michael@0 123
michael@0 124 params.scheme() = mScheme;
michael@0 125 params.path() = mPath;
michael@0 126 if (mIsRefValid) {
michael@0 127 params.ref() = mRef;
michael@0 128 }
michael@0 129 else {
michael@0 130 params.ref().SetIsVoid(true);
michael@0 131 }
michael@0 132 params.isMutable() = mMutable;
michael@0 133
michael@0 134 aParams = params;
michael@0 135 }
michael@0 136
michael@0 137 bool
michael@0 138 nsSimpleURI::Deserialize(const URIParams& aParams)
michael@0 139 {
michael@0 140 if (aParams.type() != URIParams::TSimpleURIParams) {
michael@0 141 NS_ERROR("Received unknown parameters from the other process!");
michael@0 142 return false;
michael@0 143 }
michael@0 144
michael@0 145 const SimpleURIParams& params = aParams.get_SimpleURIParams();
michael@0 146
michael@0 147 mScheme = params.scheme();
michael@0 148 mPath = params.path();
michael@0 149 if (params.ref().IsVoid()) {
michael@0 150 mRef.Truncate();
michael@0 151 mIsRefValid = false;
michael@0 152 }
michael@0 153 else {
michael@0 154 mRef = params.ref();
michael@0 155 mIsRefValid = true;
michael@0 156 }
michael@0 157 mMutable = params.isMutable();
michael@0 158
michael@0 159 return true;
michael@0 160 }
michael@0 161
michael@0 162 ////////////////////////////////////////////////////////////////////////////////
michael@0 163 // nsIURI methods:
michael@0 164
michael@0 165 NS_IMETHODIMP
michael@0 166 nsSimpleURI::GetSpec(nsACString &result)
michael@0 167 {
michael@0 168 result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
michael@0 169 if (mIsRefValid) {
michael@0 170 result += NS_LITERAL_CSTRING("#") + mRef;
michael@0 171 } else {
michael@0 172 NS_ABORT_IF_FALSE(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
michael@0 173 }
michael@0 174 return NS_OK;
michael@0 175 }
michael@0 176
michael@0 177 // result may contain unescaped UTF-8 characters
michael@0 178 NS_IMETHODIMP
michael@0 179 nsSimpleURI::GetSpecIgnoringRef(nsACString &result)
michael@0 180 {
michael@0 181 result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
michael@0 182 return NS_OK;
michael@0 183 }
michael@0 184
michael@0 185 NS_IMETHODIMP
michael@0 186 nsSimpleURI::GetHasRef(bool *result)
michael@0 187 {
michael@0 188 *result = mIsRefValid;
michael@0 189 return NS_OK;
michael@0 190 }
michael@0 191
michael@0 192 NS_IMETHODIMP
michael@0 193 nsSimpleURI::SetSpec(const nsACString &aSpec)
michael@0 194 {
michael@0 195 NS_ENSURE_STATE(mMutable);
michael@0 196
michael@0 197 const nsAFlatCString& flat = PromiseFlatCString(aSpec);
michael@0 198 const char* specPtr = flat.get();
michael@0 199
michael@0 200 // filter out unexpected chars "\r\n\t" if necessary
michael@0 201 nsAutoCString filteredSpec;
michael@0 202 int32_t specLen;
michael@0 203 if (net_FilterURIString(specPtr, filteredSpec)) {
michael@0 204 specPtr = filteredSpec.get();
michael@0 205 specLen = filteredSpec.Length();
michael@0 206 } else
michael@0 207 specLen = flat.Length();
michael@0 208
michael@0 209 // nsSimpleURI currently restricts the charset to US-ASCII
michael@0 210 nsAutoCString spec;
michael@0 211 NS_EscapeURL(specPtr, specLen, esc_OnlyNonASCII|esc_AlwaysCopy, spec);
michael@0 212
michael@0 213 int32_t colonPos = spec.FindChar(':');
michael@0 214 if (colonPos < 0 || !net_IsValidScheme(spec.get(), colonPos))
michael@0 215 return NS_ERROR_MALFORMED_URI;
michael@0 216
michael@0 217 mScheme.Truncate();
michael@0 218 mozilla::DebugOnly<int32_t> n = spec.Left(mScheme, colonPos);
michael@0 219 NS_ASSERTION(n == colonPos, "Left failed");
michael@0 220 ToLowerCase(mScheme);
michael@0 221
michael@0 222 // This sets both mPath and mRef.
michael@0 223 return SetPath(Substring(spec, colonPos + 1));
michael@0 224 }
michael@0 225
michael@0 226 NS_IMETHODIMP
michael@0 227 nsSimpleURI::GetScheme(nsACString &result)
michael@0 228 {
michael@0 229 result = mScheme;
michael@0 230 return NS_OK;
michael@0 231 }
michael@0 232
michael@0 233 NS_IMETHODIMP
michael@0 234 nsSimpleURI::SetScheme(const nsACString &scheme)
michael@0 235 {
michael@0 236 NS_ENSURE_STATE(mMutable);
michael@0 237
michael@0 238 const nsPromiseFlatCString &flat = PromiseFlatCString(scheme);
michael@0 239 if (!net_IsValidScheme(flat)) {
michael@0 240 NS_ERROR("the given url scheme contains invalid characters");
michael@0 241 return NS_ERROR_MALFORMED_URI;
michael@0 242 }
michael@0 243
michael@0 244 mScheme = scheme;
michael@0 245 ToLowerCase(mScheme);
michael@0 246 return NS_OK;
michael@0 247 }
michael@0 248
michael@0 249 NS_IMETHODIMP
michael@0 250 nsSimpleURI::GetPrePath(nsACString &result)
michael@0 251 {
michael@0 252 result = mScheme + NS_LITERAL_CSTRING(":");
michael@0 253 return NS_OK;
michael@0 254 }
michael@0 255
michael@0 256 NS_IMETHODIMP
michael@0 257 nsSimpleURI::GetUserPass(nsACString &result)
michael@0 258 {
michael@0 259 return NS_ERROR_FAILURE;
michael@0 260 }
michael@0 261
michael@0 262 NS_IMETHODIMP
michael@0 263 nsSimpleURI::SetUserPass(const nsACString &userPass)
michael@0 264 {
michael@0 265 NS_ENSURE_STATE(mMutable);
michael@0 266
michael@0 267 return NS_ERROR_FAILURE;
michael@0 268 }
michael@0 269
michael@0 270 NS_IMETHODIMP
michael@0 271 nsSimpleURI::GetUsername(nsACString &result)
michael@0 272 {
michael@0 273 return NS_ERROR_FAILURE;
michael@0 274 }
michael@0 275
michael@0 276 NS_IMETHODIMP
michael@0 277 nsSimpleURI::SetUsername(const nsACString &userName)
michael@0 278 {
michael@0 279 NS_ENSURE_STATE(mMutable);
michael@0 280
michael@0 281 return NS_ERROR_FAILURE;
michael@0 282 }
michael@0 283
michael@0 284 NS_IMETHODIMP
michael@0 285 nsSimpleURI::GetPassword(nsACString &result)
michael@0 286 {
michael@0 287 return NS_ERROR_FAILURE;
michael@0 288 }
michael@0 289
michael@0 290 NS_IMETHODIMP
michael@0 291 nsSimpleURI::SetPassword(const nsACString &password)
michael@0 292 {
michael@0 293 NS_ENSURE_STATE(mMutable);
michael@0 294
michael@0 295 return NS_ERROR_FAILURE;
michael@0 296 }
michael@0 297
michael@0 298 NS_IMETHODIMP
michael@0 299 nsSimpleURI::GetHostPort(nsACString &result)
michael@0 300 {
michael@0 301 // Note: Audit all callers before changing this to return an empty
michael@0 302 // string -- CAPS and UI code may depend on this throwing.
michael@0 303 return NS_ERROR_FAILURE;
michael@0 304 }
michael@0 305
michael@0 306 NS_IMETHODIMP
michael@0 307 nsSimpleURI::SetHostPort(const nsACString &result)
michael@0 308 {
michael@0 309 NS_ENSURE_STATE(mMutable);
michael@0 310
michael@0 311 return NS_ERROR_FAILURE;
michael@0 312 }
michael@0 313
michael@0 314 NS_IMETHODIMP
michael@0 315 nsSimpleURI::GetHost(nsACString &result)
michael@0 316 {
michael@0 317 // Note: Audit all callers before changing this to return an empty
michael@0 318 // string -- CAPS and UI code depend on this throwing.
michael@0 319 return NS_ERROR_FAILURE;
michael@0 320 }
michael@0 321
michael@0 322 NS_IMETHODIMP
michael@0 323 nsSimpleURI::SetHost(const nsACString &host)
michael@0 324 {
michael@0 325 NS_ENSURE_STATE(mMutable);
michael@0 326
michael@0 327 return NS_ERROR_FAILURE;
michael@0 328 }
michael@0 329
michael@0 330 NS_IMETHODIMP
michael@0 331 nsSimpleURI::GetPort(int32_t *result)
michael@0 332 {
michael@0 333 // Note: Audit all callers before changing this to return an empty
michael@0 334 // string -- CAPS and UI code may depend on this throwing.
michael@0 335 return NS_ERROR_FAILURE;
michael@0 336 }
michael@0 337
michael@0 338 NS_IMETHODIMP
michael@0 339 nsSimpleURI::SetPort(int32_t port)
michael@0 340 {
michael@0 341 NS_ENSURE_STATE(mMutable);
michael@0 342
michael@0 343 return NS_ERROR_FAILURE;
michael@0 344 }
michael@0 345
michael@0 346 NS_IMETHODIMP
michael@0 347 nsSimpleURI::GetPath(nsACString &result)
michael@0 348 {
michael@0 349 result = mPath;
michael@0 350 if (mIsRefValid) {
michael@0 351 result += NS_LITERAL_CSTRING("#") + mRef;
michael@0 352 }
michael@0 353
michael@0 354 return NS_OK;
michael@0 355 }
michael@0 356
michael@0 357 NS_IMETHODIMP
michael@0 358 nsSimpleURI::SetPath(const nsACString &path)
michael@0 359 {
michael@0 360 NS_ENSURE_STATE(mMutable);
michael@0 361
michael@0 362 int32_t hashPos = path.FindChar('#');
michael@0 363 if (hashPos < 0) {
michael@0 364 mIsRefValid = false;
michael@0 365 mRef.Truncate(); // invariant: mRef should be empty when it's not valid
michael@0 366 mPath = path;
michael@0 367 return NS_OK;
michael@0 368 }
michael@0 369
michael@0 370 mPath = StringHead(path, hashPos);
michael@0 371 return SetRef(Substring(path, uint32_t(hashPos)));
michael@0 372 }
michael@0 373
michael@0 374 NS_IMETHODIMP
michael@0 375 nsSimpleURI::GetRef(nsACString &result)
michael@0 376 {
michael@0 377 if (!mIsRefValid) {
michael@0 378 NS_ABORT_IF_FALSE(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
michael@0 379 result.Truncate();
michael@0 380 } else {
michael@0 381 result = mRef;
michael@0 382 }
michael@0 383
michael@0 384 return NS_OK;
michael@0 385 }
michael@0 386
michael@0 387 // NOTE: SetRef("") removes our ref, whereas SetRef("#") sets it to the empty
michael@0 388 // string (and will result in .spec and .path having a terminal #).
michael@0 389 NS_IMETHODIMP
michael@0 390 nsSimpleURI::SetRef(const nsACString &aRef)
michael@0 391 {
michael@0 392 NS_ENSURE_STATE(mMutable);
michael@0 393
michael@0 394 if (aRef.IsEmpty()) {
michael@0 395 // Empty string means to remove ref completely.
michael@0 396 mIsRefValid = false;
michael@0 397 mRef.Truncate(); // invariant: mRef should be empty when it's not valid
michael@0 398 return NS_OK;
michael@0 399 }
michael@0 400
michael@0 401 mIsRefValid = true;
michael@0 402
michael@0 403 // Gracefully skip initial hash
michael@0 404 if (aRef[0] == '#') {
michael@0 405 mRef = Substring(aRef, 1);
michael@0 406 } else {
michael@0 407 mRef = aRef;
michael@0 408 }
michael@0 409
michael@0 410 return NS_OK;
michael@0 411 }
michael@0 412
michael@0 413 NS_IMETHODIMP
michael@0 414 nsSimpleURI::Equals(nsIURI* other, bool *result)
michael@0 415 {
michael@0 416 return EqualsInternal(other, eHonorRef, result);
michael@0 417 }
michael@0 418
michael@0 419 NS_IMETHODIMP
michael@0 420 nsSimpleURI::EqualsExceptRef(nsIURI* other, bool *result)
michael@0 421 {
michael@0 422 return EqualsInternal(other, eIgnoreRef, result);
michael@0 423 }
michael@0 424
michael@0 425 /* virtual */ nsresult
michael@0 426 nsSimpleURI::EqualsInternal(nsIURI* other,
michael@0 427 nsSimpleURI::RefHandlingEnum refHandlingMode,
michael@0 428 bool* result)
michael@0 429 {
michael@0 430 NS_ENSURE_ARG_POINTER(other);
michael@0 431 NS_PRECONDITION(result, "null pointer");
michael@0 432
michael@0 433 nsRefPtr<nsSimpleURI> otherUri;
michael@0 434 nsresult rv = other->QueryInterface(kThisSimpleURIImplementationCID,
michael@0 435 getter_AddRefs(otherUri));
michael@0 436 if (NS_FAILED(rv)) {
michael@0 437 *result = false;
michael@0 438 return NS_OK;
michael@0 439 }
michael@0 440
michael@0 441 *result = EqualsInternal(otherUri, refHandlingMode);
michael@0 442 return NS_OK;
michael@0 443 }
michael@0 444
michael@0 445 bool
michael@0 446 nsSimpleURI::EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode)
michael@0 447 {
michael@0 448 bool result = (mScheme == otherUri->mScheme &&
michael@0 449 mPath == otherUri->mPath);
michael@0 450
michael@0 451 if (result && refHandlingMode == eHonorRef) {
michael@0 452 result = (mIsRefValid == otherUri->mIsRefValid &&
michael@0 453 (!mIsRefValid || mRef == otherUri->mRef));
michael@0 454 }
michael@0 455
michael@0 456 return result;
michael@0 457 }
michael@0 458
michael@0 459 NS_IMETHODIMP
michael@0 460 nsSimpleURI::SchemeIs(const char *i_Scheme, bool *o_Equals)
michael@0 461 {
michael@0 462 NS_ENSURE_ARG_POINTER(o_Equals);
michael@0 463 if (!i_Scheme) return NS_ERROR_NULL_POINTER;
michael@0 464
michael@0 465 const char *this_scheme = mScheme.get();
michael@0 466
michael@0 467 // mScheme is guaranteed to be lower case.
michael@0 468 if (*i_Scheme == *this_scheme || *i_Scheme == (*this_scheme - ('a' - 'A')) ) {
michael@0 469 *o_Equals = PL_strcasecmp(this_scheme, i_Scheme) ? false : true;
michael@0 470 } else {
michael@0 471 *o_Equals = false;
michael@0 472 }
michael@0 473
michael@0 474 return NS_OK;
michael@0 475 }
michael@0 476
michael@0 477 /* virtual */ nsSimpleURI*
michael@0 478 nsSimpleURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
michael@0 479 {
michael@0 480 return new nsSimpleURI();
michael@0 481 }
michael@0 482
michael@0 483 NS_IMETHODIMP
michael@0 484 nsSimpleURI::Clone(nsIURI** result)
michael@0 485 {
michael@0 486 return CloneInternal(eHonorRef, result);
michael@0 487 }
michael@0 488
michael@0 489 NS_IMETHODIMP
michael@0 490 nsSimpleURI::CloneIgnoringRef(nsIURI** result)
michael@0 491 {
michael@0 492 return CloneInternal(eIgnoreRef, result);
michael@0 493 }
michael@0 494
michael@0 495 nsresult
michael@0 496 nsSimpleURI::CloneInternal(nsSimpleURI::RefHandlingEnum refHandlingMode,
michael@0 497 nsIURI** result)
michael@0 498 {
michael@0 499 nsRefPtr<nsSimpleURI> url = StartClone(refHandlingMode);
michael@0 500 if (!url)
michael@0 501 return NS_ERROR_OUT_OF_MEMORY;
michael@0 502
michael@0 503 // Note: |url| may well have mMutable false at this point, so
michael@0 504 // don't call any setter methods.
michael@0 505 url->mScheme = mScheme;
michael@0 506 url->mPath = mPath;
michael@0 507 if (refHandlingMode == eHonorRef) {
michael@0 508 url->mRef = mRef;
michael@0 509 url->mIsRefValid = mIsRefValid;
michael@0 510 }
michael@0 511
michael@0 512 url.forget(result);
michael@0 513 return NS_OK;
michael@0 514 }
michael@0 515
michael@0 516 NS_IMETHODIMP
michael@0 517 nsSimpleURI::Resolve(const nsACString &relativePath, nsACString &result)
michael@0 518 {
michael@0 519 result = relativePath;
michael@0 520 return NS_OK;
michael@0 521 }
michael@0 522
michael@0 523 NS_IMETHODIMP
michael@0 524 nsSimpleURI::GetAsciiSpec(nsACString &result)
michael@0 525 {
michael@0 526 nsAutoCString buf;
michael@0 527 nsresult rv = GetSpec(buf);
michael@0 528 if (NS_FAILED(rv)) return rv;
michael@0 529 NS_EscapeURL(buf, esc_OnlyNonASCII|esc_AlwaysCopy, result);
michael@0 530 return NS_OK;
michael@0 531 }
michael@0 532
michael@0 533 NS_IMETHODIMP
michael@0 534 nsSimpleURI::GetAsciiHost(nsACString &result)
michael@0 535 {
michael@0 536 result.Truncate();
michael@0 537 return NS_OK;
michael@0 538 }
michael@0 539
michael@0 540 NS_IMETHODIMP
michael@0 541 nsSimpleURI::GetOriginCharset(nsACString &result)
michael@0 542 {
michael@0 543 result.Truncate();
michael@0 544 return NS_OK;
michael@0 545 }
michael@0 546
michael@0 547 //----------------------------------------------------------------------------
michael@0 548 // nsSimpleURI::nsIClassInfo
michael@0 549 //----------------------------------------------------------------------------
michael@0 550
michael@0 551 NS_IMETHODIMP
michael@0 552 nsSimpleURI::GetInterfaces(uint32_t *count, nsIID * **array)
michael@0 553 {
michael@0 554 *count = 0;
michael@0 555 *array = nullptr;
michael@0 556 return NS_OK;
michael@0 557 }
michael@0 558
michael@0 559 NS_IMETHODIMP
michael@0 560 nsSimpleURI::GetHelperForLanguage(uint32_t language, nsISupports **_retval)
michael@0 561 {
michael@0 562 *_retval = nullptr;
michael@0 563 return NS_OK;
michael@0 564 }
michael@0 565
michael@0 566 NS_IMETHODIMP
michael@0 567 nsSimpleURI::GetContractID(char * *aContractID)
michael@0 568 {
michael@0 569 // Make sure to modify any subclasses as needed if this ever
michael@0 570 // changes.
michael@0 571 *aContractID = nullptr;
michael@0 572 return NS_OK;
michael@0 573 }
michael@0 574
michael@0 575 NS_IMETHODIMP
michael@0 576 nsSimpleURI::GetClassDescription(char * *aClassDescription)
michael@0 577 {
michael@0 578 *aClassDescription = nullptr;
michael@0 579 return NS_OK;
michael@0 580 }
michael@0 581
michael@0 582 NS_IMETHODIMP
michael@0 583 nsSimpleURI::GetClassID(nsCID * *aClassID)
michael@0 584 {
michael@0 585 // Make sure to modify any subclasses as needed if this ever
michael@0 586 // changes to not call the virtual GetClassIDNoAlloc.
michael@0 587 *aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
michael@0 588 if (!*aClassID)
michael@0 589 return NS_ERROR_OUT_OF_MEMORY;
michael@0 590 return GetClassIDNoAlloc(*aClassID);
michael@0 591 }
michael@0 592
michael@0 593 NS_IMETHODIMP
michael@0 594 nsSimpleURI::GetImplementationLanguage(uint32_t *aImplementationLanguage)
michael@0 595 {
michael@0 596 *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
michael@0 597 return NS_OK;
michael@0 598 }
michael@0 599
michael@0 600 NS_IMETHODIMP
michael@0 601 nsSimpleURI::GetFlags(uint32_t *aFlags)
michael@0 602 {
michael@0 603 *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
michael@0 604 return NS_OK;
michael@0 605 }
michael@0 606
michael@0 607 NS_IMETHODIMP
michael@0 608 nsSimpleURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
michael@0 609 {
michael@0 610 *aClassIDNoAlloc = kSimpleURICID;
michael@0 611 return NS_OK;
michael@0 612 }
michael@0 613
michael@0 614 //----------------------------------------------------------------------------
michael@0 615 // nsSimpleURI::nsISimpleURI
michael@0 616 //----------------------------------------------------------------------------
michael@0 617 NS_IMETHODIMP
michael@0 618 nsSimpleURI::GetMutable(bool *value)
michael@0 619 {
michael@0 620 *value = mMutable;
michael@0 621 return NS_OK;
michael@0 622 }
michael@0 623
michael@0 624 NS_IMETHODIMP
michael@0 625 nsSimpleURI::SetMutable(bool value)
michael@0 626 {
michael@0 627 NS_ENSURE_ARG(mMutable || !value);
michael@0 628
michael@0 629 mMutable = value;
michael@0 630 return NS_OK;
michael@0 631 }
michael@0 632
michael@0 633 //----------------------------------------------------------------------------
michael@0 634 // nsSimpleURI::nsISizeOf
michael@0 635 //----------------------------------------------------------------------------
michael@0 636
michael@0 637 size_t
michael@0 638 nsSimpleURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
michael@0 639 {
michael@0 640 return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
michael@0 641 mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
michael@0 642 mRef.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
michael@0 643 }
michael@0 644
michael@0 645 size_t
michael@0 646 nsSimpleURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
michael@0 647 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
michael@0 648 }
michael@0 649

mercurial