Example #1
0
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();
}
Example #2
0
/* static */ void
URLMainThread::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
                               nsAString& aResult, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  CreateObjectURLInternal(aGlobal, aBlob.Impl(), aResult, aRv);
}
Example #3
0
 static void
 CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
                 const objectURLOptions& aOptions, nsAString& aResult,
                 ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
   CreateObjectURLInternal(aGlobal, aBlob.Impl(), aResult, aRv);
 }
Example #4
0
ArchiveReader::ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow,
                             const nsACString& aEncoding)
  : mBlobImpl(aBlob.Impl())
  , mWindow(aWindow)
  , mStatus(NOT_STARTED)
  , mEncoding(aEncoding)
{
  MOZ_ASSERT(aWindow);
}
bool
StructuredCloneHelper::WriteCallback(JSContext* aCx,
                                     JSStructuredCloneWriter* aWriter,
                                     JS::Handle<JSObject*> aObj)
{
  if (!mSupportsCloning) {
    return false;
  }

  // See if this is a File/Blob object.
  {
    Blob* blob = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
      BlobImpl* blobImpl = blob->Impl();
      if (JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB,
                             mBlobImplArray.Length())) {
        mBlobImplArray.AppendElement(blobImpl);
        return true;
      }

      return false;
    }
  }

  {
    FileList* fileList = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList))) {
      // A FileList is serialized writing the X number of elements and the offset
      // from mBlobImplArray. The Read will take X elements from mBlobImplArray
      // starting from the offset.
      if (!JS_WriteUint32Pair(aWriter, SCTAG_DOM_FILELIST,
                              fileList->Length()) ||
          !JS_WriteUint32Pair(aWriter, 0,
                              mBlobImplArray.Length())) {
        return false;
      }

      for (uint32_t i = 0; i < fileList->Length(); ++i) {
        mBlobImplArray.AppendElement(fileList->Item(i)->Impl());
      }

      return true;
    }
  }

  // See if this is an ImageBitmap object.
  {
    ImageBitmap* imageBitmap = nullptr;
    if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageBitmap, aObj, imageBitmap))) {
      return ImageBitmap::WriteStructuredClone(aWriter,
                                               GetImages(),
                                               imageBitmap);
    }
  }

  return NS_DOMWriteStructuredClone(aCx, aWriter, aObj, nullptr);
}
Example #6
0
    bool CustomWriteHandler(JSContext* aCx,
                            JSStructuredCloneWriter* aWriter,
                            JS::Handle<JSObject*> aObj)
    {
        {
            Blob* blob = nullptr;
            if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
                BlobImpl* blobImpl = blob->Impl();
                MOZ_ASSERT(blobImpl);

                if (!mBlobImpls.AppendElement(blobImpl))
                    return false;

                size_t idx = mBlobImpls.Length() - 1;
                return JS_WriteUint32Pair(aWriter, SCTAG_BLOB, 0) &&
                       JS_WriteBytes(aWriter, &idx, sizeof(size_t));
            }
        }

        if ((mOptions->wrapReflectors && IsReflector(aObj)) ||
            IsFileList(aObj))
        {
            if (!mReflectors.append(aObj))
                return false;

            size_t idx = mReflectors.length() - 1;
            if (!JS_WriteUint32Pair(aWriter, SCTAG_REFLECTOR, 0))
                return false;
            if (!JS_WriteBytes(aWriter, &idx, sizeof(size_t)))
                return false;
            return true;
        }

        if (JS::IsCallable(aObj)) {
            if (mOptions->cloneFunctions) {
                if (!mFunctions.append(aObj))
                    return false;
                return JS_WriteUint32Pair(aWriter, SCTAG_FUNCTION, mFunctions.length() - 1);
            } else {
                JS_ReportError(aCx, "Permission denied to pass a Function via structured clone");
                return false;
            }
        }

#ifdef MOZ_NFC
        {
          MozNDEFRecord* ndefRecord;
          if (NS_SUCCEEDED(UNWRAP_OBJECT(MozNDEFRecord, aObj, ndefRecord))) {
            return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NFC_NDEF, 0) &&
                   ndefRecord->WriteStructuredClone(aCx, aWriter);
          }
        }
#endif

        JS_ReportError(aCx, "Encountered unsupported value type writing stack-scoped structured clone");
        return false;
    }
Example #7
0
void
URL::CreateObjectURL(const GlobalObject& aGlobal,
                     Blob& aBlob,
                     const objectURLOptions& aOptions,
                     nsAString& aResult,
                     ErrorResult& aError)
{
  CreateObjectURLInternal(aGlobal, aBlob.Impl(),
                          NS_LITERAL_CSTRING(BLOBURI_SCHEME), aOptions, aResult,
                          aError);
}
Example #8
0
/* static */
void URLMainThread::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
                                    nsAString& aResult, ErrorResult& aRv) {
  MOZ_ASSERT(NS_IsMainThread());

  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
  if (NS_WARN_IF(!global)) {
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }

  nsCOMPtr<nsIPrincipal> principal =
      nsContentUtils::ObjectPrincipal(aGlobal.Get());

  nsAutoCString url;
  aRv = BlobURLProtocolHandler::AddDataEntry(aBlob.Impl(), principal, url);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  global->RegisterHostObjectURI(url);
  CopyASCIItoUTF16(url, aResult);
}