1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_XMLDocument_h
8 #define mozilla_dom_XMLDocument_h
9 
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "nsDocument.h"
13 #include "nsIDOMXMLDocument.h"
14 #include "nsIScriptContext.h"
15 
16 class nsIURI;
17 class nsIChannel;
18 
19 namespace mozilla {
20 namespace dom {
21 
22 class XMLDocument : public nsDocument, public nsIDOMXMLDocument {
23  public:
24   explicit XMLDocument(const char* aContentType = "application/xml");
25 
26   NS_DECL_ISUPPORTS_INHERITED
27 
28   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
29   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
30                           nsIPrincipal* aPrincipal) override;
31 
32   virtual void SetSuppressParserErrorElement(bool aSuppress) override;
33   virtual bool SuppressParserErrorElement() override;
34 
35   virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) override;
36   virtual bool SuppressParserErrorConsoleMessages() override;
37 
38   virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* channel,
39                                      nsILoadGroup* aLoadGroup,
40                                      nsISupports* aContainer,
41                                      nsIStreamListener** aDocListener,
42                                      bool aReset = true,
43                                      nsIContentSink* aSink = nullptr) override;
44 
45   virtual void EndLoad() override;
46 
47   // nsIDOMXMLDocument
48   NS_DECL_NSIDOMXMLDOCUMENT
49 
50   virtual nsresult Init() override;
51 
52   virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
53                          bool aPreallocateChildren) const override;
54 
55   virtual void DocAddSizeOfExcludingThis(
56       nsWindowSizes& aWindowSizes) const override;
57   // DocAddSizeOfIncludingThis is inherited from nsIDocument.
58 
59   // WebIDL API
60   bool Load(const nsAString& aUrl, CallerType aCallerType, ErrorResult& aRv);
Async()61   bool Async() const { return mAsync; }
SetAsync(bool aAsync)62   void SetAsync(bool aAsync) { mAsync = aAsync; }
63 
64   // .location is [Unforgeable], so we have to make it clear that the
65   // nsIDocument version applies to us (it's shadowed by the XPCOM thing on
66   // nsDocument).
67   using nsIDocument::GetLocation;
68 
69  protected:
70   virtual ~XMLDocument();
71 
72   virtual JSObject* WrapNode(JSContext* aCx,
73                              JS::Handle<JSObject*> aGivenProto) override;
74 
75   friend nsresult(::NS_NewXMLDocument)(nsIDocument**, bool, bool);
76 
77   // mChannelIsPending indicates whether we're currently asynchronously loading
78   // data from mChannel (via document.load() or normal load).  It's set to true
79   // when we first find out about the channel (StartDocumentLoad) and set to
80   // false in EndLoad or if ResetToURI() is called.  In the latter case our
81   // mChannel is also cancelled.  Note that if this member is true, mChannel
82   // cannot be null.
83   bool mChannelIsPending;
84   bool mAsync;
85   bool mLoopingForSyncLoad;
86 
87   // If true. we're really a Document, not an XMLDocument
88   bool mIsPlainDocument;
89 
90   // If true, do not output <parsererror> elements. Per spec, XMLHttpRequest
91   // shouldn't output them, whereas DOMParser/others should (see bug 918703).
92   bool mSuppressParserErrorElement;
93 
94   // If true, do not log parsing errors to the web console (see bug 884693).
95   bool mSuppressParserErrorConsoleMessages;
96 };
97 
98 }  // namespace dom
99 }  // namespace mozilla
100 
101 #endif  // mozilla_dom_XMLDocument_h
102