2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
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
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
2000-04-14 02:47:28 +00:00
|
|
|
#include "nsXPIDLString.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"
|
1998-11-26 01:29:10 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-05-18 23:05:43 +00:00
|
|
|
#include "nsICSSLoader.h"
|
1999-12-04 01:27:46 +00:00
|
|
|
#include "nsICSSLoaderObserver.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIScriptLoader.h"
|
|
|
|
#include "nsIScriptLoaderObserver.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
1999-05-18 23:05:43 +00:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
2001-01-27 16:58:15 +00:00
|
|
|
#include "nsIUnicharInputStream.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIURL.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.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"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsSupportsArray.h"
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
#include "jsapi.h" // for JSVERSION_* and JS_VersionToString
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2001-10-30 10:14:06 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2000-01-19 03:10:06 +00:00
|
|
|
#include "nsIElementFactory.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"
|
2000-08-23 17:27:06 +00:00
|
|
|
#include "nsIDOMHTMLDocument.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"
|
|
|
|
#include "nsIDOMHTMLOptionElement.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 "nsIScrollableView.h"
|
|
|
|
#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-03-25 01:21:21 +00:00
|
|
|
#include "nsICharsetConverterManager.h"
|
|
|
|
#include "nsIUnicodeDecoder.h"
|
|
|
|
#include "nsICharsetAlias.h"
|
2000-04-14 02:47:28 +00:00
|
|
|
#include "nsIChannel.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2002-09-11 03:12:13 +00:00
|
|
|
#include "nsCPrefetchService.h"
|
1998-07-22 23:42:47 +00:00
|
|
|
|
2000-03-11 00:34:54 +00:00
|
|
|
#include "nsIDocShell.h"
|
2000-08-30 11:37:06 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsIDocument.h"
|
2000-01-28 23:43:12 +00:00
|
|
|
#include "nsIDocumentObserver.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
1998-12-20 23:29:47 +00:00
|
|
|
#include "nsStyleConsts.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-09 00:14:53 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
1999-08-03 21:48:40 +00:00
|
|
|
#include "nsIRefreshURI.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"
|
2003-08-22 03:06:53 +00:00
|
|
|
#include "nsICodebasePrincipal.h"
|
|
|
|
#include "nsIAggregatePrincipal.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"
|
2002-03-31 10:14:01 +00:00
|
|
|
#include "nsITextAreaElement.h"
|
1999-09-30 22:07:04 +00:00
|
|
|
|
2002-12-10 23:44:03 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
1999-12-04 01:27:46 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// XXX Go through a factory for this one
|
|
|
|
#include "nsICSSParser.h"
|
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1998-09-03 22:23:09 +00:00
|
|
|
#include "nsIDOMHTMLTitleElement.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-02-29 06:51:48 +00:00
|
|
|
#include "nsIScrollable.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"
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
2000-07-13 23:18:37 +00:00
|
|
|
|
2001-04-24 08:43:08 +00:00
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsIFrameManager.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"
|
|
|
|
|
2000-02-16 06:50:39 +00:00
|
|
|
#ifdef ALLOW_ASYNCH_STYLE_SHEETS
|
2002-09-18 23:31:08 +00:00
|
|
|
const PRBool kBlockByDefault = PR_FALSE;
|
2000-02-16 06:50:39 +00:00
|
|
|
#else
|
2002-09-18 23:31:08 +00:00
|
|
|
const PRBool kBlockByDefault = PR_TRUE;
|
2000-02-16 06:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
2001-01-04 20:44:42 +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
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
typedef nsresult (*contentCreatorCallback)(nsIHTMLContent**, nsINodeInfo*);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLNOTUSEDElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("The element ctor should never be called");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element,
|
|
|
|
#define HTML_OTHER(_tag, _classname) NS_NewHTML##_classname##Element,
|
|
|
|
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;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
class HTMLContentSink : public nsIHTMLContentSink,
|
2001-05-17 05:54:16 +00:00
|
|
|
public nsIScriptLoaderObserver,
|
1999-12-04 01:27:46 +00:00
|
|
|
public nsITimerCallback,
|
2000-01-28 23:43:12 +00:00
|
|
|
public nsICSSLoaderObserver,
|
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
|
2002-09-18 23:31:08 +00:00
|
|
|
public nsIDocumentObserver
|
1999-11-02 06:49:44 +00:00
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
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
|
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc, nsIURI* aURL, 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
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-05-17 05:54:16 +00:00
|
|
|
NS_DECL_NSISCRIPTLOADEROBSERVER
|
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);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHOD FlushPendingNotifications();
|
2003-06-17 16:40:34 +00:00
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
|
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);
|
2003-01-03 23:17:22 +00:00
|
|
|
NS_IMETHOD AddHeadContent(const nsIParserNode& aNode);
|
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);
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD SetTitle(const nsString& aValue);
|
|
|
|
NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseHTML();
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseHead();
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseBody();
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseForm();
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseFrameset();
|
1998-07-20 18:52:40 +00:00
|
|
|
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseMap();
|
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
|
|
|
|
|
|
|
// nsICSSLoaderObserver
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
// nsIDocumentObserver
|
2002-11-25 08:33:30 +00:00
|
|
|
NS_DECL_NSIDOCUMENTOBSERVER
|
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
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool IsTimeToNotify();
|
2002-06-11 23:23:12 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult SetDocumentTitle(const nsAString& aTitle);
|
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.
|
2001-03-13 02:27:25 +00:00
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode, nsIHTMLContent* aContent,
|
2003-07-31 14:07:17 +00:00
|
|
|
PRBool aNotify = PR_FALSE,
|
|
|
|
PRBool aCheckIfPresent = PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType,
|
1999-09-30 22:07:04 +00:00
|
|
|
nsIDOMHTMLFormElement* aForm,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsIDocShell* aDocShell,
|
1999-09-30 22:07:04 +00:00
|
|
|
nsIHTMLContent** aResult);
|
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
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIDocument* mDocument;
|
1999-01-15 02:02:48 +00:00
|
|
|
nsIHTMLDocument* mHTMLDocument;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
|
1999-08-27 21:52:19 +00:00
|
|
|
nsIURI* mDocumentURI;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* mDocumentBaseURL;
|
2003-04-02 11:18:00 +00:00
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
1998-12-11 17:02:37 +00:00
|
|
|
nsIParser* mParser;
|
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
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIHTMLContent* mRoot;
|
|
|
|
nsIHTMLContent* mBody;
|
1998-07-20 18:52:40 +00:00
|
|
|
nsIHTMLContent* mFrameset;
|
1998-06-04 21:33:44 +00:00
|
|
|
nsIHTMLContent* mHead;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsString mTitle;
|
|
|
|
nsString mUnicodeXferBuf;
|
|
|
|
|
2002-11-20 22:30:53 +00:00
|
|
|
nsString mSkippedContent;
|
|
|
|
|
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;
|
|
|
|
PRPackedBool mNeedToBlockParser;
|
2001-05-30 02:25:52 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
PRInt32 mInNotification;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> mCurrentForm;
|
|
|
|
nsCOMPtr<nsIHTMLContent> mCurrentMap;
|
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;
|
2002-02-12 21:17:53 +00:00
|
|
|
nsCOMPtr<nsISupportsArray> mScriptElements;
|
2001-06-21 02:06:23 +00:00
|
|
|
nsCOMPtr<nsIRequest> mDummyParserRequest;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCString mRef;
|
1998-07-22 23:42:47 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsString mBaseHREF;
|
|
|
|
nsString mBaseTarget;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsICSSLoader *mCSSLoader;
|
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
|
|
|
|
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
|
|
|
|
2003-03-14 01:16:31 +00:00
|
|
|
void ScrollToRef(PRBool aReallyScroll);
|
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
|
|
|
|
*/
|
1998-08-28 16:20:16 +00:00
|
|
|
void AddBaseTagInfo(nsIHTMLContent* aContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult ProcessLinkHeader(nsIHTMLContent* aElement,
|
|
|
|
const nsAString& aLinkData);
|
|
|
|
nsresult ProcessLink(nsIHTMLContent* aElement, const nsString& aHref,
|
|
|
|
const nsString& aRel, const nsString& aTitle,
|
|
|
|
const nsString& aType, const nsString& aMedia);
|
1999-01-23 07:05:49 +00:00
|
|
|
nsresult ProcessStyleLink(nsIHTMLContent* aElement,
|
2002-09-18 23:31:08 +00:00
|
|
|
const nsString& aHref,
|
|
|
|
const nsStringArray& aLinkTypes,
|
1999-01-23 07:05:49 +00:00
|
|
|
const nsString& aTitle, const nsString& aType,
|
1999-05-26 23:49:33 +00:00
|
|
|
const nsString& aMedia);
|
2003-03-06 21:37:09 +00:00
|
|
|
void PrefetchHref(const nsAString &aHref, PRBool aExplicit);
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-03-23 23:13:20 +00:00
|
|
|
void ProcessBaseHref(const nsAString& aBaseHref);
|
|
|
|
void ProcessBaseTarget(const nsAString& aBaseTarget);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
nsresult RefreshIfEnabled(nsIViewManager* vm);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Routines for tags that require special handling
|
|
|
|
nsresult ProcessAREATag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessBASETag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessLINKTag(const nsIParserNode& aNode);
|
1999-03-01 16:57:35 +00:00
|
|
|
nsresult ProcessMAPTag(const nsIParserNode& aNode, nsIHTMLContent* aContent);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult ProcessMETATag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessSCRIPTTag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessSTYLETag(const nsIParserNode& aNode);
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
|
|
|
|
nsIHTMLContent* aContent = nsnull);
|
2001-03-03 00:39:29 +00:00
|
|
|
nsresult ProcessHTTPHeaders(nsIChannel* aChannel);
|
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult OpenHeadContext();
|
|
|
|
nsresult CloseHeadContext();
|
1998-12-15 06:10:59 +00:00
|
|
|
// Script processing related routines
|
|
|
|
nsresult ResumeParsing();
|
2002-09-18 23:31:08 +00:00
|
|
|
PRBool PreEvaluateScript();
|
|
|
|
void PostEvaluateScript();
|
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
|
|
|
|
|
|
|
|
// nsIRequest
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHOD GetName(nsACString &result)
|
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
result = NS_LITERAL_CSTRING("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
|
|
|
|
|
|
|
// 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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Normally when OpenContainer's are done the container is not
|
|
|
|
// appended to it's parent until the container is closed. By setting
|
|
|
|
// pre-append to true, the container will be appended when it is
|
|
|
|
// created.
|
2002-09-18 23:31:08 +00:00
|
|
|
void SetPreAppend(PRBool aPreAppend)
|
|
|
|
{
|
1998-08-31 17:51:32 +00:00
|
|
|
mPreAppend = aPreAppend;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsIHTMLContent* 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);
|
2002-11-19 18:29:35 +00:00
|
|
|
nsresult CloseContainer(const nsHTMLTag aTag);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult AddLeaf(const nsIParserNode& aNode);
|
1999-01-09 00:14:53 +00:00
|
|
|
nsresult AddLeaf(nsIHTMLContent* 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
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
nsresult FlushTags(PRBool aNotify = PR_TRUE);
|
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);
|
|
|
|
nsIHTMLContent* GetCurrentContainer();
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink* mSink;
|
|
|
|
PRBool mPreAppend;
|
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;
|
|
|
|
nsIHTMLContent* mContent;
|
|
|
|
PRUint32 mFlags;
|
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.mFlags
|
|
|
|
#define APPENDED 0x1
|
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)) {
|
2002-11-19 18:29:35 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
if (mParser) {
|
1999-09-30 22:07:04 +00:00
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
2002-11-19 18:29:35 +00:00
|
|
|
if (!dtd)
|
|
|
|
return;
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
2002-11-19 18:29:35 +00:00
|
|
|
const char* cp =
|
|
|
|
NS_ConvertUCS2toUTF8(dtd->IntTagToStringTag(aTag)).get();
|
|
|
|
PR_LogPrint("%s: this=%p node='%s' stackPos=%d",
|
|
|
|
aMsg, aThis, cp, aStackPos);
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
|
2003-07-31 14:07:17 +00:00
|
|
|
nsIHTMLContent* aContent, PRBool aNotify,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString 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
|
|
|
|
// more common case of reasonable HTML.
|
|
|
|
|
|
|
|
for (PRInt32 i = ac - 1; i >= 0; i--) {
|
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);
|
2001-11-02 07:40:01 +00:00
|
|
|
k.Assign(key);
|
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";
|
|
|
|
const nsAString& v =
|
|
|
|
nsContentUtils::TrimCharsInSet(kWhitespace, aNode.GetValueAt(i));
|
|
|
|
|
|
|
|
if (nodeType == eHTMLTag_a && keyAtom == nsHTMLAtoms::name) {
|
|
|
|
NS_ConvertUCS2toUTF8 cname(v);
|
|
|
|
NS_ConvertUTF8toUCS2 uv(nsUnescape(NS_CONST_CAST(char *,
|
|
|
|
cname.get())));
|
|
|
|
|
|
|
|
// 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
|
|
|
|
SetForm(nsIHTMLContent* aContent, nsIDOMHTMLFormElement* aForm)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(aContent));
|
2003-09-24 06:16:52 +00:00
|
|
|
NS_ASSERTION(formControl, "nsIDOMHTMLFormElement doesnt implement nsIFormControl?");
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
formControl->SetForm(aForm);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
static nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo,
|
2003-09-24 06:16:52 +00:00
|
|
|
nsIDOMHTMLFormElement* aForm, nsIHTMLContent** aResult,
|
|
|
|
PRBool aInsideNoXXXTag, PRBool aFromParser);
|
2000-12-10 09:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory subroutine to create all of the html content objects.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
|
|
|
|
nsHTMLTag aNodeType,
|
|
|
|
nsIDOMHTMLFormElement* aForm,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsIDocShell* aDocShell,
|
2000-12-10 09:20:40 +00:00
|
|
|
nsIHTMLContent** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Find/create atom for the tag name
|
2001-11-28 06:13:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
|
|
|
|
if (aNodeType == eHTMLTag_userdefined) {
|
|
|
|
nsAutoString tmp;
|
2000-12-10 09:20:40 +00:00
|
|
|
tmp.Append(aNode.GetText());
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(tmp);
|
2001-11-28 06:13:11 +00:00
|
|
|
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(tmp, nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2000-12-10 09:20:40 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
rv = mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-11-28 06:13:11 +00:00
|
|
|
nsDependentString tag(dtd->IntTagToStringTag(aNodeType));
|
|
|
|
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(tag, nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// XXX if the parser treated the text in a textarea like a normal
|
|
|
|
// textnode we wouldn't need to do this.
|
2002-11-20 22:30:53 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aNodeType == eHTMLTag_textarea) {
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 lineNo = 0;
|
2000-12-10 09:20:40 +00:00
|
|
|
|
2002-11-20 22:30:53 +00:00
|
|
|
dtd->CollectSkippedContent(eHTMLTag_textarea, mSkippedContent, lineNo);
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Make the content object
|
2003-09-24 06:16:52 +00:00
|
|
|
rv = MakeContentObject(aNodeType, nodeInfo, aForm, aResult,
|
2002-09-18 23:31:08 +00:00
|
|
|
!!mInsideNoXXXTag, PR_TRUE);
|
|
|
|
|
2002-11-20 22:30:53 +00:00
|
|
|
if (aNodeType == eHTMLTag_textarea && !mSkippedContent.IsEmpty()) {
|
|
|
|
// XXX: if the parser treated the text in a textarea like a normal
|
|
|
|
// textnode we wouldn't need to do this.
|
|
|
|
|
|
|
|
// If the text area has some content, set it
|
|
|
|
|
|
|
|
// Strip only one leading newline if there is one (bug 40394)
|
|
|
|
nsString::const_iterator start, end;
|
|
|
|
mSkippedContent.BeginReading(start);
|
|
|
|
mSkippedContent.EndReading(end);
|
|
|
|
if (*start == nsCRT::CR) {
|
|
|
|
++start;
|
|
|
|
|
|
|
|
if (start != end && *start == nsCRT::LF) {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
} else if (*start == nsCRT::LF) {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> ta(do_QueryInterface(*aResult));
|
|
|
|
NS_ASSERTION(ta, "Huh? text area doesn't implement "
|
|
|
|
"nsIDOMHTMLTextAreaElement?");
|
|
|
|
|
|
|
|
ta->SetDefaultValue(Substring(start, end));
|
|
|
|
|
|
|
|
// Release whatever's in the skipped content string, no point in
|
|
|
|
// holding on to this any longer.
|
|
|
|
mSkippedContent.Truncate();
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
(*aResult)->SetContentID(id);
|
|
|
|
|
2000-12-10 09:20:40 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-11-28 06:13:11 +00:00
|
|
|
NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo,
|
|
|
|
PRBool aCaseSensitive)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-11-19 13:39:20 +00:00
|
|
|
nsIParserService* parserService = nsContentUtils::GetParserServiceWeakRef();
|
|
|
|
if (!parserService)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = aNodeInfo->GetNameAtom();
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Find tag in tag table
|
|
|
|
PRInt32 id;
|
2001-02-02 16:32:27 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aCaseSensitive) {
|
|
|
|
parserService->HTMLCaseSensitiveAtomTagToId(name, &id);
|
|
|
|
} else {
|
|
|
|
parserService->HTMLAtomTagToId(name, &id);
|
|
|
|
}
|
2001-05-12 05:10:48 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aCaseSensitive) {
|
2003-09-24 06:16:52 +00:00
|
|
|
rv = MakeContentObject(nsHTMLTag(id), aNodeInfo, nsnull,
|
2002-11-20 22:30:53 +00:00
|
|
|
aResult, PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
|
|
|
// Revese map id to name to get the correct character case in
|
|
|
|
// 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
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (nsHTMLTag(id) != eHTMLTag_userdefined) {
|
|
|
|
const PRUnichar *tag = nsnull;
|
|
|
|
parserService->HTMLIdToStringTag(id, &tag);
|
|
|
|
NS_ASSERTION(tag, "What? Reverse mapping of id to string broken!!!");
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2003-03-25 18:55:59 +00:00
|
|
|
if (!name->Equals(nsDependentString(tag))) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> atom = do_GetAtom(tag);
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
rv = aNodeInfo->NameChanged(atom, getter_AddRefs(kungFuDeathGrip));
|
2002-09-18 23:31:08 +00:00
|
|
|
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
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
rv = MakeContentObject(nsHTMLTag(id), nodeInfo, nsnull, aResult,
|
2002-11-20 22:30:53 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
class nsHTMLElementFactory : public nsIElementFactory,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
2000-12-10 09:20:40 +00:00
|
|
|
public:
|
|
|
|
nsHTMLElementFactory();
|
|
|
|
virtual ~nsHTMLElementFactory();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo,
|
|
|
|
nsIContent** aResult);
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLElementFactory(nsIElementFactory** aInstancePtrResult)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
*aInstancePtrResult = new nsHTMLElementFactory();
|
|
|
|
if (!*aInstancePtrResult) {
|
2000-12-10 09:20:40 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aInstancePtrResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::~nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLElementFactory, nsIElementFactory,
|
2003-09-07 21:50:21 +00:00
|
|
|
nsISupportsWeakReference)
|
2000-12-10 09:20:40 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLElementFactory::CreateInstanceByTag(nsINodeInfo *aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(aNodeInfo);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent;
|
2002-01-06 10:34:41 +00:00
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(htmlContent), aNodeInfo,
|
|
|
|
aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML));
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
*aResult = htmlContent;
|
2000-12-10 09:20:40 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-12-10 09:20:40 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
MakeContentObject(nsHTMLTag aNodeType, nsINodeInfo *aNodeInfo,
|
2003-09-24 06:16:52 +00:00
|
|
|
nsIDOMHTMLFormElement* aForm, nsIHTMLContent** aResult,
|
|
|
|
PRBool aInsideNoXXXTag, PRBool aFromParser)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
if (aNodeType == eHTMLTag_form) {
|
1998-09-23 17:16:51 +00:00
|
|
|
if (aForm) {
|
2003-09-24 06:16:52 +00:00
|
|
|
// the form was already created
|
|
|
|
return CallQueryInterface(aForm, aResult);
|
1998-11-16 06:16:17 +00:00
|
|
|
}
|
2003-09-24 06:16:52 +00:00
|
|
|
return NS_NewHTMLFormElement(aResult, aNodeInfo);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
nsresult rv;
|
|
|
|
// The "creator" functions for input and select elements don't have
|
|
|
|
// the usual prototype and hence are not in the creator callback
|
|
|
|
// table
|
|
|
|
if (aNodeType == eHTMLTag_input) {
|
2002-03-31 10:14:01 +00:00
|
|
|
rv = NS_NewHTMLInputElement(aResult, aNodeInfo, aFromParser);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!aInsideNoXXXTag) {
|
2000-10-11 23:23:21 +00:00
|
|
|
SetForm(*aResult, aForm);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2003-09-24 06:16:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
if (aNodeType == eHTMLTag_select) {
|
2002-03-31 10:14:01 +00:00
|
|
|
rv = NS_NewHTMLSelectElement(aResult, aNodeInfo, aFromParser);
|
2002-01-05 07:17:10 +00:00
|
|
|
if (!aInsideNoXXXTag) {
|
|
|
|
SetForm(*aResult, aForm);
|
2000-10-11 23:23:21 +00:00
|
|
|
}
|
2003-09-24 06:16:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
rv = sContentCreatorCallbacks[aNodeType](aResult, aNodeInfo);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-24 06:16:52 +00:00
|
|
|
switch (aNodeType) {
|
|
|
|
case eHTMLTag_button:
|
|
|
|
case eHTMLTag_fieldset:
|
|
|
|
case eHTMLTag_label:
|
|
|
|
case eHTMLTag_legend:
|
|
|
|
case eHTMLTag_object:
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_textarea:
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!aInsideNoXXXTag) {
|
2001-12-23 16:06:13 +00:00
|
|
|
SetForm(*aResult, aForm);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
1998-09-01 01:37:17 +00:00
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1998-09-01 01:37:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-06 19:26:43 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-01-27 23:06:33 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(SinkContext)
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext::SinkContext(HTMLContentSink* aSink)
|
2002-12-19 20:23:57 +00:00
|
|
|
: mSink(aSink), mPreAppend(PR_FALSE), mNotifyLevel(0),
|
2002-09-18 23:31:08 +00:00
|
|
|
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,
|
|
|
|
nsIHTMLContent* 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;
|
|
|
|
mStack[0].mFlags = APPENDED;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLContent*
|
|
|
|
SinkContext::GetCurrentContainer()
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIHTMLContent* content = mStack[mStackPos - 1].mContent;
|
1999-07-22 23:28:16 +00:00
|
|
|
NS_ADDREF(content);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if ((mStackPos == 2) && (mSink->mBody == mStack[1].mContent)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
// We just finished adding something to the body
|
1999-10-26 14:55:51 +00:00
|
|
|
mNotifyLevel = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we just added content to a node for which
|
2002-09-18 23:31:08 +00:00
|
|
|
// an insertion happen, we need to do an immediate
|
1999-10-26 14:55:51 +00:00
|
|
|
// notification for that insertion.
|
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
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mSink->mParser->GetDTD(getter_AddRefs(dtd));
|
2002-09-18 23:31:08 +00:00
|
|
|
nsHTMLTag tag = nsHTMLTag(mStack[mStackPos - 1].mType);
|
|
|
|
nsDependentString str(dtd->IntTagToStringTag(tag));
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("SinkContext::DidAddContent: Insertion notification for "
|
|
|
|
"parent=%s at position=%d and stackPos=%d",
|
2001-10-16 03:53:44 +00:00
|
|
|
NS_LossyConvertUCS2toASCII(str).get(),
|
2002-09-18 23:31:08 +00:00
|
|
|
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
|
|
|
|
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());
|
|
|
|
nsIHTMLContent* content;
|
2003-04-02 14:31:43 +00:00
|
|
|
nsIDocShell *docshell = nsnull;
|
2003-04-02 13:59:09 +00:00
|
|
|
if (mSink->mFrameset) docshell = (nsIDocShell *) mSink->mDocShell;
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = mSink->CreateContentObject(aNode, nodeType, mSink->mCurrentForm,
|
2003-04-02 13:59:09 +00:00
|
|
|
docshell, &content);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[mStackPos].mType = nodeType;
|
|
|
|
mStack[mStackPos].mContent = content;
|
|
|
|
mStack[mStackPos].mFlags = 0;
|
1999-10-26 14:55:51 +00:00
|
|
|
mStack[mStackPos].mNumFlushed = 0;
|
|
|
|
mStack[mStackPos].mInsertionPoint = -1;
|
2000-05-19 04:48:43 +00:00
|
|
|
content->SetDocument(mSink->mDocument, PR_FALSE, PR_TRUE);
|
2001-03-13 02:27:25 +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.
|
|
|
|
switch (nodeType) {
|
|
|
|
// Containers with "href="
|
|
|
|
case eHTMLTag_a:
|
|
|
|
case eHTMLTag_map:
|
|
|
|
|
|
|
|
// 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);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mPreAppend) {
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mStackPos <= 0) {
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ERROR("container w/o parent");
|
|
|
|
|
1999-12-09 03:10:22 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
|
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2001-04-02 00:45:52 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-04-02 00:45:52 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[mStackPos].mFlags |= APPENDED;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStackPos++;
|
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) {
|
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_map:
|
|
|
|
mSink->ProcessMAPTag(aNode, content);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES++;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
SinkContext::CloseContainer(const nsHTMLTag aTag)
|
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
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_WARN_IF_FALSE(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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIHTMLContent* 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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add container to its parent if we haven't already done it
|
2002-09-18 23:31:08 +00:00
|
|
|
if ((mStack[mStackPos].mFlags & APPENDED) == 0) {
|
1999-12-08 23:05:14 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0, "container w/o parent");
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the parent has an insertion point, insert rather than
|
|
|
|
// append.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
result = parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2001-04-02 00:45:52 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-04-02 00:45:52 +00:00
|
|
|
result = parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
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
|
|
|
|
// Tracing code
|
2002-06-25 06:47:53 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2003-06-13 20:10:01 +00:00
|
|
|
mStack[mStackPos].mContent->GetTag(getter_AddRefs(tag));
|
2003-03-25 18:55:59 +00:00
|
|
|
const char *tagStr;
|
|
|
|
tag->GetUTF8String(&tagStr);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("SinkContext::CloseContainer: reflow on notifyImmediate "
|
|
|
|
"tag=%s newIndex=%d stackPos=%d",
|
2003-03-25 18:55:59 +00:00
|
|
|
tagStr,
|
2001-10-16 03:53:44 +00:00
|
|
|
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) {
|
|
|
|
result = CloseContainer(aTag);
|
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;
|
|
|
|
case eHTMLTag_select:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectElement> select = do_QueryInterface(content);
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (select) {
|
|
|
|
result = select->DoneAddingChildren();
|
1999-11-11 22:15:02 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
1999-11-11 22:15:02 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
|
|
|
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
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mPreAppend &&
|
|
|
|
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());
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> content;
|
1999-09-30 22:07:04 +00:00
|
|
|
rv = mSink->CreateContentObject(aNode, nodeType,
|
2003-04-02 11:18:00 +00:00
|
|
|
mSink->mCurrentForm, mSink->mDocShell,
|
2002-09-18 23:31:08 +00:00
|
|
|
getter_AddRefs(content));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
|
|
|
// Set the content's document
|
2000-05-19 04:48:43 +00:00
|
|
|
content->SetDocument(mSink->mDocument, PR_FALSE, PR_TRUE);
|
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) {
|
2003-04-17 23:15:21 +00:00
|
|
|
// leaves with 'SRC='
|
|
|
|
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:
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->AddBaseTagInfo(content);
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
|
|
|
// Notify input and button that they are now fully created
|
|
|
|
switch (nodeType) {
|
|
|
|
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;
|
|
|
|
case eHTMLTag_textarea:
|
2002-04-16 18:09:53 +00:00
|
|
|
{
|
2002-03-31 10:14:01 +00:00
|
|
|
// XXX textarea deserves to be treated like the container it is.
|
|
|
|
nsCOMPtr<nsITextAreaElement> textarea(do_QueryInterface(content));
|
|
|
|
if (textarea) {
|
|
|
|
textarea->DoneAddingChildren();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-03-31 10:14:01 +00:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
SinkContext::AddLeaf(nsIHTMLContent* aContent)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
|
|
|
|
// If the parent has an insertion point, insert rather than append.
|
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(aContent,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2001-04-02 00:45:52 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-04-02 00:45:52 +00:00
|
|
|
parent->AppendChildTo(aContent, PR_FALSE, 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
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mPreAppend &&
|
|
|
|
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;
|
|
|
|
nsresult rv = NS_NewCommentNode(getter_AddRefs(comment));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMComment> domComment(do_QueryInterface(comment));
|
|
|
|
NS_ENSURE_TRUE(domComment, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
domComment->AppendData(aNode.GetText());
|
|
|
|
|
|
|
|
comment->SetDocument(mSink->mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
|
2003-04-03 18:32:58 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0, "stack out of bounds");
|
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIHTMLContent* 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++,
|
|
|
|
PR_FALSE, PR_FALSE);
|
|
|
|
} else {
|
|
|
|
parent->AppendChildTo(comment, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
DidAddContent(comment, PR_FALSE);
|
1999-04-03 19:00:23 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mPreAppend &&
|
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
nsresult result = NS_OK;
|
2000-04-05 04:02:38 +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
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 childCount;
|
1999-10-26 14:55:51 +00:00
|
|
|
nsIHTMLContent* content;
|
|
|
|
|
|
|
|
// Start from the top of the stack (growing upwards) and append
|
|
|
|
// all content that hasn't been previously appended to the tree
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 stackPos = mStackPos - 1;
|
|
|
|
|
|
|
|
while ((stackPos > 0) && ((mStack[stackPos].mFlags & APPENDED) == 0)) {
|
1999-10-26 14:55:51 +00:00
|
|
|
content = mStack[stackPos].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIHTMLContent* parent = mStack[stackPos - 1].mContent;
|
|
|
|
|
2002-04-06 00:47:43 +00:00
|
|
|
mStack[stackPos].mFlags |= APPENDED;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the parent has an insertion point, insert rather than
|
|
|
|
// append.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content, mStack[mStackPos - 1].mInsertionPoint++,
|
2001-04-02 00:45:52 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-04-02 00:45:52 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
stackPos = 1;
|
|
|
|
PRBool flushed = PR_FALSE;
|
|
|
|
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
|
|
|
|
// Tracing code
|
2002-06-25 06:47:53 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2003-06-13 20:10:01 +00:00
|
|
|
mStack[stackPos].mContent->GetTag(getter_AddRefs(tag));
|
2003-03-25 18:55:59 +00:00
|
|
|
const char* tagStr;
|
|
|
|
tag->GetUTF8String(&tagStr);
|
2002-06-25 06:47:53 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("SinkContext::FlushTags: tag=%s from newindex=%d at "
|
2003-03-25 18:55:59 +00:00
|
|
|
"stackPos=%d", tagStr,
|
2001-10-16 03:53:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SinkContext::UpdateChildCounts()
|
|
|
|
{
|
|
|
|
nsIHTMLContent* content;
|
|
|
|
|
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) {
|
|
|
|
if (mStack[stackPos].mFlags & APPENDED) {
|
|
|
|
content = mStack[stackPos].mContent;
|
2003-09-27 04:18:26 +00:00
|
|
|
mStack[stackPos].mNumFlushed = content->GetChildCount();
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
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;
|
|
|
|
rv = NS_NewTextNode(getter_AddRefs(textContent));
|
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 content's document
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode->SetDocument(mSink->mDocument, PR_FALSE, PR_TRUE);
|
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
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
if (mStack[mStackPos - 1].mInsertionPoint != -1) {
|
2002-12-19 20:23:57 +00:00
|
|
|
parent->InsertChildAt(mLastTextNode,
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint++,
|
2002-09-18 23:31:08 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
|
|
|
} else {
|
2002-12-19 20:23:57 +00:00
|
|
|
parent->AppendChildTo(mLastTextNode, PR_FALSE, 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
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mPreAppend && 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,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
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);
|
|
|
|
|
1998-09-12 19:33:48 +00:00
|
|
|
HTMLContentSink* it;
|
|
|
|
NS_NEWXPCOM(it, 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
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURL, aContainer, aChannel);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
delete it;
|
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
|
|
|
|
|
|
|
*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(mFrameset);
|
|
|
|
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);
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
}
|
1999-01-15 02:02:48 +00:00
|
|
|
NS_IF_RELEASE(mHTMLDocument);
|
1999-08-27 21:52:19 +00:00
|
|
|
NS_IF_RELEASE(mDocumentURI);
|
1999-01-15 02:02:48 +00:00
|
|
|
NS_IF_RELEASE(mDocumentBaseURL);
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
1999-05-18 23:05:43 +00:00
|
|
|
NS_IF_RELEASE(mCSSLoader);
|
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
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS7(HTMLContentSink,
|
1999-11-30 04:50:42 +00:00
|
|
|
nsIHTMLContentSink,
|
|
|
|
nsIContentSink,
|
2001-05-17 05:54:16 +00:00
|
|
|
nsIScriptLoaderObserver,
|
1999-12-04 01:27:46 +00:00
|
|
|
nsITimerCallback,
|
2000-01-28 23:43:12 +00:00
|
|
|
nsICSSLoaderObserver,
|
2000-05-26 19:45:49 +00:00
|
|
|
nsIDocumentObserver,
|
|
|
|
nsIDebugDumpContent)
|
2001-10-16 05:31:36 +00:00
|
|
|
#else
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS6(HTMLContentSink,
|
2001-10-16 05:31:36 +00:00
|
|
|
nsIHTMLContentSink,
|
|
|
|
nsIContentSink,
|
|
|
|
nsIScriptLoaderObserver,
|
|
|
|
nsITimerCallback,
|
|
|
|
nsICSSLoaderObserver,
|
|
|
|
nsIDocumentObserver)
|
|
|
|
#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);
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(securityManager, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
aDoc->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
NS_ENSURE_TRUE(principal, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
aDoc->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
owner->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext;
|
|
|
|
globalObject->GetContext(getter_AddRefs(scriptContext));
|
|
|
|
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
|
|
|
|
|
|
|
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
|
|
|
NS_ENSURE_TRUE(cx, PR_TRUE);
|
|
|
|
|
|
|
|
PRBool enabled = PR_TRUE;
|
|
|
|
securityManager->CanExecuteScripts(cx, principal, &enabled);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-20 01:04:24 +00:00
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::Init(nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!aDoc || !aURL || !aContainer) {
|
|
|
|
NS_ERROR("Null ptr!");
|
|
|
|
|
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-08-31 17:51:32 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mScriptElements));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mDocument = aDoc;
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_ADDREF(aDoc);
|
2002-09-18 23:31:08 +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
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
rv = mDocument->GetNodeInfoManager(getter_AddRefs(mNodeInfoManager));
|
2000-05-10 13:13:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-08-27 21:52:19 +00:00
|
|
|
mDocumentURI = aURL;
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_ADDREF(aURL);
|
1999-01-15 02:02:48 +00:00
|
|
|
mDocumentBaseURL = aURL;
|
|
|
|
NS_ADDREF(aURL);
|
2003-04-02 11:18:00 +00:00
|
|
|
mDocShell = do_QueryInterface(aContainer);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2001-09-28 23:08:17 +00:00
|
|
|
mObservers = nsnull;
|
|
|
|
|
2002-11-19 13:39:20 +00:00
|
|
|
nsIParserService* service = nsContentUtils::GetParserServiceWeakRef();
|
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));
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
rv = mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
loader->AddObserver(this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
NS_WARN_IF_FALSE(mDocShell, "oops no docshell!");
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2002-12-10 23:44:03 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2002-12-10 23:44:03 +00:00
|
|
|
PRBool notifyPref = PR_TRUE;
|
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetBoolPref("content.notify.ontimer", ¬ifyPref);
|
2001-04-24 23:25:09 +00:00
|
|
|
}
|
2002-12-10 23:44:03 +00:00
|
|
|
mNotifyOnTimer = notifyPref;
|
1999-12-04 01:27:46 +00:00
|
|
|
|
2000-08-18 06:33:34 +00:00
|
|
|
mBackoffCount = -1; // never
|
2002-12-10 23:44:03 +00:00
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetIntPref("content.notify.backoffcount", &mBackoffCount);
|
2001-04-24 23:25:09 +00:00
|
|
|
}
|
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.
|
2001-06-21 02:06:23 +00:00
|
|
|
mNotificationInterval = 120000;
|
2002-12-10 23:44:03 +00:00
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetIntPref("content.notify.interval", &mNotificationInterval);
|
2001-04-24 23:25:09 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
mMaxTokenProcessingTime = mNotificationInterval * 3;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 04:01:26 +00:00
|
|
|
PRBool enableInterruptParsing = PR_TRUE;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// 3/4 second default for switching
|
|
|
|
mDynamicIntervalSwitchThreshold = 750000;
|
|
|
|
|
2002-12-10 23:44:03 +00:00
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetBoolPref("content.interrupt.parsing",
|
|
|
|
&enableInterruptParsing);
|
|
|
|
prefBranch->GetIntPref("content.max.tokenizing.time",
|
|
|
|
&mMaxTokenProcessingTime);
|
|
|
|
prefBranch->GetIntPref("content.switch.threshold",
|
|
|
|
&mDynamicIntervalSwitchThreshold);
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (enableInterruptParsing) {
|
|
|
|
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.
|
2001-04-26 14:37:31 +00:00
|
|
|
mMaxTextRun = 8191;
|
2002-12-10 23:44:03 +00:00
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetIntPref("content.maxtextrun", &mMaxTextRun);
|
2001-04-24 23:25:09 +00:00
|
|
|
}
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2001-06-20 01:04:24 +00:00
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer(do_QueryInterface(aDoc));
|
|
|
|
if (htmlContainer) {
|
1999-05-18 23:05:43 +00:00
|
|
|
htmlContainer->GetCSSLoader(mCSSLoader);
|
|
|
|
}
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
// XXX this presumes HTTP header info is alread set in document
|
|
|
|
// XXX if it isn't we need to set it here...
|
2001-03-03 00:39:29 +00:00
|
|
|
|
|
|
|
ProcessHTTPHeaders(aChannel);
|
|
|
|
|
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
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIContent> doc_root;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(doc_root));
|
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()...
|
|
|
|
|
|
|
|
CallQueryInterface(doc_root, &mRoot);
|
|
|
|
} else {
|
|
|
|
rv = NS_NewHTMLHtmlElement(&mRoot, nodeInfo);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-04-12 09:50:55 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRoot->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
mDocument->SetRootContent(mRoot);
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make head part
|
2001-04-26 19:33:12 +00:00
|
|
|
rv = mNodeInfoManager->GetNodeInfo(NS_LITERAL_STRING("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);
|
|
|
|
|
|
|
|
rv = NS_NewHTMLHeadElement(&mHead, 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);
|
1998-07-30 16:06:22 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-04-02 00:45:52 +00:00
|
|
|
mRoot->AppendChildTo(mHead, PR_FALSE, 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;
|
|
|
|
(void)aURL->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;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mTitle.IsEmpty()) {
|
2000-08-23 17:27:06 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> domDoc(do_QueryInterface(mHTMLDocument));
|
|
|
|
if (domDoc)
|
2002-09-18 23:31:08 +00:00
|
|
|
domDoc->SetTitle(mTitle);
|
1998-08-10 17:39:48 +00:00
|
|
|
}
|
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
// Reflow the last batch of content
|
2001-04-10 00:49:49 +00:00
|
|
|
if (mBody) {
|
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-04-02 11:18:00 +00:00
|
|
|
ScrollToRef(!(LoadType & nsIDocShell::LOAD_CMD_HISTORY));
|
2002-04-04 22:10:10 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
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.
|
|
|
|
NS_IF_RELEASE(mParser);
|
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
|
|
|
|
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) {
|
1999-12-04 01:27:46 +00:00
|
|
|
PRTime now = PR_Now();
|
|
|
|
PRInt64 interval, diff;
|
|
|
|
PRInt32 delay;
|
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);
|
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
|
1999-12-10 22:47:39 +00:00
|
|
|
if (LL_CMP(diff, >, interval)) {
|
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);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
1999-12-04 01:27:46 +00:00
|
|
|
// If the time since the last notification is less than
|
|
|
|
// the expected interval but positive, set a timer up for the remaining
|
|
|
|
// interval.
|
|
|
|
if (LL_CMP(diff, >, LL_ZERO)) {
|
|
|
|
LL_SUB(diff, interval, diff);
|
|
|
|
LL_L2I(delay, diff);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
|
|
|
// Else set up a timer for the expected interval
|
2001-06-29 04:01:26 +00:00
|
|
|
delay = GetNotificationInterval();
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// Convert to milliseconds
|
|
|
|
delay /= PR_USEC_PER_MSEC;
|
2002-09-18 23:31:08 +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::WillInterrupt: canceling notification "
|
|
|
|
"timeout"));
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
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);
|
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
|
|
|
|
|
|
|
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));
|
|
|
|
|
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::WillResume: canceling notification "
|
|
|
|
"timeout"));
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
mNotificationTimer = 0;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mParser);
|
|
|
|
mParser = aParser;
|
|
|
|
NS_IF_ADDREF(mParser);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
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
|
|
|
|
|
|
|
PRInt32 insertionPoint = -1;
|
1999-04-15 20:18:34 +00:00
|
|
|
nsHTMLTag nodeType = mCurrentContext->mStack[aPosition].mType;
|
|
|
|
nsIHTMLContent* 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
|
|
|
}
|
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::SetTitle(const nsString& aValue)
|
1998-07-22 23:42:47 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::SetTitle()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1998-07-22 23:42:47 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult rv = OpenHeadContext();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = SetDocumentTitle(aValue);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2003-01-03 23:17:22 +00:00
|
|
|
CloseHeadContext();
|
2000-05-10 13:13:39 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::SetTitle()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
return rv;
|
1998-07-22 23:42:47 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenHTML(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
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::OpenHTML",
|
|
|
|
eHTMLTag_html, 0, this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mRoot) {
|
2000-03-30 01:07:02 +00:00
|
|
|
// Add attributes to the node...if found.
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (ac > 0) {
|
2003-07-31 14:07:17 +00:00
|
|
|
AddAttributes(aNode, mRoot, PR_TRUE, PR_TRUE);
|
2001-03-13 02:27:25 +00:00
|
|
|
}
|
2000-03-30 01:07:02 +00:00
|
|
|
}
|
1999-09-14 19:24:42 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenHead(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenHead()\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::OpenHead",
|
|
|
|
eHTMLTag_head, 0, this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult rv = OpenHeadContext();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-10-19 20:48:18 +00:00
|
|
|
if (mHead && aNode.GetNodeType() == eHTMLTag_head) {
|
2003-07-31 14:07:17 +00:00
|
|
|
rv = AddAttributes(aNode, mHead, PR_FALSE, PR_TRUE);
|
1999-03-20 01:51:00 +00:00
|
|
|
}
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-03-20 01:51:00 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseHead()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseHead()\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::CloseHead",
|
|
|
|
eHTMLTag_head, 0, this);
|
2003-01-03 23:17:22 +00:00
|
|
|
CloseHeadContext();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Open body. Note that we pre-append the body to the root so that
|
|
|
|
// incremental reflow during document loading will work properly.
|
|
|
|
mCurrentContext->SetPreAppend(PR_TRUE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext->SetPreAppend(PR_FALSE);
|
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::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
|
|
|
|
|
|
|
// Check to see if InitialReflow() has been called on any of our
|
|
|
|
// presShells. If so, the InitialReflow() call inside StartLayout()
|
|
|
|
// will be supressed, so we can't rely on it to construct the body
|
|
|
|
// frame for us, so we'll have to manually call NotifyInsert() or
|
|
|
|
// NotifyAppend() to make sure a body frame gets constructed. (Bug 153815)
|
|
|
|
|
|
|
|
PRBool didInitialReflow = PR_FALSE;
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, ns = mDocument->GetNumberOfShells();
|
2002-09-06 05:44:31 +00:00
|
|
|
for (i = 0; i < ns; i++) {
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(i);
|
|
|
|
|
|
|
|
shell->GetDidInitialReflow(&didInitialReflow);
|
|
|
|
if (didInitialReflow) {
|
|
|
|
break;
|
2002-09-06 05:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (didInitialReflow && mCurrentContext->mStackPos > 1) {
|
|
|
|
PRInt32 parentIndex = mCurrentContext->mStackPos - 2;
|
|
|
|
nsIHTMLContent *parent = mCurrentContext->mStack[parentIndex].mContent;
|
|
|
|
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 {
|
|
|
|
// XXX: Would it be better to use |parent->ChildCount() - 1| so
|
|
|
|
// that we don't cause notifications for the <head> element and
|
|
|
|
// it's children?
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
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);
|
2002-11-19 18:29:35 +00:00
|
|
|
mCurrentContext->CloseContainer(eHTMLTag_body);
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
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)) {
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
result = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::form, 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(result, result);
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> content;
|
|
|
|
result = NS_NewHTMLFormElement(getter_AddRefs(content), nodeInfo);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
mCurrentForm = do_QueryInterface(content);
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
result = 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);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> content =
|
|
|
|
dont_AddRef(mCurrentContext->GetCurrentContainer());
|
|
|
|
|
|
|
|
mCurrentForm = do_QueryInterface(content);
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX MAYBE add code to place close form tag into the content model
|
|
|
|
// for navigator layout compatability.
|
|
|
|
NS_IMETHODIMP
|
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)) {
|
|
|
|
mCurrentContext->FlushTextAndRelease();
|
2002-11-19 18:29:35 +00:00
|
|
|
result = mCurrentContext->CloseContainer(eHTMLTag_form);
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !mFrameset &&
|
2001-04-21 22:22:15 +00:00
|
|
|
(mFlags & NS_SINK_FLAG_FRAMES_ENABLED)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
mFrameset =
|
|
|
|
mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_ADDREF(mFrameset);
|
|
|
|
}
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
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;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIHTMLContent* fs = sc->mStack[sc->mStackPos - 1].mContent;
|
1998-08-28 16:20:16 +00:00
|
|
|
PRBool done = fs == mFrameset;
|
2002-11-19 18:29:35 +00:00
|
|
|
nsresult rv = sc->CloseContainer(eHTMLTag_frameset);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenMap(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::OpenMap()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 19:24:42 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-03-01 16:57:35 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::OpenMap",
|
|
|
|
eHTMLTag_map,
|
|
|
|
mCurrentContext->mStackPos,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-03-01 16:57:35 +00:00
|
|
|
// We used to treat MAP elements specially (i.e. they were
|
|
|
|
// only parent elements for AREAs), but we don't anymore.
|
|
|
|
// HTML 4.0 says that MAP elements can have block content
|
|
|
|
// as children.
|
1999-09-14 19:24:42 +00:00
|
|
|
rv = mCurrentContext->OpenContainer(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenMap()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 19:24:42 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseMap()
|
1998-07-12 00:18:26 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseMap()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 19:24:42 +00:00
|
|
|
nsresult rv = NS_OK;
|
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::CloseMap",
|
|
|
|
eHTMLTag_map,
|
|
|
|
mCurrentContext->mStackPos - 1,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
mCurrentMap = nsnull;
|
1999-03-01 16:57:35 +00:00
|
|
|
|
2002-11-19 18:29:35 +00:00
|
|
|
rv = mCurrentContext->CloseContainer(eHTMLTag_map);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseMap()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 19:24:42 +00:00
|
|
|
return rv;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-12 00:18:26 +00:00
|
|
|
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX work around parser bug
|
|
|
|
if (eHTMLTag_frameset == aNode.GetNodeType()) {
|
2001-04-21 22:22:15 +00:00
|
|
|
rv = OpenFrameset(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-04-21 22:22:15 +00:00
|
|
|
rv = mCurrentContext->OpenContainer(aNode);
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX work around parser bug
|
2002-11-19 18:29:35 +00:00
|
|
|
if (eHTMLTag_frameset == aTag) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
2002-11-19 18:29:35 +00:00
|
|
|
return CloseFrameset();
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-04-03 18:32:58 +00:00
|
|
|
nsresult rv = mCurrentContext->CloseContainer(aTag);
|
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
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::AddHeadContent(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddHeadContent()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
|
|
|
|
|
|
|
nsresult rv = OpenHeadContext();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsHTMLTag type = nsHTMLTag(aNode.GetNodeType());
|
|
|
|
if (eHTMLTag_title == type) {
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
if (dtd) {
|
|
|
|
nsAutoString title;
|
|
|
|
PRInt32 lineNo = 0;
|
|
|
|
dtd->CollectSkippedContent(eHTMLTag_title, title, lineNo);
|
|
|
|
rv = SetDocumentTitle(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = AddLeaf(aNode);
|
|
|
|
}
|
|
|
|
CloseHeadContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddHeadContent()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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_area:
|
|
|
|
rv = ProcessAREATag(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
|
|
|
case eHTMLTag_base:
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1998-08-28 16:20:16 +00:00
|
|
|
rv = ProcessBASETag(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
|
|
|
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
|
|
|
case eHTMLTag_meta:
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1998-08-28 16:20:16 +00:00
|
|
|
rv = ProcessMETATag(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
|
|
|
case eHTMLTag_style:
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1998-08-28 16:20:16 +00:00
|
|
|
rv = ProcessSTYLETag(aNode);
|
1998-07-12 00:18:26 +00:00
|
|
|
|
|
|
|
break;
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_script:
|
|
|
|
mCurrentContext->FlushTextAndRelease();
|
|
|
|
rv = ProcessSCRIPTTag(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
|
|
|
|
HTMLContentSink::SetDocumentTitle(const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::SetDocumentTitle()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
|
|
|
NS_ASSERTION(mCurrentContext == mHeadContext, "title not in head");
|
|
|
|
|
|
|
|
if (!mTitle.IsEmpty()) {
|
|
|
|
// If the title was already set then don't try to overwrite it
|
|
|
|
// when a new title is encountered - For backwards compatiblity
|
|
|
|
//*mTitle = aValue;
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::SetDocumentTitle()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTitle.Assign(aTitle);
|
|
|
|
mTitle.CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> domDoc(do_QueryInterface(mHTMLDocument));
|
|
|
|
if (domDoc) {
|
|
|
|
domDoc->SetTitle(mTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsresult rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::title, nsnull,
|
|
|
|
kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2003-01-03 23:17:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTMLContent> it;
|
|
|
|
rv = NS_NewHTMLTitleElement(getter_AddRefs(it), nodeInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITextContent> text;
|
|
|
|
rv = NS_NewTextNode(getter_AddRefs(text));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
text->SetText(mTitle, PR_TRUE);
|
|
|
|
|
|
|
|
it->AppendChildTo(text, PR_FALSE, PR_FALSE);
|
|
|
|
text->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
|
|
|
|
mHead->AppendChildTo(it, PR_FALSE, PR_FALSE);
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::SetDocumentTitle()\n"));
|
|
|
|
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
|
|
|
|
2000-03-28 23:25:26 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mHTMLDocument));
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!doc) {
|
2000-03-28 23:25:26 +00:00
|
|
|
return NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
2000-03-28 23:25:26 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
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()) {
|
2001-12-16 11:58:03 +00:00
|
|
|
name.Assign(NS_LITERAL_STRING("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;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> tmpNode;
|
|
|
|
|
|
|
|
if (oldDocType) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// If we already have a doctype we replace the old one.
|
|
|
|
|
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.
|
2000-03-28 23:25:26 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> firstChild;
|
|
|
|
|
|
|
|
doc->GetFirstChild(getter_AddRefs(firstChild));
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// If the above fails it must be because we don't have any child
|
|
|
|
// nodes, then firstChild will be 0 and InsertBefore() will
|
|
|
|
// append
|
2000-03-28 23:25:26 +00:00
|
|
|
|
|
|
|
rv = doc->InsertBefore(docType, firstChild, getter_AddRefs(tmpNode));
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv), NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2002-03-06 01:00:48 +00:00
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(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
|
|
|
|
// us into interactive mode otherwise. It also supresses reaction
|
|
|
|
// 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();
|
|
|
|
|
2000-02-19 02:34:20 +00:00
|
|
|
// If it's a frameset document then disable scrolling.
|
2000-02-29 06:51:48 +00:00
|
|
|
// Else, reset scrolling to default settings for this shell.
|
|
|
|
// This must happen before the initial reflow, when we create the root frame
|
|
|
|
nsresult rv;
|
2003-04-02 11:18:00 +00:00
|
|
|
nsCOMPtr<nsIScrollable> scrollableContainer = do_QueryInterface(mDocShell);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (scrollableContainer) {
|
2001-03-14 07:35:29 +00:00
|
|
|
if (mFrameset) {
|
2002-09-18 23:31:08 +00:00
|
|
|
scrollableContainer->
|
|
|
|
SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
scrollableContainer->
|
|
|
|
SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
2001-03-14 07:35:29 +00:00
|
|
|
} else {
|
|
|
|
scrollableContainer->ResetScrollbarPreferences();
|
2000-02-29 06:51:48 +00:00
|
|
|
}
|
1998-12-20 23:29:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, ns = mDocument->GetNumberOfShells();
|
1998-08-28 16:20:16 +00:00
|
|
|
for (i = 0; i < ns; i++) {
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(i);
|
2002-09-06 05:44:31 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (shell) {
|
2002-09-06 05:44:31 +00:00
|
|
|
// Make sure we don't call InitialReflow() for a shell that has
|
|
|
|
// already called it. This can happen when the layout frame for
|
|
|
|
// an iframe is constructed *between* the Embed() call for the
|
|
|
|
// docshell in the iframe, and the content sink's call to OpenBody().
|
|
|
|
// (Bug 153815)
|
|
|
|
|
|
|
|
PRBool didInitialReflow = PR_FALSE;
|
|
|
|
shell->GetDidInitialReflow(&didInitialReflow);
|
|
|
|
if (didInitialReflow) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// XXX: The assumption here is that if something already
|
|
|
|
// called InitialReflow() on this shell, it also did some of
|
|
|
|
// the setup below, so we do nothing and just move on to the
|
|
|
|
// next shell in the list.
|
2002-09-06 05:44:31 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make shell an observer for next time
|
|
|
|
shell->BeginObservingDocument();
|
1998-07-12 00:18:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Resize-reflow this time
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
1998-08-28 16:20:16 +00:00
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
1998-09-10 19:32:14 +00:00
|
|
|
shell->InitialReflow(r.width, r.height);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
// Now trigger a refresh
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
1999-05-13 20:27:47 +00:00
|
|
|
RefreshIfEnabled(vm);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// If the document we are loading has a reference or it is a
|
1998-08-28 16:20:16 +00:00
|
|
|
// frameset document, disable the scroll bars on the views.
|
2001-05-17 02:37:30 +00:00
|
|
|
|
|
|
|
if (mDocumentURI) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString ref;
|
2001-05-17 02:37:30 +00:00
|
|
|
|
|
|
|
// Since all URI's that pass through here aren't URL's we can't
|
|
|
|
// rely on the nsIURI implementation for providing a way for
|
|
|
|
// finding the 'ref' part of the URI, we'll haveto revert to
|
|
|
|
// string routines for finding the data past '#'
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = mDocumentURI->GetSpec(ref);
|
2001-05-17 02:37:30 +00:00
|
|
|
|
|
|
|
nsReadingIterator<char> start, end;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
ref.BeginReading(start);
|
|
|
|
ref.EndReading(end);
|
2001-05-17 02:37:30 +00:00
|
|
|
|
|
|
|
if (FindCharInReadable('#', start, end)) {
|
|
|
|
++start; // Skip over the '#'
|
|
|
|
|
|
|
|
mRef = Substring(start, end);
|
2000-11-27 21:43:28 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
|
2001-05-17 02:37:30 +00:00
|
|
|
if (!mRef.IsEmpty() || mFrameset) {
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX support more than one presentation-shell here
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Get initial scroll preference and save it away; disable the
|
|
|
|
// scroll bars.
|
1999-07-05 19:45:27 +00:00
|
|
|
ns = mDocument->GetNumberOfShells();
|
1998-08-28 16:20:16 +00:00
|
|
|
for (i = 0; i < ns; i++) {
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(i);
|
|
|
|
|
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
|
|
|
if (vm) {
|
|
|
|
nsIView* rootView = nsnull;
|
|
|
|
vm->GetRootView(rootView);
|
|
|
|
if (rootView) {
|
|
|
|
nsCOMPtr<nsIScrollableView> sview(do_QueryInterface(rootView));
|
|
|
|
|
|
|
|
if (sview) {
|
|
|
|
sview->SetScrollPreference(nsScrollPreference_kNeverScroll);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-27 21:43:28 +00:00
|
|
|
// Convert the ref from document charset to unicode.
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult
|
2003-06-11 18:16:03 +00:00
|
|
|
CharsetConvRef(const nsCString& aDocCharset, const nsCString& aRefInDocCharset,
|
2002-09-18 23:31:08 +00:00
|
|
|
nsString& aRefInUnicode)
|
2000-11-27 21:43:28 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-11-27 21:43:28 +00:00
|
|
|
nsCOMPtr <nsIAtom> docCharsetAtom;
|
2003-06-11 18:16:03 +00:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> ccm =
|
2002-09-18 23:31:08 +00:00
|
|
|
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUnicodeDecoder> decoder;
|
2003-06-11 18:16:03 +00:00
|
|
|
rv = ccm->GetUnicodeDecoder(aDocCharset.get(), getter_AddRefs(decoder));
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2000-11-27 21:43:28 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
PRInt32 srcLen = aRefInDocCharset.Length();
|
|
|
|
PRInt32 dstLen;
|
|
|
|
rv = decoder->GetMaxLength(aRefInDocCharset.get(), srcLen, &dstLen);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar *ustr = (PRUnichar *)nsMemory::Alloc((dstLen + 1) *
|
|
|
|
sizeof(PRUnichar));
|
|
|
|
if (!ustr) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = decoder->Convert(aRefInDocCharset.get(), &srcLen, ustr, &dstLen);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
ustr[dstLen] = 0;
|
|
|
|
aRefInUnicode.Assign(ustr, dstLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMemory::Free(ustr);
|
|
|
|
|
2000-11-27 21:43:28 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-10-05 10:39:01 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::TryToScrollToRef()
|
|
|
|
{
|
|
|
|
if (mRef.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mScrolledToRefAlready) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-14 01:16:31 +00:00
|
|
|
ScrollToRef(PR_TRUE);
|
2001-10-05 10:39:01 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
2003-03-14 01:16:31 +00:00
|
|
|
HTMLContentSink::ScrollToRef(PRBool aReallyScroll)
|
1998-04-22 22:12:24 +00:00
|
|
|
{
|
2001-08-01 23:04:32 +00:00
|
|
|
// XXX Duplicate code in nsXMLContentSink.
|
|
|
|
// XXX Be sure to change both places if you make changes here.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mRef.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2001-06-21 14:40:55 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
char* tmpstr = ToNewCString(mRef);
|
|
|
|
if (!tmpstr) {
|
|
|
|
return;
|
|
|
|
}
|
2000-11-27 21:43:28 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsUnescape(tmpstr);
|
|
|
|
nsCAutoString unescapedRef;
|
|
|
|
unescapedRef.Assign(tmpstr);
|
|
|
|
nsMemory::Free(tmpstr);
|
2001-05-17 02:37:30 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
// We assume that the bytes are in UTF-8, as it says in the spec:
|
|
|
|
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
|
2003-06-21 00:26:28 +00:00
|
|
|
nsAutoString ref;
|
|
|
|
CopyUTF8toUTF16(unescapedRef, ref);
|
2000-11-27 21:43:28 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, ns = mDocument->GetNumberOfShells();
|
2002-09-18 23:31:08 +00:00
|
|
|
for (i = 0; i < ns; i++) {
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(i);
|
2001-05-17 02:37:30 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
// Scroll to the anchor
|
|
|
|
if (aReallyScroll) {
|
|
|
|
shell->FlushPendingNotifications(PR_FALSE);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
// Check an empty string which might be caused by the UTF-8 conversion
|
|
|
|
if (!ref.IsEmpty()) {
|
|
|
|
rv = shell->GoToAnchor(ref, aReallyScroll);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-05-17 02:37:30 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
// If UTF-8 URL failed then try to assume the string as a
|
|
|
|
// document's charset.
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCAutoString docCharset;
|
|
|
|
rv = mDocument->GetDocumentCharacterSet(docCharset);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-09-27 04:18:26 +00:00
|
|
|
rv = CharsetConvRef(docCharset, unescapedRef, ref);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
|
|
|
|
rv = shell->GoToAnchor(ref, aReallyScroll);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
}
|
2003-09-27 04:18:26 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mScrolledToRefAlready = PR_TRUE;
|
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-24 18:20:27 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::AddBaseTagInfo(nsIHTMLContent* aContent)
|
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!mBaseHREF.IsEmpty()) {
|
2002-05-20 22:47:02 +00:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::_baseHref, mBaseHREF,
|
|
|
|
PR_FALSE);
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!mBaseTarget.IsEmpty()) {
|
2002-05-20 22:47:02 +00:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::_baseTarget,
|
|
|
|
mBaseTarget, PR_FALSE);
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mCurrentMap) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2000-06-08 21:32:09 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> area;
|
|
|
|
nsresult rv = CreateContentObject(aNode, nodeType, nsnull, nsnull,
|
|
|
|
getter_AddRefs(area));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
// Set the content's document
|
2002-09-18 23:31:08 +00:00
|
|
|
area->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
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.
|
|
|
|
AddBaseTagInfo(area);
|
|
|
|
|
|
|
|
// Set the content's attributes
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = AddAttributes(aNode, area);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Add AREA object to the current map
|
|
|
|
mCurrentMap->AppendChildTo(area, PR_FALSE, PR_FALSE);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
2002-03-23 23:13:20 +00:00
|
|
|
HTMLContentSink::ProcessBaseHref(const nsAString& aBaseHref)
|
1999-01-23 07:05:49 +00:00
|
|
|
{
|
2000-05-26 23:28:40 +00:00
|
|
|
//-- Make sure this page is allowed to load this URL
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> baseHrefURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(baseHrefURI), aBaseHref, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
2002-09-16 21:48:25 +00:00
|
|
|
// Setting "BASE URL" from the last BASE tag appearing in HEAD.
|
|
|
|
if (!mBody) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// The document checks if it is legal to set this base
|
|
|
|
rv = mDocument->SetBaseURL(baseHrefURI);
|
|
|
|
|
2001-04-30 23:35:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_RELEASE(mDocumentBaseURL);
|
2003-06-13 20:10:01 +00:00
|
|
|
mDocument->GetBaseURL(&mDocumentBaseURL);
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
|
|
|
// NAV compatibility quirk
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = securityManager->CheckLoadURI(mDocumentBaseURL, baseHrefURI,
|
|
|
|
nsIScriptSecurityManager::STANDARD);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-30 23:35:09 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
mBaseHREF = aBaseHref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
mHeadContext->SetPreAppend(PR_TRUE);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::CloseHeadContext()
|
|
|
|
{
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!vm) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-02 11:18:00 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (contentViewer) {
|
|
|
|
PRBool enabled;
|
|
|
|
contentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
|
|
|
vm->EnableRefresh(NS_VMREFRESH_NO_SYNC);
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
2002-03-23 23:13:20 +00:00
|
|
|
HTMLContentSink::ProcessBaseTarget(const nsAString& aBaseTarget)
|
1999-01-23 07:05:49 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mBody) {
|
|
|
|
// still in real HEAD
|
2001-04-30 23:35:09 +00:00
|
|
|
mDocument->SetBaseTarget(aBaseTarget);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
|
|
|
// NAV compatibility quirk
|
1999-01-23 07:05:49 +00:00
|
|
|
mBaseTarget = aBaseTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-06-16 00:44:50 +00:00
|
|
|
nsresult result = NS_OK;
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* parent = nsnull;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mCurrentContext) {
|
|
|
|
parent = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (parent) {
|
2000-02-11 22:07:12 +00:00
|
|
|
// Create content object
|
|
|
|
nsCOMPtr<nsIHTMLContent> element;
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2002-09-18 23:31:08 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(NS_LITERAL_STRING("base"), nsnull,
|
|
|
|
kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2001-05-12 07:12:33 +00:00
|
|
|
result = NS_CreateHTMLElement(getter_AddRefs(element), nodeInfo, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
|
|
|
|
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
result = AddAttributes(aNode, element);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
parent->AppendChildTo(element, PR_FALSE, PR_FALSE);
|
|
|
|
if (!mInsideNoXXXTag) {
|
|
|
|
nsAutoString value;
|
|
|
|
if (element->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href,
|
|
|
|
value) == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
ProcessBaseHref(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element->GetAttr(kNameSpaceID_None, nsHTMLAtoms::target,
|
|
|
|
value) == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
ProcessBaseTarget(value);
|
1999-06-16 00:44:50 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-06-16 00:44:50 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
const PRUnichar kSemiCh = PRUnichar(';');
|
1999-01-30 06:24:09 +00:00
|
|
|
const PRUnichar kCommaCh = PRUnichar(',');
|
1999-01-23 07:05:49 +00:00
|
|
|
const PRUnichar kEqualsCh = PRUnichar('=');
|
|
|
|
const PRUnichar kLessThanCh = PRUnichar('<');
|
|
|
|
const PRUnichar kGreaterThanCh = PRUnichar('>');
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessLinkHeader(nsIHTMLContent* aElement,
|
|
|
|
const nsAString& aLinkData)
|
1999-01-23 07:05:49 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
// parse link content and call process style link
|
|
|
|
nsAutoString href;
|
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
1999-01-30 06:24:09 +00:00
|
|
|
PRBool didBlock = PR_FALSE;
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// copy to work buffer
|
|
|
|
nsAutoString stringList(aLinkData);
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// put an extra null at the end
|
|
|
|
stringList.Append(kNullCh);
|
|
|
|
|
|
|
|
PRUnichar* start = NS_CONST_CAST(PRUnichar *, stringList.get());
|
1999-01-23 07:05:49 +00:00
|
|
|
PRUnichar* end = start;
|
|
|
|
PRUnichar* last = start;
|
1999-01-30 06:24:09 +00:00
|
|
|
PRUnichar endCh;
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
while (*start != kNullCh) {
|
|
|
|
// skip leading space
|
|
|
|
while ((*start != kNullCh) && nsCRT::IsAsciiSpace(*start)) {
|
|
|
|
++start;
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
last = end - 1;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// look for semicolon or comma
|
|
|
|
while (*end != kNullCh && *end != kSemiCh && *end != kCommaCh) {
|
|
|
|
PRUnichar ch = *end;
|
|
|
|
|
|
|
|
if (ch == kApostrophe || ch == kQuote || ch == kLessThanCh) {
|
|
|
|
// quoted string
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
PRUnichar quote = *end;
|
2002-09-18 23:31:08 +00:00
|
|
|
if (quote == kLessThanCh) {
|
1999-01-23 07:05:49 +00:00
|
|
|
quote = kGreaterThanCh;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
PRUnichar* closeQuote = (end + 1);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// seek closing quote
|
|
|
|
while (*closeQuote != kNullCh && quote != *closeQuote) {
|
|
|
|
++closeQuote;
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (quote == *closeQuote) {
|
|
|
|
// found closer
|
|
|
|
|
|
|
|
// skip to close quote
|
|
|
|
end = closeQuote;
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
last = end - 1;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
ch = *(end + 1);
|
|
|
|
|
|
|
|
if (ch != kNullCh && ch != kSemiCh && ch != kCommaCh) {
|
|
|
|
// end string here
|
|
|
|
*(++end) = kNullCh;
|
|
|
|
|
|
|
|
ch = *(end + 1);
|
|
|
|
|
|
|
|
// keep going until semi or comma
|
|
|
|
while (ch != kNullCh && ch != kSemiCh && ch != kCommaCh) {
|
|
|
|
++end;
|
|
|
|
|
|
|
|
ch = *end;
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
++end;
|
|
|
|
++last;
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
1999-01-30 06:24:09 +00:00
|
|
|
endCh = *end;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// end string here
|
|
|
|
*end = kNullCh;
|
1999-01-23 07:05:49 +00:00
|
|
|
|
|
|
|
if (start < end) {
|
2002-09-18 23:31:08 +00:00
|
|
|
if ((*start == kLessThanCh) && (*last == kGreaterThanCh)) {
|
1999-01-23 07:05:49 +00:00
|
|
|
*last = kNullCh;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-05-19 02:59:15 +00:00
|
|
|
if (href.IsEmpty()) { // first one wins
|
1999-01-30 06:24:09 +00:00
|
|
|
href = (start + 1);
|
|
|
|
href.StripWhitespace();
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
1999-01-23 07:05:49 +00:00
|
|
|
PRUnichar* equals = start;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
while ((*equals != kNullCh) && (*equals != kEqualsCh)) {
|
1999-01-23 07:05:49 +00:00
|
|
|
equals++;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (*equals != kNullCh) {
|
1999-01-23 07:05:49 +00:00
|
|
|
*equals = kNullCh;
|
2000-08-19 22:23:46 +00:00
|
|
|
nsAutoString attr(start);
|
1999-01-23 07:05:49 +00:00
|
|
|
attr.StripWhitespace();
|
|
|
|
|
|
|
|
PRUnichar* value = ++equals;
|
2000-03-12 09:14:14 +00:00
|
|
|
while (nsCRT::IsAsciiSpace(*value)) {
|
1999-01-23 07:05:49 +00:00
|
|
|
value++;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (((*value == kApostrophe) || (*value == kQuote)) &&
|
1999-01-23 07:05:49 +00:00
|
|
|
(*value == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.EqualsIgnoreCase("rel")) {
|
2001-05-19 02:59:15 +00:00
|
|
|
if (rel.IsEmpty()) {
|
1999-01-30 06:24:09 +00:00
|
|
|
rel = value;
|
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (attr.EqualsIgnoreCase("title")) {
|
2001-05-19 02:59:15 +00:00
|
|
|
if (title.IsEmpty()) {
|
1999-01-30 06:24:09 +00:00
|
|
|
title = value;
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (attr.EqualsIgnoreCase("type")) {
|
2001-05-19 02:59:15 +00:00
|
|
|
if (type.IsEmpty()) {
|
1999-01-30 06:24:09 +00:00
|
|
|
type = value;
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (attr.EqualsIgnoreCase("media")) {
|
2002-01-24 02:03:19 +00:00
|
|
|
if (media.IsEmpty()) {
|
1999-01-30 06:24:09 +00:00
|
|
|
media = value;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
ToLowerCase(media);
|
1999-01-30 06:24:09 +00:00
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (endCh == kCommaCh) {
|
|
|
|
// hit a comma, process what we've got so far
|
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
if (!href.IsEmpty() && !rel.IsEmpty()) {
|
|
|
|
result = ProcessLink(aElement, href, rel, title, type, media);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (result == NS_ERROR_HTMLPARSER_BLOCK) {
|
1999-01-30 06:24:09 +00:00
|
|
|
didBlock = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-01-30 06:24:09 +00:00
|
|
|
href.Truncate();
|
|
|
|
rel.Truncate();
|
|
|
|
title.Truncate();
|
|
|
|
type.Truncate();
|
|
|
|
media.Truncate();
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
if (!href.IsEmpty() && !rel.IsEmpty()) {
|
|
|
|
result = ProcessLink(aElement, href, rel, title, type, media);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
if (NS_SUCCEEDED(result) && didBlock) {
|
1999-01-23 07:05:49 +00:00
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-11 03:12:13 +00:00
|
|
|
HTMLContentSink::ProcessLink(nsIHTMLContent* aElement,
|
|
|
|
const nsString& aHref, const nsString& aRel,
|
|
|
|
const nsString& aTitle, const nsString& aType,
|
|
|
|
const nsString& aMedia)
|
1999-01-23 07:05:49 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
// XXX seems overkill to generate this string array
|
1999-05-26 23:49:33 +00:00
|
|
|
nsStringArray linkTypes;
|
2001-05-19 02:59:15 +00:00
|
|
|
nsStyleLinkElement::ParseLinkTypes(aRel, linkTypes);
|
2002-09-11 03:12:13 +00:00
|
|
|
|
2003-03-06 21:37:09 +00:00
|
|
|
PRBool hasPrefetch = (linkTypes.IndexOf(NS_LITERAL_STRING("prefetch")) != -1);
|
2002-10-03 02:53:18 +00:00
|
|
|
// prefetch href if relation is "next" or "prefetch"
|
2003-03-06 21:37:09 +00:00
|
|
|
if (hasPrefetch || linkTypes.IndexOf(NS_LITERAL_STRING("next")) != -1) {
|
|
|
|
PrefetchHref(aHref, hasPrefetch);
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// is it a stylesheet link?
|
|
|
|
if (linkTypes.IndexOf(NS_LITERAL_STRING("stylesheet")) != -1) {
|
|
|
|
result = ProcessStyleLink(aElement, aHref, linkTypes, aTitle, aType,
|
|
|
|
aMedia);
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessStyleLink(nsIHTMLContent* aElement,
|
2002-09-18 23:31:08 +00:00
|
|
|
const nsString& aHref,
|
|
|
|
const nsStringArray& aLinkTypes,
|
|
|
|
const nsString& aTitle,
|
|
|
|
const nsString& aType,
|
2002-09-11 03:12:13 +00:00
|
|
|
const nsString& aMedia)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
PRBool isAlternate = PR_FALSE;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// if alternate, does it have title?
|
|
|
|
if (aLinkTypes.IndexOf(NS_LITERAL_STRING("alternate")) != -1) {
|
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
// return without error, for now
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
isAlternate = PR_TRUE;
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
nsParserUtils::SplitMimeType(aType, mimeType, params);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// see bug 18817
|
2002-11-27 03:42:37 +00:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.EqualsIgnoreCase("text/css")) {
|
|
|
|
// Unknown stylesheet language
|
|
|
|
return NS_OK;
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
result = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentBaseURL);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
// The URL is bad, move along, don't propagate the error (for now)
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
if (!isAlternate) {
|
|
|
|
// possibly preferred sheet
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
if (!aTitle.IsEmpty()) {
|
|
|
|
nsAutoString preferredStyle;
|
|
|
|
mDocument->GetHeaderData(nsHTMLAtoms::headerDefaultStyle,
|
|
|
|
preferredStyle);
|
|
|
|
if (preferredStyle.IsEmpty()) {
|
|
|
|
mDocument->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, aTitle);
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
2002-09-11 03:12:13 +00:00
|
|
|
}
|
2002-11-27 03:42:37 +00:00
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
PRBool blockParser = kBlockByDefault;
|
|
|
|
if (isAlternate) {
|
|
|
|
blockParser = PR_FALSE;
|
|
|
|
}
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
// NOTE: no longer honoring the important keyword to indicate
|
|
|
|
// blocking as it is proprietary and unnecessary since all
|
|
|
|
// non-alternate will block the parser now -mja
|
2002-09-18 23:31:08 +00:00
|
|
|
#if 0
|
2002-11-27 03:42:37 +00:00
|
|
|
if (linkTypes.IndexOf("important") != -1) {
|
|
|
|
blockParser = PR_TRUE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
#endif
|
2002-09-11 03:12:13 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
PRBool doneLoading;
|
|
|
|
result = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia,
|
|
|
|
((blockParser) ? mParser : nsnull),
|
|
|
|
doneLoading,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-11-27 03:42:37 +00:00
|
|
|
if (NS_SUCCEEDED(result) && blockParser && !doneLoading) {
|
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
void
|
2003-03-06 21:37:09 +00:00
|
|
|
HTMLContentSink::PrefetchHref(const nsAString &aHref, PRBool aExplicit)
|
2002-09-11 03:12:13 +00:00
|
|
|
{
|
2002-10-24 03:17:44 +00:00
|
|
|
//
|
|
|
|
// SECURITY CHECK: disable prefetching from mailnews!
|
|
|
|
//
|
|
|
|
// walk up the docshell tree to see if any containing
|
|
|
|
// docshell are of type MAIL.
|
|
|
|
//
|
2003-04-02 11:18:00 +00:00
|
|
|
if (!mDocShell)
|
2002-10-24 03:17:44 +00:00
|
|
|
return;
|
2003-04-02 11:18:00 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell = mDocShell;
|
|
|
|
|
2002-10-24 03:17:44 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem, parentItem;
|
|
|
|
do {
|
2003-04-02 11:18:00 +00:00
|
|
|
PRUint32 appType = 0;
|
2002-10-24 03:17:44 +00:00
|
|
|
nsresult rv = docshell->GetAppType(&appType);
|
|
|
|
if (NS_FAILED(rv) || appType == nsIDocShell::APP_TYPE_MAIL)
|
|
|
|
return; // do not prefetch from mailnews
|
|
|
|
if (treeItem = do_QueryInterface(docshell)) {
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
|
|
|
treeItem = parentItem;
|
|
|
|
docshell = do_QueryInterface(treeItem);
|
|
|
|
if (!docshell) {
|
|
|
|
NS_ERROR("cannot get a docshell from a treeItem!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (parentItem);
|
|
|
|
|
|
|
|
// OK, we passed the security check...
|
|
|
|
|
2002-09-11 03:12:13 +00:00
|
|
|
nsCOMPtr<nsIPrefetchService> prefetchService(
|
|
|
|
do_GetService(NS_PREFETCHSERVICE_CONTRACTID));
|
|
|
|
if (prefetchService) {
|
|
|
|
// construct URI using document charset
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString charset;
|
2002-09-11 03:12:13 +00:00
|
|
|
mDocument->GetDocumentCharacterSet(charset);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), aHref,
|
2003-06-17 16:40:34 +00:00
|
|
|
charset.IsEmpty() ? nsnull : charset.get(),
|
2002-09-11 03:12:13 +00:00
|
|
|
mDocumentBaseURL);
|
|
|
|
if (uri)
|
2003-03-06 21:37:09 +00:00
|
|
|
prefetchService->PrefetchURI(uri, mDocumentURI, aExplicit);
|
2002-09-11 03:12:13 +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;
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* 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
|
|
|
|
2003-04-03 18:32:58 +00:00
|
|
|
// XXX - Hack to fix the crash reported in bug 197015; Once the real
|
|
|
|
// problem, in CSSLoader, is fixed then this hack could be removed.
|
|
|
|
// Close the head context, that got opened up by the link tag, because
|
|
|
|
// our CSSLoader, on loading the linked style sheet, calls the parser's
|
|
|
|
// ContinueParsing() even if the parser is not blocked and that causes
|
|
|
|
// the sink, whose current context is head, to go haywire.
|
|
|
|
// Note: CSS loading is initiated before unwinding off this stack and
|
|
|
|
// therefore the sink never got the chance to close its head context.
|
|
|
|
CloseHeadContext();
|
|
|
|
|
2001-06-14 12:33:38 +00:00
|
|
|
if (parent) {
|
2000-02-11 22:07:12 +00:00
|
|
|
// Create content object
|
2001-05-19 02:59:15 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> 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
|
|
|
|
2001-05-19 02:59:15 +00:00
|
|
|
result = NS_CreateHTMLElement(getter_AddRefs(element), nodeInfo, PR_FALSE);
|
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
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
2001-05-19 02:59:15 +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.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
result = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
parent->AppendChildTo(element, PR_FALSE, PR_FALSE);
|
|
|
|
|
|
|
|
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-03-01 16:57:35 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessMAPTag(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aContent)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentMap = nsnull;
|
1999-03-01 16:57:35 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> domMap(do_QueryInterface(aContent));
|
|
|
|
if (!domMap) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-03-01 16:57:35 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// We used to strip whitespace from the NAME attribute here, to
|
|
|
|
// match a 4.x quirk, but it proved too quirky for us, and IE never
|
|
|
|
// did that. See bug 79738 for details.
|
1999-03-01 16:57:35 +00:00
|
|
|
|
|
|
|
// Don't need to add the map to the document here anymore.
|
|
|
|
// The map adds itself
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentMap = aContent;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-03-01 16:57:35 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* parent = nsnull;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mCurrentContext) {
|
|
|
|
parent = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!parent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Create content object
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(NS_LITERAL_STRING("meta"), nsnull,
|
|
|
|
kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTMLContent> it;
|
|
|
|
rv = NS_NewHTMLMetaElement(getter_AddRefs(it), nodeInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Add in the attributes and add the meta content object to the head
|
|
|
|
// container.
|
|
|
|
it->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
rv = AddAttributes(aNode, it);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->AppendChildTo(it, PR_FALSE, PR_FALSE);
|
|
|
|
|
|
|
|
// XXX It's just not sufficient to check if the parent is head. Also
|
|
|
|
// check for the preference.
|
|
|
|
if (!mInsideNoXXXTag) {
|
|
|
|
// Bug 40072: Don't evaluate METAs after FRAMESET.
|
|
|
|
|
|
|
|
if (!mFrameset) {
|
|
|
|
// set any HTTP-EQUIV data into document's header data as well as url
|
|
|
|
nsAutoString header;
|
|
|
|
it->GetAttr(kNameSpaceID_None, nsHTMLAtoms::httpEquiv, header);
|
|
|
|
|
|
|
|
if (!header.IsEmpty()) {
|
|
|
|
nsAutoString result;
|
|
|
|
it->GetAttr(kNameSpaceID_None, nsHTMLAtoms::content, result);
|
|
|
|
|
|
|
|
if (!result.IsEmpty()) {
|
|
|
|
ToLowerCase(header);
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> fieldAtom = do_GetAtom(header);
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = ProcessHeaderData(fieldAtom, result, it);
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessHTTPHeaders(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aChannel, "can't process http headers without a channel");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpchannel(do_QueryInterface(aChannel));
|
|
|
|
|
|
|
|
if (!httpchannel) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
const char *const headers[] = {
|
|
|
|
"link",
|
|
|
|
"default-style",
|
|
|
|
"content-style-type",
|
|
|
|
// add more http headers if you need
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *const *name = headers;
|
|
|
|
nsCAutoString tmp;
|
|
|
|
|
|
|
|
while (*name) {
|
|
|
|
rv = httpchannel->GetResponseHeader(nsDependentCString(*name), tmp);
|
|
|
|
if (NS_SUCCEEDED(rv) && !tmp.IsEmpty()) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> key = do_GetAtom(*name);
|
2002-09-18 23:31:08 +00:00
|
|
|
ProcessHeaderData(key, NS_ConvertASCIItoUCS2(tmp));
|
|
|
|
}
|
|
|
|
name++;
|
|
|
|
}
|
2001-03-03 00:39:29 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
|
|
|
|
nsIHTMLContent* aContent)
|
2001-03-03 00:39:29 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// XXX necko isn't going to process headers coming in from the
|
|
|
|
// parser
|
2001-08-22 00:38:46 +00:00
|
|
|
|
|
|
|
mDocument->SetHeaderData(aHeader, aValue);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
|
|
|
|
2001-03-03 00:39:29 +00:00
|
|
|
// see if we have a refresh "header".
|
|
|
|
if (aHeader == nsHTMLAtoms::refresh) {
|
|
|
|
// first get our baseURI
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-03-03 00:39:29 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2003-04-02 11:18:00 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mDocShell);
|
2001-03-03 00:39:29 +00:00
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-04-20 08:11:12 +00:00
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mDocShell);
|
2001-04-20 08:11:12 +00:00
|
|
|
if (reefer) {
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = reefer->SetupRefreshURIFromHeader(baseURI,
|
|
|
|
NS_ConvertUCS2toUTF8(aValue));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-03 00:39:29 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (aHeader == nsHTMLAtoms::setcookie) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookieService> cookieServ =
|
|
|
|
do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-07-02 17:58:24 +00:00
|
|
|
|
|
|
|
// Get a URI from the document principal
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// We use the original codebase in case the codebase was changed
|
|
|
|
// by SetDomain
|
|
|
|
|
2002-07-02 17:58:24 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> docPrincipal;
|
|
|
|
rv = mDocument->GetPrincipal(getter_AddRefs(docPrincipal));
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv) || !docPrincipal) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-07-02 17:58:24 +00:00
|
|
|
|
2003-08-22 03:06:53 +00:00
|
|
|
nsCOMPtr<nsIAggregatePrincipal> agg(do_QueryInterface(docPrincipal, &rv));
|
|
|
|
// Document principal should always be an aggregate
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-02 17:58:24 +00:00
|
|
|
|
2003-08-22 03:06:53 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> originalPrincipal;
|
|
|
|
rv = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> originalCodebase =
|
|
|
|
do_QueryInterface(originalPrincipal, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// Document's principal is not a codebase (may be system), so
|
|
|
|
// can't set cookies
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-07-02 17:58:24 +00:00
|
|
|
}
|
|
|
|
|
2003-08-22 03:06:53 +00:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2001-04-30 23:35:09 +00:00
|
|
|
char *cookie = ToNewUTF8String(aValue);
|
2001-03-29 02:11:48 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
if (globalObj) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
|
|
|
if (window) {
|
|
|
|
window->GetPrompter(getter_AddRefs(prompt));
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-05-05 21:27:02 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2001-11-16 15:05:53 +00:00
|
|
|
if (mParser) {
|
2003-05-05 21:27:02 +00:00
|
|
|
mParser->GetChannel(getter_AddRefs(channel));
|
2001-11-16 15:05:53 +00:00
|
|
|
}
|
|
|
|
|
2003-05-05 21:27:02 +00:00
|
|
|
rv = cookieServ->SetCookieString(codebaseURI, prompt, cookie, channel);
|
2001-03-29 02:11:48 +00:00
|
|
|
nsCRT::free(cookie);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else if (aHeader == nsHTMLAtoms::link) {
|
2002-09-11 03:12:13 +00:00
|
|
|
rv = ProcessLinkHeader(aContent, aValue);
|
2002-09-21 01:03:38 +00:00
|
|
|
}
|
|
|
|
else if (aHeader == nsHTMLAtoms::msthemecompatible) {
|
|
|
|
// Disable theming for the presshell if the value is no.
|
|
|
|
nsAutoString value(aValue);
|
|
|
|
if (value.EqualsIgnoreCase("no")) {
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *shell = mDocument->GetShellAt(0);
|
2002-09-21 01:03:38 +00:00
|
|
|
if (shell)
|
|
|
|
shell->DisableThemeSupport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mParser) {
|
2001-08-22 00:38:46 +00:00
|
|
|
// we also need to report back HTTP-EQUIV headers to the channel
|
|
|
|
// so that it can process things like pragma: no-cache or other
|
|
|
|
// cache-control headers. Ideally this should also be the way for
|
|
|
|
// cookies to be set! But we'll worry about that in the next
|
|
|
|
// iteration
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
2003-03-25 18:55:59 +00:00
|
|
|
const char* header;
|
|
|
|
(void)aHeader->GetUTF8String(&header);
|
|
|
|
(void)httpChannel->SetResponseHeader(nsDependentCString(header),
|
|
|
|
NS_ConvertUCS2toUTF8(aValue),
|
|
|
|
PR_TRUE);
|
2001-08-22 00:38:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-03-03 00:39:29 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2002-11-25 08:33:30 +00:00
|
|
|
NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(HTMLContentSink)
|
|
|
|
NS_IMPL_NSIDOCUMENTOBSERVER_REFLOW_STUB(HTMLContentSink)
|
|
|
|
NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(HTMLContentSink)
|
|
|
|
NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(HTMLContentSink)
|
2003-10-02 21:29:40 +00:00
|
|
|
NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(HTMLContentSink)
|
2002-11-25 08:33:30 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHODIMP
|
2003-10-02 21:29:40 +00:00
|
|
|
HTMLContentSink::BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
2000-01-28 23:43:12 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
// 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
|
|
|
|
// continue
|
2003-04-21 23:51:17 +00:00
|
|
|
if (!mInNotification && mCurrentContext) {
|
2000-01-28 23:43:12 +00:00
|
|
|
result = mCurrentContext->FlushTags(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHODIMP
|
2003-10-02 21:29:40 +00:00
|
|
|
HTMLContentSink::EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
|
2000-01-28 23:43:12 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
|
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
|
|
|
|
// has been flushed to include any new content.
|
2003-04-21 23:51:17 +00:00
|
|
|
if (!mInNotification) {
|
2000-01-28 23:43:12 +00:00
|
|
|
UpdateAllContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-25 08:33:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ResumeParsing()
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mParser) {
|
2002-09-18 23:31:08 +00:00
|
|
|
result = mParser->ContinueParsing();
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-07-27 23:33:16 +00:00
|
|
|
return result;
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 02:08:04 +00:00
|
|
|
PRBool
|
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);
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->SetPreAppend(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 02:08:04 +00:00
|
|
|
void
|
2001-05-17 05:54:16 +00:00
|
|
|
HTMLContentSink::PostEvaluateScript()
|
1999-04-13 22:22:51 +00:00
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->SetPreAppend(PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
NS_IMETHODIMP
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::ScriptAvailable(nsresult aResult,
|
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
2001-05-17 05:54:16 +00:00
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending,
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIURI *aURI,
|
|
|
|
PRInt32 aLineNo,
|
2001-05-17 05:54:16 +00:00
|
|
|
const nsAString& aScript)
|
1998-12-15 06:10:59 +00:00
|
|
|
{
|
2001-05-17 05:54:16 +00:00
|
|
|
// Check if this is the element we were waiting for
|
|
|
|
PRUint32 count;
|
2002-02-12 21:17:53 +00:00
|
|
|
mScriptElements->Count(&count);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement =
|
2002-09-18 23:31:08 +00:00
|
|
|
do_QueryElementAt(mScriptElements, count - 1);
|
|
|
|
if (aElement != scriptElement) {
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2001-06-29 09:59:45 +00:00
|
|
|
if (mParser && !mParser->IsParserEnabled()) {
|
2001-03-13 07:23:15 +00:00
|
|
|
// make sure to unblock the parser before evaluating the script,
|
|
|
|
// we must unblock the parser even if loading the script failed or
|
|
|
|
// if the script was empty, if we don't, the parser will never be
|
|
|
|
// unblocked.
|
|
|
|
mParser->UnblockParser();
|
|
|
|
}
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
// Mark the current script as loaded
|
|
|
|
mNeedToBlockParser = PR_FALSE;
|
2000-04-14 02:47:28 +00:00
|
|
|
|
2003-07-31 01:28:16 +00:00
|
|
|
if (NS_SUCCEEDED(aResult) && aResult != NS_CONTENT_SCRIPT_IS_EVENTHANDLER) {
|
2001-05-17 05:54:16 +00:00
|
|
|
PreEvaluateScript();
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
|
|
|
mScriptElements->RemoveElementAt(count - 1);
|
|
|
|
|
|
|
|
if (mParser && aWasPending) {
|
2001-08-17 22:24:39 +00:00
|
|
|
// Loading external script failed!. So, resume
|
|
|
|
// parsing since the parser got blocked when loading
|
|
|
|
// external script. - Ref. Bug: 94903
|
|
|
|
mParser->ContinueParsing();
|
|
|
|
}
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-25 01:21:21 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::ScriptEvaluated(nsresult aResult,
|
2001-05-17 05:54:16 +00:00
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending)
|
|
|
|
{
|
|
|
|
// Check if this is the element we were waiting for
|
|
|
|
PRUint32 count;
|
2002-02-12 21:17:53 +00:00
|
|
|
mScriptElements->Count(&count);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement =
|
2002-09-18 23:31:08 +00:00
|
|
|
do_QueryElementAt(mScriptElements, count - 1);
|
|
|
|
if (aElement != scriptElement) {
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
// Pop the script element stack
|
2002-09-18 23:31:08 +00:00
|
|
|
mScriptElements->RemoveElementAt(count - 1);
|
2000-03-25 01:21:21 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
if (NS_SUCCEEDED(aResult)) {
|
|
|
|
PostEvaluateScript();
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mParser && mParser->IsParserEnabled() && aWasPending) {
|
2001-05-17 05:54:16 +00:00
|
|
|
mParser->ContinueParsing();
|
2001-02-09 22:36:23 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
1998-06-25 22:26:52 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-07-02 20:59:39 +00:00
|
|
|
// Create content object
|
1999-12-08 23:05:14 +00:00
|
|
|
NS_ASSERTION(mCurrentContext->mStackPos > 0, "leaf w/o container");
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mCurrentContext->mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-01-10 12:31:41 +00:00
|
|
|
|
|
|
|
// Inserting the element into the document may execute a script.
|
|
|
|
// This can potentially make the parent go away. So, hold
|
|
|
|
// on to it till we are done.
|
|
|
|
nsCOMPtr<nsIHTMLContent> parent =
|
2002-09-18 23:31:08 +00:00
|
|
|
mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2001-05-17 05:54:16 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> element;
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::script, nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(element), nodeInfo, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1999-07-02 20:59:39 +00:00
|
|
|
}
|
2001-05-17 05:54:16 +00:00
|
|
|
|
|
|
|
PRInt32 id;
|
2002-09-18 23:31:08 +00:00
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
2001-05-17 05:54:16 +00:00
|
|
|
element->SetContentID(id);
|
|
|
|
|
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
rv = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-07-02 20:59:39 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2002-04-10 22:16:46 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
|
|
|
|
|
2002-11-07 05:17:21 +00:00
|
|
|
nsCOMPtr<nsIScriptElement> sele(do_QueryInterface(element));
|
2002-04-10 22:16:46 +00:00
|
|
|
nsAutoString script;
|
|
|
|
PRInt32 lineNo = 0;
|
|
|
|
|
|
|
|
dtd->CollectSkippedContent(eHTMLTag_script, script, lineNo);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
if (sele) {
|
2002-04-10 22:16:46 +00:00
|
|
|
sele->SetLineNumber((PRUint32)lineNo);
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Create a text node holding the content. First, get the text
|
|
|
|
// content of the script tag
|
1999-07-02 20:59:39 +00:00
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!script.IsEmpty()) {
|
2002-11-21 23:53:06 +00:00
|
|
|
nsCOMPtr<nsITextContent> text;
|
2001-05-17 05:54:16 +00:00
|
|
|
rv = NS_NewTextNode(getter_AddRefs(text));
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-11-21 23:53:06 +00:00
|
|
|
text->SetText(script, PR_TRUE);
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
element->AppendChildTo(text, PR_FALSE, PR_FALSE);
|
|
|
|
text->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
1999-07-02 20:59:39 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
2002-10-11 00:38:29 +00:00
|
|
|
loader->SetEnabled(PR_FALSE);
|
2001-06-18 21:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-06-18 21:18:37 +00:00
|
|
|
// Don't include script loading and evaluation in the stopwatch
|
|
|
|
// that is measuring content creation time
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::ProcessSCRIPTTag()\n"));
|
|
|
|
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
|
|
|
|
2003-07-31 01:28:16 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement = do_QueryInterface(element);
|
2002-02-12 21:17:53 +00:00
|
|
|
mScriptElements->AppendElement(scriptElement);
|
2001-06-18 21:18:37 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
// Insert the child into the content tree. This will evaluate the
|
|
|
|
// script as well.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(element,
|
|
|
|
mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mInsertionPoint++,
|
2001-06-18 21:18:37 +00:00
|
|
|
PR_FALSE, PR_FALSE);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2001-05-17 05:54:16 +00:00
|
|
|
parent->AppendChildTo(element, PR_FALSE, PR_FALSE);
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +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.
|
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
|
|
|
|
HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* parent = nsnull;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-05-29 08:10:58 +00:00
|
|
|
if (mCurrentContext) {
|
|
|
|
parent = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!parent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Create content object
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::style, nsnull, kNameSpaceID_None,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
1999-08-31 11:17:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> element;
|
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(element), nodeInfo, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-29 08:10:58 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
2001-05-29 08:10:58 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(element);
|
2000-02-11 22:07:12 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
rv = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// The skipped content contains the inline style data
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsAutoString content;
|
|
|
|
PRInt32 lineNo = 0;
|
2000-02-11 22:07:12 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
dtd->CollectSkippedContent(eHTMLTag_style, content, lineNo);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!content.IsEmpty()) {
|
|
|
|
// Create a text node holding the content
|
2002-11-21 23:53:06 +00:00
|
|
|
nsCOMPtr<nsITextContent> text;
|
2002-09-18 23:31:08 +00:00
|
|
|
rv = NS_NewTextNode(getter_AddRefs(text));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-11-21 23:53:06 +00:00
|
|
|
text->SetText(content, PR_TRUE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
element->AppendChildTo(text, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->AppendChildTo(element, PR_FALSE, PR_FALSE);
|
|
|
|
|
|
|
|
if (ssle) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-01-24 06:43:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::FlushPendingNotifications()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2000-01-28 23:43:12 +00:00
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
2002-09-18 23:31:08 +00:00
|
|
|
// (since we aren't reentrant) and if we're in a script (since we
|
|
|
|
// only care to flush if this is done via script).
|
|
|
|
//
|
|
|
|
// Bug 4891: Also flush outside of <script> tags - if script is
|
|
|
|
// executing after the page has finished loading, and a
|
|
|
|
// document.write occurs, we might need this flush.
|
2000-07-08 00:19:44 +00:00
|
|
|
if (mCurrentContext && !mInNotification) {
|
2000-01-24 06:43:15 +00:00
|
|
|
result = mCurrentContext->FlushTags();
|
|
|
|
}
|
2000-01-28 23:43:12 +00:00
|
|
|
|
|
|
|
return result;
|
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) {
|
|
|
|
return mDocument->SetDocumentCharacterSet(aCharset);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsresult result = NS_OK;
|
|
|
|
FILE* out = ::fopen("rtest_html.txt", "a");
|
|
|
|
if (out) {
|
|
|
|
if (mDocument) {
|
2001-06-20 03:27:48 +00:00
|
|
|
nsIContent* root = nsnull;
|
|
|
|
mDocument->GetRootContent(&root);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (root) {
|
|
|
|
if (mDocumentURI) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString buf;
|
|
|
|
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);
|
|
|
|
result = root->DumpContent(out, 0, PR_FALSE);
|
|
|
|
fputs(";\n", out);
|
2000-05-26 19:45:49 +00:00
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2000-05-26 19:45:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
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) {
|
|
|
|
rv = mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
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) {
|
|
|
|
rv = mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loadGroup && mDummyParserRequest) {
|
|
|
|
rv = loadGroup->RemoveRequest(mDummyParserRequest, nsnull, NS_OK);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDummyParserRequest = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|