コード例 #1
0
// static
File* File::create(
    ExecutionContext* context,
    const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& fileBits,
    const String& fileName,
    const FilePropertyBag& options,
    ExceptionState& exceptionState) {
  ASSERT(options.hasType());
  if (!options.type().containsOnlyASCII()) {
    exceptionState.throwDOMException(
        SyntaxError, "The 'type' property must consist of ASCII characters.");
    return nullptr;
  }

  double lastModified;
  if (options.hasLastModified())
    lastModified = static_cast<double>(options.lastModified());
  else
    lastModified = currentTimeMS();
  ASSERT(options.hasEndings());
  bool normalizeLineEndingsToNative = options.endings() == "native";
  if (normalizeLineEndingsToNative)
    UseCounter::count(context, UseCounter::FileAPINativeLineEndings);

  std::unique_ptr<BlobData> blobData = BlobData::create();
  blobData->setContentType(options.type().lower());
  populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative);

  long long fileSize = blobData->length();
  return File::create(fileName, lastModified,
                      BlobDataHandle::create(std::move(blobData), fileSize));
}
コード例 #2
0
ファイル: Blob.cpp プロジェクト: mirror/chromium
// static
Blob* Blob::create(
    ExecutionContext* context,
    const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& blobParts,
    const BlobPropertyBag& options,
    ExceptionState& exceptionState) {
  ASSERT(options.hasType());
  if (!options.type().containsOnlyASCII()) {
    exceptionState.throwDOMException(
        SyntaxError, "The 'type' property must consist of ASCII characters.");
    return nullptr;
  }

  ASSERT(options.hasEndings());
  bool normalizeLineEndingsToNative = options.endings() == "native";
  if (normalizeLineEndingsToNative)
    UseCounter::count(context, UseCounter::FileAPINativeLineEndings);

  std::unique_ptr<BlobData> blobData = BlobData::create();
  blobData->setContentType(options.type().lower());

  populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative);

  long long blobSize = blobData->length();
  return new Blob(BlobDataHandle::create(std::move(blobData), blobSize));
}