2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
#ifndef nsDOMParser_h_
|
|
|
|
#define nsDOMParser_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIDOMParser.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIJSNativeInitializer.h"
|
2012-01-20 04:03:49 -08:00
|
|
|
#include "nsIDocument.h"
|
2012-12-03 17:26:16 -08:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/DOMParserBinding.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
class nsDOMParser MOZ_FINAL : public nsIDOMParser,
|
|
|
|
public nsIDOMParserJS,
|
|
|
|
public nsIJSNativeInitializer,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMParser();
|
|
|
|
virtual ~nsDOMParser();
|
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMParser,
|
|
|
|
nsIDOMParser)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMParser
|
|
|
|
NS_DECL_NSIDOMPARSER
|
|
|
|
|
|
|
|
// nsIDOMParserJS
|
|
|
|
NS_DECL_NSIDOMPARSERJS
|
|
|
|
|
|
|
|
// nsIJSNativeInitializer
|
2007-12-12 00:33:32 -08:00
|
|
|
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t argc, jsval *argv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
// WebIDL API
|
|
|
|
static already_AddRefed<nsDOMParser>
|
|
|
|
Constructor(nsISupports* aOwner, mozilla::ErrorResult& rv)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMParser> domParser = new nsDOMParser(aOwner);
|
|
|
|
rv = domParser->Initialize(aOwner, nullptr, nullptr, 0, nullptr);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return domParser.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<nsDOMParser>
|
|
|
|
Constructor(nsISupports* aOwner, nsIPrincipal* aPrincipal,
|
|
|
|
nsIURI* aDocumentURI, nsIURI* aBaseURI,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
ParseFromBuffer(const mozilla::dom::Sequence<uint8_t>& aBuf,
|
|
|
|
uint32_t aBufLen, mozilla::dom::SupportedType aType,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
ParseFromBuffer(const mozilla::dom::Uint8Array& aBuf, uint32_t aBufLen,
|
|
|
|
mozilla::dom::SupportedType aType,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset,
|
|
|
|
int32_t aContentLength, mozilla::dom::SupportedType aType,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
|
|
|
void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
|
|
|
|
nsIURI* aBaseURI, mozilla::ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = Init(aPrincipal, aDocumentURI, aBaseURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
|
|
|
|
bool* aTriedToWrap) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return mozilla::dom::DOMParserBinding::Wrap(aCx, aScope, this,
|
|
|
|
aTriedToWrap);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2012-12-03 17:26:16 -08:00
|
|
|
nsDOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOwner);
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
|
|
|
|
nsIURI* documentURI, nsIURI* baseURI);
|
|
|
|
|
2012-01-20 04:03:49 -08:00
|
|
|
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class AttemptedInitMarker {
|
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
AttemptedInitMarker(bool* aAttemptedInit) :
|
2007-03-22 10:30:00 -07:00
|
|
|
mAttemptedInit(aAttemptedInit)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~AttemptedInitMarker() {
|
2011-10-17 07:59:28 -07:00
|
|
|
*mAttemptedInit = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* mAttemptedInit;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2012-12-03 17:26:16 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2008-03-27 20:46:15 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mOriginalPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
2007-10-01 03:02:32 -07:00
|
|
|
nsWeakPtr mScriptHandlingObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAttemptedInit;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|