Source code

Revision control

Other Tools

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 nsIInputStream;
9
10
%{C++
11
namespace mozilla {
12
namespace net {
13
class PreferredAlternativeDataTypeParams;
14
}
15
} // namespace mozilla
16
%}
17
18
[ref] native ConstPreferredAlternativeDataTypeArray(const nsTArray<mozilla::net::PreferredAlternativeDataTypeParams>);
19
20
[scriptable, uuid(1fb8ccf2-5fa5-45ec-bc57-8c8022a5d0d3)]
21
interface nsIInputStreamReceiver : nsISupports
22
{
23
void onInputStreamReady(in nsIInputStream aStream);
24
};
25
26
[scriptable, builtinclass, uuid(72c34415-c6eb-48af-851f-772fa9ee5972)]
27
interface nsICacheInfoChannel : nsISupports
28
{
29
/**
30
* Get the number of times the cache entry has been opened. This attribute is
31
* equivalent to nsICachingChannel.cacheToken.fetchCount.
32
*
33
* @throws NS_ERROR_NOT_AVAILABLE if the cache entry or the alternate data
34
* cache entry cannot be read.
35
*/
36
readonly attribute int32_t cacheTokenFetchCount;
37
38
/**
39
* Get expiration time from cache token. This attribute is equivalent to
40
* nsICachingChannel.cacheToken.expirationTime.
41
*/
42
readonly attribute uint32_t cacheTokenExpirationTime;
43
44
/**
45
* Set/get charset of cache entry. Accessing this attribute is equivalent to
46
* calling nsICachingChannel.cacheToken.getMetaDataElement("charset") and
47
* nsICachingChannel.cacheToken.setMetaDataElement("charset").
48
*/
49
attribute ACString cacheTokenCachedCharset;
50
51
/**
52
* TRUE if this channel's data is being loaded from the cache. This value
53
* is undefined before the channel fires its OnStartRequest notification
54
* and after the channel fires its OnStopRequest notification.
55
*/
56
boolean isFromCache();
57
58
/**
59
* Returns true if the channel raced the cache and network requests.
60
* In order to determine if the response is coming from the cache or the
61
* network, the consumer can check isFromCache().
62
* The method can only be called after the channel fires its OnStartRequest
63
* notification.
64
*/
65
boolean isRacing();
66
67
/**
68
* The unique ID of the corresponding nsICacheEntry from which the response is
69
* retrieved. By comparing the returned value, we can judge whether the data
70
* of two distinct nsICacheInfoChannels is from the same nsICacheEntry. This
71
* scenario could be useful when verifying whether the alternative data from
72
* one nsICacheInfochannel matches the main data from another one.
73
*
74
* Note: NS_ERROR_NOT_AVAILABLE is thrown when a nsICacheInfoChannel has no
75
* valid corresponding nsICacheEntry.
76
*/
77
uint64_t getCacheEntryId();
78
79
/**
80
* Set/get the cache key. This integer uniquely identifies the data in
81
* the cache for this channel.
82
*
83
* A cache key retrieved from a particular instance of nsICacheInfoChannel
84
* could be set on another instance of nsICacheInfoChannel provided the
85
* underlying implementations are compatible and provided the new
86
* channel instance was created with the same URI. The implementation of
87
* nsICacheInfoChannel would be expected to use the cache entry identified
88
* by the cache token. Depending on the value of nsIRequest::loadFlags,
89
* the cache entry may be validated, overwritten, or simply read.
90
*
91
* The cache key may be 0 indicating that the URI of the channel is
92
* sufficient to locate the same cache entry. Setting a 0 cache key
93
* is likewise valid.
94
*/
95
attribute unsigned long cacheKey;
96
97
/**
98
* Tells the channel to behave as if the LOAD_FROM_CACHE flag has been set,
99
* but without affecting the loads for the entire loadGroup in case of this
100
* channel being the default load group's channel.
101
*/
102
attribute boolean allowStaleCacheContent;
103
104
/**
105
* Calling this method instructs the channel to serve the alternative data
106
* if that was previously saved in the cache, otherwise it will serve the
107
* real data.
108
* @param type
109
* a string identifying the alt-data format
110
* @param contentType
111
* the contentType for which the preference applies.
112
* an empty contentType means the preference applies for ANY contentType
113
* @param deliverAltData
114
* if false, also if alt-data is available, the channel will deliver
115
* the original data.
116
*
117
* The method may be called several times, with different type and contentType.
118
*
119
* Must be called before AsyncOpen.
120
*/
121
void preferAlternativeDataType(in ACString type, in ACString contentType,
122
in boolean deliverAltData);
123
124
/**
125
* Get the preferred alternative data type set by preferAlternativeDataType().
126
* The returned types stand for the desired data type instead of the type of the
127
* information retrieved from the network stack.
128
*/
129
[noscript, notxpcom, nostdcall]
130
ConstPreferredAlternativeDataTypeArray preferredAlternativeDataTypes();
131
132
/**
133
* Holds the type of the alternative data representation that the channel
134
* is returning.
135
* Is empty string if no alternative data representation was requested, or
136
* if the requested representation wasn't found in the cache.
137
* Can only be called during or after OnStartRequest.
138
*/
139
readonly attribute ACString alternativeDataType;
140
141
/**
142
* If preferAlternativeDataType() has been called passing deliverAltData
143
* equal to false, this method will expose the alt-data inputStream if
144
* aviable.
145
*/
146
void getAltDataInputStream(in ACString type,
147
in nsIInputStreamReceiver aReceiver);
148
149
/**
150
* Sometimes when the channel is delivering alt-data, we may want to somehow
151
* access the original content too. This method asynchronously opens the
152
* input stream and delivers it to the receiver.
153
*/
154
void getOriginalInputStream(in nsIInputStreamReceiver aReceiver);
155
156
/**
157
* Opens and returns an output stream that a consumer may use to save an
158
* alternate representation of the data.
159
* Must be called after the OnStopRequest that delivered the real data.
160
* The consumer may choose to replace the saved alt representation.
161
* Opening the output stream will fail if there are any open input streams
162
* reading the already saved alt representation. After successfully opening
163
* an output stream, if there is an error before the entire alt data can be
164
* written successfully, the client must signal failure by passing an error
165
* code to CloseWithStatus().
166
*
167
* @param type
168
* type of the alternative data representation
169
* @param predictedSize
170
* Predicted size of the data that will be written. It's used to decide
171
* whether the resulting entry would exceed size limit, in which case
172
* an error is thrown. If the size isn't known in advance, -1 should be
173
* passed.
174
*/
175
nsIAsyncOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
176
};