1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim:set ts=2 sw=2 sts=2 et cindent: */
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
7#include "nsISupports.idl"
8
9%{C++
10#include <windows.h>
11%}
12
13native HKEY(HKEY);
14
15/**
16 * This interface is designed to provide scriptable access to the Windows
17 * registry system ("With Great Power Comes Great Responsibility").  The
18 * interface represents a single key in the registry.
19 *
20 * This interface is highly Win32 specific.
21 */
22[scriptable, uuid(2555b930-d64f-437e-9be7-0a2cb252c1f4)]
23interface nsIWindowsRegKey : nsISupports
24{
25  /**
26   * Root keys.  The values for these keys correspond to the values from
27   * WinReg.h in the MS Platform SDK.  The ROOT_KEY_ prefix corresponds to the
28   * HKEY_ prefix in the MS Platform SDK.
29   *
30   * This interface is not restricted to using only these root keys.
31   */
32  const unsigned long ROOT_KEY_CLASSES_ROOT     = 0x80000000;
33  const unsigned long ROOT_KEY_CURRENT_USER     = 0x80000001;
34  const unsigned long ROOT_KEY_LOCAL_MACHINE    = 0x80000002;
35
36  /**
37   * Values for the mode parameter passed to the open and create methods.
38   * The values defined here correspond to the REGSAM values defined in
39   * WinNT.h in the MS Platform SDK, where ACCESS_ is replaced with KEY_.
40   *
41   * This interface is not restricted to using only these access types.
42   */
43  const unsigned long ACCESS_BASIC              = 0x00020000;
44  const unsigned long ACCESS_QUERY_VALUE        = 0x00000001;
45  const unsigned long ACCESS_SET_VALUE          = 0x00000002;
46  const unsigned long ACCESS_CREATE_SUB_KEY     = 0x00000004;
47  const unsigned long ACCESS_ENUMERATE_SUB_KEYS = 0x00000008;
48  const unsigned long ACCESS_NOTIFY             = 0x00000010;
49  const unsigned long ACCESS_READ               = ACCESS_BASIC |
50                                                  ACCESS_QUERY_VALUE |
51                                                  ACCESS_ENUMERATE_SUB_KEYS |
52                                                  ACCESS_NOTIFY;
53  const unsigned long ACCESS_WRITE              = ACCESS_BASIC |
54                                                  ACCESS_SET_VALUE |
55                                                  ACCESS_CREATE_SUB_KEY;
56  const unsigned long ACCESS_ALL                = ACCESS_READ |
57                                                  ACCESS_WRITE;
58  const unsigned long WOW64_32                  = 0x00000200;
59  const unsigned long WOW64_64                  = 0x00000100;
60
61
62  /**
63   * Values for the type of a registry value.  The numeric values of these
64   * constants are taken directly from WinNT.h in the MS Platform SDK.
65   * The Microsoft documentation should be consulted for the exact meaning of
66   * these value types.
67   *
68   * This interface is somewhat restricted to using only these value types.
69   * There is no method that is directly equivalent to RegQueryValueEx or
70   * RegSetValueEx.  In particular, this interface does not support the
71   * REG_MULTI_SZ and REG_EXPAND_SZ value types.  It is still possible to
72   * enumerate values that have other types (i.e., getValueType may return a
73   * type not defined below).
74   */
75  const unsigned long TYPE_NONE   = 0;  // REG_NONE
76  const unsigned long TYPE_STRING = 1;  // REG_SZ
77  const unsigned long TYPE_BINARY = 3;  // REG_BINARY
78  const unsigned long TYPE_INT    = 4;  // REG_DWORD
79  const unsigned long TYPE_INT64  = 11; // REG_QWORD
80
81  /**
82   * This attribute exposes the native HKEY and is available to provide C++
83   * consumers with the flexibility of making other Windows registry API calls
84   * that are not exposed via this interface.
85   *
86   * It is possible to initialize this object by setting an HKEY on it.  In
87   * that case, it is the responsibility of the consumer setting the HKEY to
88   * ensure that it is a valid HKEY.
89   *
90   * WARNING: Setting the key does not close the old key.
91   */
92  [noscript] attribute HKEY key;
93
94  /**
95   * This method closes the key.  If the key is already closed, then this
96   * method does nothing.
97   */
98  void close();
99
100  /**
101   * This method opens an existing key.  This method fails if the key
102   * does not exist.
103   *
104   * NOTE: On 32-bit Windows, it is valid to pass any HKEY as the rootKey
105   * parameter of this function.  However, for compatibility with 64-bit
106   * Windows, that usage should probably be avoided in favor of openChild.
107   *
108   * @param rootKey
109   *        A root key defined above or any valid HKEY on 32-bit Windows.
110   * @param relPath
111   *        A relative path from the given root key.
112   * @param mode
113   *        Access mode, which is a bit-wise OR of the ACCESS_ values defined
114   *        above.
115   */
116  void open(in unsigned long rootKey, in AString relPath, in unsigned long mode);
117
118  /**
119   * This method opens an existing key or creates a new key.
120   *
121   * NOTE: On 32-bit Windows, it is valid to pass any HKEY as the rootKey
122   * parameter of this function.  However, for compatibility with 64-bit
123   * Windows, that usage should probably be avoided in favor of createChild.
124   *
125   * @param rootKey
126   *        A root key defined above or any valid HKEY on 32-bit Windows.
127   * @param relPath
128   *        A relative path from the given root key.
129   * @param mode
130   *        Access mode, which is a bit-wise OR of the ACCESS_ values defined
131   *        above.
132   */
133  void create(in unsigned long rootKey, in AString relPath, in unsigned long mode);
134
135  /**
136   * This method opens a subkey relative to this key.  This method fails if the
137   * key does not exist.
138   *
139   * @return nsIWindowsRegKey for the newly opened subkey.
140   */
141  nsIWindowsRegKey openChild(in AString relPath, in unsigned long mode);
142
143  /**
144   * This method opens or creates a subkey relative to this key.
145   *
146   * @return nsIWindowsRegKey for the newly opened or created subkey.
147   */
148  nsIWindowsRegKey createChild(in AString relPath, in unsigned long mode);
149
150  /**
151   * This attribute returns the number of child keys.
152   */
153  readonly attribute unsigned long childCount;
154
155  /**
156   * This method returns the name of the n'th child key.
157   *
158   * @param index
159   *        The index of the requested child key.
160   */
161  AString getChildName(in unsigned long index);
162
163  /**
164   * This method checks to see if the key has a child by the given name.
165   *
166   * @param name
167   *        The name of the requested child key.
168   */
169  boolean hasChild(in AString name);
170
171  /**
172   * This attribute returns the number of values under this key.
173   */
174  readonly attribute unsigned long valueCount;
175
176  /**
177   * This method returns the name of the n'th value under this key.
178   *
179   * @param index
180   *        The index of the requested value.
181   */
182  AString getValueName(in unsigned long index);
183
184  /**
185   * This method checks to see if the key has a value by the given name.
186   *
187   * @param name
188   *        The name of the requested value.
189   */
190  boolean hasValue(in AString name);
191
192  /**
193   * This method removes a child key and all of its values.  This method will
194   * fail if the key has any children of its own.
195   *
196   * @param relPath
197   *        The relative path from this key to the key to be removed.
198   */
199  void removeChild(in AString relPath);
200
201  /**
202   * This method removes the value with the given name.
203   *
204   * @param name
205   *        The name of the value to be removed.
206   */
207  void removeValue(in AString name);
208
209  /**
210   * This method returns the type of the value with the given name.  The return
211   * value is one of the "TYPE_" constants defined above.
212   *
213   * @param name
214   *        The name of the value to query.
215   */
216  unsigned long getValueType(in AString name);
217
218  /**
219   * This method reads the string contents of the named value as a Unicode
220   * string.
221   *
222   * @param name
223   *        The name of the value to query.  This parameter can be the empty
224   *        string to request the key's default value.
225   */
226  AString readStringValue(in AString name);
227
228  /**
229   * This method reads the integer contents of the named value.
230   *
231   * @param name
232   *        The name of the value to query.
233   */
234  unsigned long readIntValue(in AString name);
235
236  /**
237   * This method reads the 64-bit integer contents of the named value.
238   *
239   * @param name
240   *        The name of the value to query.
241   */
242  unsigned long long readInt64Value(in AString name);
243
244  /**
245   * This method reads the binary contents of the named value under this key.
246   *
247   * JavaScript callers should take care with the result of this method since
248   * it will be byte-expanded to form a JS string.  (The binary data will be
249   * treated as an ISO-Latin-1 character string, which it is not).
250   *
251   * @param name
252   *        The name of the value to query.
253   */
254  ACString readBinaryValue(in AString name);
255
256  /**
257   * This method writes the unicode string contents of the named value.  The
258   * value will be created if it does not already exist.
259   *
260   * @param name
261   *        The name of the value to modify.  This parameter can be the empty
262   *        string to modify the key's default value.
263   * @param data
264   *        The data for the value to modify.
265   */
266  void writeStringValue(in AString name, in AString data);
267
268  /**
269   * This method writes the integer contents of the named value.  The value
270   * will be created if it does not already exist.
271   *
272   * @param name
273   *        The name of the value to modify.
274   * @param data
275   *        The data for the value to modify.
276   */
277  void writeIntValue(in AString name, in unsigned long data);
278
279  /**
280   * This method writes the 64-bit integer contents of the named value.  The
281   * value will be created if it does not already exist.
282   *
283   * @param name
284   *        The name of the value to modify.
285   * @param data
286   *        The data for the value to modify.
287   */
288  void writeInt64Value(in AString name, in unsigned long long data);
289
290  /**
291   * This method writes the binary contents of the named value.  The value will
292   * be created if it does not already exist.
293   *
294   * JavaScript callers should take care with the value passed to this method
295   * since it will be truncated from a JS string (unicode) to a ISO-Latin-1
296   * string.  (The binary data will be treated as an ISO-Latin-1 character
297   * string, which it is not).  So, JavaScript callers should only pass
298   * character values in the range \u0000 to \u00FF, or else data loss will
299   * occur.
300   *
301   * @param name
302   *        The name of the value to modify.
303   * @param data
304   *        The data for the value to modify.
305   */
306  void writeBinaryValue(in AString name, in ACString data);
307
308  /**
309   * This method starts watching the key to see if any of its values have
310   * changed.  The key must have been opened with mode including ACCESS_NOTIFY.
311   * If recurse is true, then this key and any of its descendant keys are
312   * watched.  Otherwise, only this key is watched.
313   *
314   * @param recurse
315   *        Indicates whether or not to also watch child keys.
316   */
317  void startWatching(in boolean recurse);
318
319  /**
320   * This method stops any watching of the key initiated by a call to
321   * startWatching.  This method does nothing if the key is not being watched.
322   */
323  void stopWatching();
324
325  /**
326   * This method returns true if the key is being watched for changes (i.e.,
327   * if startWatching() was called).
328   */
329  boolean isWatching();
330
331  /**
332   * This method returns true if the key has changed and false otherwise.
333   * This method will always return false if startWatching was not called.
334   */
335  boolean hasChanged();
336};
337