2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-10-05 07:29:50 +00:00
|
|
|
|
2012-03-22 06:34:29 +00:00
|
|
|
/**
|
|
|
|
* This file is near-OBSOLETE. It is used for about:blank only and for the
|
|
|
|
* HTML element factory.
|
|
|
|
* Don't bother adding new stuff in this file.
|
|
|
|
*/
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsContentSink.h"
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContentSink.h"
|
2000-06-16 14:54:57 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2006-11-04 05:45:02 +00:00
|
|
|
#include "nsScriptLoader.h"
|
2004-01-09 23:54:21 +00:00
|
|
|
#include "nsIURI.h"
|
1999-05-13 20:27:47 +00:00
|
|
|
#include "nsIContentViewer.h"
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2013-08-12 15:28:41 +00:00
|
|
|
#include "nsToken.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsIAppShell.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prtime.h"
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsIContent.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-05-25 06:32:00 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-10-30 10:14:06 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1998-09-06 00:20:59 +00:00
|
|
|
|
2005-01-12 02:47:53 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2000-03-28 23:25:26 +00:00
|
|
|
#include "nsIDOMDocumentType.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIScriptElement.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1998-04-22 22:12:24 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-04-14 02:47:28 +00:00
|
|
|
#include "nsIChannel.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-03-11 00:34:54 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsIDocument.h"
|
2004-01-28 21:04:33 +00:00
|
|
|
#include "nsStubDocumentObserver.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
1999-01-09 00:14:53 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2000-02-04 22:50:39 +00:00
|
|
|
#include "nsICookieService.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
1999-11-16 05:07:31 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-10-06 21:13:37 +00:00
|
|
|
#include "nsIPrincipal.h"
|
1999-09-11 17:28:36 +00:00
|
|
|
#include "nsTextFragment.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIParserService.h"
|
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1999-12-04 01:27:46 +00:00
|
|
|
#include "nsITimer.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2000-05-25 13:29:15 +00:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIScriptContext.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsStyleLinkElement.h"
|
1999-09-14 14:38:52 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#include "nsWeakReference.h" // nsHTMLElementFactory supports weak references
|
2001-03-29 02:11:48 +00:00
|
|
|
#include "nsIPrompt.h"
|
2001-04-24 08:43:08 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2002-08-26 20:13:31 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-06-21 14:40:55 +00:00
|
|
|
|
|
|
|
#include "nsEscape.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2013-04-04 12:01:08 +00:00
|
|
|
#include "nsTextNode.h"
|
2002-04-18 22:11:17 +00:00
|
|
|
|
2011-05-25 06:32:00 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
typedef nsGenericHTMLElement*
|
2014-06-20 02:01:40 +00:00
|
|
|
(*contentCreatorCallback)(already_AddRefed<mozilla::dom::NodeInfo>&&,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser);
|
2003-09-24 06:16:52 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement*
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_NewHTMLNOTUSEDElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
2003-09-24 06:16:52 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("The element ctor should never be called");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-09-24 06:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element,
|
2010-07-06 04:24:35 +00:00
|
|
|
#define HTML_HTMLELEMENT_TAG(_tag) NS_NewHTMLElement,
|
2005-06-16 13:10:58 +00:00
|
|
|
#define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement,
|
2003-09-24 06:16:52 +00:00
|
|
|
static const contentCreatorCallback sContentCreatorCallbacks[] = {
|
|
|
|
NS_NewHTMLUnknownElement,
|
|
|
|
#include "nsHTMLTagList.h"
|
|
|
|
#undef HTML_TAG
|
2010-07-06 04:24:35 +00:00
|
|
|
#undef HTML_HTMLELEMENT_TAG
|
2003-09-24 06:16:52 +00:00
|
|
|
#undef HTML_OTHER
|
2003-09-24 07:30:16 +00:00
|
|
|
NS_NewHTMLUnknownElement
|
|
|
|
};
|
2003-09-24 06:16:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
class SinkContext;
|
2006-02-08 05:56:13 +00:00
|
|
|
class HTMLContentSink;
|
|
|
|
|
2012-03-22 06:34:29 +00:00
|
|
|
/**
|
|
|
|
* This class is near-OBSOLETE. It is used for about:blank only.
|
|
|
|
* Don't bother adding new stuff in this file.
|
|
|
|
*/
|
2003-10-05 07:29:50 +00:00
|
|
|
class HTMLContentSink : public nsContentSink,
|
2007-01-30 21:21:06 +00:00
|
|
|
public nsIHTMLContentSink
|
1999-11-02 06:49:44 +00:00
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
2003-10-05 07:29:50 +00:00
|
|
|
friend class SinkContext;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink();
|
|
|
|
|
1999-02-26 20:02:06 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsISupports
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentSink, nsContentSink)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsIContentSink
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD WillParse(void) override;
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
|
|
|
NS_IMETHOD WillInterrupt(void) override;
|
|
|
|
NS_IMETHOD WillResume(void) override;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) override;
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
|
|
|
virtual nsISupports *GetTarget() override;
|
|
|
|
virtual bool IsScriptExecuting() override;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// nsIHTMLContentSink
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD OpenContainer(ElementType aNodeType) override;
|
|
|
|
NS_IMETHOD CloseContainer(ElementType aTag) override;
|
2000-09-01 18:17:43 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~HTMLContentSink();
|
|
|
|
|
2010-03-31 11:35:20 +00:00
|
|
|
nsCOMPtr<nsIHTMLDocument> mHTMLDocument;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// The maximum length of a text run
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mMaxTextRun;
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> mRoot;
|
|
|
|
RefPtr<nsGenericHTMLElement> mBody;
|
|
|
|
RefPtr<nsGenericHTMLElement> mHead;
|
2004-09-17 20:11:02 +00:00
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
nsAutoTArray<SinkContext*, 8> mContextStack;
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext* mCurrentContext;
|
|
|
|
SinkContext* mHeadContext;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2006-01-27 01:13:00 +00:00
|
|
|
// Boolean indicating whether we've seen a <head> tag that might have had
|
|
|
|
// attributes once already.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHaveSeenHead;
|
2006-01-27 01:13:00 +00:00
|
|
|
|
2007-02-02 02:12:48 +00:00
|
|
|
// Boolean indicating whether we've notified insertion of our root content
|
|
|
|
// yet. We want to make sure to only do this once.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mNotifiedRootInsertion;
|
2007-02-02 02:12:48 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo* mNodeInfoCache[NS_HTML_TAG_MAX + 1];
|
2006-10-04 22:02:17 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
nsresult FlushTags() override;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Routines for tags that require special handling
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult CloseHTML();
|
2013-08-17 15:39:34 +00:00
|
|
|
nsresult OpenBody();
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult CloseBody();
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
void CloseHeadContext();
|
2003-10-05 07:29:50 +00:00
|
|
|
|
|
|
|
// nsContentSink overrides
|
2015-03-21 16:28:04 +00:00
|
|
|
void UpdateChildCounts() override;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer);
|
2007-10-04 05:16:35 +00:00
|
|
|
void NotifyRootInsertion();
|
2001-06-21 02:06:23 +00:00
|
|
|
};
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
class SinkContext
|
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit SinkContext(HTMLContentSink* aSink);
|
1998-08-28 16:20:16 +00:00
|
|
|
~SinkContext();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsGenericHTMLElement* aRoot,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aNumFlushed, int32_t aInsertionPoint);
|
2013-08-17 15:39:34 +00:00
|
|
|
nsresult OpenBody();
|
2013-08-17 19:26:48 +00:00
|
|
|
nsresult CloseBody();
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult End();
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult GrowStack();
|
2006-11-06 23:50:33 +00:00
|
|
|
nsresult FlushTags();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsCurrentContainer(nsHTMLTag mType);
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2006-06-08 04:38:44 +00:00
|
|
|
void DidAddContent(nsIContent* aContent);
|
1999-10-26 14:55:51 +00:00
|
|
|
void UpdateChildCounts();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-09-22 02:33:36 +00:00
|
|
|
private:
|
|
|
|
// Function to check whether we've notified for the current content.
|
|
|
|
// What this actually does is check whether we've notified for all
|
|
|
|
// of the parent's kids.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
2005-09-22 02:33:36 +00:00
|
|
|
|
|
|
|
public:
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink* mSink;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mNotifyLevel;
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
struct Node {
|
|
|
|
nsHTMLTag mType;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* mContent;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mNumFlushed;
|
|
|
|
int32_t mInsertionPoint;
|
2008-10-12 17:44:23 +00:00
|
|
|
|
|
|
|
nsIContent *Add(nsIContent *child);
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
Node* mStack;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mStackSize;
|
|
|
|
int32_t mStackPos;
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-06-27 22:57:52 +00:00
|
|
|
|
2000-12-10 09:20:40 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2004-06-25 12:26:02 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
|
2010-07-23 09:49:57 +00:00
|
|
|
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService* parserService = nsContentUtils::GetParserService();
|
2002-11-19 13:39:20 +00:00
|
|
|
if (!parserService)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsIAtom *name = nodeInfo->NameAtom();
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
2009-06-09 07:41:19 +00:00
|
|
|
"Trying to HTML elements that don't have the XHTML namespace");
|
2014-02-23 21:01:26 +00:00
|
|
|
|
|
|
|
// Per the Custom Element specification, unknown tags that are valid custom
|
|
|
|
// element names should be HTMLElement instead of HTMLUnknownElement.
|
|
|
|
int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name);
|
|
|
|
if (tag == eHTMLTag_userdefined &&
|
|
|
|
nsContentUtils::IsCustomElementName(name)) {
|
2014-03-15 19:00:15 +00:00
|
|
|
nsIDocument* doc = nodeInfo->GetDocument();
|
|
|
|
|
2014-02-23 21:01:26 +00:00
|
|
|
NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
|
|
|
|
if (!*aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-12-23 02:19:08 +00:00
|
|
|
doc->SetupCustomElement(*aResult, kNameSpaceID_XHTML);
|
2014-02-23 21:01:26 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = CreateHTMLElement(tag,
|
2014-03-15 19:00:15 +00:00
|
|
|
nodeInfo.forget(), aFromParser).take();
|
2006-10-13 22:54:12 +00:00
|
|
|
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2014-03-15 19:00:17 +00:00
|
|
|
CreateHTMLElement(uint32_t aNodeType,
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2006-10-16 21:43:08 +00:00
|
|
|
NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX ||
|
|
|
|
aNodeType == eHTMLTag_userdefined,
|
|
|
|
"aNodeType is out of bounds");
|
2006-10-13 22:54:12 +00:00
|
|
|
|
2004-06-02 00:25:00 +00:00
|
|
|
contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType];
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-06-02 00:25:00 +00:00
|
|
|
NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement,
|
|
|
|
"Don't know how to construct tag element!");
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> result = cb(Move(aNodeInfo), aFromParser);
|
2004-06-06 02:38:32 +00:00
|
|
|
|
2013-04-22 11:15:59 +00:00
|
|
|
return result.forget();
|
1998-09-01 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
1999-05-06 19:26:43 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext::SinkContext(HTMLContentSink* aSink)
|
2005-04-07 03:30:50 +00:00
|
|
|
: mSink(aSink),
|
|
|
|
mNotifyLevel(0),
|
2012-07-30 14:20:58 +00:00
|
|
|
mStack(nullptr),
|
2005-04-07 03:30:50 +00:00
|
|
|
mStackSize(0),
|
2013-08-17 18:42:20 +00:00
|
|
|
mStackPos(0)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(SinkContext);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SinkContext::~SinkContext()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(SinkContext);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mStack) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = 0; i < mStackPos; i++) {
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(mStack[i].mContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
delete [] mStack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
SinkContext::Begin(nsHTMLTag aNodeType,
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* aRoot,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aNumFlushed,
|
|
|
|
int32_t aInsertionPoint)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStackSize < 1) {
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = GrowStack();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[0].mType = aNodeType;
|
|
|
|
mStack[0].mContent = aRoot;
|
1999-10-26 14:55:51 +00:00
|
|
|
mStack[0].mNumFlushed = aNumFlushed;
|
|
|
|
mStack[0].mInsertionPoint = aInsertionPoint;
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_ADDREF(aRoot);
|
|
|
|
mStackPos = 1;
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
1999-04-13 22:22:51 +00:00
|
|
|
SinkContext::IsCurrentContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aTag == mStack[mStackPos - 1].mType) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
2006-06-08 04:38:44 +00:00
|
|
|
SinkContext::DidAddContent(nsIContent* aContent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-01-25 07:48:59 +00:00
|
|
|
if ((mStackPos == 2) && (mSink->mBody == mStack[1].mContent)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
// We just finished adding something to the body
|
1999-10-26 14:55:51 +00:00
|
|
|
mNotifyLevel = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we just added content to a node for which
|
2002-09-18 23:31:08 +00:00
|
|
|
// an insertion happen, we need to do an immediate
|
1999-10-26 14:55:51 +00:00
|
|
|
// notification for that insertion.
|
2006-06-08 04:38:44 +00:00
|
|
|
if (0 < mStackPos &&
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint != -1 &&
|
|
|
|
mStack[mStackPos - 1].mNumFlushed <
|
|
|
|
mStack[mStackPos - 1].mContent->GetChildCount()) {
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t childIndex = mStack[mStackPos - 1].mInsertionPoint - 1;
|
2008-10-12 17:44:23 +00:00
|
|
|
NS_ASSERTION(parent->GetChildAt(childIndex) == aContent,
|
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(parent, aContent, childIndex);
|
2003-09-27 04:18:26 +00:00
|
|
|
mStack[mStackPos - 1].mNumFlushed = parent->GetChildCount();
|
2006-06-08 04:38:44 +00:00
|
|
|
} else if (mSink->IsTimeToNotify()) {
|
2006-11-06 23:50:33 +00:00
|
|
|
FlushTags();
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
1999-01-12 23:49:13 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2013-08-17 15:39:34 +00:00
|
|
|
SinkContext::OpenBody()
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
2006-04-08 00:32:03 +00:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
NS_ERROR("container w/o parent");
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (mStackPos + 1 > mStackSize) {
|
|
|
|
rv = GrowStack();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2013-08-17 15:39:34 +00:00
|
|
|
mSink->mNodeInfoManager->GetNodeInfo(nsGkAtoms::body, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Make the content object
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsGenericHTMLElement> body =
|
2013-08-17 15:39:34 +00:00
|
|
|
NS_NewHTMLBodyElement(nodeInfo.forget(), FROM_PARSER_NETWORK);
|
|
|
|
if (!body) {
|
2004-06-06 02:38:32 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
|
2013-08-17 15:39:34 +00:00
|
|
|
mStack[mStackPos].mType = eHTMLTag_body;
|
|
|
|
body.forget(&mStack[mStackPos].mContent);
|
1999-10-26 14:55:51 +00:00
|
|
|
mStack[mStackPos].mNumFlushed = 0;
|
|
|
|
mStack[mStackPos].mInsertionPoint = -1;
|
2006-04-08 00:32:03 +00:00
|
|
|
++mStackPos;
|
2013-08-17 15:39:34 +00:00
|
|
|
mStack[mStackPos - 2].Add(mStack[mStackPos - 1].mContent);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-09-22 02:33:36 +00:00
|
|
|
SinkContext::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
|
|
|
if (0 < mStackPos) {
|
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
return mStack[mStackPos-1].mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-09-22 02:33:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
nsIContent *
|
|
|
|
SinkContext::Node::Add(nsIContent *child)
|
|
|
|
{
|
2008-12-20 00:49:08 +00:00
|
|
|
NS_ASSERTION(mContent, "No parent to insert/append into!");
|
2008-10-12 17:44:23 +00:00
|
|
|
if (mInsertionPoint != -1) {
|
|
|
|
NS_ASSERTION(mNumFlushed == mContent->GetChildCount(),
|
|
|
|
"Inserting multiple children without flushing.");
|
2011-10-17 14:59:28 +00:00
|
|
|
mContent->InsertChildAt(child, mInsertionPoint++, false);
|
2008-10-12 17:44:23 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mContent->AppendChildTo(child, false);
|
2008-10-12 17:44:23 +00:00
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2013-08-17 19:26:48 +00:00
|
|
|
SinkContext::CloseBody()
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0,
|
|
|
|
"stack out of bounds. wrong context probably!");
|
2000-07-28 01:01:08 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStackPos <= 0) {
|
2000-07-28 01:01:08 +00:00
|
|
|
return NS_OK; // Fix crash - Ref. bug 45975 or 45007
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
--mStackPos;
|
2013-08-17 19:26:48 +00:00
|
|
|
NS_ASSERTION(mStack[mStackPos].mType == eHTMLTag_body,
|
2006-06-08 04:29:28 +00:00
|
|
|
"Tag mismatch. Closing tag on wrong context or something?");
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content = mStack[mStackPos].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2008-02-02 23:41:24 +00:00
|
|
|
content->Compact();
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we're in a state where we do append notifications as
|
|
|
|
// we go up the tree, and we're at the level where the next
|
|
|
|
// notification needs to be done, do the notification.
|
|
|
|
if (mNotifyLevel >= mStackPos) {
|
|
|
|
// Check to see if new content has been added after our last
|
|
|
|
// notification
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (mStack[mStackPos].mNumFlushed < content->GetChildCount()) {
|
1999-10-26 14:55:51 +00:00
|
|
|
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
|
2006-06-08 04:38:44 +00:00
|
|
|
mStack[mStackPos].mNumFlushed = content->GetChildCount();
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that notification has now happened at this level
|
2002-09-18 23:31:08 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2006-06-08 04:38:44 +00:00
|
|
|
DidAddContent(content);
|
1999-11-11 22:15:02 +00:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
|
2013-08-17 19:26:48 +00:00
|
|
|
return NS_OK;
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::End()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = 0; i < mStackPos; i++) {
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(mStack[i].mContent);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStackPos = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::GrowStack()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t newSize = mStackSize * 2;
|
2002-09-18 23:31:08 +00:00
|
|
|
if (newSize == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
newSize = 32;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
Node* stack = new Node[newSize];
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mStackPos != 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
memcpy(stack, mStack, sizeof(Node) * mStackPos);
|
|
|
|
delete [] mStack;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack = stack;
|
|
|
|
mStackSize = newSize;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
/**
|
2007-01-30 21:21:06 +00:00
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*
|
1998-11-28 23:51:06 +00:00
|
|
|
* Flush all elements that have been seen so far such that
|
|
|
|
* they are visible in the tree. Specifically, make sure
|
|
|
|
* that they are all added to their respective parents.
|
1999-10-26 14:55:51 +00:00
|
|
|
* Also, do notification at the top for all content that
|
|
|
|
* has been newly added so that the frame tree is complete.
|
1998-11-28 23:51:06 +00:00
|
|
|
*/
|
|
|
|
nsresult
|
2006-11-06 23:50:33 +00:00
|
|
|
SinkContext::FlushTags()
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mSink->mDeferredFlushTags = false;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool oldBeganUpdate = mSink->mBeganUpdate;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t oldUpdates = mSink->mUpdatesInNotification;
|
2007-03-09 23:43:50 +00:00
|
|
|
|
2006-11-06 23:50:33 +00:00
|
|
|
++(mSink->mInNotification);
|
2007-05-17 23:54:35 +00:00
|
|
|
mSink->mUpdatesInNotification = 0;
|
2007-04-07 00:20:09 +00:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
mozAutoDocUpdate updateBatch(mSink->mDocument, UPDATE_CONTENT_MODEL,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
|
|
|
mSink->mBeganUpdate = true;
|
2007-04-07 00:20:09 +00:00
|
|
|
|
|
|
|
// Start from the base of the stack (growing downward) and do
|
|
|
|
// a notification from the node that is closest to the root of
|
|
|
|
// tree for any content that has been added.
|
|
|
|
|
|
|
|
// Note that we can start at stackPos == 0 here, because it's the caller's
|
|
|
|
// responsibility to handle flushing interactions between contexts (see
|
|
|
|
// HTMLContentSink::BeginContext).
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t stackPos = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool flushed = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t childCount;
|
2007-04-07 00:20:09 +00:00
|
|
|
nsGenericHTMLElement* content;
|
|
|
|
|
|
|
|
while (stackPos < mStackPos) {
|
|
|
|
content = mStack[stackPos].mContent;
|
|
|
|
childCount = content->GetChildCount();
|
|
|
|
|
|
|
|
if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) {
|
2009-08-13 20:27:37 +00:00
|
|
|
if (mStack[stackPos].mInsertionPoint != -1) {
|
|
|
|
// We might have popped the child off our stack already
|
|
|
|
// but not notified on it yet, which is why we have to get it
|
|
|
|
// directly from its parent node.
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t childIndex = mStack[stackPos].mInsertionPoint - 1;
|
2009-08-13 20:27:37 +00:00
|
|
|
nsIContent* child = content->GetChildAt(childIndex);
|
|
|
|
// Child not on stack anymore; can't assert it's correct
|
|
|
|
NS_ASSERTION(!(mStackPos > (stackPos + 1)) ||
|
|
|
|
(child == mStack[stackPos + 1].mContent),
|
2008-10-12 17:44:23 +00:00
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(content, child, childIndex);
|
2007-04-07 00:20:09 +00:00
|
|
|
} else {
|
|
|
|
mSink->NotifyAppend(content, mStack[stackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
flushed = true;
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 00:20:09 +00:00
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
stackPos++;
|
2000-01-28 23:43:12 +00:00
|
|
|
}
|
2007-04-07 00:20:09 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2006-11-06 23:50:33 +00:00
|
|
|
--(mSink->mInNotification);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2007-05-17 23:54:35 +00:00
|
|
|
if (mSink->mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSink->mUpdatesInNotification = oldUpdates;
|
2007-03-09 23:43:50 +00:00
|
|
|
mSink->mBeganUpdate = oldBeganUpdate;
|
|
|
|
|
2005-04-07 03:30:50 +00:00
|
|
|
return NS_OK;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
/**
|
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*/
|
1999-10-26 14:55:51 +00:00
|
|
|
void
|
|
|
|
SinkContext::UpdateChildCounts()
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
// Start from the top of the stack (growing upwards) and see if any
|
|
|
|
// new content has been appended. If so, we recognize that reflows
|
|
|
|
// have been generated for it and we should make sure that no
|
2006-05-12 20:36:39 +00:00
|
|
|
// further reflows occur. Note that we have to include stackPos == 0
|
|
|
|
// to properly notify on kids of <html>.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t stackPos = mStackPos - 1;
|
2006-05-12 20:36:39 +00:00
|
|
|
while (stackPos >= 0) {
|
2005-04-07 03:30:50 +00:00
|
|
|
Node & node = mStack[stackPos];
|
|
|
|
node.mNumFlushed = node.mContent->GetChildCount();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
stackPos--;
|
|
|
|
}
|
2000-03-10 02:00:42 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLContentSink(nsIHTMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HTMLContentSink> it = new HTMLContentSink();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
*aResult = it;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::HTMLContentSink()
|
|
|
|
{
|
|
|
|
// Note: operator new zeros our memory
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mNotificationTimer) {
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t numContexts = mContextStack.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (mCurrentContext == mHeadContext && numContexts > 0) {
|
1999-11-19 04:02:23 +00:00
|
|
|
// Pop off the second html context if it's not done earlier
|
|
|
|
mContextStack.RemoveElementAt(--numContexts);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i;
|
2006-10-04 22:02:17 +00:00
|
|
|
for (i = 0; i < numContexts; i++) {
|
2009-03-20 08:15:35 +00:00
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (sc) {
|
1999-11-19 04:02:23 +00:00
|
|
|
sc->End();
|
|
|
|
if (sc == mCurrentContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentContext = nullptr;
|
1999-11-19 04:02:23 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-19 04:02:23 +00:00
|
|
|
delete sc;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mCurrentContext == mHeadContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentContext = nullptr;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete mCurrentContext;
|
|
|
|
|
|
|
|
delete mHeadContext;
|
2006-10-04 22:02:17 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (i = 0; uint32_t(i) < ArrayLength(mNodeInfoCache); ++i) {
|
2006-10-04 22:02:17 +00:00
|
|
|
NS_IF_RELEASE(mNodeInfoCache[i]);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLContentSink)
|
|
|
|
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLContentSink, nsContentSink)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHead)
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_IF_RELEASE(tmp->mNodeInfoCache[i]);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLContentSink,
|
|
|
|
nsContentSink)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHead)
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfoCache[i]");
|
2014-06-20 02:01:40 +00:00
|
|
|
cb.NoteNativeChild(tmp->mNodeInfoCache[i],
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo));
|
2010-03-31 11:35:20 +00:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLContentSink)
|
|
|
|
NS_INTERFACE_TABLE_BEGIN
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIContentSink)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIHTMLContentSink)
|
|
|
|
NS_INTERFACE_TABLE_END
|
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLContentSink, nsContentSink)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLContentSink, nsContentSink)
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::Init(nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ENSURE_TRUE(aContainer, NS_ERROR_NULL_POINTER);
|
2009-08-28 18:03:51 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
|
2005-09-15 23:17:17 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-10-05 07:29:50 +00:00
|
|
|
return rv;
|
1998-08-31 17:51:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
aDoc->AddObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDocumentObserver = true;
|
2010-03-31 11:35:20 +00:00
|
|
|
mHTMLDocument = do_QueryInterface(aDoc);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(mDocShell, "oops no docshell!");
|
2003-04-02 11:18:00 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Changed from 8192 to greatly improve page loading performance on
|
|
|
|
// large pages. See bugzilla bug 77540.
|
2011-05-25 06:32:00 +00:00
|
|
|
mMaxTextRun = Preferences::GetInt("content.maxtextrun", 8191);
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 14:20:58 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nullptr,
|
2011-06-14 07:56:49 +00:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
1998-07-30 16:06:22 +00:00
|
|
|
// Make root part
|
2010-07-23 09:49:57 +00:00
|
|
|
mRoot = NS_NewHTMLHtmlElement(nodeInfo.forget());
|
2010-04-30 13:12:05 +00:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
NS_ASSERTION(mDocument->GetChildCount() == 0,
|
|
|
|
"Document should have no kids here!");
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = mDocument->AppendChildTo(mRoot, false);
|
2010-04-30 13:12:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make head part
|
2008-09-12 22:32:18 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, kNameSpaceID_XHTML,
|
2011-06-14 07:56:49 +00:00
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
mHead = NS_NewHTMLHeadElement(nodeInfo.forget());
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-06-06 02:38:32 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-30 16:06:22 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mRoot->AppendChildTo(mHead, false);
|
1998-07-30 16:06:22 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = new SinkContext(this);
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->Begin(eHTMLTag_html, mRoot, 0, -1);
|
1998-08-28 16:20:16 +00:00
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-30 21:31:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillParse(void)
|
|
|
|
{
|
|
|
|
return WillParseImpl();
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2009-06-23 21:22:16 +00:00
|
|
|
HTMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
WillBuildModelImpl();
|
2009-06-23 21:22:16 +00:00
|
|
|
|
2001-12-07 21:53:39 +00:00
|
|
|
if (mHTMLDocument) {
|
2002-06-25 21:16:17 +00:00
|
|
|
nsCompatibility mode = eCompatibility_NavQuirks;
|
2009-06-23 21:22:16 +00:00
|
|
|
switch (aDTDMode) {
|
|
|
|
case eDTDMode_full_standards:
|
|
|
|
mode = eCompatibility_FullStandards;
|
|
|
|
break;
|
|
|
|
case eDTDMode_almost_standards:
|
|
|
|
mode = eCompatibility_AlmostStandards;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-06-25 21:16:17 +00:00
|
|
|
}
|
|
|
|
mHTMLDocument->SetCompatibilityMode(mode);
|
2001-12-07 21:53:39 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
HTMLContentSink::DidBuildModel(bool aTerminated)
|
1998-06-30 23:51:53 +00:00
|
|
|
{
|
2009-10-02 11:13:59 +00:00
|
|
|
DidBuildModelImpl(aTerminated);
|
1998-08-10 17:39:48 +00:00
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
// Reflow the last batch of content
|
2012-01-25 07:48:59 +00:00
|
|
|
if (mBody) {
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (!mLayoutStarted) {
|
2001-04-10 00:49:49 +00:00
|
|
|
// We never saw the body, and layout never got started. Force
|
|
|
|
// layout *now*, to get an initial reflow.
|
2002-09-18 23:31:08 +00:00
|
|
|
// NOTE: only force the layout if we are NOT destroying the
|
2003-04-02 11:18:00 +00:00
|
|
|
// docshell. If we are destroying it, then starting layout will
|
2002-09-18 23:31:08 +00:00
|
|
|
// likely cause us to crash, or at best waste a lot of time as we
|
|
|
|
// are just going to tear it down anyway.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bDestroying = true;
|
2003-04-02 11:18:00 +00:00
|
|
|
if (mDocShell) {
|
|
|
|
mDocShell->IsBeingDestroyed(&bDestroying);
|
2001-12-07 00:02:03 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-12-07 00:02:03 +00:00
|
|
|
if (!bDestroying) {
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(false);
|
2001-12-07 00:02:03 +00:00
|
|
|
}
|
2001-04-10 00:49:49 +00:00
|
|
|
}
|
2000-10-18 20:37:54 +00:00
|
|
|
|
2007-02-03 00:48:29 +00:00
|
|
|
ScrollToRef();
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2006-06-19 21:10:29 +00:00
|
|
|
// Make sure we no longer respond to document mutations. We've flushed all
|
|
|
|
// our notifications out, so there's no need to do anything else here.
|
|
|
|
|
|
|
|
// XXXbz I wonder whether we could End() our contexts here too, or something,
|
2009-05-17 14:22:55 +00:00
|
|
|
// just to make sure we no longer notify... Or is the mIsDocumentObserver
|
|
|
|
// thing sufficient?
|
2006-06-19 21:10:29 +00:00
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDocumentObserver = false;
|
2006-06-19 21:10:29 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mDocument->EndLoad();
|
2000-09-19 22:35:50 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
DropParserAndPerfHint();
|
2000-04-05 04:02:38 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IMETHODIMP
|
2012-01-20 11:16:27 +00:00
|
|
|
HTMLContentSink::SetParser(nsParserBase* aParser)
|
1998-12-11 17:02:37 +00:00
|
|
|
{
|
2007-04-27 04:05:08 +00:00
|
|
|
NS_PRECONDITION(aParser, "Should have a parser here!");
|
1998-12-11 17:02:37 +00:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseHTML()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mHeadContext) {
|
|
|
|
if (mCurrentContext == mHeadContext) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numContexts = mContextStack.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-10 03:36:50 +00:00
|
|
|
// Pop off the second html context if it's not done earlier
|
2009-03-20 08:15:35 +00:00
|
|
|
mCurrentContext = mContextStack.ElementAt(--numContexts);
|
2000-01-28 23:43:12 +00:00
|
|
|
mContextStack.RemoveElementAt(numContexts);
|
1999-12-10 03:36:50 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mHeadContext->End();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
delete mHeadContext;
|
2012-07-30 14:20:58 +00:00
|
|
|
mHeadContext = nullptr;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2013-08-17 15:39:34 +00:00
|
|
|
HTMLContentSink::OpenBody()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2003-01-09 18:29:23 +00:00
|
|
|
CloseHeadContext(); // do this just in case if the HEAD was left open!
|
|
|
|
|
2013-08-16 23:51:58 +00:00
|
|
|
// if we already have a body we're done
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mBody) {
|
1999-04-05 20:53:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2013-08-17 15:39:34 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenBody();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mBody = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
if (mCurrentContext->mStackPos > 1) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t parentIndex = mCurrentContext->mStackPos - 2;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement *parent = mCurrentContext->mStack[parentIndex].mContent;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t numFlushed = mCurrentContext->mStack[parentIndex].mNumFlushed;
|
|
|
|
int32_t childCount = parent->GetChildCount();
|
2006-05-12 20:36:39 +00:00
|
|
|
NS_ASSERTION(numFlushed < childCount, "Already notified on the body?");
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t insertionPoint =
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentContext->mStack[parentIndex].mInsertionPoint;
|
2002-09-06 05:44:31 +00:00
|
|
|
|
|
|
|
// XXX: I have yet to see a case where numFlushed is non-zero and
|
2002-09-18 23:31:08 +00:00
|
|
|
// insertionPoint is not -1, but this code will try to handle
|
|
|
|
// those cases too.
|
2002-09-06 05:44:31 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t oldUpdates = mUpdatesInNotification;
|
2008-08-25 17:21:29 +00:00
|
|
|
mUpdatesInNotification = 0;
|
2002-09-06 05:44:31 +00:00
|
|
|
if (insertionPoint != -1) {
|
|
|
|
NotifyInsert(parent, mBody, insertionPoint - 1);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2002-09-06 05:44:31 +00:00
|
|
|
NotifyAppend(parent, numFlushed);
|
|
|
|
}
|
2006-05-12 20:36:39 +00:00
|
|
|
mCurrentContext->mStack[parentIndex].mNumFlushed = childCount;
|
2008-08-25 17:21:29 +00:00
|
|
|
if (mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
mUpdatesInNotification = oldUpdates;
|
2002-09-06 05:44:31 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(false);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseBody()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-10-29 19:07:24 +00:00
|
|
|
// Flush out anything that's left
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2013-08-17 19:26:48 +00:00
|
|
|
mCurrentContext->CloseBody();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-26 15:08:55 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2013-08-17 12:06:23 +00:00
|
|
|
HTMLContentSink::OpenContainer(ElementType aElementType)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2013-08-17 12:06:23 +00:00
|
|
|
switch (aElementType) {
|
|
|
|
case eBody:
|
2013-08-17 15:39:34 +00:00
|
|
|
rv = OpenBody();
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
2013-08-17 12:06:23 +00:00
|
|
|
case eHTML:
|
2005-10-21 15:39:06 +00:00
|
|
|
if (mRoot) {
|
2013-08-16 23:51:58 +00:00
|
|
|
// If we've already hit this code once, then we're done
|
2006-01-12 17:11:57 +00:00
|
|
|
if (!mNotifiedRootInsertion) {
|
2007-10-04 05:16:35 +00:00
|
|
|
NotifyRootInsertion();
|
2006-01-12 17:11:57 +00:00
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
ProcessOfflineManifest(mRoot);
|
2005-10-21 15:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-12 00:18:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2013-08-17 12:06:23 +00:00
|
|
|
HTMLContentSink::CloseContainer(const ElementType aTag)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
switch (aTag) {
|
2013-08-17 12:06:23 +00:00
|
|
|
case eBody:
|
2005-10-21 15:39:06 +00:00
|
|
|
rv = CloseBody();
|
|
|
|
break;
|
2013-08-17 12:06:23 +00:00
|
|
|
case eHTML:
|
2005-10-21 15:39:06 +00:00
|
|
|
rv = CloseHTML();
|
|
|
|
break;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-12 00:18:26 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillInterrupt()
|
|
|
|
{
|
2008-10-30 21:31:00 +00:00
|
|
|
return WillInterruptImpl();
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillResume()
|
|
|
|
{
|
|
|
|
return WillResumeImpl();
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
void
|
2003-01-03 23:17:22 +00:00
|
|
|
HTMLContentSink::CloseHeadContext()
|
|
|
|
{
|
2006-01-27 01:05:54 +00:00
|
|
|
if (mCurrentContext) {
|
|
|
|
if (!mCurrentContext->IsCurrentContainer(eHTMLTag_head))
|
|
|
|
return;
|
2003-01-03 23:17:22 +00:00
|
|
|
|
2009-03-23 22:10:12 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2006-01-27 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
if (!mContextStack.IsEmpty())
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t n = mContextStack.Length() - 1;
|
2009-03-20 08:15:35 +00:00
|
|
|
mCurrentContext = mContextStack.ElementAt(n);
|
|
|
|
mContextStack.RemoveElementAt(n);
|
|
|
|
}
|
2003-01-03 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
1999-10-26 14:55:51 +00:00
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer)
|
1999-10-26 14:55:51 +00:00
|
|
|
{
|
2014-10-02 19:07:24 +00:00
|
|
|
if (aContent && aContent->GetUncomposedDoc() != mDocument) {
|
2005-05-19 19:56:13 +00:00
|
|
|
// aContent is not actually in our document anymore.... Just bail out of
|
|
|
|
// here; notifying on our document for this insert would be wrong.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification++;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2007-03-09 23:43:50 +00:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_CONTENT_MODEL, !mBeganUpdate);
|
|
|
|
nsNodeUtils::ContentInserted(NODE_FROM(aContent, mDocument),
|
|
|
|
aChildContent, aIndexInContainer);
|
|
|
|
mLastNotificationTime = PR_Now();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification--;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 05:16:35 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyRootInsertion()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mNotifiedRootInsertion, "Double-notifying on root?");
|
|
|
|
NS_ASSERTION(!mLayoutStarted,
|
|
|
|
"How did we start layout without notifying on root?");
|
|
|
|
// Now make sure to notify that we have now inserted our root. If
|
|
|
|
// there has been no initial reflow yet it'll be a no-op, but if
|
|
|
|
// there has been one we need this to get its frames constructed.
|
|
|
|
// Note that if mNotifiedRootInsertion is true we don't notify here,
|
|
|
|
// since that just means there are multiple <html> tags in the
|
|
|
|
// document; in those cases we just want to put all the attrs on one
|
|
|
|
// tag.
|
2011-10-17 14:59:28 +00:00
|
|
|
mNotifiedRootInsertion = true;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = mDocument->IndexOf(mRoot);
|
2007-10-04 05:16:35 +00:00
|
|
|
NS_ASSERTION(index != -1, "mRoot not child of document?");
|
2012-07-30 14:20:58 +00:00
|
|
|
NotifyInsert(nullptr, mRoot, index);
|
2007-10-04 05:16:35 +00:00
|
|
|
|
|
|
|
// Now update the notification information in all our
|
|
|
|
// contexts, since we just inserted the root and notified on
|
|
|
|
// our whole tree
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void
|
2007-01-30 21:21:06 +00:00
|
|
|
HTMLContentSink::UpdateChildCounts()
|
1999-10-26 14:55:51 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numContexts = mContextStack.Length();
|
|
|
|
for (uint32_t i = 0; i < numContexts; i++) {
|
2009-03-20 08:15:35 +00:00
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
sc->UpdateChildCounts();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
void
|
2005-08-24 20:56:58 +00:00
|
|
|
HTMLContentSink::FlushPendingNotifications(mozFlushType aType)
|
2000-01-24 06:43:15 +00:00
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
2004-05-27 22:08:42 +00:00
|
|
|
// (since we aren't reentrant)
|
2007-10-04 05:16:35 +00:00
|
|
|
if (!mInNotification) {
|
2009-05-17 14:22:55 +00:00
|
|
|
// Only flush if we're still a document observer (so that our child counts
|
|
|
|
// should be correct).
|
|
|
|
if (mIsDocumentObserver) {
|
|
|
|
if (aType >= Flush_ContentAndNotify) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
2006-11-06 23:50:33 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
if (aType >= Flush_InterruptibleLayout) {
|
2005-08-24 20:56:58 +00:00
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(true);
|
2005-08-24 20:56:58 +00:00
|
|
|
}
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
1999-03-15 05:11:43 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::FlushTags()
|
|
|
|
{
|
2007-10-04 05:16:35 +00:00
|
|
|
if (!mNotifiedRootInsertion) {
|
|
|
|
NotifyRootInsertion();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
return mCurrentContext ? mCurrentContext->FlushTags() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 16:40:34 +00:00
|
|
|
HTMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
2001-06-29 22:56:58 +00:00
|
|
|
{
|
2014-04-21 05:00:33 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("<meta charset> case doesn't occur with about:blank");
|
2013-10-16 01:46:10 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-06-29 22:56:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-02 19:52:32 +00:00
|
|
|
nsISupports *
|
|
|
|
HTMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-15 22:34:50 +00:00
|
|
|
HTMLContentSink::IsScriptExecuting()
|
|
|
|
{
|
|
|
|
return IsScriptExecutingImpl();
|
|
|
|
}
|