michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef nsXBLService_h_ michael@0: #define nsXBLService_h_ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsTArray.h" michael@0: #include "nsDataHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: michael@0: class nsXBLBinding; michael@0: class nsXBLDocumentInfo; michael@0: class nsIContent; michael@0: class nsIDocument; michael@0: class nsString; michael@0: class nsIURI; michael@0: class nsIPrincipal; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class EventTarget; michael@0: } michael@0: } michael@0: michael@0: class nsXBLService MOZ_FINAL : public nsSupportsWeakReference michael@0: { michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: static nsXBLService* gInstance; michael@0: michael@0: static void Init(); michael@0: michael@0: static void Shutdown() { michael@0: NS_IF_RELEASE(gInstance); michael@0: } michael@0: michael@0: static nsXBLService* GetInstance() { return gInstance; } michael@0: michael@0: static bool IsChromeOrResourceURI(nsIURI* aURI); michael@0: michael@0: // This function loads a particular XBL file and installs all of the bindings michael@0: // onto the element. aOriginPrincipal must not be null here. michael@0: nsresult LoadBindings(nsIContent* aContent, nsIURI* aURL, michael@0: nsIPrincipal* aOriginPrincipal, michael@0: nsXBLBinding** aBinding, bool* aResolveStyle); michael@0: michael@0: // Indicates whether or not a binding is fully loaded. michael@0: nsresult BindingReady(nsIContent* aBoundElement, nsIURI* aURI, bool* aIsReady); michael@0: michael@0: // This method checks the hashtable and then calls FetchBindingDocument on a michael@0: // miss. aOriginPrincipal or aBoundDocument may be null to bypass security michael@0: // checks. michael@0: nsresult LoadBindingDocumentInfo(nsIContent* aBoundElement, michael@0: nsIDocument* aBoundDocument, michael@0: nsIURI* aBindingURI, michael@0: nsIPrincipal* aOriginPrincipal, michael@0: bool aForceSyncLoad, michael@0: nsXBLDocumentInfo** aResult); michael@0: michael@0: // Used by XUL key bindings and for window XBL. michael@0: static nsresult AttachGlobalKeyHandler(mozilla::dom::EventTarget* aTarget); michael@0: static nsresult DetachGlobalKeyHandler(mozilla::dom::EventTarget* aTarget); michael@0: michael@0: private: michael@0: nsXBLService(); michael@0: virtual ~nsXBLService(); michael@0: michael@0: protected: michael@0: // This function clears out the bindings on a given content node. michael@0: nsresult FlushStyleBindings(nsIContent* aContent); michael@0: michael@0: // This method synchronously loads and parses an XBL file. michael@0: nsresult FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoundDocument, michael@0: nsIURI* aDocumentURI, nsIURI* aBindingURI, michael@0: bool aForceSyncLoad, nsIDocument** aResult); michael@0: michael@0: /** michael@0: * This method calls the one below with an empty |aDontExtendURIs| array. michael@0: */ michael@0: nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI, michael@0: bool aPeekFlag, nsIPrincipal* aOriginPrincipal, michael@0: bool* aIsReady, nsXBLBinding** aResult); michael@0: michael@0: /** michael@0: * This method loads a binding doc and then builds the specific binding michael@0: * required. It can also peek without building. michael@0: * @param aBoundElement the element to get a binding for michael@0: * @param aURI the binding URI michael@0: * @param aPeekFlag if true then just peek to see if the binding is ready michael@0: * @param aIsReady [out] if the binding is ready or not michael@0: * @param aResult [out] where to store the resulting binding (not used if michael@0: * aPeekFlag is true, otherwise it must be non-null) michael@0: * @param aDontExtendURIs a set of URIs that are already bound to this michael@0: * element. If a binding extends any of these then further loading michael@0: * is aborted (because it would lead to the binding extending itself) michael@0: * and NS_ERROR_ILLEGAL_VALUE is returned. michael@0: * michael@0: * @note This method always calls LoadBindingDocumentInfo(), so it's michael@0: * enough to funnel all security checks through that function. michael@0: */ michael@0: nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI, michael@0: bool aPeekFlag, nsIPrincipal* aOriginPrincipal, michael@0: bool* aIsReady, nsXBLBinding** aResult, michael@0: nsTArray& aDontExtendURIs); michael@0: michael@0: // MEMBER VARIABLES michael@0: public: michael@0: static bool gDisableChromeCache; michael@0: static bool gAllowDataURIs; // Whether we should allow data michael@0: // urls in -moz-binding. Needed for michael@0: // testing. michael@0: }; michael@0: michael@0: #endif