michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=80: */ 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 nsIScriptGlobalObject_h__ michael@0: #define nsIScriptGlobalObject_h__ michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsIGlobalObject.h" michael@0: #include "js/TypeDecls.h" michael@0: #include "mozilla/EventForwards.h" michael@0: michael@0: class nsIScriptContext; michael@0: class nsIScriptGlobalObject; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: struct ErrorEventInit; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: // A helper function for nsIScriptGlobalObject implementations to use michael@0: // when handling a script error. Generally called by the global when a context michael@0: // notifies it of an error via nsIScriptGlobalObject::HandleScriptError. michael@0: // Returns true if HandleDOMEvent was actually called, in which case michael@0: // aStatus will be filled in with the status. michael@0: bool michael@0: NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal, michael@0: const mozilla::dom::ErrorEventInit &aErrorEvent, michael@0: nsEventStatus *aStatus); michael@0: michael@0: michael@0: #define NS_ISCRIPTGLOBALOBJECT_IID \ michael@0: { 0x876f83bd, 0x6314, 0x460a, \ michael@0: { 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 } } michael@0: michael@0: /** michael@0: * The global object which keeps a script context for each supported script michael@0: * language. This often used to store per-window global state. michael@0: * This is a heavyweight interface implemented only by DOM globals, and michael@0: * it might go away some time in the future. michael@0: */ michael@0: michael@0: class nsIScriptGlobalObject : public nsIGlobalObject michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID) michael@0: michael@0: /** michael@0: * Ensure that the script global object is initialized for working with the michael@0: * specified script language ID. This will set up the nsIScriptContext michael@0: * and 'script global' for that language, allowing these to be fetched michael@0: * and manipulated. michael@0: * @return NS_OK if successful; error conditions include that the language michael@0: * has not been registered, as well as 'normal' errors, such as michael@0: * out-of-memory michael@0: */ michael@0: virtual nsresult EnsureScriptEnvironment() = 0; michael@0: /** michael@0: * Get a script context (WITHOUT added reference) for the specified language. michael@0: */ michael@0: virtual nsIScriptContext *GetScriptContext() = 0; michael@0: michael@0: nsIScriptContext* GetContext() { michael@0: return GetScriptContext(); michael@0: } michael@0: michael@0: /** michael@0: * Handle a script error. Generally called by a script context. michael@0: */ michael@0: virtual nsresult HandleScriptError( michael@0: const mozilla::dom::ErrorEventInit &aErrorEventInit, michael@0: nsEventStatus *aEventStatus) { michael@0: NS_ENSURE_STATE(NS_HandleScriptError(this, aErrorEventInit, aEventStatus)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; } michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject, michael@0: NS_ISCRIPTGLOBALOBJECT_IID) michael@0: michael@0: #endif