tor-browser

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

StartupCacheUtils.h (3287B)


      1 /* -*- Mode: C++; 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 #ifndef nsStartupCacheUtils_h_
      6 #define nsStartupCacheUtils_h_
      7 
      8 #include "nsString.h"
      9 #include "nsIStorageStream.h"
     10 #include "nsIObjectInputStream.h"
     11 #include "nsIObjectOutputStream.h"
     12 #include "mozilla/UniquePtrExtensions.h"
     13 
     14 class nsIURI;
     15 
     16 namespace mozilla {
     17 namespace scache {
     18 
     19 nsresult NewObjectInputStreamFromBuffer(const char* buffer, uint32_t len,
     20                                        nsIObjectInputStream** stream);
     21 
     22 // We can't retrieve the wrapped stream from the objectOutputStream later,
     23 // so we return it here. We give callers in debug builds the option
     24 // to wrap the outputstream in a debug stream, which will detect if
     25 // non-singleton objects are written out multiple times during a serialization.
     26 // This could cause them to be deserialized incorrectly (as multiple copies
     27 // instead of references).
     28 nsresult NewObjectOutputWrappedStorageStream(
     29    nsIObjectOutputStream** wrapperStream, nsIStorageStream** stream,
     30    bool wantDebugStream);
     31 
     32 // Creates a buffer for storing the stream into the cache. The buffer is
     33 // allocated with 'new []'.  After calling this function, the caller would
     34 // typically call StartupCache::PutBuffer with the returned buffer.
     35 nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream,
     36                                    UniqueFreePtr<char[]>* buffer,
     37                                    uint32_t* len);
     38 
     39 nsresult ResolveURI(nsIURI* in, nsIURI** out);
     40 
     41 // PathifyURI transforms uris into useful zip paths
     42 // to make it easier to manipulate startup cache entries
     43 // using standard zip tools.
     44 //
     45 // Transformations applied:
     46 //  * resource:// URIs are resolved to their corresponding file/jar URI to
     47 //    canonicalize resources URIs other than gre and app.
     48 //  * Paths under GRE or APP directory have their base path replaced with
     49 //    resource/gre or resource/app to avoid depending on install location.
     50 //  * jar:file:///path/to/file.jar!/sub/path urls are replaced with
     51 //    /path/to/file.jar/sub/path
     52 //
     53 // The result is concatenated with loaderType and stored into the string
     54 // passed in.
     55 //
     56 // For example, in the js loader (loaderType = "jsloader"):
     57 //  resource://gre/modules/XPCOMUtils.sys.mjs or
     58 //  file://$GRE_DIR/modules/XPCOMUtils.sys.mjs or
     59 //  jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.sys.mjs becomes
     60 //     jsloader/resource/gre/modules/XPCOMUtils.sys.mjs
     61 //  file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
     62 //     jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js
     63 //  jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
     64 //     jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
     65 nsresult PathifyURI(const char* loaderType, size_t loaderTypeLength, nsIURI* in,
     66                    nsACString& out);
     67 
     68 template <int N>
     69 nsresult PathifyURI(const char (&loaderType)[N], nsIURI* in, nsACString& out) {
     70  return PathifyURI(loaderType, N - 1, in, out);
     71 }
     72 
     73 }  // namespace scache
     74 }  // namespace mozilla
     75 
     76 #endif  // nsStartupCacheUtils_h_