2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-08-15 18:16:42 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2001-09-25 22:43:09 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-23 18:43:06 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-06-23 18:43:06 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-06-23 18:43:06 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:43:09 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:43:09 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:43:09 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-06-23 18:43:06 +00:00
|
|
|
|
|
|
|
#ifndef nsIScriptGlobalObject_h__
|
|
|
|
#define nsIScriptGlobalObject_h__
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
2006-06-26 11:11:57 +00:00
|
|
|
#include "nsEvent.h"
|
2006-06-13 03:07:47 +00:00
|
|
|
#include "nsIProgrammingLanguage.h"
|
1998-06-23 18:43:06 +00:00
|
|
|
|
|
|
|
class nsIScriptContext;
|
|
|
|
class nsIDOMDocument;
|
1998-07-24 05:05:42 +00:00
|
|
|
class nsIDOMEvent;
|
2004-07-31 23:15:21 +00:00
|
|
|
class nsPresContext;
|
1999-12-03 09:24:22 +00:00
|
|
|
class nsIScriptGlobalObjectOwner;
|
2006-06-13 03:07:47 +00:00
|
|
|
class nsIArray;
|
|
|
|
class nsScriptErrorEvent;
|
|
|
|
class nsIScriptGlobalObject;
|
|
|
|
struct JSObject; // until we finally remove GetGlobalJSObject...
|
|
|
|
|
|
|
|
// Some helpers for working with integer "script type IDs", and specifically
|
|
|
|
// for working with arrays of such objects. For example, it is common for
|
|
|
|
// implementations supporting multiple script languages to keep each
|
|
|
|
// language's nsIScriptContext in an array indexed by the language ID.
|
|
|
|
|
|
|
|
// Implementation note: We always ignore nsIProgrammingLanguage::UNKNOWN and
|
|
|
|
// nsIProgrammingLanguage::CPLUSPLUS - this gives javascript slot 0. An
|
|
|
|
// attempted micro-optimization tried to avoid us going all the way to
|
|
|
|
// nsIProgrammingLanguage::MAX; however:
|
|
|
|
// * Someone is reportedly working on a PHP impl - that has value 9
|
|
|
|
// * nsGenericElement therefore allows 4 bits for the value.
|
|
|
|
// So there is no good reason for us to be more restrictive again...
|
|
|
|
|
|
|
|
#define NS_STID_FIRST nsIProgrammingLanguage::JAVASCRIPT
|
|
|
|
// like nsGenericElement, only 4 bits worth is valid...
|
|
|
|
#define NS_STID_LAST (nsIProgrammingLanguage::MAX > 0x000FU ? \
|
|
|
|
0x000FU : nsIProgrammingLanguage::MAX)
|
|
|
|
|
|
|
|
// Use to declare the array size
|
|
|
|
#define NS_STID_ARRAY_UBOUND (NS_STID_LAST-NS_STID_FIRST+1)
|
|
|
|
|
|
|
|
// Is a language ID valid?
|
|
|
|
#define NS_STID_VALID(langID) (langID >= NS_STID_FIRST && langID <= NS_STID_LAST)
|
|
|
|
|
|
|
|
// Return an index for a given ID.
|
|
|
|
#define NS_STID_INDEX(langID) (langID-NS_STID_FIRST)
|
|
|
|
|
|
|
|
// Create a 'for' loop iterating over all possible language IDs (*not* indexes)
|
|
|
|
#define NS_STID_FOR_ID(varName) \
|
|
|
|
for (varName=NS_STID_FIRST;varName<=NS_STID_LAST;varName++)
|
|
|
|
|
|
|
|
// Create a 'for' loop iterating over all indexes (when you don't need to know
|
|
|
|
// what language it is)
|
|
|
|
#define NS_STID_FOR_INDEX(varName) \
|
|
|
|
for (varName=0;varName<=NS_STID_INDEX(NS_STID_LAST);varName++)
|
|
|
|
|
|
|
|
// A helper function for nsIScriptGlobalObject implementations to use
|
|
|
|
// when handling a script error. Generally called by the global when a context
|
|
|
|
// notifies it of an error via nsIScriptGlobalObject::HandleScriptError.
|
|
|
|
// Returns PR_TRUE if HandleDOMEvent was actually called, in which case
|
|
|
|
// aStatus will be filled in with the status.
|
|
|
|
PRBool
|
|
|
|
NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
|
|
|
|
nsScriptErrorEvent *aErrorEvent,
|
|
|
|
nsEventStatus *aStatus);
|
|
|
|
|
1998-06-23 18:43:06 +00:00
|
|
|
|
|
|
|
#define NS_ISCRIPTGLOBALOBJECT_IID \
|
2007-08-09 22:30:30 +00:00
|
|
|
{ /* {6afecd40-0b9a-4cfd-8c42-0f645cd91829} */ \
|
|
|
|
0x6afecd40, 0x0b9a, 0x4cfd, \
|
|
|
|
{ 0x8c, 0x42, 0x0f, 0x64, 0x5c, 0xd9, 0x18, 0x29 } }
|
1998-06-23 18:43:06 +00:00
|
|
|
|
|
|
|
/**
|
2006-06-13 03:07:47 +00:00
|
|
|
+ * The global object which keeps a script context for each supported script
|
|
|
|
+ * language. This often used to store per-window global state.
|
1998-06-23 18:43:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
class nsIScriptGlobalObject : public nsISupports
|
|
|
|
{
|
1998-06-23 18:43:06 +00:00
|
|
|
public:
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
|
1999-06-29 20:28:56 +00:00
|
|
|
|
2006-06-13 03:07:47 +00:00
|
|
|
/**
|
|
|
|
* Ensure that the script global object is initialized for working with the
|
|
|
|
* specified script language ID. This will set up the nsIScriptContext
|
|
|
|
* and 'script global' for that language, allowing these to be fetched
|
|
|
|
* and manipulated.
|
|
|
|
* @return NS_OK if successful; error conditions include that the language
|
|
|
|
* has not been registered, as well as 'normal' errors, such as
|
|
|
|
* out-of-memory
|
|
|
|
*/
|
|
|
|
virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID) = 0;
|
|
|
|
/**
|
|
|
|
* Get a script context (WITHOUT added reference) for the specified language.
|
|
|
|
*/
|
|
|
|
virtual nsIScriptContext *GetScriptContext(PRUint32 lang) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the opaque "global" object for the specified lang.
|
|
|
|
*/
|
|
|
|
virtual void *GetScriptGlobal(PRUint32 lang) = 0;
|
|
|
|
|
|
|
|
// Set/GetContext deprecated methods - use GetScriptContext/Global
|
|
|
|
virtual JSObject *GetGlobalJSObject() {
|
|
|
|
return (JSObject *)GetScriptGlobal(nsIProgrammingLanguage::JAVASCRIPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsIScriptContext *GetContext() {
|
|
|
|
return GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new language context for this global. The native global for the
|
|
|
|
* context is created by the context's GetNativeGlobal() method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext) = 0;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
|
|
|
/**
|
2006-06-13 03:07:47 +00:00
|
|
|
* Called when the global script for a language is finalized, typically as
|
|
|
|
* part of its GC process. By the time this call is made, the
|
|
|
|
* nsIScriptContext for the language has probably already been removed.
|
|
|
|
* After this call, the passed object is dead - which should generally be the
|
|
|
|
* same object the global is using for a global for that language.
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-13 03:07:47 +00:00
|
|
|
virtual void OnFinalize(PRUint32 aLangID, void *aScriptGlobal) = 0;
|
2001-11-27 09:18:28 +00:00
|
|
|
|
|
|
|
/**
|
2004-03-03 04:01:33 +00:00
|
|
|
* Called to enable/disable scripts.
|
2001-11-27 09:18:28 +00:00
|
|
|
*/
|
2004-02-09 22:48:53 +00:00
|
|
|
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0;
|
2005-07-30 20:57:07 +00:00
|
|
|
|
2006-06-13 03:07:47 +00:00
|
|
|
/** Set a new arguments object for this window. This will be set on
|
2005-07-30 20:57:07 +00:00
|
|
|
* the window right away (if there's an existing document) and it
|
|
|
|
* will also be installed on the window when the next document is
|
2006-06-13 03:07:47 +00:00
|
|
|
* loaded. Each language impl is responsible for converting to
|
|
|
|
* an array of args as appropriate for that language.
|
|
|
|
*/
|
|
|
|
virtual nsresult SetNewArguments(nsIArray *aArguments) = 0;
|
|
|
|
|
|
|
|
/** Handle a script error. Generally called by a script context.
|
2005-07-30 20:57:07 +00:00
|
|
|
*/
|
2006-06-13 03:07:47 +00:00
|
|
|
virtual nsresult HandleScriptError(nsScriptErrorEvent *aErrorEvent,
|
|
|
|
nsEventStatus *aEventStatus) {
|
|
|
|
return NS_HandleScriptError(this, aErrorEvent, aEventStatus);
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
};
|
1998-06-23 18:43:06 +00:00
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject,
|
|
|
|
NS_ISCRIPTGLOBALOBJECT_IID)
|
|
|
|
|
1998-06-23 18:43:06 +00:00
|
|
|
#endif
|