Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLDocument.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsHTMLDocument_h___
00038 #define nsHTMLDocument_h___
00039 
00040 #include "nsDocument.h"
00041 #include "nsIHTMLDocument.h"
00042 #include "nsIDOMHTMLDocument.h"
00043 #include "nsIDOMNSHTMLDocument.h"
00044 #include "nsIDOMHTMLBodyElement.h"
00045 #include "nsIDOMHTMLMapElement.h"
00046 #include "nsIDOMHTMLCollection.h"
00047 #include "jsapi.h"
00048 #include "rdf.h"
00049 #include "nsRDFCID.h"
00050 #include "nsIRDFService.h"
00051 #include "pldhash.h"
00052 #include "nsIHttpChannel.h"
00053 #include "nsHTMLStyleSheet.h"
00054 
00055 // Document.Write() related
00056 #include "nsIWyciwygChannel.h"
00057 #include "nsILoadGroup.h"
00058 #include "nsNetUtil.h"
00059 
00060 #include "nsICommandManager.h"
00061 
00062 class nsIParser;
00063 class nsIURI;
00064 class nsIMarkupDocumentViewer;
00065 class nsIDocumentCharsetInfo;
00066 class nsICacheEntryDescriptor;
00067 
00068 class nsHTMLDocument : public nsDocument,
00069                        public nsIHTMLDocument,
00070                        public nsIDOMHTMLDocument,
00071                        public nsIDOMNSHTMLDocument
00072 {
00073 public:
00074   nsHTMLDocument();
00075   virtual ~nsHTMLDocument();
00076   virtual nsresult Init();
00077   virtual NS_HIDDEN_(void) Destroy();
00078  
00079   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00080 
00081   NS_IMETHOD_(nsrefcnt) AddRef(void);
00082   NS_IMETHOD_(nsrefcnt) Release(void);
00083 
00084   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
00085   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup);
00086   virtual nsStyleSet::sheetType GetAttrSheetType();
00087 
00088   virtual nsresult CreateShell(nsPresContext* aContext,
00089                                nsIViewManager* aViewManager,
00090                                nsStyleSet* aStyleSet,
00091                                nsIPresShell** aInstancePtrResult);
00092 
00093   virtual nsresult StartDocumentLoad(const char* aCommand,
00094                                      nsIChannel* aChannel,
00095                                      nsILoadGroup* aLoadGroup,
00096                                      nsISupports* aContainer,
00097                                      nsIStreamListener **aDocListener,
00098                                      PRBool aReset = PR_TRUE,
00099                                      nsIContentSink* aSink = nsnull);
00100 
00101   virtual void EndLoad();
00102 
00103   virtual nsresult AddImageMap(nsIDOMHTMLMapElement* aMap);
00104 
00105   virtual void RemoveImageMap(nsIDOMHTMLMapElement* aMap);
00106 
00107   virtual nsIDOMHTMLMapElement *GetImageMap(const nsAString& aMapName);
00108 
00109   virtual nsCompatibility GetCompatibilityMode();
00110   virtual void SetCompatibilityMode(nsCompatibility aMode);
00111 
00112   virtual PRBool IsWriting()
00113   {
00114     return mWriteLevel != PRUint32(0);
00115   }
00116 
00117   virtual PRBool GetIsFrameset() { return mIsFrameset; }
00118   virtual void SetIsFrameset(PRBool aFrameset) { mIsFrameset = aFrameset; }
00119 
00120   virtual NS_HIDDEN_(nsContentList*) GetForms();
00121  
00122   virtual void ContentAppended(nsIContent* aContainer,
00123                                PRInt32 aNewIndexInContainer);
00124   virtual void ContentInserted(nsIContent* aContainer,
00125                                nsIContent* aChild,
00126                                PRInt32 aIndexInContainer);
00127   virtual void ContentRemoved(nsIContent* aContainer,
00128                               nsIContent* aChild,
00129                               PRInt32 aIndexInContainer);
00130   virtual void AttributeChanged(nsIContent* aChild,
00131                                 PRInt32 aNameSpaceID,
00132                                 nsIAtom* aAttribute,
00133                                 PRInt32 aModType);
00134   virtual void AttributeWillChange(nsIContent* aChild,
00135                                    PRInt32 aNameSpaceID,
00136                                    nsIAtom* aAttribute);
00137 
00138   virtual void FlushPendingNotifications(mozFlushType aType);
00139 
00140   virtual PRBool IsCaseSensitive();
00141 
00142   // nsIDOMDocument interface
00143   NS_DECL_NSIDOMDOCUMENT
00144 
00145   // nsIDOM3Document interface
00146   NS_IMETHOD GetXmlEncoding(nsAString& aXmlVersion);
00147   NS_IMETHOD GetXmlStandalone(PRBool *aXmlStandalone);
00148   NS_IMETHOD SetXmlStandalone(PRBool aXmlStandalone);
00149   NS_IMETHOD GetXmlVersion(nsAString& aXmlVersion);
00150   NS_IMETHOD SetXmlVersion(const nsAString& aXmlVersion);
00151 
00152   // nsIDOMNode interface
00153   NS_FORWARD_NSIDOMNODE(nsDocument::)
00154 
00155   // nsIDOM3Node interface
00156   NS_IMETHOD GetBaseURI(nsAString& aBaseURI);
00157 
00158   // nsIDOMHTMLDocument interface
00159   NS_IMETHOD GetTitle(nsAString & aTitle);
00160   NS_IMETHOD SetTitle(const nsAString & aTitle);
00161   NS_IMETHOD GetReferrer(nsAString & aReferrer);
00162   NS_IMETHOD GetURL(nsAString & aURL);
00163   NS_IMETHOD GetBody(nsIDOMHTMLElement * *aBody);
00164   NS_IMETHOD SetBody(nsIDOMHTMLElement * aBody);
00165   NS_IMETHOD GetImages(nsIDOMHTMLCollection * *aImages);
00166   NS_IMETHOD GetApplets(nsIDOMHTMLCollection * *aApplets);
00167   NS_IMETHOD GetLinks(nsIDOMHTMLCollection * *aLinks);
00168   NS_IMETHOD GetForms(nsIDOMHTMLCollection * *aForms);
00169   NS_IMETHOD GetAnchors(nsIDOMHTMLCollection * *aAnchors);
00170   NS_IMETHOD GetCookie(nsAString & aCookie);
00171   NS_IMETHOD SetCookie(const nsAString & aCookie);
00172   NS_IMETHOD Open(void);
00173   NS_IMETHOD Close(void);
00174   NS_IMETHOD Write(const nsAString & text);
00175   NS_IMETHOD Writeln(const nsAString & text);
00176   NS_IMETHOD GetElementsByName(const nsAString & elementName,
00177                                nsIDOMNodeList **_retval);
00178 
00179   // nsIDOMNSHTMLDocument interface
00180   NS_DECL_NSIDOMNSHTMLDOCUMENT
00181 
00182   /*
00183    * Returns true if document.domain was set for this document
00184    */
00185   virtual PRBool WasDomainSet();
00186 
00187   virtual nsresult ResolveName(const nsAString& aName,
00188                          nsIDOMHTMLFormElement *aForm,
00189                          nsISupports **aResult);
00190 
00191   virtual void AddedForm();
00192   virtual void RemovedForm();
00193   virtual PRInt32 GetNumFormsSynchronous();
00194 
00195   PRBool IsXHTML()
00196   {
00197     return mDefaultNamespaceID == kNameSpaceID_XHTML;
00198   }
00199 
00200 #ifdef DEBUG
00201   virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
00202                               PRInt32 aNamespaceID,
00203                               PRBool aDocumentDefaultType,
00204                               nsIContent** aResult);
00205 #endif
00206 
00207 protected:
00208   nsresult GetPixelDimensions(nsIPresShell* aShell,
00209                               PRInt32* aWidth,
00210                               PRInt32* aHeight);
00211 
00212   nsresult RegisterNamedItems(nsIContent *aContent);
00213   nsresult UnregisterNamedItems(nsIContent *aContent);
00214   nsresult UpdateNameTableEntry(const nsAString& aName,
00215                                 nsIContent *aContent);
00216   nsresult AddToIdTable(const nsAString& aId, nsIContent *aContent);
00217   nsresult UpdateIdTableEntry(const nsAString& aId, nsIContent *aContent);
00218   nsresult RemoveFromNameTable(const nsAString& aName, nsIContent *aContent);
00219   nsresult RemoveFromIdTable(nsIContent *aContent);
00220 
00221   void InvalidateHashTables();
00222   nsresult PrePopulateHashTables();
00223 
00224   nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
00225 
00226   static PRBool MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID,
00227                            nsIAtom* aAtom, const nsAString& aData);
00228   static PRBool MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID,
00229                              nsIAtom* aAtom, const nsAString& aData);
00230   static PRBool MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
00231                                    nsIAtom* aAtom, const nsAString& aData);
00232 
00233   static void DocumentWriteTerminationFunc(nsISupports *aRef);
00234 
00235   PRBool GetBodyContent();
00236   void GetBodyElement(nsIDOMHTMLBodyElement** aBody);
00237 
00238   void GetDomainURI(nsIURI **uri);
00239 
00240   nsresult WriteCommon(const nsAString& aText,
00241                        PRBool aNewlineTerminate);
00242   nsresult ScriptWriteCommon(PRBool aNewlineTerminate);
00243   nsresult OpenCommon(const nsACString& aContentType, PRBool aReplace);
00244 
00245   nsresult CreateAndAddWyciwygChannel(void);
00246   nsresult RemoveWyciwygChannel(void);
00247 
00248   void *GenerateParserKey(void);
00249 
00250   PRInt32 GetDefaultNamespaceID() const
00251   {
00252     return mDefaultNamespaceID;
00253   };
00254 
00255   nsCompatibility mCompatMode;
00256 
00257   nsCOMArray<nsIDOMHTMLMapElement> mImageMaps;
00258 
00259   nsCOMPtr<nsIDOMHTMLCollection> mImages;
00260   nsCOMPtr<nsIDOMHTMLCollection> mApplets;
00261   nsCOMPtr<nsIDOMHTMLCollection> mEmbeds;
00262   nsCOMPtr<nsIDOMHTMLCollection> mLinks;
00263   nsCOMPtr<nsIDOMHTMLCollection> mAnchors;
00264   nsRefPtr<nsContentList> mForms;
00265 
00267   PRInt32 mNumForms;
00268 
00269   // ahmed 12-2
00270   PRInt32  mTexttype;
00271 
00272   static PRUint32 gWyciwygSessionCnt;
00273 
00274   static PRBool TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
00275                                PRInt32& aCharsetSource,
00276                                nsACString& aCharset);
00277   static PRBool TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
00278                                      nsIDocumentCharsetInfo*  aDocInfo,
00279                                      PRInt32& aCharsetSource,
00280                                      nsACString& aCharset);
00281   static PRBool TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
00282                                 PRInt32& aCharsetSource,
00283                                 nsACString& aCharset);
00284   static PRBool TryBookmarkCharset(nsIDocShell* aDocShell,
00285                                    nsIChannel* aChannel,
00286                                    PRInt32& aCharsetSource,
00287                                    nsACString& aCharset);
00288   // aParentDocument could be null.
00289   PRBool TryParentCharset(nsIDocumentCharsetInfo*  aDocInfo,
00290                           nsIDocument* aParentDocument,
00291                           PRInt32& charsetSource, nsACString& aCharset);
00292   static PRBool UseWeakDocTypeDefault(PRInt32& aCharsetSource,
00293                                       nsACString& aCharset);
00294   static PRBool TryDefaultCharset(nsIMarkupDocumentViewer* aMarkupDV,
00295                                   PRInt32& aCharsetSource,
00296                                   nsACString& aCharset);
00297 
00298   void StartAutodetection(nsIDocShell *aDocShell, nsACString& aCharset,
00299                           const char* aCommand);
00300 
00301   PRUint32 mIsWriting : 1;
00302   PRUint32 mWriteLevel : 31;
00303 
00304   // Load flags of the document's channel
00305   PRUint32 mLoadFlags;
00306 
00307   nsCOMPtr<nsIDOMNode> mBodyContent;
00308 
00309   /*
00310    * Bug 13871: Frameset spoofing - find out if document.domain was set
00311    */
00312   PRPackedBool mDomainWasSet;
00313 
00314   PRPackedBool mIsFrameset;
00315 
00316   PRPackedBool mTooDeepWriteRecursion;
00317 
00318   PLDHashTable mIdAndNameHashTable;
00319 
00320   nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
00321 
00322   /* Midas implementation */
00323   nsresult   GetMidasCommandManager(nsICommandManager** aCommandManager);
00324   PRBool     ConvertToMidasInternalCommand(const nsAString & inCommandID,
00325                                            const nsAString & inParam,
00326                                            nsACString& outCommandID,
00327                                            nsACString& outParam,
00328                                            PRBool& isBoolean,
00329                                            PRBool& boolValue);
00330   nsCOMPtr<nsICommandManager> mMidasCommandManager;
00331   PRBool                      mEditingIsOn;
00332 
00333   nsresult   DoClipboardSecurityCheck(PRBool aPaste);
00334   static jsval       sCutCopyInternal_id;
00335   static jsval       sPasteInternal_id;
00336 
00337   // kNameSpaceID_None for good ol' HTML documents, and
00338   // kNameSpaceID_XHTML for spiffy new XHTML documents.
00339   // XXXbz should this be reset if someone manually calls
00340   // SetContentType() on this document?
00341   PRInt32 mDefaultNamespaceID;
00342 };
00343 
00344 #endif /* nsHTMLDocument_h___ */