LCOV - code coverage report
Current view: directory - objdir/dist/include - nsIScriptGlobalObject.h (source / functions) Found Hit Coverage
Test: app.info Lines: 6 0 0.0 %
Date: 2012-06-02 Functions: 4 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim: set ts=2 sw=2 et tw=80: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsIScriptGlobalObject_h__
      40                 : #define nsIScriptGlobalObject_h__
      41                 : 
      42                 : #include "nsISupports.h"
      43                 : #include "nsEvent.h"
      44                 : #include "nsIProgrammingLanguage.h"
      45                 : 
      46                 : class nsIScriptContext;
      47                 : class nsIDOMDocument;
      48                 : class nsIDOMEvent;
      49                 : class nsIScriptGlobalObjectOwner;
      50                 : class nsIArray;
      51                 : class nsScriptErrorEvent;
      52                 : class nsIScriptGlobalObject;
      53                 : struct JSObject; // until we finally remove GetGlobalJSObject...
      54                 : 
      55                 : // Some helpers for working with integer "script type IDs", and specifically
      56                 : // for working with arrays of such objects. For example, it is common for
      57                 : // implementations supporting multiple script languages to keep each
      58                 : // language's nsIScriptContext in an array indexed by the language ID.
      59                 : 
      60                 : // Implementation note: We always ignore nsIProgrammingLanguage::UNKNOWN and
      61                 : // nsIProgrammingLanguage::CPLUSPLUS - this gives javascript slot 0.  An
      62                 : // attempted micro-optimization tried to avoid us going all the way to 
      63                 : // nsIProgrammingLanguage::MAX; however:
      64                 : // * Someone is reportedly working on a PHP impl - that has value 9
      65                 : // * nsGenericElement therefore allows 4 bits for the value.
      66                 : // So there is no good reason for us to be more restrictive again...
      67                 : 
      68                 : #define NS_STID_FIRST nsIProgrammingLanguage::JAVASCRIPT
      69                 : // like nsGenericElement, only 4 bits worth is valid...
      70                 : #define NS_STID_LAST (nsIProgrammingLanguage::MAX > 0x000FU ? \
      71                 :                       0x000FU : nsIProgrammingLanguage::MAX)
      72                 : 
      73                 : // Use to declare the array size
      74                 : #define NS_STID_ARRAY_UBOUND (NS_STID_LAST-NS_STID_FIRST+1)
      75                 : 
      76                 : // Is a language ID valid?
      77                 : #define NS_STID_VALID(langID) (langID >= NS_STID_FIRST && langID <= NS_STID_LAST)
      78                 : 
      79                 : // Return an index for a given ID.
      80                 : #define NS_STID_INDEX(langID) (langID-NS_STID_FIRST)
      81                 : 
      82                 : // Create a 'for' loop iterating over all possible language IDs (*not* indexes)
      83                 : #define NS_STID_FOR_ID(varName) \
      84                 :           for (varName=NS_STID_FIRST;varName<=NS_STID_LAST;varName++)
      85                 : 
      86                 : // Create a 'for' loop iterating over all indexes (when you don't need to know
      87                 : // what language it is)
      88                 : #define NS_STID_FOR_INDEX(varName) \
      89                 :           for (varName=0;varName<=NS_STID_INDEX(NS_STID_LAST);varName++)
      90                 : 
      91                 : // A helper function for nsIScriptGlobalObject implementations to use
      92                 : // when handling a script error.  Generally called by the global when a context
      93                 : // notifies it of an error via nsIScriptGlobalObject::HandleScriptError.
      94                 : // Returns true if HandleDOMEvent was actually called, in which case
      95                 : // aStatus will be filled in with the status.
      96                 : bool
      97                 : NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
      98                 :                      nsScriptErrorEvent *aErrorEvent,
      99                 :                      nsEventStatus *aStatus);
     100                 : 
     101                 : 
     102                 : #define NS_ISCRIPTGLOBALOBJECT_IID \
     103                 : { 0x8f19a761, 0x0717, 0x4b3f, \
     104                 :   { 0x80, 0xc5, 0xed, 0x7e, 0x9c, 0xbc, 0x40, 0xb1 } }
     105                 : 
     106                 : /**
     107                 :  * The global object which keeps a script context for each supported script
     108                 :  * language. This often used to store per-window global state.
     109                 :  */
     110                 : 
     111                 : class nsIScriptGlobalObject : public nsISupports
     112               0 : {
     113                 : public:
     114                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
     115                 : 
     116                 :   /**
     117                 :    * Ensure that the script global object is initialized for working with the
     118                 :    * specified script language ID.  This will set up the nsIScriptContext
     119                 :    * and 'script global' for that language, allowing these to be fetched
     120                 :    * and manipulated.
     121                 :    * @return NS_OK if successful; error conditions include that the language
     122                 :    * has not been registered, as well as 'normal' errors, such as
     123                 :    * out-of-memory
     124                 :    */
     125                 :   virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID) = 0;
     126                 :   /**
     127                 :    * Get a script context (WITHOUT added reference) for the specified language.
     128                 :    */
     129                 :   virtual nsIScriptContext *GetScriptContext(PRUint32 lang) = 0;
     130                 :   
     131                 :   virtual JSObject* GetGlobalJSObject() = 0;
     132                 : 
     133               0 :   virtual nsIScriptContext *GetContext() {
     134               0 :         return GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT);
     135                 :   }
     136                 : 
     137                 :   /**
     138                 :    * Set a new language context for this global.  The native global for the
     139                 :    * context is created by the context's GetNativeGlobal() method.
     140                 :    */
     141                 : 
     142                 :   virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext) = 0;
     143                 : 
     144                 :   /**
     145                 :    * Called when the global script for a language is finalized, typically as
     146                 :    * part of its GC process.  By the time this call is made, the
     147                 :    * nsIScriptContext for the language has probably already been removed.
     148                 :    * After this call, the passed object is dead - which should generally be the
     149                 :    * same object the global is using for a global for that language.
     150                 :    */
     151                 :   virtual void OnFinalize(JSObject* aObject) = 0;
     152                 : 
     153                 :   /**
     154                 :    * Called to enable/disable scripts.
     155                 :    */
     156                 :   virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts) = 0;
     157                 : 
     158                 :   /**
     159                 :    * Handle a script error.  Generally called by a script context.
     160                 :    */
     161               0 :   virtual nsresult HandleScriptError(nsScriptErrorEvent *aErrorEvent,
     162                 :                                      nsEventStatus *aEventStatus) {
     163               0 :     return NS_HandleScriptError(this, aErrorEvent, aEventStatus);
     164                 :   }
     165                 : 
     166               0 :   virtual bool IsBlackForCC() { return false; }
     167                 : };
     168                 : 
     169                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject,
     170                 :                               NS_ISCRIPTGLOBALOBJECT_IID)
     171                 : 
     172                 : #endif

Generated by: LCOV version 1.7