michael@0: /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "PluginStreamParent.h" michael@0: #include "PluginInstanceParent.h" michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: PluginStreamParent::PluginStreamParent(PluginInstanceParent* npp, michael@0: const nsCString& mimeType, michael@0: const nsCString& target, michael@0: NPError* result) michael@0: : mInstance(npp) michael@0: , mClosed(false) michael@0: { michael@0: *result = mInstance->mNPNIface->newstream(mInstance->mNPP, michael@0: const_cast(mimeType.get()), michael@0: NullableStringGet(target), michael@0: &mStream); michael@0: if (*result == NPERR_NO_ERROR) michael@0: mStream->pdata = static_cast(this); michael@0: else michael@0: mStream = nullptr; michael@0: } michael@0: michael@0: bool michael@0: PluginStreamParent::AnswerNPN_Write(const Buffer& data, int32_t* written) michael@0: { michael@0: if (mClosed) { michael@0: *written = -1; michael@0: return true; michael@0: } michael@0: michael@0: *written = mInstance->mNPNIface->write(mInstance->mNPP, mStream, michael@0: data.Length(), michael@0: const_cast(data.get())); michael@0: if (*written < 0) michael@0: mClosed = true; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: PluginStreamParent::Answer__delete__(const NPError& reason, michael@0: const bool& artificial) michael@0: { michael@0: if (!artificial) michael@0: this->NPN_DestroyStream(reason); michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: PluginStreamParent::NPN_DestroyStream(NPReason reason) michael@0: { michael@0: if (mClosed) michael@0: return; michael@0: michael@0: mInstance->mNPNIface->destroystream(mInstance->mNPP, mStream, reason); michael@0: mClosed = true; michael@0: } michael@0: michael@0: } // namespace plugins michael@0: } // namespace mozilla