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: #ifndef mozilla_dom_DOMParser_h_ michael@0: #define mozilla_dom_DOMParser_h_ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIDOMParser.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/dom/DOMParserBinding.h" michael@0: #include "mozilla/dom/TypedArray.h" michael@0: michael@0: class nsIDocument; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class DOMParser MOZ_FINAL : public nsIDOMParser, michael@0: public nsSupportsWeakReference, michael@0: public nsWrapperCache michael@0: { michael@0: typedef mozilla::dom::GlobalObject GlobalObject; michael@0: public: michael@0: DOMParser(); michael@0: virtual ~DOMParser(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser, michael@0: nsIDOMParser) michael@0: michael@0: // nsIDOMParser michael@0: NS_DECL_NSIDOMPARSER michael@0: michael@0: // WebIDL API michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aOwner, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aOwner, michael@0: nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, nsIURI* aBaseURI, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: already_AddRefed michael@0: ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: already_AddRefed michael@0: ParseFromBuffer(const mozilla::dom::Sequence& aBuf, michael@0: uint32_t aBufLen, mozilla::dom::SupportedType aType, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: already_AddRefed michael@0: ParseFromBuffer(const mozilla::dom::Uint8Array& aBuf, uint32_t aBufLen, michael@0: mozilla::dom::SupportedType aType, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: already_AddRefed michael@0: ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset, michael@0: int32_t aContentLength, mozilla::dom::SupportedType aType, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, michael@0: nsIURI* aBaseURI, mozilla::ErrorResult& rv); michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return mOwner; michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE michael@0: { michael@0: return mozilla::dom::DOMParserBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: private: michael@0: DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false) michael@0: { michael@0: MOZ_ASSERT(aOwner); michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin, michael@0: nsIURI* documentURI, nsIURI* baseURI); michael@0: michael@0: nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult); michael@0: michael@0: // Helper for ParseFromString michael@0: nsresult ParseFromString(const nsAString& str, const char *contentType, michael@0: nsIDOMDocument **aResult); michael@0: michael@0: class AttemptedInitMarker { michael@0: public: michael@0: AttemptedInitMarker(bool* aAttemptedInit) : michael@0: mAttemptedInit(aAttemptedInit) michael@0: {} michael@0: michael@0: ~AttemptedInitMarker() { michael@0: *mAttemptedInit = true; michael@0: } michael@0: michael@0: private: michael@0: bool* mAttemptedInit; michael@0: }; michael@0: michael@0: nsCOMPtr mOwner; michael@0: nsCOMPtr mPrincipal; michael@0: nsCOMPtr mOriginalPrincipal; michael@0: nsCOMPtr mDocumentURI; michael@0: nsCOMPtr mBaseURI; michael@0: nsWeakPtr mScriptHandlingObject; michael@0: michael@0: bool mAttemptedInit; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif