Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "PluginStreamParent.h" |
michael@0 | 7 | #include "PluginInstanceParent.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | namespace plugins { |
michael@0 | 11 | |
michael@0 | 12 | PluginStreamParent::PluginStreamParent(PluginInstanceParent* npp, |
michael@0 | 13 | const nsCString& mimeType, |
michael@0 | 14 | const nsCString& target, |
michael@0 | 15 | NPError* result) |
michael@0 | 16 | : mInstance(npp) |
michael@0 | 17 | , mClosed(false) |
michael@0 | 18 | { |
michael@0 | 19 | *result = mInstance->mNPNIface->newstream(mInstance->mNPP, |
michael@0 | 20 | const_cast<char*>(mimeType.get()), |
michael@0 | 21 | NullableStringGet(target), |
michael@0 | 22 | &mStream); |
michael@0 | 23 | if (*result == NPERR_NO_ERROR) |
michael@0 | 24 | mStream->pdata = static_cast<AStream*>(this); |
michael@0 | 25 | else |
michael@0 | 26 | mStream = nullptr; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | bool |
michael@0 | 30 | PluginStreamParent::AnswerNPN_Write(const Buffer& data, int32_t* written) |
michael@0 | 31 | { |
michael@0 | 32 | if (mClosed) { |
michael@0 | 33 | *written = -1; |
michael@0 | 34 | return true; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | *written = mInstance->mNPNIface->write(mInstance->mNPP, mStream, |
michael@0 | 38 | data.Length(), |
michael@0 | 39 | const_cast<char*>(data.get())); |
michael@0 | 40 | if (*written < 0) |
michael@0 | 41 | mClosed = true; |
michael@0 | 42 | |
michael@0 | 43 | return true; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | bool |
michael@0 | 47 | PluginStreamParent::Answer__delete__(const NPError& reason, |
michael@0 | 48 | const bool& artificial) |
michael@0 | 49 | { |
michael@0 | 50 | if (!artificial) |
michael@0 | 51 | this->NPN_DestroyStream(reason); |
michael@0 | 52 | return true; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void |
michael@0 | 56 | PluginStreamParent::NPN_DestroyStream(NPReason reason) |
michael@0 | 57 | { |
michael@0 | 58 | if (mClosed) |
michael@0 | 59 | return; |
michael@0 | 60 | |
michael@0 | 61 | mInstance->mNPNIface->destroystream(mInstance->mNPP, mStream, reason); |
michael@0 | 62 | mClosed = true; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | } // namespace plugins |
michael@0 | 66 | } // namespace mozilla |