nsXBLService.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* -*- Mode: C++; tab-width: 8; 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/. */
  5. //////////////////////////////////////////////////////////////////////////////////////////
  6. #ifndef nsXBLService_h_
  7. #define nsXBLService_h_
  8. #include "nsString.h"
  9. #include "nsWeakReference.h"
  10. #include "nsTArray.h"
  11. #include "nsDataHashtable.h"
  12. #include "nsHashKeys.h"
  13. class nsXBLBinding;
  14. class nsXBLDocumentInfo;
  15. class nsIContent;
  16. class nsIDocument;
  17. class nsString;
  18. class nsIURI;
  19. class nsIPrincipal;
  20. namespace mozilla {
  21. namespace dom {
  22. class EventTarget;
  23. } // namespace dom
  24. } // namespace mozilla
  25. class nsXBLService final : public nsSupportsWeakReference
  26. {
  27. NS_DECL_ISUPPORTS
  28. static nsXBLService* gInstance;
  29. static void Init();
  30. static void Shutdown() {
  31. NS_IF_RELEASE(gInstance);
  32. }
  33. static nsXBLService* GetInstance() { return gInstance; }
  34. static bool IsChromeOrResourceURI(nsIURI* aURI);
  35. // This function loads a particular XBL file and installs all of the bindings
  36. // onto the element. aOriginPrincipal must not be null here.
  37. nsresult LoadBindings(nsIContent* aContent, nsIURI* aURL,
  38. nsIPrincipal* aOriginPrincipal,
  39. nsXBLBinding** aBinding, bool* aResolveStyle);
  40. // Indicates whether or not a binding is fully loaded.
  41. nsresult BindingReady(nsIContent* aBoundElement, nsIURI* aURI, bool* aIsReady);
  42. // This method checks the hashtable and then calls FetchBindingDocument on a
  43. // miss. aOriginPrincipal or aBoundDocument may be null to bypass security
  44. // checks.
  45. nsresult LoadBindingDocumentInfo(nsIContent* aBoundElement,
  46. nsIDocument* aBoundDocument,
  47. nsIURI* aBindingURI,
  48. nsIPrincipal* aOriginPrincipal,
  49. bool aForceSyncLoad,
  50. nsXBLDocumentInfo** aResult);
  51. // Used by XUL key bindings and for window XBL.
  52. static nsresult AttachGlobalKeyHandler(mozilla::dom::EventTarget* aTarget);
  53. static nsresult DetachGlobalKeyHandler(mozilla::dom::EventTarget* aTarget);
  54. private:
  55. nsXBLService();
  56. virtual ~nsXBLService();
  57. protected:
  58. // This function clears out the bindings on a given content node.
  59. nsresult FlushStyleBindings(nsIContent* aContent);
  60. // This method synchronously loads and parses an XBL file.
  61. nsresult FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoundDocument,
  62. nsIURI* aDocumentURI, nsIURI* aBindingURI,
  63. nsIPrincipal* aOriginPrincipal, bool aForceSyncLoad,
  64. nsIDocument** aResult);
  65. /**
  66. * This method calls the one below with an empty |aDontExtendURIs| array.
  67. */
  68. nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
  69. bool aPeekFlag, nsIPrincipal* aOriginPrincipal,
  70. bool* aIsReady, nsXBLBinding** aResult);
  71. /**
  72. * This method loads a binding doc and then builds the specific binding
  73. * required. It can also peek without building.
  74. * @param aBoundElement the element to get a binding for
  75. * @param aURI the binding URI
  76. * @param aPeekFlag if true then just peek to see if the binding is ready
  77. * @param aIsReady [out] if the binding is ready or not
  78. * @param aResult [out] where to store the resulting binding (not used if
  79. * aPeekFlag is true, otherwise it must be non-null)
  80. * @param aDontExtendURIs a set of URIs that are already bound to this
  81. * element. If a binding extends any of these then further loading
  82. * is aborted (because it would lead to the binding extending itself)
  83. * and NS_ERROR_ILLEGAL_VALUE is returned.
  84. *
  85. * @note This method always calls LoadBindingDocumentInfo(), so it's
  86. * enough to funnel all security checks through that function.
  87. */
  88. nsresult GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
  89. bool aPeekFlag, nsIPrincipal* aOriginPrincipal,
  90. bool* aIsReady, nsXBLBinding** aResult,
  91. nsTArray<nsCOMPtr<nsIURI>>& aDontExtendURIs);
  92. // MEMBER VARIABLES
  93. public:
  94. static bool gDisableChromeCache;
  95. static bool gAllowDataURIs; // Whether we should allow data
  96. // urls in -moz-binding. Needed for
  97. // testing.
  98. };
  99. #endif