OLD | NEW |
(Empty) | |
| 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 <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 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 |
| 41 #include "nsIPrefBranch.idl" |
| 42 |
| 43 interface nsIObserver; |
| 44 |
| 45 /** |
| 46 * nsIPrefBranch2 allows clients to observe changes to pref values. |
| 47 * |
| 48 * @status FROZEN |
| 49 * @see nsIPrefBranch |
| 50 */ |
| 51 [scriptable, uuid(74567534-eb94-4b1c-8f45-389643bfc555)] |
| 52 interface nsIPrefBranch2 : nsIPrefBranch |
| 53 { |
| 54 /** |
| 55 * Add a preference change observer. On preference changes, the following |
| 56 * arguments will be passed to the nsIObserver.observe() method: |
| 57 * aSubject - The nsIPrefBranch object (this) |
| 58 * aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID |
| 59 * aData - The preference which has changed |
| 60 * |
| 61 * @param aDomain The preference on which to listen for changes. This can |
| 62 * be the name of an entire branch to observe. |
| 63 * e.g. Holding the "root" prefbranch and calling |
| 64 * addObserver("foo.bar.", ...) will observe changes to |
| 65 * foo.bar.baz and foo.bar.bzip |
| 66 * @param aObserver The object to be notified if the preference changes. |
| 67 * @param aHoldWeak true Hold a weak reference to |aObserver|. The object |
| 68 * must implement the nsISupportsWeakReference |
| 69 * interface or this will fail. |
| 70 * false Hold a strong reference to |aObserver|. |
| 71 * |
| 72 * @note |
| 73 * Registering as a preference observer can open an object to potential |
| 74 * cyclical references which will cause memory leaks. These cycles generally |
| 75 * occur because an object both registers itself as an observer (causing the |
| 76 * branch to hold a reference to the observer) and holds a reference to the |
| 77 * branch object for the purpose of getting/setting preference values. There |
| 78 * are 3 approaches which have been implemented in an attempt to avoid these |
| 79 * situations. |
| 80 * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer |
| 81 * may hold a weak reference to it instead of a strong one. |
| 82 * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the |
| 83 * objects currently in its observer list. This insures that long lived |
| 84 * objects (services for example) will be freed correctly. |
| 85 * 3) The observer can request to be held as a weak reference when it is |
| 86 * registered. This insures that shorter lived objects (say one tied to an |
| 87 * open window) will not fall into the cyclical reference trap. |
| 88 * |
| 89 * @see nsIObserver |
| 90 * @see removeObserver |
| 91 */ |
| 92 void addObserver(in string aDomain, in nsIObserver aObserver, |
| 93 in boolean aHoldWeak); |
| 94 |
| 95 /** |
| 96 * Remove a preference change observer. |
| 97 * |
| 98 * @param aDomain The preference which is being observed for changes. |
| 99 * @param aObserver An observer previously registered with addObserver(). |
| 100 * |
| 101 * @see nsIObserver |
| 102 * @see addObserver |
| 103 */ |
| 104 void removeObserver(in string aDomain, in nsIObserver aObserver); |
| 105 }; |
| 106 |
| 107 %{C++ |
| 108 |
| 109 /** |
| 110 * Notification sent when a preference changes. |
| 111 */ |
| 112 #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed" |
| 113 |
| 114 %} |
OLD | NEW |