tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsICacheEntry.idl (12656B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "nsISupports.idl"
      6 
      7 interface nsIAsyncOutputStream;
      8 interface nsICacheEntryDoomCallback;
      9 interface nsICacheEntryMetaDataVisitor;
     10 interface nsIInputStream;
     11 interface nsILoadContextInfo;
     12 interface nsIOutputStream;
     13 interface nsITransportSecurityInfo;
     14 
     15 %{C++
     16 namespace mozilla::net {
     17 class DictionaryCacheEntry;
     18 }
     19 %}
     20 [ptr] native DictionaryCacheEntry(mozilla::net::DictionaryCacheEntry);
     21 
     22 [scriptable, uuid(607c2a2c-0a48-40b9-a956-8cf2bb9857cf)]
     23 interface nsICacheEntry : nsISupports
     24 {
     25  const unsigned long CONTENT_TYPE_UNKNOWN = 0;
     26  const unsigned long CONTENT_TYPE_OTHER = 1;
     27  const unsigned long CONTENT_TYPE_JAVASCRIPT = 2;
     28  const unsigned long CONTENT_TYPE_IMAGE = 3;
     29  const unsigned long CONTENT_TYPE_MEDIA = 4;
     30  const unsigned long CONTENT_TYPE_STYLESHEET = 5;
     31  const unsigned long CONTENT_TYPE_WASM = 6;
     32  const unsigned long CONTENT_TYPE_DICTIONARY = 7;
     33  /**
     34   * Content type that is used internally to check whether the value parsed
     35   * from disk is within allowed limits. Don't pass CONTENT_TYPE_LAST to
     36   * setContentType method.
     37   */
     38  const unsigned long CONTENT_TYPE_LAST = 8;
     39 
     40  /**
     41   * Placeholder for the initial value of expiration time.
     42   */
     43  const unsigned long NO_EXPIRATION_TIME = 0xFFFFFFFF;
     44 
     45  /**
     46   * Get the key identifying the cache entry.
     47   */
     48  readonly attribute ACString key;
     49 
     50  /**
     51   * The unique ID for every nsICacheEntry instance, which can be used to check
     52   * whether two pieces of information are from the same nsICacheEntry instance.
     53   */
     54  readonly attribute uint64_t cacheEntryId;
     55 
     56  /**
     57   * Whether the entry is memory/only or persisted to disk.
     58   * Note: private browsing entries are reported as persistent for consistency
     59   * while are not actually persisted to disk.
     60   */
     61  readonly attribute boolean persistent;
     62 
     63  /**
     64   * Get if the cache file is READY or REVALIDATING
     65   */
     66  readonly attribute boolean readyOrRevalidating;
     67 
     68  /**
     69   * Get the number of times the cache entry has been opened.
     70   */
     71  readonly attribute uint32_t  fetchCount;
     72 
     73  /**
     74   * Get the last time the cache entry was opened (in seconds since the Epoch).
     75   */
     76  readonly attribute uint32_t  lastFetched;
     77 
     78  /**
     79   * Get the last time the cache entry was modified (in seconds since the Epoch).
     80   */
     81  readonly attribute uint32_t  lastModified;
     82 
     83  /**
     84   * Get the expiration time of the cache entry (in seconds since the Epoch).
     85   */
     86  readonly attribute uint32_t  expirationTime;
     87 
     88  /**
     89   * Set the time at which the cache entry should be considered invalid (in
     90   * seconds since the Epoch).
     91   */
     92  void setExpirationTime(in uint32_t expirationTime);
     93 
     94  /**
     95   * Get the last network response times for onStartReqeust/onStopRequest (in ms).
     96   * @throws
     97   *    - NS_ERROR_NOT_AVAILABLE if onStartTime/onStopTime does not exist.
     98   */
     99  readonly attribute uint64_t  onStartTime;
    100  readonly attribute uint64_t  onStopTime;
    101 
    102  /**
    103   * Set the network response times for onStartReqeust/onStopRequest (in ms).
    104   */
    105  void setNetworkTimes(in uint64_t onStartTime, in uint64_t onStopTime);
    106 
    107  /**
    108   * Set content type. Available types are defined at the begining of this file.
    109   * The content type is used internally for cache partitioning and telemetry
    110   * purposes so there is no getter.
    111   */
    112  void setContentType(in uint8_t contentType);
    113 
    114  /**
    115   * This method is intended to override the per-spec cache validation
    116   * decisions for a duration specified in seconds. The current state can
    117   * be examined with isForcedValid (see below). This value is not persisted,
    118   * so it will not survive session restart. Cache entries that are forced valid
    119   * will not be evicted from the cache for the duration of forced validity.
    120   * This means that there is a potential problem if the number of forced valid
    121   * entries grows to take up more space than the cache size allows.
    122   *
    123   * NOTE: entries that have been forced valid will STILL be ignored by HTTP
    124   * channels if they have expired AND the resource in question requires
    125   * validation after expiring. This is to avoid using known-stale content.
    126   *
    127   * @param aSecondsToTheFuture
    128   *        the number of seconds the default cache validation behavior will be
    129   *        overridden before it returns to normal
    130   */
    131  void forceValidFor(in unsigned long aSecondsToTheFuture);
    132 
    133  /**
    134   * The state variable for whether this entry is currently forced valid.
    135   * Defaults to false for normal cache validation behavior, and will return
    136   * true if the number of seconds set by forceValidFor() has yet to be reached.
    137   */
    138  readonly attribute boolean isForcedValid;
    139 
    140  /**
    141   * This method gets called to mark the actual use of the forced-valid entry.
    142   * This is necessary for telemetry, so when the entry eventually gets
    143   * evicted we can report whether it was ever used or not.
    144   * If the entry was not forced-valid, then this operation has no effect.
    145   */
    146  void markForcedValidUse();
    147 
    148  /**
    149   * Open blocking input stream to cache data.  Use the stream transport
    150   * service to asynchronously read this stream on a background thread.
    151   * The returned stream MAY implement nsISeekableStream.
    152   *
    153   * @param offset
    154   *        read starting from this offset into the cached data.  an offset
    155   *        beyond the end of the stream has undefined consequences.
    156   *
    157   * @return non-blocking, buffered input stream.
    158   */
    159  nsIInputStream openInputStream(in long long offset);
    160 
    161  /**
    162   * Open non-blocking output stream to cache data.  The returned stream
    163   * MAY implement nsISeekableStream.
    164   *
    165   * If opening an output stream to existing cached data, the data will be
    166   * truncated to the specified offset.
    167   *
    168   * @param offset
    169   *        write starting from this offset into the cached data.  an offset
    170   *        beyond the end of the stream has undefined consequences.
    171   * @param predictedSize
    172   *        Predicted size of the data that will be written. It's used to decide
    173   *        whether the resulting entry would exceed size limit, in which case
    174   *        an error is thrown. If the size isn't known in advance, -1 should be
    175   *        passed.
    176   *
    177   * @return blocking, buffered output stream.
    178   */
    179  nsIOutputStream openOutputStream(in long long offset, in long long predictedSize);
    180 
    181  /**
    182   * Get/set security info on the cache entry for this descriptor.
    183   */
    184  attribute nsITransportSecurityInfo securityInfo;
    185 
    186  /**
    187   * Get the size of the cache entry data, as stored. This may differ
    188   * from the entry's dataSize, if the entry is compressed.
    189   */
    190  readonly attribute unsigned long storageDataSize;
    191 
    192  /**
    193   * Asynchronously doom an entry. Listener will be notified about the status
    194   * of the operation. Null may be passed if caller doesn't care about the
    195   * result.
    196   */
    197  void asyncDoom(in nsICacheEntryDoomCallback listener);
    198 
    199  /**
    200   * Methods for accessing meta data.  Meta data is a table of key/value
    201   * string pairs.  The strings do not have to conform to any particular
    202   * charset, but they must be null terminated.
    203   */
    204  string getMetaDataElement(in string key);
    205  void   setMetaDataElement(in string key, in string value);
    206 
    207  /**
    208   * Get if the entry is empty (new)
    209   */
    210  readonly attribute boolean isEmpty;
    211 
    212  /**
    213   * Obtain the list of metadata keys this entry keeps.
    214   *
    215   * NOTE: The callback is invoked under the CacheFile's lock.  It means
    216   * there should not be made any calls to the entry from the visitor and
    217   * if the values need to be processed somehow, it's better to cache them
    218   * and process outside the callback.
    219   */
    220  void visitMetaData(in nsICacheEntryMetaDataVisitor visitor);
    221 
    222  /**
    223   * Claims that all metadata on this entry are up-to-date and this entry
    224   * now can be delivered to other waiting consumers.
    225   *
    226   * We need such method since metadata must be delivered synchronously.
    227   */
    228  void metaDataReady();
    229 
    230  /**
    231   * Called by consumer upon 304/206 response from the server.  This marks
    232   * the entry content as positively revalidated.
    233   * Consumer uses this method after the consumer has returned ENTRY_NEEDS_REVALIDATION
    234   * result from onCacheEntryCheck and after successfull revalidation with the server.
    235   */
    236  void setValid();
    237 
    238  /**
    239   * Explicitly tell the cache backend this consumer is no longer going to modify
    240   * this cache entry data or metadata.  In case the consumer was responsible to
    241   * either of writing the cache entry or revalidating it, calling this method
    242   * reverts the state to initial (as never written) or as not-validated and
    243   * immediately notifies the next consumer in line waiting for this entry.
    244   * This is the way to prevent deadlocks when someone else than the responsible
    245   * channel references the cache entry being in a non-written or revalidating
    246   * state.
    247   */
    248  void dismiss();
    249 
    250  /**
    251   * Returns the size in kilobytes used to store the cache entry on disk.
    252   */
    253  readonly attribute uint32_t diskStorageSizeInKB;
    254 
    255  /**
    256   * Doom this entry and open a new, empty, entry for write.  Consumer has
    257   * to exchange the entry this method is called on for the newly created.
    258   * Used on 200 responses to conditional requests.
    259   *
    260   * @param aMemoryOnly
    261   *    - whether the entry is to be created as memory/only regardless how
    262   *      the entry being recreated persistence is set
    263   * @returns
    264   *    - an entry that can be used to write to
    265   * @throws
    266   *    - NS_ERROR_NOT_AVAILABLE when the entry cannot be from some reason
    267   *      recreated for write
    268   */
    269  nsICacheEntry recreate([optional] in boolean aMemoryOnly);
    270 
    271  /**
    272   * Returns the length of data this entry holds.
    273   * @throws
    274   *    NS_ERROR_IN_PROGRESS when the write is still in progress.
    275   */
    276  readonly attribute long long dataSize;
    277 
    278  /**
    279  * Returns the length of data this entry holds.
    280  * @throws
    281  *    - NS_ERROR_IN_PROGRESS when a write is still in progress (either real
    282                              content or alt data).
    283  *    - NS_ERROR_NOT_AVAILABLE if alt data does not exist.
    284  */
    285  readonly attribute long long altDataSize;
    286 
    287  /**
    288  * Returns the type of the saved alt data.
    289  * @throws
    290  *    - NS_ERROR_NOT_AVAILABLE if alt data does not exist.
    291  */
    292  readonly attribute ACString altDataType;
    293 
    294  /**
    295   * Opens and returns an output stream that a consumer may use to save an
    296   * alternate representation of the data.
    297   *
    298   * @param type
    299   *        type of the alternative data representation
    300   * @param predictedSize
    301   *        Predicted size of the data that will be written. It's used to decide
    302   *        whether the resulting entry would exceed size limit, in which case
    303   *        an error is thrown. If the size isn't known in advance, -1 should be
    304   *        passed.
    305   *
    306   * @throws
    307   *    - NS_ERROR_NOT_AVAILABLE if the real data hasn't been written.
    308   *    - NS_ERROR_IN_PROGRESS when the writing regular content or alt-data to
    309   *      the cache entry is still in progress.
    310   *
    311   * If there is alt-data already saved, it will be overwritten.
    312   */
    313  nsIAsyncOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
    314 
    315  /**
    316   * Opens and returns an input stream that can be used to read the alternative
    317   * representation previously saved in the cache.
    318   * If this call is made while writing alt-data is still in progress, it is
    319   * still possible to read content from the input stream as it's being written.
    320   * @throws
    321   *    - NS_ERROR_NOT_AVAILABLE if the alt-data representation doesn't exist at
    322   *      all or if alt-data of the given type doesn't exist.
    323   */
    324  nsIInputStream openAlternativeInputStream(in ACString type);
    325 
    326  /**
    327   * Get the nsILoadContextInfo of the cache entry
    328   */
    329  readonly attribute nsILoadContextInfo loadContextInfo;
    330 
    331  /**
    332   * This method gets called to indicate that this entry will be used
    333   * as a Dictionary in the future, so we know to calculate a hash for it.
    334   */
    335  [noscript] void SetDictionary(in DictionaryCacheEntry dict);
    336 
    337  /**
    338   * Set bypass flag to allow waiting listeners to continue even while entry is being written
    339   */
    340  void setBypassWriterLock(in boolean aBypass);
    341 };
    342 
    343 /**
    344 * Argument for nsICacheEntry.visitMetaData, provides access to all metadata
    345 * keys and values stored on the entry.
    346 */
    347 [scriptable, uuid(fea3e276-6ba5-4ceb-a581-807d1f43f6d0)]
    348 interface nsICacheEntryMetaDataVisitor : nsISupports
    349 {
    350  /**
    351   * Called over each key / value pair.
    352   */
    353  void onMetaDataElement(in string key, in string value);
    354 };