2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
#ifndef mozilla_dom_DOMParser_h_
|
|
|
|
#define mozilla_dom_DOMParser_h_
|
2006-04-20 07:36:57 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-01-20 16:03:49 +04:00
|
|
|
#include "nsIDocument.h"
|
2013-03-22 04:05:19 +04:00
|
|
|
#include "nsIDOMParser.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-12-04 05:26:16 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2018-04-21 06:01:25 +03:00
|
|
|
#include "mozilla/Span.h"
|
2012-12-04 05:26:16 +04:00
|
|
|
#include "mozilla/dom/DOMParserBinding.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2006-04-20 07:37:35 +04:00
|
|
|
|
2013-03-22 04:05:19 +04:00
|
|
|
class nsIDocument;
|
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMParser final : public nsIDOMParser,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsWrapperCache
|
2006-04-20 07:36:57 +04:00
|
|
|
{
|
2013-08-23 09:17:08 +04:00
|
|
|
typedef mozilla::dom::GlobalObject GlobalObject;
|
2014-06-25 06:09:15 +04:00
|
|
|
|
|
|
|
virtual ~DOMParser();
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
public:
|
2013-08-30 21:16:32 +04:00
|
|
|
DOMParser();
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2012-12-04 05:26:16 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-08-30 21:16:32 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser,
|
2012-12-04 05:26:16 +04:00
|
|
|
nsIDOMParser)
|
2006-04-20 07:36:57 +04:00
|
|
|
|
|
|
|
// nsIDOMParser
|
2006-04-20 07:37:01 +04:00
|
|
|
NS_DECL_NSIDOMPARSER
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2012-12-04 05:26:16 +04:00
|
|
|
// WebIDL API
|
2013-08-30 21:16:32 +04:00
|
|
|
static already_AddRefed<DOMParser>
|
2013-08-23 09:17:08 +04:00
|
|
|
Constructor(const GlobalObject& aOwner,
|
2012-12-03 20:07:49 +04:00
|
|
|
mozilla::ErrorResult& rv);
|
2012-12-04 05:26:16 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
2018-04-21 06:01:25 +03:00
|
|
|
ParseFromString(const nsAString& aStr, SupportedType aType, ErrorResult& aRv);
|
2012-12-04 05:26:16 +04:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
// Sequence converts to Span, so we can use this overload for both
|
|
|
|
// the Sequence case and our internal uses.
|
2012-12-04 05:26:16 +04:00
|
|
|
already_AddRefed<nsIDocument>
|
2018-04-21 06:01:25 +03:00
|
|
|
ParseFromBuffer(Span<const uint8_t> aBuf, SupportedType aType,
|
|
|
|
ErrorResult& aRv);
|
2012-12-04 05:26:16 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
2018-04-21 06:01:25 +03:00
|
|
|
ParseFromBuffer(const Uint8Array& aBuf, SupportedType aType,
|
|
|
|
ErrorResult& aRv);
|
2012-12-04 05:26:16 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset,
|
|
|
|
int32_t aContentLength, mozilla::dom::SupportedType aType,
|
|
|
|
mozilla::ErrorResult& rv);
|
|
|
|
|
2018-04-21 06:01:24 +03:00
|
|
|
void
|
|
|
|
ForceEnableXULXBL()
|
|
|
|
{
|
|
|
|
mForceEnableXULXBL = true;
|
|
|
|
}
|
2012-12-04 05:26:16 +04:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2012-12-04 05:26:16 +04: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 17:13:33 +03:00
|
|
|
return mozilla::dom::DOMParserBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-04 05:26:16 +04:00
|
|
|
}
|
|
|
|
|
2006-04-20 07:37:01 +04:00
|
|
|
private:
|
2017-02-10 22:47:49 +03:00
|
|
|
explicit DOMParser(nsISupports* aOwner)
|
|
|
|
: mOwner(aOwner)
|
|
|
|
, mAttemptedInit(false)
|
2018-04-21 06:01:24 +03:00
|
|
|
, mForceEnableXULXBL(false)
|
2012-12-04 05:26:16 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOwner);
|
|
|
|
}
|
|
|
|
|
2018-04-21 06:01:24 +03:00
|
|
|
/**
|
|
|
|
* Initialize the principal and document and base URIs that the parser should
|
|
|
|
* use for documents it creates. If this is not called, then a null
|
|
|
|
* principal and its URI will be used. When creating a DOMParser via the JS
|
|
|
|
* constructor, this will be called automatically. This method may only be
|
|
|
|
* called once. If this method fails, all following parse attempts will
|
|
|
|
* fail.
|
|
|
|
*
|
|
|
|
* @param principal The principal to use for documents we create.
|
|
|
|
* If this is null, a codebase principal will be created
|
|
|
|
* based on documentURI; in that case the documentURI must
|
|
|
|
* be non-null.
|
|
|
|
* @param documentURI The documentURI to use for the documents we create.
|
|
|
|
* If null, the principal's URI will be used;
|
|
|
|
* in that case, the principal must be non-null and its
|
|
|
|
* URI must be non-null.
|
|
|
|
* @param baseURI The baseURI to use for the documents we create.
|
|
|
|
* If null, the documentURI will be used.
|
|
|
|
* @param scriptObject The object from which the context for event handling
|
|
|
|
* can be got.
|
|
|
|
*/
|
|
|
|
nsresult Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
|
|
|
|
nsIURI* aBaseURI, nsIGlobalObject* aSriptObjet);
|
|
|
|
|
|
|
|
|
2012-12-04 05:26:16 +04:00
|
|
|
nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
|
|
|
|
nsIURI* documentURI, nsIURI* baseURI);
|
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDocument** aResult);
|
2012-12-05 08:15:47 +04:00
|
|
|
|
2006-09-09 08:54:03 +04:00
|
|
|
class AttemptedInitMarker {
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit AttemptedInitMarker(bool* aAttemptedInit) :
|
2006-09-09 08:54:03 +04:00
|
|
|
mAttemptedInit(aAttemptedInit)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~AttemptedInitMarker() {
|
2011-10-17 18:59:28 +04:00
|
|
|
*mAttemptedInit = true;
|
2006-09-09 08:54:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* mAttemptedInit;
|
2006-09-09 08:54:03 +04:00
|
|
|
};
|
2012-12-04 05:26:16 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
2006-09-09 08:54:03 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
2006-04-20 07:37:01 +04:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
2007-10-01 14:02:32 +04:00
|
|
|
nsWeakPtr mScriptHandlingObject;
|
2017-02-03 00:57:51 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAttemptedInit;
|
2018-04-21 06:01:24 +03:00
|
|
|
bool mForceEnableXULXBL;
|
2006-04-20 07:36:57 +04:00
|
|
|
};
|
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2006-04-20 07:36:57 +04:00
|
|
|
#endif
|