michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsHTMLDocument_h___ michael@0: #define nsHTMLDocument_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsDocument.h" michael@0: #include "nsIHTMLDocument.h" michael@0: #include "nsIDOMHTMLDocument.h" michael@0: #include "nsIDOMHTMLCollection.h" michael@0: #include "nsIScriptElement.h" michael@0: #include "nsTArray.h" michael@0: michael@0: #include "pldhash.h" michael@0: #include "nsIHttpChannel.h" michael@0: #include "nsHTMLStyleSheet.h" michael@0: michael@0: #include "nsICommandManager.h" michael@0: #include "mozilla/dom/HTMLSharedElement.h" michael@0: michael@0: class nsIEditor; michael@0: class nsIParser; michael@0: class nsIURI; michael@0: class nsIMarkupDocumentViewer; michael@0: class nsIDocShell; michael@0: class nsICachingChannel; michael@0: class nsIWyciwygChannel; michael@0: class nsILoadGroup; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class HTMLAllCollection; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: class nsHTMLDocument : public nsDocument, michael@0: public nsIHTMLDocument, michael@0: public nsIDOMHTMLDocument michael@0: { michael@0: public: michael@0: using nsDocument::SetDocumentURI; michael@0: using nsDocument::GetPlugins; michael@0: michael@0: nsHTMLDocument(); michael@0: ~nsHTMLDocument(); michael@0: virtual nsresult Init() MOZ_OVERRIDE; michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsDocument) michael@0: michael@0: // nsIDocument michael@0: virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) MOZ_OVERRIDE; michael@0: virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, michael@0: nsIPrincipal* aPrincipal) MOZ_OVERRIDE; michael@0: michael@0: virtual already_AddRefed CreateShell(nsPresContext* aContext, michael@0: nsViewManager* aViewManager, michael@0: nsStyleSet* aStyleSet) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult StartDocumentLoad(const char* aCommand, michael@0: nsIChannel* aChannel, michael@0: nsILoadGroup* aLoadGroup, michael@0: nsISupports* aContainer, michael@0: nsIStreamListener **aDocListener, michael@0: bool aReset = true, michael@0: nsIContentSink* aSink = nullptr) MOZ_OVERRIDE; michael@0: virtual void StopDocumentLoad() MOZ_OVERRIDE; michael@0: michael@0: virtual void BeginLoad() MOZ_OVERRIDE; michael@0: virtual void EndLoad() MOZ_OVERRIDE; michael@0: michael@0: // nsIHTMLDocument michael@0: virtual void SetCompatibilityMode(nsCompatibility aMode) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsWriting() MOZ_OVERRIDE michael@0: { michael@0: return mWriteLevel != uint32_t(0); michael@0: } michael@0: michael@0: virtual NS_HIDDEN_(nsContentList*) GetForms(); michael@0: michael@0: virtual NS_HIDDEN_(nsContentList*) GetFormControls(); michael@0: michael@0: // nsIDOMDocument interface michael@0: using nsDocument::CreateElement; michael@0: using nsDocument::CreateElementNS; michael@0: NS_FORWARD_NSIDOMDOCUMENT(nsDocument::) michael@0: michael@0: // And explicitly import the things from nsDocument that we just shadowed michael@0: using nsDocument::GetImplementation; michael@0: using nsDocument::GetTitle; michael@0: using nsDocument::SetTitle; michael@0: using nsDocument::GetLastStyleSheetSet; michael@0: using nsDocument::MozSetImageElement; michael@0: using nsDocument::GetMozFullScreenElement; michael@0: michael@0: // nsIDOMNode interface michael@0: NS_FORWARD_NSIDOMNODE_TO_NSINODE michael@0: michael@0: // nsIDOMHTMLDocument interface michael@0: NS_DECL_NSIDOMHTMLDOCUMENT michael@0: michael@0: mozilla::dom::HTMLAllCollection* All(); michael@0: void GetAll(JSContext* aCx, JS::MutableHandle aRetval, michael@0: mozilla::ErrorResult& aRv); michael@0: michael@0: nsISupports* ResolveName(const nsAString& aName, nsWrapperCache **aCache); michael@0: michael@0: virtual void AddedForm() MOZ_OVERRIDE; michael@0: virtual void RemovedForm() MOZ_OVERRIDE; michael@0: virtual int32_t GetNumFormsSynchronous() MOZ_OVERRIDE; michael@0: virtual void TearingDownEditor(nsIEditor *aEditor) MOZ_OVERRIDE; michael@0: virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE { mIsRegularHTML = !aXHTML; } michael@0: virtual void SetDocWriteDisabled(bool aDisabled) MOZ_OVERRIDE michael@0: { michael@0: mDisableDocWrite = aDisabled; michael@0: } michael@0: michael@0: nsresult ChangeContentEditableCount(nsIContent *aElement, int32_t aChange) MOZ_OVERRIDE; michael@0: void DeferredContentEditableCountChange(nsIContent *aElement); michael@0: michael@0: virtual EditingState GetEditingState() MOZ_OVERRIDE michael@0: { michael@0: return mEditingState; michael@0: } michael@0: michael@0: virtual void DisableCookieAccess() MOZ_OVERRIDE michael@0: { michael@0: mDisableCookieAccess = true; michael@0: } michael@0: michael@0: class nsAutoEditingState { michael@0: public: michael@0: nsAutoEditingState(nsHTMLDocument* aDoc, EditingState aState) michael@0: : mDoc(aDoc), mSavedState(aDoc->mEditingState) michael@0: { michael@0: aDoc->mEditingState = aState; michael@0: } michael@0: ~nsAutoEditingState() { michael@0: mDoc->mEditingState = mSavedState; michael@0: } michael@0: private: michael@0: nsHTMLDocument* mDoc; michael@0: EditingState mSavedState; michael@0: }; michael@0: friend class nsAutoEditingState; michael@0: michael@0: void EndUpdate(nsUpdateType aUpdateType) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult SetEditingState(EditingState aState) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; michael@0: michael@0: virtual NS_HIDDEN_(void) RemovedFromDocShell() MOZ_OVERRIDE; michael@0: michael@0: virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId) michael@0: { michael@0: return nsDocument::GetElementById(aElementId); michael@0: } michael@0: michael@0: virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const MOZ_OVERRIDE; michael@0: // DocAddSizeOfIncludingThis is inherited from nsIDocument. michael@0: michael@0: virtual bool WillIgnoreCharsetOverride() MOZ_OVERRIDE; michael@0: michael@0: // WebIDL API michael@0: virtual JSObject* WrapNode(JSContext* aCx) michael@0: MOZ_OVERRIDE; michael@0: void GetDomain(nsAString& aDomain, mozilla::ErrorResult& rv); michael@0: void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv); michael@0: void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv); michael@0: void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv); michael@0: void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound, michael@0: JS::MutableHandle aRetval, michael@0: mozilla::ErrorResult& rv); michael@0: bool NameIsEnumerable(const nsAString& aName); michael@0: void GetSupportedNames(unsigned, nsTArray& aNames); michael@0: nsGenericHTMLElement *GetBody(); michael@0: void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv); michael@0: mozilla::dom::HTMLSharedElement *GetHead() { michael@0: return static_cast(GetHeadElement()); michael@0: } michael@0: nsIHTMLCollection* Images(); michael@0: nsIHTMLCollection* Embeds(); michael@0: nsIHTMLCollection* Plugins(); michael@0: nsIHTMLCollection* Links(); michael@0: nsIHTMLCollection* Forms() michael@0: { michael@0: return nsHTMLDocument::GetForms(); michael@0: } michael@0: nsIHTMLCollection* Scripts(); michael@0: already_AddRefed GetElementsByName(const nsAString & aName) michael@0: { michael@0: return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr, michael@0: UseExistingNameString, aName); michael@0: } michael@0: already_AddRefed GetItems(const nsAString& aTypeNames); michael@0: already_AddRefed Open(JSContext* cx, michael@0: const nsAString& aType, michael@0: const nsAString& aReplace, michael@0: mozilla::ErrorResult& rv); michael@0: already_AddRefed Open(JSContext* cx, michael@0: const nsAString& aURL, michael@0: const nsAString& aName, michael@0: const nsAString& aFeatures, michael@0: bool aReplace, michael@0: mozilla::ErrorResult& rv); michael@0: void Close(mozilla::ErrorResult& rv); michael@0: void Write(JSContext* cx, const mozilla::dom::Sequence& aText, michael@0: mozilla::ErrorResult& rv); michael@0: void Writeln(JSContext* cx, const mozilla::dom::Sequence& aText, michael@0: mozilla::ErrorResult& rv); michael@0: // The XPCOM GetDesignMode() works OK for us, since it never throws. michael@0: void SetDesignMode(const nsAString& aDesignMode, mozilla::ErrorResult& rv); michael@0: bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI, michael@0: const nsAString& aValue, mozilla::ErrorResult& rv); michael@0: bool QueryCommandEnabled(const nsAString& aCommandID, michael@0: mozilla::ErrorResult& rv); michael@0: bool QueryCommandIndeterm(const nsAString& aCommandID, michael@0: mozilla::ErrorResult& rv); michael@0: bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv); michael@0: bool QueryCommandSupported(const nsAString& aCommandID); michael@0: void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue, michael@0: mozilla::ErrorResult& rv); michael@0: // The XPCOM Get/SetFgColor work OK for us, since they never throw. michael@0: // The XPCOM Get/SetLinkColor work OK for us, since they never throw. michael@0: // The XPCOM Get/SetVLinkColor work OK for us, since they never throw. michael@0: // The XPCOM Get/SetALinkColor work OK for us, since they never throw. michael@0: // The XPCOM Get/SetBgColor work OK for us, since they never throw. michael@0: nsIHTMLCollection* Anchors(); michael@0: nsIHTMLCollection* Applets(); michael@0: void Clear() const michael@0: { michael@0: // Deprecated michael@0: } michael@0: mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aRv); michael@0: // The XPCOM CaptureEvents works fine for us. michael@0: // The XPCOM ReleaseEvents works fine for us. michael@0: // We're picking up GetLocation from Document michael@0: already_AddRefed GetLocation() const { michael@0: return nsIDocument::GetLocation(); michael@0: } michael@0: michael@0: virtual nsHTMLDocument* AsHTMLDocument() MOZ_OVERRIDE { return this; } michael@0: michael@0: protected: michael@0: nsresult GetBodySize(int32_t* aWidth, michael@0: int32_t* aHeight); michael@0: michael@0: nsIContent *MatchId(nsIContent *aContent, const nsAString& aId); michael@0: michael@0: static bool MatchLinks(nsIContent *aContent, int32_t aNamespaceID, michael@0: nsIAtom* aAtom, void* aData); michael@0: static bool MatchAnchors(nsIContent *aContent, int32_t aNamespaceID, michael@0: nsIAtom* aAtom, void* aData); michael@0: static bool MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID, michael@0: nsIAtom* aAtom, void* aData); michael@0: static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName); michael@0: michael@0: static void DocumentWriteTerminationFunc(nsISupports *aRef); michael@0: michael@0: already_AddRefed GetDomainURI(); michael@0: michael@0: nsresult WriteCommon(JSContext *cx, const nsAString& aText, michael@0: bool aNewlineTerminate); michael@0: // A version of WriteCommon used by WebIDL bindings michael@0: void WriteCommon(JSContext *cx, michael@0: const mozilla::dom::Sequence& aText, michael@0: bool aNewlineTerminate, michael@0: mozilla::ErrorResult& rv); michael@0: michael@0: nsresult CreateAndAddWyciwygChannel(void); michael@0: nsresult RemoveWyciwygChannel(void); michael@0: michael@0: /** michael@0: * Like IsEditingOn(), but will flush as needed first. michael@0: */ michael@0: bool IsEditingOnAfterFlush(); michael@0: michael@0: void *GenerateParserKey(void); michael@0: michael@0: nsRefPtr mImages; michael@0: nsRefPtr mApplets; michael@0: nsRefPtr mEmbeds; michael@0: nsRefPtr mLinks; michael@0: nsRefPtr mAnchors; michael@0: nsRefPtr mScripts; michael@0: nsRefPtr mForms; michael@0: nsRefPtr mFormControls; michael@0: michael@0: nsRefPtr mAll; michael@0: michael@0: /** # of forms in the document, synchronously set */ michael@0: int32_t mNumForms; michael@0: michael@0: static uint32_t gWyciwygSessionCnt; michael@0: michael@0: static void TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV, michael@0: int32_t& aCharsetSource, michael@0: nsACString& aCharset); michael@0: void TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV, michael@0: nsIDocShell* aDocShell, michael@0: int32_t& aCharsetSource, michael@0: nsACString& aCharset); michael@0: static void TryCacheCharset(nsICachingChannel* aCachingChannel, michael@0: int32_t& aCharsetSource, michael@0: nsACString& aCharset); michael@0: void TryParentCharset(nsIDocShell* aDocShell, michael@0: int32_t& charsetSource, nsACString& aCharset); michael@0: void TryTLD(int32_t& aCharsetSource, nsACString& aCharset); michael@0: static void TryFallback(int32_t& aCharsetSource, nsACString& aCharset); michael@0: michael@0: // Override so we can munge the charset on our wyciwyg channel as needed. michael@0: virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) MOZ_OVERRIDE; michael@0: michael@0: // Tracks if we are currently processing any document.write calls (either michael@0: // implicit or explicit). Note that if a write call writes out something which michael@0: // would block the parser, then mWriteLevel will be incorrect until the parser michael@0: // finishes processing that script. michael@0: uint32_t mWriteLevel; michael@0: michael@0: // Load flags of the document's channel michael@0: uint32_t mLoadFlags; michael@0: michael@0: bool mTooDeepWriteRecursion; michael@0: michael@0: bool mDisableDocWrite; michael@0: michael@0: bool mWarnedWidthHeight; michael@0: michael@0: nsCOMPtr mWyciwygChannel; michael@0: michael@0: /* Midas implementation */ michael@0: nsresult GetMidasCommandManager(nsICommandManager** aCommandManager); michael@0: michael@0: nsCOMPtr mMidasCommandManager; michael@0: michael@0: nsresult TurnEditingOff(); michael@0: nsresult EditingStateChanged(); michael@0: void MaybeEditingStateChanged(); michael@0: michael@0: uint32_t mContentEditableCount; michael@0: EditingState mEditingState; michael@0: michael@0: // When false, the .cookies property is completely disabled michael@0: bool mDisableCookieAccess; michael@0: michael@0: /** michael@0: * Temporary flag that is set in EndUpdate() to ignore michael@0: * MaybeEditingStateChanged() script runners from a nested scope. michael@0: */ michael@0: bool mPendingMaybeEditingStateChanged; michael@0: }; michael@0: michael@0: #define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \ michael@0: NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \ michael@0: NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument) \ michael@0: NS_INTERFACE_TABLE_ENTRY(_class, nsIDOMHTMLDocument) michael@0: michael@0: #endif /* nsHTMLDocument_h___ */