Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
6 #include "nsISupports.idl"
8 interface nsIOutputStream;
9 interface nsIInputStream;
11 %{C++
12 /**
13 * The signature for the reader function passed to WriteSegments. This
14 * is the "provider" of data that gets written into the stream's buffer.
15 *
16 * @param aOutStream stream being written to
17 * @param aClosure opaque parameter passed to WriteSegments
18 * @param aToSegment pointer to memory owned by the output stream
19 * @param aFromOffset amount already written (since WriteSegments was called)
20 * @param aCount length of toSegment
21 * @param aReadCount number of bytes written
22 *
23 * Implementers should return the following:
24 *
25 * @throws <any-error> if not interested in providing any data
26 *
27 * Errors are never passed to the caller of WriteSegments.
28 */
29 typedef NS_CALLBACK(nsReadSegmentFun)(nsIOutputStream *aOutStream,
30 void *aClosure,
31 char *aToSegment,
32 uint32_t aFromOffset,
33 uint32_t aCount,
34 uint32_t *aReadCount);
35 %}
37 native nsReadSegmentFun(nsReadSegmentFun);
39 /**
40 * nsIOutputStream
41 *
42 * An interface describing a writable stream of data. An output stream may be
43 * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
44 * output stream may suspend the calling thread in order to satisfy a call to
45 * Close, Flush, Write, WriteFrom, or WriteSegments. A non-blocking output
46 * stream, on the other hand, must not block the calling thread of execution.
47 *
48 * NOTE: blocking output streams are often written to on a background thread to
49 * avoid locking up the main application thread. For this reason, it is
50 * generally the case that a blocking output stream should be implemented using
51 * thread- safe AddRef and Release.
52 */
53 [scriptable, uuid(0d0acd2a-61b4-11d4-9877-00c04fa0cf4a)]
54 interface nsIOutputStream : nsISupports
55 {
56 /**
57 * Close the stream. Forces the output stream to flush any buffered data.
58 *
59 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
60 * the calling thread (non-blocking mode only)
61 */
62 void close();
64 /**
65 * Flush the stream.
66 *
67 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
68 * the calling thread (non-blocking mode only)
69 */
70 void flush();
72 /**
73 * Write data into the stream.
74 *
75 * @param aBuf the buffer containing the data to be written
76 * @param aCount the maximum number of bytes to be written
77 *
78 * @return number of bytes written (may be less than aCount)
79 *
80 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
81 * block the calling thread (non-blocking mode only)
82 * @throws <other-error> on failure
83 */
84 unsigned long write(in string aBuf, in unsigned long aCount);
86 /**
87 * Writes data into the stream from an input stream.
88 *
89 * @param aFromStream the stream containing the data to be written
90 * @param aCount the maximum number of bytes to be written
91 *
92 * @return number of bytes written (may be less than aCount)
93 *
94 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
95 * block the calling thread (non-blocking mode only)
96 * @throws <other-error> on failure
97 *
98 * NOTE: This method is defined by this interface in order to allow the
99 * output stream to efficiently copy the data from the input stream into
100 * its internal buffer (if any). If this method was provided as an external
101 * facility, a separate char* buffer would need to be used in order to call
102 * the output stream's other Write method.
103 */
104 unsigned long writeFrom(in nsIInputStream aFromStream,
105 in unsigned long aCount);
107 /**
108 * Low-level write method that has access to the stream's underlying buffer.
109 * The reader function may be called multiple times for segmented buffers.
110 * WriteSegments is expected to keep calling the reader until either there
111 * is nothing left to write or the reader returns an error. WriteSegments
112 * should not call the reader with zero bytes to provide.
113 *
114 * @param aReader the "provider" of the data to be written
115 * @param aClosure opaque parameter passed to reader
116 * @param aCount the maximum number of bytes to be written
117 *
118 * @return number of bytes written (may be less than aCount)
119 *
120 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
121 * block the calling thread (non-blocking mode only)
122 * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
123 * @throws <other-error> on failure
124 *
125 * NOTE: this function may be unimplemented if a stream has no underlying
126 * buffer (e.g., socket output stream).
127 */
128 [noscript] unsigned long writeSegments(in nsReadSegmentFun aReader,
129 in voidPtr aClosure,
130 in unsigned long aCount);
132 /**
133 * @return true if stream is non-blocking
134 *
135 * NOTE: writing to a blocking output stream will block the calling thread
136 * until all given data can be consumed by the stream.
137 *
138 * NOTE: a non-blocking output stream may implement nsIAsyncOutputStream to
139 * provide consumers with a way to wait for the stream to accept more data
140 * once its write method is unable to accept any data without blocking.
141 */
142 boolean isNonBlocking();
143 };