2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-09-09 18:03:47 +00:00
|
|
|
/* vim: set sw=2 ts=2 et tw=78: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-04-20 08:11:12 +00:00
|
|
|
* Peter Annema <disttsc@bart.nl>
|
2002-04-05 11:29:40 +00:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
1998-12-11 17:02:37 +00:00
|
|
|
#include "nsIParser.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsParserUtils.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIScriptLoader.h"
|
2004-01-09 23:54:21 +00:00
|
|
|
#include "nsIURI.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresShell.h"
|
1998-06-23 01:34:25 +00:00
|
|
|
#include "nsIViewManager.h"
|
2002-10-01 03:04:22 +00:00
|
|
|
#include "nsIWidget.h"
|
1999-05-13 20:27:47 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsINodeInfo.h"
|
2002-09-18 23:31:08 +00:00
|
|
|
#include "nsHTMLTokens.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlog.h"
|
2004-05-13 01:39:29 +00:00
|
|
|
#include "nsInt64.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
|
|
|
#include "nsITextContent.h"
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
#include "nsIDOMText.h"
|
1999-01-22 22:48:00 +00:00
|
|
|
#include "nsIDOMComment.h"
|
2005-01-12 02:47:53 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNSDocument.h"
|
2000-03-28 23:25:26 +00:00
|
|
|
#include "nsIDOMDOMImplementation.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIDOMHTMLScriptElement.h"
|
|
|
|
#include "nsIScriptElement.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
1998-05-08 20:18:06 +00:00
|
|
|
#include "nsIFormControl.h"
|
2001-11-28 06:13:11 +00:00
|
|
|
#include "nsIForm.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
|
|
|
|
1998-07-22 23:42:47 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
1998-07-22 23:42:47 +00:00
|
|
|
#include "nsIFrame.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"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-09 00:14:53 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2000-02-04 22:50:39 +00:00
|
|
|
#include "nsICookieService.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsVoidArray.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"
|
2001-06-20 01:04:24 +00:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIParserService.h"
|
1999-11-11 22:15:02 +00:00
|
|
|
#include "nsISelectElement.h"
|
1999-09-30 22:07:04 +00:00
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1999-11-10 03:41:09 +00:00
|
|
|
#include "nsTimer.h"
|
1999-12-04 01:27:46 +00:00
|
|
|
#include "nsITimer.h"
|
1999-11-02 23:44:27 +00:00
|
|
|
#include "nsDOMError.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
|
|
|
|
2000-12-12 21:58:13 +00:00
|
|
|
#include "nsReadableUtils.h"
|
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"
|
2002-10-16 02:13:48 +00:00
|
|
|
#include "plevent.h"
|
2001-06-21 14:40:55 +00:00
|
|
|
|
|
|
|
#include "nsEscape.h"
|
2002-04-18 22:11:17 +00:00
|
|
|
#include "nsIElementObserver.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2002-04-18 22:11:17 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-06-30 23:51:53 +00:00
|
|
|
static PRLogModuleInfo* gSinkLogModuleInfo;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-04-21 22:22:15 +00:00
|
|
|
#define SINK_TRACE_CALLS 0x1
|
|
|
|
#define SINK_TRACE_REFLOW 0x2
|
|
|
|
#define SINK_ALWAYS_REFLOW 0x4
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#define SINK_LOG_TEST(_lm, _bit) (PRIntn((_lm)->level) & (_bit))
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#define SINK_TRACE(_bit, _args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, _bit)) { \
|
|
|
|
PR_LogPrint _args; \
|
|
|
|
} \
|
1998-06-30 23:51:53 +00:00
|
|
|
PR_END_MACRO
|
1998-07-11 03:51:50 +00:00
|
|
|
|
2002-11-19 18:29:35 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit, _msg, _tag, _sp, _obj) \
|
|
|
|
_obj->SinkTraceNode(_bit, _msg, _tag, _sp, this)
|
1998-07-11 03:51:50 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#else
|
2002-09-18 23:31:08 +00:00
|
|
|
#define SINK_TRACE(_bit, _args)
|
2002-11-19 18:29:35 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit, _msg, _tag, _sp, _obj)
|
1998-06-30 23:51:53 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-11-12 02:07:54 +00:00
|
|
|
#undef SINK_NO_INCREMENTAL
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#define NS_SINK_FLAG_SCRIPT_ENABLED 0x00000008
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#define NS_SINK_FLAG_FRAMES_ENABLED 0x00000010
|
|
|
|
|
|
|
|
// Interrupt parsing when mMaxTokenProcessingTime is exceeded
|
|
|
|
#define NS_SINK_FLAG_CAN_INTERRUPT_PARSER 0x00000020
|
|
|
|
|
|
|
|
// Lower the value for mNotificationInterval and
|
|
|
|
// mMaxTokenProcessingTime
|
|
|
|
#define NS_SINK_FLAG_DYNAMIC_LOWER_VALUE 0x00000040
|
|
|
|
|
|
|
|
#define NS_SINK_FLAG_FORM_ON_STACK 0x00000080
|
|
|
|
|
2004-05-13 01:39:29 +00:00
|
|
|
#define NS_SINK_FLAG_PARSING 0x00000100
|
|
|
|
|
|
|
|
#define NS_SINK_FLAG_DROPPED_TIMER 0x00000200
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// 1/2 second fudge factor for window creation
|
|
|
|
#define NS_DELAY_FOR_WINDOW_CREATION 500000
|
|
|
|
|
|
|
|
// 200 determined empirically to provide good user response without
|
|
|
|
// sampling the clock too often.
|
|
|
|
#define NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE 200
|
2001-04-21 23:40:05 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
typedef nsGenericHTMLElement* (*contentCreatorCallback)(nsINodeInfo*, PRBool aFromParser);
|
2003-09-24 06:16:52 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement*
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_NewHTMLNOTUSEDElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
|
2003-09-24 06:16:52 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("The element ctor should never be called");
|
2004-06-06 02:38:32 +00:00
|
|
|
return nsnull;
|
2003-09-24 06:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element,
|
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
|
|
|
|
#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;
|
|
|
|
|
|
|
|
static void MaybeSetForm(nsGenericHTMLElement*, nsHTMLTag, HTMLContentSink*);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
class HTMLContentSink : public nsContentSink,
|
|
|
|
public nsIHTMLContentSink,
|
1999-12-04 01:27:46 +00:00
|
|
|
public nsITimerCallback,
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
public nsIDebugDumpContent,
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2004-01-28 21:04:33 +00:00
|
|
|
public nsStubDocumentObserver
|
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;
|
|
|
|
friend class DummyParserRequest;
|
2006-02-08 05:56:13 +00:00
|
|
|
friend void MaybeSetForm(nsGenericHTMLElement*, nsHTMLTag, HTMLContentSink*);
|
2003-10-05 07:29:50 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink();
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~HTMLContentSink();
|
1998-08-28 16:20:16 +00:00
|
|
|
|
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
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsIContentSink
|
|
|
|
NS_IMETHOD WillBuildModel(void);
|
2003-07-22 18:38:08 +00:00
|
|
|
NS_IMETHOD DidBuildModel(void);
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD WillInterrupt(void);
|
|
|
|
NS_IMETHOD WillResume(void);
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD SetParser(nsIParser* aParser);
|
2005-08-24 20:56:58 +00:00
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType);
|
2003-06-17 16:40:34 +00:00
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
|
2004-11-02 19:52:32 +00:00
|
|
|
virtual nsISupports *GetTarget();
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// nsIHTMLContentSink
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
|
2006-01-31 22:19:46 +00:00
|
|
|
NS_IMETHOD CloseMalformedContainer(const nsHTMLTag aTag);
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
2002-06-25 21:16:17 +00:00
|
|
|
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
2001-06-21 02:06:23 +00:00
|
|
|
NS_IMETHOD WillProcessTokens(void);
|
|
|
|
NS_IMETHOD DidProcessTokens(void);
|
|
|
|
NS_IMETHOD WillProcessAToken(void);
|
|
|
|
NS_IMETHOD DidProcessAToken(void);
|
2001-09-28 23:08:17 +00:00
|
|
|
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode);
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHOD BeginContext(PRInt32 aID);
|
|
|
|
NS_IMETHOD EndContext(PRInt32 aID);
|
2005-09-09 18:03:47 +00:00
|
|
|
NS_IMETHOD OpenHead();
|
2003-01-16 20:24:03 +00:00
|
|
|
NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn);
|
2002-04-11 23:50:44 +00:00
|
|
|
NS_IMETHOD_(PRBool) IsFormOnStack();
|
2000-09-01 18:17:43 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// nsITimerCallback
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
// nsIDocumentObserver
|
2004-01-28 21:04:33 +00:00
|
|
|
virtual void BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType);
|
|
|
|
virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType);
|
2000-01-28 23:43:12 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2000-05-26 19:45:49 +00:00
|
|
|
// nsIDebugDumpContent
|
|
|
|
NS_IMETHOD DumpContentModel();
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-05-26 19:45:49 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
protected:
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool IsTimeToNotify();
|
2002-06-11 23:23:12 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
nsresult UpdateDocumentTitle();
|
2003-07-31 14:07:17 +00:00
|
|
|
// If aCheckIfPresent is true, will only set an attribute in cases
|
|
|
|
// when it's not already set.
|
2004-06-25 12:26:02 +00:00
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode, nsIContent* aContent,
|
2003-07-31 14:07:17 +00:00
|
|
|
PRBool aNotify = PR_FALSE,
|
|
|
|
PRBool aCheckIfPresent = PR_FALSE);
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2006-02-08 05:56:13 +00:00
|
|
|
CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType);
|
2001-06-29 04:01:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
inline PRInt32 GetNotificationInterval()
|
|
|
|
{
|
|
|
|
if (mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE) {
|
|
|
|
return 1000;
|
|
|
|
}
|
2001-06-29 04:01:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
return mNotificationInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRInt32 GetMaxTokenProcessingTime()
|
|
|
|
{
|
|
|
|
if (mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE) {
|
|
|
|
return 3000;
|
|
|
|
}
|
2001-06-29 04:01:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
return mMaxTokenProcessingTime;
|
|
|
|
}
|
2001-06-29 04:01:26 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void SinkTraceNode(PRUint32 aBit,
|
|
|
|
const char* aMsg,
|
2002-11-19 18:29:35 +00:00
|
|
|
const nsHTMLTag aTag,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 aStackPos,
|
1999-09-30 22:07:04 +00:00
|
|
|
void* aThis);
|
|
|
|
#endif
|
|
|
|
|
1999-01-15 02:02:48 +00:00
|
|
|
nsIHTMLDocument* mHTMLDocument;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// back off timer notification after count
|
|
|
|
PRInt32 mBackoffCount;
|
|
|
|
|
|
|
|
// Notification interval in microseconds
|
|
|
|
PRInt32 mNotificationInterval;
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Time of last notification
|
|
|
|
PRTime mLastNotificationTime;
|
|
|
|
|
|
|
|
// Timer used for notification
|
|
|
|
nsCOMPtr<nsITimer> mNotificationTimer;
|
|
|
|
|
|
|
|
// The maximum length of a text run
|
|
|
|
PRInt32 mMaxTextRun;
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* mRoot;
|
|
|
|
nsGenericHTMLElement* mBody;
|
2005-10-21 15:39:06 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mFrameset;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* mHead;
|
2004-09-17 20:11:02 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Do we notify based on time?
|
|
|
|
PRPackedBool mNotifyOnTimer;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-05-30 02:25:52 +00:00
|
|
|
PRPackedBool mLayoutStarted;
|
2001-10-05 10:39:01 +00:00
|
|
|
PRPackedBool mScrolledToRefAlready;
|
2005-09-09 18:03:47 +00:00
|
|
|
PRPackedBool mInTitle;
|
2001-05-30 02:25:52 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
nsString mTitleString;
|
2000-01-28 23:43:12 +00:00
|
|
|
PRInt32 mInNotification;
|
2005-01-14 13:28:34 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mCurrentForm;
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2001-09-06 19:16:03 +00:00
|
|
|
nsAutoVoidArray mContextStack;
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext* mCurrentContext;
|
|
|
|
SinkContext* mHeadContext;
|
1999-09-16 23:30:51 +00:00
|
|
|
PRInt32 mNumOpenIFRAMES;
|
2001-06-21 02:06:23 +00:00
|
|
|
nsCOMPtr<nsIRequest> mDummyParserRequest;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2006-02-01 04:43:55 +00:00
|
|
|
nsCOMPtr<nsIURI> mBaseHref;
|
|
|
|
nsCOMPtr<nsIAtom> mBaseTarget;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-03-25 18:55:59 +00:00
|
|
|
// depth of containment within <noembed>, <noframes> etc
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 mInsideNoXXXTag;
|
|
|
|
PRInt32 mInMonolithicContainer;
|
|
|
|
PRUint32 mFlags;
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// -- Can interrupt parsing members --
|
|
|
|
PRUint32 mDelayTimerStart;
|
|
|
|
|
|
|
|
// Interrupt parsing during token procesing after # of microseconds
|
|
|
|
PRInt32 mMaxTokenProcessingTime;
|
|
|
|
|
|
|
|
// Switch between intervals when time is exceeded
|
|
|
|
PRInt32 mDynamicIntervalSwitchThreshold;
|
|
|
|
|
|
|
|
PRInt32 mBeginLoadTime;
|
|
|
|
|
|
|
|
// Last mouse event or keyboard event time sampled by the content
|
|
|
|
// sink
|
|
|
|
PRUint32 mLastSampledUserEventTime;
|
|
|
|
|
|
|
|
// The number of tokens that have been processed while in the low
|
|
|
|
// frequency parser interrupt mode without falling through to the
|
|
|
|
// logic which decides whether to switch to the high frequency
|
|
|
|
// parser interrupt mode.
|
|
|
|
PRUint8 mDeflectedCount;
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2006-01-12 17:11:57 +00:00
|
|
|
// Boolean indicating whether we've notified insertion of our root content
|
|
|
|
// yet. We want to make sure to only do this once.
|
|
|
|
PRPackedBool mNotifiedRootInsertion;
|
|
|
|
|
2006-01-27 01:13:00 +00:00
|
|
|
// Boolean indicating whether we've seen a <head> tag that might have had
|
|
|
|
// attributes once already.
|
|
|
|
PRPackedBool mHaveSeenHead;
|
|
|
|
|
2001-09-28 23:08:17 +00:00
|
|
|
nsCOMPtr<nsIObserverEntry> mObservers;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void StartLayout();
|
1998-07-22 23:42:47 +00:00
|
|
|
|
2001-10-05 10:39:01 +00:00
|
|
|
void TryToScrollToRef();
|
1998-05-08 20:18:06 +00:00
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
/**
|
|
|
|
* AddBaseTagInfo adds the "current" base URI and target to the content node
|
|
|
|
* in the form of bogo-attributes. This MUST be called before attributes are
|
|
|
|
* added to the content node, since the way URI attributes are treated may
|
|
|
|
* depend on the value of the base URI
|
|
|
|
*/
|
2004-06-25 12:26:02 +00:00
|
|
|
void AddBaseTagInfo(nsIContent* aContent);
|
1998-04-13 20:24:54 +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();
|
|
|
|
nsresult OpenFrameset(const nsIParserNode& aNode);
|
|
|
|
nsresult CloseFrameset();
|
|
|
|
nsresult OpenBody(const nsIParserNode& aNode);
|
|
|
|
nsresult CloseBody();
|
|
|
|
nsresult OpenForm(const nsIParserNode& aNode);
|
|
|
|
nsresult CloseForm();
|
2005-11-10 15:51:10 +00:00
|
|
|
void ProcessBASEElement(nsGenericHTMLElement* aElement);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult ProcessLINKTag(const nsIParserNode& aNode);
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
// Routines for tags that require special handling when we reach their end
|
|
|
|
// tag.
|
2005-09-22 02:33:36 +00:00
|
|
|
nsresult ProcessSCRIPTEndTag(nsGenericHTMLElement* content,
|
2006-01-31 22:19:46 +00:00
|
|
|
PRBool aHaveNotified,
|
|
|
|
PRBool aMalformed);
|
2005-09-09 18:03:47 +00:00
|
|
|
nsresult ProcessSTYLEEndTag(nsGenericHTMLElement* content);
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult OpenHeadContext();
|
2005-10-21 15:39:06 +00:00
|
|
|
void CloseHeadContext();
|
2003-10-05 07:29:50 +00:00
|
|
|
|
|
|
|
// nsContentSink overrides
|
2003-10-05 11:28:06 +00:00
|
|
|
virtual void PreEvaluateScript();
|
2006-01-24 01:25:14 +00:00
|
|
|
virtual void PostEvaluateScript(nsIScriptElement *aElement);
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void UpdateAllContexts();
|
2002-09-18 23:31:08 +00:00
|
|
|
void NotifyAppend(nsIContent* aContent,
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 aStartIndex);
|
1999-10-26 14:55:51 +00:00
|
|
|
void NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer);
|
2000-02-16 23:43:59 +00:00
|
|
|
PRBool IsMonolithicContainer(nsHTMLTag aTag);
|
2001-06-21 02:06:23 +00:00
|
|
|
|
|
|
|
// CanInterrupt parsing related routines
|
|
|
|
nsresult AddDummyParserRequest(void);
|
|
|
|
nsresult RemoveDummyParserRequest(void);
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void ForceReflow();
|
1999-04-03 19:00:23 +00:00
|
|
|
#endif
|
1999-09-14 14:38:52 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Measures content model creation time for current document
|
|
|
|
MOZ_TIMER_DECLARE(mWatch)
|
2001-06-21 02:06:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DummyParserRequest
|
|
|
|
//
|
|
|
|
// This is a dummy request implementation that we add to the document's load
|
|
|
|
// group. It ensures that EndDocumentLoad() in the docshell doesn't fire
|
|
|
|
// before we've finished all of parsing and tokenizing of the document.
|
|
|
|
//
|
|
|
|
|
|
|
|
class DummyParserRequest : public nsIChannel
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
DummyParserRequest(nsIHTMLContentSink* aSink);
|
|
|
|
virtual ~DummyParserRequest();
|
|
|
|
|
|
|
|
static PRInt32 gRefCnt;
|
|
|
|
static nsIURI* gURI;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
nsIHTMLContentSink* mSink; // Weak reference
|
|
|
|
|
|
|
|
public:
|
|
|
|
static nsresult
|
|
|
|
Create(nsIRequest** aResult, nsIHTMLContentSink* aSink);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
// nsIRequest
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD GetName(nsACString &result)
|
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
result.AssignLiteral("about:layout-dummy-request");
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
NS_IMETHOD IsPending(PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetStatus(nsresult *status)
|
|
|
|
{
|
|
|
|
*status = NS_OK;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
NS_IMETHOD Cancel(nsresult status);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD Suspend(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Resume(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup)
|
|
|
|
{
|
|
|
|
*aLoadGroup = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup)
|
|
|
|
{
|
|
|
|
mLoadGroup = aLoadGroup;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
|
|
|
*aLoadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
// nsIChannel
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI)
|
|
|
|
{
|
|
|
|
*aOriginalURI = gURI;
|
|
|
|
NS_ADDREF(*aOriginalURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI)
|
|
|
|
{
|
|
|
|
gURI = aOriginalURI;
|
|
|
|
NS_ADDREF(gURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetURI(nsIURI **aURI)
|
|
|
|
{
|
|
|
|
*aURI = gURI;
|
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
gURI = aURI;
|
|
|
|
NS_ADDREF(gURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Open(nsIInputStream **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetOwner(nsISupports **aOwner)
|
|
|
|
{
|
|
|
|
*aOwner = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetOwner(nsISupports *aOwner)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aNotifCallbacks)
|
|
|
|
{
|
|
|
|
*aNotifCallbacks = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aNotifCallbacks)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo)
|
|
|
|
{
|
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD GetContentType(nsACString &aContentType)
|
|
|
|
{
|
|
|
|
aContentType.Truncate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetContentType(const nsACString &aContentType)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
aContentCharset.Truncate();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetContentLength(PRInt32 *aContentLength)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-06-23 22:25:28 +00:00
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
PRInt32 DummyParserRequest::gRefCnt;
|
|
|
|
nsIURI* DummyParserRequest::gURI;
|
|
|
|
|
2003-09-07 21:50:21 +00:00
|
|
|
NS_IMPL_ADDREF(DummyParserRequest)
|
|
|
|
NS_IMPL_RELEASE(DummyParserRequest)
|
|
|
|
NS_IMPL_QUERY_INTERFACE2(DummyParserRequest, nsIRequest, nsIChannel)
|
2001-06-21 02:06:23 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
DummyParserRequest::Create(nsIRequest** aResult, nsIHTMLContentSink* aSink)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
*aResult = new DummyParserRequest(aSink);
|
|
|
|
if (!*aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DummyParserRequest::DummyParserRequest(nsIHTMLContentSink* aSink)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (gRefCnt++ == 0) {
|
2002-09-18 23:31:08 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
NS_NewURI(&gURI, NS_LITERAL_CSTRING("about:parser-dummy-request"));
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"unable to create about:parser-dummy-request");
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mSink = aSink;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DummyParserRequest::~DummyParserRequest()
|
|
|
|
{
|
|
|
|
if (--gRefCnt == 0) {
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IF_RELEASE(gURI);
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DummyParserRequest::Cancel(nsresult status)
|
|
|
|
{
|
|
|
|
// Cancel parser
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
HTMLContentSink* sink = NS_STATIC_CAST(HTMLContentSink*, mSink);
|
|
|
|
if ((sink) && (sink->mParser)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
sink->mParser->CancelParsingEvents();
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
class SinkContext
|
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
public:
|
|
|
|
SinkContext(HTMLContentSink* aSink);
|
|
|
|
~SinkContext();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsGenericHTMLElement* aRoot,
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 aNumFlushed, PRInt32 aInsertionPoint);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult OpenContainer(const nsIParserNode& aNode);
|
2006-01-31 22:19:46 +00:00
|
|
|
nsresult CloseContainer(const nsHTMLTag aTag, PRBool aMalformed);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult AddLeaf(const nsIParserNode& aNode);
|
2005-01-12 19:45:38 +00:00
|
|
|
nsresult AddLeaf(nsGenericHTMLElement* aContent);
|
1999-01-22 22:48:00 +00:00
|
|
|
nsresult AddComment(const nsIParserNode& aNode);
|
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();
|
2002-03-23 23:13:20 +00:00
|
|
|
nsresult AddText(const nsAString& aText);
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult FlushText(PRBool* aDidFlush = nsnull,
|
|
|
|
PRBool aReleaseLast = PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult FlushTextAndRelease(PRBool* aDidFlush = nsnull)
|
|
|
|
{
|
|
|
|
return FlushText(aDidFlush, PR_TRUE);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
nsresult FlushTags(PRBool aNotify);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-04-13 22:22:51 +00:00
|
|
|
PRBool IsCurrentContainer(nsHTMLTag mType);
|
1999-07-22 23:28:16 +00:00
|
|
|
PRBool IsAncestorContainer(nsHTMLTag mType);
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void DidAddContent(nsIContent* aContent, PRBool aDidNotify = PR_FALSE);
|
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.
|
|
|
|
PRBool HaveNotifiedForCurrentContent() const;
|
|
|
|
|
|
|
|
public:
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink* mSink;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mNotifyLevel;
|
2002-12-19 20:23:57 +00:00
|
|
|
nsCOMPtr<nsITextContent> mLastTextNode;
|
2000-01-31 23:39:19 +00:00
|
|
|
PRInt32 mLastTextNodeSize;
|
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;
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 mNumFlushed;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mInsertionPoint;
|
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;
|
|
|
|
PRInt32 mStackSize;
|
|
|
|
PRInt32 mStackPos;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRUnichar* mText;
|
|
|
|
PRInt32 mTextLength;
|
|
|
|
PRInt32 mTextSize;
|
|
|
|
};
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
//----------------------------------------------------------------------
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void
|
|
|
|
HTMLContentSink::SinkTraceNode(PRUint32 aBit,
|
|
|
|
const char* aMsg,
|
2002-11-19 18:29:35 +00:00
|
|
|
const nsHTMLTag aTag,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 aStackPos,
|
1999-09-30 22:07:04 +00:00
|
|
|
void* aThis)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, aBit)) {
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (!parserService)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 tag(parserService->HTMLIdToStringTag(aTag));
|
2002-11-19 18:29:35 +00:00
|
|
|
PR_LogPrint("%s: this=%p node='%s' stackPos=%d",
|
2005-06-16 13:10:58 +00:00
|
|
|
aMsg, aThis, tag.get(), aStackPos);
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
|
2004-06-25 12:26:02 +00:00
|
|
|
nsIContent* aContent, PRBool aNotify,
|
2003-07-31 14:07:17 +00:00
|
|
|
PRBool aCheckIfPresent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add tag attributes to the content attributes
|
2001-11-21 09:10:41 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
2001-11-21 09:10:41 +00:00
|
|
|
|
|
|
|
if (ac == 0) {
|
|
|
|
// No attributes, nothing to do. Do an early return to avoid
|
|
|
|
// constructing the nsAutoString object for nothing.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-24 06:10:52 +00:00
|
|
|
nsCAutoString k;
|
2001-11-06 07:14:40 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2003-07-22 14:21:59 +00:00
|
|
|
// The attributes are on the parser node in the order they came in in the
|
|
|
|
// source. What we want to happen if a single attribute is set multiple
|
|
|
|
// times on an element is that the first time should "win". That is, <input
|
|
|
|
// value="foo" value="bar"> should show "foo". So we loop over the
|
|
|
|
// attributes backwards; this ensures that the first attribute in the set
|
|
|
|
// wins. This does mean that we do some extra work in the case when the same
|
|
|
|
// attribute is set multiple times, but we save a HasAttr call in the much
|
2006-01-27 01:13:00 +00:00
|
|
|
// more common case of reasonable HTML. Note that if aCheckIfPresent is set
|
|
|
|
// then we actually want to loop _forwards_ to preserve the "first attribute
|
|
|
|
// wins" behavior. That does mean that when aCheckIfPresent is set the order
|
|
|
|
// of attributes will get "reversed" from the point of view of the
|
|
|
|
// serializer. But aCheckIfPresent is only true for malformed documents with
|
|
|
|
// multiple <html>, <head>, or <body> tags, so we're doing fixup anyway at
|
|
|
|
// that point.
|
|
|
|
|
|
|
|
PRInt32 i, limit, step;
|
|
|
|
if (aCheckIfPresent) {
|
|
|
|
i = 0;
|
|
|
|
limit = ac;
|
|
|
|
step = 1;
|
|
|
|
} else {
|
|
|
|
i = ac - 1;
|
|
|
|
limit = -1;
|
|
|
|
step = -1;
|
|
|
|
}
|
2003-07-22 14:21:59 +00:00
|
|
|
|
2006-01-27 01:13:00 +00:00
|
|
|
for (; i != limit; i += step) {
|
2003-07-22 01:31:34 +00:00
|
|
|
// Get lower-cased key
|
2002-03-23 23:13:20 +00:00
|
|
|
const nsAString& key = aNode.GetKeyAt(i);
|
2004-05-24 06:10:52 +00:00
|
|
|
// Copy up-front to avoid shared-buffer overhead (and convert to UTF-8
|
|
|
|
// at the same time since that's what the atom table uses).
|
|
|
|
CopyUTF16toUTF8(key, k);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(k);
|
1998-09-22 02:09:26 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(k);
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2003-07-31 14:07:17 +00:00
|
|
|
if (aCheckIfPresent && aContent->HasAttr(kNameSpaceID_None, keyAtom)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-22 14:21:59 +00:00
|
|
|
// Get value and remove mandatory quotes
|
|
|
|
static const char* kWhitespace = "\n\r\t\b";
|
2006-04-17 21:28:47 +00:00
|
|
|
|
|
|
|
// Bug 114997: Don't trim whitespace on <input value="...">:
|
|
|
|
// Using ?: outside the function call would be more efficient, but
|
|
|
|
// we don't trust ?: with references.
|
2003-07-22 14:21:59 +00:00
|
|
|
const nsAString& v =
|
2006-04-17 21:28:47 +00:00
|
|
|
nsContentUtils::TrimCharsInSet(
|
|
|
|
(nodeType == eHTMLTag_input &&
|
|
|
|
keyAtom == nsHTMLAtoms::value) ?
|
|
|
|
"" : kWhitespace, aNode.GetValueAt(i));
|
2003-07-22 14:21:59 +00:00
|
|
|
|
|
|
|
if (nodeType == eHTMLTag_a && keyAtom == nsHTMLAtoms::name) {
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertUTF16toUTF8 cname(v);
|
|
|
|
NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting()));
|
2003-07-22 14:21:59 +00:00
|
|
|
|
|
|
|
// Add attribute to content
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, keyAtom, uv, aNotify);
|
|
|
|
} else {
|
|
|
|
// Add attribute to content
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, keyAtom, v, aNotify);
|
1998-09-22 02:09:26 +00:00
|
|
|
}
|
1998-06-26 16:12:51 +00:00
|
|
|
}
|
2001-11-21 09:10:41 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
static void
|
2006-02-08 05:56:13 +00:00
|
|
|
MaybeSetForm(nsGenericHTMLElement* aContent, nsHTMLTag aNodeType,
|
|
|
|
HTMLContentSink* aSink)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
2006-02-08 05:56:13 +00:00
|
|
|
nsGenericHTMLElement* form = aSink->mCurrentForm;
|
|
|
|
|
|
|
|
if (!form || aSink->mInsideNoXXXTag) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aNodeType) {
|
|
|
|
case eHTMLTag_button:
|
|
|
|
case eHTMLTag_fieldset:
|
|
|
|
case eHTMLTag_label:
|
|
|
|
case eHTMLTag_legend:
|
|
|
|
case eHTMLTag_object:
|
|
|
|
case eHTMLTag_input:
|
|
|
|
case eHTMLTag_select:
|
|
|
|
case eHTMLTag_textarea:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(aContent));
|
2006-02-08 05:56:13 +00:00
|
|
|
NS_ASSERTION(formControl,
|
|
|
|
"nsGenericHTMLElement didn't implement nsIFormControl");
|
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(form));
|
|
|
|
NS_ASSERTION(!form || formElement,
|
|
|
|
"nsGenericHTMLElement didn't implement nsIDOMHTMLFormElement");
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-01-14 13:28:34 +00:00
|
|
|
formControl->SetForm(formElement);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
static already_AddRefed<nsGenericHTMLElement>
|
2002-09-18 23:31:08 +00:00
|
|
|
MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo,
|
2006-02-08 05:56:13 +00:00
|
|
|
PRBool aFromParser);
|
2000-12-10 09:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory subroutine to create all of the html content objects.
|
|
|
|
*/
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2000-12-10 09:20:40 +00:00
|
|
|
HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
|
2006-02-08 05:56:13 +00:00
|
|
|
nsHTMLTag aNodeType)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
|
|
|
// Find/create atom for the tag name
|
2001-11-28 06:13:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
|
|
|
|
if (aNodeType == eHTMLTag_userdefined) {
|
2003-11-05 05:17:07 +00:00
|
|
|
NS_ConvertUTF16toUTF8 tmp(aNode.GetText());
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(tmp);
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2004-02-10 10:58:13 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(tmp);
|
2005-06-16 13:10:58 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_None,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (!parserService)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIAtom *name = parserService->HTMLIdToAtomTag(aNodeType);
|
|
|
|
NS_ASSERTION(name, "What? Reverse mapping of id to string broken!!!");
|
|
|
|
|
|
|
|
mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_None,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 13:10:58 +00:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, nsnull);
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Make the content object
|
2006-02-08 05:56:13 +00:00
|
|
|
nsGenericHTMLElement* result = MakeContentObject(aNodeType, nodeInfo,
|
|
|
|
PR_TRUE).get();
|
2004-06-06 02:38:32 +00:00
|
|
|
if (!result) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-06-06 02:38:32 +00:00
|
|
|
return result;
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-06-25 12:26:02 +00:00
|
|
|
NS_NewHTMLElement(nsIContent** aResult, nsINodeInfo *aNodeInfo)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
2004-06-25 12:26:02 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
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
|
|
|
|
2003-11-15 05:27:37 +00:00
|
|
|
nsIAtom *name = aNodeInfo->NameAtom();
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2005-06-16 13:10:58 +00:00
|
|
|
nsHTMLTag id;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> result;
|
2004-06-25 12:26:02 +00:00
|
|
|
if (aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
|
|
|
|
// Find tag in tag table
|
2005-06-16 13:10:58 +00:00
|
|
|
id = nsHTMLTag(parserService->HTMLCaseSensitiveAtomTagToId(name));
|
2004-06-25 12:26:02 +00:00
|
|
|
|
2006-02-08 05:56:13 +00:00
|
|
|
result = MakeContentObject(id, aNodeInfo, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2004-06-25 12:26:02 +00:00
|
|
|
else {
|
|
|
|
// Find tag in tag table
|
2005-06-16 13:10:58 +00:00
|
|
|
id = nsHTMLTag(parserService->HTMLAtomTagToId(name));
|
2005-03-17 20:41:27 +00:00
|
|
|
|
|
|
|
// Reverse map id to name to get the correct character case in
|
2002-09-18 23:31:08 +00:00
|
|
|
// the tag name.
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> kungFuDeathGrip;
|
|
|
|
nsINodeInfo *nodeInfo = aNodeInfo;
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2005-06-16 13:10:58 +00:00
|
|
|
if (id != eHTMLTag_userdefined) {
|
|
|
|
nsIAtom *tag = parserService->HTMLIdToAtomTag(id);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ASSERTION(tag, "What? Reverse mapping of id to string broken!!!");
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2005-06-16 13:10:58 +00:00
|
|
|
if (name != tag) {
|
2004-06-25 12:26:02 +00:00
|
|
|
nsresult rv =
|
2005-06-16 13:10:58 +00:00
|
|
|
nsContentUtils::NameChanged(aNodeInfo, tag,
|
2004-06-25 12:26:02 +00:00
|
|
|
getter_AddRefs(kungFuDeathGrip));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nodeInfo = kungFuDeathGrip;
|
|
|
|
}
|
2001-05-12 05:10:48 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-02-08 05:56:13 +00:00
|
|
|
result = MakeContentObject(id, nodeInfo, PR_FALSE);
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
return result ? CallQueryInterface(result.get(), aResult)
|
|
|
|
: NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2002-09-18 23:31:08 +00:00
|
|
|
MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo,
|
2006-02-08 05:56:13 +00:00
|
|
|
PRBool aFromParser)
|
1998-04-13 20:24:54 +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
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* result = cb(aNodeInfo, aFromParser);
|
2004-06-06 02:38:32 +00:00
|
|
|
if (!result) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_ADDREF(result);
|
|
|
|
|
|
|
|
return result;
|
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),
|
|
|
|
mLastTextNodeSize(0),
|
|
|
|
mStack(nsnull),
|
|
|
|
mStackSize(0),
|
|
|
|
mStackPos(0),
|
|
|
|
mText(nsnull),
|
|
|
|
mTextLength(0),
|
|
|
|
mTextSize(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) {
|
1998-08-28 16:20:16 +00:00
|
|
|
for (PRInt32 i = 0; i < mStackPos; i++) {
|
|
|
|
NS_RELEASE(mStack[i].mContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
delete [] mStack;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete [] mText;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
SinkContext::Begin(nsHTMLTag aNodeType,
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* aRoot,
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 aNumFlushed,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 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;
|
|
|
|
mTextLength = 0;
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-04-13 22:22:51 +00:00
|
|
|
PRBool
|
|
|
|
SinkContext::IsCurrentContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aTag == mStack[mStackPos - 1].mType) {
|
1999-04-13 22:22:51 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
PRBool
|
|
|
|
SinkContext::IsAncestorContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 stackPos = mStackPos - 1;
|
1999-07-22 23:28:16 +00:00
|
|
|
|
|
|
|
while (stackPos >= 0) {
|
|
|
|
if (aTag == mStack[stackPos].mType) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
1999-10-27 14:03:15 +00:00
|
|
|
SinkContext::DidAddContent(nsIContent* aContent, PRBool aDidNotify)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-10-27 14:03:15 +00:00
|
|
|
// If there was a notification done for this content, update the
|
|
|
|
// parent's notification count.
|
|
|
|
if (aDidNotify && (0 < mStackPos)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
2003-09-27 04:18:26 +00:00
|
|
|
mStack[mStackPos - 1].mNumFlushed = parent->GetChildCount();
|
1999-10-27 14:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-10-20 02:12:20 +00:00
|
|
|
if ((mStackPos == 2) && (mSink->mBody == mStack[1].mContent ||
|
|
|
|
mSink->mFrameset == 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.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!aDidNotify && (0 < mStackPos) &&
|
|
|
|
(mStack[mStackPos - 1].mInsertionPoint != -1)) {
|
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Tracing code
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (parserService) {
|
|
|
|
nsHTMLTag tag = nsHTMLTag(mStack[mStackPos - 1].mType);
|
|
|
|
NS_ConvertUTF16toUTF8 str(parserService->HTMLIdToStringTag(tag));
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::DidAddContent: Insertion notification for "
|
|
|
|
"parent=%s at position=%d and stackPos=%d",
|
|
|
|
str.get(), mStack[mStackPos - 1].mInsertionPoint - 1,
|
|
|
|
mStackPos - 1));
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->NotifyInsert(parent, aContent,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint - 1);
|
2003-09-27 04:18:26 +00:00
|
|
|
mStack[mStackPos - 1].mNumFlushed = parent->GetChildCount();
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (!aDidNotify && mSink->IsTimeToNotify()) {
|
1999-12-04 01:27:46 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("SinkContext::DidAddContent: Notification as a result of the "
|
|
|
|
"interval expiring; backoff count: %d", mSink->mBackoffCount));
|
2000-01-28 23:43:12 +00:00
|
|
|
FlushTags(PR_TRUE);
|
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
|
|
|
|
SinkContext::OpenContainer(const nsIParserNode& aNode)
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::OpenContainer",
|
|
|
|
nsHTMLTag(aNode.GetNodeType()),
|
|
|
|
mStackPos,
|
|
|
|
mSink);
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create new container content object
|
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content =
|
2006-02-08 05:56:13 +00:00
|
|
|
mSink->CreateContentObject(aNode, nodeType).get();
|
2004-06-06 02:38:32 +00:00
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[mStackPos].mType = nodeType;
|
|
|
|
mStack[mStackPos].mContent = content;
|
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;
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
// XXX Need to do this before we start adding attributes.
|
|
|
|
if (nodeType == eHTMLTag_style) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(content);
|
|
|
|
NS_ASSERTION(ssle, "Style content isn't a style sheet?");
|
|
|
|
ssle->SetLineNumber(aNode.GetSourceLineNumber());
|
|
|
|
|
|
|
|
// Now disable updates so that every time we add an attribute or child
|
|
|
|
// text token, we don't try to update the style sheet.
|
|
|
|
if (!mSink->mInsideNoXXXTag) {
|
|
|
|
ssle->InitStyleLinkElement(mSink->mParser, PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We're not going to be evaluating this style anyway.
|
|
|
|
ssle->InitStyleLinkElement(nsnull, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
// Make sure to add base tag info, if needed, before setting any other
|
|
|
|
// attributes -- what URI attrs do will depend on the base URI. Only do this
|
|
|
|
// for elements that have useful URI attributes.
|
|
|
|
// See bug 18478 and bug 30617 for why we need to do this.
|
|
|
|
switch (nodeType) {
|
|
|
|
// Containers with "href="
|
|
|
|
case eHTMLTag_a:
|
|
|
|
case eHTMLTag_map:
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
// Containers with "src="
|
|
|
|
case eHTMLTag_script:
|
2003-04-17 23:15:21 +00:00
|
|
|
|
|
|
|
// Containers with "action="
|
|
|
|
case eHTMLTag_form:
|
|
|
|
|
|
|
|
// Containers with "data="
|
|
|
|
case eHTMLTag_object:
|
|
|
|
|
|
|
|
// Containers with "background="
|
|
|
|
case eHTMLTag_table:
|
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tbody:
|
|
|
|
case eHTMLTag_tfoot:
|
|
|
|
case eHTMLTag_tr:
|
|
|
|
case eHTMLTag_td:
|
|
|
|
case eHTMLTag_th:
|
|
|
|
mSink->AddBaseTagInfo(content);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content);
|
2006-02-08 05:56:13 +00:00
|
|
|
MaybeSetForm(content, nodeType, mSink);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
2006-04-08 00:32:03 +00:00
|
|
|
nsGenericHTMLElement* parent = mStack[mStackPos - 2].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-04-08 00:32:03 +00:00
|
|
|
if (mStack[mStackPos - 2].mInsertionPoint != -1) {
|
2005-04-07 03:30:50 +00:00
|
|
|
parent->InsertChildAt(content,
|
2006-04-08 00:32:03 +00:00
|
|
|
mStack[mStackPos - 2].mInsertionPoint++,
|
2005-04-18 22:58:35 +00:00
|
|
|
PR_FALSE);
|
2005-04-07 03:30:50 +00:00
|
|
|
} else {
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mSink->IsMonolithicContainer(nodeType)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->mInMonolithicContainer++;
|
2000-02-16 23:43:59 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
2005-10-21 15:39:06 +00:00
|
|
|
case eHTMLTag_form:
|
|
|
|
mSink->mCurrentForm = content;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_frameset:
|
|
|
|
if (!mSink->mFrameset &&
|
|
|
|
mSink->mFlags & NS_SINK_FLAG_FRAMES_ENABLED) {
|
|
|
|
mSink->mFrameset = content;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
|
|
|
mSink->mInsideNoXXXTag++;
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES++;
|
2005-09-09 18:03:47 +00:00
|
|
|
break;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
case eHTMLTag_script:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
|
|
|
|
NS_ASSERTION(sele, "Script content isn't a script element?");
|
|
|
|
sele->SetScriptLineNumber(aNode.GetSourceLineNumber());
|
|
|
|
}
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
case eHTMLTag_title:
|
|
|
|
if (mSink->mDocument->GetDocumentTitle().IsVoid()) {
|
|
|
|
// The first title wins.
|
|
|
|
mSink->mInTitle = PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-22 02:33:36 +00:00
|
|
|
PRBool
|
|
|
|
SinkContext::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
|
|
|
if (0 < mStackPos) {
|
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
return mStack[mStackPos-1].mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2006-01-31 22:19:46 +00:00
|
|
|
SinkContext::CloseContainer(const nsHTMLTag aTag, PRBool aMalformed)
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Flush any collected text content. Release the last text
|
|
|
|
// node to indicate that no more should be added to it.
|
|
|
|
FlushTextAndRelease();
|
2002-04-17 04:17:16 +00:00
|
|
|
|
1998-07-20 18:52:40 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::CloseContainer",
|
|
|
|
aTag, mStackPos - 1, mSink);
|
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;
|
|
|
|
nsHTMLTag nodeType = mStack[mStackPos].mType;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content = mStack[mStackPos].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +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
|
|
|
#ifdef NS_DEBUG
|
2003-11-19 01:20:56 +00:00
|
|
|
{
|
|
|
|
// Tracing code
|
|
|
|
const char *tagStr;
|
|
|
|
mStack[mStackPos].mContent->Tag()->GetUTF8String(&tagStr);
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::CloseContainer: reflow on notifyImmediate "
|
|
|
|
"tag=%s newIndex=%d stackPos=%d",
|
|
|
|
tagStr,
|
|
|
|
mStack[mStackPos].mNumFlushed, mStackPos));
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
#endif
|
1999-10-26 14:55:51 +00:00
|
|
|
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mSink->IsMonolithicContainer(nodeType)) {
|
|
|
|
--mSink->mInMonolithicContainer;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2001-03-06 00:52:54 +00:00
|
|
|
DidAddContent(content, PR_FALSE);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
|
|
|
// Fix bug 40216
|
|
|
|
NS_ASSERTION((mSink->mInsideNoXXXTag > 0), "mInsideNoXXXTag underflow");
|
|
|
|
if (mSink->mInsideNoXXXTag > 0) {
|
|
|
|
mSink->mInsideNoXXXTag--;
|
|
|
|
}
|
1999-09-11 14:55:33 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_form:
|
|
|
|
{
|
|
|
|
mSink->mFlags &= ~NS_SINK_FLAG_FORM_ON_STACK;
|
|
|
|
// If there's a FORM on the stack, but this close tag doesn't
|
|
|
|
// close the form, then close out the form *and* close out the
|
|
|
|
// next container up. This is since the parser doesn't do fix up
|
|
|
|
// of invalid form nesting. When the end FORM tag comes through,
|
|
|
|
// we'll ignore it.
|
2002-11-19 18:29:35 +00:00
|
|
|
if (aTag != nodeType) {
|
2006-01-31 22:19:46 +00:00
|
|
|
result = CloseContainer(aTag, PR_FALSE);
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
1999-09-16 23:30:51 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES--;
|
1999-09-16 23:30:51 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2005-10-21 15:39:06 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_select:
|
2005-06-01 21:23:23 +00:00
|
|
|
case eHTMLTag_textarea:
|
2004-06-02 00:25:00 +00:00
|
|
|
case eHTMLTag_object:
|
|
|
|
case eHTMLTag_applet:
|
2005-09-22 02:33:36 +00:00
|
|
|
content->DoneAddingChildren(HaveNotifiedForCurrentContent());
|
2005-09-09 18:03:47 +00:00
|
|
|
break;
|
1999-11-11 22:15:02 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
case eHTMLTag_script:
|
2005-09-22 02:33:36 +00:00
|
|
|
result = mSink->ProcessSCRIPTEndTag(content,
|
2006-01-31 22:19:46 +00:00
|
|
|
HaveNotifiedForCurrentContent(),
|
|
|
|
aMalformed);
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
case eHTMLTag_style:
|
|
|
|
result = mSink->ProcessSTYLEEndTag(content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_title:
|
|
|
|
if (mSink->mInTitle) {
|
|
|
|
mSink->UpdateDocumentTitle();
|
|
|
|
mSink->mInTitle = PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
|
|
|
|
1999-11-11 22:15:02 +00:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::AddLeaf(const nsIParserNode& aNode)
|
1998-07-15 22:31:10 +00:00
|
|
|
{
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::AddLeaf",
|
|
|
|
nsHTMLTag(aNode.GetNodeType()),
|
|
|
|
mStackPos, mSink);
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
switch (aNode.GetTokenType()) {
|
|
|
|
case eToken_start:
|
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create new leaf content object
|
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2005-01-12 19:45:38 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> content =
|
2006-02-08 05:56:13 +00:00
|
|
|
mSink->CreateContentObject(aNode, nodeType);
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_OUT_OF_MEMORY);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
// Make sure to add base tag info, if needed, before setting any other
|
|
|
|
// attributes -- what URI attrs do will depend on the base URI. Only do
|
|
|
|
// this for elements that have useful URI attributes.
|
|
|
|
// See bug 18478 and bug 30617 for why we need to do this.
|
1998-08-28 16:20:16 +00:00
|
|
|
switch (nodeType) {
|
2005-11-10 15:51:10 +00:00
|
|
|
case eHTMLTag_area:
|
|
|
|
case eHTMLTag_meta:
|
2003-04-17 23:15:21 +00:00
|
|
|
case eHTMLTag_img:
|
1998-11-24 02:01:45 +00:00
|
|
|
case eHTMLTag_frame:
|
|
|
|
case eHTMLTag_input:
|
2003-04-17 23:15:21 +00:00
|
|
|
case eHTMLTag_embed:
|
2005-10-21 15:39:06 +00:00
|
|
|
mSink->AddBaseTagInfo(content);
|
|
|
|
break;
|
|
|
|
|
2005-08-16 22:57:11 +00:00
|
|
|
// <form> can end up as a leaf if it's misnested with table elements
|
|
|
|
case eHTMLTag_form:
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->AddBaseTagInfo(content);
|
2005-10-21 15:39:06 +00:00
|
|
|
mSink->mCurrentForm = content;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1999-02-12 17:45:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-15 22:31:10 +00:00
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-02-08 05:56:13 +00:00
|
|
|
MaybeSetForm(content, nodeType, mSink);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add new leaf to its parent
|
1999-01-09 00:14:53 +00:00
|
|
|
AddLeaf(content);
|
2002-03-31 10:14:01 +00:00
|
|
|
|
2005-11-10 15:51:10 +00:00
|
|
|
// Additional processing needed once the element is in the tree
|
2002-03-31 10:14:01 +00:00
|
|
|
switch (nodeType) {
|
2005-11-10 15:51:10 +00:00
|
|
|
case eHTMLTag_base:
|
|
|
|
if (!mSink->mInsideNoXXXTag) {
|
|
|
|
mSink->ProcessBASEElement(content);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_meta:
|
|
|
|
// XXX It's just not sufficient to check if the parent is head. Also
|
|
|
|
// check for the preference.
|
|
|
|
// Bug 40072: Don't evaluate METAs after FRAMESET.
|
|
|
|
if (!mSink->mInsideNoXXXTag && !mSink->mFrameset) {
|
|
|
|
rv = mSink->ProcessMETATag(content);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-03-31 10:14:01 +00:00
|
|
|
case eHTMLTag_input:
|
|
|
|
case eHTMLTag_button:
|
|
|
|
content->DoneCreatingElement();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-03-31 10:14:01 +00:00
|
|
|
break;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-04-16 18:09:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
case eToken_text:
|
|
|
|
case eToken_whitespace:
|
|
|
|
case eToken_newline:
|
1999-04-03 19:00:23 +00:00
|
|
|
rv = AddText(aNode.GetText());
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eToken_entity:
|
|
|
|
{
|
|
|
|
nsAutoString tmp;
|
|
|
|
PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp);
|
|
|
|
if (unicode < 0) {
|
1999-04-03 19:00:23 +00:00
|
|
|
rv = AddText(aNode.GetText());
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
1999-07-05 19:45:27 +00:00
|
|
|
// Map carriage returns to newlines
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!tmp.IsEmpty()) {
|
|
|
|
if (tmp.CharAt(0) == '\r') {
|
2001-12-16 08:16:29 +00:00
|
|
|
tmp.Assign((PRUnichar)'\n');
|
2001-02-01 21:04:48 +00:00
|
|
|
}
|
|
|
|
rv = AddText(tmp);
|
1999-07-05 19:45:27 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2002-04-16 18:09:53 +00:00
|
|
|
default:
|
1998-04-22 23:24:43 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1999-01-09 00:14:53 +00:00
|
|
|
nsresult
|
2005-01-12 19:45:38 +00:00
|
|
|
SinkContext::AddLeaf(nsGenericHTMLElement* aContent)
|
1999-01-09 00:14:53 +00:00
|
|
|
{
|
1999-12-08 23:05:14 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0, "leaf w/o container");
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* parent = mStack[mStackPos - 1].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// If the parent has an insertion point, insert rather than append.
|
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(aContent,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2005-04-18 22:58:35 +00:00
|
|
|
PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(aContent, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
DidAddContent(aContent, PR_FALSE);
|
1999-01-09 00:14:53 +00:00
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-09 00:14:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-10 04:13:59 +00:00
|
|
|
|
1999-01-22 22:48:00 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::AddComment(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::AddLeaf",
|
|
|
|
nsHTMLTag(aNode.GetNodeType()),
|
|
|
|
mStackPos, mSink);
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
|
|
|
|
2003-01-11 02:42:36 +00:00
|
|
|
if (!mSink) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIContent> comment;
|
2005-09-24 18:43:15 +00:00
|
|
|
nsresult rv = NS_NewCommentNode(getter_AddRefs(comment),
|
|
|
|
mSink->mNodeInfoManager);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMComment> domComment(do_QueryInterface(comment));
|
|
|
|
NS_ENSURE_TRUE(domComment, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
domComment->AppendData(aNode.GetText());
|
|
|
|
|
2003-04-03 18:32:58 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0, "stack out of bounds");
|
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* parent;
|
2003-01-11 02:42:36 +00:00
|
|
|
if (!mSink->mBody && !mSink->mFrameset && mSink->mHead) {
|
2002-09-18 23:31:08 +00:00
|
|
|
parent = mSink->mHead;
|
|
|
|
} else {
|
|
|
|
parent = mStack[mStackPos - 1].mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the parent has an insertion point, insert rather than append.
|
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(comment,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2005-04-18 22:58:35 +00:00
|
|
|
PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(comment, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DidAddContent(comment, PR_FALSE);
|
1999-04-03 19:00:23 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->ForceReflow();
|
1999-01-22 22:48:00 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
1999-01-22 22:48:00 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::End()
|
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; i < mStackPos; i++) {
|
|
|
|
NS_RELEASE(mStack[i].mContent);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStackPos = 0;
|
|
|
|
mTextLength = 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()
|
|
|
|
{
|
|
|
|
PRInt32 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 (!stack) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
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-08-28 16:20:16 +00:00
|
|
|
/**
|
|
|
|
* Add textual content to the current running text buffer. If the text buffer
|
|
|
|
* overflows, flush out the text by creating a text content object and adding
|
|
|
|
* it to the content tree.
|
|
|
|
*/
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// XXX If we get a giant string grow the buffer instead of chopping it
|
|
|
|
// up???
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2002-03-23 23:13:20 +00:00
|
|
|
SinkContext::AddText(const nsAString& aText)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
PRInt32 addLen = aText.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (addLen == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
if (mSink->mInTitle) {
|
|
|
|
// Hang onto the title text specially.
|
|
|
|
mSink->mTitleString.Append(aText);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create buffer when we first need it
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mTextSize == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
mText = new PRUnichar[4096];
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mText) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = 4096;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up
|
|
|
|
PRInt32 offset = 0;
|
2001-07-05 22:20:34 +00:00
|
|
|
PRBool isLastCharCR = PR_FALSE;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
while (addLen != 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (amount > addLen) {
|
|
|
|
amount = addLen;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (amount == 0) {
|
1999-10-26 14:55:51 +00:00
|
|
|
// Don't release last text node so we can add to it again
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = FlushText();
|
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
|
|
|
|
|
|
|
mTextLength +=
|
|
|
|
nsContentUtils::CopyNewlineNormalizedUnicodeTo(aText, offset,
|
|
|
|
&mText[mTextLength],
|
|
|
|
amount, isLastCharCR);
|
1998-08-28 16:20:16 +00:00
|
|
|
offset += amount;
|
|
|
|
addLen -= amount;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
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
|
2000-01-28 23:43:12 +00:00
|
|
|
SinkContext::FlushTags(PRBool aNotify)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
// Don't release last text node in case we need to add to it again
|
1998-11-28 23:51:06 +00:00
|
|
|
FlushText();
|
1999-01-12 23:49:13 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
if (aNotify) {
|
|
|
|
// Start from the base of the stack (growing upward) and do
|
|
|
|
// a notification from the node that is closest to the root of
|
|
|
|
// tree for any content that has been added.
|
2005-04-07 03:30:50 +00:00
|
|
|
PRInt32 stackPos = 1;
|
2000-01-28 23:43:12 +00:00
|
|
|
PRBool flushed = PR_FALSE;
|
2005-04-07 03:30:50 +00:00
|
|
|
PRUint32 childCount;
|
|
|
|
nsGenericHTMLElement* content;
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
while (stackPos < mStackPos) {
|
|
|
|
content = mStack[stackPos].mContent;
|
2003-09-27 04:18:26 +00:00
|
|
|
childCount = content->GetChildCount();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) {
|
|
|
|
#ifdef NS_DEBUG
|
2003-11-19 01:20:56 +00:00
|
|
|
{
|
|
|
|
// Tracing code
|
|
|
|
const char* tagStr;
|
|
|
|
mStack[stackPos].mContent->Tag()->GetUTF8String(&tagStr);
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::FlushTags: tag=%s from newindex=%d at "
|
|
|
|
"stackPos=%d", tagStr,
|
|
|
|
mStack[stackPos].mNumFlushed, stackPos));
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
#endif
|
2000-01-28 23:43:12 +00:00
|
|
|
if ((mStack[stackPos].mInsertionPoint != -1) &&
|
2002-09-18 23:31:08 +00:00
|
|
|
(mStackPos > (stackPos + 1))) {
|
|
|
|
nsIContent* child = mStack[stackPos + 1].mContent;
|
|
|
|
mSink->NotifyInsert(content,
|
|
|
|
child,
|
|
|
|
mStack[stackPos].mInsertionPoint);
|
|
|
|
} else {
|
|
|
|
mSink->NotifyAppend(content, mStack[stackPos].mNumFlushed);
|
2000-01-28 23:43:12 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
flushed = PR_TRUE;
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
stackPos++;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2005-04-07 03:30:50 +00:00
|
|
|
return NS_OK;
|
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
|
|
|
|
// further reflows occur.
|
|
|
|
PRInt32 stackPos = mStackPos - 1;
|
1999-10-26 14:55:51 +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
|
|
|
/**
|
|
|
|
* Flush any buffered text out by creating a text content object and
|
|
|
|
* adding it to the content.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-10-26 14:55:51 +00:00
|
|
|
SinkContext::FlushText(PRBool* aDidFlush, PRBool aReleaseLast)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool didFlush = PR_FALSE;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mTextLength != 0) {
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mLastTextNode) {
|
2000-01-31 23:39:19 +00:00
|
|
|
if ((mLastTextNodeSize + mTextLength) > mSink->mMaxTextRun) {
|
|
|
|
mLastTextNodeSize = 0;
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = nsnull;
|
2000-01-31 23:39:19 +00:00
|
|
|
FlushText(aDidFlush, aReleaseLast);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-12-23 16:06:13 +00:00
|
|
|
nsCOMPtr<nsIDOMCharacterData> cdata(do_QueryInterface(mLastTextNode));
|
|
|
|
|
|
|
|
if (cdata) {
|
|
|
|
rv = cdata->AppendData(Substring(mText, mText + mTextLength));
|
|
|
|
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
|
|
|
didFlush = PR_TRUE;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2002-12-19 20:23:57 +00:00
|
|
|
nsCOMPtr<nsITextContent> textContent;
|
2005-09-24 18:43:15 +00:00
|
|
|
rv = NS_NewTextNode(getter_AddRefs(textContent),
|
|
|
|
mSink->mNodeInfoManager);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-03-31 09:51:02 +00:00
|
|
|
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = textContent;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Set the text in the text node
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode->SetText(mText, mTextLength, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// Eat up the rest of the text up in state.
|
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
1998-09-06 00:20:59 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Add text to its parent
|
|
|
|
NS_ASSERTION(mStackPos > 0, "leaf w/o container");
|
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-12-10 22:47:39 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* parent = mStack[mStackPos - 1].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
2002-12-19 20:23:57 +00:00
|
|
|
parent->InsertChildAt(mLastTextNode,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2005-04-18 22:58:35 +00:00
|
|
|
PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(mLastTextNode, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
didFlush = PR_TRUE;
|
|
|
|
|
2002-12-19 20:23:57 +00:00
|
|
|
DidAddContent(mLastTextNode, PR_FALSE);
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (aDidFlush) {
|
1998-08-28 16:20:16 +00:00
|
|
|
*aDidFlush = didFlush;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
2002-12-19 20:23:57 +00:00
|
|
|
if (aReleaseLast) {
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize = 0;
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = nsnull;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (didFlush &&
|
2002-09-18 23:31:08 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1998-04-13 20:24:54 +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);
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
nsRefPtr<HTMLContentSink> it = new HTMLContentSink();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (!it) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
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
|
|
|
#ifdef NS_DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!gSinkLogModuleInfo) {
|
1998-08-28 16:20:16 +00:00
|
|
|
gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mHead);
|
|
|
|
NS_IF_RELEASE(mBody);
|
|
|
|
NS_IF_RELEASE(mRoot);
|
1998-04-22 23:24:43 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->RemoveObserver(this);
|
|
|
|
}
|
1999-01-15 02:02:48 +00:00
|
|
|
NS_IF_RELEASE(mHTMLDocument);
|
1998-06-03 15:58:52 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mNotificationTimer) {
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
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);
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
for (PRInt32 i = 0; i < numContexts; i++) {
|
|
|
|
SinkContext* sc = (SinkContext*)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) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
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) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete mCurrentContext;
|
|
|
|
|
|
|
|
delete mHeadContext;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
#if DEBUG
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED5(HTMLContentSink,
|
|
|
|
nsContentSink,
|
|
|
|
nsIContentSink,
|
|
|
|
nsIHTMLContentSink,
|
|
|
|
nsITimerCallback,
|
|
|
|
nsIDocumentObserver,
|
|
|
|
nsIDebugDumpContent)
|
2001-10-16 05:31:36 +00:00
|
|
|
#else
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED4(HTMLContentSink,
|
|
|
|
nsContentSink,
|
|
|
|
nsIContentSink,
|
|
|
|
nsIHTMLContentSink,
|
|
|
|
nsITimerCallback,
|
|
|
|
nsIDocumentObserver)
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2001-06-20 01:04:24 +00:00
|
|
|
static PRBool
|
2003-04-02 11:18:00 +00:00
|
|
|
IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
|
2001-06-20 01:04:24 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aDoc && aContainer, PR_TRUE);
|
|
|
|
|
2006-02-02 20:02:34 +00:00
|
|
|
nsIPrincipal *principal = aDoc->GetNodePrincipal();
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(principal, PR_TRUE);
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject = aDoc->GetScriptGlobalObject();
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Getting context is tricky if the document hasn't had it's
|
|
|
|
// GlobalObject set yet
|
2001-06-20 01:04:24 +00:00
|
|
|
if (!globalObject) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> owner = do_GetInterface(aContainer);
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(owner, PR_TRUE);
|
|
|
|
|
2004-07-16 17:03:10 +00:00
|
|
|
globalObject = owner->GetScriptGlobalObject();
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptContext *scriptContext = globalObject->GetContext();
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
|
|
|
|
|
|
|
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
|
|
|
NS_ENSURE_TRUE(cx, PR_TRUE);
|
|
|
|
|
|
|
|
PRBool enabled = PR_TRUE;
|
2005-10-14 09:07:29 +00:00
|
|
|
nsContentUtils::GetSecurityManager()->CanExecuteScripts(cx, principal,
|
|
|
|
&enabled);
|
2001-06-20 01:04:24 +00:00
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Reset and start: nsHTMLContentSink::Init(), this=%p\n",
|
|
|
|
this));
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_RESET(mWatch);
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-09-14 14:38:52 +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)) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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);
|
2002-12-11 14:24:49 +00:00
|
|
|
CallQueryInterface(aDoc, &mHTMLDocument);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-09-28 23:08:17 +00:00
|
|
|
mObservers = nsnull;
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService* service = nsContentUtils::GetParserService();
|
2001-09-28 23:08:17 +00:00
|
|
|
if (!service) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-09-28 23:08:17 +00:00
|
|
|
service->GetTopicObservers(NS_LITERAL_STRING("text/html"),
|
|
|
|
getter_AddRefs(mObservers));
|
|
|
|
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(mDocShell, "oops no docshell!");
|
2003-04-02 11:18:00 +00:00
|
|
|
|
|
|
|
// Find out if subframes are enabled
|
|
|
|
if (mDocShell) {
|
|
|
|
PRBool subFramesEnabled = PR_TRUE;
|
|
|
|
mDocShell->GetAllowSubframes(&subFramesEnabled);
|
|
|
|
if (subFramesEnabled) {
|
2001-04-21 22:22:15 +00:00
|
|
|
mFlags |= NS_SINK_FLAG_FRAMES_ENABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-20 01:04:24 +00:00
|
|
|
// Find out if scripts are enabled, if not, show <noscript> content
|
2003-04-02 11:18:00 +00:00
|
|
|
if (IsScriptEnabled(aDoc, mDocShell)) {
|
2001-06-20 01:04:24 +00:00
|
|
|
mFlags |= NS_SINK_FLAG_SCRIPT_ENABLED;
|
|
|
|
}
|
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
mNotifyOnTimer =
|
|
|
|
nsContentUtils::GetBoolPref("content.notify.ontimer", PR_TRUE);
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
// -1 means never
|
|
|
|
mBackoffCount =
|
|
|
|
nsContentUtils::GetIntPref("content.notify.backoffcount", -1);
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// The mNotificationInterval has a dramatic effect on how long it
|
2001-03-23 14:16:05 +00:00
|
|
|
// takes to initially display content for slow connections.
|
2002-09-18 23:31:08 +00:00
|
|
|
// The current value provides good
|
2001-03-23 14:16:05 +00:00
|
|
|
// incremental display of content without causing an increase
|
|
|
|
// in page load time. If this value is set below 1/10 of second
|
|
|
|
// it starts to impact page load performance.
|
|
|
|
// see bugzilla bug 72138 for more info.
|
2004-04-29 23:34:19 +00:00
|
|
|
mNotificationInterval =
|
|
|
|
nsContentUtils::GetIntPref("content.notify.interval", 120000);
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
// The mMaxTokenProcessingTime controls how long we stay away from
|
2002-09-18 23:31:08 +00:00
|
|
|
// the event loop when processing token. A lower value makes the app
|
|
|
|
// more responsive, but may increase page load time. The content
|
|
|
|
// sink mNotificationInterval gates how frequently the content is
|
|
|
|
// processed so it will also affect how interactive the app is
|
|
|
|
// during page load also. The mNotification prevents contents
|
|
|
|
// flushes from happening too frequently. while
|
|
|
|
// mMaxTokenProcessingTime prevents flushes from happening too
|
|
|
|
// infrequently.
|
|
|
|
|
|
|
|
// The current ratio of 3 to 1 was determined to be the lowest
|
|
|
|
// mMaxTokenProcessingTime which does not impact page load
|
|
|
|
// performance. See bugzilla bug 76722 for details.
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
mMaxTokenProcessingTime =
|
|
|
|
nsContentUtils::GetIntPref("content.max.tokenizing.time",
|
|
|
|
mNotificationInterval * 3);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
// 3/4 second (750000us) default for switching
|
|
|
|
mDynamicIntervalSwitchThreshold =
|
|
|
|
nsContentUtils::GetIntPref("content.switch.threshold", 750000);
|
2001-06-29 04:01:26 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
if (nsContentUtils::GetBoolPref("content.interrupt.parsing", PR_TRUE)) {
|
2001-06-21 02:06:23 +00:00
|
|
|
mFlags |= NS_SINK_FLAG_CAN_INTERRUPT_PARSER;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Changed from 8192 to greatly improve page loading performance on
|
|
|
|
// large pages. See bugzilla bug 77540.
|
2004-04-29 23:34:19 +00:00
|
|
|
mMaxTextRun = nsContentUtils::GetIntPref("content.maxtextrun", 8191);
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,
|
|
|
|
kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-07-30 16:06:22 +00:00
|
|
|
// Make root part
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *doc_root = mDocument->GetRootContent();
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
if (doc_root) {
|
|
|
|
// If the document already has a root we'll use it. This will
|
|
|
|
// happen when we do document.open()/.write()/.close()...
|
|
|
|
|
2005-01-14 15:32:58 +00:00
|
|
|
NS_ADDREF(mRoot = NS_STATIC_CAST(nsGenericHTMLElement*, doc_root));
|
2001-04-12 09:50:55 +00:00
|
|
|
} else {
|
2004-06-06 02:38:32 +00:00
|
|
|
mRoot = NS_NewHTMLHtmlElement(nodeInfo);
|
|
|
|
if (!mRoot) {
|
2001-04-12 09:50:55 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2004-06-06 02:38:32 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-04-12 09:50:55 +00:00
|
|
|
}
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_ADDREF(mRoot);
|
2001-04-12 09:50:55 +00:00
|
|
|
|
2006-01-19 03:34:18 +00:00
|
|
|
NS_ASSERTION(mDocument->GetChildCount() == 0,
|
|
|
|
"Document should have no kids here!");
|
|
|
|
rv = mDocument->AppendChildTo(mRoot, PR_FALSE);
|
2005-04-15 01:30:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make head part
|
2004-01-18 10:22:22 +00:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::head,
|
2000-05-10 13:13:39 +00:00
|
|
|
nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-06-06 02:38:32 +00:00
|
|
|
mHead = NS_NewHTMLHeadElement(nodeInfo);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2004-06-06 02:38:32 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-30 16:06:22 +00:00
|
|
|
}
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_ADDREF(mHead);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-04-18 22:58:35 +00:00
|
|
|
mRoot->AppendChildTo(mHead, PR_FALSE);
|
1998-07-30 16:06:22 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = new SinkContext(this);
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(mCurrentContext, NS_ERROR_OUT_OF_MEMORY);
|
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);
|
|
|
|
|
2001-04-10 00:49:49 +00:00
|
|
|
#ifdef NS_DEBUG
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
2004-01-09 23:54:21 +00:00
|
|
|
(void)aURI->GetSpec(spec);
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::Init: this=%p url='%s'",
|
2002-03-06 07:48:55 +00:00
|
|
|
this, spec.get()));
|
2001-04-10 00:49:49 +00:00
|
|
|
#endif
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillBuildModel(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_CAN_INTERRUPT_PARSER) {
|
|
|
|
nsresult rv = AddDummyParserRequest();
|
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ERROR("Adding dummy parser request failed");
|
|
|
|
|
|
|
|
// Don't return the error result, just reset flag which
|
|
|
|
// indicates that it can interrupt parsing. If
|
|
|
|
// AddDummyParserRequests fails it should not affect
|
2001-06-21 02:06:23 +00:00
|
|
|
// WillBuildModel.
|
|
|
|
mFlags &= ~NS_SINK_FLAG_CAN_INTERRUPT_PARSER;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-30 01:58:38 +00:00
|
|
|
mBeginLoadTime = PR_IntervalToMicroseconds(PR_IntervalNow());
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-10-05 10:39:01 +00:00
|
|
|
mScrolledToRefAlready = PR_FALSE;
|
2001-12-07 21:53:39 +00:00
|
|
|
|
|
|
|
if (mHTMLDocument) {
|
2003-03-16 01:03:20 +00:00
|
|
|
NS_ASSERTION(mParser, "no parser");
|
2002-06-25 21:16:17 +00:00
|
|
|
nsCompatibility mode = eCompatibility_NavQuirks;
|
|
|
|
if (mParser) {
|
|
|
|
nsDTDMode dtdMode = mParser->GetParseMode();
|
|
|
|
switch (dtdMode) {
|
|
|
|
case eDTDMode_full_standards:
|
|
|
|
mode = eCompatibility_FullStandards;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
break;
|
|
|
|
case eDTDMode_almost_standards:
|
|
|
|
mode = eCompatibility_AlmostStandards;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = eCompatibility_NavQuirks;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2003-07-22 18:38:08 +00:00
|
|
|
HTMLContentSink::DidBuildModel(void)
|
1998-06-30 23:51:53 +00:00
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
// NRA Dump stopwatch stop info here
|
1999-10-19 22:27:20 +00:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
2002-09-18 23:31:08 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::DidBuildModel(), this=%p\n",
|
|
|
|
this));
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
MOZ_TIMER_LOG(("Content creation time (this=%p): ", this));
|
|
|
|
MOZ_TIMER_PRINT(mWatch);
|
1999-09-14 19:24:42 +00:00
|
|
|
#endif
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// Cancel a timer if we had one out there
|
|
|
|
if (mNotificationTimer) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::DidBuildModel: canceling notification "
|
|
|
|
"timeout"));
|
1999-12-04 01:27:46 +00:00
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
mNotificationTimer = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-12 02:47:53 +00:00
|
|
|
if (mDocument->GetDocumentTitle().IsVoid()) {
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> domDoc(do_QueryInterface(mDocument));
|
|
|
|
domDoc->SetTitle(EmptyString());
|
1998-08-10 17:39:48 +00:00
|
|
|
}
|
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
// Reflow the last batch of content
|
2005-10-20 02:12:20 +00:00
|
|
|
if (mBody || mFrameset) {
|
1999-04-03 19:00:23 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::DidBuildModel: layout final content"));
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
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.
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::DidBuildModel: forcing reflow on empty "
|
|
|
|
"document"));
|
2001-04-10 00:49:49 +00:00
|
|
|
|
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.
|
2001-12-07 00:02:03 +00:00
|
|
|
PRBool bDestroying = PR_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) {
|
|
|
|
StartLayout();
|
|
|
|
}
|
2001-04-10 00:49:49 +00:00
|
|
|
}
|
2000-10-18 20:37:54 +00:00
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
if (mDocShell) {
|
|
|
|
PRUint32 LoadType = 0;
|
|
|
|
mDocShell->GetLoadType(&LoadType);
|
2002-04-04 22:10:10 +00:00
|
|
|
|
2003-10-05 11:28:06 +00:00
|
|
|
if (ScrollToRef(!(LoadType & nsIDocShell::LOAD_CMD_HISTORY))) {
|
|
|
|
mScrolledToRefAlready = PR_TRUE;
|
|
|
|
}
|
2002-04-04 22:10:10 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIScriptLoader *loader = mDocument->GetScriptLoader();
|
2001-05-17 05:54:16 +00:00
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mDocument->EndLoad();
|
2000-09-19 22:35:50 +00:00
|
|
|
|
|
|
|
// Ref. Bug 49115
|
|
|
|
// Do this hack to make sure that the parser
|
2002-09-18 23:31:08 +00:00
|
|
|
// doesn't get destroyed, accidently, before
|
2000-09-19 22:35:50 +00:00
|
|
|
// the circularity, between sink & parser, is
|
2002-09-18 23:31:08 +00:00
|
|
|
// actually borken.
|
2000-09-19 22:35:50 +00:00
|
|
|
nsCOMPtr<nsIParser> kungFuDeathGrip(mParser);
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
// Drop our reference to the parser to get rid of a circular
|
|
|
|
// reference.
|
2003-12-24 13:43:25 +00:00
|
|
|
mParser = nsnull;
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2002-10-16 02:13:48 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE) {
|
|
|
|
// Reset the performance hint which was set to FALSE
|
|
|
|
// when NS_SINK_FLAG_DYNAMIC_LOWER_VALUE was set.
|
2002-10-16 03:07:37 +00:00
|
|
|
PL_FavorPerformanceHint(PR_TRUE , 0);
|
2002-10-16 02:13:48 +00:00
|
|
|
}
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_CAN_INTERRUPT_PARSER) {
|
|
|
|
// Note: Don't return value from RemoveDummyParserRequest,
|
|
|
|
// If RemoveDummyParserRequests fails it should not affect
|
|
|
|
// DidBuildModel. The remove can fail if the parser request
|
|
|
|
// was already removed by a DummyParserRequest::Cancel
|
|
|
|
RemoveDummyParserRequest();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 01:27:46 +00:00
|
|
|
HTMLContentSink::Notify(nsITimer *timer)
|
|
|
|
{
|
2000-04-05 04:02:38 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::Notify()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-05-13 01:39:29 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_PARSING) {
|
|
|
|
// We shouldn't interfere with our normal DidProcessAToken logic
|
|
|
|
mFlags |= NS_SINK_FLAG_DROPPED_TIMER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
#ifdef MOZ_DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
PRInt64 diff, interval;
|
|
|
|
PRInt32 delay;
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
LL_I2L(interval, GetNotificationInterval());
|
|
|
|
LL_SUB(diff, now, mLastNotificationTime);
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
LL_SUB(diff, diff, interval);
|
|
|
|
LL_L2I(delay, diff);
|
|
|
|
delay /= PR_USEC_PER_MSEC;
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
mBackoffCount--;
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::Notify: reflow on a timer: %d milliseconds "
|
|
|
|
"late, backoff count: %d", delay, mBackoffCount));
|
|
|
|
}
|
2000-04-05 04:02:38 +00:00
|
|
|
#endif
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
if (mCurrentContext) {
|
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
2001-10-05 10:39:01 +00:00
|
|
|
|
|
|
|
// Now try and scroll to the reference
|
2003-03-14 01:16:31 +00:00
|
|
|
// XXX Should we scroll unconditionally for history loads??
|
2001-10-05 10:39:01 +00:00
|
|
|
TryToScrollToRef();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
mNotificationTimer = 0;
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Notify()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-07 05:38:16 +00:00
|
|
|
return NS_OK;
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::WillInterrupt()
|
1998-06-27 22:57:52 +00:00
|
|
|
{
|
1999-12-04 01:27:46 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS, ("HTMLContentSink::WillInterrupt: this=%p",
|
|
|
|
this));
|
|
|
|
#ifndef SINK_NO_INCREMENTAL
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mNotifyOnTimer && mLayoutStarted) {
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mBackoffCount && !mInMonolithicContainer) {
|
2004-05-13 01:39:29 +00:00
|
|
|
nsInt64 now(PR_Now());
|
|
|
|
nsInt64 interval(GetNotificationInterval());
|
|
|
|
nsInt64 lastNotification(mLastNotificationTime);
|
|
|
|
nsInt64 diff(now - lastNotification);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// If it's already time for us to have a notification
|
2004-05-13 01:39:29 +00:00
|
|
|
if (diff > interval || (mFlags & NS_SINK_FLAG_DROPPED_TIMER)) {
|
1999-12-04 01:27:46 +00:00
|
|
|
mBackoffCount--;
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::WillInterrupt: flushing tags since we've "
|
|
|
|
"run out time; backoff count: %d", mBackoffCount));
|
2000-01-28 23:43:12 +00:00
|
|
|
result = mCurrentContext->FlushTags(PR_TRUE);
|
2004-05-13 01:39:29 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_DROPPED_TIMER) {
|
|
|
|
TryToScrollToRef();
|
|
|
|
mFlags &= ~NS_SINK_FLAG_DROPPED_TIMER;
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
2004-05-13 01:39:29 +00:00
|
|
|
} else if (!mNotificationTimer) {
|
|
|
|
interval -= diff;
|
|
|
|
PRInt32 delay = interval;
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// Convert to milliseconds
|
|
|
|
delay /= PR_USEC_PER_MSEC;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
mNotificationTimer = do_CreateInstance("@mozilla.org/timer;1",
|
|
|
|
&result);
|
1999-12-04 01:27:46 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::WillInterrupt: setting up timer with "
|
|
|
|
"delay %d", delay));
|
|
|
|
|
|
|
|
result =
|
|
|
|
mNotificationTimer->InitWithCallback(this, delay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2004-05-13 01:39:29 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
mNotificationTimer = nsnull;
|
|
|
|
}
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
1999-12-04 01:27:46 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::WillInterrupt: flushing tags "
|
|
|
|
"unconditionally"));
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
result = mCurrentContext->FlushTags(PR_TRUE);
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
#endif
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2004-05-13 01:39:29 +00:00
|
|
|
mFlags &= ~NS_SINK_FLAG_PARSING;
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
return result;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::WillResume()
|
1998-06-27 22:57:52 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS, ("HTMLContentSink::WillResume: this=%p", this));
|
|
|
|
|
2004-05-13 01:39:29 +00:00
|
|
|
mFlags |= NS_SINK_FLAG_PARSING;
|
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
|
|
|
|
HTMLContentSink::SetParser(nsIParser* aParser)
|
|
|
|
{
|
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-11 23:50:44 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::IsFormOnStack()
|
2002-04-11 23:50:44 +00:00
|
|
|
{
|
|
|
|
return mFlags & NS_SINK_FLAG_FORM_ON_STACK;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-15 20:18:34 +00:00
|
|
|
HTMLContentSink::BeginContext(PRInt32 aPosition)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::BeginContext()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_PRECONDITION(aPosition > -1, "out of bounds");
|
1998-07-30 16:06:22 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create new context
|
|
|
|
SinkContext* sc = new SinkContext(this);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!sc) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (!mCurrentContext) {
|
|
|
|
NS_ERROR("Non-existing context");
|
|
|
|
|
1999-12-09 03:10:22 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Flush everything in the current context so that we don't have
|
|
|
|
// to worry about insertions resulting in inconsistent frame creation.
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2005-04-04 21:20:00 +00:00
|
|
|
// Sanity check.
|
|
|
|
if (mCurrentContext->mStackPos <= aPosition) {
|
|
|
|
NS_ERROR("Out of bounds position");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 insertionPoint = -1;
|
1999-04-15 20:18:34 +00:00
|
|
|
nsHTMLTag nodeType = mCurrentContext->mStack[aPosition].mType;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content = mCurrentContext->mStack[aPosition].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the content under which the new context is created
|
|
|
|
// has a child on the stack, the insertion point is
|
|
|
|
// before the last child.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aPosition < (mCurrentContext->mStackPos - 1)) {
|
2003-09-27 04:18:26 +00:00
|
|
|
insertionPoint = content->GetChildCount() - 1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
sc->Begin(nodeType,
|
|
|
|
content,
|
|
|
|
mCurrentContext->mStack[aPosition].mNumFlushed,
|
|
|
|
insertionPoint);
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_ADDREF(sc->mSink);
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
mCurrentContext = sc;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-15 20:18:34 +00:00
|
|
|
HTMLContentSink::EndContext(PRInt32 aPosition)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::EndContext()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_PRECONDITION(mCurrentContext && aPosition > -1, "non-existing context");
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
PRInt32 n = mContextStack.Count() - 1;
|
1999-04-15 20:18:34 +00:00
|
|
|
SinkContext* sc = (SinkContext*) mContextStack.ElementAt(n);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ASSERTION(sc->mStack[aPosition].mType == mCurrentContext->mStack[0].mType,
|
|
|
|
"ending a wrong context");
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
|
|
|
|
|
|
|
sc->mStack[aPosition].mNumFlushed = mCurrentContext->mStack[0].mNumFlushed;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
for (PRInt32 i = 0; i<mCurrentContext->mStackPos; i++) {
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_IF_RELEASE(mCurrentContext->mStack[i].mContent);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
delete [] mCurrentContext->mStack;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
mCurrentContext->mStack = nsnull;
|
|
|
|
mCurrentContext->mStackPos = 0;
|
|
|
|
mCurrentContext->mStackSize = 0;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete [] mCurrentContext->mText;
|
|
|
|
|
|
|
|
mCurrentContext->mText = nsnull;
|
1999-04-15 20:18:34 +00:00
|
|
|
mCurrentContext->mTextLength = 0;
|
|
|
|
mCurrentContext->mTextSize = 0;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_IF_RELEASE(mCurrentContext->mSink);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
delete mCurrentContext;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = sc;
|
1999-04-15 20:18:34 +00:00
|
|
|
mContextStack.RemoveElementAt(n);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::EndContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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::CloseHTML()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseHTML()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseHTML",
|
|
|
|
eHTMLTag_html, 0, this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mHeadContext) {
|
|
|
|
if (mCurrentContext == mHeadContext) {
|
1999-12-10 03:36:50 +00:00
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
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
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext = (SinkContext*)mContextStack.ElementAt(--numContexts);
|
|
|
|
mContextStack.RemoveElementAt(numContexts);
|
1999-12-10 03:36:50 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-01-27 01:05:54 +00:00
|
|
|
NS_ASSERTION(mHeadContext->mTextLength == 0, "Losing text");
|
|
|
|
|
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;
|
|
|
|
mHeadContext = nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseHTML()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
2005-09-09 18:03:47 +00:00
|
|
|
HTMLContentSink::OpenHead()
|
|
|
|
{
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
|
|
|
|
|
|
|
nsresult rv = OpenHeadContext();
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::OpenBody(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::OpenBody",
|
|
|
|
eHTMLTag_body,
|
|
|
|
mCurrentContext->mStackPos,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
CloseHeadContext(); // do this just in case if the HEAD was left open!
|
|
|
|
|
|
|
|
// Add attributes, if any, to the current BODY node
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mBody) {
|
2003-07-31 14:07:17 +00:00
|
|
|
AddAttributes(aNode, mBody, PR_TRUE, PR_TRUE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-05 20:53:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_ADDREF(mBody);
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-06 05:44:31 +00:00
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
if (mCurrentContext->mStackPos > 1) {
|
2002-09-06 05:44:31 +00:00
|
|
|
PRInt32 parentIndex = mCurrentContext->mStackPos - 2;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement *parent = mCurrentContext->mStack[parentIndex].mContent;
|
2002-09-06 05:44:31 +00:00
|
|
|
PRInt32 numFlushed = mCurrentContext->mStack[parentIndex].mNumFlushed;
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 insertionPoint =
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
StartLayout();
|
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-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseBody()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-07-11 03:51:50 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseBody",
|
|
|
|
eHTMLTag_body,
|
|
|
|
mCurrentContext->mStackPos - 1,
|
|
|
|
this);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRBool didFlush;
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult rv = mCurrentContext->FlushTextAndRelease(&didFlush);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-29 19:07:24 +00:00
|
|
|
// Flush out anything that's left
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::CloseBody: layout final body content"));
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
2006-01-31 22:19:46 +00:00
|
|
|
mCurrentContext->CloseContainer(eHTMLTag_body, PR_FALSE);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-26 15:08:55 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::OpenForm(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenForm()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::OpenForm",
|
|
|
|
eHTMLTag_form,
|
|
|
|
mCurrentContext->mStackPos,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
// Close out previous form if it's there. If there is one
|
|
|
|
// around, it's probably because the last one wasn't well-formed.
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentForm = nsnull;
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
// Check if the parent is a table, tbody, thead, tfoot, tr, col or
|
1999-10-26 14:55:51 +00:00
|
|
|
// colgroup. If so, we fix up by making the form leaf content.
|
1999-07-22 23:28:16 +00:00
|
|
|
if (mCurrentContext->IsCurrentContainer(eHTMLTag_table) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_tbody) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_thead) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_tfoot) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_tr) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_col) ||
|
|
|
|
mCurrentContext->IsCurrentContainer(eHTMLTag_colgroup)) {
|
2005-10-21 15:39:06 +00:00
|
|
|
result = mCurrentContext->AddLeaf(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2002-04-11 23:50:44 +00:00
|
|
|
mFlags |= NS_SINK_FLAG_FORM_ON_STACK;
|
1999-07-22 23:28:16 +00:00
|
|
|
// Otherwise the form can be a content parent.
|
|
|
|
result = mCurrentContext->OpenContainer(aNode);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenForm()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return result;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-22 17:40:05 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseForm()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseForm()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseForm",
|
|
|
|
eHTMLTag_form,
|
|
|
|
mCurrentContext->mStackPos - 1,
|
|
|
|
this);
|
1999-07-22 23:28:16 +00:00
|
|
|
|
2002-05-09 00:29:23 +00:00
|
|
|
if (mCurrentForm) {
|
|
|
|
// if this is a well-formed form, close it too
|
2003-06-16 23:40:13 +00:00
|
|
|
if (mCurrentContext->IsCurrentContainer(eHTMLTag_form)) {
|
2006-01-31 22:19:46 +00:00
|
|
|
result = mCurrentContext->CloseContainer(eHTMLTag_form, PR_FALSE);
|
2002-04-11 23:50:44 +00:00
|
|
|
mFlags &= ~NS_SINK_FLAG_FORM_ON_STACK;
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
mCurrentForm = nsnull;
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseForm()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return result;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::OpenFrameset(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenFrameset()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::OpenFrameset",
|
|
|
|
eHTMLTag_frameset,
|
|
|
|
mCurrentContext->mStackPos,
|
|
|
|
this);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
CloseHeadContext(); // do this just in case if the HEAD was left open!
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-04-04 22:37:23 +00:00
|
|
|
// Need to keep track of whether OpenContainer changes mFrameset
|
|
|
|
nsGenericHTMLElement* oldFrameset = mFrameset;
|
2003-01-09 18:29:23 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
2006-04-04 22:37:23 +00:00
|
|
|
PRBool isFirstFrameset = NS_SUCCEEDED(rv) && mFrameset != oldFrameset;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenFrameset()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-10-20 02:12:20 +00:00
|
|
|
if (isFirstFrameset && mCurrentContext->mStackPos > 1) {
|
|
|
|
NS_ASSERTION(mFrameset, "Must have frameset!");
|
2005-10-14 21:48:33 +00:00
|
|
|
// Have to notify for the frameset now, since we never actually
|
|
|
|
// close out <html>, so won't notify for it then.
|
|
|
|
PRInt32 parentIndex = mCurrentContext->mStackPos - 2;
|
|
|
|
nsGenericHTMLElement *parent = mCurrentContext->mStack[parentIndex].mContent;
|
|
|
|
PRInt32 numFlushed = mCurrentContext->mStack[parentIndex].mNumFlushed;
|
|
|
|
PRInt32 insertionPoint =
|
|
|
|
mCurrentContext->mStack[parentIndex].mInsertionPoint;
|
|
|
|
|
|
|
|
// XXX: I have yet to see a case where numFlushed is non-zero and
|
|
|
|
// insertionPoint is not -1, but this code will try to handle
|
|
|
|
// those cases too.
|
|
|
|
|
|
|
|
if (insertionPoint != -1) {
|
|
|
|
NotifyInsert(parent, mFrameset, insertionPoint - 1);
|
|
|
|
} else {
|
|
|
|
NotifyAppend(parent, numFlushed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
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::CloseFrameset()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseFrameset()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseFrameset",
|
|
|
|
eHTMLTag_frameset,
|
|
|
|
mCurrentContext->mStackPos - 1,
|
|
|
|
this);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
SinkContext* sc = mCurrentContext;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* fs = sc->mStack[sc->mStackPos - 1].mContent;
|
1998-08-28 16:20:16 +00:00
|
|
|
PRBool done = fs == mFrameset;
|
2005-10-20 02:12:20 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (done) {
|
|
|
|
PRBool didFlush;
|
|
|
|
rv = sc->FlushTextAndRelease(&didFlush);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseFrameset()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush out anything that's left
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::CloseFrameset: layout final content"));
|
|
|
|
|
|
|
|
sc->FlushTags(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:19:46 +00:00
|
|
|
rv = sc->CloseContainer(eHTMLTag_frameset, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseFrameset()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2001-04-21 22:22:15 +00:00
|
|
|
|
|
|
|
if (done && (mFlags & NS_SINK_FLAG_FRAMES_ENABLED)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
StartLayout();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-09-01 18:17:43 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-16 20:24:03 +00:00
|
|
|
HTMLContentSink::IsEnabled(PRInt32 aTag, PRBool* aReturn)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
2001-04-21 22:22:15 +00:00
|
|
|
nsHTMLTag theHTMLTag = nsHTMLTag(aTag);
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2001-04-21 22:22:15 +00:00
|
|
|
if (theHTMLTag == eHTMLTag_script) {
|
2003-01-16 20:24:03 +00:00
|
|
|
*aReturn = mFlags & NS_SINK_FLAG_SCRIPT_ENABLED ? PR_TRUE : PR_FALSE;
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (theHTMLTag == eHTMLTag_frameset) {
|
2003-01-16 20:24:03 +00:00
|
|
|
*aReturn = mFlags & NS_SINK_FLAG_FRAMES_ENABLED ? PR_TRUE : PR_FALSE;
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2003-01-16 20:24:03 +00:00
|
|
|
*aReturn = PR_FALSE;
|
2000-09-01 18:17:43 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-04-21 22:22:15 +00:00
|
|
|
return NS_OK;
|
2000-09-01 18:17:43 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenContainer(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenContainer()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_frameset:
|
|
|
|
rv = OpenFrameset(aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_head:
|
|
|
|
rv = OpenHeadContext();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-01-27 01:13:00 +00:00
|
|
|
rv = AddAttributes(aNode, mHead, PR_FALSE, mHaveSeenHead);
|
|
|
|
mHaveSeenHead = PR_TRUE;
|
2005-10-21 15:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eHTMLTag_body:
|
|
|
|
rv = OpenBody(aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_html:
|
|
|
|
if (mRoot) {
|
2006-01-27 01:13:00 +00:00
|
|
|
// If we've already hit this code once, need to check for
|
|
|
|
// already-present attributes on the root.
|
|
|
|
AddAttributes(aNode, mRoot, PR_TRUE, mNotifiedRootInsertion);
|
2006-01-12 17:11:57 +00:00
|
|
|
if (!mNotifiedRootInsertion) {
|
|
|
|
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.
|
|
|
|
mNotifiedRootInsertion = PR_TRUE;
|
|
|
|
PRInt32 index = mDocument->IndexOf(mRoot);
|
|
|
|
NS_ASSERTION(index != -1, "mRoot not child of document?");
|
|
|
|
NotifyInsert(nsnull, mRoot, index);
|
|
|
|
|
|
|
|
}
|
2005-10-21 15:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eHTMLTag_form:
|
|
|
|
rv = OpenForm(aNode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseContainer(const eHTMLTags aTag)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +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) {
|
|
|
|
case eHTMLTag_frameset:
|
|
|
|
rv = CloseFrameset();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_head:
|
|
|
|
CloseHeadContext();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_body:
|
|
|
|
rv = CloseBody();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_html:
|
|
|
|
rv = CloseHTML();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_form:
|
|
|
|
rv = CloseForm();
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-31 22:19:46 +00:00
|
|
|
rv = mCurrentContext->CloseContainer(aTag, PR_FALSE);
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
2006-01-31 22:19:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::CloseMalformedContainer(const eHTMLTags aTag)
|
|
|
|
{
|
|
|
|
return mCurrentContext->CloseContainer(aTag, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::AddLeaf(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddLeaf()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
1998-07-12 00:18:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
|
|
|
switch (nodeType) {
|
|
|
|
case eHTMLTag_link:
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1998-08-28 16:20:16 +00:00
|
|
|
rv = ProcessLINKTag(aNode);
|
1998-07-12 00:18:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
default:
|
|
|
|
rv = mCurrentContext->AddLeaf(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1998-07-22 23:42:47 +00:00
|
|
|
}
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddLeaf()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
1998-07-12 00:18:26 +00:00
|
|
|
}
|
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult
|
2005-09-09 18:03:47 +00:00
|
|
|
HTMLContentSink::UpdateDocumentTitle()
|
2003-01-03 23:17:22 +00:00
|
|
|
{
|
2005-09-09 18:03:47 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::UpdateDocumentTitle()\n"));
|
2003-01-03 23:17:22 +00:00
|
|
|
MOZ_TIMER_START(mWatch);
|
|
|
|
NS_ASSERTION(mCurrentContext == mHeadContext, "title not in head");
|
|
|
|
|
2005-01-12 02:47:53 +00:00
|
|
|
if (!mDocument->GetDocumentTitle().IsVoid()) {
|
2005-09-09 18:03:47 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::UpdateDocumentTitle()\n"));
|
2003-01-03 23:17:22 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
// Use mTitleString.
|
|
|
|
mTitleString.CompressWhitespace(PR_TRUE, PR_TRUE);
|
2003-01-03 23:17:22 +00:00
|
|
|
|
2005-01-12 02:47:53 +00:00
|
|
|
nsCOMPtr<nsIDOMNSDocument> domDoc(do_QueryInterface(mDocument));
|
2005-09-09 18:03:47 +00:00
|
|
|
domDoc->SetTitle(mTitleString);
|
2003-01-03 23:17:22 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
mTitleString.Truncate();
|
2003-01-03 23:17:22 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::UpdateDocumentTitle()\n"));
|
2003-01-03 23:17:22 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-10 04:13:59 +00:00
|
|
|
/**
|
|
|
|
* This gets called by the parsing system when we find a comment
|
|
|
|
* @update gess11/9/98
|
|
|
|
* @param aNode contains a comment token
|
|
|
|
* @return error code
|
|
|
|
*/
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddComment(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddComment()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsresult rv = mCurrentContext->AddComment(aNode);
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddComment()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1998-11-10 04:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This gets called by the parsing system when we find a PI
|
|
|
|
* @update gess11/9/98
|
|
|
|
* @param aNode contains a comment token
|
|
|
|
* @return error code
|
|
|
|
*/
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
// Implementation of AddProcessingInstruction() should start here
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-11-10 04:13:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-26 05:40:25 +00:00
|
|
|
/**
|
|
|
|
* This gets called by the parser when it encounters
|
|
|
|
* a DOCTYPE declaration in the HTML document.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-06-25 21:16:17 +00:00
|
|
|
HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode)
|
1999-07-26 05:40:25 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsAutoString docTypeStr(aNode.GetText());
|
|
|
|
nsresult rv = NS_OK;
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
PRInt32 publicStart = docTypeStr.Find("PUBLIC", PR_TRUE);
|
|
|
|
PRInt32 systemStart = docTypeStr.Find("SYSTEM", PR_TRUE);
|
|
|
|
nsAutoString name, publicId, systemId;
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
if (publicStart >= 0 || systemStart >= 0) {
|
2000-03-28 23:25:26 +00:00
|
|
|
/*
|
2000-06-14 23:08:19 +00:00
|
|
|
* If we find the keyword 'PUBLIC' after the keyword 'SYSTEM' we assume
|
|
|
|
* that we got a system id that happens to contain the string "PUBLIC"
|
|
|
|
* and we ignore that as the start of the public id.
|
2000-03-28 23:25:26 +00:00
|
|
|
*/
|
2002-09-18 23:31:08 +00:00
|
|
|
if (systemStart >= 0 && (publicStart > systemStart)) {
|
2000-06-14 23:08:19 +00:00
|
|
|
publicStart = -1;
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
|
|
|
/*
|
2000-06-14 23:08:19 +00:00
|
|
|
* We found 'PUBLIC' or 'SYSTEM' in the doctype, put everything before
|
|
|
|
* the first one of those in name.
|
2000-03-28 23:25:26 +00:00
|
|
|
*/
|
2000-06-14 23:08:19 +00:00
|
|
|
docTypeStr.Mid(name, 0, publicStart >= 0 ? publicStart : systemStart);
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
if (publicStart >= 0) {
|
|
|
|
// We did find 'PUBLIC'
|
|
|
|
docTypeStr.Mid(publicId, publicStart + 6,
|
|
|
|
docTypeStr.Length() - publicStart);
|
|
|
|
publicId.Trim(" \t\n\r");
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
// Strip quotes
|
2002-01-24 02:03:19 +00:00
|
|
|
PRUnichar ch = publicId.IsEmpty() ? '\0' : publicId.First();
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2002-05-09 14:41:51 +00:00
|
|
|
PRBool hasQuote = PR_FALSE;
|
2000-06-14 23:08:19 +00:00
|
|
|
if (ch == '"' || ch == '\'') {
|
|
|
|
publicId.Cut(0, 1);
|
|
|
|
|
|
|
|
PRInt32 end = publicId.FindChar(ch);
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
if (end < 0) {
|
|
|
|
/*
|
2002-09-18 23:31:08 +00:00
|
|
|
* We didn't find an end quote, so just make sure we cut off
|
2000-06-14 23:08:19 +00:00
|
|
|
* the '>' on the end of the doctype declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
end = publicId.FindChar('>');
|
2002-05-09 14:41:51 +00:00
|
|
|
} else {
|
|
|
|
hasQuote = PR_TRUE;
|
2000-06-14 23:08:19 +00:00
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
|
|
|
/*
|
2002-09-18 23:31:08 +00:00
|
|
|
* If we didn't find a closing quote or a '>' we leave publicId as
|
2000-06-14 23:08:19 +00:00
|
|
|
* it is.
|
2000-03-28 23:25:26 +00:00
|
|
|
*/
|
2000-06-14 23:08:19 +00:00
|
|
|
if (end >= 0) {
|
|
|
|
publicId.Truncate(end);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No quotes, ignore the public id
|
|
|
|
publicId.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the 'SYSTEM' word we found is not inside the pubilc id
|
|
|
|
*/
|
|
|
|
PRInt32 pos = docTypeStr.Find(publicId);
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
if (systemStart > 0) {
|
|
|
|
if (systemStart < pos + (PRInt32)publicId.Length()) {
|
|
|
|
systemStart = docTypeStr.Find("SYSTEM", PR_TRUE,
|
|
|
|
pos + publicId.Length());
|
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-07-14 07:37:39 +00:00
|
|
|
* If we didn't find 'SYSTEM' we treat everything after the public id
|
2000-06-14 23:08:19 +00:00
|
|
|
* as the system id.
|
2000-03-28 23:25:26 +00:00
|
|
|
*/
|
2000-06-14 23:08:19 +00:00
|
|
|
if (systemStart < 0) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// 1 is the end quote
|
|
|
|
systemStart = pos + publicId.Length() + (hasQuote ? 1 : 0);
|
2000-06-14 23:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (systemStart >= 0) {
|
|
|
|
// We either found 'SYSTEM' or we have data after the public id
|
|
|
|
docTypeStr.Mid(systemId, systemStart,
|
|
|
|
docTypeStr.Length() - systemStart);
|
|
|
|
|
|
|
|
// Strip off 'SYSTEM' if we have it.
|
2003-07-14 07:37:39 +00:00
|
|
|
if (StringBeginsWith(systemId, NS_LITERAL_STRING("SYSTEM")))
|
2000-06-14 23:08:19 +00:00
|
|
|
systemId.Cut(0, 6);
|
|
|
|
|
|
|
|
systemId.Trim(" \t\n\r");
|
|
|
|
|
|
|
|
// Strip quotes
|
2002-01-24 02:03:19 +00:00
|
|
|
PRUnichar ch = systemId.IsEmpty() ? '\0' : systemId.First();
|
2000-06-14 23:08:19 +00:00
|
|
|
|
|
|
|
if (ch == '"' || ch == '\'') {
|
|
|
|
systemId.Cut(0, 1);
|
|
|
|
|
|
|
|
PRInt32 end = systemId.FindChar(ch);
|
|
|
|
|
|
|
|
if (end < 0) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// We didn't find an end quote, then we just make sure we
|
|
|
|
// cut of the '>' on the end of the doctype declaration
|
2000-06-14 23:08:19 +00:00
|
|
|
|
|
|
|
end = systemId.FindChar('>');
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// If we found an closing quote nor a '>' we truncate systemId
|
|
|
|
// at that length.
|
2000-06-14 23:08:19 +00:00
|
|
|
if (end >= 0) {
|
|
|
|
systemId.Truncate(end);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
systemId.Truncate();
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2000-04-15 20:15:37 +00:00
|
|
|
name.Assign(docTypeStr);
|
2000-06-14 23:08:19 +00:00
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Cut out "<!DOCTYPE" or "DOCTYPE" from the name.
|
2003-07-14 07:37:39 +00:00
|
|
|
if (StringBeginsWith(name, NS_LITERAL_STRING("<!DOCTYPE"), nsCaseInsensitiveStringComparator())) {
|
2000-06-14 23:08:19 +00:00
|
|
|
name.Cut(0, 9);
|
2003-07-14 07:37:39 +00:00
|
|
|
} else if (StringBeginsWith(name, NS_LITERAL_STRING("DOCTYPE"), nsCaseInsensitiveStringComparator())) {
|
2000-06-14 23:08:19 +00:00
|
|
|
name.Cut(0, 7);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
name.Trim(" \t\n\r");
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Check if name contains whitespace chars. If it does and the first
|
|
|
|
// char is not a quote, we set the name to contain the characters
|
|
|
|
// before the whitespace
|
2000-06-14 23:08:19 +00:00
|
|
|
PRInt32 nameEnd = 0;
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-06-21 01:13:10 +00:00
|
|
|
if (name.IsEmpty() || (name.First() != '"' && name.First() != '\'')) {
|
2000-06-14 23:08:19 +00:00
|
|
|
nameEnd = name.FindCharInSet(" \n\r\t");
|
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// If we didn't find a public id we grab everything after the name
|
|
|
|
// and use that as public id.
|
2000-06-14 23:08:19 +00:00
|
|
|
if (publicStart < 0) {
|
|
|
|
name.Mid(publicId, nameEnd, name.Length() - nameEnd);
|
|
|
|
publicId.Trim(" \t\n\r");
|
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
PRUnichar ch = publicId.IsEmpty() ? '\0' : publicId.First();
|
2000-06-14 23:08:19 +00:00
|
|
|
|
|
|
|
if (ch == '"' || ch == '\'') {
|
|
|
|
publicId.Cut(0, 1);
|
|
|
|
|
|
|
|
PRInt32 publicEnd = publicId.FindChar(ch);
|
|
|
|
|
|
|
|
if (publicEnd < 0) {
|
|
|
|
publicEnd = publicId.FindChar('>');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (publicEnd < 0) {
|
|
|
|
publicEnd = publicId.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
publicId.Truncate(publicEnd);
|
|
|
|
} else {
|
2002-09-18 23:31:08 +00:00
|
|
|
// No quotes, no public id
|
|
|
|
publicId.Truncate();
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (nameEnd >= 0) {
|
2000-06-14 23:08:19 +00:00
|
|
|
name.Truncate(nameEnd);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2000-06-14 23:08:19 +00:00
|
|
|
nameEnd = name.FindChar('>');
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (nameEnd >= 0) {
|
2000-06-14 23:08:19 +00:00
|
|
|
name.Truncate(nameEnd);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2000-06-14 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!publicId.IsEmpty() || !systemId.IsEmpty() || !name.IsEmpty()) {
|
2000-03-28 23:25:26 +00:00
|
|
|
nsCOMPtr<nsIDOMDocumentType> oldDocType;
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
|
2006-01-19 03:34:18 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mHTMLDocument));
|
2000-03-28 23:25:26 +00:00
|
|
|
doc->GetDoctype(getter_AddRefs(oldDocType));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDOMImplementation> domImpl;
|
|
|
|
|
|
|
|
rv = doc->GetImplementation(getter_AddRefs(domImpl));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !domImpl) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (name.IsEmpty()) {
|
2004-06-17 00:13:25 +00:00
|
|
|
name.AssignLiteral("HTML");
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
|
2000-06-14 23:08:19 +00:00
|
|
|
rv = domImpl->CreateDocumentType(name, publicId, systemId,
|
2000-03-28 23:25:26 +00:00
|
|
|
getter_AddRefs(docType));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldDocType) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// If we already have a doctype we replace the old one.
|
2006-01-19 03:34:18 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> tmpNode;
|
2000-03-28 23:25:26 +00:00
|
|
|
rv = doc->ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
|
|
|
|
} else {
|
2002-09-18 23:31:08 +00:00
|
|
|
// If we don't already have one we insert it as the first child,
|
|
|
|
// this might not be 100% correct but since this is called from
|
|
|
|
// the content sink we assume that this is what we want.
|
2006-01-19 03:34:18 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(docType);
|
|
|
|
NS_ASSERTION(content, "Doctype isn't content?");
|
|
|
|
|
|
|
|
mDocument->InsertChildAt(content, 0, PR_TRUE);
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1999-07-26 05:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::WillProcessTokens(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_CAN_INTERRUPT_PARSER) {
|
2001-06-29 04:01:26 +00:00
|
|
|
mDelayTimerStart = PR_IntervalToMicroseconds(PR_IntervalNow());
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::DidProcessTokens(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::WillProcessAToken(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::DidProcessAToken(void)
|
|
|
|
{
|
2001-06-29 04:01:26 +00:00
|
|
|
if (mFlags & NS_SINK_FLAG_CAN_INTERRUPT_PARSER) {
|
2002-04-17 04:17:16 +00:00
|
|
|
// There is both a high frequency interrupt mode and a low
|
|
|
|
// frequency interupt mode controlled by the flag
|
|
|
|
// NS_SINK_FLAG_DYNAMIC_LOWER_VALUE The high frequency mode
|
|
|
|
// interupts the parser frequently to provide UI responsiveness at
|
|
|
|
// the expense of page load time. The low frequency mode
|
|
|
|
// interrupts the parser and samples the system clock infrequently
|
|
|
|
// to provide fast page load time. When the user moves the mouse,
|
|
|
|
// clicks or types the mode switches to the high frequency
|
|
|
|
// interrupt mode. If the user stops moving the mouse or typing
|
|
|
|
// for a duration of time (mDynamicIntervalSwitchThreshold) it
|
|
|
|
// switches to low frequency interrupt mode.
|
2002-03-06 01:00:48 +00:00
|
|
|
|
|
|
|
// Get the current user event time
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(0);
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
if (!shell) {
|
|
|
|
// If there's no pres shell in the document, return early since
|
|
|
|
// we're not laying anything out here.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
2002-03-06 01:00:48 +00:00
|
|
|
NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
|
|
|
|
PRUint32 eventTime;
|
2002-10-01 03:04:22 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
nsresult rv = vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
if (!widget || NS_FAILED(widget->GetLastInputEventTime(eventTime))) {
|
|
|
|
// If we can't get the last input time from the widget
|
|
|
|
// then we will get it from the viewmanager.
|
|
|
|
rv = vm->GetLastUserEventTime(eventTime);
|
2004-05-25 06:09:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv , NS_ERROR_FAILURE);
|
2002-10-01 03:04:22 +00:00
|
|
|
}
|
|
|
|
|
2004-05-25 06:09:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if ((!(mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE)) &&
|
2002-03-06 01:00:48 +00:00
|
|
|
(mLastSampledUserEventTime == eventTime)) {
|
2002-04-17 04:17:16 +00:00
|
|
|
// The magic value of NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE
|
|
|
|
// was selected by empirical testing. It provides reasonable
|
|
|
|
// user response and prevents us from sampling the clock too
|
|
|
|
// frequently.
|
2002-03-06 01:00:48 +00:00
|
|
|
if (mDeflectedCount < NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE) {
|
|
|
|
mDeflectedCount++;
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
// return early to prevent sampling the clock. Note: This
|
|
|
|
// prevents us from switching to higher frequency (better UI
|
|
|
|
// responsive) mode, so limit ourselves to doing for no more
|
|
|
|
// than NS_MAX_TOKENS_DEFLECTED_IN_LOW_FREQ_MODE tokens.
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-03-06 01:00:48 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// reset count and drop through to the code which samples the
|
|
|
|
// clock and does the dynamic switch between the high
|
|
|
|
// frequency and low frequency interruption of the parser.
|
|
|
|
|
|
|
|
mDeflectedCount = 0;
|
2002-03-06 01:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mLastSampledUserEventTime = eventTime;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 04:01:26 +00:00
|
|
|
PRUint32 currentTime = PR_IntervalToMicroseconds(PR_IntervalNow());
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
// Get the last user event time and compare it with the current
|
|
|
|
// time to determine if the lower value for content notification
|
|
|
|
// and max token processing should be used. But only consider
|
|
|
|
// using the lower value if the document has already been loading
|
|
|
|
// for 2 seconds. 2 seconds was chosen because it is greater than
|
|
|
|
// the default 3/4 of second that is used to determine when to
|
|
|
|
// switch between the modes and it gives the document a little
|
|
|
|
// time to create windows. This is important because on some
|
|
|
|
// systems (Windows, for example) when a window is created and the
|
|
|
|
// mouse is over it, a mouse move event is sent, which will kick
|
2005-11-25 08:16:51 +00:00
|
|
|
// us into interactive mode otherwise. It also suppresses reaction
|
2002-04-17 04:17:16 +00:00
|
|
|
// to pressing the ENTER key in the URL bar...
|
2001-06-30 01:58:38 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRUint32 delayBeforeLoweringThreshold =
|
|
|
|
NS_STATIC_CAST(PRUint32, ((2 * mDynamicIntervalSwitchThreshold) +
|
|
|
|
NS_DELAY_FOR_WINDOW_CREATION));
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
if ((currentTime - mBeginLoadTime) > delayBeforeLoweringThreshold) {
|
|
|
|
if ((currentTime - eventTime) <
|
|
|
|
NS_STATIC_CAST(PRUint32, mDynamicIntervalSwitchThreshold)) {
|
2002-10-16 02:13:48 +00:00
|
|
|
|
|
|
|
if (! (mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE)) {
|
|
|
|
// lower the dynamic values to favor application
|
|
|
|
// responsiveness over page load time.
|
|
|
|
mFlags |= NS_SINK_FLAG_DYNAMIC_LOWER_VALUE;
|
|
|
|
// Set the performance hint to prevent event starvation when
|
|
|
|
// dispatching PLEvents. This improves application responsiveness
|
|
|
|
// during page loads.
|
2002-10-16 02:50:06 +00:00
|
|
|
PL_FavorPerformanceHint(PR_FALSE, 0);
|
2002-10-16 02:13:48 +00:00
|
|
|
}
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
} else {
|
2002-10-16 02:13:48 +00:00
|
|
|
|
|
|
|
if (mFlags & NS_SINK_FLAG_DYNAMIC_LOWER_VALUE) {
|
|
|
|
// raise the content notification and MaxTokenProcessing time
|
|
|
|
// to favor overall page load speed over responsiveness.
|
|
|
|
mFlags &= ~NS_SINK_FLAG_DYNAMIC_LOWER_VALUE;
|
|
|
|
// Reset the hint that to favoring performance for PLEvent dispatch.
|
2002-10-16 02:50:06 +00:00
|
|
|
PL_FavorPerformanceHint(PR_TRUE, 0);
|
2002-10-16 02:13:48 +00:00
|
|
|
}
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2001-06-29 04:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
if ((currentTime - mDelayTimerStart) >
|
|
|
|
NS_STATIC_CAST(PRUint32, GetMaxTokenProcessingTime())) {
|
|
|
|
return NS_ERROR_HTMLPARSER_INTERRUPTED;
|
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-28 23:08:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::NotifyTagObservers(nsIParserNode* aNode)
|
|
|
|
{
|
2002-04-18 22:11:17 +00:00
|
|
|
// Bug 125317
|
2002-09-18 23:31:08 +00:00
|
|
|
// Inform observers that we're handling a document.write().
|
2002-04-18 22:11:17 +00:00
|
|
|
// This information is necessary for the charset observer, atleast,
|
|
|
|
// to make a decision whether a new charset loading is required or not.
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (!mObservers) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 flag = 0;
|
|
|
|
|
|
|
|
if (mHTMLDocument && mHTMLDocument->IsWriting()) {
|
|
|
|
flag = nsIElementObserver::IS_DOCUMENT_WRITE;
|
|
|
|
}
|
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
return mObservers->Notify(aNode, mParser, mDocShell, flag);
|
2001-09-28 23:08:17 +00:00
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::StartLayout()
|
1998-07-12 00:18:26 +00:00
|
|
|
{
|
1998-09-12 19:33:48 +00:00
|
|
|
if (mLayoutStarted) {
|
|
|
|
return;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-09-12 19:33:48 +00:00
|
|
|
mLayoutStarted = PR_TRUE;
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
mLastNotificationTime = PR_Now();
|
|
|
|
|
2004-09-04 19:51:21 +00:00
|
|
|
mHTMLDocument->SetIsFrameset(mFrameset != nsnull);
|
1998-12-20 23:29:47 +00:00
|
|
|
|
2004-09-04 19:51:21 +00:00
|
|
|
nsContentSink::StartLayout(mFrameset != nsnull);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2001-10-05 10:39:01 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::TryToScrollToRef()
|
|
|
|
{
|
|
|
|
if (mRef.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mScrolledToRefAlready) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-05 11:28:06 +00:00
|
|
|
if (ScrollToRef(PR_TRUE)) {
|
|
|
|
mScrolledToRefAlready = PR_TRUE;
|
1998-04-22 22:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-24 18:20:27 +00:00
|
|
|
void
|
2004-06-25 12:26:02 +00:00
|
|
|
HTMLContentSink::AddBaseTagInfo(nsIContent* aContent)
|
1998-07-24 18:20:27 +00:00
|
|
|
{
|
2006-02-01 04:43:55 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (mBaseHref) {
|
|
|
|
rv = aContent->SetProperty(nsHTMLAtoms::htmlBaseHref, mBaseHref,
|
|
|
|
nsPropertyTable::SupportsDtorFunc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// circumvent nsDerivedSafe
|
|
|
|
NS_ADDREF(NS_STATIC_CAST(nsIURI*, mBaseHref));
|
|
|
|
}
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
2006-02-01 04:43:55 +00:00
|
|
|
if (mBaseTarget) {
|
|
|
|
rv = aContent->SetProperty(nsHTMLAtoms::htmlBaseTarget, mBaseTarget,
|
|
|
|
nsPropertyTable::SupportsDtorFunc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// circumvent nsDerivedSafe
|
|
|
|
NS_ADDREF(NS_STATIC_CAST(nsIAtom*, mBaseTarget));
|
|
|
|
}
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::OpenHeadContext()
|
|
|
|
{
|
2003-01-09 18:29:23 +00:00
|
|
|
if (mCurrentContext && mCurrentContext->IsCurrentContainer(eHTMLTag_head))
|
|
|
|
return NS_OK;
|
2003-01-03 23:17:22 +00:00
|
|
|
|
|
|
|
// Flush everything in the current context so that we don't have
|
|
|
|
// to worry about insertions resulting in inconsistent frame creation.
|
|
|
|
//
|
|
|
|
// Try to do this only if needed (costly), i.e., only if we are sure
|
|
|
|
// we are changing contexts from some other context to the head.
|
|
|
|
//
|
|
|
|
// PERF: This call causes approximately a 2% slowdown in page load time
|
|
|
|
// according to jrgm's page load tests, but seems to be a necessary evil
|
|
|
|
if (mCurrentContext && (mCurrentContext != mHeadContext)) {
|
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHeadContext) {
|
|
|
|
mHeadContext = new SinkContext(this);
|
|
|
|
NS_ENSURE_TRUE(mHeadContext, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
nsresult rv = mHeadContext->Begin(eHTMLTag_head, mHead, 0, -1);
|
2003-01-03 23:17:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
mCurrentContext = mHeadContext;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-01-27 01:05:54 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mContextStack.Count() > 0, "Stack should not be empty");
|
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
PRInt32 n = mContextStack.Count() - 1;
|
2003-01-03 23:17:22 +00:00
|
|
|
mCurrentContext = (SinkContext*) mContextStack.ElementAt(n);
|
|
|
|
mContextStack.RemoveElementAt(n);
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
2005-11-10 15:51:10 +00:00
|
|
|
HTMLContentSink::ProcessBASEElement(nsGenericHTMLElement* aElement)
|
|
|
|
{
|
|
|
|
// href attribute
|
|
|
|
nsAutoString attrValue;
|
|
|
|
if (aElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, attrValue)) {
|
|
|
|
//-- Make sure this page is allowed to load this URI
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> baseHrefURI;
|
2006-02-02 00:17:15 +00:00
|
|
|
rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(baseHrefURI),
|
|
|
|
attrValue, mDocument,
|
|
|
|
nsnull);
|
2005-11-10 15:51:10 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-11-10 15:51:10 +00:00
|
|
|
// Setting "BASE URI" from the last BASE tag appearing in HEAD.
|
|
|
|
if (!mBody) {
|
|
|
|
// The document checks if it is legal to set this base. Failing here is
|
|
|
|
// ok, we just won't set a new base.
|
|
|
|
rv = mDocument->SetBaseURI(baseHrefURI);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDocumentBaseURI = mDocument->GetBaseURI();
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2005-11-10 15:51:10 +00:00
|
|
|
} else {
|
|
|
|
// NAV compatibility quirk
|
|
|
|
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-11-10 15:51:10 +00:00
|
|
|
rv = securityManager->
|
2006-02-02 20:02:34 +00:00
|
|
|
CheckLoadURIWithPrincipal(mDocument->GetNodePrincipal(), baseHrefURI,
|
2005-11-10 15:51:10 +00:00
|
|
|
nsIScriptSecurityManager::STANDARD);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-02-01 04:43:55 +00:00
|
|
|
mBaseHref = baseHrefURI;
|
1999-06-16 00:44:50 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-11-10 15:51:10 +00:00
|
|
|
// target attribute
|
|
|
|
if (aElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::target, attrValue)) {
|
|
|
|
if (!mBody) {
|
|
|
|
// still in real HEAD
|
|
|
|
mDocument->SetBaseTarget(attrValue);
|
|
|
|
} else {
|
|
|
|
// NAV compatibility quirk
|
2006-02-01 04:43:55 +00:00
|
|
|
mBaseTarget = do_GetAtom(attrValue);
|
2005-11-10 15:51:10 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-26 15:08:55 +00:00
|
|
|
nsresult
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
|
1998-06-26 15:08:55 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult result = NS_OK;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* parent = nsnull;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-14 12:33:38 +00:00
|
|
|
if (mCurrentContext) {
|
|
|
|
parent = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
1998-06-26 15:08:55 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-14 12:33:38 +00:00
|
|
|
if (parent) {
|
2000-02-11 22:07:12 +00:00
|
|
|
// Create content object
|
2004-06-25 12:26:02 +00:00
|
|
|
nsCOMPtr<nsIContent> element;
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2002-05-20 22:47:02 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::link, nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
result = NS_NewHTMLElement(getter_AddRefs(element), nodeInfo);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2000-02-11 22:07:12 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(element));
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (ssle) {
|
|
|
|
// XXX need prefs. check here.
|
|
|
|
if (!mInsideNoXXXTag) {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
} else {
|
|
|
|
ssle->InitStyleLinkElement(nsnull, PR_TRUE);
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2001-06-14 12:33:38 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
2004-04-20 23:41:56 +00:00
|
|
|
AddBaseTagInfo(element);
|
2002-09-18 23:31:08 +00:00
|
|
|
result = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(element, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2003-01-06 14:55:13 +00:00
|
|
|
result = ssle->UpdateStyleSheet(nsnull, nsnull);
|
2002-09-11 03:12:13 +00:00
|
|
|
|
|
|
|
// look for <link rel="next" href="url">
|
|
|
|
nsAutoString relVal;
|
|
|
|
element->GetAttr(kNameSpaceID_None, nsHTMLAtoms::rel, relVal);
|
|
|
|
if (!relVal.IsEmpty()) {
|
|
|
|
// XXX seems overkill to generate this string array
|
|
|
|
nsStringArray linkTypes;
|
|
|
|
nsStyleLinkElement::ParseLinkTypes(relVal, linkTypes);
|
2003-03-06 21:37:09 +00:00
|
|
|
PRBool hasPrefetch = (linkTypes.IndexOf(NS_LITERAL_STRING("prefetch")) != -1);
|
|
|
|
if (hasPrefetch || linkTypes.IndexOf(NS_LITERAL_STRING("next")) != -1) {
|
2002-09-11 03:12:13 +00:00
|
|
|
nsAutoString hrefVal;
|
|
|
|
element->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, hrefVal);
|
|
|
|
if (!hrefVal.IsEmpty()) {
|
2003-03-06 21:37:09 +00:00
|
|
|
PrefetchHref(hrefVal, hasPrefetch);
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
1998-11-26 01:29:10 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
HTMLContentSink::ForceReflow()
|
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2003-09-27 04:18:26 +00:00
|
|
|
HTMLContentSink::NotifyAppend(nsIContent* aContainer, PRUint32 aStartIndex)
|
1999-10-26 14:55:51 +00:00
|
|
|
{
|
2005-05-19 19:56:13 +00:00
|
|
|
if (aContainer->GetCurrentDoc() != mDocument) {
|
|
|
|
// aContainer is not actually in our document anymore.... Just bail out of
|
|
|
|
// here; notifying on our document for this append would be wrong.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification++;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Save and stop: nsHTMLContentSink::NotifyAppend()\n"));
|
2002-09-18 23:31:08 +00:00
|
|
|
MOZ_TIMER_SAVE(mWatch)
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mDocument->ContentAppended(aContainer, aStartIndex);
|
1999-12-04 01:27:46 +00:00
|
|
|
mLastNotificationTime = PR_Now();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Restore: nsHTMLContentSink::NotifyAppend()\n"));
|
|
|
|
MOZ_TIMER_RESTORE(mWatch);
|
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
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
1999-10-26 14:55:51 +00:00
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2006-01-12 17:11:57 +00:00
|
|
|
if (aContent && aContent->GetCurrentDoc() != 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
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Save and stop: nsHTMLContentSink::NotifyInsert()\n"));
|
2002-09-18 23:31:08 +00:00
|
|
|
MOZ_TIMER_SAVE(mWatch)
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mDocument->ContentInserted(aContent, aChildContent, aIndexInContainer);
|
1999-12-04 01:27:46 +00:00
|
|
|
mLastNotificationTime = PR_Now();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Restore: nsHTMLContentSink::NotifyInsert()\n"));
|
|
|
|
MOZ_TIMER_RESTORE(mWatch);
|
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
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRBool
|
2000-02-16 23:43:59 +00:00
|
|
|
HTMLContentSink::IsMonolithicContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aTag == eHTMLTag_tr ||
|
|
|
|
aTag == eHTMLTag_select ||
|
|
|
|
aTag == eHTMLTag_applet ||
|
|
|
|
aTag == eHTMLTag_object) {
|
2000-02-16 23:43:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
return PR_FALSE;
|
2000-02-16 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool
|
|
|
|
HTMLContentSink::IsTimeToNotify()
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mNotifyOnTimer || !mLayoutStarted || !mBackoffCount ||
|
|
|
|
mInMonolithicContainer) {
|
1999-12-04 01:27:46 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
PRInt64 interval, diff;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 04:01:26 +00:00
|
|
|
LL_I2L(interval, GetNotificationInterval());
|
1999-12-04 01:27:46 +00:00
|
|
|
LL_SUB(diff, now, mLastNotificationTime);
|
|
|
|
|
1999-12-10 22:47:39 +00:00
|
|
|
if (LL_CMP(diff, >, interval)) {
|
1999-12-04 01:27:46 +00:00
|
|
|
mBackoffCount--;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::UpdateAllContexts()
|
|
|
|
{
|
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
|
|
|
for (PRInt32 i = 0; i < numContexts; i++) {
|
|
|
|
SinkContext* sc = (SinkContext*)mContextStack.ElementAt(i);
|
|
|
|
|
|
|
|
sc->UpdateChildCounts();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2003-10-02 21:29:40 +00:00
|
|
|
HTMLContentSink::BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
2000-01-28 23:43:12 +00:00
|
|
|
{
|
|
|
|
// If we're in a script and we didn't do the notification,
|
2002-09-18 23:31:08 +00:00
|
|
|
// something else in the script processing caused the
|
2000-01-28 23:43:12 +00:00
|
|
|
// notification to occur. Since this could result in frame
|
|
|
|
// creation, make sure we've flushed everything before we
|
2003-10-21 16:23:27 +00:00
|
|
|
// continue.
|
2005-09-26 01:27:42 +00:00
|
|
|
|
|
|
|
// Note that UPDATE_CONTENT_STATE notifications never cause
|
|
|
|
// synchronous frame construction, so we never have to worry about
|
|
|
|
// them here. The code that handles the async event these
|
|
|
|
// notifications post will flush us out if it needs to.
|
|
|
|
|
|
|
|
// Also, if this is not an UPDATE_CONTENT_STATE notification,
|
|
|
|
// increment mInNotification to make sure we don't flush again until
|
|
|
|
// the end of this update, even if nested updates or
|
2003-10-21 16:23:27 +00:00
|
|
|
// FlushPendingNotifications calls happen during it.
|
2005-09-26 01:27:42 +00:00
|
|
|
NS_ASSERTION(aUpdateType && (aUpdateType & UPDATE_ALL) == aUpdateType,
|
|
|
|
"Weird update type bitmask");
|
|
|
|
if (aUpdateType != UPDATE_CONTENT_STATE && !mInNotification++ &&
|
|
|
|
mCurrentContext) {
|
2004-01-24 00:46:17 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
2000-01-28 23:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-24 00:46:17 +00:00
|
|
|
void
|
2003-10-02 21:29:40 +00:00
|
|
|
HTMLContentSink::EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
2000-01-28 23:43:12 +00:00
|
|
|
{
|
|
|
|
// If we're in a script and we didn't do the notification,
|
2002-09-18 23:31:08 +00:00
|
|
|
// something else in the script processing caused the
|
2000-01-28 23:43:12 +00:00
|
|
|
// notification to occur. Update our notion of how much
|
2003-10-21 16:23:27 +00:00
|
|
|
// has been flushed to include any new content if ending
|
2005-09-26 01:27:42 +00:00
|
|
|
// this update leaves us not inside a notification. Note that we
|
|
|
|
// exclude UPDATE_CONTENT_STATE notifications here, since those
|
|
|
|
// never affect the frame model directly while inside the
|
|
|
|
// notification.
|
|
|
|
NS_ASSERTION(aUpdateType && (aUpdateType & UPDATE_ALL) == aUpdateType,
|
|
|
|
"Weird update type bitmask");
|
|
|
|
if (aUpdateType != UPDATE_CONTENT_STATE && !--mInNotification) {
|
2000-01-28 23:43:12 +00:00
|
|
|
UpdateAllContexts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
void
|
1999-04-13 22:22:51 +00:00
|
|
|
HTMLContentSink::PreEvaluateScript()
|
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
// Eagerly append all pending elements (including the current body child)
|
|
|
|
// to the body (so that they can be seen by scripts) and force reflow.
|
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::PreEvaluateScript: flushing tags before "
|
|
|
|
"evaluating script"));
|
|
|
|
|
2002-03-26 11:15:15 +00:00
|
|
|
mCurrentContext->FlushTags(PR_FALSE);
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 02:08:04 +00:00
|
|
|
void
|
2006-01-24 01:25:14 +00:00
|
|
|
HTMLContentSink::PostEvaluateScript(nsIScriptElement *aElement)
|
1999-04-13 22:22:51 +00:00
|
|
|
{
|
2006-01-24 01:25:14 +00:00
|
|
|
mHTMLDocument->ScriptExecuted(aElement);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2005-09-22 02:33:36 +00:00
|
|
|
HTMLContentSink::ProcessSCRIPTEndTag(nsGenericHTMLElement *content,
|
2006-01-31 22:19:46 +00:00
|
|
|
PRBool aHaveNotified,
|
|
|
|
PRBool aMalformed)
|
1998-06-25 22:26:52 +00:00
|
|
|
{
|
2005-09-09 18:03:47 +00:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
|
|
|
|
NS_ASSERTION(sele, "Not really closing a script tag?");
|
2003-01-10 12:31:41 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> parent =
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
1999-07-02 20:59:39 +00:00
|
|
|
|
2006-01-31 22:19:46 +00:00
|
|
|
if (aMalformed) {
|
|
|
|
// Make sure to serialize this script correctly, for nice round tripping.
|
|
|
|
sele->SetIsMalformed();
|
|
|
|
}
|
|
|
|
|
2001-06-18 21:18:37 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mFrameset) {
|
2001-06-18 21:18:37 +00:00
|
|
|
// Fix bug 82498
|
|
|
|
// We don't want to evaluate scripts in a frameset document.
|
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
loader = mDocument->GetScriptLoader();
|
2001-06-18 21:18:37 +00:00
|
|
|
if (loader) {
|
2002-10-11 00:38:29 +00:00
|
|
|
loader->SetEnabled(PR_FALSE);
|
2001-06-18 21:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-02 02:38:20 +00:00
|
|
|
} else if (parent->GetCurrentDoc() == mDocument) {
|
|
|
|
// We test the current doc of |parent| because if it doesn't have one we
|
|
|
|
// won't actually try to evaluate the script, so we shouldn't be blocking
|
|
|
|
// or appending to mScriptElements or anything.
|
|
|
|
|
2001-06-18 21:18:37 +00:00
|
|
|
// Don't include script loading and evaluation in the stopwatch
|
|
|
|
// that is measuring content creation time
|
2005-09-09 18:03:47 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::ProcessSCRIPTEndTag()\n"));
|
2001-06-18 21:18:37 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
|
2001-06-18 21:18:37 +00:00
|
|
|
// Assume that we're going to block the parser with a script load.
|
|
|
|
// If it's an inline script, we'll be told otherwise in the call
|
|
|
|
// to our ScriptAvailable method.
|
2003-07-31 01:28:16 +00:00
|
|
|
mNeedToBlockParser = PR_TRUE;
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2004-07-06 22:52:03 +00:00
|
|
|
mScriptElements.AppendObject(sele);
|
2001-06-18 21:18:37 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
// Notify our document that we're loading this script.
|
|
|
|
mHTMLDocument->ScriptLoading(sele);
|
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
// Now tell the script that it's ready to go. This will execute the script
|
|
|
|
// and call our ScriptAvailable method.
|
2005-09-22 02:33:36 +00:00
|
|
|
content->DoneAddingChildren(aHaveNotified);
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2006-01-31 22:19:46 +00:00
|
|
|
// To prevent script evaluation in a frameset document we suspended the
|
|
|
|
// script loader. Now that the script content has been handled, let's resume
|
|
|
|
// the script loader.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (loader) {
|
2002-10-11 00:38:29 +00:00
|
|
|
loader->SetEnabled(PR_TRUE);
|
2001-06-18 21:18:37 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
// If the act of insertion evaluated the script, we're fine.
|
|
|
|
// Else, block the parser till the script has loaded.
|
2006-01-31 22:19:46 +00:00
|
|
|
// Note: If the script is malformed, we'll get a ScriptAvailable call to
|
|
|
|
// take care of this test.
|
2001-06-29 19:57:52 +00:00
|
|
|
if (mNeedToBlockParser || (mParser && !mParser->IsParserEnabled())) {
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
2001-06-29 09:59:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// 3 ways to load a style sheet: inline, style src=, link tag
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX What does nav do if we have SRC= and some style data inline?
|
|
|
|
|
|
|
|
nsresult
|
2005-09-09 18:03:47 +00:00
|
|
|
HTMLContentSink::ProcessSTYLEEndTag(nsGenericHTMLElement* content)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-09-09 18:03:47 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(content);
|
2000-02-11 22:07:12 +00:00
|
|
|
|
2004-09-09 17:32:35 +00:00
|
|
|
NS_ASSERTION(ssle,
|
|
|
|
"html:style doesn't implement nsIStyleSheetLinkingElement");
|
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (ssle) {
|
2005-09-09 18:03:47 +00:00
|
|
|
// Note: if we are inside a noXXX tag, then we init'ed this style element
|
|
|
|
// with mDontLoadStyle = PR_TRUE, so these two calls will have no effect.
|
2002-09-18 23:31:08 +00:00
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2003-01-06 14:55:13 +00:00
|
|
|
rv = ssle->UpdateStyleSheet(nsnull, nsnull);
|
2002-04-05 11:29:40 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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)
|
2000-07-08 00:19:44 +00:00
|
|
|
if (mCurrentContext && !mInNotification) {
|
2005-08-24 20:56:58 +00:00
|
|
|
PRBool notify = ((aType & Flush_SinkNotifications) != 0);
|
|
|
|
mCurrentContext->FlushTags(notify);
|
|
|
|
if (aType & Flush_OnlyReflow) {
|
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
|
|
|
StartLayout();
|
|
|
|
}
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
1999-03-15 05:11:43 +00:00
|
|
|
|
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
|
|
|
{
|
2003-04-02 11:18:00 +00:00
|
|
|
if (mDocShell) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// the following logic to get muCV is copied from
|
2002-08-26 20:13:31 +00:00
|
|
|
// nsHTMLDocument::StartDocumentLoad
|
|
|
|
// We need to call muCV->SetPrevDocCharacterSet here in case
|
|
|
|
// the charset is detected by parser DetectMetaTag
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2003-04-02 11:18:00 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
2002-08-26 20:13:31 +00:00
|
|
|
if (cv) {
|
2002-09-18 23:31:08 +00:00
|
|
|
muCV = do_QueryInterface(cv);
|
2002-08-26 20:13:31 +00:00
|
|
|
} else {
|
2002-09-18 23:31:08 +00:00
|
|
|
// in this block of code, if we get an error result, we return
|
|
|
|
// it but if we get a null pointer, that's perfectly legal for
|
|
|
|
// parent and parentContentViewer
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
2003-04-02 11:18:00 +00:00
|
|
|
do_QueryInterface(mDocShell);
|
2002-08-26 20:13:31 +00:00
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-08-26 20:13:31 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
|
|
|
if (parent) {
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv =
|
|
|
|
parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
2002-08-26 20:13:31 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && parentContentViewer) {
|
|
|
|
muCV = do_QueryInterface(parentContentViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-08-26 20:13:31 +00:00
|
|
|
if (muCV) {
|
2003-06-17 16:40:34 +00:00
|
|
|
muCV->SetPrevDocCharacterSet(aCharset);
|
2002-08-26 20:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
mDocument->SetDocumentCharacterSet(aCharset);
|
2001-06-29 22:56:58 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-11-02 19:52:32 +00:00
|
|
|
nsISupports *
|
|
|
|
HTMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2000-05-26 19:45:49 +00:00
|
|
|
/**
|
|
|
|
* This will dump content model into the output file.
|
2002-09-18 23:31:08 +00:00
|
|
|
*
|
2000-05-26 19:45:49 +00:00
|
|
|
* @update harishd 05/25/00
|
2002-09-18 23:31:08 +00:00
|
|
|
* @param
|
|
|
|
* @return NS_OK all went well, error on failure
|
2000-05-26 19:45:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::DumpContentModel()
|
2000-05-26 19:45:49 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
FILE* out = ::fopen("rtest_html.txt", "a");
|
|
|
|
if (out) {
|
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent* root = mDocument->GetRootContent();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (root) {
|
2004-01-09 23:54:21 +00:00
|
|
|
if (mDocumentURI) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString buf;
|
2004-01-09 23:54:21 +00:00
|
|
|
mDocumentURI->GetSpec(buf);
|
2002-09-18 23:31:08 +00:00
|
|
|
fputs(buf.get(), out);
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
fputs(";", out);
|
2004-01-09 23:54:21 +00:00
|
|
|
root->DumpContent(out, 0, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
fputs(";\n", out);
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-05-26 19:45:49 +00:00
|
|
|
fclose(out);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return NS_OK;
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2001-06-21 02:06:23 +00:00
|
|
|
|
|
|
|
// If the content sink can interrupt the parser (@see mCanInteruptParsing)
|
|
|
|
// then it needs to schedule a dummy parser request to delay the document
|
|
|
|
// from firing onload handlers and other document done actions until all of the
|
2002-09-18 23:31:08 +00:00
|
|
|
// parsing has completed.
|
2001-06-21 02:06:23 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddDummyParserRequest(void)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ASSERTION(!mDummyParserRequest, "Already have a dummy parser request");
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
rv = DummyParserRequest::Create(getter_AddRefs(mDummyParserRequest), this);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-06-21 02:06:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
loadGroup = mDocument->GetDocumentLoadGroup();
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loadGroup) {
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = mDummyParserRequest->SetLoadGroup(loadGroup);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = loadGroup->AddRequest(mDummyParserRequest, nsnull);
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::RemoveDummyParserRequest(void)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
loadGroup = mDocument->GetDocumentLoadGroup();
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loadGroup && mDummyParserRequest) {
|
|
|
|
rv = loadGroup->RemoveRequest(mDummyParserRequest, nsnull, NS_OK);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDummyParserRequest = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|