bool DeviceStorageRequestChild:: Recv__delete__(const DeviceStorageResponseValue& aValue) { if (mCallback) { mCallback->RequestComplete(); mCallback = nullptr; } nsCOMPtr<nsPIDOMWindow> window = mRequest->GetOwner(); if (!window) { return true; } switch (aValue.type()) { case DeviceStorageResponseValue::TErrorResponse: { ErrorResponse r = aValue; mRequest->FireError(r.error()); break; } case DeviceStorageResponseValue::TSuccessResponse: { nsString fullPath; mDSFile->GetFullPath(fullPath); AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, fullPath, &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFileDescriptorResponse: { FileDescriptorResponse r = aValue; nsString fullPath; mDSFile->GetFullPath(fullPath); AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, fullPath, &result); mDSFileDescriptor->mDSFile = mDSFile; mDSFileDescriptor->mFileDescriptor = r.fileDescriptor(); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TBlobResponse: { BlobResponse r = aValue; BlobChild* actor = static_cast<BlobChild*>(r.blobChild()); nsRefPtr<BlobImpl> bloblImpl = actor->GetBlobImpl(); nsRefPtr<Blob> blob = Blob::Create(mRequest->GetParentObject(), bloblImpl); AutoJSContext cx; JS::Rooted<JSObject*> obj(cx, blob->WrapObject(cx, JS::NullPtr())); MOZ_ASSERT(obj); JS::Rooted<JS::Value> result(cx, JS::ObjectValue(*obj)); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFreeSpaceStorageResponse: { FreeSpaceStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.freeBytes()))); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TUsedSpaceStorageResponse: { UsedSpaceStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.usedBytes()))); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TAvailableStorageResponse: { AvailableStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.mountState(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TStorageStatusResponse: { StorageStatusResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFormatStorageResponse: { FormatStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.mountState(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TMountStorageResponse: { MountStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TUnmountStorageResponse: { UnmountStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TEnumerationResponse: { EnumerationResponse r = aValue; nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get()); uint32_t count = r.paths().Length(); for (uint32_t i = 0; i < count; i++) { nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), r.rootdir(), r.paths()[i].name()); cursor->mFiles.AppendElement(dsf); } nsRefPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor); event->Continue(); break; } default: { NS_RUNTIMEABORT("not reached"); break; } } return true; }
bool DeviceStorageRequestChild:: Recv__delete__(const DeviceStorageResponseValue& aValue) { switch (aValue.type()) { case DeviceStorageResponseValue::TErrorResponse: { DS_LOG_INFO("error %u", mRequest->GetId()); ErrorResponse r = aValue; mRequest->Reject(r.error()); break; } case DeviceStorageResponseValue::TSuccessResponse: { DS_LOG_INFO("success %u", mRequest->GetId()); nsString fullPath; mRequest->GetFile()->GetFullPath(fullPath); mRequest->Resolve(fullPath); break; } case DeviceStorageResponseValue::TFileDescriptorResponse: { DS_LOG_INFO("fd %u", mRequest->GetId()); FileDescriptorResponse r = aValue; DeviceStorageFile* file = mRequest->GetFile(); DeviceStorageFileDescriptor* descriptor = mRequest->GetFileDescriptor(); nsString fullPath; file->GetFullPath(fullPath); descriptor->mDSFile = file; descriptor->mFileDescriptor = r.fileDescriptor(); mRequest->Resolve(fullPath); break; } case DeviceStorageResponseValue::TBlobResponse: { DS_LOG_INFO("blob %u", mRequest->GetId()); BlobResponse r = aValue; BlobChild* actor = static_cast<BlobChild*>(r.blobChild()); RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl(); mRequest->Resolve(blobImpl.get()); break; } case DeviceStorageResponseValue::TFreeSpaceStorageResponse: { DS_LOG_INFO("free %u", mRequest->GetId()); FreeSpaceStorageResponse r = aValue; mRequest->Resolve(r.freeBytes()); break; } case DeviceStorageResponseValue::TUsedSpaceStorageResponse: { DS_LOG_INFO("used %u", mRequest->GetId()); UsedSpaceStorageResponse r = aValue; mRequest->Resolve(r.usedBytes()); break; } case DeviceStorageResponseValue::TAvailableStorageResponse: { DS_LOG_INFO("available %u", mRequest->GetId()); AvailableStorageResponse r = aValue; mRequest->Resolve(r.mountState()); break; } case DeviceStorageResponseValue::TStorageStatusResponse: { DS_LOG_INFO("status %u", mRequest->GetId()); StorageStatusResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TFormatStorageResponse: { DS_LOG_INFO("format %u", mRequest->GetId()); FormatStorageResponse r = aValue; mRequest->Resolve(r.mountState()); break; } case DeviceStorageResponseValue::TMountStorageResponse: { DS_LOG_INFO("mount %u", mRequest->GetId()); MountStorageResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TUnmountStorageResponse: { DS_LOG_INFO("unmount %u", mRequest->GetId()); UnmountStorageResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TEnumerationResponse: { DS_LOG_INFO("enumerate %u", mRequest->GetId()); EnumerationResponse r = aValue; auto request = static_cast<DeviceStorageCursorRequest*>(mRequest.get()); uint32_t count = r.paths().Length(); request->AddFiles(count); for (uint32_t i = 0; i < count; i++) { RefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), r.rootdir(), r.paths()[i].name()); request->AddFile(dsf.forget()); } request->Continue(); break; } default: { DS_LOG_ERROR("unknown %u", mRequest->GetId()); NS_RUNTIMEABORT("not reached"); break; } } return true; }