content/base/src/DOMParser.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_dom_DOMParser_h_
     7 #define mozilla_dom_DOMParser_h_
     9 #include "nsCOMPtr.h"
    10 #include "nsIDocument.h"
    11 #include "nsIDOMParser.h"
    12 #include "nsWeakReference.h"
    13 #include "nsWrapperCache.h"
    14 #include "mozilla/ErrorResult.h"
    15 #include "mozilla/dom/DOMParserBinding.h"
    16 #include "mozilla/dom/TypedArray.h"
    18 class nsIDocument;
    20 namespace mozilla {
    21 namespace dom {
    23 class DOMParser MOZ_FINAL : public nsIDOMParser,
    24                             public nsSupportsWeakReference,
    25                             public nsWrapperCache
    26 {
    27   typedef mozilla::dom::GlobalObject GlobalObject;
    28 public: 
    29   DOMParser();
    30   virtual ~DOMParser();
    32   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    33   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser,
    34                                                          nsIDOMParser)
    36   // nsIDOMParser
    37   NS_DECL_NSIDOMPARSER
    39   // WebIDL API
    40   static already_AddRefed<DOMParser>
    41   Constructor(const GlobalObject& aOwner,
    42               mozilla::ErrorResult& rv);
    44   static already_AddRefed<DOMParser>
    45   Constructor(const GlobalObject& aOwner,
    46               nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, nsIURI* aBaseURI,
    47               mozilla::ErrorResult& rv);
    49   already_AddRefed<nsIDocument>
    50   ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType,
    51                   mozilla::ErrorResult& rv);
    53   already_AddRefed<nsIDocument>
    54   ParseFromBuffer(const mozilla::dom::Sequence<uint8_t>& aBuf,
    55                   uint32_t aBufLen, mozilla::dom::SupportedType aType,
    56                   mozilla::ErrorResult& rv);
    58   already_AddRefed<nsIDocument>
    59   ParseFromBuffer(const mozilla::dom::Uint8Array& aBuf, uint32_t aBufLen,
    60                   mozilla::dom::SupportedType aType,
    61                   mozilla::ErrorResult& rv);
    63   already_AddRefed<nsIDocument>
    64   ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset,
    65                   int32_t aContentLength, mozilla::dom::SupportedType aType,
    66                   mozilla::ErrorResult& rv);
    68   void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
    69             nsIURI* aBaseURI, mozilla::ErrorResult& rv);
    71   nsISupports* GetParentObject() const
    72   {
    73     return mOwner;
    74   }
    76   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    77   {
    78     return mozilla::dom::DOMParserBinding::Wrap(aCx, this);
    79   }
    81 private:
    82   DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false)
    83   {
    84     MOZ_ASSERT(aOwner);
    85     SetIsDOMBinding();
    86   }
    88   nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
    89                         nsIURI* documentURI, nsIURI* baseURI);
    91   nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
    93   // Helper for ParseFromString
    94   nsresult ParseFromString(const nsAString& str, const char *contentType,
    95                            nsIDOMDocument **aResult);
    97   class AttemptedInitMarker {
    98   public:
    99     AttemptedInitMarker(bool* aAttemptedInit) :
   100       mAttemptedInit(aAttemptedInit)
   101     {}
   103     ~AttemptedInitMarker() {
   104       *mAttemptedInit = true;
   105     }
   107   private:
   108     bool* mAttemptedInit;
   109   };
   111   nsCOMPtr<nsISupports> mOwner;
   112   nsCOMPtr<nsIPrincipal> mPrincipal;
   113   nsCOMPtr<nsIPrincipal> mOriginalPrincipal;
   114   nsCOMPtr<nsIURI> mDocumentURI;
   115   nsCOMPtr<nsIURI> mBaseURI;
   116   nsWeakPtr mScriptHandlingObject;
   118   bool mAttemptedInit;
   119 };
   121 } // namespace dom
   122 } // namespace mozilla
   124 #endif

mercurial