|
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsISupports.idl" |
|
7 |
|
8 interface nsIFile; |
|
9 interface nsIURI; |
|
10 interface nsITransaction; |
|
11 interface nsINavHistoryBatchCallback; |
|
12 |
|
13 /** |
|
14 * Observer for bookmarks changes. |
|
15 */ |
|
16 [scriptable, uuid(8ab925f8-af9b-4837-afa0-ffed507212ce)] |
|
17 interface nsINavBookmarkObserver : nsISupports |
|
18 { |
|
19 /** |
|
20 * Notifies that a batch transaction has started. |
|
21 * Other notifications will be sent during the batch, but the observer is |
|
22 * guaranteed that onEndUpdateBatch() will be called at its completion. |
|
23 * During a batch the observer should do its best to reduce the work done to |
|
24 * handle notifications, since multiple changes are going to happen in a short |
|
25 * timeframe. |
|
26 */ |
|
27 void onBeginUpdateBatch(); |
|
28 |
|
29 /** |
|
30 * Notifies that a batch transaction has ended. |
|
31 */ |
|
32 void onEndUpdateBatch(); |
|
33 |
|
34 /** |
|
35 * Notifies that an item (any type) was added. Called after the actual |
|
36 * addition took place. |
|
37 * When a new item is created, all the items following it in the same folder |
|
38 * will have their index shifted down, but no additional notifications will |
|
39 * be sent. |
|
40 * |
|
41 * @param aItemId |
|
42 * The id of the item that was added. |
|
43 * @param aParentId |
|
44 * The id of the folder to which the item was added. |
|
45 * @param aIndex |
|
46 * The item's index in the folder. |
|
47 * @param aItemType |
|
48 * The type of the added item (see TYPE_* constants below). |
|
49 * @param aURI |
|
50 * The URI of the added item if it was TYPE_BOOKMARK, null otherwise. |
|
51 * @param aTitle |
|
52 * The title of the added item. |
|
53 * @param aDateAdded |
|
54 * The stored date added value, in microseconds from the epoch. |
|
55 * @param aGUID |
|
56 * The unique ID associated with the item. |
|
57 * @param aParentGUID |
|
58 * The unique ID associated with the item's parent. |
|
59 */ |
|
60 void onItemAdded(in long long aItemId, |
|
61 in long long aParentId, |
|
62 in long aIndex, |
|
63 in unsigned short aItemType, |
|
64 in nsIURI aURI, |
|
65 in AUTF8String aTitle, |
|
66 in PRTime aDateAdded, |
|
67 in ACString aGUID, |
|
68 in ACString aParentGUID); |
|
69 |
|
70 /** |
|
71 * Notifies that an item was removed. Called after the actual remove took |
|
72 * place. |
|
73 * When an item is removed, all the items following it in the same folder |
|
74 * will have their index shifted down, but no additional notifications will |
|
75 * be sent. |
|
76 * |
|
77 * @param aItemId |
|
78 * The id of the item that was removed. |
|
79 * @param aParentId |
|
80 * The id of the folder from which the item was removed. |
|
81 * @param aIndex |
|
82 * The bookmark's index in the folder. |
|
83 * @param aItemType |
|
84 * The type of the item to be removed (see TYPE_* constants below). |
|
85 * @param aURI |
|
86 * The URI of the added item if it was TYPE_BOOKMARK, null otherwise. |
|
87 * @param aGUID |
|
88 * The unique ID associated with the item. |
|
89 * @param aParentGUID |
|
90 * The unique ID associated with the item's parent. |
|
91 */ |
|
92 void onItemRemoved(in long long aItemId, |
|
93 in long long aParentId, |
|
94 in long aIndex, |
|
95 in unsigned short aItemType, |
|
96 in nsIURI aURI, |
|
97 in ACString aGUID, |
|
98 in ACString aParentGUID); |
|
99 |
|
100 /** |
|
101 * Notifies that an item's information has changed. This will be called |
|
102 * whenever any attributes like "title" are changed. |
|
103 * |
|
104 * @param aItemId |
|
105 * The id of the item that was changed. |
|
106 * @param aProperty |
|
107 * The property which changed. Can be null for the removal of all of |
|
108 * the annotations, in this case aIsAnnotationProperty is true. |
|
109 * @param aIsAnnotationProperty |
|
110 * Whether or not aProperty is the name of an annotation. If true |
|
111 * aNewValue is always an empty string. |
|
112 * @param aNewValue |
|
113 * For certain properties, this is set to the new value of the |
|
114 * property (see the list below). |
|
115 * @param aLastModified |
|
116 * If lastModified changed, this parameter is the new value, otherwise |
|
117 * it's set to 0. |
|
118 * @param aItemType |
|
119 * The type of the item to be removed (see TYPE_* constants below). |
|
120 * @param aParentId |
|
121 * The id of the folder containing the item. |
|
122 * @param aGUID |
|
123 * The unique ID associated with the item. |
|
124 * @param aParentGUID |
|
125 * The unique ID associated with the item's parent. |
|
126 * |
|
127 * @note List of values that may be associated with properties: |
|
128 * aProperty | aNewValue |
|
129 * ===================================================================== |
|
130 * cleartime | Empty string (all visits to this item were removed). |
|
131 * title | The new title. |
|
132 * favicon | The "moz-anno" URL of the new favicon. |
|
133 * uri | new URL. |
|
134 * tags | Empty string (tags for this item changed) |
|
135 * dateAdded | PRTime (as string) when the item was first added. |
|
136 * lastModified | PRTime (as string) when the item was last modified. |
|
137 */ |
|
138 void onItemChanged(in long long aItemId, |
|
139 in ACString aProperty, |
|
140 in boolean aIsAnnotationProperty, |
|
141 in AUTF8String aNewValue, |
|
142 in PRTime aLastModified, |
|
143 in unsigned short aItemType, |
|
144 in long long aParentId, |
|
145 in ACString aGUID, |
|
146 in ACString aParentGUID); |
|
147 |
|
148 /** |
|
149 * Notifies that the item was visited. Can be invoked only for TYPE_BOOKMARK |
|
150 * items. |
|
151 * |
|
152 * @param aItemId |
|
153 * The id of the bookmark that was visited. |
|
154 * @param aVisitId |
|
155 * The id of the visit. |
|
156 * @param aTime |
|
157 * The time of the visit. |
|
158 * @param aTransitionType |
|
159 * The transition for the visit. See nsINavHistoryService::TRANSITION_* |
|
160 * constants for a list of possible values. |
|
161 * @param aURI |
|
162 * The nsIURI for this bookmark. |
|
163 * @param aParentId |
|
164 * The id of the folder containing the item. |
|
165 * @param aGUID |
|
166 * The unique ID associated with the item. |
|
167 * @param aParentGUID |
|
168 * The unique ID associated with the item's parent. |
|
169 * |
|
170 * @see onItemChanged with property = "cleartime" for when all visits to an |
|
171 * item are removed. |
|
172 * |
|
173 * @note The reported time is the time of the visit that was added, which may |
|
174 * be well in the past since the visit time can be specified. This |
|
175 * means that the visit the observer is told about may not be the most |
|
176 * recent visit for that page. |
|
177 */ |
|
178 void onItemVisited(in long long aItemId, |
|
179 in long long aVisitId, |
|
180 in PRTime aTime, |
|
181 in unsigned long aTransitionType, |
|
182 in nsIURI aURI, |
|
183 in long long aParentId, |
|
184 in ACString aGUID, |
|
185 in ACString aParentGUID); |
|
186 |
|
187 /** |
|
188 * Notifies that an item has been moved. |
|
189 * |
|
190 * @param aItemId |
|
191 * The id of the item that was moved. |
|
192 * @param aOldParentId |
|
193 * The id of the old parent. |
|
194 * @param aOldIndex |
|
195 * The old index inside the old parent. |
|
196 * @param aNewParentId |
|
197 * The id of the new parent. |
|
198 * @param aNewIndex |
|
199 * The index inside the new parent. |
|
200 * @param aItemType |
|
201 * The type of the item to be removed (see TYPE_* constants below). |
|
202 * @param aGUID |
|
203 * The unique ID associated with the item. |
|
204 * @param aOldParentGUID |
|
205 * The unique ID associated with the old item's parent. |
|
206 * @param aNewParentGUID |
|
207 * The unique ID associated with the new item's parent. |
|
208 */ |
|
209 void onItemMoved(in long long aItemId, |
|
210 in long long aOldParentId, |
|
211 in long aOldIndex, |
|
212 in long long aNewParentId, |
|
213 in long aNewIndex, |
|
214 in unsigned short aItemType, |
|
215 in ACString aGUID, |
|
216 in ACString aOldParentGUID, |
|
217 in ACString aNewParentGUID); |
|
218 }; |
|
219 |
|
220 /** |
|
221 * The BookmarksService interface provides methods for managing bookmarked |
|
222 * history items. Bookmarks consist of a set of user-customizable |
|
223 * folders. A URI in history can be contained in one or more such folders. |
|
224 */ |
|
225 |
|
226 [scriptable, uuid(A78EA368-E28E-462E-897A-26606D4DDCE6)] |
|
227 interface nsINavBookmarksService : nsISupports |
|
228 { |
|
229 /** |
|
230 * The item ID of the Places root. |
|
231 */ |
|
232 readonly attribute long long placesRoot; |
|
233 |
|
234 /** |
|
235 * The item ID of the bookmarks menu folder. |
|
236 */ |
|
237 readonly attribute long long bookmarksMenuFolder; |
|
238 |
|
239 /** |
|
240 * The item ID of the top-level folder that contain the tag "folders". |
|
241 */ |
|
242 readonly attribute long long tagsFolder; |
|
243 |
|
244 /** |
|
245 * The item ID of the unfiled-bookmarks folder. |
|
246 */ |
|
247 readonly attribute long long unfiledBookmarksFolder; |
|
248 |
|
249 /** |
|
250 * The item ID of the personal toolbar folder. |
|
251 */ |
|
252 readonly attribute long long toolbarFolder; |
|
253 |
|
254 /** |
|
255 * This value should be used for APIs that allow passing in an index |
|
256 * where an index is not known, or not required to be specified. |
|
257 * e.g.: When appending an item to a folder. |
|
258 */ |
|
259 const short DEFAULT_INDEX = -1; |
|
260 |
|
261 const unsigned short TYPE_BOOKMARK = 1; |
|
262 const unsigned short TYPE_FOLDER = 2; |
|
263 const unsigned short TYPE_SEPARATOR = 3; |
|
264 // Dynamic containers are deprecated and unsupported. |
|
265 // This const exists just to avoid reusing the value. |
|
266 const unsigned short TYPE_DYNAMIC_CONTAINER = 4; |
|
267 |
|
268 /** |
|
269 * Inserts a child bookmark into the given folder. |
|
270 * |
|
271 * @param aParentId |
|
272 * The id of the parent folder |
|
273 * @param aURI |
|
274 * The URI to insert |
|
275 * @param aIndex |
|
276 * The index to insert at, or DEFAULT_INDEX to append |
|
277 * @param aTitle |
|
278 * The title for the new bookmark |
|
279 * @param [optional] aGUID |
|
280 * The GUID to be set for the new item. If not set, a new GUID is |
|
281 * generated. Unless you've a very sound reason, such as an undo |
|
282 * manager implementation, do not pass this argument. |
|
283 * @return The ID of the newly-created bookmark. |
|
284 * |
|
285 * @note aTitle will be truncated to TITLE_LENGTH_MAX and |
|
286 * aURI will be truncated to URI_LENGTH_MAX. |
|
287 * @throws if aGUID is malformed. |
|
288 */ |
|
289 long long insertBookmark(in long long aParentId, in nsIURI aURI, |
|
290 in long aIndex, in AUTF8String aTitle, |
|
291 [optional] in ACString aGUID); |
|
292 |
|
293 /** |
|
294 * Removes a child item. Used to delete a bookmark or separator. |
|
295 * @param aItemId |
|
296 * The child item to remove |
|
297 */ |
|
298 void removeItem(in long long aItemId); |
|
299 |
|
300 /** |
|
301 * Creates a new child folder and inserts it under the given parent. |
|
302 * @param aParentFolder |
|
303 * The id of the parent folder |
|
304 * @param aName |
|
305 * The name of the new folder |
|
306 * @param aIndex |
|
307 * The index to insert at, or DEFAULT_INDEX to append |
|
308 * @param [optional] aGUID |
|
309 * The GUID to be set for the new item. If not set, a new GUID is |
|
310 * generated. Unless you've a very sound reason, such as an undo |
|
311 * manager implementation, do not pass this argument. |
|
312 * @return The ID of the newly-inserted folder. |
|
313 * @throws if aGUID is malformed. |
|
314 */ |
|
315 long long createFolder(in long long aParentFolder, in AUTF8String name, |
|
316 in long index, |
|
317 [optional] in ACString aGUID); |
|
318 |
|
319 /** |
|
320 * Gets an undo-able transaction for removing a folder from the bookmarks |
|
321 * tree. |
|
322 * @param aItemId |
|
323 * The id of the folder to remove. |
|
324 * @return An object implementing nsITransaction that can be used to undo |
|
325 * or redo the action. |
|
326 * |
|
327 * This method exists because complex delete->undo operations rely on |
|
328 * recreated folders to have the same ID they had before they were deleted, |
|
329 * so that any other items deleted in different transactions can be |
|
330 * re-inserted correctly. This provides a safe encapsulation of this |
|
331 * functionality without exposing the ability to recreate folders with |
|
332 * specific IDs (potentially dangerous if abused by other code!) in the |
|
333 * public API. |
|
334 */ |
|
335 nsITransaction getRemoveFolderTransaction(in long long aItemId); |
|
336 |
|
337 /** |
|
338 * Convenience function for container services. Removes |
|
339 * all children of the given folder. |
|
340 * @param aItemId |
|
341 * The id of the folder to remove children from. |
|
342 */ |
|
343 void removeFolderChildren(in long long aItemId); |
|
344 |
|
345 /** |
|
346 * Moves an item to a different container, preserving its contents. |
|
347 * @param aItemId |
|
348 * The id of the item to move |
|
349 * @param aNewParentId |
|
350 * The id of the new parent |
|
351 * @param aIndex |
|
352 * The index under aNewParent, or DEFAULT_INDEX to append |
|
353 * |
|
354 * NOTE: When moving down in the same container we take into account the |
|
355 * removal of the original item. If you want to move from index X to |
|
356 * index Y > X you must use moveItem(id, folder, Y + 1) |
|
357 */ |
|
358 void moveItem(in long long aItemId, in long long aNewParentId, in long aIndex); |
|
359 |
|
360 /** |
|
361 * Inserts a bookmark separator into the given folder at the given index. |
|
362 * The separator can be removed using removeChildAt(). |
|
363 * @param aParentId |
|
364 * The id of the parent folder |
|
365 * @param aIndex |
|
366 * The separator's index under folder, or DEFAULT_INDEX to append |
|
367 * @param [optional] aGUID |
|
368 * The GUID to be set for the new item. If not set, a new GUID is |
|
369 * generated. Unless you've a very sound reason, such as an undo |
|
370 * manager implementation, do not pass this argument. |
|
371 * @return The ID of the new separator. |
|
372 * @throws if aGUID is malformed. |
|
373 */ |
|
374 long long insertSeparator(in long long aParentId, in long aIndex, |
|
375 [optional] in ACString aGUID); |
|
376 |
|
377 /** |
|
378 * Get the itemId given the containing folder and the index. |
|
379 * @param aParentId |
|
380 * The id of the diret parent folder of the item |
|
381 * @param aIndex |
|
382 * The index of the item within the parent folder. |
|
383 * Pass DEFAULT_INDEX for the last item. |
|
384 * @return The ID of the found item, -1 if the item does not exists. |
|
385 */ |
|
386 long long getIdForItemAt(in long long aParentId, in long aIndex); |
|
387 |
|
388 /** |
|
389 * Set the title for an item. |
|
390 * @param aItemId |
|
391 * The id of the item whose title should be updated. |
|
392 * @param aTitle |
|
393 * The new title for the bookmark. |
|
394 * |
|
395 * @note aTitle will be truncated to TITLE_LENGTH_MAX. |
|
396 */ |
|
397 void setItemTitle(in long long aItemId, in AUTF8String aTitle); |
|
398 |
|
399 /** |
|
400 * Get the title for an item. |
|
401 * |
|
402 * If no item title is available it will return a void string (null in JS). |
|
403 * |
|
404 * @param aItemId |
|
405 * The id of the item whose title should be retrieved |
|
406 * @return The title of the item. |
|
407 */ |
|
408 AUTF8String getItemTitle(in long long aItemId); |
|
409 |
|
410 /** |
|
411 * Set the date added time for an item. |
|
412 */ |
|
413 void setItemDateAdded(in long long aItemId, in PRTime aDateAdded); |
|
414 /** |
|
415 * Get the date added time for an item. |
|
416 */ |
|
417 PRTime getItemDateAdded(in long long aItemId); |
|
418 |
|
419 /** |
|
420 * Set the last modified time for an item. |
|
421 * |
|
422 * @note This is the only method that will send an itemChanged notification |
|
423 * for the property. lastModified will still be updated in |
|
424 * any other method that changes an item property, but we will send |
|
425 * the corresponding itemChanged notification instead. |
|
426 */ |
|
427 void setItemLastModified(in long long aItemId, in PRTime aLastModified); |
|
428 /** |
|
429 * Get the last modified time for an item. |
|
430 * |
|
431 * @note When an item is added lastModified is set to the same value as |
|
432 * dateAdded. |
|
433 */ |
|
434 PRTime getItemLastModified(in long long aItemId); |
|
435 |
|
436 /** |
|
437 * Get the URI for a bookmark item. |
|
438 */ |
|
439 nsIURI getBookmarkURI(in long long aItemId); |
|
440 |
|
441 /** |
|
442 * Get the index for an item. |
|
443 */ |
|
444 long getItemIndex(in long long aItemId); |
|
445 |
|
446 /** |
|
447 * Changes the index for a item. This method does not change the indices of |
|
448 * any other items in the same folder, so ensure that the new index does not |
|
449 * already exist, or change the index of other items accordingly, otherwise |
|
450 * the indices will become corrupted. |
|
451 * |
|
452 * WARNING: This is API is intended for scenarios such as folder sorting, |
|
453 * where the caller manages the indices of *all* items in the folder. |
|
454 * You must always ensure each index is unique after a reordering. |
|
455 * |
|
456 * @param aItemId The id of the item to modify |
|
457 * @param aNewIndex The new index |
|
458 * |
|
459 * @throws If aNewIndex is out of bounds. |
|
460 */ |
|
461 void setItemIndex(in long long aItemId, in long aNewIndex); |
|
462 |
|
463 /** |
|
464 * Get an item's type (bookmark, separator, folder). |
|
465 * The type is one of the TYPE_* constants defined above. |
|
466 */ |
|
467 unsigned short getItemType(in long long aItemId); |
|
468 |
|
469 /** |
|
470 * Checks whether a folder is marked as read-only. |
|
471 * If this is set to true, UI will not allow the user to add, remove, |
|
472 * or reorder children in this folder. The default for all folders is false. |
|
473 * Note: This does not restrict API calls, only UI actions. |
|
474 * |
|
475 * @param aItemId |
|
476 * the item-id of the folder. |
|
477 */ |
|
478 boolean getFolderReadonly(in long long aItemId); |
|
479 |
|
480 /** |
|
481 * Sets or unsets the readonly flag from a folder. |
|
482 * If this is set to true, UI will not allow the user to add, remove, |
|
483 * or reorder children in this folder. The default for all folders is false. |
|
484 * Note: This does not restrict API calls, only UI actions. |
|
485 * |
|
486 * @param aFolder |
|
487 * the item-id of the folder. |
|
488 * @param aReadOnly |
|
489 * the read-only state (boolean). |
|
490 */ |
|
491 void setFolderReadonly(in long long aFolder, in boolean aReadOnly); |
|
492 |
|
493 /** |
|
494 * Returns true if the given URI is in any bookmark folder. If you want the |
|
495 * results to be redirect-aware, use getBookmarkedURIFor() |
|
496 */ |
|
497 boolean isBookmarked(in nsIURI aURI); |
|
498 |
|
499 /** |
|
500 * Used to see if the given URI is bookmarked, or any page that redirected to |
|
501 * it is bookmarked. For example, if I bookmark "mozilla.org" by manually |
|
502 * typing it in, and follow the bookmark, I will get redirected to |
|
503 * "www.mozilla.org". Logically, this new page is also bookmarked. This |
|
504 * function, if given "www.mozilla.org", will return the URI of the bookmark, |
|
505 * in this case "mozilla.org". |
|
506 * |
|
507 * If there is no bookmarked page found, it will return NULL. |
|
508 * |
|
509 * @note The function will only return bookmarks in the first 2 levels of |
|
510 * redirection (1 -> 2 -> aURI). |
|
511 */ |
|
512 nsIURI getBookmarkedURIFor(in nsIURI aURI); |
|
513 |
|
514 /** |
|
515 * Change the bookmarked URI for a bookmark. |
|
516 * This changes which "place" the bookmark points at, |
|
517 * which means all annotations, etc are carried along. |
|
518 */ |
|
519 void changeBookmarkURI(in long long aItemId, in nsIURI aNewURI); |
|
520 |
|
521 /** |
|
522 * Get the parent folder's id for an item. |
|
523 */ |
|
524 long long getFolderIdForItem(in long long aItemId); |
|
525 |
|
526 /** |
|
527 * Returns the list of bookmark ids that contain the given URI. |
|
528 */ |
|
529 void getBookmarkIdsForURI(in nsIURI aURI, [optional] out unsigned long count, |
|
530 [array, retval, size_is(count)] out long long bookmarks); |
|
531 |
|
532 /** |
|
533 * Associates the given keyword with the given bookmark. |
|
534 * |
|
535 * Use an empty keyword to clear the keyword associated with the URI. |
|
536 * In both of these cases, succeeds but does nothing if the URL/keyword is not found. |
|
537 */ |
|
538 void setKeywordForBookmark(in long long aItemId, in AString aKeyword); |
|
539 |
|
540 /** |
|
541 * Retrieves the keyword for the given URI. Will be void string |
|
542 * (null in JS) if no such keyword is found. |
|
543 */ |
|
544 AString getKeywordForURI(in nsIURI aURI); |
|
545 |
|
546 /** |
|
547 * Retrieves the keyword for the given bookmark. Will be void string |
|
548 * (null in JS) if no such keyword is found. |
|
549 */ |
|
550 AString getKeywordForBookmark(in long long aItemId); |
|
551 |
|
552 /** |
|
553 * Returns the URI associated with the given keyword. Empty if no such |
|
554 * keyword is found. |
|
555 */ |
|
556 nsIURI getURIForKeyword(in AString keyword); |
|
557 |
|
558 /** |
|
559 * Adds a bookmark observer. If ownsWeak is false, the bookmark service will |
|
560 * keep an owning reference to the observer. If ownsWeak is true, then |
|
561 * aObserver must implement nsISupportsWeakReference, and the bookmark |
|
562 * service will keep a weak reference to the observer. |
|
563 */ |
|
564 void addObserver(in nsINavBookmarkObserver observer, in boolean ownsWeak); |
|
565 |
|
566 /** |
|
567 * Removes a bookmark observer. |
|
568 */ |
|
569 void removeObserver(in nsINavBookmarkObserver observer); |
|
570 |
|
571 /** |
|
572 * Runs the passed callback inside of a database transaction. |
|
573 * Use this when a lot of things are about to change, for example |
|
574 * adding or deleting a large number of bookmark items. Calls can |
|
575 * be nested. Observers are notified when batches begin and end, via |
|
576 * nsINavBookmarkObserver.onBeginUpdateBatch/onEndUpdateBatch. |
|
577 * |
|
578 * @param aCallback |
|
579 * nsINavHistoryBatchCallback interface to call. |
|
580 * @param aUserData |
|
581 * Opaque parameter passed to nsINavBookmarksBatchCallback |
|
582 */ |
|
583 void runInBatchMode(in nsINavHistoryBatchCallback aCallback, |
|
584 in nsISupports aUserData); |
|
585 }; |