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