Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / components / places / public / nsIAnnotationService.idl
blob465c594579a2446ce79a829d8af40887fdabd3d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
15 * The Original Code is Annotation code
17 * The Initial Developer of the Original Code is
18 * Google Inc.
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Brett Wilson <brettw@gmail.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsISupports.idl"
41 interface nsIURI;
42 interface nsIVariant;
44 [scriptable, uuid(63fe98e0-6889-4c2c-ac9f-703e4bc25027)]
45 interface nsIAnnotationObserver : nsISupports
47 /**
48 * Called when an annotation value is set. It could be a new annotation,
49 * or it could be a new value for an existing annotation.
51 void onPageAnnotationSet(in nsIURI aPage, in AUTF8String aName);
52 void onItemAnnotationSet(in long long aItemId, in AUTF8String aName);
54 /**
55 * Called when an annotation is deleted. If aName is empty, then ALL
56 * annotations for the given URI have been deleted. This is not called when
57 * annotations are expired (normally happens when the app exits).
59 void onPageAnnotationRemoved(in nsIURI aURI, in AUTF8String aName);
60 void onItemAnnotationRemoved(in long long aItemId, in AUTF8String aName);
63 [scriptable, uuid(ba249b58-346f-42a9-a393-203ae34ec6c4)]
64 interface nsIAnnotationService : nsISupports
66 /**
67 * Valid values for aExpiration, which sets the expiration policy for your
68 * annotation. The times for the days, weeks and months policies are
69 * measured since the last visit date of the page in question. These
70 * will not expire so long as the user keeps visiting the page from time
71 * to time.
74 // For temporary data that can be discarded when the user exits.
75 // Removed at application exit.
76 const unsigned short EXPIRE_SESSION = 0;
78 // NOTE: 1 is skipped due to its temporary use as EXPIRE_NEVER in bug #319455.
80 // For general page settings, things the user is interested in seeing
81 // if they come back to this page some time in the near future.
82 // Removed at 30 days.
83 const unsigned short EXPIRE_WEEKS = 2;
85 // Something that the user will be interested in seeing in their
86 // history like favicons. If they haven't visited a page in a couple
87 // of months, they probably aren't interested in many other annotations,
88 // the positions of things, or other stuff you create, so put that in
89 // the weeks policy.
90 // Removed at 180 days.
91 const unsigned short EXPIRE_MONTHS = 3;
93 // For annotations that only live as long as the URI is in the database.
94 // A page annotation will expire if the page has no visits
95 // and is not bookmarked.
96 // An item annotation will expire when the item is deleted.
97 const unsigned short EXPIRE_NEVER = 4;
99 // For annotations that only live as long as the URI has visits.
100 // Valid only for page annotations.
101 const unsigned short EXPIRE_WITH_HISTORY = 5;
103 // For short-lived temporary data that you still want to outlast a session.
104 // Removed at 7 days.
105 const unsigned short EXPIRE_DAYS = 6;
107 // type constants
108 const unsigned short TYPE_INT32 = 1;
109 const unsigned short TYPE_DOUBLE = 2;
110 const unsigned short TYPE_STRING = 3;
111 const unsigned short TYPE_BINARY = 4;
112 const unsigned short TYPE_INT64 = 5;
115 * Sets an annotation, overwriting any previous annotation with the same
116 * URL/name. IT IS YOUR JOB TO NAMESPACE YOUR ANNOTATION NAMES.
117 * Use the form "namespace/value", so your name would be like
118 * "bills_extension/page_state" or "history/thumbnail".
120 * Do not use characters that are not valid in URLs such as spaces, ":",
121 * commas, or most other symbols. You should stick to ASCII letters and
122 * numbers plus "_", "-", and "/".
124 * aExpiration is one of EXPIRE_* above. aFlags should be 0 for now, some
125 * flags will be defined in the future.
127 * NOTE: ALL ANNOTATIONS WILL GET DELETED WHEN THE PAGE IS REMOVED FROM HISTORY,
128 * UNLESS YOU USE THE EXPIRE_NEVER FLAG. This means that if you create an
129 * annotation on a random unvisited URI, it will get deleted when the
130 * browser shuts down. Otherwise, things can exist in history as
131 * annotations but the user has no way of knowing it, potentially violating
132 * their privacy expectations about actions such as "Clear history." If
133 * there is an important annotation that the user wants to keep, you should
134 * make sure that you use EXPIRE_NEVER. This will ensure the item is never
135 * completely deleted from the Places database.
137 * The annotation "favicon" is special. Favicons are stored in the favicon
138 * service, but are special cased in the protocol handler so they look like
139 * annotations. Do not set favicons using this service, it will not work.
141 * Binary annotations should be set using
142 * setItemAnnotationBinary/setPageAnnotationBinary. For other types, only
143 * C++ consumers may use the type-specific methods.
145 void setPageAnnotation(in nsIURI aURI, in AUTF8String aName,
146 in nsIVariant aValue, in long aFlags,
147 in unsigned short aExpiration);
148 void setItemAnnotation(in long long aItemId, in AUTF8String aName,
149 in nsIVariant aValue, in long aFlags,
150 in unsigned short aExpiration);
152 [noscript] void setPageAnnotationString(in nsIURI aURI, in AUTF8String aName,
153 in AString aValue, in long aFlags,
154 in unsigned short aExpiration);
155 [noscript] void setItemAnnotationString(in long long aItemId, in AUTF8String aName,
156 in AString aValue, in long aFlags,
157 in unsigned short aExpiration);
160 * Sets an annotation just like setAnnotationString, but takes an Int32 as
161 * input.
163 [noscript] void setPageAnnotationInt32(in nsIURI aURI, in AUTF8String aName,
164 in long aValue, in long aFlags,
165 in unsigned short aExpiration);
166 [noscript] void setItemAnnotationInt32(in long long aItemId, in AUTF8String aName,
167 in long aValue, in long aFlags,
168 in unsigned short aExpiration);
171 * Sets an annotation just like setAnnotationString, but takes an Int64 as
172 * input.
174 [noscript] void setPageAnnotationInt64(in nsIURI aURI, in AUTF8String aName,
175 in long long aValue, in long aFlags,
176 in unsigned short aExpiration);
177 [noscript] void setItemAnnotationInt64(in long long aItemId, in AUTF8String aName,
178 in long long aValue, in long aFlags,
179 in unsigned short aExpiration);
182 * Sets an annotation just like setAnnotationString, but takes a double as
183 * input.
185 [noscript] void setPageAnnotationDouble(in nsIURI aURI, in AUTF8String aName,
186 in double aValue, in long aFlags,
187 in unsigned short aExpiration);
188 [noscript] void setItemAnnotationDouble(in long long aItemId, in AUTF8String aName,
189 in double aValue, in long aFlags,
190 in unsigned short aExpiration);
192 * Sets an annotation just like setAnnotationString, but takes binary data
193 * as input. You MUST supply a valid MIME type.
195 void setPageAnnotationBinary(in nsIURI aURI, in AUTF8String aName,
196 [const,array,size_is(aDataLen)] in octet aData,
197 in unsigned long aDataLen,
198 in AUTF8String aMimeType,
199 in long aFlags,
200 in unsigned short aExpiration);
201 void setItemAnnotationBinary(in long long aItemId, in AUTF8String aName,
202 [const,array,size_is(aDataLen)] in octet aData,
203 in unsigned long aDataLen,
204 in AUTF8String aMimeType,
205 in long aFlags,
206 in unsigned short aExpiration);
209 * Retrieves the value of a given annotation. Throws an error if the
210 * annotation does not exist. Throws for binary annotations, for which
211 * getPageAnnotationBinary/getItemAnnotationBinary should be used. C++
212 * consumers may use the type-specific methods.
214 * The type-specific methods throw if the given annotation is set in
215 * a different type.
217 nsIVariant getPageAnnotation(in nsIURI aURI, in AUTF8String aName);
218 nsIVariant getItemAnnotation(in long long aItemId, in AUTF8String aName);
221 * @see getPageAnnotation
223 [noscript] AString getPageAnnotationString(in nsIURI aURI, in AUTF8String aName);
224 [noscript] AString getItemAnnotationString(in long long aItemId, in AUTF8String aName);
227 * @see getPageAnnotation
229 [noscript] long getPageAnnotationInt32(in nsIURI aURI, in AUTF8String aName);
230 [noscript] long getItemAnnotationInt32(in long long aItemId, in AUTF8String aName);
233 * @see getPageAnnotation
235 [noscript] long long getPageAnnotationInt64(in nsIURI aURI, in AUTF8String aName);
236 [noscript] long long getItemAnnotationInt64(in long long aItemId, in AUTF8String aName);
239 * @see getPageAnnotation
241 [noscript] double getPageAnnotationDouble(in nsIURI aURI, in AUTF8String aName);
242 [noscript] double getItemAnnotationDouble(in long long aItemId, in AUTF8String aName);
245 * @see getPageAnnotation. This also returns the
246 * MIME type.
248 void getPageAnnotationBinary(in nsIURI aURI, in AUTF8String aName,
249 [array,size_is(aDataLen)] out octet aData,
250 out unsigned long aDataLen,
251 out AUTF8String aMimeType);
252 void getItemAnnotationBinary(in long long aItemId, in AUTF8String aName,
253 [array,size_is(aDataLen)] out octet aData,
254 out unsigned long aDataLen,
255 out AUTF8String aMimeType);
258 * Retrieves info about an existing annotation. aMimeType will be empty
259 * if the value was not binary data.
261 * aType will be one of TYPE_* constansts above
263 * example JS:
264 * var flags = {}, exp = {}, mimeType = {};
265 * annotator.getAnnotationInfo(myURI, "foo", flags, exp, mimeType);
266 * // now you can use 'exp.value' and 'flags.value'
268 void getPageAnnotationInfo(in nsIURI aURI,
269 in AUTF8String aName,
270 out PRInt32 aFlags,
271 out unsigned short aExpiration,
272 out AUTF8String aMimeType,
273 out unsigned short aType);
274 void getItemAnnotationInfo(in long long aItemId, in AUTF8String aName,
275 out long aFlags, out unsigned short aExpiration,
276 out AUTF8String aMimeType,
277 out unsigned short aType);
280 * Retrieves the type of an existing annotation
281 * Use getAnnotationInfo if you need this along with the mime-type etc.
283 * @param aURI
284 * the uri on which the annotation is set
285 * @param aName
286 * the annotation name
287 * @return one of the TYPE_* constants above
288 * @throws if the annotation is not set
290 PRUint16 getPageAnnotationType(in nsIURI aURI, in AUTF8String aName);
291 PRUint16 getItemAnnotationType(in long long aItemId, in AUTF8String aName);
294 * Returns a list of all URIs having a given annotation.
296 void getPagesWithAnnotation(in AUTF8String name,
297 out unsigned long resultCount,
298 [retval, array, size_is(resultCount)] out nsIURI results);
299 void getItemsWithAnnotation(in AUTF8String name,
300 out unsigned long resultCount,
301 [retval, array, size_is(resultCount)] out long long results);
304 * Get the names of all annotations for this URI.
306 * example JS:
307 * var annotations = annotator.getPageAnnotations(myURI, {});
309 void getPageAnnotationNames(in nsIURI aURI, out unsigned long count,
310 [retval, array, size_is(count)] out nsIVariant result);
311 void getItemAnnotationNames(in long long aItemId, out unsigned long count,
312 [retval, array, size_is(count)] out nsIVariant result);
315 * Test for annotation existance.
317 boolean pageHasAnnotation(in nsIURI aURI, in AUTF8String aName);
318 boolean itemHasAnnotation(in long long aItemId, in AUTF8String aName);
321 * Removes a specific annotation. Succeeds even if the annotation is
322 * not found.
324 void removePageAnnotation(in nsIURI aURI, in AUTF8String aName);
325 void removeItemAnnotation(in long long aItemId, in AUTF8String aName);
328 * Removes all annotations for the given page/item.
329 * We may want some other similar functions to get annotations with given
330 * flags (once we have flags defined).
332 void removePageAnnotations(in nsIURI aURI);
333 void removeItemAnnotations(in long long aItemId);
336 * Copies all annotations from the source to the destination URI/item. If
337 * the destination already has an annotation with the same name as one on
338 * the source, it will be overwritten if aOverwriteDest is set. Otherwise,
339 * the destination URIs will be preferred.
341 * All the source annotations will stay as-is. If you don't want them
342 * any more, use removePageAnnotations on that URI.
344 void copyPageAnnotations(in nsIURI aSourceURI, in nsIURI aDestURI,
345 in boolean aOverwriteDest);
346 void copyItemAnnotations(in long long aSourceItemId,
347 in long long aDestItemId,
348 in boolean aOverwriteDest);
351 * Adds an annotation observer. The annotation service will keep an owning
352 * reference to the observer object.
354 void addObserver(in nsIAnnotationObserver aObserver);
358 * Removes an annotaton observer previously registered by addObserver.
360 void removeObserver(in nsIAnnotationObserver aObserver);
363 * Returns a URI that can be used to access the given binary annotation.
364 * This function does NOT check that the annotation exists. Also, note that
365 * you can only load URIs for annotations that have have a valid MIME type
366 * set by setAnnotationBinary. No non-URI valid chars in name, especially
367 * colon, which will mess up parsing.
369 nsIURI getAnnotationURI(in nsIURI aURI, in AUTF8String aName);