1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//
// DO NOT EDIT.  THIS FILE IS GENERATED FROM ../../../dist/idl/nsIIncrementalDownload.idl
//


/// `interface nsIIncrementalDownload : nsIRequest`
///

/// ```text
/// /**
///  * An incremental download object attempts to fetch a file piecemeal over time
///  * in an effort to minimize network bandwidth usage.
///  *
///  * Canceling a background download does not cause the file on disk to be
///  * deleted.
///  */
/// ```
///

// The actual type definition for the interface. This struct has methods
// declared on it which will call through its vtable. You never want to pass
// this type around by value, always pass it behind a reference.

#[repr(C)]
pub struct nsIIncrementalDownload {
    vtable: *const nsIIncrementalDownloadVTable,

    /// This field is a phantomdata to ensure that the VTable type and any
    /// struct containing it is not safe to send across threads, as XPCOM is
    /// generally not threadsafe.
    ///
    /// XPCOM interfaces in general are not safe to send across threads.
    __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>,
}

// Implementing XpCom for an interface exposes its IID, which allows for easy
// use of the `.query_interface<T>` helper method. This also defines that
// method for nsIIncrementalDownload.
unsafe impl XpCom for nsIIncrementalDownload {
    const IID: nsIID = nsID(0x6687823f, 0x56c4, 0x461d,
        [0x93, 0xa1, 0x7f, 0x6c, 0xb7, 0xdf, 0xbf, 0xba]);
}

// We need to implement the RefCounted trait so we can be used with `RefPtr`.
// This trait teaches `RefPtr` how to manage our memory.
unsafe impl RefCounted for nsIIncrementalDownload {
    #[inline]
    unsafe fn addref(&self) {
        self.AddRef();
    }
    #[inline]
    unsafe fn release(&self) {
        self.Release();
    }
}

// This trait is implemented on all types which can be coerced to from nsIIncrementalDownload.
// It is used in the implementation of `fn coerce<T>`. We hide it from the
// documentation, because it clutters it up a lot.
#[doc(hidden)]
pub trait nsIIncrementalDownloadCoerce {
    /// Cheaply cast a value of this type from a `nsIIncrementalDownload`.
    fn coerce_from(v: &nsIIncrementalDownload) -> &Self;
}

// The trivial implementation: We can obviously coerce ourselves to ourselves.
impl nsIIncrementalDownloadCoerce for nsIIncrementalDownload {
    #[inline]
    fn coerce_from(v: &nsIIncrementalDownload) -> &Self {
        v
    }
}

impl nsIIncrementalDownload {
    /// Cast this `nsIIncrementalDownload` to one of its base interfaces.
    #[inline]
    pub fn coerce<T: nsIIncrementalDownloadCoerce>(&self) -> &T {
        T::coerce_from(self)
    }
}

// Every interface struct type implements `Deref` to its base interface. This
// causes methods on the base interfaces to be directly avaliable on the
// object. For example, you can call `.AddRef` or `.QueryInterface` directly
// on any interface which inherits from `nsISupports`.
impl ::std::ops::Deref for nsIIncrementalDownload {
    type Target = nsIRequest;
    #[inline]
    fn deref(&self) -> &nsIRequest {
        unsafe {
            ::std::mem::transmute(self)
        }
    }
}

// Ensure we can use .coerce() to cast to our base types as well. Any type which
// our base interface can coerce from should be coercable from us as well.
impl<T: nsIRequestCoerce> nsIIncrementalDownloadCoerce for T {
    #[inline]
    fn coerce_from(v: &nsIIncrementalDownload) -> &Self {
        T::coerce_from(v)
    }
}

// This struct represents the interface's VTable. A pointer to a statically
// allocated version of this struct is at the beginning of every nsIIncrementalDownload
// object. It contains one pointer field for each method in the interface. In
// the case where we can't generate a binding for a method, we include a void
// pointer.
#[doc(hidden)]
#[repr(C)]
pub struct nsIIncrementalDownloadVTable {
    /// We need to include the members from the base interface's vtable at the start
    /// of the VTable definition.
    pub __base: nsIRequestVTable,

    /* void init (in nsIURI uri, in nsIFile destination, in long chunkSize, in long intervalInSeconds); */
    pub Init: unsafe extern "system" fn (this: *const nsIIncrementalDownload, uri: *const nsIURI, destination: *const nsIFile, chunkSize: libc::int32_t, intervalInSeconds: libc::int32_t) -> nsresult,

    /* readonly attribute nsIURI URI; */
    pub GetURI: unsafe extern "system" fn (this: *const nsIIncrementalDownload, aURI: *mut *const nsIURI) -> nsresult,

    /* readonly attribute nsIURI finalURI; */
    pub GetFinalURI: unsafe extern "system" fn (this: *const nsIIncrementalDownload, aFinalURI: *mut *const nsIURI) -> nsresult,

    /* readonly attribute nsIFile destination; */
    pub GetDestination: unsafe extern "system" fn (this: *const nsIIncrementalDownload, aDestination: *mut *const nsIFile) -> nsresult,

    /* readonly attribute long long totalSize; */
    pub GetTotalSize: unsafe extern "system" fn (this: *const nsIIncrementalDownload, aTotalSize: *mut libc::int64_t) -> nsresult,

    /* readonly attribute long long currentSize; */
    pub GetCurrentSize: unsafe extern "system" fn (this: *const nsIIncrementalDownload, aCurrentSize: *mut libc::int64_t) -> nsresult,

    /* void start (in nsIRequestObserver observer, in nsISupports ctxt); */
    pub Start: unsafe extern "system" fn (this: *const nsIIncrementalDownload, observer: *const nsIRequestObserver, ctxt: *const nsISupports) -> nsresult,
}


