nsIPrefBranch2.idl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Netscape Public License
  6. * Version 1.1 (the "License"); you may not use this file except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/NPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is Mozilla Communicator client code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Alec Flett <[email protected]>
  24. * Brian Nesse <[email protected]>
  25. * Benjamin Smedberg <[email protected]>
  26. *
  27. * Alternatively, the contents of this file may be used under the terms of
  28. * either the GNU General Public License Version 2 or later (the "GPL"), or
  29. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30. * in which case the provisions of the GPL or the LGPL are applicable instead
  31. * of those above. If you wish to allow use of your version of this file only
  32. * under the terms of either the GPL or the LGPL, and not to allow others to
  33. * use your version of this file under the terms of the NPL, indicate your
  34. * decision by deleting the provisions above and replace them with the notice
  35. * and other provisions required by the GPL or the LGPL. If you do not delete
  36. * the provisions above, a recipient may use your version of this file under
  37. * the terms of any one of the NPL, the GPL or the LGPL.
  38. *
  39. * ***** END LICENSE BLOCK ***** */
  40. #include "nsIPrefBranch.idl"
  41. interface nsIObserver;
  42. /**
  43. * nsIPrefBranch2 allows clients to observe changes to pref values.
  44. *
  45. * @status FROZEN
  46. * @see nsIPrefBranch
  47. */
  48. [scriptable, uuid(74567534-eb94-4b1c-8f45-389643bfc555)]
  49. interface nsIPrefBranch2 : nsIPrefBranch
  50. {
  51. /**
  52. * Add a preference change observer. On preference changes, the following
  53. * arguments will be passed to the nsIObserver.observe() method:
  54. * aSubject - The nsIPrefBranch object (this)
  55. * aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
  56. * aData - The preference which has changed
  57. *
  58. * @param aDomain The preference on which to listen for changes. This can
  59. * be the name of an entire branch to observe.
  60. * e.g. Holding the "root" prefbranch and calling
  61. * addObserver("foo.bar.", ...) will observe changes to
  62. * foo.bar.baz and foo.bar.bzip
  63. * @param aObserver The object to be notified if the preference changes.
  64. * @param aHoldWeak true Hold a weak reference to |aObserver|. The object
  65. * must implement the nsISupportsWeakReference
  66. * interface or this will fail.
  67. * false Hold a strong reference to |aObserver|.
  68. *
  69. * @note
  70. * Registering as a preference observer can open an object to potential
  71. * cyclical references which will cause memory leaks. These cycles generally
  72. * occur because an object both registers itself as an observer (causing the
  73. * branch to hold a reference to the observer) and holds a reference to the
  74. * branch object for the purpose of getting/setting preference values. There
  75. * are 3 approaches which have been implemented in an attempt to avoid these
  76. * situations.
  77. * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer
  78. * may hold a weak reference to it instead of a strong one.
  79. * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the
  80. * objects currently in its observer list. This insures that long lived
  81. * objects (services for example) will be freed correctly.
  82. * 3) The observer can request to be held as a weak reference when it is
  83. * registered. This insures that shorter lived objects (say one tied to an
  84. * open window) will not fall into the cyclical reference trap.
  85. *
  86. * @see nsIObserver
  87. * @see removeObserver
  88. */
  89. void addObserver(in string aDomain, in nsIObserver aObserver,
  90. in boolean aHoldWeak);
  91. /**
  92. * Remove a preference change observer.
  93. *
  94. * @param aDomain The preference which is being observed for changes.
  95. * @param aObserver An observer previously registered with addObserver().
  96. *
  97. * @see nsIObserver
  98. * @see addObserver
  99. */
  100. void removeObserver(in string aDomain, in nsIObserver aObserver);
  101. };
  102. %{C++
  103. /**
  104. * Notification sent when a preference changes.
  105. */
  106. #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed"
  107. %}