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