Back to index

lightning-sunbird  0.9+nobinonly
ns4xPluginStreamListener.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef ns4xPluginStreamListener_h__
00039 #define ns4xPluginStreamListener_h__
00040 
00041 #include "nsIPluginStreamListener.h"
00042 #include "nsIPluginStreamInfo.h"
00043 #include "nsIHTTPHeaderListener.h"
00044 #include "nsIRequest.h"
00045 #include "nsITimer.h"
00046 #include "nsCOMPtr.h"
00047 
00048 #define MAX_PLUGIN_NECKO_BUFFER 16384
00049 
00050 class ns4xPluginInstance;
00051 class nsI4xPluginStreamInfo;
00052 
00053 class ns4xPluginStreamListener : public nsIPluginStreamListener,
00054                                  public nsITimerCallback,
00055                                  public nsIHTTPHeaderListener_MOZILLA_1_8_BRANCH
00056 {
00057 public:
00058   NS_DECL_ISUPPORTS
00059 
00060   // from nsIPluginStreamListener:
00061   NS_IMETHOD OnStartBinding(nsIPluginStreamInfo* pluginInfo);
00062   NS_IMETHOD OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
00063                              nsIInputStream* input, PRUint32 length);
00064   NS_IMETHOD OnFileAvailable( nsIPluginStreamInfo* pluginInfo,
00065                               const char* fileName);
00066   NS_IMETHOD OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status);
00067   NS_IMETHOD GetStreamType(nsPluginStreamType *result);
00068 
00069   NS_DECL_NSITIMERCALLBACK
00070 
00071   // from nsIHTTPHeaderListener:
00072   NS_IMETHOD StatusLine(const char* line);
00073   NS_IMETHOD NewResponseHeader(const char* headerName, const char* headerValue);
00074 
00075   // ns4xPluginStreamListener specific methods:
00076   ns4xPluginStreamListener(nsIPluginInstance* inst, void* notifyData,
00077                            const char* aURL);
00078   virtual ~ns4xPluginStreamListener();
00079   PRBool IsStarted();
00080   nsresult CleanUpStream(NPReason reason);
00081   void CallURLNotify(NPReason reason);
00082   void SetCallNotify(PRBool aCallNotify)
00083   {
00084     mCallNotify = aCallNotify;
00085   }
00086   nsresult SuspendRequest();
00087   void ResumeRequest();
00088   nsresult StartDataPump();
00089   void StopDataPump();
00090 
00091 protected:
00092   void* mNotifyData;
00093   char* mStreamBuffer;
00094   char* mNotifyURL;
00095   ns4xPluginInstance* mInst;
00096   NPStream mNPStream;
00097   PRUint32 mStreamBufferSize;
00098   PRInt32 mStreamBufferByteCount;
00099   nsPluginStreamType mStreamType;
00100   PRPackedBool mStreamStarted;
00101   PRPackedBool mStreamCleanedUp;
00102   PRPackedBool mCallNotify;
00103   PRPackedBool mIsSuspended;
00104   nsCString mResponseHeaders;
00105   char* mResponseHeaderBuf;
00106 
00107   nsCOMPtr<nsITimer> mDataPumpTimer;
00108 
00109 public:
00110   nsCOMPtr<nsIPluginStreamInfo> mStreamInfo;
00111 };
00112 
00113 // nsI4xPluginStreamInfo is an internal helper interface that exposes
00114 // the underlying necko request to consumers of nsIPluginStreamInfo's.
00115 #define NS_I4XPLUGINSTREAMINFO_IID       \
00116 { 0x097fdaaa, 0xa2a3, 0x49c2, \
00117   {0x91, 0xee, 0xeb, 0xc5, 0x7d, 0x6c, 0x9c, 0x97} }
00118 
00119 class nsI4xPluginStreamInfo : public nsIPluginStreamInfo
00120 {
00121 public:
00122   NS_DEFINE_STATIC_IID_ACCESSOR(NS_I4XPLUGINSTREAMINFO_IID)
00123 
00124   nsIRequest *GetRequest()
00125   {
00126     return mRequest;
00127   }
00128 
00129 protected:
00130   nsCOMPtr<nsIRequest> mRequest;
00131 };
00132 
00133 #endif