michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsNPAPIPluginStreamListener_h_ michael@0: #define nsNPAPIPluginStreamListener_h_ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsIHTTPHeaderListener.h" michael@0: #include "nsIRequest.h" michael@0: #include "nsITimer.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsIOutputStream.h" michael@0: #include "nsIPluginInstanceOwner.h" michael@0: #include "nsString.h" michael@0: #include "nsIAsyncVerifyRedirectCallback.h" michael@0: #include "mozilla/PluginLibrary.h" michael@0: michael@0: #define MAX_PLUGIN_NECKO_BUFFER 16384 michael@0: michael@0: class nsPluginStreamListenerPeer; michael@0: class nsNPAPIPluginStreamListener; michael@0: class nsNPAPIPluginInstance; michael@0: class nsIChannel; michael@0: michael@0: class nsNPAPIStreamWrapper michael@0: { michael@0: public: michael@0: nsNPAPIStreamWrapper(nsIOutputStream *outputStream, michael@0: nsNPAPIPluginStreamListener *streamListener); michael@0: ~nsNPAPIStreamWrapper(); michael@0: michael@0: nsIOutputStream* GetOutputStream() { return mOutputStream.get(); } michael@0: nsNPAPIPluginStreamListener* GetStreamListener() { return mStreamListener; } michael@0: michael@0: NPStream mNPStream; michael@0: protected: michael@0: nsCOMPtr mOutputStream; // only valid if not browser initiated michael@0: nsNPAPIPluginStreamListener* mStreamListener; // only valid if browser initiated michael@0: }; michael@0: michael@0: // Used to handle NPN_NewStream() - writes the stream as received by the plugin michael@0: // to a file and at completion (NPN_DestroyStream), tells the browser to load it into michael@0: // a plugin-specified target michael@0: class nsPluginStreamToFile : public nsIOutputStream michael@0: { michael@0: public: michael@0: nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); michael@0: virtual ~nsPluginStreamToFile(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIOUTPUTSTREAM michael@0: protected: michael@0: char* mTarget; michael@0: nsCString mFileURL; michael@0: nsCOMPtr mTempFile; michael@0: nsCOMPtr mOutputStream; michael@0: nsIPluginInstanceOwner* mOwner; michael@0: }; michael@0: michael@0: class nsNPAPIPluginStreamListener : public nsITimerCallback, michael@0: public nsIHTTPHeaderListener michael@0: { michael@0: private: michael@0: typedef mozilla::PluginLibrary PluginLibrary; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSITIMERCALLBACK michael@0: NS_DECL_NSIHTTPHEADERLISTENER michael@0: michael@0: nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, void* notifyData, michael@0: const char* aURL); michael@0: virtual ~nsNPAPIPluginStreamListener(); michael@0: michael@0: nsresult OnStartBinding(nsPluginStreamListenerPeer* streamPeer); michael@0: nsresult OnDataAvailable(nsPluginStreamListenerPeer* streamPeer, michael@0: nsIInputStream* input, michael@0: uint32_t length); michael@0: nsresult OnFileAvailable(nsPluginStreamListenerPeer* streamPeer, michael@0: const char* fileName); michael@0: nsresult OnStopBinding(nsPluginStreamListenerPeer* streamPeer, michael@0: nsresult status); michael@0: nsresult GetStreamType(int32_t *result); michael@0: michael@0: bool IsStarted(); michael@0: nsresult CleanUpStream(NPReason reason); michael@0: void CallURLNotify(NPReason reason); michael@0: void SetCallNotify(bool aCallNotify) { mCallNotify = aCallNotify; } michael@0: void SuspendRequest(); michael@0: void ResumeRequest(); michael@0: nsresult StartDataPump(); michael@0: void StopDataPump(); michael@0: bool PluginInitJSLoadInProgress(); michael@0: michael@0: void* GetNotifyData(); michael@0: nsPluginStreamListenerPeer* GetStreamListenerPeer() { return mStreamListenerPeer; } michael@0: void SetStreamListenerPeer(nsPluginStreamListenerPeer* aPeer) { mStreamListenerPeer = aPeer; } michael@0: michael@0: // Returns true if the redirect will be handled by NPAPI, false otherwise. michael@0: bool HandleRedirectNotification(nsIChannel *oldChannel, nsIChannel *newChannel, michael@0: nsIAsyncVerifyRedirectCallback* callback); michael@0: void URLRedirectResponse(NPBool allow); michael@0: michael@0: protected: michael@0: char* mStreamBuffer; michael@0: char* mNotifyURL; michael@0: nsRefPtr mInst; michael@0: nsNPAPIStreamWrapper *mNPStreamWrapper; michael@0: uint32_t mStreamBufferSize; michael@0: int32_t mStreamBufferByteCount; michael@0: int32_t mStreamType; michael@0: bool mStreamStarted; michael@0: bool mStreamCleanedUp; michael@0: bool mCallNotify; michael@0: bool mIsSuspended; michael@0: bool mIsPluginInitJSStream; michael@0: bool mRedirectDenied; michael@0: nsCString mResponseHeaders; michael@0: char* mResponseHeaderBuf; michael@0: nsCOMPtr mDataPumpTimer; michael@0: nsCOMPtr mHTTPRedirectCallback; michael@0: michael@0: public: michael@0: nsRefPtr mStreamListenerPeer; michael@0: }; michael@0: michael@0: #endif // nsNPAPIPluginStreamListener_h_