/src/mozilla-central/dom/xbl/nsXBLService.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | ////////////////////////////////////////////////////////////////////////////////////////// |
8 | | |
9 | | #ifndef nsXBLService_h_ |
10 | | #define nsXBLService_h_ |
11 | | |
12 | | #include "nsString.h" |
13 | | #include "nsWeakReference.h" |
14 | | #include "nsTArray.h" |
15 | | #include "nsDataHashtable.h" |
16 | | #include "nsHashKeys.h" |
17 | | |
18 | | class nsXBLBinding; |
19 | | class nsXBLDocumentInfo; |
20 | | class nsIContent; |
21 | | class nsIDocument; |
22 | | class nsIURI; |
23 | | class nsIPrincipal; |
24 | | |
25 | | namespace mozilla { |
26 | | namespace dom { |
27 | | class EventTarget; |
28 | | } // namespace dom |
29 | | } // namespace mozilla |
30 | | |
31 | | class nsXBLService final : public nsSupportsWeakReference |
32 | | { |
33 | | NS_DECL_ISUPPORTS |
34 | | |
35 | | static nsXBLService* gInstance; |
36 | | |
37 | | static void Init(); |
38 | | |
39 | 0 | static void Shutdown() { |
40 | 0 | NS_IF_RELEASE(gInstance); |
41 | 0 | } |
42 | | |
43 | 0 | static nsXBLService* GetInstance() { return gInstance; } |
44 | | |
45 | | static bool IsChromeOrResourceURI(nsIURI* aURI); |
46 | | |
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(mozilla::dom::Element* aElement, nsIURI* aURL, |
50 | | nsIPrincipal* aOriginPrincipal, |
51 | | nsXBLBinding** aBinding, bool* aResolveStyle); |
52 | | |
53 | | // Indicates whether or not a binding is fully loaded. |
54 | | nsresult BindingReady(nsIContent* aBoundElement, nsIURI* aURI, bool* aIsReady); |
55 | | |
56 | | // This method checks the hashtable and then calls FetchBindingDocument on a |
57 | | // miss. aOriginPrincipal or aBoundDocument may be null to bypass security |
58 | | // checks. |
59 | | nsresult LoadBindingDocumentInfo(nsIContent* aBoundElement, |
60 | | nsIDocument* aBoundDocument, |
61 | | nsIURI* aBindingURI, |
62 | | nsIPrincipal* aOriginPrincipal, |
63 | | bool aForceSyncLoad, |
64 | | nsXBLDocumentInfo** aResult); |
65 | | |
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); |
69 | | |
70 | | private: |
71 | | nsXBLService(); |
72 | | virtual ~nsXBLService(); |
73 | | |
74 | | protected: |
75 | | // This function clears out the bindings on a given element. |
76 | | void FlushStyleBindings(mozilla::dom::Element*); |
77 | | |
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); |
83 | | |
84 | | /** |
85 | | * This method calls the one below with an empty |aDontExtendURIs| array. |
86 | | */ |
87 | | nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI, |
88 | | bool aPeekFlag, nsIPrincipal* aOriginPrincipal, |
89 | | bool* aIsReady, nsXBLBinding** aResult); |
90 | | |
91 | | /** |
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. |
104 | | * |
105 | | * @note This method always calls LoadBindingDocumentInfo(), so it's |
106 | | * enough to funnel all security checks through that function. |
107 | | */ |
108 | | nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI, |
109 | | bool aPeekFlag, nsIPrincipal* aOriginPrincipal, |
110 | | bool* aIsReady, nsXBLBinding** aResult, |
111 | | nsTArray<nsCOMPtr<nsIURI>>& aDontExtendURIs); |
112 | | |
113 | | // MEMBER VARIABLES |
114 | | public: |
115 | | static bool gDisableChromeCache; |
116 | | static bool gAllowDataURIs; // Whether we should allow data |
117 | | // urls in -moz-binding. Needed for |
118 | | // testing. |
119 | | }; |
120 | | |
121 | | #endif |