Source code

Revision control

Other Tools

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(4d00c221-2c4a-47ab-a617-abb324110492)]
17
interface nsINavBookmarkObserver : nsISupports
18
{
19
/*
20
* This observer should not be called for items that are tags.
21
*/
22
readonly attribute boolean skipTags;
23
24
/*
25
* This observer should not be called for descendants when the parent is removed.
26
* For example when revmoing a folder containing bookmarks.
27
*/
28
readonly attribute boolean skipDescendantsOnItemRemoval;
29
30
/**
31
* Notifies that a batch transaction has started.
32
* Other notifications will be sent during the batch, but the observer is
33
* guaranteed that onEndUpdateBatch() will be called at its completion.
34
* During a batch the observer should do its best to reduce the work done to
35
* handle notifications, since multiple changes are going to happen in a short
36
* timeframe.
37
*/
38
void onBeginUpdateBatch();
39
40
/**
41
* Notifies that a batch transaction has ended.
42
*/
43
void onEndUpdateBatch();
44
45
/**
46
* Notifies that an item was removed. Called after the actual remove took
47
* place.
48
* When an item is removed, all the items following it in the same folder
49
* will have their index shifted down, but no additional notifications will
50
* be sent.
51
*
52
* @param aItemId
53
* The id of the item that was removed.
54
* @param aParentId
55
* The id of the folder from which the item was removed.
56
* @param aIndex
57
* The bookmark's index in the folder.
58
* @param aItemType
59
* The type of the item to be removed (see TYPE_* constants below).
60
* @param aURI
61
* The URI of the added item if it was TYPE_BOOKMARK, null otherwise.
62
* @param aGuid
63
* The unique ID associated with the item.
64
* @param aParentGuid
65
* The unique ID associated with the item's parent.
66
* @param aSource
67
* A change source constant from nsINavBookmarksService::SOURCE_*,
68
* passed to the method that notifies the observer.
69
*/
70
void onItemRemoved(in long long aItemId,
71
in long long aParentId,
72
in long aIndex,
73
in unsigned short aItemType,
74
in nsIURI aURI,
75
in ACString aGuid,
76
in ACString aParentGuid,
77
in unsigned short aSource);
78
79
/**
80
* Notifies that an item's information has changed. This will be called
81
* whenever any attributes like "title" are changed.
82
*
83
* @param aItemId
84
* The id of the item that was changed.
85
* @param aProperty
86
* The property which changed.
87
* @param aIsAnnotationProperty
88
* Obsolete and unused.
89
* @param aNewValue
90
* For certain properties, this is set to the new value of the
91
* property (see the list below).
92
* @param aLastModified
93
* The updated last-modified value.
94
* @param aItemType
95
* The type of the item to be removed (see TYPE_* constants below).
96
* @param aParentId
97
* The id of the folder containing the item.
98
* @param aGuid
99
* The unique ID associated with the item.
100
* @param aParentGuid
101
* The unique ID associated with the item's parent.
102
* @param aOldValue
103
* For certain properties, this is set to the new value of the
104
* property (see the list below).
105
* @param aSource
106
* A change source constant from nsINavBookmarksService::SOURCE_*,
107
* passed to the method that notifies the observer.
108
*
109
* @note List of values that may be associated with properties:
110
* aProperty | aNewValue
111
* =====================================================================
112
* guid | The new bookmark guid.
113
* cleartime | Empty string (all visits to this item were removed).
114
* title | The new title.
115
* favicon | The "moz-anno" URL of the new favicon.
116
* uri | new URL.
117
* tags | Empty string (tags for this item changed)
118
* dateAdded | PRTime (as string) when the item was first added.
119
* lastModified | PRTime (as string) when the item was last modified.
120
*
121
* aProperty | aOldValue
122
* =====================================================================
123
* guid | The old bookmark guid.
124
* cleartime | Empty string (currently unused).
125
* title | Empty string (currently unused).
126
* favicon | Empty string (currently unused).
127
* uri | old URL.
128
* tags | Empty string (currently unused).
129
* dateAdded | Empty string (currently unused).
130
* lastModified | Empty string (currently unused).
131
*/
132
void onItemChanged(in long long aItemId,
133
in ACString aProperty,
134
in boolean aIsAnnotationProperty,
135
in AUTF8String aNewValue,
136
in PRTime aLastModified,
137
in unsigned short aItemType,
138
in long long aParentId,
139
in ACString aGuid,
140
in ACString aParentGuid,
141
in AUTF8String aOldValue,
142
in unsigned short aSource);
143
144
/**
145
* Notifies that the item was visited. Can be invoked only for TYPE_BOOKMARK
146
* items.
147
*
148
* @param aItemId
149
* The id of the bookmark that was visited.
150
* @param aVisitId
151
* The id of the visit.
152
* @param aTime
153
* The time of the visit.
154
* @param aTransitionType
155
* The transition for the visit. See nsINavHistoryService::TRANSITION_*
156
* constants for a list of possible values.
157
* @param aURI
158
* The nsIURI for this bookmark.
159
* @param aParentId
160
* The id of the folder containing the item.
161
* @param aGuid
162
* The unique ID associated with the item.
163
* @param aParentGuid
164
* The unique ID associated with the item's parent.
165
*
166
* @see onItemChanged with property = "cleartime" for when all visits to an
167
* item are removed.
168
*
169
* @note The reported time is the time of the visit that was added, which may
170
* be well in the past since the visit time can be specified. This
171
* means that the visit the observer is told about may not be the most
172
* recent visit for that page.
173
*/
174
void onItemVisited(in long long aItemId,
175
in long long aVisitId,
176
in PRTime aTime,
177
in unsigned long aTransitionType,
178
in nsIURI aURI,
179
in long long aParentId,
180
in ACString aGuid,
181
in ACString aParentGuid);
182
183
/**
184
* Notifies that an item has been moved.
185
*
186
* @param aItemId
187
* The id of the item that was moved.
188
* @param aOldParentId
189
* The id of the old parent.
190
* @param aOldIndex
191
* The old index inside the old parent.
192
* @param aNewParentId
193
* The id of the new parent.
194
* @param aNewIndex
195
* The index inside the new parent.
196
* @param aItemType
197
* The type of the item to be removed (see TYPE_* constants below).
198
* @param aGuid
199
* The unique ID associated with the item.
200
* @param aOldParentGuid
201
* The unique ID associated with the old item's parent.
202
* @param aNewParentGuid
203
* The unique ID associated with the new item's parent.
204
* @param aSource
205
* A change source constant from nsINavBookmarksService::SOURCE_*,
206
* passed to the method that notifies the observer.
207
* @param aURI
208
* The URI for this bookmark.
209
*/
210
void onItemMoved(in long long aItemId,
211
in long long aOldParentId,
212
in long aOldIndex,
213
in long long aNewParentId,
214
in long aNewIndex,
215
in unsigned short aItemType,
216
in ACString aGuid,
217
in ACString aOldParentGuid,
218
in ACString aNewParentGuid,
219
in unsigned short aSource,
220
in AUTF8String aURI);
221
};
222
223
/**
224
* The BookmarksService interface provides methods for managing bookmarked
225
* history items. Bookmarks consist of a set of user-customizable
226
* folders. A URI in history can be contained in one or more such folders.
227
*/
228
229
[scriptable, uuid(24533891-afa6-4663-b72d-3143d03f1b04)]
230
interface nsINavBookmarksService : nsISupports
231
{
232
/**
233
* The item ID of the Places root.
234
*/
235
readonly attribute long long placesRoot;
236
237
/**
238
* The item ID of the bookmarks menu folder.
239
*/
240
readonly attribute long long bookmarksMenuFolder;
241
242
/**
243
* The item ID of the top-level folder that contain the tag "folders".
244
*/
245
readonly attribute long long tagsFolder;
246
247
/**
248
* The item ID of the personal toolbar folder.
249
*/
250
readonly attribute long long toolbarFolder;
251
252
/**
253
* The total number of Sync changes (inserts, updates, deletes, merges, and
254
* uploads) recorded since Places startup for all bookmarks.
255
*
256
* Note that this is *not* the number of bookmark syncs. It's a monotonically
257
* increasing counter incremented for every change that affects a bookmark's
258
* `syncChangeCounter`.
259
*
260
* The counter can be used to avoid keeping an exclusive transaction open for
261
* time-consuming work. One way to do that is to store the current value of
262
* the counter, do the work, start a transaction, check the current value
263
* again, and compare it to the stored value to determine if the database
264
* changed during the work.
265
*
266
* The bookmarks mirror does this to check for changes between building and
267
* applying a merged tree. This avoids blocking the main Places connection
268
* during the merge, and ensures that the new tree still applies cleanly.
269
*/
270
readonly attribute long long totalSyncChanges;
271
272
/**
273
* This value should be used for APIs that allow passing in an index
274
* where an index is not known, or not required to be specified.
275
* e.g.: When appending an item to a folder.
276
*/
277
const short DEFAULT_INDEX = -1;
278
279
const unsigned short TYPE_BOOKMARK = 1;
280
const unsigned short TYPE_FOLDER = 2;
281
const unsigned short TYPE_SEPARATOR = 3;
282
// Dynamic containers are deprecated and unsupported.
283
// This const exists just to avoid reusing the value.
284
const unsigned short TYPE_DYNAMIC_CONTAINER = 4;
285
286
// Change source constants. These are used to distinguish changes made by
287
// Sync and bookmarks import from other Places consumers, though they can
288
// be extended to support other callers. Sources are passed as optional
289
// parameters to methods used by Sync, and forwarded to observers.
290
const unsigned short SOURCE_DEFAULT = 0;
291
const unsigned short SOURCE_SYNC = 1;
292
const unsigned short SOURCE_IMPORT = 2;
293
const unsigned short SOURCE_SYNC_REPARENT_REMOVED_FOLDER_CHILDREN = 4;
294
const unsigned short SOURCE_RESTORE = 5;
295
const unsigned short SOURCE_RESTORE_ON_STARTUP = 6;
296
297
/**
298
* Sync status flags, stored in Places for each item. These affect conflict
299
* resolution, when an item is changed both locally and remotely; deduping,
300
* when a local item matches a remote item with similar contents and different
301
* GUIDs; and whether we write a tombstone when an item is deleted locally.
302
*
303
* Status | Description | Conflict | Can | Needs
304
* | | resolution | dedupe? | tombstone?
305
* -----------------------------------------------------------------------
306
* UNKNOWN | Automatically restored | Prefer | No | No
307
* | on startup to recover | deletion | |
308
* | from database corruption, | | |
309
* | or sync ID change on | | |
310
* | server. | | |
311
* -----------------------------------------------------------------------
312
* NEW | Item not uploaded to | Prefer | Yes | No
313
* | server yet, or Sync | newer | |
314
* | disconnected. | | |
315
* -----------------------------------------------------------------------
316
* NORMAL | Item uploaded to server. | Prefer | No | Yes
317
* | | newer | |
318
*/
319
const unsigned short SYNC_STATUS_UNKNOWN = 0;
320
const unsigned short SYNC_STATUS_NEW = 1;
321
const unsigned short SYNC_STATUS_NORMAL = 2;
322
323
/**
324
* Inserts a child bookmark into the given folder.
325
*
326
* @param aParentId
327
* The id of the parent folder
328
* @param aURI
329
* The URI to insert
330
* @param aIndex
331
* The index to insert at, or DEFAULT_INDEX to append
332
* @param aTitle
333
* The title for the new bookmark
334
* @param [optional] aGuid
335
* The GUID to be set for the new item. If not set, a new GUID is
336
* generated. Unless you've a very sound reason, such as an undo
337
* manager implementation, do not pass this argument.
338
* @param [optional] aSource
339
* The change source. This is forwarded to all bookmark observers,
340
* allowing them to distinguish between insertions from different
341
* callers. Defaults to SOURCE_DEFAULT if omitted.
342
* @return The ID of the newly-created bookmark.
343
*
344
* @note aTitle will be truncated to TITLE_LENGTH_MAX and
345
* aURI will be truncated to URI_LENGTH_MAX.
346
* @throws if aGuid is malformed.
347
*/
348
[can_run_script]
349
long long insertBookmark(in long long aParentId, in nsIURI aURI,
350
in long aIndex, in AUTF8String aTitle,
351
[optional] in ACString aGuid,
352
[optional] in unsigned short aSource);
353
354
/**
355
* Removes a child item. Used to delete a bookmark or separator.
356
* @param aItemId
357
* The child item to remove
358
* @param [optional] aSource
359
* The change source, forwarded to all bookmark observers. Defaults
360
* to SOURCE_DEFAULT.
361
*/
362
void removeItem(in long long aItemId, [optional] in unsigned short aSource);
363
364
/**
365
* Creates a new child folder and inserts it under the given parent.
366
* @param aParentFolder
367
* The id of the parent folder
368
* @param aName
369
* The name of the new folder
370
* @param aIndex
371
* The index to insert at, or DEFAULT_INDEX to append
372
* @param [optional] aGuid
373
* The GUID to be set for the new item. If not set, a new GUID is
374
* generated. Unless you've a very sound reason, such as an undo
375
* manager implementation, do not pass this argument.
376
* @param [optional] aSource
377
* The change source, forwarded to all bookmark observers. Defaults
378
* to SOURCE_DEFAULT.
379
* @return The ID of the newly-inserted folder.
380
* @throws if aGuid is malformed.
381
*/
382
[can_run_script]
383
long long createFolder(in long long aParentFolder, in AUTF8String name,
384
in long index,
385
[optional] in ACString aGuid,
386
[optional] in unsigned short aSource);
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
* @param [optional] aSource
395
* The change source, forwarded to all bookmark observers. Defaults
396
* to SOURCE_DEFAULT.
397
*
398
* @note aTitle will be truncated to TITLE_LENGTH_MAX.
399
*/
400
void setItemTitle(in long long aItemId, in AUTF8String aTitle,
401
[optional] in unsigned short aSource);
402
403
/**
404
* Get the title for an item.
405
*
406
* If no item title is available it will return a void string (null in JS).
407
*
408
* @param aItemId
409
* The id of the item whose title should be retrieved
410
* @return The title of the item.
411
*/
412
AUTF8String getItemTitle(in long long aItemId);
413
414
/**
415
* Set the last modified time for an item.
416
*
417
* @param aItemId
418
* the id of the item whose last modified time should be updated.
419
* @param aLastModified
420
* the new last modified value in microseconds. Note that it is
421
* rounded down to milliseconds precision.
422
* @param [optional] aSource
423
* The change source, forwarded to all bookmark observers. Defaults
424
* to SOURCE_DEFAULT.
425
*
426
* @note This is the only method that will send an itemChanged notification
427
* for the property. lastModified will still be updated in
428
* any other method that changes an item property, but we will send
429
* the corresponding itemChanged notification instead.
430
*/
431
void setItemLastModified(in long long aItemId,
432
in PRTime aLastModified,
433
[optional] in unsigned short aSource);
434
435
/**
436
* Get the parent folder's id for an item.
437
*/
438
long long getFolderIdForItem(in long long aItemId);
439
440
/**
441
* Adds a bookmark observer. If ownsWeak is false, the bookmark service will
442
* keep an owning reference to the observer. If ownsWeak is true, then
443
* aObserver must implement nsISupportsWeakReference, and the bookmark
444
* service will keep a weak reference to the observer.
445
*/
446
void addObserver(in nsINavBookmarkObserver observer,
447
[optional] in boolean ownsWeak);
448
449
/**
450
* Removes a bookmark observer.
451
*/
452
void removeObserver(in nsINavBookmarkObserver observer);
453
454
/**
455
* Gets an array of registered nsINavBookmarkObserver objects.
456
*/
457
Array<nsINavBookmarkObserver> getObservers();
458
};