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
|
|
|
|
2013-08-30 10:16:32 -07:00
|
|
|
#ifndef mozilla_dom_DOMParser_h_
|
|
|
|
#define mozilla_dom_DOMParser_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-01-20 04:03:49 -08:00
|
|
|
#include "nsIDocument.h"
|
2013-03-21 17:05:19 -07:00
|
|
|
#include "nsIDOMParser.h"
|
|
|
|
#include "nsWeakReference.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
|
|
|
|
2013-03-21 17:05:19 -07:00
|
|
|
class nsIDocument;
|
|
|
|
|
2013-08-30 10:16:32 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class DOMParser final : public nsIDOMParser,
|
2015-03-27 11:52:19 -07:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
typedef mozilla::dom::GlobalObject GlobalObject;
|
2014-06-24 19:09:15 -07:00
|
|
|
|
|
|
|
virtual ~DOMParser();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2013-08-30 10:16:32 -07:00
|
|
|
DOMParser();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-08-30 10:16:32 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser,
|
2012-12-03 17:26:16 -08:00
|
|
|
nsIDOMParser)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMParser
|
|
|
|
NS_DECL_NSIDOMPARSER
|
|
|
|
|
2012-12-03 17:26:16 -08:00
|
|
|
// WebIDL API
|
2013-08-30 10:16:32 -07:00
|
|
|
static already_AddRefed<DOMParser>
|
2013-08-22 22:17:08 -07:00
|
|
|
Constructor(const GlobalObject& aOwner,
|
2012-12-03 08:07:49 -08:00
|
|
|
mozilla::ErrorResult& rv);
|
2012-12-03 17:26:16 -08:00
|
|
|
|
2013-08-30 10:16:32 -07:00
|
|
|
static already_AddRefed<DOMParser>
|
2013-08-22 22:17:08 -07:00
|
|
|
Constructor(const GlobalObject& aOwner,
|
2012-12-03 08:07:49 -08:00
|
|
|
nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, nsIURI* aBaseURI,
|
2012-12-03 17:26:16 -08:00
|
|
|
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,
|
2012-12-03 17:26:16 -08:00
|
|
|
nsIURI* aBaseURI, mozilla::ErrorResult& rv);
|
2012-12-03 17:26:16 -08:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2012-12-03 17:26:16 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return mozilla::dom::DOMParserBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-03 17:26:16 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false)
|
2012-12-03 17:26:16 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
|
|
|
|
nsIURI* documentURI, nsIURI* baseURI);
|
|
|
|
|
2012-01-20 04:03:49 -08:00
|
|
|
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
|
|
|
|
|
2012-12-04 20:15:47 -08:00
|
|
|
// Helper for ParseFromString
|
|
|
|
nsresult ParseFromString(const nsAString& str, const char *contentType,
|
|
|
|
nsIDOMDocument **aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class AttemptedInitMarker {
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit 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
|
|
|
};
|
|
|
|
|
2013-08-30 10:16:32 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|