Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsISupports.idl" |
michael@0 | 7 | |
michael@0 | 8 | interface nsIURI; |
michael@0 | 9 | interface nsIVariant; |
michael@0 | 10 | interface mozIAnnotatedResult; |
michael@0 | 11 | |
michael@0 | 12 | [scriptable, uuid(63fe98e0-6889-4c2c-ac9f-703e4bc25027)] |
michael@0 | 13 | interface nsIAnnotationObserver : nsISupports |
michael@0 | 14 | { |
michael@0 | 15 | /** |
michael@0 | 16 | * Called when an annotation value is set. It could be a new annotation, |
michael@0 | 17 | * or it could be a new value for an existing annotation. |
michael@0 | 18 | */ |
michael@0 | 19 | void onPageAnnotationSet(in nsIURI aPage, |
michael@0 | 20 | in AUTF8String aName); |
michael@0 | 21 | void onItemAnnotationSet(in long long aItemId, |
michael@0 | 22 | in AUTF8String aName); |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * Called when an annotation is deleted. If aName is empty, then ALL |
michael@0 | 26 | * annotations for the given URI have been deleted. This is not called when |
michael@0 | 27 | * annotations are expired (normally happens when the app exits). |
michael@0 | 28 | */ |
michael@0 | 29 | void onPageAnnotationRemoved(in nsIURI aURI, |
michael@0 | 30 | in AUTF8String aName); |
michael@0 | 31 | void onItemAnnotationRemoved(in long long aItemId, |
michael@0 | 32 | in AUTF8String aName); |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | [scriptable, uuid(D4CDAAB1-8EEC-47A8-B420-AD7CB333056A)] |
michael@0 | 36 | interface nsIAnnotationService : nsISupports |
michael@0 | 37 | { |
michael@0 | 38 | /** |
michael@0 | 39 | * Valid values for aExpiration, which sets the expiration policy for your |
michael@0 | 40 | * annotation. The times for the days, weeks and months policies are |
michael@0 | 41 | * measured since the last visit date of the page in question. These |
michael@0 | 42 | * will not expire so long as the user keeps visiting the page from time |
michael@0 | 43 | * to time. |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | // For temporary data that can be discarded when the user exits. |
michael@0 | 47 | // Removed at application exit. |
michael@0 | 48 | const unsigned short EXPIRE_SESSION = 0; |
michael@0 | 49 | |
michael@0 | 50 | // NOTE: 1 is skipped due to its temporary use as EXPIRE_NEVER in bug #319455. |
michael@0 | 51 | |
michael@0 | 52 | // For general page settings, things the user is interested in seeing |
michael@0 | 53 | // if they come back to this page some time in the near future. |
michael@0 | 54 | // Removed at 30 days. |
michael@0 | 55 | const unsigned short EXPIRE_WEEKS = 2; |
michael@0 | 56 | |
michael@0 | 57 | // Something that the user will be interested in seeing in their |
michael@0 | 58 | // history like favicons. If they haven't visited a page in a couple |
michael@0 | 59 | // of months, they probably aren't interested in many other annotations, |
michael@0 | 60 | // the positions of things, or other stuff you create, so put that in |
michael@0 | 61 | // the weeks policy. |
michael@0 | 62 | // Removed at 180 days. |
michael@0 | 63 | const unsigned short EXPIRE_MONTHS = 3; |
michael@0 | 64 | |
michael@0 | 65 | // For annotations that only live as long as the URI is in the database. |
michael@0 | 66 | // A page annotation will expire if the page has no visits |
michael@0 | 67 | // and is not bookmarked. |
michael@0 | 68 | // An item annotation will expire when the item is deleted. |
michael@0 | 69 | const unsigned short EXPIRE_NEVER = 4; |
michael@0 | 70 | |
michael@0 | 71 | // For annotations that only live as long as the URI has visits. |
michael@0 | 72 | // Valid only for page annotations. |
michael@0 | 73 | const unsigned short EXPIRE_WITH_HISTORY = 5; |
michael@0 | 74 | |
michael@0 | 75 | // For short-lived temporary data that you still want to outlast a session. |
michael@0 | 76 | // Removed at 7 days. |
michael@0 | 77 | const unsigned short EXPIRE_DAYS = 6; |
michael@0 | 78 | |
michael@0 | 79 | // type constants |
michael@0 | 80 | const unsigned short TYPE_INT32 = 1; |
michael@0 | 81 | const unsigned short TYPE_DOUBLE = 2; |
michael@0 | 82 | const unsigned short TYPE_STRING = 3; |
michael@0 | 83 | const unsigned short TYPE_INT64 = 5; |
michael@0 | 84 | |
michael@0 | 85 | /** |
michael@0 | 86 | * Sets an annotation, overwriting any previous annotation with the same |
michael@0 | 87 | * URL/name. IT IS YOUR JOB TO NAMESPACE YOUR ANNOTATION NAMES. |
michael@0 | 88 | * Use the form "namespace/value", so your name would be like |
michael@0 | 89 | * "bills_extension/page_state" or "history/thumbnail". |
michael@0 | 90 | * |
michael@0 | 91 | * Do not use characters that are not valid in URLs such as spaces, ":", |
michael@0 | 92 | * commas, or most other symbols. You should stick to ASCII letters and |
michael@0 | 93 | * numbers plus "_", "-", and "/". |
michael@0 | 94 | * |
michael@0 | 95 | * aExpiration is one of EXPIRE_* above. aFlags should be 0 for now, some |
michael@0 | 96 | * flags will be defined in the future. |
michael@0 | 97 | * |
michael@0 | 98 | * NOTE: ALL PAGE ANNOTATIONS WILL GET DELETED WHEN THE PAGE IS REMOVED FROM |
michael@0 | 99 | * HISTORY IF THE PAGE IS NOT BOOKMARKED. This means that if you create an |
michael@0 | 100 | * annotation on an unvisited URI, it will get deleted when the browser |
michael@0 | 101 | * shuts down. Otherwise, URIs can exist in history as annotations but the |
michael@0 | 102 | * user has no way of knowing it, potentially violating their privacy |
michael@0 | 103 | * expectations about actions such as "Clear history". |
michael@0 | 104 | * If there is an important annotation that the user or extension wants to |
michael@0 | 105 | * keep, you should add a bookmark for the page and use an EXPIRE_NEVER |
michael@0 | 106 | * annotation. This will ensure the annotation exists until the item is |
michael@0 | 107 | * removed by the user. |
michael@0 | 108 | * See EXPIRE_* constants above for further information. |
michael@0 | 109 | * |
michael@0 | 110 | * The annotation "favicon" is special. Favicons are stored in the favicon |
michael@0 | 111 | * service, but are special cased in the protocol handler so they look like |
michael@0 | 112 | * annotations. Do not set favicons using this service, it will not work. |
michael@0 | 113 | * |
michael@0 | 114 | * Only C++ consumers may use the type-specific methods. |
michael@0 | 115 | * |
michael@0 | 116 | * @throws NS_ERROR_ILLEGAL_VALUE if the page or the bookmark doesn't exist. |
michael@0 | 117 | */ |
michael@0 | 118 | void setPageAnnotation(in nsIURI aURI, |
michael@0 | 119 | in AUTF8String aName, |
michael@0 | 120 | in nsIVariant aValue, |
michael@0 | 121 | in long aFlags, |
michael@0 | 122 | in unsigned short aExpiration); |
michael@0 | 123 | void setItemAnnotation(in long long aItemId, |
michael@0 | 124 | in AUTF8String aName, |
michael@0 | 125 | in nsIVariant aValue, |
michael@0 | 126 | in long aFlags, |
michael@0 | 127 | in unsigned short aExpiration); |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * @throws NS_ERROR_ILLEGAL_VALUE if the page or the bookmark doesn't exist. |
michael@0 | 131 | */ |
michael@0 | 132 | [noscript] void setPageAnnotationString(in nsIURI aURI, |
michael@0 | 133 | in AUTF8String aName, |
michael@0 | 134 | in AString aValue, |
michael@0 | 135 | in long aFlags, |
michael@0 | 136 | in unsigned short aExpiration); |
michael@0 | 137 | [noscript] void setItemAnnotationString(in long long aItemId, |
michael@0 | 138 | in AUTF8String aName, |
michael@0 | 139 | in AString aValue, |
michael@0 | 140 | in long aFlags, |
michael@0 | 141 | in unsigned short aExpiration); |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Sets an annotation just like setAnnotationString, but takes an Int32 as |
michael@0 | 145 | * input. |
michael@0 | 146 | * |
michael@0 | 147 | * @throws NS_ERROR_ILLEGAL_VALUE if the page or the bookmark doesn't exist. |
michael@0 | 148 | */ |
michael@0 | 149 | [noscript] void setPageAnnotationInt32(in nsIURI aURI, |
michael@0 | 150 | in AUTF8String aName, |
michael@0 | 151 | in long aValue, |
michael@0 | 152 | in long aFlags, |
michael@0 | 153 | in unsigned short aExpiration); |
michael@0 | 154 | [noscript] void setItemAnnotationInt32(in long long aItemId, |
michael@0 | 155 | in AUTF8String aName, |
michael@0 | 156 | in long aValue, |
michael@0 | 157 | in long aFlags, |
michael@0 | 158 | in unsigned short aExpiration); |
michael@0 | 159 | |
michael@0 | 160 | /** |
michael@0 | 161 | * Sets an annotation just like setAnnotationString, but takes an Int64 as |
michael@0 | 162 | * input. |
michael@0 | 163 | * |
michael@0 | 164 | * @throws NS_ERROR_ILLEGAL_VALUE if the page or the bookmark doesn't exist. |
michael@0 | 165 | */ |
michael@0 | 166 | [noscript] void setPageAnnotationInt64(in nsIURI aURI, |
michael@0 | 167 | in AUTF8String aName, |
michael@0 | 168 | in long long aValue, |
michael@0 | 169 | in long aFlags, |
michael@0 | 170 | in unsigned short aExpiration); |
michael@0 | 171 | [noscript] void setItemAnnotationInt64(in long long aItemId, |
michael@0 | 172 | in AUTF8String aName, |
michael@0 | 173 | in long long aValue, |
michael@0 | 174 | in long aFlags, |
michael@0 | 175 | in unsigned short aExpiration); |
michael@0 | 176 | |
michael@0 | 177 | /** |
michael@0 | 178 | * Sets an annotation just like setAnnotationString, but takes a double as |
michael@0 | 179 | * input. |
michael@0 | 180 | * |
michael@0 | 181 | * @throws NS_ERROR_ILLEGAL_VALUE if the page or the bookmark doesn't exist. |
michael@0 | 182 | */ |
michael@0 | 183 | [noscript] void setPageAnnotationDouble(in nsIURI aURI, |
michael@0 | 184 | in AUTF8String aName, |
michael@0 | 185 | in double aValue, |
michael@0 | 186 | in long aFlags, |
michael@0 | 187 | in unsigned short aExpiration); |
michael@0 | 188 | [noscript] void setItemAnnotationDouble(in long long aItemId, |
michael@0 | 189 | in AUTF8String aName, |
michael@0 | 190 | in double aValue, |
michael@0 | 191 | in long aFlags, |
michael@0 | 192 | in unsigned short aExpiration); |
michael@0 | 193 | |
michael@0 | 194 | /** |
michael@0 | 195 | * Retrieves the value of a given annotation. Throws an error if the |
michael@0 | 196 | * annotation does not exist. C++ consumers may use the type-specific |
michael@0 | 197 | * methods. |
michael@0 | 198 | * |
michael@0 | 199 | * The type-specific methods throw if the given annotation is set in |
michael@0 | 200 | * a different type. |
michael@0 | 201 | */ |
michael@0 | 202 | nsIVariant getPageAnnotation(in nsIURI aURI, |
michael@0 | 203 | in AUTF8String aName); |
michael@0 | 204 | nsIVariant getItemAnnotation(in long long aItemId, |
michael@0 | 205 | in AUTF8String aName); |
michael@0 | 206 | |
michael@0 | 207 | /** |
michael@0 | 208 | * @see getPageAnnotation |
michael@0 | 209 | */ |
michael@0 | 210 | [noscript] AString getPageAnnotationString(in nsIURI aURI, |
michael@0 | 211 | in AUTF8String aName); |
michael@0 | 212 | [noscript] AString getItemAnnotationString(in long long aItemId, |
michael@0 | 213 | in AUTF8String aName); |
michael@0 | 214 | |
michael@0 | 215 | /** |
michael@0 | 216 | * @see getPageAnnotation |
michael@0 | 217 | */ |
michael@0 | 218 | [noscript] long getPageAnnotationInt32(in nsIURI aURI, |
michael@0 | 219 | in AUTF8String aName); |
michael@0 | 220 | [noscript] long getItemAnnotationInt32(in long long aItemId, |
michael@0 | 221 | in AUTF8String aName); |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * @see getPageAnnotation |
michael@0 | 225 | */ |
michael@0 | 226 | [noscript] long long getPageAnnotationInt64(in nsIURI aURI, |
michael@0 | 227 | in AUTF8String aName); |
michael@0 | 228 | [noscript] long long getItemAnnotationInt64(in long long aItemId, |
michael@0 | 229 | in AUTF8String aName); |
michael@0 | 230 | |
michael@0 | 231 | /** |
michael@0 | 232 | * @see getPageAnnotation |
michael@0 | 233 | */ |
michael@0 | 234 | [noscript] double getPageAnnotationDouble(in nsIURI aURI, |
michael@0 | 235 | in AUTF8String aName); |
michael@0 | 236 | [noscript] double getItemAnnotationDouble(in long long aItemId, |
michael@0 | 237 | in AUTF8String aName); |
michael@0 | 238 | |
michael@0 | 239 | /** |
michael@0 | 240 | * Retrieves info about an existing annotation. |
michael@0 | 241 | * |
michael@0 | 242 | * aType will be one of TYPE_* constansts above |
michael@0 | 243 | * |
michael@0 | 244 | * example JS: |
michael@0 | 245 | * var flags = {}, exp = {}, type = {}; |
michael@0 | 246 | * annotator.getAnnotationInfo(myURI, "foo", flags, exp, type); |
michael@0 | 247 | * // now you can use 'exp.value' and 'flags.value' |
michael@0 | 248 | */ |
michael@0 | 249 | void getPageAnnotationInfo(in nsIURI aURI, |
michael@0 | 250 | in AUTF8String aName, |
michael@0 | 251 | out int32_t aFlags, |
michael@0 | 252 | out unsigned short aExpiration, |
michael@0 | 253 | out unsigned short aType); |
michael@0 | 254 | void getItemAnnotationInfo(in long long aItemId, |
michael@0 | 255 | in AUTF8String aName, |
michael@0 | 256 | out long aFlags, |
michael@0 | 257 | out unsigned short aExpiration, |
michael@0 | 258 | out unsigned short aType); |
michael@0 | 259 | |
michael@0 | 260 | /** |
michael@0 | 261 | * Retrieves the type of an existing annotation |
michael@0 | 262 | * Use getAnnotationInfo if you need this along with the mime-type etc. |
michael@0 | 263 | * |
michael@0 | 264 | * @param aURI |
michael@0 | 265 | * the uri on which the annotation is set |
michael@0 | 266 | * @param aName |
michael@0 | 267 | * the annotation name |
michael@0 | 268 | * @return one of the TYPE_* constants above |
michael@0 | 269 | * @throws if the annotation is not set |
michael@0 | 270 | */ |
michael@0 | 271 | uint16_t getPageAnnotationType(in nsIURI aURI, |
michael@0 | 272 | in AUTF8String aName); |
michael@0 | 273 | uint16_t getItemAnnotationType(in long long aItemId, |
michael@0 | 274 | in AUTF8String aName); |
michael@0 | 275 | |
michael@0 | 276 | /** |
michael@0 | 277 | * Returns a list of all URIs having a given annotation. |
michael@0 | 278 | */ |
michael@0 | 279 | void getPagesWithAnnotation( |
michael@0 | 280 | in AUTF8String name, |
michael@0 | 281 | [optional] out unsigned long resultCount, |
michael@0 | 282 | [retval, array, size_is(resultCount)] out nsIURI results); |
michael@0 | 283 | void getItemsWithAnnotation( |
michael@0 | 284 | in AUTF8String name, |
michael@0 | 285 | [optional] out unsigned long resultCount, |
michael@0 | 286 | [retval, array, size_is(resultCount)] out long long results); |
michael@0 | 287 | |
michael@0 | 288 | /** |
michael@0 | 289 | * Returns a list of mozIAnnotation(s), having a given annotation name. |
michael@0 | 290 | * |
michael@0 | 291 | * @param name |
michael@0 | 292 | * The annotation to search for. |
michael@0 | 293 | * @return list of mozIAnnotation objects. |
michael@0 | 294 | */ |
michael@0 | 295 | void getAnnotationsWithName( |
michael@0 | 296 | in AUTF8String name, |
michael@0 | 297 | [optional] out unsigned long count, |
michael@0 | 298 | [retval, array, size_is(count)] out mozIAnnotatedResult results); |
michael@0 | 299 | |
michael@0 | 300 | /** |
michael@0 | 301 | * Get the names of all annotations for this URI. |
michael@0 | 302 | * |
michael@0 | 303 | * example JS: |
michael@0 | 304 | * var annotations = annotator.getPageAnnotations(myURI, {}); |
michael@0 | 305 | */ |
michael@0 | 306 | void getPageAnnotationNames( |
michael@0 | 307 | in nsIURI aURI, |
michael@0 | 308 | [optional] out unsigned long count, |
michael@0 | 309 | [retval, array, size_is(count)] out nsIVariant result); |
michael@0 | 310 | void getItemAnnotationNames( |
michael@0 | 311 | in long long aItemId, |
michael@0 | 312 | [optional] out unsigned long count, |
michael@0 | 313 | [retval, array, size_is(count)] out nsIVariant result); |
michael@0 | 314 | |
michael@0 | 315 | /** |
michael@0 | 316 | * Test for annotation existence. |
michael@0 | 317 | */ |
michael@0 | 318 | boolean pageHasAnnotation(in nsIURI aURI, |
michael@0 | 319 | in AUTF8String aName); |
michael@0 | 320 | boolean itemHasAnnotation(in long long aItemId, |
michael@0 | 321 | in AUTF8String aName); |
michael@0 | 322 | |
michael@0 | 323 | /** |
michael@0 | 324 | * Removes a specific annotation. Succeeds even if the annotation is |
michael@0 | 325 | * not found. |
michael@0 | 326 | */ |
michael@0 | 327 | void removePageAnnotation(in nsIURI aURI, |
michael@0 | 328 | in AUTF8String aName); |
michael@0 | 329 | void removeItemAnnotation(in long long aItemId, |
michael@0 | 330 | in AUTF8String aName); |
michael@0 | 331 | |
michael@0 | 332 | /** |
michael@0 | 333 | * Removes all annotations for the given page/item. |
michael@0 | 334 | * We may want some other similar functions to get annotations with given |
michael@0 | 335 | * flags (once we have flags defined). |
michael@0 | 336 | */ |
michael@0 | 337 | void removePageAnnotations(in nsIURI aURI); |
michael@0 | 338 | void removeItemAnnotations(in long long aItemId); |
michael@0 | 339 | |
michael@0 | 340 | /** |
michael@0 | 341 | * Copies all annotations from the source to the destination URI/item. If |
michael@0 | 342 | * the destination already has an annotation with the same name as one on |
michael@0 | 343 | * the source, it will be overwritten if aOverwriteDest is set. Otherwise, |
michael@0 | 344 | * the original annotation will be preferred. |
michael@0 | 345 | * |
michael@0 | 346 | * All the source annotations will stay as-is. If you don't want them |
michael@0 | 347 | * any more, use removePageAnnotations on that URI. |
michael@0 | 348 | */ |
michael@0 | 349 | void copyPageAnnotations(in nsIURI aSourceURI, |
michael@0 | 350 | in nsIURI aDestURI, |
michael@0 | 351 | in boolean aOverwriteDest); |
michael@0 | 352 | void copyItemAnnotations(in long long aSourceItemId, |
michael@0 | 353 | in long long aDestItemId, |
michael@0 | 354 | in boolean aOverwriteDest); |
michael@0 | 355 | |
michael@0 | 356 | /** |
michael@0 | 357 | * Adds an annotation observer. The annotation service will keep an owning |
michael@0 | 358 | * reference to the observer object. |
michael@0 | 359 | */ |
michael@0 | 360 | void addObserver(in nsIAnnotationObserver aObserver); |
michael@0 | 361 | |
michael@0 | 362 | |
michael@0 | 363 | /** |
michael@0 | 364 | * Removes an annotaton observer previously registered by addObserver. |
michael@0 | 365 | */ |
michael@0 | 366 | void removeObserver(in nsIAnnotationObserver aObserver); |
michael@0 | 367 | }; |
michael@0 | 368 | |
michael@0 | 369 | /** |
michael@0 | 370 | * Represents a place annotated with a given annotation. If a place has |
michael@0 | 371 | * multiple annotations, it can be represented by multiple |
michael@0 | 372 | * mozIAnnotatedResult(s). |
michael@0 | 373 | */ |
michael@0 | 374 | [scriptable, uuid(81fd0188-db6a-492e-80b6-f6414913b396)] |
michael@0 | 375 | interface mozIAnnotatedResult : nsISupports |
michael@0 | 376 | { |
michael@0 | 377 | /** |
michael@0 | 378 | * The globally unique identifier of the place with this annotation. |
michael@0 | 379 | * |
michael@0 | 380 | * @note if itemId is valid this is the guid of the bookmark, otherwise |
michael@0 | 381 | * of the page. |
michael@0 | 382 | */ |
michael@0 | 383 | readonly attribute AUTF8String guid; |
michael@0 | 384 | |
michael@0 | 385 | /** |
michael@0 | 386 | * The URI of the place with this annotation, if available, null otherwise. |
michael@0 | 387 | */ |
michael@0 | 388 | readonly attribute nsIURI uri; |
michael@0 | 389 | |
michael@0 | 390 | /** |
michael@0 | 391 | * The bookmark id of the place with this annotation, if available, |
michael@0 | 392 | * -1 otherwise. |
michael@0 | 393 | * |
michael@0 | 394 | * @note if itemId is -1, it doesn't mean the page is not bookmarked, just |
michael@0 | 395 | * that this annotation is relative to the page, not to the bookmark. |
michael@0 | 396 | */ |
michael@0 | 397 | readonly attribute long long itemId; |
michael@0 | 398 | |
michael@0 | 399 | /** |
michael@0 | 400 | * Name of the annotation. |
michael@0 | 401 | */ |
michael@0 | 402 | readonly attribute AUTF8String annotationName; |
michael@0 | 403 | |
michael@0 | 404 | /** |
michael@0 | 405 | * Value of the annotation. |
michael@0 | 406 | */ |
michael@0 | 407 | readonly attribute nsIVariant annotationValue; |
michael@0 | 408 | }; |