// The implementations of the function wrappers which are exposed to rust code.
// Call these methods rather than manually calling through the VTable struct.
impl nsIIncrementalDownload {

    /// ```text
    /// /**
    ///    * Initialize the incremental download object.  If the destination file
    ///    * already exists, then only the remaining portion of the file will be
    ///    * fetched.
    ///    *
    ///    * NOTE: The downloader will create the destination file if it does not
    ///    * already exist.  It will create the file with the permissions 0600 if
    ///    * needed.  To affect the permissions of the file, consumers of this
    ///    * interface may create an empty file at the specified destination prior to
    ///    * starting the incremental download.
    ///    *
    ///    * NOTE: Since this class may create a temporary file at the specified
    ///    * destination, it is advisable for the consumer of this interface to specify
    ///    * a file name for the destination that would not tempt the user into
    ///    * double-clicking it.  For example, it might be wise to append a file
    ///    * extension like ".part" to the end of the destination to protect users from
    ///    * accidentally running "blah.exe" before it is a complete file.
    ///    *
    ///    * @param uri
    ///    *        The URI to fetch.
    ///    * @param destination
    ///    *        The location where the file is to be stored.
    ///    * @param chunkSize
    ///    *        The size of the chunks to fetch.  A non-positive value results in
    ///    *        the default chunk size being used.
    ///    * @param intervalInSeconds
    ///    *        The amount of time to wait between fetching chunks.  Pass a
    ///    *        negative to use the default interval, or 0 to fetch the remaining
    ///    *        part of the file in one chunk.
    ///    */
    /// ```
    ///

    /// `void init (in nsIURI uri, in nsIFile destination, in long chunkSize, in long intervalInSeconds);`
    #[inline]
    pub unsafe fn Init(&self, uri: *const nsIURI, destination: *const nsIFile, chunkSize: libc::int32_t, intervalInSeconds: libc::int32_t) -> nsresult {
        ((*self.vtable).Init)(self, uri, destination, chunkSize, intervalInSeconds)
    }


    /// ```text
    /// /**
    ///    * The URI being fetched.
    ///    */
    /// ```
    ///

    /// `readonly attribute nsIURI URI;`
    #[inline]
    pub unsafe fn GetURI(&self, aURI: *mut *const nsIURI) -> nsresult {
        ((*self.vtable).GetURI)(self, aURI)
    }


    /// ```text
    /// /**
    ///    * The URI being fetched after any redirects have been followed.  This
    ///    * attribute is set just prior to calling OnStartRequest on the observer
    ///    * passed to the start method.
    ///    */
    /// ```
    ///

    /// `readonly attribute nsIURI finalURI;`
    #[inline]
    pub unsafe fn GetFinalURI(&self, aFinalURI: *mut *const nsIURI) -> nsresult {
        ((*self.vtable).GetFinalURI)(self, aFinalURI)
    }


    /// ```text
    /// /**
    ///    * The file where the download is being written.
    ///    */
    /// ```
    ///

    /// `readonly attribute nsIFile destination;`
    #[inline]
    pub unsafe fn GetDestination(&self, aDestination: *mut *const nsIFile) -> nsresult {
        ((*self.vtable).GetDestination)(self, aDestination)
    }


    /// ```text
    /// /**
    ///    * The total number of bytes for the requested file.  This attribute is set
    ///    * just prior to calling OnStartRequest on the observer passed to the start
    ///    * method.
    ///    *
    ///    * This attribute has a value of -1 if the total size is unknown.
    ///    */
    /// ```
    ///

    /// `readonly attribute long long totalSize;`
    #[inline]
    pub unsafe fn GetTotalSize(&self, aTotalSize: *mut libc::int64_t) -> nsresult {
        ((*self.vtable).GetTotalSize)(self, aTotalSize)
    }


    /// ```text
    /// /**
    ///    * The current number of bytes downloaded so far.  This attribute is set just
    ///    * prior to calling OnStartRequest on the observer passed to the start
    ///    * method.
    ///    *
    ///    * This attribute has a value of -1 if the current size is unknown.
    ///    */
    /// ```
    ///

    /// `readonly attribute long long currentSize;`
    #[inline]
    pub unsafe fn GetCurrentSize(&self, aCurrentSize: *mut libc::int64_t) -> nsresult {
        ((*self.vtable).GetCurrentSize)(self, aCurrentSize)
    }


    /// ```text
    /// /**
    ///    * Start the incremental download.
    ///    *
    ///    * @param observer
    ///    *        An observer to be notified of various events.  OnStartRequest is
    ///    *        called when finalURI and totalSize have been determined or when an
    ///    *        error occurs.  OnStopRequest is called when the file is completely
    ///    *        downloaded or when an error occurs.  If this object implements
    ///    *        nsIProgressEventSink, then its OnProgress method will be called as
    ///    *        data is written to the destination file.  If this object implements
    ///    *        nsIInterfaceRequestor, then it will be assigned as the underlying
    ///    *        channel's notification callbacks, which allows it to provide a
    ///    *        nsIAuthPrompt implementation if needed by the channel, for example.
    ///    * @param ctxt
    ///    *        User defined object forwarded to the observer's methods.
    ///    */
    /// ```
    ///

    /// `void start (in nsIRequestObserver observer, in nsISupports ctxt);`
    #[inline]
    pub unsafe fn Start(&self, observer: *const nsIRequestObserver, ctxt: *const nsISupports) -> nsresult {
        ((*self.vtable).Start)(self, observer, ctxt)
    }


}