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