Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsNPAPIPluginStreamListener_h_ |
michael@0 | 7 | #define nsNPAPIPluginStreamListener_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nscore.h" |
michael@0 | 10 | #include "nsIHTTPHeaderListener.h" |
michael@0 | 11 | #include "nsIRequest.h" |
michael@0 | 12 | #include "nsITimer.h" |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | #include "nsCOMArray.h" |
michael@0 | 15 | #include "nsIOutputStream.h" |
michael@0 | 16 | #include "nsIPluginInstanceOwner.h" |
michael@0 | 17 | #include "nsString.h" |
michael@0 | 18 | #include "nsIAsyncVerifyRedirectCallback.h" |
michael@0 | 19 | #include "mozilla/PluginLibrary.h" |
michael@0 | 20 | |
michael@0 | 21 | #define MAX_PLUGIN_NECKO_BUFFER 16384 |
michael@0 | 22 | |
michael@0 | 23 | class nsPluginStreamListenerPeer; |
michael@0 | 24 | class nsNPAPIPluginStreamListener; |
michael@0 | 25 | class nsNPAPIPluginInstance; |
michael@0 | 26 | class nsIChannel; |
michael@0 | 27 | |
michael@0 | 28 | class nsNPAPIStreamWrapper |
michael@0 | 29 | { |
michael@0 | 30 | public: |
michael@0 | 31 | nsNPAPIStreamWrapper(nsIOutputStream *outputStream, |
michael@0 | 32 | nsNPAPIPluginStreamListener *streamListener); |
michael@0 | 33 | ~nsNPAPIStreamWrapper(); |
michael@0 | 34 | |
michael@0 | 35 | nsIOutputStream* GetOutputStream() { return mOutputStream.get(); } |
michael@0 | 36 | nsNPAPIPluginStreamListener* GetStreamListener() { return mStreamListener; } |
michael@0 | 37 | |
michael@0 | 38 | NPStream mNPStream; |
michael@0 | 39 | protected: |
michael@0 | 40 | nsCOMPtr<nsIOutputStream> mOutputStream; // only valid if not browser initiated |
michael@0 | 41 | nsNPAPIPluginStreamListener* mStreamListener; // only valid if browser initiated |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | // Used to handle NPN_NewStream() - writes the stream as received by the plugin |
michael@0 | 45 | // to a file and at completion (NPN_DestroyStream), tells the browser to load it into |
michael@0 | 46 | // a plugin-specified target |
michael@0 | 47 | class nsPluginStreamToFile : public nsIOutputStream |
michael@0 | 48 | { |
michael@0 | 49 | public: |
michael@0 | 50 | nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner); |
michael@0 | 51 | virtual ~nsPluginStreamToFile(); |
michael@0 | 52 | |
michael@0 | 53 | NS_DECL_ISUPPORTS |
michael@0 | 54 | NS_DECL_NSIOUTPUTSTREAM |
michael@0 | 55 | protected: |
michael@0 | 56 | char* mTarget; |
michael@0 | 57 | nsCString mFileURL; |
michael@0 | 58 | nsCOMPtr<nsIFile> mTempFile; |
michael@0 | 59 | nsCOMPtr<nsIOutputStream> mOutputStream; |
michael@0 | 60 | nsIPluginInstanceOwner* mOwner; |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | class nsNPAPIPluginStreamListener : public nsITimerCallback, |
michael@0 | 64 | public nsIHTTPHeaderListener |
michael@0 | 65 | { |
michael@0 | 66 | private: |
michael@0 | 67 | typedef mozilla::PluginLibrary PluginLibrary; |
michael@0 | 68 | |
michael@0 | 69 | public: |
michael@0 | 70 | NS_DECL_ISUPPORTS |
michael@0 | 71 | NS_DECL_NSITIMERCALLBACK |
michael@0 | 72 | NS_DECL_NSIHTTPHEADERLISTENER |
michael@0 | 73 | |
michael@0 | 74 | nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, void* notifyData, |
michael@0 | 75 | const char* aURL); |
michael@0 | 76 | virtual ~nsNPAPIPluginStreamListener(); |
michael@0 | 77 | |
michael@0 | 78 | nsresult OnStartBinding(nsPluginStreamListenerPeer* streamPeer); |
michael@0 | 79 | nsresult OnDataAvailable(nsPluginStreamListenerPeer* streamPeer, |
michael@0 | 80 | nsIInputStream* input, |
michael@0 | 81 | uint32_t length); |
michael@0 | 82 | nsresult OnFileAvailable(nsPluginStreamListenerPeer* streamPeer, |
michael@0 | 83 | const char* fileName); |
michael@0 | 84 | nsresult OnStopBinding(nsPluginStreamListenerPeer* streamPeer, |
michael@0 | 85 | nsresult status); |
michael@0 | 86 | nsresult GetStreamType(int32_t *result); |
michael@0 | 87 | |
michael@0 | 88 | bool IsStarted(); |
michael@0 | 89 | nsresult CleanUpStream(NPReason reason); |
michael@0 | 90 | void CallURLNotify(NPReason reason); |
michael@0 | 91 | void SetCallNotify(bool aCallNotify) { mCallNotify = aCallNotify; } |
michael@0 | 92 | void SuspendRequest(); |
michael@0 | 93 | void ResumeRequest(); |
michael@0 | 94 | nsresult StartDataPump(); |
michael@0 | 95 | void StopDataPump(); |
michael@0 | 96 | bool PluginInitJSLoadInProgress(); |
michael@0 | 97 | |
michael@0 | 98 | void* GetNotifyData(); |
michael@0 | 99 | nsPluginStreamListenerPeer* GetStreamListenerPeer() { return mStreamListenerPeer; } |
michael@0 | 100 | void SetStreamListenerPeer(nsPluginStreamListenerPeer* aPeer) { mStreamListenerPeer = aPeer; } |
michael@0 | 101 | |
michael@0 | 102 | // Returns true if the redirect will be handled by NPAPI, false otherwise. |
michael@0 | 103 | bool HandleRedirectNotification(nsIChannel *oldChannel, nsIChannel *newChannel, |
michael@0 | 104 | nsIAsyncVerifyRedirectCallback* callback); |
michael@0 | 105 | void URLRedirectResponse(NPBool allow); |
michael@0 | 106 | |
michael@0 | 107 | protected: |
michael@0 | 108 | char* mStreamBuffer; |
michael@0 | 109 | char* mNotifyURL; |
michael@0 | 110 | nsRefPtr<nsNPAPIPluginInstance> mInst; |
michael@0 | 111 | nsNPAPIStreamWrapper *mNPStreamWrapper; |
michael@0 | 112 | uint32_t mStreamBufferSize; |
michael@0 | 113 | int32_t mStreamBufferByteCount; |
michael@0 | 114 | int32_t mStreamType; |
michael@0 | 115 | bool mStreamStarted; |
michael@0 | 116 | bool mStreamCleanedUp; |
michael@0 | 117 | bool mCallNotify; |
michael@0 | 118 | bool mIsSuspended; |
michael@0 | 119 | bool mIsPluginInitJSStream; |
michael@0 | 120 | bool mRedirectDenied; |
michael@0 | 121 | nsCString mResponseHeaders; |
michael@0 | 122 | char* mResponseHeaderBuf; |
michael@0 | 123 | nsCOMPtr<nsITimer> mDataPumpTimer; |
michael@0 | 124 | nsCOMPtr<nsIAsyncVerifyRedirectCallback> mHTTPRedirectCallback; |
michael@0 | 125 | |
michael@0 | 126 | public: |
michael@0 | 127 | nsRefPtr<nsPluginStreamListenerPeer> mStreamListenerPeer; |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | #endif // nsNPAPIPluginStreamListener_h_ |