2009-09-09 10:31:35 +04:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-30 22:51:05 +04:00
|
|
|
|
2009-09-09 18:04:09 +04:00
|
|
|
#ifndef mozilla_plugins_BrowserStreamChild_h
|
|
|
|
#define mozilla_plugins_BrowserStreamChild_h 1
|
2009-06-30 22:51:05 +04:00
|
|
|
|
2009-09-10 02:59:06 +04:00
|
|
|
#include "mozilla/plugins/PBrowserStreamChild.h"
|
2009-09-21 18:51:35 +04:00
|
|
|
#include "mozilla/plugins/AStream.h"
|
2016-05-13 01:15:43 +03:00
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/timer.h"
|
2009-06-30 22:51:05 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace plugins {
|
|
|
|
|
2009-09-09 10:31:35 +04:00
|
|
|
class PluginInstanceChild;
|
2010-03-07 00:03:05 +03:00
|
|
|
class StreamNotifyChild;
|
2009-09-09 10:31:35 +04:00
|
|
|
|
2009-09-21 18:51:35 +04:00
|
|
|
class BrowserStreamChild : public PBrowserStreamChild, public AStream {
|
2009-08-11 03:28:22 +04:00
|
|
|
public:
|
2009-09-09 18:04:09 +04:00
|
|
|
BrowserStreamChild(PluginInstanceChild* instance, const nsCString& url,
|
|
|
|
const uint32_t& length, const uint32_t& lastmodified,
|
2010-03-07 00:03:05 +03:00
|
|
|
StreamNotifyChild* notifyData, const nsCString& headers);
|
|
|
|
virtual ~BrowserStreamChild();
|
2009-09-09 10:31:35 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsBrowserStream() override { return true; }
|
2009-09-21 18:51:35 +04:00
|
|
|
|
2010-01-13 02:06:18 +03:00
|
|
|
NPError StreamConstructed(const nsCString& mimeType, const bool& seekable,
|
|
|
|
uint16_t* stype);
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
virtual mozilla::ipc::IPCResult RecvWrite(const int32_t& offset,
|
|
|
|
const uint32_t& newsize,
|
|
|
|
const Buffer& data) override;
|
|
|
|
virtual mozilla::ipc::IPCResult RecvNPP_DestroyStream(
|
|
|
|
const NPReason& reason) override;
|
|
|
|
virtual mozilla::ipc::IPCResult Recv__delete__() override;
|
2009-09-09 10:31:35 +04:00
|
|
|
|
2009-09-15 23:48:18 +04:00
|
|
|
void EnsureCorrectInstance(PluginInstanceChild* i) {
|
2016-12-03 00:46:53 +03:00
|
|
|
if (i != mInstance) MOZ_CRASH("Incorrect stream instance");
|
2009-09-15 23:48:18 +04:00
|
|
|
}
|
2009-09-23 01:06:00 +04:00
|
|
|
void EnsureCorrectStream(NPStream* s) {
|
2016-12-03 00:46:53 +03:00
|
|
|
if (s != &mStream) MOZ_CRASH("Incorrect stream data");
|
2009-09-23 01:06:00 +04:00
|
|
|
}
|
2009-09-15 23:48:18 +04:00
|
|
|
|
2010-03-07 00:03:05 +03:00
|
|
|
void NotifyPending() {
|
|
|
|
NS_ASSERTION(!mNotifyPending, "Pending twice?");
|
|
|
|
mNotifyPending = true;
|
|
|
|
EnsureDeliveryPending();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* During instance destruction, artificially cancel all outstanding streams.
|
|
|
|
*
|
|
|
|
* @return false if we are already in the DELETING state.
|
|
|
|
*/
|
|
|
|
bool InstanceDying() {
|
|
|
|
if (DELETING == mState) return false;
|
|
|
|
|
|
|
|
mInstanceDying = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishDelivery() {
|
|
|
|
NS_ASSERTION(mInstanceDying, "Should only be called after InstanceDying");
|
|
|
|
NS_ASSERTION(DELETING != mState, "InstanceDying didn't work?");
|
2010-03-11 22:15:48 +03:00
|
|
|
mStreamStatus = NPRES_USER_BREAK;
|
2010-03-07 00:03:05 +03:00
|
|
|
Deliver();
|
|
|
|
NS_ASSERTION(!mStreamNotify, "Didn't deliver NPN_URLNotify?");
|
|
|
|
}
|
|
|
|
|
2009-09-09 10:31:35 +04:00
|
|
|
private:
|
2010-03-07 00:03:05 +03:00
|
|
|
friend class StreamNotifyChild;
|
2010-03-07 00:02:31 +03:00
|
|
|
|
2010-02-24 00:45:00 +03:00
|
|
|
/**
|
2010-03-07 00:03:05 +03:00
|
|
|
* Post an event to ensure delivery of pending data/destroy/urlnotify events
|
|
|
|
* outside of the current RPC stack.
|
|
|
|
*/
|
|
|
|
void EnsureDeliveryPending();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deliver data, destruction, notify scheduling
|
2010-02-24 00:45:00 +03:00
|
|
|
* or cancelling the suspended timer as needed.
|
|
|
|
*/
|
2010-03-07 00:03:05 +03:00
|
|
|
void Deliver();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deliver one chunk of pending data.
|
|
|
|
* @return true if the plugin indicated a pause was necessary
|
|
|
|
*/
|
|
|
|
bool DeliverPendingData();
|
|
|
|
|
2010-02-24 00:45:00 +03:00
|
|
|
void SetSuspendedTimer();
|
|
|
|
void ClearSuspendedTimer();
|
|
|
|
|
2009-09-09 10:31:35 +04:00
|
|
|
PluginInstanceChild* mInstance;
|
|
|
|
NPStream mStream;
|
2010-03-07 00:03:05 +03:00
|
|
|
|
|
|
|
static const NPReason kStreamOpen = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The plugin's notion of whether a stream has been "closed" (no more
|
|
|
|
* data delivery) differs from the plugin host due to asynchronous delivery
|
2017-07-17 20:06:01 +03:00
|
|
|
* of data and stream destruction. While the plugin-visible stream is open,
|
2010-03-07 00:03:05 +03:00
|
|
|
* mStreamStatus should be kStreamOpen (-1). mStreamStatus will be a
|
|
|
|
* failure code if either the parent or child indicates stream failure.
|
|
|
|
*/
|
|
|
|
NPReason mStreamStatus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delivery of NPP_DestroyStream and NPP_URLNotify must be postponed until
|
|
|
|
* all data has been delivered.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
NOT_DESTROYED, // NPP_DestroyStream not yet received
|
|
|
|
DESTROY_PENDING, // NPP_DestroyStream received, not yet delivered
|
|
|
|
DESTROYED // NPP_DestroyStream delivered, NPP_URLNotify may still be
|
|
|
|
// pending
|
|
|
|
} mDestroyPending;
|
|
|
|
bool mNotifyPending;
|
|
|
|
|
|
|
|
// When NPP_Destroy is called for our instance (manager), this flag is set
|
|
|
|
// cancels the stream and avoids sending StreamDestroyed.
|
|
|
|
bool mInstanceDying;
|
|
|
|
|
2010-02-24 00:45:00 +03:00
|
|
|
enum { CONSTRUCTING, ALIVE, DYING, DELETING } mState;
|
2009-09-09 10:31:35 +04:00
|
|
|
nsCString mURL;
|
|
|
|
nsCString mHeaders;
|
2010-03-07 00:03:05 +03:00
|
|
|
StreamNotifyChild* mStreamNotify;
|
2010-03-07 00:02:31 +03:00
|
|
|
|
2010-02-24 00:45:00 +03:00
|
|
|
struct PendingData {
|
|
|
|
int32_t offset;
|
|
|
|
Buffer data;
|
|
|
|
int32_t curpos;
|
|
|
|
};
|
|
|
|
nsTArray<PendingData> mPendingData;
|
|
|
|
|
2010-03-07 00:02:31 +03:00
|
|
|
/**
|
|
|
|
* Asynchronous RecvWrite messages are never delivered to the plugin
|
|
|
|
* immediately, because that may be in the midst of an unexpected RPC
|
|
|
|
* stack frame. It instead posts a runnable using this tracker to cancel
|
|
|
|
* in case we are destroyed.
|
|
|
|
*/
|
2010-03-07 00:03:05 +03:00
|
|
|
ScopedRunnableMethodFactory<BrowserStreamChild> mDeliveryTracker;
|
2010-02-24 00:45:00 +03:00
|
|
|
base::RepeatingTimer<BrowserStreamChild> mSuspendedTimer;
|
2009-06-30 22:51:05 +04:00
|
|
|
};
|
|
|
|
|
2009-09-09 10:31:35 +04:00
|
|
|
} // namespace plugins
|
|
|
|
} // namespace mozilla
|
2009-06-30 22:51:05 +04:00
|
|
|
|
2009-09-09 18:04:09 +04:00
|
|
|
#endif /* mozilla_plugins_BrowserStreamChild_h */
|