本文整理汇总了C++中BlobImpl类的典型用法代码示例。如果您正苦于以下问题:C++ BlobImpl类的具体用法?C++ BlobImpl怎么用?C++ BlobImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlobImpl类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_CreateInstance
void
MultipartBlobImpl::GetInternalStream(nsIInputStream** aStream,
ErrorResult& aRv)
{
*aStream = nullptr;
nsCOMPtr<nsIMultiplexInputStream> stream =
do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
if (NS_WARN_IF(!stream)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
uint32_t i;
for (i = 0; i < mBlobImpls.Length(); i++) {
nsCOMPtr<nsIInputStream> scratchStream;
BlobImpl* blobImpl = mBlobImpls.ElementAt(i).get();
blobImpl->GetInternalStream(getter_AddRefs(scratchStream), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
aRv = stream->AppendStream(scratchStream);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
stream.forget(aStream);
}
示例2:
void
MultipartBlobImpl::GetMozFullPathInternal(nsAString& aFilename,
ErrorResult& aRv)
{
if (!mIsFromNsIFile || mBlobImpls.Length() == 0) {
BlobImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
BlobImpl* blobImpl = mBlobImpls.ElementAt(0).get();
if (!blobImpl) {
BlobImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
blobImpl->GetMozFullPathInternal(aFilename, aRv);
}
示例3:
nsresult
nsFileControlFrame::DnDListener::GetBlobImplForWebkitDirectory(nsIDOMFileList* aFileList,
BlobImpl** aBlobImpl)
{
*aBlobImpl = nullptr;
HTMLInputElement* inputElement =
HTMLInputElement::FromContent(mFrame->GetContent());
bool webkitDirPicker =
Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
inputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory);
if (!webkitDirPicker) {
return NS_OK;
}
if (!aFileList) {
return NS_ERROR_FAILURE;
}
FileList* files = static_cast<FileList*>(aFileList);
// webkitdirectory doesn't care about the length of the file list but
// only about the first item on it.
uint32_t len = files->Length();
if (len) {
File* file = files->Item(0);
if (file) {
BlobImpl* impl = file->Impl();
if (impl && impl->IsDirectory()) {
RefPtr<BlobImpl> retVal = impl;
retVal.swap(*aBlobImpl);
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
示例4: LogicExceptionImpl
//.........这里部分代码省略.........
{
*(int64_t*)var->sqldata = *(int64_t*)value;
}
else if (ivType == ivFloat)
{
// This SQL_INT64 is a NUMERIC(x,y), scale it !
double multiplier = consts::dscales[-var->sqlscale];
*(int64_t*)var->sqldata =
(int64_t)floor(*(float*)value * multiplier + 0.5);
}
else if (ivType == ivDouble)
{
// This SQL_INT64 is a NUMERIC(x,y), scale it !
double multiplier = consts::dscales[-var->sqlscale];
*(int64_t*)var->sqldata =
(int64_t)floor(*(double*)value * multiplier + 0.5);
}
else throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
break;
case SQL_FLOAT :
if (ivType != ivFloat || var->sqlscale != 0)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
*(float*)var->sqldata = *(float*)value;
break;
case SQL_DOUBLE :
if (ivType != ivDouble)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
if (var->sqlscale != 0)
{
// Round to scale of NUMERIC(x,y)
double multiplier = consts::dscales[-var->sqlscale];
*(double*)var->sqldata =
floor(*(double*)value * multiplier + 0.5) / multiplier;
}
else *(double*)var->sqldata = *(double*)value;
break;
case SQL_TIMESTAMP :
if (ivType != ivTimestamp)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
encodeTimestamp(*(ISC_TIMESTAMP*)var->sqldata, *(IBPP::Timestamp*)value);
break;
case SQL_TYPE_DATE :
if (ivType != ivDate)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
encodeDate(*(ISC_DATE*)var->sqldata, *(IBPP::Date*)value);
break;
case SQL_TYPE_TIME :
if (ivType != ivTime)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
encodeTime(*(ISC_TIME*)var->sqldata, *(IBPP::Time*)value);
break;
case SQL_BLOB :
if (ivType == ivBlob)
{
BlobImpl* blob = (BlobImpl*)value;
blob->GetId((ISC_QUAD*)var->sqldata);
}
else if (ivType == ivString)
{
BlobImpl blob(mDatabase, mTransaction);
blob.Save(*(std::string*)value);
blob.GetId((ISC_QUAD*)var->sqldata);
}
else throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
break;
case SQL_ARRAY :
if (ivType != ivArray)
throw WrongTypeImpl("RowImpl::SetValue", var->sqltype, ivType,
_("Incompatible types."));
{
ArrayImpl* array = (ArrayImpl*)value;
array->GetId((ISC_QUAD*)var->sqldata);
// When an array has been affected to a column, we want to reset
// its ID. This way, the next WriteFrom() on the same Array object
// will allocate a new ID. This protects against storing the same
// array ID in multiple columns or rows.
array->ResetId();
}
break;
default : throw LogicExceptionImpl("RowImpl::SetValue",
_("The field uses an unsupported SQL type !"));
}
if (var->sqltype & 1) *var->sqlind = 0; // Remove the 0 flag
}
示例5: MultipartBlobImpl
already_AddRefed<BlobImpl>
MultipartBlobImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
// If we clamped to nothing we create an empty blob
nsTArray<nsRefPtr<BlobImpl>> blobImpls;
uint64_t length = aLength;
uint64_t skipStart = aStart;
// Prune the list of blobs if we can
uint32_t i;
for (i = 0; length && skipStart && i < mBlobImpls.Length(); i++) {
BlobImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (skipStart < l) {
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);
nsRefPtr<BlobImpl> firstBlobImpl =
blobImpl->CreateSlice(skipStart, upperBound,
aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// Avoid wrapping a single blob inside an MultipartBlobImpl
if (length == upperBound) {
return firstBlobImpl.forget();
}
blobImpls.AppendElement(firstBlobImpl);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobImpls.Length(); i++) {
BlobImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (length < l) {
nsRefPtr<BlobImpl> lastBlobImpl =
blobImpl->CreateSlice(0, length, aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
blobImpls.AppendElement(lastBlobImpl);
} else {
blobImpls.AppendElement(blobImpl);
}
length -= std::min<uint64_t>(l, length);
}
// we can create our blob now
nsRefPtr<BlobImpl> impl =
new MultipartBlobImpl(blobImpls, aContentType);
return impl.forget();
}
示例6: NS_NewURI
nsresult
FetchDriver::BasicFetch()
{
nsAutoCString url;
mRequest->GetURL(url);
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri),
url,
nullptr,
nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
nsAutoCString scheme;
rv = uri->GetScheme(scheme);
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
if (scheme.LowerCaseEqualsLiteral("about")) {
if (url.EqualsLiteral("about:blank")) {
nsRefPtr<InternalResponse> response =
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ErrorResult result;
response->Headers()->Append(NS_LITERAL_CSTRING("content-type"),
NS_LITERAL_CSTRING("text/html;charset=utf-8"),
result);
MOZ_ASSERT(!result.Failed());
nsCOMPtr<nsIInputStream> body;
rv = NS_NewCStringInputStream(getter_AddRefs(body), EmptyCString());
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
response->SetBody(body);
BeginResponse(response);
return SucceedWithResponse();
}
return FailWithNetworkError();
}
if (scheme.LowerCaseEqualsLiteral("blob")) {
nsRefPtr<BlobImpl> blobImpl;
rv = NS_GetBlobForBlobURI(uri, getter_AddRefs(blobImpl));
BlobImpl* blob = static_cast<BlobImpl*>(blobImpl.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
nsRefPtr<InternalResponse> response = new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ErrorResult result;
uint64_t size = blob->GetSize(result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsAutoString sizeStr;
sizeStr.AppendInt(size);
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Length"), NS_ConvertUTF16toUTF8(sizeStr), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsAutoString type;
blob->GetType(type);
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Type"), NS_ConvertUTF16toUTF8(type), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsCOMPtr<nsIInputStream> stream;
blob->GetInternalStream(getter_AddRefs(stream), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
response->SetBody(stream);
BeginResponse(response);
return SucceedWithResponse();
}
if (scheme.LowerCaseEqualsLiteral("data")) {
nsAutoCString method;
mRequest->GetMethod(method);
if (method.LowerCaseEqualsASCII("get")) {
nsresult rv;
nsCOMPtr<nsIProtocolHandler> dataHandler =
do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "data", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return FailWithNetworkError();
//.........这里部分代码省略.........
示例7: GetAsFileWithPrincipal
already_AddRefed<FileSystemEntry>
DataTransferItem::GetAsEntryWithPrincipal(nsIPrincipal* aPrincipal,
ErrorResult& aRv)
{
RefPtr<File> file = GetAsFileWithPrincipal(aPrincipal, aRv);
if (NS_WARN_IF(aRv.Failed()) || !file) {
return nullptr;
}
nsCOMPtr<nsIGlobalObject> global;
// This is annoying, but DataTransfer may have various things as parent.
nsCOMPtr<EventTarget> target =
do_QueryInterface(mDataTransfer->GetParentObject());
if (target) {
global = target->GetOwnerGlobal();
} else {
nsCOMPtr<nsIDOMEvent> event =
do_QueryInterface(mDataTransfer->GetParentObject());
if (event) {
global = event->InternalDOMEvent()->GetParentObject();
}
}
if (!global) {
return nullptr;
}
RefPtr<FileSystem> fs = FileSystem::Create(global);
RefPtr<FileSystemEntry> entry;
BlobImpl* impl = file->Impl();
MOZ_ASSERT(impl);
if (impl->IsDirectory()) {
nsAutoString fullpath;
impl->GetMozFullPathInternal(fullpath, aRv);
if (aRv.Failed()) {
aRv.SuppressException();
return nullptr;
}
nsCOMPtr<nsIFile> directoryFile;
nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(fullpath),
true, getter_AddRefs(directoryFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
RefPtr<Directory> directory = Directory::Create(global, directoryFile);
entry = new FileSystemDirectoryEntry(global, directory, fs);
} else {
entry = new FileSystemFileEntry(global, file, fs);
}
Sequence<RefPtr<FileSystemEntry>> entries;
if (!entries.AppendElement(entry, fallible)) {
return nullptr;
}
fs->CreateRoot(entries);
return entry.forget();
}
示例8: NS_NewURI
nsresult
FetchDriver::BasicFetch()
{
nsAutoCString url;
mRequest->GetURL(url);
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri),
url,
nullptr,
nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
nsAutoCString scheme;
rv = uri->GetScheme(scheme);
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
if (scheme.LowerCaseEqualsLiteral("about")) {
if (url.EqualsLiteral("about:blank")) {
nsRefPtr<InternalResponse> response =
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ErrorResult result;
response->Headers()->Append(NS_LITERAL_CSTRING("content-type"),
NS_LITERAL_CSTRING("text/html;charset=utf-8"),
result);
MOZ_ASSERT(!result.Failed());
nsCOMPtr<nsIInputStream> body;
rv = NS_NewCStringInputStream(getter_AddRefs(body), EmptyCString());
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
response->SetBody(body);
BeginResponse(response);
return SucceedWithResponse();
}
return FailWithNetworkError();
}
if (scheme.LowerCaseEqualsLiteral("blob")) {
nsRefPtr<BlobImpl> blobImpl;
rv = NS_GetBlobForBlobURI(uri, getter_AddRefs(blobImpl));
BlobImpl* blob = static_cast<BlobImpl*>(blobImpl.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
return rv;
}
nsRefPtr<InternalResponse> response = new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ErrorResult result;
uint64_t size = blob->GetSize(result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsAutoString sizeStr;
sizeStr.AppendInt(size);
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Length"), NS_ConvertUTF16toUTF8(sizeStr), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsAutoString type;
blob->GetType(type);
response->Headers()->Append(NS_LITERAL_CSTRING("Content-Type"), NS_ConvertUTF16toUTF8(type), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
nsCOMPtr<nsIInputStream> stream;
blob->GetInternalStream(getter_AddRefs(stream), result);
if (NS_WARN_IF(result.Failed())) {
FailWithNetworkError();
return result.StealNSResult();
}
response->SetBody(stream);
BeginResponse(response);
return SucceedWithResponse();
}
if (scheme.LowerCaseEqualsLiteral("data")) {
nsAutoCString method;
mRequest->GetMethod(method);
if (method.LowerCaseEqualsASCII("get")) {
// Use nsDataHandler directly so that we can extract the content type.
// XXX(nsm): Is there a way to acquire the charset without such tight
// coupling with the DataHandler? nsIProtocolHandler does not provide
// anything similar.
nsAutoCString contentType, contentCharset, dataBuffer, hashRef;
bool isBase64;
//.........这里部分代码省略.........
示例9: CollectReports
NS_DECL_ISUPPORTS
NS_IMETHOD CollectReports(nsIHandleReportCallback* aCallback,
nsISupports* aData, bool aAnonymize) override
{
if (!gDataTable) {
return NS_OK;
}
nsDataHashtable<nsPtrHashKey<BlobImpl>, uint32_t> refCounts;
// Determine number of URLs per BlobImpl, to handle the case where it's > 1.
for (auto iter = gDataTable->Iter(); !iter.Done(); iter.Next()) {
if (iter.UserData()->mObjectType != DataInfo::eBlobImpl) {
continue;
}
BlobImpl* blobImpl = iter.UserData()->mBlobImpl;
MOZ_ASSERT(blobImpl);
refCounts.Put(blobImpl, refCounts.Get(blobImpl) + 1);
}
for (auto iter = gDataTable->Iter(); !iter.Done(); iter.Next()) {
nsCStringHashKey::KeyType key = iter.Key();
DataInfo* info = iter.UserData();
if (iter.UserData()->mObjectType == DataInfo::eBlobImpl) {
BlobImpl* blobImpl = iter.UserData()->mBlobImpl;
MOZ_ASSERT(blobImpl);
NS_NAMED_LITERAL_CSTRING(desc,
"A blob URL allocated with URL.createObjectURL; the referenced "
"blob cannot be freed until all URLs for it have been explicitly "
"invalidated with URL.revokeObjectURL.");
nsAutoCString path, url, owner, specialDesc;
uint64_t size = 0;
uint32_t refCount = 1;
DebugOnly<bool> blobImplWasCounted;
blobImplWasCounted = refCounts.Get(blobImpl, &refCount);
MOZ_ASSERT(blobImplWasCounted);
MOZ_ASSERT(refCount > 0);
bool isMemoryFile = blobImpl->IsMemoryFile();
if (isMemoryFile) {
ErrorResult rv;
size = blobImpl->GetSize(rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
size = 0;
}
}
path = isMemoryFile ? "memory-blob-urls/" : "file-blob-urls/";
BuildPath(path, key, info, aAnonymize);
if (refCount > 1) {
nsAutoCString addrStr;
addrStr = "0x";
addrStr.AppendInt((uint64_t)(BlobImpl*)blobImpl, 16);
path += " ";
path.AppendInt(refCount);
path += "@";
path += addrStr;
specialDesc = desc;
specialDesc += "\n\nNOTE: This blob (address ";
specialDesc += addrStr;
specialDesc += ") has ";
specialDesc.AppendInt(refCount);
specialDesc += " URLs.";
if (isMemoryFile) {
specialDesc += " Its size is divided ";
specialDesc += refCount > 2 ? "among" : "between";
specialDesc += " them in this report.";
}
}
const nsACString& descString = specialDesc.IsEmpty()
? static_cast<const nsACString&>(desc)
: static_cast<const nsACString&>(specialDesc);
if (isMemoryFile) {
aCallback->Callback(EmptyCString(),
path,
KIND_OTHER,
UNITS_BYTES,
size / refCount,
descString,
aData);
} else {
aCallback->Callback(EmptyCString(),
path,
KIND_OTHER,
UNITS_COUNT,
1,
descString,
//.........这里部分代码省略.........