content/html/document/src/nsHTMLDocument.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/html/document/src/nsHTMLDocument.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,363 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 sw=2 et tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +#ifndef nsHTMLDocument_h___
    1.10 +#define nsHTMLDocument_h___
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsDocument.h"
    1.14 +#include "nsIHTMLDocument.h"
    1.15 +#include "nsIDOMHTMLDocument.h"
    1.16 +#include "nsIDOMHTMLCollection.h"
    1.17 +#include "nsIScriptElement.h"
    1.18 +#include "nsTArray.h"
    1.19 +
    1.20 +#include "pldhash.h"
    1.21 +#include "nsIHttpChannel.h"
    1.22 +#include "nsHTMLStyleSheet.h"
    1.23 +
    1.24 +#include "nsICommandManager.h"
    1.25 +#include "mozilla/dom/HTMLSharedElement.h"
    1.26 +
    1.27 +class nsIEditor;
    1.28 +class nsIParser;
    1.29 +class nsIURI;
    1.30 +class nsIMarkupDocumentViewer;
    1.31 +class nsIDocShell;
    1.32 +class nsICachingChannel;
    1.33 +class nsIWyciwygChannel;
    1.34 +class nsILoadGroup;
    1.35 +
    1.36 +namespace mozilla {
    1.37 +namespace dom {
    1.38 +class HTMLAllCollection;
    1.39 +} // namespace dom
    1.40 +} // namespace mozilla
    1.41 +
    1.42 +class nsHTMLDocument : public nsDocument,
    1.43 +                       public nsIHTMLDocument,
    1.44 +                       public nsIDOMHTMLDocument
    1.45 +{
    1.46 +public:
    1.47 +  using nsDocument::SetDocumentURI;
    1.48 +  using nsDocument::GetPlugins;
    1.49 +
    1.50 +  nsHTMLDocument();
    1.51 +  ~nsHTMLDocument();
    1.52 +  virtual nsresult Init() MOZ_OVERRIDE;
    1.53 +
    1.54 +  NS_DECL_ISUPPORTS_INHERITED
    1.55 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsDocument)
    1.56 +
    1.57 +  // nsIDocument
    1.58 +  virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) MOZ_OVERRIDE;
    1.59 +  virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
    1.60 +                          nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
    1.61 +
    1.62 +  virtual already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
    1.63 +                                                     nsViewManager* aViewManager,
    1.64 +                                                     nsStyleSet* aStyleSet) MOZ_OVERRIDE;
    1.65 +
    1.66 +  virtual nsresult StartDocumentLoad(const char* aCommand,
    1.67 +                                     nsIChannel* aChannel,
    1.68 +                                     nsILoadGroup* aLoadGroup,
    1.69 +                                     nsISupports* aContainer,
    1.70 +                                     nsIStreamListener **aDocListener,
    1.71 +                                     bool aReset = true,
    1.72 +                                     nsIContentSink* aSink = nullptr) MOZ_OVERRIDE;
    1.73 +  virtual void StopDocumentLoad() MOZ_OVERRIDE;
    1.74 +
    1.75 +  virtual void BeginLoad() MOZ_OVERRIDE;
    1.76 +  virtual void EndLoad() MOZ_OVERRIDE;
    1.77 +
    1.78 +  // nsIHTMLDocument
    1.79 +  virtual void SetCompatibilityMode(nsCompatibility aMode) MOZ_OVERRIDE;
    1.80 +
    1.81 +  virtual bool IsWriting() MOZ_OVERRIDE
    1.82 +  {
    1.83 +    return mWriteLevel != uint32_t(0);
    1.84 +  }
    1.85 +
    1.86 +  virtual NS_HIDDEN_(nsContentList*) GetForms();
    1.87 + 
    1.88 +  virtual NS_HIDDEN_(nsContentList*) GetFormControls();
    1.89 + 
    1.90 +  // nsIDOMDocument interface
    1.91 +  using nsDocument::CreateElement;
    1.92 +  using nsDocument::CreateElementNS;
    1.93 +  NS_FORWARD_NSIDOMDOCUMENT(nsDocument::)
    1.94 +
    1.95 +  // And explicitly import the things from nsDocument that we just shadowed
    1.96 +  using nsDocument::GetImplementation;
    1.97 +  using nsDocument::GetTitle;
    1.98 +  using nsDocument::SetTitle;
    1.99 +  using nsDocument::GetLastStyleSheetSet;
   1.100 +  using nsDocument::MozSetImageElement;
   1.101 +  using nsDocument::GetMozFullScreenElement;
   1.102 +
   1.103 +  // nsIDOMNode interface
   1.104 +  NS_FORWARD_NSIDOMNODE_TO_NSINODE
   1.105 +
   1.106 +  // nsIDOMHTMLDocument interface
   1.107 +  NS_DECL_NSIDOMHTMLDOCUMENT
   1.108 +
   1.109 +  mozilla::dom::HTMLAllCollection* All();
   1.110 +  void GetAll(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
   1.111 +              mozilla::ErrorResult& aRv);
   1.112 +
   1.113 +  nsISupports* ResolveName(const nsAString& aName, nsWrapperCache **aCache);
   1.114 +
   1.115 +  virtual void AddedForm() MOZ_OVERRIDE;
   1.116 +  virtual void RemovedForm() MOZ_OVERRIDE;
   1.117 +  virtual int32_t GetNumFormsSynchronous() MOZ_OVERRIDE;
   1.118 +  virtual void TearingDownEditor(nsIEditor *aEditor) MOZ_OVERRIDE;
   1.119 +  virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE { mIsRegularHTML = !aXHTML; }
   1.120 +  virtual void SetDocWriteDisabled(bool aDisabled) MOZ_OVERRIDE
   1.121 +  {
   1.122 +    mDisableDocWrite = aDisabled;
   1.123 +  }
   1.124 +
   1.125 +  nsresult ChangeContentEditableCount(nsIContent *aElement, int32_t aChange) MOZ_OVERRIDE;
   1.126 +  void DeferredContentEditableCountChange(nsIContent *aElement);
   1.127 +
   1.128 +  virtual EditingState GetEditingState() MOZ_OVERRIDE
   1.129 +  {
   1.130 +    return mEditingState;
   1.131 +  }
   1.132 +
   1.133 +  virtual void DisableCookieAccess() MOZ_OVERRIDE
   1.134 +  {
   1.135 +    mDisableCookieAccess = true;
   1.136 +  }
   1.137 +
   1.138 +  class nsAutoEditingState {
   1.139 +  public:
   1.140 +    nsAutoEditingState(nsHTMLDocument* aDoc, EditingState aState)
   1.141 +      : mDoc(aDoc), mSavedState(aDoc->mEditingState)
   1.142 +    {
   1.143 +      aDoc->mEditingState = aState;
   1.144 +    }
   1.145 +    ~nsAutoEditingState() {
   1.146 +      mDoc->mEditingState = mSavedState;
   1.147 +    }
   1.148 +  private:
   1.149 +    nsHTMLDocument* mDoc;
   1.150 +    EditingState    mSavedState;
   1.151 +  };
   1.152 +  friend class nsAutoEditingState;
   1.153 +
   1.154 +  void EndUpdate(nsUpdateType aUpdateType) MOZ_OVERRIDE;
   1.155 +
   1.156 +  virtual nsresult SetEditingState(EditingState aState) MOZ_OVERRIDE;
   1.157 +
   1.158 +  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
   1.159 +
   1.160 +  virtual NS_HIDDEN_(void) RemovedFromDocShell() MOZ_OVERRIDE;
   1.161 +
   1.162 +  virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId)
   1.163 +  {
   1.164 +    return nsDocument::GetElementById(aElementId);
   1.165 +  }
   1.166 +
   1.167 +  virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const MOZ_OVERRIDE;
   1.168 +  // DocAddSizeOfIncludingThis is inherited from nsIDocument.
   1.169 +
   1.170 +  virtual bool WillIgnoreCharsetOverride() MOZ_OVERRIDE;
   1.171 +
   1.172 +  // WebIDL API
   1.173 +  virtual JSObject* WrapNode(JSContext* aCx)
   1.174 +    MOZ_OVERRIDE;
   1.175 +  void GetDomain(nsAString& aDomain, mozilla::ErrorResult& rv);
   1.176 +  void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
   1.177 +  void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
   1.178 +  void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
   1.179 +  void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
   1.180 +                   JS::MutableHandle<JSObject*> aRetval,
   1.181 +                   mozilla::ErrorResult& rv);
   1.182 +  bool NameIsEnumerable(const nsAString& aName);
   1.183 +  void GetSupportedNames(unsigned, nsTArray<nsString>& aNames);
   1.184 +  nsGenericHTMLElement *GetBody();
   1.185 +  void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv);
   1.186 +  mozilla::dom::HTMLSharedElement *GetHead() {
   1.187 +    return static_cast<mozilla::dom::HTMLSharedElement*>(GetHeadElement());
   1.188 +  }
   1.189 +  nsIHTMLCollection* Images();
   1.190 +  nsIHTMLCollection* Embeds();
   1.191 +  nsIHTMLCollection* Plugins();
   1.192 +  nsIHTMLCollection* Links();
   1.193 +  nsIHTMLCollection* Forms()
   1.194 +  {
   1.195 +    return nsHTMLDocument::GetForms();
   1.196 +  }
   1.197 +  nsIHTMLCollection* Scripts();
   1.198 +  already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
   1.199 +  {
   1.200 +    return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr,
   1.201 +                                    UseExistingNameString, aName);
   1.202 +  }
   1.203 +  already_AddRefed<nsINodeList> GetItems(const nsAString& aTypeNames);
   1.204 +  already_AddRefed<nsIDocument> Open(JSContext* cx,
   1.205 +                                     const nsAString& aType,
   1.206 +                                     const nsAString& aReplace,
   1.207 +                                     mozilla::ErrorResult& rv);
   1.208 +  already_AddRefed<nsIDOMWindow> Open(JSContext* cx,
   1.209 +                                      const nsAString& aURL,
   1.210 +                                      const nsAString& aName,
   1.211 +                                      const nsAString& aFeatures,
   1.212 +                                      bool aReplace,
   1.213 +                                      mozilla::ErrorResult& rv);
   1.214 +  void Close(mozilla::ErrorResult& rv);
   1.215 +  void Write(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
   1.216 +             mozilla::ErrorResult& rv);
   1.217 +  void Writeln(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
   1.218 +               mozilla::ErrorResult& rv);
   1.219 +  // The XPCOM GetDesignMode() works OK for us, since it never throws.
   1.220 +  void SetDesignMode(const nsAString& aDesignMode, mozilla::ErrorResult& rv);
   1.221 +  bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
   1.222 +                   const nsAString& aValue, mozilla::ErrorResult& rv);
   1.223 +  bool QueryCommandEnabled(const nsAString& aCommandID,
   1.224 +                           mozilla::ErrorResult& rv);
   1.225 +  bool QueryCommandIndeterm(const nsAString& aCommandID,
   1.226 +                            mozilla::ErrorResult& rv);
   1.227 +  bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv);
   1.228 +  bool QueryCommandSupported(const nsAString& aCommandID);
   1.229 +  void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue,
   1.230 +                         mozilla::ErrorResult& rv);
   1.231 +  // The XPCOM Get/SetFgColor work OK for us, since they never throw.
   1.232 +  // The XPCOM Get/SetLinkColor work OK for us, since they never throw.
   1.233 +  // The XPCOM Get/SetVLinkColor work OK for us, since they never throw.
   1.234 +  // The XPCOM Get/SetALinkColor work OK for us, since they never throw.
   1.235 +  // The XPCOM Get/SetBgColor work OK for us, since they never throw.
   1.236 +  nsIHTMLCollection* Anchors();
   1.237 +  nsIHTMLCollection* Applets();
   1.238 +  void Clear() const
   1.239 +  {
   1.240 +    // Deprecated
   1.241 +  }
   1.242 +  mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aRv);
   1.243 +  // The XPCOM CaptureEvents works fine for us.
   1.244 +  // The XPCOM ReleaseEvents works fine for us.
   1.245 +  // We're picking up GetLocation from Document
   1.246 +  already_AddRefed<nsIDOMLocation> GetLocation() const {
   1.247 +    return nsIDocument::GetLocation();
   1.248 +  }
   1.249 +
   1.250 +  virtual nsHTMLDocument* AsHTMLDocument() MOZ_OVERRIDE { return this; }
   1.251 +
   1.252 +protected:
   1.253 +  nsresult GetBodySize(int32_t* aWidth,
   1.254 +                       int32_t* aHeight);
   1.255 +
   1.256 +  nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
   1.257 +
   1.258 +  static bool MatchLinks(nsIContent *aContent, int32_t aNamespaceID,
   1.259 +                           nsIAtom* aAtom, void* aData);
   1.260 +  static bool MatchAnchors(nsIContent *aContent, int32_t aNamespaceID,
   1.261 +                             nsIAtom* aAtom, void* aData);
   1.262 +  static bool MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID,
   1.263 +                                   nsIAtom* aAtom, void* aData);
   1.264 +  static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
   1.265 +
   1.266 +  static void DocumentWriteTerminationFunc(nsISupports *aRef);
   1.267 +
   1.268 +  already_AddRefed<nsIURI> GetDomainURI();
   1.269 +
   1.270 +  nsresult WriteCommon(JSContext *cx, const nsAString& aText,
   1.271 +                       bool aNewlineTerminate);
   1.272 +  // A version of WriteCommon used by WebIDL bindings
   1.273 +  void WriteCommon(JSContext *cx,
   1.274 +                   const mozilla::dom::Sequence<nsString>& aText,
   1.275 +                   bool aNewlineTerminate,
   1.276 +                   mozilla::ErrorResult& rv);
   1.277 +
   1.278 +  nsresult CreateAndAddWyciwygChannel(void);
   1.279 +  nsresult RemoveWyciwygChannel(void);
   1.280 +
   1.281 +  /**
   1.282 +   * Like IsEditingOn(), but will flush as needed first.
   1.283 +   */
   1.284 +  bool IsEditingOnAfterFlush();
   1.285 +
   1.286 +  void *GenerateParserKey(void);
   1.287 +
   1.288 +  nsRefPtr<nsContentList> mImages;
   1.289 +  nsRefPtr<nsContentList> mApplets;
   1.290 +  nsRefPtr<nsContentList> mEmbeds;
   1.291 +  nsRefPtr<nsContentList> mLinks;
   1.292 +  nsRefPtr<nsContentList> mAnchors;
   1.293 +  nsRefPtr<nsContentList> mScripts;
   1.294 +  nsRefPtr<nsContentList> mForms;
   1.295 +  nsRefPtr<nsContentList> mFormControls;
   1.296 +
   1.297 +  nsRefPtr<mozilla::dom::HTMLAllCollection> mAll;
   1.298 +
   1.299 +  /** # of forms in the document, synchronously set */
   1.300 +  int32_t mNumForms;
   1.301 +
   1.302 +  static uint32_t gWyciwygSessionCnt;
   1.303 +
   1.304 +  static void TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
   1.305 +                             int32_t& aCharsetSource,
   1.306 +                             nsACString& aCharset);
   1.307 +  void TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
   1.308 +                            nsIDocShell*  aDocShell,
   1.309 +                            int32_t& aCharsetSource,
   1.310 +                            nsACString& aCharset);
   1.311 +  static void TryCacheCharset(nsICachingChannel* aCachingChannel,
   1.312 +                                int32_t& aCharsetSource,
   1.313 +                                nsACString& aCharset);
   1.314 +  void TryParentCharset(nsIDocShell*  aDocShell,
   1.315 +                        int32_t& charsetSource, nsACString& aCharset);
   1.316 +  void TryTLD(int32_t& aCharsetSource, nsACString& aCharset);
   1.317 +  static void TryFallback(int32_t& aCharsetSource, nsACString& aCharset);
   1.318 +
   1.319 +  // Override so we can munge the charset on our wyciwyg channel as needed.
   1.320 +  virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) MOZ_OVERRIDE;
   1.321 +
   1.322 +  // Tracks if we are currently processing any document.write calls (either
   1.323 +  // implicit or explicit). Note that if a write call writes out something which
   1.324 +  // would block the parser, then mWriteLevel will be incorrect until the parser
   1.325 +  // finishes processing that script.
   1.326 +  uint32_t mWriteLevel;
   1.327 +
   1.328 +  // Load flags of the document's channel
   1.329 +  uint32_t mLoadFlags;
   1.330 +
   1.331 +  bool mTooDeepWriteRecursion;
   1.332 +
   1.333 +  bool mDisableDocWrite;
   1.334 +
   1.335 +  bool mWarnedWidthHeight;
   1.336 +
   1.337 +  nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
   1.338 +
   1.339 +  /* Midas implementation */
   1.340 +  nsresult   GetMidasCommandManager(nsICommandManager** aCommandManager);
   1.341 +
   1.342 +  nsCOMPtr<nsICommandManager> mMidasCommandManager;
   1.343 +
   1.344 +  nsresult TurnEditingOff();
   1.345 +  nsresult EditingStateChanged();
   1.346 +  void MaybeEditingStateChanged();
   1.347 +
   1.348 +  uint32_t mContentEditableCount;
   1.349 +  EditingState mEditingState;
   1.350 +
   1.351 +  // When false, the .cookies property is completely disabled
   1.352 +  bool mDisableCookieAccess;
   1.353 +
   1.354 +  /**
   1.355 +   * Temporary flag that is set in EndUpdate() to ignore
   1.356 +   * MaybeEditingStateChanged() script runners from a nested scope.
   1.357 +   */
   1.358 +  bool mPendingMaybeEditingStateChanged;
   1.359 +};
   1.360 +
   1.361 +#define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class)                        \
   1.362 +    NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class)                                 \
   1.363 +    NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument)                         \
   1.364 +    NS_INTERFACE_TABLE_ENTRY(_class, nsIDOMHTMLDocument)
   1.365 +
   1.366 +#endif /* nsHTMLDocument_h___ */

mercurial