content/base/src/DOMParser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/src/DOMParser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_dom_DOMParser_h_
    1.10 +#define mozilla_dom_DOMParser_h_
    1.11 +
    1.12 +#include "nsCOMPtr.h"
    1.13 +#include "nsIDocument.h"
    1.14 +#include "nsIDOMParser.h"
    1.15 +#include "nsWeakReference.h"
    1.16 +#include "nsWrapperCache.h"
    1.17 +#include "mozilla/ErrorResult.h"
    1.18 +#include "mozilla/dom/DOMParserBinding.h"
    1.19 +#include "mozilla/dom/TypedArray.h"
    1.20 +
    1.21 +class nsIDocument;
    1.22 +
    1.23 +namespace mozilla {
    1.24 +namespace dom {
    1.25 +
    1.26 +class DOMParser MOZ_FINAL : public nsIDOMParser,
    1.27 +                            public nsSupportsWeakReference,
    1.28 +                            public nsWrapperCache
    1.29 +{
    1.30 +  typedef mozilla::dom::GlobalObject GlobalObject;
    1.31 +public: 
    1.32 +  DOMParser();
    1.33 +  virtual ~DOMParser();
    1.34 +
    1.35 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.36 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser,
    1.37 +                                                         nsIDOMParser)
    1.38 +
    1.39 +  // nsIDOMParser
    1.40 +  NS_DECL_NSIDOMPARSER
    1.41 +
    1.42 +  // WebIDL API
    1.43 +  static already_AddRefed<DOMParser>
    1.44 +  Constructor(const GlobalObject& aOwner,
    1.45 +              mozilla::ErrorResult& rv);
    1.46 +
    1.47 +  static already_AddRefed<DOMParser>
    1.48 +  Constructor(const GlobalObject& aOwner,
    1.49 +              nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, nsIURI* aBaseURI,
    1.50 +              mozilla::ErrorResult& rv);
    1.51 +
    1.52 +  already_AddRefed<nsIDocument>
    1.53 +  ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType,
    1.54 +                  mozilla::ErrorResult& rv);
    1.55 +
    1.56 +  already_AddRefed<nsIDocument>
    1.57 +  ParseFromBuffer(const mozilla::dom::Sequence<uint8_t>& aBuf,
    1.58 +                  uint32_t aBufLen, mozilla::dom::SupportedType aType,
    1.59 +                  mozilla::ErrorResult& rv);
    1.60 +
    1.61 +  already_AddRefed<nsIDocument>
    1.62 +  ParseFromBuffer(const mozilla::dom::Uint8Array& aBuf, uint32_t aBufLen,
    1.63 +                  mozilla::dom::SupportedType aType,
    1.64 +                  mozilla::ErrorResult& rv);
    1.65 +
    1.66 +  already_AddRefed<nsIDocument>
    1.67 +  ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset,
    1.68 +                  int32_t aContentLength, mozilla::dom::SupportedType aType,
    1.69 +                  mozilla::ErrorResult& rv);
    1.70 +
    1.71 +  void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
    1.72 +            nsIURI* aBaseURI, mozilla::ErrorResult& rv);
    1.73 +
    1.74 +  nsISupports* GetParentObject() const
    1.75 +  {
    1.76 +    return mOwner;
    1.77 +  }
    1.78 +
    1.79 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    1.80 +  {
    1.81 +    return mozilla::dom::DOMParserBinding::Wrap(aCx, this);
    1.82 +  }
    1.83 +
    1.84 +private:
    1.85 +  DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false)
    1.86 +  {
    1.87 +    MOZ_ASSERT(aOwner);
    1.88 +    SetIsDOMBinding();
    1.89 +  }
    1.90 +
    1.91 +  nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
    1.92 +                        nsIURI* documentURI, nsIURI* baseURI);
    1.93 +
    1.94 +  nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
    1.95 +
    1.96 +  // Helper for ParseFromString
    1.97 +  nsresult ParseFromString(const nsAString& str, const char *contentType,
    1.98 +                           nsIDOMDocument **aResult);
    1.99 +
   1.100 +  class AttemptedInitMarker {
   1.101 +  public:
   1.102 +    AttemptedInitMarker(bool* aAttemptedInit) :
   1.103 +      mAttemptedInit(aAttemptedInit)
   1.104 +    {}
   1.105 +
   1.106 +    ~AttemptedInitMarker() {
   1.107 +      *mAttemptedInit = true;
   1.108 +    }
   1.109 +
   1.110 +  private:
   1.111 +    bool* mAttemptedInit;
   1.112 +  };
   1.113 +
   1.114 +  nsCOMPtr<nsISupports> mOwner;
   1.115 +  nsCOMPtr<nsIPrincipal> mPrincipal;
   1.116 +  nsCOMPtr<nsIPrincipal> mOriginalPrincipal;
   1.117 +  nsCOMPtr<nsIURI> mDocumentURI;
   1.118 +  nsCOMPtr<nsIURI> mBaseURI;
   1.119 +  nsWeakPtr mScriptHandlingObject;
   1.120 +  
   1.121 +  bool mAttemptedInit;
   1.122 +};
   1.123 +
   1.124 +} // namespace dom
   1.125 +} // namespace mozilla
   1.126 +
   1.127 +#endif

mercurial