本文整理汇总了C++中BlobSet::GetBlobImpls方法的典型用法代码示例。如果您正苦于以下问题:C++ BlobSet::GetBlobImpls方法的具体用法?C++ BlobSet::GetBlobImpls怎么用?C++ BlobSet::GetBlobImpls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobSet
的用法示例。
在下文中一共展示了BlobSet::GetBlobImpls方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetLengthAndModifiedDate
void
MultipartBlobImpl::InitializeChromeFile(Blob& aBlob,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
if (mImmutable) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
mName = aBag.mName;
mContentType = aBag.mType;
mIsFromNsIFile = true;
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
aBlob.GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(aBlob.Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
示例2: if
void
MultipartBlobImpl::InitializeBlob(
JSContext* aCx,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv)
{
mContentType = aContentType;
BlobSet blobSet;
for (uint32_t i = 0, len = aData.Length(); i < len; ++i) {
const OwningArrayBufferOrArrayBufferViewOrBlobOrString& data = aData[i];
if (data.IsBlob()) {
nsRefPtr<Blob> blob = data.GetAsBlob().get();
blobSet.AppendBlobImpl(blob->Impl());
}
else if (data.IsString()) {
aRv = blobSet.AppendString(data.GetAsString(), aNativeEOL, aCx);
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBufferView()) {
const ArrayBufferView& buffer = data.GetAsArrayBufferView();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else {
MOZ_CRASH("Impossible blob data type.");
}
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
示例3: if
void
MultipartBlobImpl::InitializeBlob(const Sequence<Blob::BlobPart>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv)
{
mContentType = aContentType;
BlobSet blobSet;
for (uint32_t i = 0, len = aData.Length(); i < len; ++i) {
const Blob::BlobPart& data = aData[i];
if (data.IsBlob()) {
RefPtr<Blob> blob = data.GetAsBlob().get();
blobSet.AppendBlobImpl(blob->Impl());
}
else if (data.IsUSVString()) {
aRv = blobSet.AppendString(data.GetAsUSVString(), aNativeEOL);
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBufferView()) {
const ArrayBufferView& buffer = data.GetAsArrayBufferView();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else {
MOZ_CRASH("Impossible blob data type.");
}
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate(aRv);
NS_WARNING_ASSERTION(!aRv.Failed(), "SetLengthAndModifiedDate failed");
}
示例4: SetLengthAndModifiedDate
nsresult
MultipartBlobImpl::InitializeChromeFile(nsIFile* aFile,
const nsAString& aType,
const nsAString& aName,
bool aLastModifiedPassed,
int64_t aLastModified,
bool aIsFromNsIFile)
{
MOZ_ASSERT(!mImmutable, "Something went wrong ...");
if (mImmutable) {
return NS_ERROR_UNEXPECTED;
}
mName = aName;
mContentType = aType;
mIsFromNsIFile = aIsFromNsIFile;
bool exists;
nsresult rv= aFile->Exists(&exists);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!exists) {
return NS_ERROR_FILE_NOT_FOUND;
}
bool isDir;
rv = aFile->IsDirectory(&isDir);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (isDir) {
return NS_ERROR_FILE_IS_DIRECTORY;
}
if (mName.IsEmpty()) {
aFile->GetLeafName(mName);
}
RefPtr<File> blob = File::CreateFromFile(nullptr, aFile);
// Pre-cache size.
ErrorResult error;
blob->GetSize(error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// Pre-cache modified date.
blob->GetLastModified(error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<File*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate(error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
if (aLastModifiedPassed) {
SetLastModified(aLastModified);
}
return NS_OK;
}
示例5: SetLengthAndModifiedDate
nsresult
DOMMultipartFileImpl::InitChromeFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv)
{
nsresult rv;
NS_ASSERTION(!mImmutable, "Something went wrong ...");
NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
if (aArgc > 1) {
FilePropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]))) {
return NS_ERROR_TYPE_ERR;
}
mName = d.mName;
mContentType = d.mType;
}
// We expect to get a path to represent as a File object or
// Blob object, an nsIFile, or an nsIDOMFile.
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIDOMBlob> blob;
if (!aArgv[0].isString()) {
// Lets see if it's an nsIFile
if (!aArgv[0].isObject()) {
return NS_ERROR_UNEXPECTED; // We're not interested
}
JSObject* obj = &aArgv[0].toObject();
nsISupports* supports =
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
if (!supports) {
return NS_ERROR_UNEXPECTED;
}
blob = do_QueryInterface(supports);
file = do_QueryInterface(supports);
if (!blob && !file) {
return NS_ERROR_UNEXPECTED;
}
mIsFromNsiFile = true;
} else {
// It's a string
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[0]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, str)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
rv = NS_NewLocalFile(xpcomStr, false, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
}
if (file) {
bool exists;
rv = file->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
bool isDir;
rv = file->IsDirectory(&isDir);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_FALSE(isDir, NS_ERROR_FILE_IS_DIRECTORY);
if (mName.IsEmpty()) {
file->GetLeafName(mName);
}
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(file);
// Pre-cache size.
uint64_t unused;
rv = domFile->GetSize(&unused);
NS_ENSURE_SUCCESS(rv, rv);
// Pre-cache modified date.
rv = domFile->GetMozLastModifiedDate(&unused);
NS_ENSURE_SUCCESS(rv, rv);
blob = domFile.forget();
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<DOMFile*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
//.........这里部分代码省略.........
示例6: obj
nsresult
DOMMultipartFileImpl::ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
bool aNativeEOL,
UnwrapFuncPtr aUnwrapFunc)
{
if (!aValue.isObject()) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (!JS_IsArrayObject(aCx, obj)) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
BlobSet blobSet;
uint32_t length;
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &length));
for (uint32_t i = 0; i < length; ++i) {
JS::Rooted<JS::Value> element(aCx);
if (!JS_GetElement(aCx, obj, i, &element))
return NS_ERROR_TYPE_ERR;
if (element.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &element.toObject());
nsCOMPtr<nsIDOMBlob> blob = aUnwrapFunc(aCx, obj);
if (blob) {
nsRefPtr<DOMFileImpl> blobImpl =
static_cast<DOMFile*>(blob.get())->Impl();
// Flatten so that multipart blobs will never nest
const nsTArray<nsRefPtr<DOMFileImpl>>* subBlobImpls =
blobImpl->GetSubBlobImpls();
if (subBlobImpls) {
blobSet.AppendBlobImpls(*subBlobImpls);
} else {
blobSet.AppendBlobImpl(blobImpl);
}
continue;
}
if (JS_IsArrayBufferViewObject(obj)) {
nsresult rv = blobSet.AppendVoidPtr(
JS_GetArrayBufferViewData(obj),
JS_GetArrayBufferViewByteLength(obj));
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
if (JS_IsArrayBufferObject(obj)) {
nsresult rv = blobSet.AppendArrayBuffer(obj);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
}
// coerce it to a string
JSString* str = JS::ToString(aCx, element);
NS_ENSURE_TRUE(str, NS_ERROR_TYPE_ERR);
nsresult rv = blobSet.AppendString(str, aNativeEOL, aCx);
NS_ENSURE_SUCCESS(rv, rv);
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
return NS_OK;
}