Back to index

lightning-sunbird  0.9+nobinonly
XPConnect.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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  *   Adam Lock <adamlock@netscape.com>
00024  *   Paul Oswald <paul.oswald@isinet.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 #ifndef XPCONNECT_H
00040 #define XPCONNECT_H
00041 
00042 #include <servprov.h>
00043 
00044 #ifdef XPC_IDISPATCH_SUPPORT
00045 #include "nsIDispatchSupport.h"
00046 #include "nsIActiveXSecurityPolicy.h"
00047 #endif
00048 
00049 #include "nsID.h"
00050 #include "nsCOMPtr.h"
00051 #include "nsIClassInfo.h"
00052 #include "nsIMozAxPlugin.h"
00053 #include "nsServiceManagerUtils.h"
00054 #include "nsIURI.h"
00055 
00056 #include "ControlEventSink.h"
00057 
00058 struct PluginInstanceData;
00059 
00060 template <class T> class nsIClassInfoImpl : public nsIClassInfo
00061 {
00062     NS_IMETHODIMP GetFlags(PRUint32 *aFlags)
00063     {
00064         *aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
00065         return NS_OK;
00066     }
00067     NS_IMETHODIMP GetImplementationLanguage(PRUint32 *aImplementationLanguage)
00068     {
00069         *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
00070         return NS_OK;
00071     }
00072     // The rest of the methods can safely return error codes...
00073     NS_IMETHODIMP GetInterfaces(PRUint32 *count, nsIID * **array)
00074     { return NS_ERROR_NOT_IMPLEMENTED; }
00075     NS_IMETHODIMP GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
00076     { return NS_ERROR_NOT_IMPLEMENTED; }
00077     NS_IMETHODIMP GetContractID(char * *aContractID)
00078     { return NS_ERROR_NOT_IMPLEMENTED; }
00079     NS_IMETHODIMP GetClassDescription(char * *aClassDescription)
00080     { return NS_ERROR_NOT_IMPLEMENTED; }
00081     NS_IMETHODIMP GetClassID(nsCID * *aClassID)
00082     { return NS_ERROR_NOT_IMPLEMENTED; }
00083     NS_IMETHODIMP GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
00084     { return NS_ERROR_NOT_IMPLEMENTED; }
00085 };
00086 
00087 class nsScriptablePeerTearOff;
00088 
00089 class nsScriptablePeer :
00090     public nsIClassInfoImpl<nsScriptablePeer>,
00091     public nsIMozAxPlugin
00092 {
00093     friend nsScriptablePeerTearOff;
00094 protected:
00095     virtual ~nsScriptablePeer();
00096 
00097 public:
00098     nsScriptablePeer();
00099 
00100     nsScriptablePeerTearOff *mTearOff;
00101     PluginInstanceData* mPlugin;
00102 
00103     NS_DECL_ISUPPORTS
00104     NS_DECL_NSIMOZAXPLUGIN
00105 
00106 protected:
00107     HRESULT GetIDispatch(IDispatch **pdisp);
00108     HRESULT ConvertVariants(nsIVariant *aIn, VARIANT *aOut);
00109     HRESULT ConvertVariants(VARIANT *aIn, nsIVariant **aOut);
00110     nsresult HR2NS(HRESULT hr) const;
00111     NS_IMETHOD InternalInvoke(const char *aMethod, unsigned int aNumArgs, nsIVariant *aArgs[]);
00112 };
00113 
00114 class nsScriptablePeerTearOff :
00115     public IDispatch
00116 {
00117 public:
00118     nsScriptablePeerTearOff(nsScriptablePeer *pOwner);
00119     nsScriptablePeer *mOwner;
00120 
00121 // IUnknown
00122     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
00123     virtual ULONG STDMETHODCALLTYPE AddRef(void);
00124     virtual ULONG STDMETHODCALLTYPE Release( void);
00125 
00126 // IDispatch
00127     virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT __RPC_FAR *pctinfo);
00128     virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
00129     virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId);
00130     virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
00131 };
00132 
00133 #ifdef XPC_IDISPATCH_SUPPORT
00134 class nsEventSink : public CControlEventSink
00135 {
00136 public:
00137     PluginInstanceData* mPlugin;
00138 
00139     virtual HRESULT InternalInvoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
00140 };
00141 
00142 typedef CComObject<nsEventSink> nsEventSinkInstance;
00143 #endif
00144 
00145 namespace MozAxPlugin {
00146     extern void AddRef();
00147     extern void Release();
00148     extern CLSID GetCLSIDForType(const char *mimeType);
00149     extern NPError GetValue(NPP instance, NPPVariable variable, void *value);
00150     extern nsScriptablePeer *GetPeerForCLSID(const CLSID &clsid);
00151     extern void GetIIDForCLSID(const CLSID &clsid, nsIID &iid);
00152     extern HRESULT GetServiceProvider(PluginInstanceData *pData, IServiceProvider **pSP);
00153 #ifdef XPC_IDISPATCH_SUPPORT
00154     extern PRUint32 PrefGetHostingFlags();
00155     extern void ReleasePrefObserver();
00156     extern nsresult GetCurrentLocation(NPP instance, nsIURI **aLocation);
00157 #endif
00158 }
00159 
00160 #endif