Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_
11 #include "nsString.h"
12 #include "nsWeakReference.h"
13 #include "nsTArray.h"
14 #include "nsDataHashtable.h"
15 #include "nsHashKeys.h"
17 class nsXBLBinding;
18 class nsXBLDocumentInfo;
19 class nsIContent;
20 class nsIDocument;
21 class nsString;
22 class nsIURI;
23 class nsIPrincipal;
25 namespace mozilla {
26 namespace dom {
27 class EventTarget;
28 }
29 }
31 class nsXBLService MOZ_FINAL : public nsSupportsWeakReference
32 {
33 NS_DECL_ISUPPORTS
35 static nsXBLService* gInstance;
37 static void Init();
39 static void Shutdown() {
40 NS_IF_RELEASE(gInstance);
41 }
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
58 // checks.
59 nsresult LoadBindingDocumentInfo(nsIContent* aBoundElement,
60 nsIDocument* aBoundDocument,
61 nsIURI* aBindingURI,
62 nsIPrincipal* aOriginPrincipal,
63 bool aForceSyncLoad,
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);
70 private:
71 nsXBLService();
72 virtual ~nsXBLService();
74 protected:
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 bool aForceSyncLoad, nsIDocument** aResult);
83 /**
84 * This method calls the one below with an empty |aDontExtendURIs| array.
85 */
86 nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
87 bool aPeekFlag, nsIPrincipal* aOriginPrincipal,
88 bool* aIsReady, nsXBLBinding** aResult);
90 /**
91 * This method loads a binding doc and then builds the specific binding
92 * required. It can also peek without building.
93 * @param aBoundElement the element to get a binding for
94 * @param aURI the binding URI
95 * @param aPeekFlag if true then just peek to see if the binding is ready
96 * @param aIsReady [out] if the binding is ready or not
97 * @param aResult [out] where to store the resulting binding (not used if
98 * aPeekFlag is true, otherwise it must be non-null)
99 * @param aDontExtendURIs a set of URIs that are already bound to this
100 * element. If a binding extends any of these then further loading
101 * is aborted (because it would lead to the binding extending itself)
102 * and NS_ERROR_ILLEGAL_VALUE is returned.
103 *
104 * @note This method always calls LoadBindingDocumentInfo(), so it's
105 * enough to funnel all security checks through that function.
106 */
107 nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
108 bool aPeekFlag, nsIPrincipal* aOriginPrincipal,
109 bool* aIsReady, nsXBLBinding** aResult,
110 nsTArray<nsIURI*>& aDontExtendURIs);
112 // MEMBER VARIABLES
113 public:
114 static bool gDisableChromeCache;
115 static bool gAllowDataURIs; // Whether we should allow data
116 // urls in -moz-binding. Needed for
117 // testing.
118 };
120 #endif