JSObject* ReadStructuredCloneImageData(JSContext* aCx, JSStructuredCloneReader* aReader) { // Read the information out of the stream. uint32_t width, height; JS::Rooted<JS::Value> dataArray(aCx); if (!JS_ReadUint32Pair(aReader, &width, &height) || !JS_ReadTypedArray(aReader, &dataArray)) { return nullptr; } MOZ_ASSERT(dataArray.isObject()); // Protect the result from a moving GC in ~nsRefPtr. JS::Rooted<JSObject*> result(aCx); { // Construct the ImageData. nsRefPtr<ImageData> imageData = new ImageData(width, height, dataArray.toObject()); // Wrap it in a JS::Value. if (!imageData->WrapObject(aCx, nullptr, &result)) { return nullptr; } } return result; }
void QtCertificateViewerDialog::setCertificateChain(const std::vector<Certificate::ref>& chain) { // clean widgets ui->certChainTreeWidget->clear(); if (chain.empty()) return; // convert Swift certificate chain to qt certificate chain (root goes first) currentChain.clear(); foreach(Certificate::ref cert, chain) { ByteArray certAsDer = cert->toDER(); QByteArray dataArray(reinterpret_cast<const char*>(certAsDer.data()), certAsDer.size()); currentChain.push_front(QSslCertificate(dataArray, QSsl::Der)); }
bool Downloader::request(const QString& theMethod, const QUrl& url, const QString& theData, bool FireForget) { if (Error) return false; qDebug() << "Downloader::request: " << url; netManager.setProxy(M_PREFS->getProxy(url)); QNetworkRequest req(url); req.setRawHeader(QByteArray("Content-Type"), QByteArray("text/xml")); req.setRawHeader(QByteArray("User-Agent"), USER_AGENT.toLatin1()); QByteArray dataArray(theData.toUtf8()); QBuffer dataBuffer(&dataArray); currentReply = netManager.sendCustomRequest(req, theMethod.toLatin1(), &dataBuffer); if (AnimationTimer) { AnimationTimer->start(200); connect(currentReply,SIGNAL(downloadProgress(qint64, qint64)), this,SLOT(progress(qint64, qint64))); } if (FireForget) return true; if (Loop.exec() == QDialog::Rejected) return false; if (AnimationTimer) SAFE_DELETE(AnimationTimer); /* Test for redirections */ QVariant redir = currentReply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (redir.isValid()) { LocationText = redir.toString(); if (!LocationText.isEmpty()) { QUrl newUrl(LocationText); return request(theMethod, newUrl, theData, FireForget); } } /* Handler error? */ if (currentReply->error()) QMessageBox::information(0,tr("error"), currentReply->errorString()); /* Read the data */ Content = currentReply->readAll(); Result = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); ResultText = currentReply->errorString(); ErrorText = currentReply->rawHeader("Error"); return !Error; }
bool WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter, ImageData* aImageData) { uint32_t width = aImageData->Width(); uint32_t height = aImageData->Height(); JS::Rooted<JSObject*> dataArray(aCx, aImageData->GetDataObject()); JSAutoCompartment ac(aCx, dataArray); JS::Rooted<JS::Value> arrayValue(aCx, JS::ObjectValue(*dataArray)); return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) && JS_WriteUint32Pair(aWriter, width, height) && JS_WriteTypedArray(aWriter, arrayValue); }
void DmapClient::getLibraryContainerFinished() { QByteArray array = containersReply->readAll(); DmapStatement statement(array.data(), array.data() + (array.size() - 1), 1); QString name("miid"); QString inside("mlit"); QString insideRef("abpl"); char c = 0x01; QByteArray dataArray(1, c); DmapStatement *number = statement.findValue(name, inside, insideRef, dataArray); libid = DmapStatement::byteToInt<quint32>(number->getData()); containersReply->deleteLater(); emit getLibraryContainerCompleted(); }
AssetUploadTransferPtr HttpAssetProvider::UploadAssetFromFileInMemory(const u8 *data, size_t numBytes, AssetStoragePtr destination, const char *assetName) { QString dstUrl = destination->GetFullAssetURL(assetName); QNetworkRequest request; request.setUrl(QUrl(dstUrl)); request.setRawHeader("User-Agent", "realXtend Naali"); QByteArray dataArray((const char*)data, numBytes); QNetworkReply *reply = networkAccessManager->put(request, dataArray); AssetUploadTransferPtr transfer = AssetUploadTransferPtr(new IAssetUploadTransfer()); transfer->destinationStorage = destination; transfer->destinationProvider = shared_from_this(); transfer->destinationName = assetName; uploadTransfers[reply] = transfer; return transfer; }
bool SvmParser::parse(const QByteArray &data) { // Check the signature "VCLMTF" if (!data.startsWith("VCLMTF")) return false; QBuffer buffer((QByteArray *) &data); buffer.open(QIODevice::ReadOnly); QDataStream mainStream(&buffer); mainStream.setByteOrder(QDataStream::LittleEndian); // Start reading from the stream: read past the signature and get the header. soakBytes(mainStream, 6); SvmHeader header(mainStream); #if DEBUG_SVMPARSER debugVectorImage << "================ SVM HEADER ================"; debugVectorImage << "version, length:" << header.versionCompat.version << header.versionCompat.length; debugVectorImage << "compressionMode:" << header.compressionMode; debugVectorImage << "mapMode:" << "Origin" << header.mapMode.origin << "scaleX" << header.mapMode.scaleX.numerator << header.mapMode.scaleX.denominator << (qreal(header.mapMode.scaleX.numerator) / header.mapMode.scaleX.denominator) << "scaleY" << header.mapMode.scaleY.numerator << header.mapMode.scaleY.denominator << (qreal(header.mapMode.scaleY.numerator) / header.mapMode.scaleY.denominator); debugVectorImage << "size:" << header.width << header.height; debugVectorImage << "actionCount:" << header.actionCount; debugVectorImage << "================ SVM HEADER ================"; #endif mBackend->init(header); #if DEBUG_SVMPARSER { QPolygon polygon; polygon << QPoint(0, 0); polygon << QPoint(header.width, header.height); mBackend->polyLine(mContext, polygon); } #endif // Parse all actions and call the appropriate backend callback for // the graphics drawing actions. The context actions will // manipulate the graphics context, which is maintained here. for (uint action = 0; action < header.actionCount; ++action) { quint16 actionType; quint16 version; quint32 totalSize; // Here starts the Action itself. The first two bytes is the action type. mainStream >> actionType; // The VersionCompat object mainStream >> version; mainStream >> totalSize; char *rawData = new char[totalSize]; mainStream.readRawData(rawData, totalSize); QByteArray dataArray(rawData, totalSize); QDataStream stream(&dataArray, QIODevice::ReadOnly); stream.setByteOrder(QDataStream::LittleEndian); // Debug #if DEBUG_SVMPARSER { QString name; if (actionType == 0) name = actionNames[0].actionName; else if (100 <= actionType && actionType <= META_LAST_ACTION) name = actionNames[actionType - 99].actionName; else if (actionType == 512) name = "META_COMMENT_ACTION"; else name = "(out of bounds)"; debugVectorImage << name << "(" << actionType << ")" << "version" << version << "totalSize" << totalSize; } #endif // Parse all actions. switch (actionType) { case META_NULL_ACTION: break; case META_PIXEL_ACTION: break; case META_POINT_ACTION: break; case META_LINE_ACTION: break; case META_RECT_ACTION: { QRect rect; parseRect(stream, rect); debugVectorImage << "Rect:" << rect; mBackend->rect(mContext, rect); } break; case META_ROUNDRECT_ACTION: break; case META_ELLIPSE_ACTION: break; case META_ARC_ACTION: break; case META_PIE_ACTION: break; case META_CHORD_ACTION: break; case META_POLYLINE_ACTION: { QPolygon polygon; parsePolygon(stream, polygon); debugVectorImage << "Polyline:" << polygon; mBackend->polyLine(mContext, polygon); // FIXME: Version 2: Lineinfo, Version 3: polyflags if (version > 1) soakBytes(stream, totalSize - 2 - 4 * 2 * polygon.size()); } break; case META_POLYGON_ACTION: { QPolygon polygon; parsePolygon(stream, polygon); debugVectorImage << "Polygon:" << polygon; mBackend->polygon(mContext, polygon); // FIXME: Version 2: Lineinfo, Version 3: polyflags if (version > 1) soakBytes(stream, totalSize - 2 - 4 * 2 * polygon.size()); } break; case META_POLYPOLYGON_ACTION: { quint16 polygonCount; stream >> polygonCount; //debugVectorImage << "Number of polygons:" << polygonCount; QList<QPolygon> polygons; for (quint16 i = 0 ; i < polygonCount ; i++) { QPolygon polygon; parsePolygon(stream, polygon); polygons << polygon; //debugVectorImage << "Polygon:" << polygon; } if (version > 1) { quint16 complexPolygonCount; stream >> complexPolygonCount; //debugVectorImage << "Number of complex polygons:" << complexPolygonCount; // Parse the so called "complex polygons". For // each one, there is an index and a polygon. The // index tells which of the original polygons to // replace. for (quint16 i = 0; i < complexPolygonCount; i++) { quint16 complexPolygonIndex; stream >> complexPolygonIndex; QPolygon polygon; parsePolygon(stream, polygon); //debugVectorImage << "polygon index:" << complexPolygonIndex << polygon; // FIXME: The so called complex polygons have something to do // with modifying the polygons, but I have not yet been // able to understand how. So until I do, we'll disable // this. //polygons[complexPolygonIndex] = polygon; } } mBackend->polyPolygon(mContext, polygons); } break; case META_TEXT_ACTION: break; case META_TEXTARRAY_ACTION: { QPoint startPoint; QString string; quint16 startIndex; quint16 len; quint32 dxArrayLen; qint32 *dxArray = 0; stream >> startPoint; parseString(stream, string); stream >> startIndex; stream >> len; stream >> dxArrayLen; if (dxArrayLen > 0) { quint32 maxDxArrayLen = totalSize - stream.device()->pos(); if (dxArrayLen > maxDxArrayLen) { debugVectorImage << "Defined dxArrayLen= " << dxArrayLen << "exceeds availalable size" << maxDxArrayLen; dxArrayLen = maxDxArrayLen; } dxArray = new qint32[dxArrayLen]; for (uint i = 0; i < dxArrayLen; ++i) stream >> dxArray[i]; } if (version > 1) { quint16 len2; stream >> len2; // FIXME: More here } #if 0 debugVectorImage << "Text: " << startPoint << string << startIndex << len; if (dxArrayLen > 0) { debugVectorImage << "dxArrayLen:" << dxArrayLen; for (uint i = 0; i < dxArrayLen; ++i) debugVectorImage << dxArray[i]; } else debugVectorImage << "dxArrayLen = 0"; #endif mBackend->textArray(mContext, startPoint, string, startIndex, len, dxArrayLen, dxArray); if (dxArrayLen) delete[] dxArray; }