Ejemplo n.º 1
0
  NS_IMETHOD Run()
  {
    MOZ_ASSERT(NS_IsMainThread());

    mozilla::ErrorResult rv;

    if (!mFailed) {
      nsRefPtr<DOMFile> blob =
        DOMFile::CreateMemoryFile(mImgData, mImgSize, mType);

      {
        AutoJSAPI jsapi;
        jsapi.Init(mGlobal);
        JS_updateMallocCounter(jsapi.cx(), mImgSize);
      }

      mCallback->Call(blob, rv);
    }

    // These members aren't thread-safe. We're making sure that they're being
    // released on the main thread here. Otherwise, they could be getting
    // released by EncodingRunnable's destructor on the encoding thread
    // (bug 916128).
    mGlobal = nullptr;
    mCallback = nullptr;

    mEncoderThread->Shutdown();
    return rv.ErrorCode();
  }
Ejemplo n.º 2
0
    // This is called on main thread.
    nsresult ReceiveBlob(already_AddRefed<Blob> aBlob)
    {
      RefPtr<Blob> blob = aBlob;

      ErrorResult rv;
      uint64_t size = blob->GetSize(rv);
      if (rv.Failed()) {
        rv.SuppressException();
      } else {
        AutoJSAPI jsapi;
        if (jsapi.Init(mGlobal)) {
          JS_updateMallocCounter(jsapi.cx(), size);
        }
      }

      if (mPromise) {
        RefPtr<Blob> newBlob = Blob::Create(mGlobal, blob->Impl());
        mPromise->MaybeResolve(newBlob);
      }

      mGlobal = nullptr;
      mPromise = nullptr;

      return rv.StealNSResult();
    }