/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** *//* * Base class for all our document implementations. */#ifndef nsDocument_h___#define nsDocument_h___#include"nsCOMPtr.h"#include"nsAutoPtr.h"#include"nsCRT.h"#include"nsIDocument.h"#include"nsWeakReference.h"#include"nsWeakPtr.h"#include"nsVoidArray.h"#include"nsTArray.h"#include"nsHashSets.h"#include"nsIDOMXMLDocument.h"#include"nsIDOMDocumentXBL.h"#include"nsIDOMNSDocument.h"#include"nsIDOMNSDocumentStyle.h"#include"nsIDOMDocumentRange.h"#include"nsIDOMDocumentTraversal.h"#include"nsStubDocumentObserver.h"#include"nsIDOM3EventTarget.h"#include"nsIDOMNSEventTarget.h"#include"nsIDOMStyleSheetList.h"#include"nsIScriptGlobalObject.h"#include"nsIDOMEventTarget.h"#include"nsIContent.h"#include"nsIEventListenerManager.h"#include"nsIDOM3Node.h"#include"nsIDOMNodeSelector.h"#include"nsIPrincipal.h"#include"nsIParser.h"#include"nsBindingManager.h"#include"nsINodeInfo.h"#include"nsIDOMDocumentEvent.h"#include"nsIDOM3DocumentEvent.h"#include"nsHashtable.h"#include"nsInterfaceHashtable.h"#include"nsIBoxObject.h"#include"nsPIBoxObject.h"#include"nsIScriptObjectPrincipal.h"#include"nsIURI.h"#include"nsScriptLoader.h"#include"nsIRadioGroupContainer.h"#include"nsIScriptEventManager.h"#include"nsILayoutHistoryState.h"#include"nsIRequest.h"#include"nsILoadGroup.h"#include"nsTObserverArray.h"#include"nsStubMutationObserver.h"#include"nsIChannel.h"#include"nsCycleCollectionParticipant.h"#include"nsContentList.h"#include"nsGkAtoms.h"#include"nsIApplicationCache.h"#include"nsIApplicationCacheContainer.h"#include"nsStyleSet.h"#include"pldhash.h"#include"nsAttrAndChildArray.h"#include"nsDOMAttributeMap.h"#include"nsContentUtils.h"#include"nsThreadUtils.h"#include"nsIDocumentViewer.h"#include"nsIDOMXPathNSResolver.h"#include"nsIInterfaceRequestor.h"#include"nsILoadContext.h"#include"nsIProgressEventSink.h"#include"nsISecurityEventSink.h"#include"nsIChannelEventSink.h"#include"imgIRequest.h"#include"nsIDOMDOMImplementation.h"#include"nsIDOMTouchEvent.h"#define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0)#define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1)#define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2)#define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3)classnsIEventListenerManager;classnsDOMStyleSheetList;classnsDOMStyleSheetSetList;classnsIOutputStream;classnsDocument;classnsIDTD;classnsIRadioVisitor;classnsIFormControl;structnsRadioGroupStruct;classnsOnloadBlocker;classnsUnblockOnloadEvent;classnsChildContentList;classnsXMLEventsManager;classnsHTMLStyleSheet;classnsHTMLCSSStyleSheet;/** * Right now our identifier map entries contain information for 'name' * and 'id' mappings of a given string. This is so that * nsHTMLDocument::ResolveName only has to do one hash lookup instead * of two. It's not clear whether this still matters for performance. * * We also store the document.all result list here. This is mainly so that * when all elements with the given ID are removed and we remove * the ID's nsIdentifierMapEntry, the document.all result is released too. * Perhaps the document.all results should have their own hashtable * in nsHTMLDocument. */classnsIdentifierMapEntry:publicnsStringHashKey{public:typedefmozilla::dom::ElementElement;nsIdentifierMapEntry(constnsAString&aKey):nsStringHashKey(&aKey),mNameContentList(nsnull){}nsIdentifierMapEntry(constnsAString*aKey):nsStringHashKey(aKey),mNameContentList(nsnull){}nsIdentifierMapEntry(constnsIdentifierMapEntry&aOther):nsStringHashKey(&aOther.GetKey()){NS_ERROR("Should never be called");}~nsIdentifierMapEntry();voidSetInvalidName();PRBoolIsInvalidName();voidAddNameElement(nsIDocument*aDocument,Element*aElement);voidRemoveNameElement(Element*aElement);PRBoolIsEmpty();nsBaseContentList*GetNameContentList(){returnmNameContentList;}/** * Returns the element if we know the element associated with this * id. Otherwise returns null. */Element*GetIdElement();/** * If this entry has a non-null image element set (using SetImageElement), * the image element will be returned, otherwise the same as GetIdElement(). */Element*GetImageIdElement();/** * Append all the elements with this id to aElements */voidAppendAllIdContent(nsCOMArray<nsIContent>*aElements);/** * This can fire ID change callbacks. * @return true if the content could be added, false if we failed due * to OOM. */PRBoolAddIdElement(Element*aElement);/** * This can fire ID change callbacks. */voidRemoveIdElement(Element*aElement);/** * Set the image element override for this ID. This will be returned by * GetIdElement(PR_TRUE) if non-null. */voidSetImageElement(Element*aElement);PRBoolHasContentChangeCallback(){returnmChangeCallbacks!=nsnull;}voidAddContentChangeCallback(nsIDocument::IDTargetObserveraCallback,void*aData,PRBoolaForImage);voidRemoveContentChangeCallback(nsIDocument::IDTargetObserveraCallback,void*aData,PRBoolaForImage);voidTraverse(nsCycleCollectionTraversalCallback*aCallback);voidSetDocAllList(nsContentList*aContentList){mDocAllList=aContentList;}nsContentList*GetDocAllList(){returnmDocAllList;}structChangeCallback{nsIDocument::IDTargetObservermCallback;void*mData;PRBoolmForImage;};structChangeCallbackEntry:publicPLDHashEntryHdr{typedefconstChangeCallbackKeyType;typedefconstChangeCallback*KeyTypePointer;ChangeCallbackEntry(constChangeCallback*key):mKey(*key){}ChangeCallbackEntry(constChangeCallbackEntry&toCopy):mKey(toCopy.mKey){}KeyTypeGetKey()const{returnmKey;}PRBoolKeyEquals(KeyTypePointeraKey)const{returnaKey->mCallback==mKey.mCallback&&aKey->mData==mKey.mData&&aKey->mForImage==mKey.mForImage;}staticKeyTypePointerKeyToPointer(KeyType&aKey){return&aKey;}staticPLDHashNumberHashKey(KeyTypePointeraKey){return(NS_PTR_TO_INT32(aKey->mCallback)>>2)^(NS_PTR_TO_INT32(aKey->mData));}enum{ALLOW_MEMMOVE=PR_TRUE};ChangeCallbackmKey;};private:voidFireChangeCallbacks(Element*aOldElement,Element*aNewElement,PRBoolaImageOnly=PR_FALSE);// empty if there are no elementswith this ID.// The elements are stored as weak pointers.nsSmallVoidArraymIdContentList;nsRefPtr<nsBaseContentList>mNameContentList;nsRefPtr<nsContentList>mDocAllList;nsAutoPtr<nsTHashtable<ChangeCallbackEntry>>mChangeCallbacks;nsRefPtr<Element>mImageElement;};classnsDocHeaderData{public:nsDocHeaderData(nsIAtom*aField,constnsAString&aData):mField(aField),mData(aData),mNext(nsnull){}~nsDocHeaderData(void){deletemNext;}nsCOMPtr<nsIAtom>mField;nsStringmData;nsDocHeaderData*mNext;};classnsDOMStyleSheetList:publicnsIDOMStyleSheetList,publicnsStubDocumentObserver{public:nsDOMStyleSheetList(nsIDocument*aDocument);virtual~nsDOMStyleSheetList();NS_DECL_ISUPPORTSNS_DECL_NSIDOMSTYLESHEETLIST// nsIDocumentObserverNS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDEDNS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED// nsIMutationObserverNS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYEDnsIStyleSheet*GetItemAt(PRUint32aIndex);staticnsDOMStyleSheetList*FromSupports(nsISupports*aSupports){nsIDOMStyleSheetList*list=static_cast<nsIDOMStyleSheetList*>(aSupports);#ifdef DEBUG{nsCOMPtr<nsIDOMStyleSheetList>list_qi=do_QueryInterface(aSupports);// If this assertion fires the QI implementation for the object in// question doesn't use the nsIDOMStyleSheetList pointer as the// nsISupports pointer. That must be fixed, or we'll crash...NS_ASSERTION(list_qi==list,"Uh, fix QI!");}#endifreturnstatic_cast<nsDOMStyleSheetList*>(list);}protected:PRInt32mLength;nsIDocument*mDocument;};classnsOnloadBlocker:publicnsIRequest{public:nsOnloadBlocker(){}NS_DECL_ISUPPORTSNS_DECL_NSIREQUESTprivate:~nsOnloadBlocker(){}};classnsExternalResourceMap{public:typedefnsIDocument::ExternalResourceLoadExternalResourceLoad;nsExternalResourceMap();/** * Request an external resource document. This does exactly what * nsIDocument::RequestExternalResource is documented to do. */nsIDocument*RequestResource(nsIURI*aURI,nsINode*aRequestingNode,nsDocument*aDisplayDocument,ExternalResourceLoad**aPendingLoad);/** * Enumerate the resource documents. See * nsIDocument::EnumerateExternalResources. */voidEnumerateResources(nsIDocument::nsSubDocEnumFuncaCallback,void*aData);/** * Traverse ourselves for cycle-collection */voidTraverse(nsCycleCollectionTraversalCallback*aCallback)const;/** * Shut ourselves down (used for cycle-collection unlink), as well * as for document destruction. */voidShutdown(){mPendingLoads.Clear();mMap.Clear();mHaveShutDown=PR_TRUE;}PRBoolHaveShutDown()const{returnmHaveShutDown;}// Needs to be public so we can traverse them sanelystructExternalResource{~ExternalResource();nsCOMPtr<nsIDocument>mDocument;nsCOMPtr<nsIContentViewer>mViewer;nsCOMPtr<nsILoadGroup>mLoadGroup;};// Hide all our viewersvoidHideViewers();// Show all our viewersvoidShowViewers();protected:classPendingLoad:publicExternalResourceLoad,publicnsIStreamListener{public:PendingLoad(nsDocument*aDisplayDocument):mDisplayDocument(aDisplayDocument){}NS_DECL_ISUPPORTSNS_DECL_NSISTREAMLISTENERNS_DECL_NSIREQUESTOBSERVER/** * Start aURI loading. This will perform the necessary security checks and * so forth. */nsresultStartLoad(nsIURI*aURI,nsINode*aRequestingNode);/** * Set up an nsIDocumentViewer based on aRequest. This is guaranteed to * put null in *aViewer and *aLoadGroup on all failures. */nsresultSetupViewer(nsIRequest*aRequest,nsIDocumentViewer**aViewer,nsILoadGroup**aLoadGroup);private:nsRefPtr<nsDocument>mDisplayDocument;nsCOMPtr<nsIStreamListener>mTargetListener;nsCOMPtr<nsIURI>mURI;};friendclassPendingLoad;classLoadgroupCallbacks:publicnsIInterfaceRequestor{public:LoadgroupCallbacks(nsIInterfaceRequestor*aOtherCallbacks):mCallbacks(aOtherCallbacks){}NS_DECL_ISUPPORTSNS_DECL_NSIINTERFACEREQUESTORprivate:// The only reason it's safe to hold a strong ref here without leaking is// that the notificationCallbacks on a loadgroup aren't the docshell itself// but a shim that holds a weak reference to the docshell.nsCOMPtr<nsIInterfaceRequestor>mCallbacks;// Use shims for interfaces that docshell implements directly so that we// don't hand out references to the docshell. The shims should all allow// getInterface back on us, but other than that each one should only// implement one interface.// XXXbz I wish we could just derive the _allcaps thing from _i#define DECL_SHIM(_i, _allcaps) \ class _i##Shim : public nsIInterfaceRequestor, \ public _i \ { \ public: \ _i##Shim(nsIInterfaceRequestor* aIfreq, _i* aRealPtr) \ : mIfReq(aIfreq), mRealPtr(aRealPtr) \ { \ NS_ASSERTION(mIfReq, "Expected non-null here"); \ NS_ASSERTION(mRealPtr, "Expected non-null here"); \ } \ NS_DECL_ISUPPORTS \ NS_FORWARD_NSIINTERFACEREQUESTOR(mIfReq->); \ NS_FORWARD_##_allcaps(mRealPtr->); \ private: \ nsCOMPtr<nsIInterfaceRequestor> mIfReq; \ nsCOMPtr<_i> mRealPtr; \ };DECL_SHIM(nsILoadContext,NSILOADCONTEXT)DECL_SHIM(nsIProgressEventSink,NSIPROGRESSEVENTSINK)DECL_SHIM(nsIChannelEventSink,NSICHANNELEVENTSINK)DECL_SHIM(nsISecurityEventSink,NSISECURITYEVENTSINK)DECL_SHIM(nsIApplicationCacheContainer,NSIAPPLICATIONCACHECONTAINER)#undef DECL_SHIM};/** * Add an ExternalResource for aURI. aViewer and aLoadGroup might be null * when this is called if the URI didn't result in an XML document. This * function makes sure to remove the pending load for aURI, if any, from our * hashtable, and to notify its observers, if any. */nsresultAddExternalResource(nsIURI*aURI,nsIDocumentViewer*aViewer,nsILoadGroup*aLoadGroup,nsIDocument*aDisplayDocument);nsClassHashtable<nsURIHashKey,ExternalResource>mMap;nsRefPtrHashtable<nsURIHashKey,PendingLoad>mPendingLoads;PRPackedBoolmHaveShutDown;};// Base class for our document implementations.//// Note that this class *implements* nsIDOMXMLDocument, but it's not// really an nsIDOMXMLDocument. The reason for implementing// nsIDOMXMLDocument on this class is to avoid having to duplicate all// its inherited methods on document classes that *are*// nsIDOMXMLDocument's. nsDocument's QI should *not* claim to support// nsIDOMXMLDocument unless someone writes a real implementation of// the interface.classnsDocument:publicnsIDocument,publicnsIDOMXMLDocument,// inherits nsIDOMDocumentpublicnsIDOMNSDocument,publicnsIDOMDocumentEvent,publicnsIDOM3DocumentEvent,publicnsIDOMNSDocumentStyle,publicnsIDOMDocumentRange,publicnsIDOMDocumentTraversal,publicnsIDOMDocumentXBL,publicnsSupportsWeakReference,publicnsIDOMEventTarget,publicnsIDOM3EventTarget,publicnsIDOMNSEventTarget,publicnsIScriptObjectPrincipal,publicnsIRadioGroupContainer_MOZILLA_2_0_BRANCH,publicnsIApplicationCacheContainer,publicnsStubMutationObserver,publicnsIDOMDocumentTouch{public:typedefmozilla::dom::ElementElement;NS_DECL_CYCLE_COLLECTING_ISUPPORTSusingnsINode::GetScriptTypeID;virtualvoidReset(nsIChannel*aChannel,nsILoadGroup*aLoadGroup);virtualvoidResetToURI(nsIURI*aURI,nsILoadGroup*aLoadGroup,nsIPrincipal*aPrincipal);// StartDocumentLoad is pure virtual so that subclasses must override it.// The nsDocument StartDocumentLoad does some setup, but does NOT set// *aDocListener; this is the job of subclasses.virtualnsresultStartDocumentLoad(constchar*aCommand,nsIChannel*aChannel,nsILoadGroup*aLoadGroup,nsISupports*aContainer,nsIStreamListener**aDocListener,PRBoolaReset=PR_TRUE,nsIContentSink*aContentSink=nsnull)=0;virtualvoidStopDocumentLoad();virtualvoidNotifyPossibleTitleChange(PRBoolaBoundTitleElement);virtualvoidSetDocumentURI(nsIURI*aURI);/** * Set the principal responsible for this document. */virtualvoidSetPrincipal(nsIPrincipal*aPrincipal);/** * Get the Content-Type of this document. */// NS_IMETHOD GetContentType(nsAString& aContentType);// Already declared in nsIDOMNSDocument/** * Set the Content-Type of this document. */virtualvoidSetContentType(constnsAString&aContentType);virtualnsresultSetBaseURI(nsIURI*aURI);/** * Get/Set the base target of a link in a document. */virtualvoidGetBaseTarget(nsAString&aBaseTarget);/** * Return a standard name for the document's character set. This will * trigger a startDocumentLoad if necessary to answer the question. */virtualvoidSetDocumentCharacterSet(constnsACString&aCharSetID);/** * Add an observer that gets notified whenever the charset changes. */virtualnsresultAddCharSetObserver(nsIObserver*aObserver);/** * Remove a charset observer. */virtualvoidRemoveCharSetObserver(nsIObserver*aObserver);virtualElement*AddIDTargetObserver(nsIAtom*aID,IDTargetObserveraObserver,void*aData,PRBoolaForImage);virtualvoidRemoveIDTargetObserver(nsIAtom*aID,IDTargetObserveraObserver,void*aData,PRBoolaForImage);/** * Access HTTP header data (this may also get set from other sources, like * HTML META tags). */virtualvoidGetHeaderData(nsIAtom*aHeaderField,nsAString&aData)const;virtualvoidSetHeaderData(nsIAtom*aheaderField,constnsAString&aData);/** * Create a new presentation shell that will use aContext for * its presentation context (presentation context's <b>must not</b> be * shared among multiple presentation shell's). */virtualnsresultCreateShell(nsPresContext*aContext,nsIViewManager*aViewManager,nsStyleSet*aStyleSet,nsIPresShell**aInstancePtrResult);virtualvoidDeleteShell();virtualnsresultSetSubDocumentFor(nsIContent*aContent,nsIDocument*aSubDoc);virtualnsIDocument*GetSubDocumentFor(nsIContent*aContent)const;virtualnsIContent*FindContentForSubDocument(nsIDocument*aDocument)const;virtualElement*GetRootElementInternal()const;/** * Get the style sheets owned by this document. * These are ordered, highest priority last */virtualPRInt32GetNumberOfStyleSheets()const;virtualnsIStyleSheet*GetStyleSheetAt(PRInt32aIndex)const;virtualPRInt32GetIndexOfStyleSheet(nsIStyleSheet*aSheet)const;virtualvoidAddStyleSheet(nsIStyleSheet*aSheet);virtualvoidRemoveStyleSheet(nsIStyleSheet*aSheet);virtualvoidUpdateStyleSheets(nsCOMArray<nsIStyleSheet>&aOldSheets,nsCOMArray<nsIStyleSheet>&aNewSheets);virtualvoidAddStyleSheetToStyleSets(nsIStyleSheet*aSheet);virtualvoidRemoveStyleSheetFromStyleSets(nsIStyleSheet*aSheet);virtualvoidInsertStyleSheetAt(nsIStyleSheet*aSheet,PRInt32aIndex);virtualvoidSetStyleSheetApplicableState(nsIStyleSheet*aSheet,PRBoolaApplicable);virtualPRInt32GetNumberOfCatalogStyleSheets()const;virtualnsIStyleSheet*GetCatalogStyleSheetAt(PRInt32aIndex)const;virtualvoidAddCatalogStyleSheet(nsIStyleSheet*aSheet);virtualvoidEnsureCatalogStyleSheet(constchar*aStyleSheetURI);virtualnsIChannel*GetChannel()const{returnmChannel;}/** * Get this document's attribute stylesheet. May return null if * there isn't one. */virtualnsHTMLStyleSheet*GetAttributeStyleSheet()const{returnmAttrStyleSheet;}/** * Get this document's inline style sheet. May return null if there * isn't one */virtualnsHTMLCSSStyleSheet*GetInlineStyleSheet()const{returnmStyleAttrStyleSheet;}/** * Set the object from which a document can get a script context. * This is the context within which all scripts (during document * creation and during event handling) will run. */virtualnsIScriptGlobalObject*GetScriptGlobalObject()const;virtualvoidSetScriptGlobalObject(nsIScriptGlobalObject*aGlobalObject);virtualvoidSetScriptHandlingObject(nsIScriptGlobalObject*aScriptObject);virtualnsIScriptGlobalObject*GetScopeObject();/** * Get the script loader for this document */virtualnsScriptLoader*ScriptLoader();/** * Add/Remove an element to the document's id and name hashes */virtualvoidAddToIdTable(Element*aElement,nsIAtom*aId);virtualvoidRemoveFromIdTable(Element*aElement,nsIAtom*aId);virtualvoidAddToNameTable(Element*aElement,nsIAtom*aName);virtualvoidRemoveFromNameTable(Element*aElement,nsIAtom*aName);/** * Add a new observer of document change notifications. Whenever * content is changed, appended, inserted or removed the observers are * informed. */virtualvoidAddObserver(nsIDocumentObserver*aObserver);/** * Remove an observer of document change notifications. This will * return false if the observer cannot be found. */virtualPRBoolRemoveObserver(nsIDocumentObserver*aObserver);// Observation hooks used to propagate notifications to document// observers.virtualvoidBeginUpdate(nsUpdateTypeaUpdateType);virtualvoidEndUpdate(nsUpdateTypeaUpdateType);virtualvoidBeginLoad();virtualvoidEndLoad();virtualvoidSetReadyStateInternal(ReadyStaters);virtualReadyStateGetReadyStateEnum();virtualvoidContentStateChanged(nsIContent*aContent,nsEventStatesaStateMask);virtualvoidDocumentStatesChanged(nsEventStatesaStateMask);virtualvoidStyleRuleChanged(nsIStyleSheet*aStyleSheet,nsIStyleRule*aOldStyleRule,nsIStyleRule*aNewStyleRule);virtualvoidStyleRuleAdded(nsIStyleSheet*aStyleSheet,nsIStyleRule*aStyleRule);virtualvoidStyleRuleRemoved(nsIStyleSheet*aStyleSheet,nsIStyleRule*aStyleRule);virtualvoidFlushPendingNotifications(mozFlushTypeaType);virtualvoidFlushExternalResources(mozFlushTypeaType);virtualnsIScriptEventManager*GetScriptEventManager();virtualvoidSetXMLDeclaration(constPRUnichar*aVersion,constPRUnichar*aEncoding,constPRInt32aStandalone);virtualvoidGetXMLDeclaration(nsAString&aVersion,nsAString&aEncoding,nsAString&Standalone);virtualPRBoolIsScriptEnabled();virtualvoidOnPageShow(PRBoolaPersisted,nsIDOMEventTarget*aDispatchStartTarget);virtualvoidOnPageHide(PRBoolaPersisted,nsIDOMEventTarget*aDispatchStartTarget);virtualvoidWillDispatchMutationEvent(nsINode*aTarget);virtualvoidMutationEventDispatched(nsINode*aTarget);// nsINodevirtualPRBoolIsNodeOfType(PRUint32aFlags)const;virtualnsIContent*GetChildAt(PRUint32aIndex)const;virtualnsIContent*const*GetChildArray(PRUint32*aChildCount)const;virtualPRInt32IndexOf(nsINode*aPossibleChild)const;virtualPRUint32GetChildCount()const;virtualnsresultInsertChildAt(nsIContent*aKid,PRUint32aIndex,PRBoolaNotify);virtualnsresultAppendChildTo(nsIContent*aKid,PRBoolaNotify);virtualnsresultRemoveChildAt(PRUint32aIndex,PRBoolaNotify,PRBoolaMutationEvent=PR_TRUE);virtualnsresultPreHandleEvent(nsEventChainPreVisitor&aVisitor);virtualnsresultPostHandleEvent(nsEventChainPostVisitor&aVisitor);virtualnsresultDispatchDOMEvent(nsEvent*aEvent,nsIDOMEvent*aDOMEvent,nsPresContext*aPresContext,nsEventStatus*aEventStatus);virtualnsIEventListenerManager*GetListenerManager(PRBoolaCreateIfNotFound);virtualnsresultAddEventListenerByIID(nsIDOMEventListener*aListener,constnsIID&aIID);virtualnsresultRemoveEventListenerByIID(nsIDOMEventListener*aListener,constnsIID&aIID);virtualnsresultGetSystemEventGroup(nsIDOMEventGroup**aGroup);virtualnsIScriptContext*GetContextForEventHandlers(nsresult*aRv){returnnsContentUtils::GetContextForEventHandlers(this,aRv);}virtualnsresultClone(nsINodeInfo*aNodeInfo,nsINode**aResult)const{returnNS_ERROR_NOT_IMPLEMENTED;}virtualPRBoolIsEqualNode(nsINode*aOther);virtualvoidGetTextContent(nsAString&aTextContent);// nsIRadioGroupContainerNS_IMETHODWalkRadioGroup(constnsAString&aName,nsIRadioVisitor*aVisitor,PRBoolaFlushContent);NS_IMETHODSetCurrentRadioButton(constnsAString&aName,nsIDOMHTMLInputElement*aRadio);NS_IMETHODGetCurrentRadioButton(constnsAString&aName,nsIDOMHTMLInputElement**aRadio);NS_IMETHODGetPositionInGroup(nsIDOMHTMLInputElement*aRadio,PRInt32*aPositionIndex,PRInt32*aItemsInGroup);NS_IMETHODGetNextRadioButton(constnsAString&aName,constPRBoolaPrevious,nsIDOMHTMLInputElement*aFocusedRadio,nsIDOMHTMLInputElement**aRadioOut);NS_IMETHODAddToRadioGroup(constnsAString&aName,nsIFormControl*aRadio);NS_IMETHODRemoveFromRadioGroup(constnsAString&aName,nsIFormControl*aRadio);virtualPRUint32GetRequiredRadioCount(constnsAString&aName)const;virtualvoidRadioRequiredChanged(constnsAString&aName,nsIFormControl*aRadio);virtualboolGetValueMissingState(constnsAString&aName)const;virtualvoidSetValueMissingState(constnsAString&aName,boolaValue);// for radio groupnsresultGetRadioGroup(constnsAString&aName,nsRadioGroupStruct**aRadioGroup);// nsIDOMNodeNS_DECL_NSIDOMNODE// nsIDOMDocumentNS_DECL_NSIDOMDOCUMENT// nsIDOMXMLDocumentNS_DECL_NSIDOMXMLDOCUMENT// nsIDOMNSDocumentNS_DECL_NSIDOMNSDOCUMENT// nsIDOMDocumentEventNS_DECL_NSIDOMDOCUMENTEVENT// nsIDOM3DocumentEventNS_DECL_NSIDOM3DOCUMENTEVENT// nsIDOMDocumentStyleNS_DECL_NSIDOMDOCUMENTSTYLE// nsIDOMNSDocumentStyleNS_DECL_NSIDOMNSDOCUMENTSTYLE// nsIDOMDocumentRangeNS_DECL_NSIDOMDOCUMENTRANGE// nsIDOMDocumentTraversalNS_DECL_NSIDOMDOCUMENTTRAVERSAL// nsIDOMDocumentXBLNS_DECL_NSIDOMDOCUMENTXBL// nsIDOMEventTargetNS_DECL_NSIDOMEVENTTARGET// nsIDOM3EventTargetNS_DECL_NSIDOM3EVENTTARGET// nsIDOMNSEventTargetNS_DECL_NSIDOMNSEVENTTARGET// nsIScriptObjectPrincipalvirtualnsIPrincipal*GetPrincipal();// nsIApplicationCacheContainerNS_DECL_NSIAPPLICATIONCACHECONTAINER// nsIDOMDocumentTouchNS_DECL_NSIDOMDOCUMENTTOUCHvirtualnsresultInit();virtualnsresultAddXMLEventsContent(nsIContent*aXMLEventsElement);virtualnsresultCreateElem(constnsAString&aName,nsIAtom*aPrefix,PRInt32aNamespaceID,PRBoolaDocumentDefaultType,nsIContent**aResult);nsresultCreateElement(constnsAString&aTagName,nsIContent**aReturn);nsresultCreateElementNS(constnsAString&aNamespaceURI,constnsAString&aQualifiedName,nsIContent**aReturn);nsresultCreateTextNode(constnsAString&aData,nsIContent**aReturn);virtualNS_HIDDEN_(nsresult)Sanitize();virtualNS_HIDDEN_(void)EnumerateSubDocuments(nsSubDocEnumFuncaCallback,void*aData);virtualNS_HIDDEN_(PRBool)CanSavePresentation(nsIRequest*aNewRequest);virtualNS_HIDDEN_(void)Destroy();virtualNS_HIDDEN_(void)RemovedFromDocShell();virtualNS_HIDDEN_(already_AddRefed<nsILayoutHistoryState>)GetLayoutHistoryState()const;virtualNS_HIDDEN_(void)BlockOnload();virtualNS_HIDDEN_(void)UnblockOnload(PRBoolaFireSync);virtualNS_HIDDEN_(void)AddStyleRelevantLink(mozilla::dom::Link*aLink);virtualNS_HIDDEN_(void)ForgetLink(mozilla::dom::Link*aLink);NS_HIDDEN_(void)ClearBoxObjectFor(nsIContent*aContent);NS_IMETHODGetBoxObjectFor(nsIDOMElement*aElement,nsIBoxObject**aResult);virtualNS_HIDDEN_(nsresult)GetXBLChildNodesFor(nsIContent*aContent,nsIDOMNodeList**aResult);virtualNS_HIDDEN_(nsresult)GetContentListFor(nsIContent*aContent,nsIDOMNodeList**aResult);virtualNS_HIDDEN_(nsresult)ElementFromPointHelper(floataX,floataY,PRBoolaIgnoreRootScrollFrame,PRBoolaFlushLayout,nsIDOMElement**aReturn);virtualNS_HIDDEN_(nsresult)NodesFromRectHelper(floataX,floataY,floataTopSize,floataRightSize,floataBottomSize,floataLeftSize,PRBoolaIgnoreRootScrollFrame,PRBoolaFlushLayout,nsIDOMNodeList**aReturn);virtualNS_HIDDEN_(void)FlushSkinBindings();virtualNS_HIDDEN_(nsresult)InitializeFrameLoader(nsFrameLoader*aLoader);virtualNS_HIDDEN_(nsresult)FinalizeFrameLoader(nsFrameLoader*aLoader);virtualNS_HIDDEN_(void)TryCancelFrameLoaderInitialization(nsIDocShell*aShell);virtualNS_HIDDEN_(PRBool)FrameLoaderScheduledToBeFinalized(nsIDocShell*aShell);virtualNS_HIDDEN_(nsIDocument*)RequestExternalResource(nsIURI*aURI,nsINode*aRequestingNode,ExternalResourceLoad**aPendingLoad);virtualNS_HIDDEN_(void)EnumerateExternalResources(nsSubDocEnumFuncaCallback,void*aData);nsTArray<nsCString>mFileDataUris;#ifdef MOZ_SMIL// Returns our (lazily-initialized) animation controller.// If HasAnimationController is true, this is guaranteed to return non-null.nsSMILAnimationController*GetAnimationController();#endif // MOZ_SMILvoidSetImagesNeedAnimating(PRBoolaAnimating);virtualvoidSuppressEventHandling(PRUint32aIncrease);virtualvoidUnsuppressEventHandlingAndFireEvents(PRBoolaFireEvents);voidDecreaseEventSuppression(){--mEventsSuppressed;}NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,nsIDocument)voidDoNotifyPossibleTitleChange();nsExternalResourceMap&ExternalResourceMap(){returnmExternalResourceMap;}voidSetLoadedAsData(PRBoolaLoadedAsData){mLoadedAsData=aLoadedAsData;}nsresultCloneDocHelper(nsDocument*clone)const;voidMaybeInitializeFinalizeFrameLoaders();voidMaybeEndOutermostXBLUpdate();virtualvoidMaybePreLoadImage(nsIURI*uri);virtualvoidPreloadStyle(nsIURI*uri,constnsAString&charset);virtualnsresultLoadChromeSheetSync(nsIURI*uri,PRBoolisAgentSheet,nsCSSStyleSheet**sheet);virtualnsISupports*GetCurrentContentSink();virtualnsEventStatesGetDocumentState();virtualvoidRegisterFileDataUri(constnsACString&aUri);virtualvoidUnregisterFileDataUri(constnsACString&aUri);// Only BlockOnload should call this!voidAsyncBlockOnload();virtualvoidSetScrollToRef(nsIURI*aDocumentURI);virtualvoidScrollToRef();virtualvoidResetScrolledToRefAlready();virtualvoidSetChangeScrollPosWhenScrollingToRef(PRBoolaValue);already_AddRefed<nsContentList>GetElementsByTagName(constnsAString&aTagName){returnNS_GetContentList(this,kNameSpaceID_Unknown,aTagName);}already_AddRefed<nsContentList>GetElementsByTagNameNS(constnsAString&aNamespaceURI,constnsAString&aLocalName);virtualElement*GetElementById(constnsAString&aElementId);virtualElement*LookupImageElement(constnsAString&aElementId);virtualNS_HIDDEN_(nsresult)AddImage(imgIRequest*aImage);virtualNS_HIDDEN_(nsresult)RemoveImage(imgIRequest*aImage);virtualNS_HIDDEN_(nsresult)SetImageLockingState(PRBoolaLocked);virtualnsresultGetStateObject(nsIVariant**aResult);protected:friendclassnsNodeUtils;/** * Check that aId is not empty and log a message to the console * service if it is. * @returns PR_TRUE if aId looks correct, PR_FALSE otherwise. */inlinePRBoolCheckGetElementByIdArg(constnsAString&aId){if(aId.IsEmpty()){ReportEmptyGetElementByIdArg();returnPR_FALSE;}returnPR_TRUE;}voidReportEmptyGetElementByIdArg();voidDispatchContentLoadedEvents();voidRetrieveRelevantHeaders(nsIChannel*aChannel);staticPRBoolTryChannelCharset(nsIChannel*aChannel,PRInt32&aCharsetSource,nsACString&aCharset);// Call this before the document does something that will unbind all content.// That will stop us from doing a lot of work as each element is removed.voidDestroyElementMaps();// Refreshes the hrefs of all the links in the document.voidRefreshLinkHrefs();nsIContent*GetFirstBaseNodeWithHref();nsresultSetFirstBaseNodeWithHref(nsIContent*node);// Get the first <title> element with the given IsNodeOfType type, or// return null if there isn't onensIContent*GetTitleContent(PRUint32aNodeType);// Find the first "title" element in the given IsNodeOfType type and// append the concatenation of its text node children to aTitle. Do// nothing if there is no such element.voidGetTitleFromElement(PRUint32aNodeType,nsAString&aTitle);nsresultdoCreateShell(nsPresContext*aContext,nsIViewManager*aViewManager,nsStyleSet*aStyleSet,nsCompatibilityaCompatMode,nsIPresShell**aInstancePtrResult);nsresultResetStylesheetsToURI(nsIURI*aURI);voidFillStyleSet(nsStyleSet*aStyleSet);// Return whether all the presshells for this document are safe to flushPRBoolIsSafeToFlush()const;virtualPRInt32GetDefaultNamespaceID()const{returnkNameSpaceID_None;}voidDispatchPageTransition(nsPIDOMEventTarget*aDispatchTarget,constnsAString&aType,PRBoolaPersisted);virtualnsPIDOMWindow*GetWindowInternal()const;virtualnsPIDOMWindow*GetInnerWindowInternal();virtualnsIScriptGlobalObject*GetScriptHandlingObjectInternal()const;virtualPRBoolInternalAllowXULXBL();#define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) \ NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \ func_, params_);#ifdef DEBUGvoidVerifyRootContentState();#endifnsDocument(constchar*aContentType);virtual~nsDocument();voidEnsureOnloadBlocker();nsCStringmReferrer;nsStringmLastModified;nsTArray<nsIObserver*>mCharSetObservers;PLDHashTable*mSubDocuments;// Array of owning references to all childrennsAttrAndChildArraymChildren;// Pointer to our parser if we're currently in the process of being// parsed into.nsCOMPtr<nsIParser>mParser;// Weak reference to our sink for in case we no longer have a parser. This// will allow us to flush out any pending stuff from the sink even if// EndLoad() has already happened.nsWeakPtrmWeakSink;nsCOMArray<nsIStyleSheet>mStyleSheets;nsCOMArray<nsIStyleSheet>mCatalogSheets;// Array of observersnsTObserverArray<nsIDocumentObserver*>mObservers;// If document is created for example using// document.implementation.createDocument(...), mScriptObject points to// the script global object of the original document.nsWeakPtrmScriptObject;// Weak reference to the scope object (aka the script global object)// that, unlike mScriptGlobalObject, is never unset once set. This// is a weak reference to avoid leaks due to circular references.nsWeakPtrmScopeObject;nsCOMPtr<nsIEventListenerManager>mListenerManager;nsCOMPtr<nsIDOMStyleSheetList>mDOMStyleSheets;nsRefPtr<nsDOMStyleSheetSetList>mStyleSheetSetList;nsRefPtr<nsScriptLoader>mScriptLoader;nsDocHeaderData*mHeaderData;/* mIdentifierMap works as follows for IDs: * 1) Attribute changes affect the table immediately (removing and adding * entries as needed). * 2) Removals from the DOM affect the table immediately * 3) Additions to the DOM always update existing entries for names, and add * new ones for IDs. */nsTHashtable<nsIdentifierMapEntry>mIdentifierMap;nsClassHashtable<nsStringHashKey,nsRadioGroupStruct>mRadioGroups;// True if the document has been detached from its content viewer.PRPackedBoolmIsGoingAway:1;// True if the document is being destroyed.PRPackedBoolmInDestructor:1;// True if this document has ever had an HTML or SVG <title> element// bound to itPRPackedBoolmMayHaveTitleElement:1;PRPackedBoolmHasWarnedAboutBoxObjects:1;PRPackedBoolmDelayFrameLoaderInitialization:1;PRPackedBoolmSynchronousDOMContentLoaded:1;// If true, we have an input encoding. If this is false, then the// document was created entirely in memoryPRPackedBoolmHaveInputEncoding:1;PRPackedBoolmInXBLUpdate:1;// This flag is only set in nsXMLDocument, for e.g. documents used in XBL. We// don't want animations to play in such documents, so we need to store the// flag here so that we can check it in nsDocument::GetAnimationController.PRPackedBoolmLoadedAsInteractiveData:1;// Whether we're currently holding a lock on all of our images.PRPackedBoolmLockingImages:1;// Whether we currently require our images to animatePRPackedBoolmAnimatingImages:1;PRUint8mXMLDeclarationBits;PRUint8mDefaultElementType;nsInterfaceHashtable<nsVoidPtrHashKey,nsPIBoxObject>*mBoxObjectTable;// The channel that got passed to StartDocumentLoad(), if anynsCOMPtr<nsIChannel>mChannel;nsRefPtr<nsHTMLStyleSheet>mAttrStyleSheet;nsRefPtr<nsHTMLCSSStyleSheet>mStyleAttrStyleSheet;nsRefPtr<nsXMLEventsManager>mXMLEventsManager;nsCOMPtr<nsIScriptEventManager>mScriptEventManager;// Our update nesting levelPRUint32mUpdateNestLevel;// The application cache that this document is associated with, if// any. This can change during the lifetime of the document.nsCOMPtr<nsIApplicationCache>mApplicationCache;nsCOMPtr<nsIContent>mFirstBaseNodeWithHref;nsEventStatesmDocumentState;nsEventStatesmGotDocumentState;private:friendclassnsUnblockOnloadEvent;voidPostUnblockOnloadEvent();voidDoUnblockOnload();nsresultCheckFrameOptions();nsresultInitCSP();/** * See if aDocument is a child of this. If so, return the frame element in * this document that holds currentDoc (or an ancestor). */already_AddRefed<nsIDOMElement>CheckAncestryAndGetFrame(nsIDocument*aDocument)const;// Just like EnableStyleSheetsForSet, but doesn't check whether// aSheetSet is null and allows the caller to control whether to set// aSheetSet as the preferred set in the CSSLoader.voidEnableStyleSheetsForSetInternal(constnsAString&aSheetSet,PRBoolaUpdateCSSLoader);// Revoke any pending notifications due to mozRequestAnimationFrame callsvoidRevokeAnimationFrameNotifications();// Reschedule any notifications we need to handle mozRequestAnimationFramevoidRescheduleAnimationFrameNotifications();// These are not implemented and not supported.nsDocument(constnsDocument&aOther);nsDocument&operator=(constnsDocument&aOther);nsCOMPtr<nsISupports>mXPathEvaluatorTearoff;// The layout history state that should be used by nodes in this// document. We only actually store a pointer to it when:// 1) We have no script global object.// 2) We haven't had Destroy() called on us yet.nsCOMPtr<nsILayoutHistoryState>mLayoutHistoryState;// Currently active onload blockersPRUint32mOnloadBlockCount;// Onload blockers which haven't been activated yetPRUint32mAsyncOnloadBlockCount;nsCOMPtr<nsIRequest>mOnloadBlocker;ReadyStatemReadyState;// A hashtable of styled links keyed by address pointer.nsTHashtable<nsPtrHashKey<mozilla::dom::Link>>mStyledLinks;#ifdef DEBUG// Indicates whether mStyledLinks was cleared or not. This is used to track// state so we can provide useful assertions to consumers of ForgetLink and// AddStyleRelevantLink.boolmStyledLinksCleared;#endif// Member to store out last-selected stylesheet set.nsStringmLastStyleSheetSet;nsTArray<nsRefPtr<nsFrameLoader>>mInitializableFrameLoaders;nsTArray<nsRefPtr<nsFrameLoader>>mFinalizableFrameLoaders;nsRefPtr<nsRunnableMethod<nsDocument>>mFrameLoaderRunner;nsRevocableEventPtr<nsRunnableMethod<nsDocument,void,false>>mPendingTitleChangeEvent;nsExternalResourceMapmExternalResourceMap;// All images in process of being preloadednsCOMArray<imgIRequest>mPreloadingImages;nsCOMPtr<nsIDOMDOMImplementation>mDOMImplementation;nsCStringmScrollToRef;PRUint8mScrolledToRefAlready:1;PRUint8mChangeScrollPosWhenScrollingToRef:1;// Tracking for images in the document.nsDataHashtable<nsPtrHashKey<imgIRequest>,PRUint32>mImageTracker;#ifdef DEBUGprotected:PRBoolmWillReparent;#endif};#define NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \ NS_NODE_OFFSET_AND_INTERFACE_TABLE_BEGIN(_class) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMDocument, nsDocument) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMNSDocument, nsDocument) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMDocumentEvent, nsDocument) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMDocumentTraversal, \ nsDocument) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMEventTarget, nsDocument) \ NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, nsIDOMNode, nsDocument)#endif /* nsDocument_h___ */