|
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 "nsAutoPtr.h" |
|
14 #include "nsCOMArray.h" |
|
15 #include "nsIOutputStream.h" |
|
16 #include "nsIPluginInstanceOwner.h" |
|
17 #include "nsString.h" |
|
18 #include "nsIAsyncVerifyRedirectCallback.h" |
|
19 #include "mozilla/PluginLibrary.h" |
|
20 |
|
21 #define MAX_PLUGIN_NECKO_BUFFER 16384 |
|
22 |
|
23 class nsPluginStreamListenerPeer; |
|
24 class nsNPAPIPluginStreamListener; |
|
25 class nsNPAPIPluginInstance; |
|
26 class nsIChannel; |
|
27 |
|
28 class nsNPAPIStreamWrapper |
|
29 { |
|
30 public: |
|
31 nsNPAPIStreamWrapper(nsIOutputStream *outputStream, |
|
32 nsNPAPIPluginStreamListener *streamListener); |
|
33 ~nsNPAPIStreamWrapper(); |
|
34 |
|
35 nsIOutputStream* GetOutputStream() { return mOutputStream.get(); } |
|
36 nsNPAPIPluginStreamListener* GetStreamListener() { return mStreamListener; } |
|
37 |
|
38 NPStream mNPStream; |
|
39 protected: |
|
40 nsCOMPtr<nsIOutputStream> mOutputStream; // only valid if not browser initiated |
|
41 nsNPAPIPluginStreamListener* mStreamListener; // only valid if browser initiated |
|
42 }; |
|
43 |
|
44 // Used to handle NPN_NewStream() - writes the stream as received by the plugin |
|
45 // to a file and at completion (NPN_DestroyStream), tells the browser to load it into |
|
46 // a plugin-specified target |
|
47 class nsPluginStreamToFile : public nsIOutputStream |
|
48 { |
|
49 public: |
|
50 nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); |
|
51 virtual ~nsPluginStreamToFile(); |
|
52 |
|
53 NS_DECL_ISUPPORTS |
|
54 NS_DECL_NSIOUTPUTSTREAM |
|
55 protected: |
|
56 char* mTarget; |
|
57 nsCString mFileURL; |
|
58 nsCOMPtr<nsIFile> mTempFile; |
|
59 nsCOMPtr<nsIOutputStream> mOutputStream; |
|
60 nsIPluginInstanceOwner* mOwner; |
|
61 }; |
|
62 |
|
63 class nsNPAPIPluginStreamListener : public nsITimerCallback, |
|
64 public nsIHTTPHeaderListener |
|
65 { |
|
66 private: |
|
67 typedef mozilla::PluginLibrary PluginLibrary; |
|
68 |
|
69 public: |
|
70 NS_DECL_ISUPPORTS |
|
71 NS_DECL_NSITIMERCALLBACK |
|
72 NS_DECL_NSIHTTPHEADERLISTENER |
|
73 |
|
74 nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, void* notifyData, |
|
75 const char* aURL); |
|
76 virtual ~nsNPAPIPluginStreamListener(); |
|
77 |
|
78 nsresult OnStartBinding(nsPluginStreamListenerPeer* streamPeer); |
|
79 nsresult OnDataAvailable(nsPluginStreamListenerPeer* streamPeer, |
|
80 nsIInputStream* input, |
|
81 uint32_t length); |
|
82 nsresult OnFileAvailable(nsPluginStreamListenerPeer* streamPeer, |
|
83 const char* fileName); |
|
84 nsresult OnStopBinding(nsPluginStreamListenerPeer* streamPeer, |
|
85 nsresult status); |
|
86 nsresult GetStreamType(int32_t *result); |
|
87 |
|
88 bool IsStarted(); |
|
89 nsresult CleanUpStream(NPReason reason); |
|
90 void CallURLNotify(NPReason reason); |
|
91 void SetCallNotify(bool aCallNotify) { mCallNotify = aCallNotify; } |
|
92 void SuspendRequest(); |
|
93 void ResumeRequest(); |
|
94 nsresult StartDataPump(); |
|
95 void StopDataPump(); |
|
96 bool PluginInitJSLoadInProgress(); |
|
97 |
|
98 void* GetNotifyData(); |
|
99 nsPluginStreamListenerPeer* GetStreamListenerPeer() { return mStreamListenerPeer; } |
|
100 void SetStreamListenerPeer(nsPluginStreamListenerPeer* aPeer) { mStreamListenerPeer = aPeer; } |
|
101 |
|
102 // Returns true if the redirect will be handled by NPAPI, false otherwise. |
|
103 bool HandleRedirectNotification(nsIChannel *oldChannel, nsIChannel *newChannel, |
|
104 nsIAsyncVerifyRedirectCallback* callback); |
|
105 void URLRedirectResponse(NPBool allow); |
|
106 |
|
107 protected: |
|
108 char* mStreamBuffer; |
|
109 char* mNotifyURL; |
|
110 nsRefPtr<nsNPAPIPluginInstance> mInst; |
|
111 nsNPAPIStreamWrapper *mNPStreamWrapper; |
|
112 uint32_t mStreamBufferSize; |
|
113 int32_t mStreamBufferByteCount; |
|
114 int32_t mStreamType; |
|
115 bool mStreamStarted; |
|
116 bool mStreamCleanedUp; |
|
117 bool mCallNotify; |
|
118 bool mIsSuspended; |
|
119 bool mIsPluginInitJSStream; |
|
120 bool mRedirectDenied; |
|
121 nsCString mResponseHeaders; |
|
122 char* mResponseHeaderBuf; |
|
123 nsCOMPtr<nsITimer> mDataPumpTimer; |
|
124 nsCOMPtr<nsIAsyncVerifyRedirectCallback> mHTTPRedirectCallback; |
|
125 |
|
126 public: |
|
127 nsRefPtr<nsPluginStreamListenerPeer> mStreamListenerPeer; |
|
128 }; |
|
129 |
|
130 #endif // nsNPAPIPluginStreamListener_h_ |