Back to index

lightning-sunbird  0.9+nobinonly
nsIScriptContext.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-1999
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 of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 nsIScriptContext_h__
00039 #define nsIScriptContext_h__
00040 
00041 #include "nscore.h"
00042 #include "nsString.h"
00043 #include "nsISupports.h"
00044 #include "nsCOMPtr.h"
00045 #include "jsapi.h"
00046 
00047 class nsIScriptGlobalObject;
00048 class nsIScriptSecurityManager;
00049 class nsIScriptContextOwner;
00050 class nsIPrincipal;
00051 class nsIAtom;
00052 
00053 typedef void (*nsScriptTerminationFunc)(nsISupports* aRef);
00054 
00055 #define NS_ISCRIPTCONTEXT_IID \
00056 { /* b3fd8821-b46d-4160-913f-cc8fe8176f5f */ \
00057   0xb3fd8821, 0xb46d, 0x4160, \
00058   {0x91, 0x3f, 0xcc, 0x8f, 0xe8, 0x17, 0x6f, 0x5f} }
00059 
00067 class nsIScriptContext : public nsISupports
00068 {
00069 public:
00070   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
00071 
00072   
00091   virtual nsresult EvaluateString(const nsAString& aScript,
00092                                   void *aScopeObject,
00093                                   nsIPrincipal *aPrincipal,
00094                                   const char *aURL,
00095                                   PRUint32 aLineNo,
00096                                   const char* aVersion,
00097                                   nsAString *aRetValue,
00098                                   PRBool* aIsUndefined) = 0;
00099 
00100   virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
00101                                            void *aScopeObject,
00102                                            nsIPrincipal *aPrincipal,
00103                                            const char *aURL,
00104                                            PRUint32 aLineNo,
00105                                            const char* aVersion,
00106                                            void* aRetValue,
00107                                            PRBool* aIsUndefined) = 0;
00108 
00127   virtual nsresult CompileScript(const PRUnichar* aText,
00128                                  PRInt32 aTextLength,
00129                                  void* aScopeObject,
00130                                  nsIPrincipal* aPrincipal,
00131                                  const char* aURL,
00132                                  PRUint32 aLineNo,
00133                                  const char* aVersion,
00134                                  void** aScriptObject) = 0;
00135 
00150   virtual nsresult ExecuteScript(void* aScriptObject,
00151                                  void* aScopeObject,
00152                                  nsAString* aRetValue,
00153                                  PRBool* aIsUndefined) = 0;
00154 
00180   virtual nsresult CompileEventHandler(void* aTarget,
00181                                        nsIAtom* aName,
00182                                        const char* aEventName,
00183                                        const nsAString& aBody,
00184                                        const char* aURL,
00185                                        PRUint32 aLineNo,
00186                                        PRBool aShared,
00187                                        void** aHandler) = 0;
00188 
00201   virtual nsresult CallEventHandler(JSObject* aTarget, JSObject* aHandler,
00202                                     uintN argc, jsval* argv,
00203                                     jsval* rval) = 0;
00204 
00221   virtual nsresult BindCompiledEventHandler(void* aTarget,
00222                                             nsIAtom* aName,
00223                                             void* aHandler) = 0;
00224 
00225   virtual nsresult CompileFunction(void* aTarget,
00226                                    const nsACString& aName,
00227                                    PRUint32 aArgCount,
00228                                    const char** aArgArray,
00229                                    const nsAString& aBody,
00230                                    const char* aURL,
00231                                    PRUint32 aLineNo,
00232                                    PRBool aShared,
00233                                    void** aFunctionObject) = 0;
00234 
00235 
00241   virtual void SetDefaultLanguageVersion(const char* aVersion) = 0;
00242 
00247   virtual nsIScriptGlobalObject *GetGlobalObject() = 0;
00248 
00253   virtual void *GetNativeContext() = 0;
00254 
00263   virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject) = 0;
00264 
00272   virtual PRBool IsContextInitialized() = 0;
00273 
00280   virtual void GC() = 0;
00281 
00294   virtual void ScriptEvaluated(PRBool aTerminated) = 0;
00295 
00302   virtual void SetOwner(nsIScriptContextOwner* owner) = 0;
00303 
00310   virtual nsIScriptContextOwner *GetOwner() = 0;
00311 
00320   virtual nsresult SetTerminationFunction(nsScriptTerminationFunc aFunc,
00321                                           nsISupports* aRef) = 0;
00322 
00326   virtual PRBool GetScriptsEnabled() = 0;
00327   virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0;
00328 
00333   virtual PRBool GetProcessingScriptTag() = 0;
00334   virtual void SetProcessingScriptTag(PRBool aResult) = 0;
00335 
00339   virtual void SetGCOnDestruction(PRBool aGCOnDestruction) = 0;
00340 
00347   virtual nsresult InitClasses(JSObject *aGlobalObj) = 0;
00348 
00352   virtual void WillInitializeContext() = 0;
00353 
00357   virtual void DidInitializeContext() = 0;
00358 };
00359 
00360 inline nsIScriptContext *
00361 GetScriptContextFromJSContext(JSContext *cx)
00362 {
00363   if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) {
00364     return nsnull;
00365   }
00366 
00367   nsCOMPtr<nsIScriptContext> scx =
00368     do_QueryInterface(NS_STATIC_CAST(nsISupports *,
00369                                      ::JS_GetContextPrivate(cx)));
00370 
00371   // This will return a pointer to something that's about to be
00372   // released, but that's ok here.
00373   return scx;
00374 }
00375 
00376 #endif // nsIScriptContext_h__
00377