michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsIScriptContext_h__ michael@0: #define nsIScriptContext_h__ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsStringGlue.h" michael@0: #include "nsISupports.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIProgrammingLanguage.h" michael@0: #include "jspubtd.h" michael@0: #include "js/GCAPI.h" michael@0: michael@0: class nsIScriptGlobalObject; michael@0: class nsIScriptSecurityManager; michael@0: class nsIPrincipal; michael@0: class nsIAtom; michael@0: class nsIArray; michael@0: class nsIVariant; michael@0: class nsIObjectInputStream; michael@0: class nsIObjectOutputStream; michael@0: class nsIScriptObjectPrincipal; michael@0: class nsIDOMWindow; michael@0: class nsIURI; michael@0: michael@0: #define NS_ISCRIPTCONTEXT_IID \ michael@0: { 0x274840b6, 0x7349, 0x4798, \ michael@0: { 0xbe, 0x24, 0xbd, 0x75, 0xa6, 0x46, 0x99, 0xb7 } } michael@0: michael@0: /* This MUST match JSVERSION_DEFAULT. This version stuff if we don't michael@0: know what language we have is a little silly... */ michael@0: #define SCRIPTVERSION_DEFAULT JSVERSION_DEFAULT michael@0: michael@0: class nsIOffThreadScriptReceiver; michael@0: michael@0: /** michael@0: * It is used by the application to initialize a runtime and run scripts. michael@0: * A script runtime would implement this interface. michael@0: */ michael@0: class nsIScriptContext : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID) michael@0: michael@0: /** michael@0: * Return the global object. michael@0: * michael@0: **/ michael@0: virtual nsIScriptGlobalObject *GetGlobalObject() = 0; michael@0: michael@0: /** michael@0: * Return the native script context michael@0: * michael@0: **/ michael@0: virtual JSContext* GetNativeContext() = 0; michael@0: michael@0: /** michael@0: * Initialize the context generally. Does not create a global object. michael@0: **/ michael@0: virtual nsresult InitContext() = 0; michael@0: michael@0: /** michael@0: * Check to see if context is as yet intialized. Used to prevent michael@0: * reentrancy issues during the initialization process. michael@0: * michael@0: * @return true if initialized, false if not michael@0: * michael@0: */ michael@0: virtual bool IsContextInitialized() = 0; michael@0: michael@0: /** michael@0: * For garbage collected systems, do a synchronous collection pass. michael@0: * May be a no-op on other systems michael@0: * michael@0: * @return NS_OK if the method is successful michael@0: */ michael@0: virtual void GC(JS::gcreason::Reason aReason) = 0; michael@0: michael@0: // SetProperty is suspect and jst believes should not be needed. Currenly michael@0: // used only for "arguments". michael@0: virtual nsresult SetProperty(JS::Handle aTarget, michael@0: const char* aPropName, nsISupports* aVal) = 0; michael@0: /** michael@0: * Called to set/get information if the script context is michael@0: * currently processing a script tag michael@0: */ michael@0: virtual bool GetProcessingScriptTag() = 0; michael@0: virtual void SetProcessingScriptTag(bool aResult) = 0; michael@0: michael@0: /** michael@0: * Initialize DOM classes on aGlobalObj, always call michael@0: * WillInitializeContext() before calling InitContext(), and always michael@0: * call DidInitializeContext() when a context is fully michael@0: * (successfully) initialized. michael@0: */ michael@0: virtual nsresult InitClasses(JS::Handle aGlobalObj) = 0; michael@0: michael@0: /** michael@0: * Tell the context we're about to be reinitialize it. michael@0: */ michael@0: virtual void WillInitializeContext() = 0; michael@0: michael@0: /** michael@0: * Tell the context we're done reinitializing it. michael@0: */ michael@0: virtual void DidInitializeContext() = 0; michael@0: michael@0: /** michael@0: * Access the Window Proxy. The setter should only be called by nsGlobalWindow. michael@0: */ michael@0: virtual void SetWindowProxy(JS::Handle aWindowProxy) = 0; michael@0: virtual JSObject* GetWindowProxy() = 0; michael@0: virtual JSObject* GetWindowProxyPreserveColor() = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContext, NS_ISCRIPTCONTEXT_IID) michael@0: michael@0: #define NS_IOFFTHREADSCRIPTRECEIVER_IID \ michael@0: {0x3a980010, 0x878d, 0x46a9, \ michael@0: {0x93, 0xad, 0xbc, 0xfd, 0xd3, 0x8e, 0xa0, 0xc2}} michael@0: michael@0: class nsIOffThreadScriptReceiver : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IOFFTHREADSCRIPTRECEIVER_IID) michael@0: michael@0: /** michael@0: * Notify this object that a previous CompileScript call specifying this as michael@0: * aOffThreadReceiver has completed. The script being passed in must be michael@0: * rooted before any call which could trigger GC. michael@0: */ michael@0: NS_IMETHOD OnScriptCompileComplete(JSScript* aScript, nsresult aStatus) = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIOffThreadScriptReceiver, NS_IOFFTHREADSCRIPTRECEIVER_IID) michael@0: michael@0: #endif // nsIScriptContext_h__ michael@0: