1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Original Author: David W. Hyatt (hyatt@netscape.com)
24 * - Brendan Eich (brendan@mozilla.org)
25 * - Mike Pinkerton (pinkerton@netscape.com)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 //////////////////////////////////////////////////////////////////////////////////////////
43 #include "nsIXBLService.h"
44 #include "nsIObserver.h"
45 #include "nsWeakReference.h"
46 #include "jsapi.h" // nsXBLJSClass derives from JSClass
47 #include "jsclist.h" // nsXBLJSClass derives from JSCList
48 #include "nsFixedSizeAllocator.h"
52 class nsIXBLDocumentInfo
;
58 class nsSupportsHashtable
;
61 class nsXBLService
: public nsIXBLService
,
63 public nsSupportsWeakReference
67 // This function loads a particular XBL file and installs all of the bindings
68 // onto the element. aOriginPrincipal must not be null here.
69 NS_IMETHOD
LoadBindings(nsIContent
* aContent
, nsIURI
* aURL
,
70 nsIPrincipal
* aOriginPrincipal
, PRBool aAugmentFlag
,
71 nsXBLBinding
** aBinding
, PRBool
* aResolveStyle
);
73 // Indicates whether or not a binding is fully loaded.
74 NS_IMETHOD
BindingReady(nsIContent
* aBoundElement
, nsIURI
* aURI
, PRBool
* aIsReady
);
76 // Gets the object's base class type.
77 NS_IMETHOD
ResolveTag(nsIContent
* aContent
, PRInt32
* aNameSpaceID
, nsIAtom
** aResult
);
79 // This method checks the hashtable and then calls FetchBindingDocument on a
80 // miss. aOriginPrincipal or aBoundDocument may be null to bypass security
82 NS_IMETHOD
LoadBindingDocumentInfo(nsIContent
* aBoundElement
,
83 nsIDocument
* aBoundDocument
,
85 nsIPrincipal
* aOriginPrincipal
,
86 PRBool aForceSyncLoad
,
87 nsIXBLDocumentInfo
** aResult
);
89 // Used by XUL key bindings and for window XBL.
90 NS_IMETHOD
AttachGlobalKeyHandler(nsPIDOMEventTarget
* aTarget
);
91 NS_IMETHOD
DetachGlobalKeyHandler(nsPIDOMEventTarget
* aTarget
);
97 virtual ~nsXBLService();
100 // This function clears out the bindings on a given content node.
101 nsresult
FlushStyleBindings(nsIContent
* aContent
);
103 // Release any memory that we can
104 nsresult
FlushMemory();
106 // This method synchronously loads and parses an XBL file.
107 nsresult
FetchBindingDocument(nsIContent
* aBoundElement
, nsIDocument
* aBoundDocument
,
108 nsIURI
* aDocumentURI
, nsIURI
* aBindingURI
,
109 PRBool aForceSyncLoad
, nsIDocument
** aResult
);
112 * This method calls the one below with an empty |aDontExtendURIs| array.
114 nsresult
GetBinding(nsIContent
* aBoundElement
, nsIURI
* aURI
,
115 PRBool aPeekFlag
, nsIPrincipal
* aOriginPrincipal
,
116 PRBool
* aIsReady
, nsXBLBinding
** aResult
);
119 * This method loads a binding doc and then builds the specific binding
120 * required. It can also peek without building.
121 * @param aBoundElement the element to get a binding for
122 * @param aURI the binding URI
123 * @param aPeekFlag if true then just peek to see if the binding is ready
124 * @param aIsReady [out] if the binding is ready or not
125 * @param aResult [out] where to store the resulting binding (not used if
126 * aPeekFlag is true, otherwise it must be non-null)
127 * @param aDontExtendURIs a set of URIs that are already bound to this
128 * element. If a binding extends any of these then further loading
129 * is aborted (because it would lead to the binding extending itself)
130 * and NS_ERROR_ILLEGAL_VALUE is returned.
132 * @note This method always calls LoadBindingDocumentInfo(), so it's
133 * enough to funnel all security checks through that function.
135 nsresult
GetBinding(nsIContent
* aBoundElement
, nsIURI
* aURI
,
136 PRBool aPeekFlag
, nsIPrincipal
* aOriginPrincipal
,
137 PRBool
* aIsReady
, nsXBLBinding
** aResult
,
138 nsTArray
<nsIURI
*>& aDontExtendURIs
);
142 static PRUint32 gRefCnt
; // A count of XBLservice instances.
144 static PRBool gDisableChromeCache
;
146 static nsHashtable
* gClassTable
; // A table of nsXBLJSClass objects.
148 static JSCList gClassLRUList
; // LRU list of cached classes.
149 static PRUint32 gClassLRUListLength
; // Number of classes on LRU list.
150 static PRUint32 gClassLRUListQuota
; // Quota on class LRU list.
151 static PRBool gAllowDataURIs
; // Whether we should allow data
152 // urls in -moz-binding. Needed for
155 nsFixedSizeAllocator mPool
;
158 class nsXBLJSClass
: public JSCList
, public JSClass
165 nsXBLJSClass(const nsAFlatCString
& aClassName
);
166 ~nsXBLJSClass() { nsMemory::Free((void*) name
); }
168 nsrefcnt
Hold() { return ++mRefCnt
; }
169 nsrefcnt
Drop() { return --mRefCnt
? mRefCnt
: Destroy(); }