Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/ipc/BrowserStreamParent.cpp
Line
Count
Source (jump to first uncovered line)
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
7
#include "BrowserStreamParent.h"
8
#include "PluginInstanceParent.h"
9
#include "nsNPAPIPlugin.h"
10
11
#include "mozilla/UniquePtr.h"
12
#include "mozilla/Unused.h"
13
14
// How much data are we willing to send across the wire
15
// in one chunk?
16
static const int32_t kSendDataChunk = 0xffff;
17
18
namespace mozilla {
19
namespace plugins {
20
21
BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
22
                                         NPStream* stream)
23
  : mNPP(npp)
24
  , mStream(stream)
25
  , mState(INITIALIZING)
26
0
{
27
0
  mStream->pdata = static_cast<AStream*>(this);
28
0
  nsNPAPIStreamWrapper* wrapper =
29
0
    reinterpret_cast<nsNPAPIStreamWrapper*>(mStream->ndata);
30
0
  if (wrapper) {
31
0
    mStreamListener = wrapper->GetStreamListener();
32
0
  }
33
0
}
34
35
BrowserStreamParent::~BrowserStreamParent()
36
0
{
37
0
  mStream->pdata = nullptr;
38
0
}
39
40
void
41
BrowserStreamParent::ActorDestroy(ActorDestroyReason aWhy)
42
0
{
43
0
  // Implement me! Bug 1005159
44
0
}
45
46
void
47
BrowserStreamParent::NPP_DestroyStream(NPReason reason)
48
0
{
49
0
  NS_ASSERTION(ALIVE == mState || INITIALIZING == mState,
50
0
               "NPP_DestroyStream called twice?");
51
0
  bool stillInitializing = INITIALIZING == mState;
52
0
  if (stillInitializing) {
53
0
    mState = DEFERRING_DESTROY;
54
0
  } else {
55
0
    mState = DYING;
56
0
    Unused << SendNPP_DestroyStream(reason);
57
0
  }
58
0
}
59
60
mozilla::ipc::IPCResult
61
BrowserStreamParent::RecvStreamDestroyed()
62
0
{
63
0
  if (DYING != mState) {
64
0
    NS_ERROR("Unexpected state");
65
0
    return IPC_FAIL_NO_REASON(this);
66
0
  }
67
0
68
0
  mStreamPeer = nullptr;
69
0
70
0
  mState = DELETING;
71
0
  IProtocol* mgr = Manager();
72
0
  if (!Send__delete__(this)) {
73
0
    return IPC_FAIL_NO_REASON(mgr);
74
0
  }
75
0
  return IPC_OK();
76
0
}
77
78
int32_t
79
BrowserStreamParent::WriteReady()
80
0
{
81
0
  if (mState == INITIALIZING) {
82
0
    return 0;
83
0
  }
84
0
  return kSendDataChunk;
85
0
}
86
87
int32_t
88
BrowserStreamParent::Write(int32_t offset,
89
                           int32_t len,
90
                           void* buffer)
91
0
{
92
0
  PLUGIN_LOG_DEBUG_FUNCTION;
93
0
94
0
  NS_ASSERTION(ALIVE == mState, "Sending data after NPP_DestroyStream?");
95
0
  NS_ASSERTION(len > 0, "Non-positive length to NPP_Write");
96
0
97
0
  if (len > kSendDataChunk)
98
0
    len = kSendDataChunk;
99
0
100
0
  return SendWrite(offset,
101
0
                   mStream->end,
102
0
                   nsCString(static_cast<char*>(buffer), len)) ?
103
0
    len : -1;
104
0
}
105
106
} // namespace plugins
107
} // namespace mozilla