1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 //////////////////////////////////////////////////////////////////////////////////////////
8 #ifndef nsXBLService_h_
9 #define nsXBLService_h_
12 #include "nsWeakReference.h"
14 #include "nsDataHashtable.h"
15 #include "nsHashKeys.h"
18 class nsXBLDocumentInfo
;
31 class nsXBLService MOZ_FINAL
: public nsSupportsWeakReference
35 static nsXBLService
* gInstance
;
39 static void Shutdown() {
40 NS_IF_RELEASE(gInstance
);
43 static nsXBLService
* GetInstance() { return gInstance
; }
45 static bool IsChromeOrResourceURI(nsIURI
* aURI
);
47 // This function loads a particular XBL file and installs all of the bindings
48 // onto the element. aOriginPrincipal must not be null here.
49 nsresult
LoadBindings(nsIContent
* aContent
, nsIURI
* aURL
,
50 nsIPrincipal
* aOriginPrincipal
,
51 nsXBLBinding
** aBinding
, bool* aResolveStyle
);
53 // Indicates whether or not a binding is fully loaded.
54 nsresult
BindingReady(nsIContent
* aBoundElement
, nsIURI
* aURI
, bool* aIsReady
);
56 // This method checks the hashtable and then calls FetchBindingDocument on a
57 // miss. aOriginPrincipal or aBoundDocument may be null to bypass security
59 nsresult
LoadBindingDocumentInfo(nsIContent
* aBoundElement
,
60 nsIDocument
* aBoundDocument
,
62 nsIPrincipal
* aOriginPrincipal
,
64 nsXBLDocumentInfo
** aResult
);
66 // Used by XUL key bindings and for window XBL.
67 static nsresult
AttachGlobalKeyHandler(mozilla::dom::EventTarget
* aTarget
);
68 static nsresult
DetachGlobalKeyHandler(mozilla::dom::EventTarget
* aTarget
);
72 virtual ~nsXBLService();
75 // This function clears out the bindings on a given content node.
76 nsresult
FlushStyleBindings(nsIContent
* aContent
);
78 // This method synchronously loads and parses an XBL file.
79 nsresult
FetchBindingDocument(nsIContent
* aBoundElement
, nsIDocument
* aBoundDocument
,
80 nsIURI
* aDocumentURI
, nsIURI
* aBindingURI
,
81 nsIPrincipal
* aOriginPrincipal
, bool aForceSyncLoad
,
82 nsIDocument
** aResult
);
85 * This method calls the one below with an empty |aDontExtendURIs| array.
87 nsresult
GetBinding(nsIContent
* aBoundElement
, nsIURI
* aURI
,
88 bool aPeekFlag
, nsIPrincipal
* aOriginPrincipal
,
89 bool* aIsReady
, nsXBLBinding
** aResult
);
92 * This method loads a binding doc and then builds the specific binding
93 * required. It can also peek without building.
94 * @param aBoundElement the element to get a binding for
95 * @param aURI the binding URI
96 * @param aPeekFlag if true then just peek to see if the binding is ready
97 * @param aIsReady [out] if the binding is ready or not
98 * @param aResult [out] where to store the resulting binding (not used if
99 * aPeekFlag is true, otherwise it must be non-null)
100 * @param aDontExtendURIs a set of URIs that are already bound to this
101 * element. If a binding extends any of these then further loading
102 * is aborted (because it would lead to the binding extending itself)
103 * and NS_ERROR_ILLEGAL_VALUE is returned.
105 * @note This method always calls LoadBindingDocumentInfo(), so it's
106 * enough to funnel all security checks through that function.
108 nsresult
GetBinding(nsIContent
* aBoundElement
, nsIURI
* aURI
,
109 bool aPeekFlag
, nsIPrincipal
* aOriginPrincipal
,
110 bool* aIsReady
, nsXBLBinding
** aResult
,
111 nsTArray
<nsIURI
*>& aDontExtendURIs
);
115 static bool gDisableChromeCache
;
116 static bool gAllowDataURIs
; // Whether we should allow data
117 // urls in -moz-binding. Needed for