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
* Tells the priority for LOAD_CACHE is raised over LOAD_BYPASS_CACHE or
106
* LOAD_BYPASS_LOCAL_CACHE in case those flags are set at the same time.
107
*/
108
attribute boolean preferCacheLoadOverBypass;
109
110
/**
111
* Calling this method instructs the channel to serve the alternative data
112
* if that was previously saved in the cache, otherwise it will serve the
113
* real data.
114
* @param type
115
* a string identifying the alt-data format
116
* @param contentType
117
* the contentType for which the preference applies.
118
* an empty contentType means the preference applies for ANY contentType
119
* @param deliverAltData
120
* if false, also if alt-data is available, the channel will deliver
121
* the original data.
122
*
123
* The method may be called several times, with different type and contentType.
124
*
125
* Must be called before AsyncOpen.
126
*/
127
void preferAlternativeDataType(in ACString type, in ACString contentType,
128
in boolean deliverAltData);
129
130
/**
131
* Get the preferred alternative data type set by preferAlternativeDataType().
132
* The returned types stand for the desired data type instead of the type of the
133
* information retrieved from the network stack.
134
*/
135
[noscript, notxpcom, nostdcall]
136
ConstPreferredAlternativeDataTypeArray preferredAlternativeDataTypes();
137
138
/**
139
* Holds the type of the alternative data representation that the channel
140
* is returning.
141
* Is empty string if no alternative data representation was requested, or
142
* if the requested representation wasn't found in the cache.
143
* Can only be called during or after OnStartRequest.
144
*/
145
readonly attribute ACString alternativeDataType;
146
147
/**
148
* If preferAlternativeDataType() has been called passing deliverAltData
149
* equal to false, this method will expose the alt-data inputStream if
150
* aviable.
151
*/
152
void getAltDataInputStream(in ACString type,
153
in nsIInputStreamReceiver aReceiver);
154
155
/**
156
* Sometimes when the channel is delivering alt-data, we may want to somehow
157
* access the original content too. This method asynchronously opens the
158
* input stream and delivers it to the receiver.
159
*/
160
void getOriginalInputStream(in nsIInputStreamReceiver aReceiver);
161
162
/**
163
* Opens and returns an output stream that a consumer may use to save an
164
* alternate representation of the data.
165
* Must be called after the OnStopRequest that delivered the real data.
166
* The consumer may choose to replace the saved alt representation.
167
* Opening the output stream will fail if there are any open input streams
168
* reading the already saved alt representation. After successfully opening
169
* an output stream, if there is an error before the entire alt data can be
170
* written successfully, the client must signal failure by passing an error
171
* code to CloseWithStatus().
172
*
173
* @param type
174
* type of the alternative data representation
175
* @param predictedSize
176
* Predicted size of the data that will be written. It's used to decide
177
* whether the resulting entry would exceed size limit, in which case
178
* an error is thrown. If the size isn't known in advance, -1 should be
179
* passed.
180
*/
181
nsIAsyncOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
182
};