Back to index

lightning-sunbird  0.9+nobinonly
nsXBLService.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 Communicator client 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
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: David W. Hyatt (hyatt@netscape.com)
00024  *   - Brendan Eich (brendan@mozilla.org)
00025  *   - Mike Pinkerton (pinkerton@netscape.com)
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00042 
00043 #include "nsIXBLService.h"
00044 #include "nsIObserver.h"
00045 #include "nsWeakReference.h"
00046 #include "jsapi.h"              // nsXBLJSClass derives from JSClass
00047 #include "jsclist.h"            // nsXBLJSClass derives from JSCList
00048 #include "nsFixedSizeAllocator.h"
00049 
00050 class nsXBLBinding;
00051 class nsIXBLDocumentInfo;
00052 class nsIContent;
00053 class nsIDocument;
00054 class nsIAtom;
00055 class nsString;
00056 class nsIURI;
00057 class nsIURL;
00058 class nsSupportsHashtable;
00059 class nsHashtable;
00060 class nsIXULPrototypeCache;
00061 
00062 class nsXBLService : public nsIXBLService,
00063                      public nsIObserver,
00064                      public nsSupportsWeakReference
00065 {
00066   NS_DECL_ISUPPORTS
00067 
00068   // This function loads a particular XBL file and installs all of the bindings
00069   // onto the element.
00070   NS_IMETHOD LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFlag,
00071                           nsXBLBinding** aBinding, PRBool* aResolveStyle);
00072 
00073   // Indicates whether or not a binding is fully loaded.
00074   NS_IMETHOD BindingReady(nsIContent* aBoundElement, nsIURI* aURI, PRBool* aIsReady);
00075 
00076   // Gets the object's base class type.
00077   NS_IMETHOD ResolveTag(nsIContent* aContent, PRInt32* aNameSpaceID, nsIAtom** aResult);
00078 
00079   // This method checks the hashtable and then calls FetchBindingDocument on a miss.
00080   NS_IMETHOD LoadBindingDocumentInfo(nsIContent* aBoundElement, nsIDocument* aBoundDocument,
00081                                      nsIURI* aBindingURI,
00082                                      PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult);
00083 
00084   // Used by XUL key bindings and for window XBL.
00085   NS_IMETHOD AttachGlobalKeyHandler(nsIDOMEventReceiver* aElement);
00086   NS_IMETHOD AttachGlobalDragHandler(nsIDOMEventReceiver* aElement);
00087 
00088   NS_DECL_NSIOBSERVER
00089 
00090 public:
00091   nsXBLService();
00092   virtual ~nsXBLService();
00093 
00094 protected:
00095   // This function clears out the bindings on a given content node.
00096   nsresult FlushStyleBindings(nsIContent* aContent);
00097 
00098   // Release any memory that we can
00099   nsresult FlushMemory();
00100   
00101   // This method synchronously loads and parses an XBL file.
00102   nsresult FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoundDocument,
00103                                 nsIURI* aDocumentURI, nsIURL* aBindingURL, 
00104                                 PRBool aForceSyncLoad, nsIDocument** aResult);
00105 
00106   nsresult GetXBLDocumentInfo(nsIURI* aURI, nsIContent* aBoundElement, nsIXBLDocumentInfo** aResult);
00107 
00108   // This method loads a binding doc and then builds the specific binding required.  It
00109   // can also peek without building.
00110   nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
00111                       PRBool aPeekFlag, PRBool* aIsReady,
00112                       nsXBLBinding** aResult);
00113 
00114 // MEMBER VARIABLES
00115 public:
00116 #ifdef MOZ_XUL
00117   static nsIXULPrototypeCache* gXULCache;
00118 #endif
00119     
00120   static PRUint32 gRefCnt;                   // A count of XBLservice instances.
00121 
00122   static PRBool gDisableChromeCache;
00123 
00124   static nsHashtable* gClassTable;           // A table of nsXBLJSClass objects.
00125 
00126   static JSCList  gClassLRUList;             // LRU list of cached classes.
00127   static PRUint32 gClassLRUListLength;       // Number of classes on LRU list.
00128   static PRUint32 gClassLRUListQuota;        // Quota on class LRU list.
00129 
00130   nsFixedSizeAllocator mPool;
00131 };
00132 
00133 class nsXBLJSClass : public JSCList, public JSClass
00134 {
00135 private:
00136   nsrefcnt mRefCnt;
00137   nsrefcnt Destroy();
00138 
00139 public:
00140   nsXBLJSClass(const nsAFlatCString& aClassName);
00141   ~nsXBLJSClass() { nsMemory::Free((void*) name); }
00142 
00143   nsrefcnt Hold() { return ++mRefCnt; }
00144   nsrefcnt Drop() { return --mRefCnt ? mRefCnt : Destroy(); }
00145 };
00146