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 "PluginStreamChild.h" |
michael@0 | 7 | #include "mozilla/plugins/PluginInstanceChild.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | namespace plugins { |
michael@0 | 11 | |
michael@0 | 12 | PluginStreamChild::PluginStreamChild() |
michael@0 | 13 | : mClosed(false) |
michael@0 | 14 | { |
michael@0 | 15 | memset(&mStream, 0, sizeof(mStream)); |
michael@0 | 16 | mStream.ndata = static_cast<AStream*>(this); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | bool |
michael@0 | 20 | PluginStreamChild::Answer__delete__(const NPReason& reason, |
michael@0 | 21 | const bool& artificial) |
michael@0 | 22 | { |
michael@0 | 23 | AssertPluginThread(); |
michael@0 | 24 | if (!artificial) |
michael@0 | 25 | NPP_DestroyStream(reason); |
michael@0 | 26 | return true; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | int32_t |
michael@0 | 30 | PluginStreamChild::NPN_Write(int32_t length, void* buffer) |
michael@0 | 31 | { |
michael@0 | 32 | AssertPluginThread(); |
michael@0 | 33 | |
michael@0 | 34 | int32_t written = 0; |
michael@0 | 35 | CallNPN_Write(nsCString(static_cast<char*>(buffer), length), |
michael@0 | 36 | &written); |
michael@0 | 37 | if (written < 0) |
michael@0 | 38 | PPluginStreamChild::Call__delete__(this, NPERR_GENERIC_ERROR, true); |
michael@0 | 39 | // careful after here! |this| just got deleted |
michael@0 | 40 | |
michael@0 | 41 | return written; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | void |
michael@0 | 45 | PluginStreamChild::NPP_DestroyStream(NPError reason) |
michael@0 | 46 | { |
michael@0 | 47 | AssertPluginThread(); |
michael@0 | 48 | |
michael@0 | 49 | if (mClosed) |
michael@0 | 50 | return; |
michael@0 | 51 | |
michael@0 | 52 | mClosed = true; |
michael@0 | 53 | Instance()->mPluginIface->destroystream( |
michael@0 | 54 | &Instance()->mData, &mStream, reason); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | PluginInstanceChild* |
michael@0 | 58 | PluginStreamChild::Instance() |
michael@0 | 59 | { |
michael@0 | 60 | return static_cast<PluginInstanceChild*>(Manager()); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | } // namespace plugins |
michael@0 | 64 | } // namespace mozilla |