PageRenderTime 5ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_sdk/idl/nsIPrefBranch2.idl

http://firefox-mac-pdf.googlecode.com/
IDL | 141 lines | 12 code | 7 blank | 122 comment | 0 complexity | 68668a6a0d2639afdd934b99a26a9197 MD5 | raw file
  1. /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  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 <alecf@netscape.com>
  24. * Brian Nesse <bnesse@netscape.com>
  25. * Benjamin Smedberg <benjamin@smedbergs.us>
  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 MPL, 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 MPL, 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 name of the preference which has changed, relative to
  57. * the |root| of the aSubject branch.
  58. *
  59. * aSubject.get*Pref(aData) will get the new value of the modified
  60. * preference. For example, if your observer is registered with
  61. * addObserver("bar.", ...) on a branch with root "foo.", modifying
  62. * the preference "foo.bar.baz" will trigger the observer, and aData
  63. * parameter will be "bar.baz".
  64. *
  65. * @param aDomain The preference on which to listen for changes. This can
  66. * be the name of an entire branch to observe.
  67. * e.g. Holding the "root" prefbranch and calling
  68. * addObserver("foo.bar.", ...) will observe changes to
  69. * foo.bar.baz and foo.bar.bzip
  70. * @param aObserver The object to be notified if the preference changes.
  71. * @param aHoldWeak true Hold a weak reference to |aObserver|. The object
  72. * must implement the nsISupportsWeakReference
  73. * interface or this will fail.
  74. * false Hold a strong reference to |aObserver|.
  75. *
  76. * @note
  77. * Registering as a preference observer can open an object to potential
  78. * cyclical references which will cause memory leaks. These cycles generally
  79. * occur because an object both registers itself as an observer (causing the
  80. * branch to hold a reference to the observer) and holds a reference to the
  81. * branch object for the purpose of getting/setting preference values. There
  82. * are 3 approaches which have been implemented in an attempt to avoid these
  83. * situations.
  84. * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer
  85. * may hold a weak reference to it instead of a strong one.
  86. * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the
  87. * objects currently in its observer list. This ensures that long lived
  88. * objects (services for example) will be freed correctly.
  89. * 3) The observer can request to be held as a weak reference when it is
  90. * registered. This insures that shorter lived objects (say one tied to an
  91. * open window) will not fall into the cyclical reference trap.
  92. *
  93. * @note
  94. * The list of registered observers may be changed during the dispatch of
  95. * nsPref:changed notification. However, the observers are not guaranteed
  96. * to be notified in any particular order, so you can't be sure whether the
  97. * added/removed observer will be called during the notification when it
  98. * is added/removed.
  99. *
  100. * @note
  101. * It is possible to change preferences during the notification.
  102. *
  103. * @note
  104. * It is not safe to change observers during this callback in Gecko
  105. * releases before 1.9. If you want a safe way to remove a pref observer,
  106. * please use an nsITimer.
  107. *
  108. * @see nsIObserver
  109. * @see removeObserver
  110. */
  111. void addObserver(in string aDomain, in nsIObserver aObserver,
  112. in boolean aHoldWeak);
  113. /**
  114. * Remove a preference change observer.
  115. *
  116. * @param aDomain The preference which is being observed for changes.
  117. * @param aObserver An observer previously registered with addObserver().
  118. *
  119. * @note
  120. * Note that you must call removeObserver() on the same nsIPrefBranch2
  121. * instance on which you called addObserver() in order to remove aObserver;
  122. * otherwise, the observer will not be removed.
  123. *
  124. * @see nsIObserver
  125. * @see addObserver
  126. */
  127. void removeObserver(in string aDomain, in nsIObserver aObserver);
  128. };
  129. %{C++
  130. /**
  131. * Notification sent when a preference changes.
  132. */
  133. #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed"
  134. %}