Back to index

lightning-sunbird  0.9+nobinonly
nsURLDataCallback.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Adam Lock <adamlock@netscape.com>
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 #ifndef __NSURLDATACALLBACK_H_
00038 #define __NSURLDATACALLBACK_H_
00039 
00040 #include "resource.h"       // main symbols
00041 
00042 #include <stdio.h>
00043 
00044 #include "npapi.h"
00045 
00046 class nsPluginHostCtrl;
00047 
00048 #define WM_NPP_NEWSTREAM      WM_USER 
00049 #define WM_NPP_DESTROYSTREAM  WM_USER + 1
00050 #define WM_NPP_URLNOTIFY      WM_USER + 2
00051 #define WM_NPP_WRITEREADY     WM_USER + 3
00052 #define WM_NPP_WRITE          WM_USER + 4
00053 
00054 #define WM_CLASS_CLEANUP      WM_USER + 10
00055 #define WM_CLASS_CREATEPLUGININSTANCE WM_USER + 11
00056 
00057 struct _DestroyStreamData
00058 {
00059     NPP npp;
00060     NPStream *stream;
00061     NPReason reason;
00062 };
00063 
00064 struct _UrlNotifyData
00065 {
00066     NPP npp;
00067     char *url;
00068     NPReason reason;
00069     void *notifydata;
00070 };
00071 
00072 struct _NewStreamData
00073 {
00074     NPP npp;
00075     char *contenttype;
00076     NPStream *stream;
00077     NPBool seekable;
00078     uint16 *stype;
00079 };
00080 
00081 struct _WriteReadyData
00082 {
00083     NPP npp;
00084     NPStream *stream;
00085     int32 result;
00086 };
00087 
00088 struct _WriteData
00089 {
00090     NPP npp;
00091     NPStream *stream;
00092     int32 offset;
00093     int32 len;
00094     void* buffer;
00095 };
00096 
00098 // nsURLDataCallback
00099 class ATL_NO_VTABLE nsURLDataCallback : 
00100     public CComObjectRootEx<CComMultiThreadModel>,
00101     public CWindowImpl<nsURLDataCallback, CWindow, CNullTraits>,
00102     public CComCoClass<nsURLDataCallback, &CLSID_NULL>,
00103     public IBindStatusCallback,
00104     public IAuthenticate
00105 {
00106 public:
00107     nsURLDataCallback();
00108 
00109 DECLARE_PROTECT_FINAL_CONSTRUCT()
00110 
00111 BEGIN_COM_MAP(nsURLDataCallback)
00112     COM_INTERFACE_ENTRY(IBindStatusCallback)
00113     COM_INTERFACE_ENTRY(IAuthenticate)
00114 END_COM_MAP()
00115 
00116     DECLARE_WND_CLASS(_T("MozStreamWindow"))
00117 
00118 BEGIN_MSG_MAP(nsURLDataCallback)
00119     MESSAGE_HANDLER(WM_NPP_NEWSTREAM, OnNPPNewStream)
00120     MESSAGE_HANDLER(WM_NPP_DESTROYSTREAM, OnNPPDestroyStream)
00121     MESSAGE_HANDLER(WM_NPP_URLNOTIFY, OnNPPURLNotify)
00122     MESSAGE_HANDLER(WM_NPP_WRITEREADY, OnNPPWriteReady)
00123     MESSAGE_HANDLER(WM_NPP_WRITE, OnNPPWrite)
00124     MESSAGE_HANDLER(WM_CLASS_CLEANUP, OnClassCleanup)
00125     MESSAGE_HANDLER(WM_CLASS_CREATEPLUGININSTANCE, OnClassCreatePluginInstance)
00126 END_MSG_MAP()
00127 
00128     LRESULT OnNPPNewStream(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00129     LRESULT OnNPPDestroyStream(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00130     LRESULT OnNPPURLNotify(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00131     LRESULT OnNPPWriteReady(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00132     LRESULT OnNPPWrite(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00133 
00134     LRESULT OnClassCreatePluginInstance(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00135     LRESULT OnClassCleanup(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
00136 
00137 protected:
00138     virtual ~nsURLDataCallback();
00139 
00140 protected:
00141     nsPluginHostCtrl *m_pOwner;
00142     void *m_pNotifyData;
00143     HGLOBAL m_hPostData;
00144 
00145     NPStream m_NPStream;
00146     unsigned long m_nDataPos;
00147     unsigned long m_nDataMax;
00148 
00149     char *m_szContentType;
00150     char *m_szURL;
00151 
00152     BOOL m_bSaveToTempFile;
00153     BOOL m_bNotifyOnWrite;
00154     FILE *m_pTempFile;
00155     char *m_szTempFileName;
00156 
00157     CComPtr<IBinding> m_cpBinding;
00158 
00159     void SetURL(const char *szURL)
00160     {
00161         if (m_szURL) { free(m_szURL); m_szURL = NULL; }
00162         if (szURL) { m_szURL = strdup(szURL); }
00163     }
00164     void SetContentType(const char *szContentType)
00165     {
00166         if (m_szContentType) { free(m_szContentType); m_szContentType = NULL; }
00167         if (szContentType) { m_szContentType = strdup(szContentType); }
00168     }
00169     void SetPostData(const void *pData, unsigned long nSize);
00170     void SetOwner(nsPluginHostCtrl *pOwner) { m_pOwner = pOwner; }
00171     void SetNotifyData(void *pNotifyData)   { m_pNotifyData = pNotifyData; }
00172     
00173     static void __cdecl StreamThread(void *pThis);
00174 
00175 public:
00176     static HRESULT OpenURL(nsPluginHostCtrl *pOwner, const TCHAR *szURL, void *pNotifyData, const void *pData, unsigned long nSize);
00177 
00178 // IBindStatusCallback
00179 public:
00180     virtual HRESULT STDMETHODCALLTYPE OnStartBinding( 
00181         /* [in] */ DWORD dwReserved,
00182         /* [in] */ IBinding __RPC_FAR *pib);
00183     
00184     virtual HRESULT STDMETHODCALLTYPE GetPriority( 
00185         /* [out] */ LONG __RPC_FAR *pnPriority);
00186     
00187     virtual HRESULT STDMETHODCALLTYPE OnLowResource( 
00188         /* [in] */ DWORD reserved);
00189     
00190     virtual HRESULT STDMETHODCALLTYPE OnProgress( 
00191         /* [in] */ ULONG ulProgress,
00192         /* [in] */ ULONG ulProgressMax,
00193         /* [in] */ ULONG ulStatusCode,
00194         /* [in] */ LPCWSTR szStatusText);
00195     
00196     virtual HRESULT STDMETHODCALLTYPE OnStopBinding( 
00197         /* [in] */ HRESULT hresult,
00198         /* [unique][in] */ LPCWSTR szError);
00199     
00200     virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetBindInfo( 
00201         /* [out] */ DWORD __RPC_FAR *grfBINDF,
00202         /* [unique][out][in] */ BINDINFO __RPC_FAR *pbindinfo);
00203     
00204     virtual /* [local] */ HRESULT STDMETHODCALLTYPE OnDataAvailable( 
00205         /* [in] */ DWORD grfBSCF,
00206         /* [in] */ DWORD dwSize,
00207         /* [in] */ FORMATETC __RPC_FAR *pformatetc,
00208         /* [in] */ STGMEDIUM __RPC_FAR *pstgmed);
00209     
00210     virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable( 
00211         /* [in] */ REFIID riid,
00212         /* [iid_is][in] */ IUnknown __RPC_FAR *punk);
00213 
00214 // IAuthenticate
00215 public:
00216     virtual HRESULT STDMETHODCALLTYPE Authenticate( 
00217         /* [out] */ HWND __RPC_FAR *phwnd,
00218         /* [out] */ LPWSTR __RPC_FAR *pszUsername,
00219         /* [out] */ LPWSTR __RPC_FAR *pszPassword);
00220 };
00221 
00222 #endif //__NSURLDATACALLBACK_H_