Beispiel #1
0
void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength)
{
    ASSERT(m_peer);
    // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>.
    OwnPtr<Vector<char>> data = adoptPtr(new Vector<char>(byteLength));
    if (binaryData.byteLength())
        memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteOffset, byteLength);

    m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBinaryAsCharVector, m_peer.get(), data.release()));
}
bool WebPepperSocketImpl::sendArrayBuffer(
    const WebArrayBuffer& webArrayBuffer) {
  size_t size = webArrayBuffer.byteLength();
  m_bufferedAmount += size;
  if (m_isClosingOrClosed)
    m_bufferedAmountAfterClose += size;

  // FIXME: Deprecate this call.
  m_client->didUpdateBufferedAmount(m_bufferedAmount);

  if (m_isClosingOrClosed)
    return true;

  DOMArrayBuffer* arrayBuffer = webArrayBuffer;
  m_private->send(*arrayBuffer, 0, arrayBuffer->byteLength());
  return true;
}
PushMessageData* PushMessageData::create(const ArrayBufferOrArrayBufferViewOrUSVString& messageData)
{
    if (messageData.isArrayBuffer() || messageData.isArrayBufferView()) {
        DOMArrayBuffer* buffer = messageData.isArrayBufferView()
            ? messageData.getAsArrayBufferView()->buffer()
            : messageData.getAsArrayBuffer();

        return new PushMessageData(static_cast<const char*>(buffer->data()), buffer->byteLength());
    }

    if (messageData.isUSVString()) {
        CString encodedString = UTF8Encoding().encode(messageData.getAsUSVString(), WTF::EntitiesForUnencodables);
        return new PushMessageData(encodedString.data(), encodedString.length());
    }

    DCHECK(messageData.isNull());
    return nullptr;
}
Beispiel #4
0
// static
void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative)
{
    for (const auto& item : parts) {
        if (item.isArrayBuffer()) {
            DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer();
            blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength());
        } else if (item.isArrayBufferView()) {
            DOMArrayBufferView* arrayBufferView = item.getAsArrayBufferView();
            blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->byteLength());
        } else if (item.isBlob()) {
            item.getAsBlob()->appendTo(*blobData);
        } else if (item.isUSVString()) {
            blobData->appendText(item.getAsUSVString(), normalizeLineEndingsToNative);
        } else {
            NOTREACHED();
        }
    }
}
RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, ExceptionState& exceptionState)
{
    DictionaryHelper::get(options, "method", method);
    DictionaryHelper::get(options, "headers", headers);
    if (!headers) {
        Vector<Vector<String>> headersVector;
        if (DictionaryHelper::get(options, "headers", headersVector, exceptionState))
            headers = Headers::create(headersVector, exceptionState);
        else
            DictionaryHelper::get(options, "headers", headersDictionary);
    }
    DictionaryHelper::get(options, "mode", mode);
    DictionaryHelper::get(options, "credentials", credentials);

    v8::Local<v8::Value> body;
    if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() || body->IsNull())
        return;
    OwnPtr<BlobData> blobData = BlobData::create();
    v8::Isolate* isolate = toIsolate(context);
    if (body->IsArrayBuffer()) {
        DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Object>::Cast(body));
        ASSERT(arrayBuffer);
        blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength());
    } else if (body->IsArrayBufferView()) {
        DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(v8::Local<v8::Object>::Cast(body));
        ASSERT(arrayBufferView);
        blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferView->byteLength());
    } else if (V8Blob::hasInstance(body, isolate)) {
        Blob* blob = V8Blob::toImpl(v8::Local<v8::Object>::Cast(body));
        ASSERT(blob);
        blob->appendTo(*blobData);
        blobData->setContentType(blob->type());
    } else if (V8FormData::hasInstance(body, isolate)) {
        DOMFormData* domFormData = V8FormData::toImpl(v8::Local<v8::Object>::Cast(body));
        ASSERT(domFormData);
        RefPtr<FormData> httpBody = domFormData->createMultiPartFormData();
        for (size_t i = 0; i < httpBody->elements().size(); ++i) {
            const FormDataElement& element = httpBody->elements()[i];
            switch (element.m_type) {
            case FormDataElement::data: {
                blobData->appendBytes(element.m_data.data(), element.m_data.size());
                break;
            }
            case FormDataElement::encodedFile:
                blobData->appendFile(element.m_filename, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime);
                break;
            case FormDataElement::encodedBlob:
                if (element.m_optionalBlobDataHandle)
                    blobData->appendBlob(element.m_optionalBlobDataHandle, 0, element.m_optionalBlobDataHandle->size());
                break;
            case FormDataElement::encodedFileSystemURL:
                blobData->appendFileSystemURL(element.m_fileSystemURL, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime);
                break;
            default:
                ASSERT_NOT_REACHED();
            }
        }
        blobData->setContentType(AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data());
    } else if (body->IsString()) {
        String stringValue(toUSVString(isolate, body, exceptionState));
        blobData->appendText(stringValue, false);
        blobData->setContentType("text/plain;charset=UTF-8");
    } else {
        return;
    }
    const long long blobSize = blobData->length();
    bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize);
}
Beispiel #6
0
std::unique_ptr<Shape> Shape::createRasterShape(Image* image,
                                                float threshold,
                                                const LayoutRect& imageR,
                                                const LayoutRect& marginR,
                                                WritingMode writingMode,
                                                float margin) {
  IntRect imageRect = pixelSnappedIntRect(imageR);
  IntRect marginRect = pixelSnappedIntRect(marginR);

  std::unique_ptr<RasterShapeIntervals> intervals = wrapUnique(
      new RasterShapeIntervals(marginRect.height(), -marginRect.y()));
  std::unique_ptr<ImageBuffer> imageBuffer =
      ImageBuffer::create(imageRect.size());

  if (image && imageBuffer) {
    // FIXME: This is not totally correct but it is needed to prevent shapes
    // that loads SVG Images during paint invalidations to mark layoutObjects
    // for layout, which is not allowed. See https://crbug.com/429346
    ImageObserverDisabler disabler(image);
    SkPaint paint;
    IntRect imageSourceRect(IntPoint(), image->size());
    IntRect imageDestRect(IntPoint(), imageRect.size());
    image->draw(imageBuffer->canvas(), paint, imageDestRect, imageSourceRect,
                DoNotRespectImageOrientation,
                Image::DoNotClampImageToSourceRect);

    WTF::ArrayBufferContents contents;
    imageBuffer->getImageData(Unmultiplied,
                              IntRect(IntPoint(), imageRect.size()), contents);
    DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents);
    DOMUint8ClampedArray* pixelArray =
        DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength());
    unsigned pixelArrayOffset = 3;  // Each pixel is four bytes: RGBA.
    uint8_t alphaPixelThreshold = threshold * 255;

    ASSERT(static_cast<unsigned>(imageRect.width() * imageRect.height() * 4) ==
           pixelArray->length());

    int minBufferY = std::max(0, marginRect.y() - imageRect.y());
    int maxBufferY =
        std::min(imageRect.height(), marginRect.maxY() - imageRect.y());

    for (int y = minBufferY; y < maxBufferY; ++y) {
      int startX = -1;
      for (int x = 0; x < imageRect.width(); ++x, pixelArrayOffset += 4) {
        uint8_t alpha = pixelArray->item(pixelArrayOffset);
        bool alphaAboveThreshold = alpha > alphaPixelThreshold;
        if (startX == -1 && alphaAboveThreshold) {
          startX = x;
        } else if (startX != -1 &&
                   (!alphaAboveThreshold || x == imageRect.width() - 1)) {
          int endX = alphaAboveThreshold ? x + 1 : x;
          intervals->intervalAt(y + imageRect.y())
              .unite(IntShapeInterval(startX + imageRect.x(),
                                      endX + imageRect.x()));
          startX = -1;
        }
      }
    }
  }

  std::unique_ptr<RasterShape> rasterShape =
      wrapUnique(new RasterShape(std::move(intervals), marginRect.size()));
  rasterShape->m_writingMode = writingMode;
  rasterShape->m_margin = margin;
  return std::move(rasterShape);
}