nsIWeakReference.idl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  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/. */
  6. #include "nsISupports.idl"
  7. %{C++
  8. #include "mozilla/MemoryReporting.h"
  9. %}
  10. /**
  11. * An instance of |nsIWeakReference| is a proxy object that cooperates with
  12. * its referent to give clients a non-owning, non-dangling reference. Clients
  13. * own the proxy, and should generally manage it with an |nsCOMPtr| (see the
  14. * type |nsWeakPtr| for a |typedef| name that stands out) as they would any
  15. * other XPCOM object. The |QueryReferent| member function provides a
  16. * (hopefully short-lived) owning reference on demand, through which clients
  17. * can get useful access to the referent, while it still exists.
  18. *
  19. * @version 1.0
  20. * @see nsISupportsWeakReference
  21. * @see nsWeakReference
  22. * @see nsWeakPtr
  23. */
  24. [scriptable, uuid(9188bc85-f92e-11d2-81ef-0060083a0bcf)]
  25. interface nsIWeakReference : nsISupports
  26. {
  27. /**
  28. * |QueryReferent| queries the referent, if it exists, and like |QueryInterface|, produces
  29. * an owning reference to the desired interface. It is designed to look and act exactly
  30. * like (a proxied) |QueryInterface|. Don't hold on to the produced interface permanently;
  31. * that would defeat the purpose of using a non-owning |nsIWeakReference| in the first place.
  32. */
  33. void QueryReferent( in nsIIDRef uuid, [iid_is(uuid), retval] out nsQIResult result );
  34. %{C++
  35. virtual size_t SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
  36. /**
  37. * Returns true if the referring object is alive. Otherwise, false.
  38. */
  39. virtual bool IsAlive() const = 0;
  40. %}
  41. };
  42. /**
  43. * |nsISupportsWeakReference| is a factory interface which produces appropriate
  44. * instances of |nsIWeakReference|. Weak references in this scheme can only be
  45. * produced for objects that implement this interface.
  46. *
  47. * @version 1.0
  48. * @see nsIWeakReference
  49. * @see nsSupportsWeakReference
  50. */
  51. [scriptable, uuid(9188bc86-f92e-11d2-81ef-0060083a0bcf)]
  52. interface nsISupportsWeakReference : nsISupports
  53. {
  54. /**
  55. * |GetWeakReference| produces an appropriate instance of |nsIWeakReference|.
  56. * As with all good XPCOM `getters', you own the resulting interface and should
  57. * manage it with an |nsCOMPtr|.
  58. *
  59. * @see nsIWeakReference
  60. * @see nsWeakPtr
  61. * @see nsCOMPtr
  62. */
  63. nsIWeakReference GetWeakReference();
  64. };
  65. %{C++
  66. #ifdef MOZILLA_INTERNAL_API
  67. #include "nsIWeakReferenceUtils.h"
  68. #endif
  69. %}