1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginStreamParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "PluginStreamParent.h" 1.10 +#include "PluginInstanceParent.h" 1.11 + 1.12 +namespace mozilla { 1.13 +namespace plugins { 1.14 + 1.15 +PluginStreamParent::PluginStreamParent(PluginInstanceParent* npp, 1.16 + const nsCString& mimeType, 1.17 + const nsCString& target, 1.18 + NPError* result) 1.19 + : mInstance(npp) 1.20 + , mClosed(false) 1.21 +{ 1.22 + *result = mInstance->mNPNIface->newstream(mInstance->mNPP, 1.23 + const_cast<char*>(mimeType.get()), 1.24 + NullableStringGet(target), 1.25 + &mStream); 1.26 + if (*result == NPERR_NO_ERROR) 1.27 + mStream->pdata = static_cast<AStream*>(this); 1.28 + else 1.29 + mStream = nullptr; 1.30 +} 1.31 + 1.32 +bool 1.33 +PluginStreamParent::AnswerNPN_Write(const Buffer& data, int32_t* written) 1.34 +{ 1.35 + if (mClosed) { 1.36 + *written = -1; 1.37 + return true; 1.38 + } 1.39 + 1.40 + *written = mInstance->mNPNIface->write(mInstance->mNPP, mStream, 1.41 + data.Length(), 1.42 + const_cast<char*>(data.get())); 1.43 + if (*written < 0) 1.44 + mClosed = true; 1.45 + 1.46 + return true; 1.47 +} 1.48 + 1.49 +bool 1.50 +PluginStreamParent::Answer__delete__(const NPError& reason, 1.51 + const bool& artificial) 1.52 +{ 1.53 + if (!artificial) 1.54 + this->NPN_DestroyStream(reason); 1.55 + return true; 1.56 +} 1.57 + 1.58 +void 1.59 +PluginStreamParent::NPN_DestroyStream(NPReason reason) 1.60 +{ 1.61 + if (mClosed) 1.62 + return; 1.63 + 1.64 + mInstance->mNPNIface->destroystream(mInstance->mNPP, mStream, reason); 1.65 + mClosed = true; 1.66 +} 1.67 + 1.68 +} // namespace plugins 1.69 +} // namespace mozilla