Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 : #ifndef nsNPAPIPluginStreamListener_h_
7 : #define nsNPAPIPluginStreamListener_h_
8 :
9 : #include "nscore.h"
10 : #include "nsIHTTPHeaderListener.h"
11 : #include "nsIRequest.h"
12 : #include "nsITimer.h"
13 : #include "nsCOMArray.h"
14 : #include "nsIOutputStream.h"
15 : #include "nsIPluginInstanceOwner.h"
16 : #include "nsString.h"
17 : #include "nsIAsyncVerifyRedirectCallback.h"
18 : #include "mozilla/PluginLibrary.h"
19 :
20 : #define MAX_PLUGIN_NECKO_BUFFER 16384
21 :
22 : class nsPluginStreamListenerPeer;
23 : class nsNPAPIPluginStreamListener;
24 : class nsNPAPIPluginInstance;
25 : class nsIChannel;
26 :
27 : class nsNPAPIStreamWrapper
28 : {
29 : public:
30 : nsNPAPIStreamWrapper(nsIOutputStream *outputStream,
31 : nsNPAPIPluginStreamListener *streamListener);
32 : ~nsNPAPIStreamWrapper();
33 :
34 : nsIOutputStream* GetOutputStream() { return mOutputStream.get(); }
35 0 : nsNPAPIPluginStreamListener* GetStreamListener() { return mStreamListener; }
36 :
37 : NPStream mNPStream;
38 : protected:
39 : nsCOMPtr<nsIOutputStream> mOutputStream; // only valid if not browser initiated
40 : nsNPAPIPluginStreamListener* mStreamListener; // only valid if browser initiated
41 : };
42 :
43 : class nsNPAPIPluginStreamListener : public nsITimerCallback,
44 : public nsIHTTPHeaderListener
45 : {
46 : private:
47 : typedef mozilla::PluginLibrary PluginLibrary;
48 :
49 : public:
50 : NS_DECL_ISUPPORTS
51 : NS_DECL_NSITIMERCALLBACK
52 : NS_DECL_NSIHTTPHEADERLISTENER
53 :
54 : nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, void* notifyData,
55 : const char* aURL);
56 :
57 : nsresult OnStartBinding(nsPluginStreamListenerPeer* streamPeer);
58 : nsresult OnDataAvailable(nsPluginStreamListenerPeer* streamPeer,
59 : nsIInputStream* input,
60 : uint32_t length);
61 : nsresult OnFileAvailable(nsPluginStreamListenerPeer* streamPeer,
62 : const char* fileName);
63 : nsresult OnStopBinding(nsPluginStreamListenerPeer* streamPeer,
64 : nsresult status);
65 : nsresult GetStreamType(int32_t *result);
66 : bool SetStreamType(uint16_t aType, bool aNeedsResume = true);
67 :
68 : bool IsStarted();
69 : nsresult CleanUpStream(NPReason reason);
70 : void CallURLNotify(NPReason reason);
71 0 : void SetCallNotify(bool aCallNotify) { mCallNotify = aCallNotify; }
72 : void SuspendRequest();
73 : void ResumeRequest();
74 : nsresult StartDataPump();
75 : void StopDataPump();
76 : bool PluginInitJSLoadInProgress();
77 :
78 : void* GetNotifyData();
79 0 : nsPluginStreamListenerPeer* GetStreamListenerPeer() { return mStreamListenerPeer; }
80 0 : void SetStreamListenerPeer(nsPluginStreamListenerPeer* aPeer) { mStreamListenerPeer = aPeer; }
81 :
82 : // Returns true if the redirect will be handled by NPAPI, false otherwise.
83 : bool HandleRedirectNotification(nsIChannel *oldChannel, nsIChannel *newChannel,
84 : nsIAsyncVerifyRedirectCallback* callback);
85 : void URLRedirectResponse(NPBool allow);
86 :
87 : protected:
88 :
89 : enum StreamState
90 : {
91 : eStreamStopped = 0, // The stream is stopped
92 : eNewStreamCalled, // NPP_NewStream was called but has not completed yet
93 : eStreamTypeSet // The stream is fully initialized
94 : };
95 :
96 : enum StreamStopMode
97 : {
98 : eNormalStop = 0,
99 : eDoDeferredStop,
100 : eStopPending
101 : };
102 :
103 : virtual ~nsNPAPIPluginStreamListener();
104 : bool MaybeRunStopBinding();
105 :
106 : char* mStreamBuffer;
107 : char* mNotifyURL;
108 : RefPtr<nsNPAPIPluginInstance> mInst;
109 : nsNPAPIStreamWrapper *mNPStreamWrapper;
110 : uint32_t mStreamBufferSize;
111 : int32_t mStreamBufferByteCount;
112 : int32_t mStreamType;
113 : StreamState mStreamState;
114 : bool mStreamCleanedUp;
115 : bool mCallNotify;
116 : bool mIsSuspended;
117 : bool mIsPluginInitJSStream;
118 : bool mRedirectDenied;
119 : nsCString mResponseHeaders;
120 : char* mResponseHeaderBuf;
121 : nsCOMPtr<nsITimer> mDataPumpTimer;
122 : nsCOMPtr<nsIAsyncVerifyRedirectCallback> mHTTPRedirectCallback;
123 : StreamStopMode mStreamStopMode;
124 : nsresult mPendingStopBindingStatus;
125 :
126 : public:
127 : RefPtr<nsPluginStreamListenerPeer> mStreamListenerPeer;
128 : };
129 :
130 : #endif // nsNPAPIPluginStreamListener_h_
|