1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/base/nsNPAPIPluginStreamListener.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsNPAPIPluginStreamListener_h_ 1.10 +#define nsNPAPIPluginStreamListener_h_ 1.11 + 1.12 +#include "nscore.h" 1.13 +#include "nsIHTTPHeaderListener.h" 1.14 +#include "nsIRequest.h" 1.15 +#include "nsITimer.h" 1.16 +#include "nsAutoPtr.h" 1.17 +#include "nsCOMArray.h" 1.18 +#include "nsIOutputStream.h" 1.19 +#include "nsIPluginInstanceOwner.h" 1.20 +#include "nsString.h" 1.21 +#include "nsIAsyncVerifyRedirectCallback.h" 1.22 +#include "mozilla/PluginLibrary.h" 1.23 + 1.24 +#define MAX_PLUGIN_NECKO_BUFFER 16384 1.25 + 1.26 +class nsPluginStreamListenerPeer; 1.27 +class nsNPAPIPluginStreamListener; 1.28 +class nsNPAPIPluginInstance; 1.29 +class nsIChannel; 1.30 + 1.31 +class nsNPAPIStreamWrapper 1.32 +{ 1.33 +public: 1.34 + nsNPAPIStreamWrapper(nsIOutputStream *outputStream, 1.35 + nsNPAPIPluginStreamListener *streamListener); 1.36 + ~nsNPAPIStreamWrapper(); 1.37 + 1.38 + nsIOutputStream* GetOutputStream() { return mOutputStream.get(); } 1.39 + nsNPAPIPluginStreamListener* GetStreamListener() { return mStreamListener; } 1.40 + 1.41 + NPStream mNPStream; 1.42 +protected: 1.43 + nsCOMPtr<nsIOutputStream> mOutputStream; // only valid if not browser initiated 1.44 + nsNPAPIPluginStreamListener* mStreamListener; // only valid if browser initiated 1.45 +}; 1.46 + 1.47 +// Used to handle NPN_NewStream() - writes the stream as received by the plugin 1.48 +// to a file and at completion (NPN_DestroyStream), tells the browser to load it into 1.49 +// a plugin-specified target 1.50 +class nsPluginStreamToFile : public nsIOutputStream 1.51 +{ 1.52 +public: 1.53 + nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); 1.54 + virtual ~nsPluginStreamToFile(); 1.55 + 1.56 + NS_DECL_ISUPPORTS 1.57 + NS_DECL_NSIOUTPUTSTREAM 1.58 +protected: 1.59 + char* mTarget; 1.60 + nsCString mFileURL; 1.61 + nsCOMPtr<nsIFile> mTempFile; 1.62 + nsCOMPtr<nsIOutputStream> mOutputStream; 1.63 + nsIPluginInstanceOwner* mOwner; 1.64 +}; 1.65 + 1.66 +class nsNPAPIPluginStreamListener : public nsITimerCallback, 1.67 + public nsIHTTPHeaderListener 1.68 +{ 1.69 +private: 1.70 + typedef mozilla::PluginLibrary PluginLibrary; 1.71 + 1.72 +public: 1.73 + NS_DECL_ISUPPORTS 1.74 + NS_DECL_NSITIMERCALLBACK 1.75 + NS_DECL_NSIHTTPHEADERLISTENER 1.76 + 1.77 + nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, void* notifyData, 1.78 + const char* aURL); 1.79 + virtual ~nsNPAPIPluginStreamListener(); 1.80 + 1.81 + nsresult OnStartBinding(nsPluginStreamListenerPeer* streamPeer); 1.82 + nsresult OnDataAvailable(nsPluginStreamListenerPeer* streamPeer, 1.83 + nsIInputStream* input, 1.84 + uint32_t length); 1.85 + nsresult OnFileAvailable(nsPluginStreamListenerPeer* streamPeer, 1.86 + const char* fileName); 1.87 + nsresult OnStopBinding(nsPluginStreamListenerPeer* streamPeer, 1.88 + nsresult status); 1.89 + nsresult GetStreamType(int32_t *result); 1.90 + 1.91 + bool IsStarted(); 1.92 + nsresult CleanUpStream(NPReason reason); 1.93 + void CallURLNotify(NPReason reason); 1.94 + void SetCallNotify(bool aCallNotify) { mCallNotify = aCallNotify; } 1.95 + void SuspendRequest(); 1.96 + void ResumeRequest(); 1.97 + nsresult StartDataPump(); 1.98 + void StopDataPump(); 1.99 + bool PluginInitJSLoadInProgress(); 1.100 + 1.101 + void* GetNotifyData(); 1.102 + nsPluginStreamListenerPeer* GetStreamListenerPeer() { return mStreamListenerPeer; } 1.103 + void SetStreamListenerPeer(nsPluginStreamListenerPeer* aPeer) { mStreamListenerPeer = aPeer; } 1.104 + 1.105 + // Returns true if the redirect will be handled by NPAPI, false otherwise. 1.106 + bool HandleRedirectNotification(nsIChannel *oldChannel, nsIChannel *newChannel, 1.107 + nsIAsyncVerifyRedirectCallback* callback); 1.108 + void URLRedirectResponse(NPBool allow); 1.109 + 1.110 +protected: 1.111 + char* mStreamBuffer; 1.112 + char* mNotifyURL; 1.113 + nsRefPtr<nsNPAPIPluginInstance> mInst; 1.114 + nsNPAPIStreamWrapper *mNPStreamWrapper; 1.115 + uint32_t mStreamBufferSize; 1.116 + int32_t mStreamBufferByteCount; 1.117 + int32_t mStreamType; 1.118 + bool mStreamStarted; 1.119 + bool mStreamCleanedUp; 1.120 + bool mCallNotify; 1.121 + bool mIsSuspended; 1.122 + bool mIsPluginInitJSStream; 1.123 + bool mRedirectDenied; 1.124 + nsCString mResponseHeaders; 1.125 + char* mResponseHeaderBuf; 1.126 + nsCOMPtr<nsITimer> mDataPumpTimer; 1.127 + nsCOMPtr<nsIAsyncVerifyRedirectCallback> mHTTPRedirectCallback; 1.128 + 1.129 +public: 1.130 + nsRefPtr<nsPluginStreamListenerPeer> mStreamListenerPeer; 1.131 +}; 1.132 + 1.133 +#endif // nsNPAPIPluginStreamListener_h_