tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsHTMLDocument.h (7191B)


      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 #ifndef nsHTMLDocument_h___
      7 #define nsHTMLDocument_h___
      8 
      9 #include "PLDHashTable.h"
     10 #include "mozilla/dom/BindingDeclarations.h"
     11 #include "mozilla/dom/Document.h"
     12 #include "mozilla/dom/HTMLSharedElement.h"
     13 #include "nsContentList.h"
     14 #include "nsIHTMLCollection.h"
     15 #include "nsIScriptElement.h"
     16 #include "nsTArray.h"
     17 #include "nsThreadUtils.h"
     18 
     19 class nsCommandManager;
     20 class nsIURI;
     21 class nsIDocShell;
     22 class nsICachingChannel;
     23 class nsILoadGroup;
     24 
     25 namespace mozilla::dom {
     26 template <typename T>
     27 struct Nullable;
     28 class WindowProxyHolder;
     29 }  // namespace mozilla::dom
     30 
     31 class nsHTMLDocument : public mozilla::dom::Document {
     32 protected:
     33  using ReferrerPolicy = mozilla::dom::ReferrerPolicy;
     34  using Document = mozilla::dom::Document;
     35  using Encoding = mozilla::Encoding;
     36  template <typename T>
     37  using NotNull = mozilla::NotNull<T>;
     38 
     39 public:
     40  using Document::SetDocumentURI;
     41 
     42  explicit nsHTMLDocument(mozilla::dom::LoadedAsData aLoadedAsData);
     43  virtual nsresult Init(nsIPrincipal* aPrincipal,
     44                        nsIPrincipal* aPartitionedPrincipal) override;
     45 
     46  // Document
     47  virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
     48  virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
     49                          nsIPrincipal* aPrincipal,
     50                          nsIPrincipal* aPartitionedPrincipal) override;
     51 
     52  virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
     53                                     nsILoadGroup* aLoadGroup,
     54                                     nsISupports* aContainer,
     55                                     nsIStreamListener** aDocListener,
     56                                     bool aReset = true) override;
     57 
     58 protected:
     59  virtual bool UseWidthDeviceWidthFallbackViewport() const override;
     60 
     61 public:
     62  mozilla::dom::Element* GetUnfocusedKeyEventTarget() override;
     63 
     64  nsContentList* GetExistingForms() const { return mForms; }
     65 
     66  bool IsPlainText() const { return mIsPlainText; }
     67 
     68  bool IsViewSource() const { return mViewSource; }
     69 
     70  // Returns whether an object was found for aName.
     71  bool ResolveNameForWindow(JSContext* aCx, const nsAString& aName,
     72                            JS::MutableHandle<JS::Value> aRetVal,
     73                            mozilla::ErrorResult& aError);
     74 
     75  void GetSupportedNamesForWindow(nsTArray<nsString>& aNames);
     76 
     77  /**
     78   * Called when form->BindToTree() is called so that document knows
     79   * immediately when a form is added
     80   */
     81  void AddedForm();
     82  /**
     83   * Called when form->SetDocument() is called so that document knows
     84   * immediately when a form is removed
     85   */
     86  void RemovedForm();
     87  /**
     88   * Called to get a better count of forms than document.forms can provide
     89   * without calling FlushPendingNotifications (bug 138892).
     90   */
     91  // XXXbz is this still needed now that we can flush just content,
     92  // not the rest?
     93  int32_t GetNumFormsSynchronous() const;
     94  void SetIsXHTML(bool aXHTML) { mType = (aXHTML ? eXHTML : eHTML); }
     95 
     96  virtual nsresult Clone(mozilla::dom::NodeInfo*,
     97                         nsINode** aResult) const override;
     98 
     99  using mozilla::dom::DocumentOrShadowRoot::GetElementById;
    100 
    101  virtual void DocAddSizeOfExcludingThis(
    102      nsWindowSizes& aWindowSizes) const override;
    103  // DocAddSizeOfIncludingThis is inherited from Document.
    104 
    105  virtual bool WillIgnoreCharsetOverride() override;
    106 
    107  // WebIDL API
    108  virtual JSObject* WrapNode(JSContext* aCx,
    109                             JS::Handle<JSObject*> aGivenProto) override;
    110  bool IsRegistrableDomainSuffixOfOrEqualTo(const nsAString& aHostSuffixString,
    111                                            const nsACString& aOrigHost);
    112  void NamedGetter(JSContext* aCx, const nsAString& aName, bool& aFound,
    113                   JS::MutableHandle<JSObject*> aRetVal,
    114                   mozilla::ErrorResult& aRv);
    115  void GetSupportedNames(nsTArray<nsString>& aNames);
    116  // We're picking up GetLocation from Document
    117  already_AddRefed<mozilla::dom::Location> GetLocation() const {
    118    return Document::GetLocation();
    119  }
    120 
    121  static bool MatchFormControls(mozilla::dom::Element* aElement,
    122                                int32_t aNamespaceID, nsAtom* aAtom,
    123                                void* aData);
    124 
    125  void GetFormsAndFormControls(nsContentList** aFormList,
    126                               nsContentList** aFormControlList);
    127 
    128 protected:
    129  ~nsHTMLDocument();
    130 
    131  nsresult GetBodySize(int32_t* aWidth, int32_t* aHeight);
    132 
    133  nsIContent* MatchId(nsIContent* aContent, const nsAString& aId);
    134 
    135  static void DocumentWriteTerminationFunc(nsISupports* aRef);
    136 
    137  // A helper class to keep nsContentList objects alive for a short period of
    138  // time. Note, when the final Release is called on an nsContentList object, it
    139  // removes itself from MutationObserver list.
    140  class ContentListHolder : public mozilla::Runnable {
    141   public:
    142    ContentListHolder(nsHTMLDocument* aDocument, nsContentList* aFormList,
    143                      nsContentList* aFormControlList)
    144        : mozilla::Runnable("ContentListHolder"),
    145          mDocument(aDocument),
    146          mFormList(aFormList),
    147          mFormControlList(aFormControlList) {}
    148 
    149    ~ContentListHolder() {
    150      MOZ_ASSERT(!mDocument->mContentListHolder ||
    151                 mDocument->mContentListHolder == this);
    152      mDocument->mContentListHolder = nullptr;
    153    }
    154 
    155    RefPtr<nsHTMLDocument> mDocument;
    156    RefPtr<nsContentList> mFormList;
    157    RefPtr<nsContentList> mFormControlList;
    158  };
    159 
    160  friend class ContentListHolder;
    161  ContentListHolder* mContentListHolder;
    162 
    163  /** # of forms in the document, synchronously set */
    164  int32_t mNumForms;
    165 
    166  static void TryReloadCharset(nsIDocumentViewer* aViewer,
    167                               int32_t& aCharsetSource,
    168                               NotNull<const Encoding*>& aEncoding);
    169  void TryUserForcedCharset(nsIDocumentViewer* aViewer, nsIDocShell* aDocShell,
    170                            int32_t& aCharsetSource,
    171                            NotNull<const Encoding*>& aEncoding,
    172                            bool& aForceAutoDetection);
    173  void TryParentCharset(nsIDocShell* aDocShell, int32_t& charsetSource,
    174                        NotNull<const Encoding*>& aEncoding,
    175                        bool& aForceAutoDetection);
    176 
    177  // Load flags of the document's channel
    178  uint32_t mLoadFlags;
    179 
    180  bool mWarnedWidthHeight;
    181 
    182  /**
    183   * Set to true once we know that we are loading plain text content.
    184   */
    185  bool mIsPlainText;
    186 
    187  /**
    188   * Set to true once we know that we are viewing source.
    189   */
    190  bool mViewSource;
    191 };
    192 
    193 namespace mozilla::dom {
    194 
    195 inline nsHTMLDocument* Document::AsHTMLDocument() {
    196  MOZ_ASSERT(IsHTMLOrXHTML());
    197  return static_cast<nsHTMLDocument*>(this);
    198 }
    199 
    200 inline const nsHTMLDocument* Document::AsHTMLDocument() const {
    201  MOZ_ASSERT(IsHTMLOrXHTML());
    202  return static_cast<const nsHTMLDocument*>(this);
    203 }
    204 
    205 }  // namespace mozilla::dom
    206 
    207 #endif /* nsHTMLDocument_h___ */