/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsCOMPtr<nsIChannel> chan(do_QueryInterface(request)); if (chan) {
int64_t contentLength = -1;
chan->GetContentLength(&contentLength); if (contentLength >= 0) { // On 64bit platforms size of uint64_t coincides with the size of size_t, // so we want to compare with the minimum from size_t and int64_t. if (static_cast<uint64_t>(contentLength) >
std::min(std::numeric_limits<size_t>::max(), static_cast<size_t>(std::numeric_limits<int64_t>::max()))) { // Too big to fit into size_t, so let's bail. return NS_ERROR_OUT_OF_MEMORY;
}
if (mObserver) { // provide nsIIncrementalStreamLoader::request during call to // OnStreamComplete
mRequest = request;
size_t length = mData.length();
uint8_t* elems = mData.extractOrCopyRawBuffer();
nsresult rv =
mObserver->OnStreamComplete(this, mContext, aStatus, length, elems); if (rv != NS_SUCCESS_ADOPTED_DATA) { // The observer didn't take ownership of the extracted data buffer, so // put it back into mData.
mData.replaceRawBuffer(elems, length);
} // done.. cleanup
ReleaseData();
mRequest = nullptr;
mObserver = nullptr;
} return NS_OK;
}
// We still own elems, freeing its memory when exiting scope. if (rv != NS_OK) {
free(elems); return rv;
}
if (consumedCount > reportCount) {
free(elems); return NS_ERROR_INVALID_ARG;
}
if (consumedCount == length) {
free(elems); // good case -- fully consumed data
} else { // Adopting elems back (at least its portion).
self->mData.replaceRawBuffer(elems, length); if (consumedCount > 0) {
self->mData.erase(self->mData.begin(),
self->mData.begin() + consumedCount);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.