1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +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
|
|
|
*
|
1999-11-06 03:40:37 +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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-13 20:24:54 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-04-14 02:47:28 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContentSink.h"
|
1998-12-11 17:02:37 +00:00
|
|
|
#include "nsIParser.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"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
1999-05-18 23:05:43 +00:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIURL.h"
|
2000-02-02 23:04:47 +00:00
|
|
|
#include "nsIStreamLoader.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"
|
1999-05-13 20:27:47 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
1999-02-16 07:38:27 +00:00
|
|
|
#include "nsHTMLTokens.h"
|
1998-08-11 00:19:11 +00:00
|
|
|
#include "nsHTMLEntities.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCRT.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"
|
|
|
|
|
|
|
|
#include "nsHTMLParts.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-03-28 23:25:26 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDOMImplementation.h"
|
|
|
|
#include "nsIDOMDocumentType.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"
|
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"
|
|
|
|
#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"
|
|
|
|
#include "nsIHTTPChannel.h"
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-07-18 21:47:56 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-03-11 00:34:54 +00:00
|
|
|
#include "nsIDocShell.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"
|
1999-04-27 22:14:17 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1999-09-11 17:28:36 +00:00
|
|
|
#include "nsTextFragment.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIParserService.h"
|
|
|
|
#include "nsParserCIID.h"
|
1999-11-11 22:15:02 +00:00
|
|
|
#include "nsISelectElement.h"
|
1999-09-30 22:07:04 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
#include "nsIPref.h"
|
|
|
|
|
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"
|
|
|
|
#include "nsITimerCallback.h"
|
1999-11-02 23:44:27 +00:00
|
|
|
#include "nsDOMError.h"
|
2000-02-29 06:51:48 +00:00
|
|
|
#include "nsIScrollable.h"
|
1999-09-14 14:38:52 +00:00
|
|
|
|
2000-02-16 06:50:39 +00:00
|
|
|
#ifdef ALLOW_ASYNCH_STYLE_SHEETS
|
2000-04-05 04:02:38 +00:00
|
|
|
const PRBool kBlockByDefault=PR_FALSE;
|
2000-02-16 06:50:39 +00:00
|
|
|
#else
|
2000-04-05 04:02:38 +00:00
|
|
|
const PRBool kBlockByDefault=PR_TRUE;
|
2000-02-16 06:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
1998-09-03 22:23:09 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLTitleElementIID, NS_IDOMHTMLTITLEELEMENT_IID);
|
1998-11-26 01:29:10 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
1998-09-03 22:23:09 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
1998-09-06 00:20:59 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
1999-01-22 22:48:00 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
1998-09-23 17:16:51 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
|
1999-01-09 00:14:53 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLMapElementIID, NS_IDOMHTMLMAPELEMENT_IID);
|
1998-09-23 17:16:51 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
1998-08-28 16:20:16 +00:00
|
|
|
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
|
|
|
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID);
|
|
|
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
1998-09-23 17:16:51 +00:00
|
|
|
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
|
1999-05-18 23:05:43 +00:00
|
|
|
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
|
1998-12-15 06:10:59 +00:00
|
|
|
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
1999-02-23 19:18:12 +00:00
|
|
|
static NS_DEFINE_IID(kIStyleSheetLinkingElementIID, NS_ISTYLESHEETLINKINGELEMENT_IID);
|
1999-12-04 01:27:46 +00:00
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
2000-03-25 01:21:21 +00:00
|
|
|
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
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
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_TRACE_CALLS 0x1
|
|
|
|
#define SINK_TRACE_REFLOW 0x2
|
1999-04-03 19:00:23 +00:00
|
|
|
#define SINK_ALWAYS_REFLOW 0x4
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_LOG_TEST(_lm,_bit) (PRIntn((_lm)->level) & (_bit))
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_TRACE(_bit,_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo,_bit)) { \
|
|
|
|
PR_LogPrint _args; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
1998-07-11 03:51:50 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit,_msg,_node,_sp,_obj) _obj->SinkTraceNode(_bit,_msg,_node,_sp,this)
|
1998-07-11 03:51:50 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#else
|
|
|
|
#define SINK_TRACE(_bit,_args)
|
1999-10-26 14:55:51 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit,_msg,_node,_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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
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,
|
2000-02-02 23:04:47 +00:00
|
|
|
public nsIStreamLoaderObserver,
|
1999-12-04 01:27:46 +00:00
|
|
|
public nsITimerCallback,
|
2000-01-28 23:43:12 +00:00
|
|
|
public nsICSSLoaderObserver,
|
|
|
|
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
|
|
|
|
|
1998-07-18 21:47:56 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1998-07-18 21:47:56 +00:00
|
|
|
nsIWebShell* aContainer);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
2000-02-02 23:04:47 +00:00
|
|
|
NS_DECL_NSISTREAMLOADEROBSERVER
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsIContentSink
|
|
|
|
NS_IMETHOD WillBuildModel(void);
|
|
|
|
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
|
|
|
NS_IMETHOD WillInterrupt(void);
|
|
|
|
NS_IMETHOD WillResume(void);
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD SetParser(nsIParser* aParser);
|
|
|
|
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD NotifyError(const nsParserError* aError);
|
2000-01-24 06:43:15 +00:00
|
|
|
NS_IMETHOD FlushPendingNotifications();
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
1999-07-28 06:56:05 +00:00
|
|
|
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
|
1999-07-26 05:40:25 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsIHTMLContentSink
|
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);
|
|
|
|
NS_IMETHOD CloseHTML(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseHead(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseBody(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseForm(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseFrameset(const nsIParserNode& aNode);
|
1998-07-20 18:52:40 +00:00
|
|
|
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
|
|
|
|
NS_IMETHOD CloseMap(const nsIParserNode& aNode);
|
1999-07-26 05:40:25 +00:00
|
|
|
|
1999-03-15 05:11:43 +00:00
|
|
|
NS_IMETHOD DoFragment(PRBool aFlag);
|
1998-05-07 21:11:07 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
// nsITimerCallback
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHOD_(void) Notify(nsITimer *timer);
|
1999-12-04 01:27:46 +00:00
|
|
|
|
|
|
|
// nsICSSLoaderObserver
|
|
|
|
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify);
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
// nsIDocumentObserver
|
|
|
|
NS_IMETHOD BeginUpdate(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD EndUpdate(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
|
|
|
|
nsIPresShell* aShell) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndReflow(nsIDocument *aDocument,
|
|
|
|
nsIPresShell* aShell) { return NS_OK; }
|
|
|
|
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent) { return NS_OK; }
|
|
|
|
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2) { return NS_OK; }
|
|
|
|
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint) { return NS_OK; }
|
|
|
|
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{ return NS_OK; }
|
|
|
|
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer) { return NS_OK; }
|
|
|
|
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer) { return NS_OK; }
|
|
|
|
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule) { return NS_OK; }
|
|
|
|
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool IsTimeToNotify();
|
1999-10-26 14:55:51 +00:00
|
|
|
PRBool IsInScript();
|
1999-09-30 22:07:04 +00:00
|
|
|
void ReduceEntities(nsString& aString);
|
|
|
|
void GetAttributeValueAt(const nsIParserNode& aNode,
|
|
|
|
PRInt32 aIndex,
|
1999-12-03 09:24:22 +00:00
|
|
|
nsString& aResult);
|
1999-09-30 22:07:04 +00:00
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aContent,
|
|
|
|
PRBool aNotify = PR_FALSE);
|
|
|
|
nsresult CreateContentObject(const nsIParserNode& aNode,
|
|
|
|
nsHTMLTag aNodeType,
|
|
|
|
nsIDOMHTMLFormElement* aForm,
|
|
|
|
nsIWebShell* aWebShell,
|
|
|
|
nsIHTMLContent** aResult);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void SinkTraceNode(PRUint32 aBit,
|
|
|
|
const char* aMsg,
|
|
|
|
const nsIParserNode& aNode,
|
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;
|
1999-08-27 21:52:19 +00:00
|
|
|
nsIURI* mDocumentURI;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* mDocumentBaseURL;
|
2000-03-07 21:08:46 +00:00
|
|
|
nsCOMPtr<nsIURI> mScriptURI;
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIWebShell* mWebShell;
|
1998-12-11 17:02:37 +00:00
|
|
|
nsIParser* mParser;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool mNotifyOnTimer; // Do we notify based on time?
|
|
|
|
PRInt32 mBackoffCount; // back off timer notification after count
|
|
|
|
PRInt32 mNotificationInterval; // Notification interval in microseconds
|
|
|
|
PRTime mLastNotificationTime; // Time of last notification
|
|
|
|
nsCOMPtr<nsITimer> mNotificationTimer; // Timer used for notification
|
|
|
|
|
2000-01-31 23:39:19 +00:00
|
|
|
PRInt32 mMaxTextRun; // The maximum length of a text run
|
|
|
|
|
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;
|
1998-08-28 16:20:16 +00:00
|
|
|
nsString* mTitle;
|
2000-03-25 01:21:21 +00:00
|
|
|
nsString mUnicodeXferBuf;
|
2000-04-14 02:47:28 +00:00
|
|
|
nsString mScriptCharset;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-09-12 19:33:48 +00:00
|
|
|
PRBool mLayoutStarted;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mInScript;
|
2000-01-28 23:43:12 +00:00
|
|
|
PRInt32 mInNotification;
|
1998-09-23 17:16:51 +00:00
|
|
|
nsIDOMHTMLFormElement* mCurrentForm;
|
1999-01-09 00:14:53 +00:00
|
|
|
nsIHTMLContent* mCurrentMap;
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
nsVoidArray mContextStack;
|
|
|
|
SinkContext* mCurrentContext;
|
|
|
|
SinkContext* mHeadContext;
|
1999-09-16 23:30:51 +00:00
|
|
|
PRInt32 mNumOpenIFRAMES;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
nsString* mRef;
|
|
|
|
nsScrollPreference mOriginalScrollPreference;
|
|
|
|
PRBool mNotAtRef;
|
|
|
|
nsIHTMLContent* mRefContent;
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
nsString mBaseHREF;
|
|
|
|
nsString mBaseTarget;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
nsString mPreferredStyle;
|
|
|
|
PRInt32 mStyleSheetCount;
|
|
|
|
nsICSSLoader* mCSSLoader;
|
|
|
|
PRInt32 mInsideNoXXXTag;
|
2000-02-16 23:43:59 +00:00
|
|
|
PRInt32 mInMonolithicContainer;
|
1999-01-23 07:05:49 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void StartLayout();
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void ScrollToRef();
|
1998-05-08 20:18:06 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void AddBaseTagInfo(nsIHTMLContent* aContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
nsresult ProcessLink(nsIHTMLContent* aElement, const nsString& aLinkData);
|
|
|
|
nsresult ProcessStyleLink(nsIHTMLContent* aElement,
|
|
|
|
const nsString& aHref, const nsString& aRel,
|
|
|
|
const nsString& aTitle, const nsString& aType,
|
1999-05-26 23:49:33 +00:00
|
|
|
const nsString& aMedia);
|
1999-01-23 07:05:49 +00:00
|
|
|
|
|
|
|
void ProcessBaseHref(const nsString& aBaseHref);
|
|
|
|
void ProcessBaseTarget(const nsString& 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 ProcessATag(const nsIParserNode& aNode, nsIHTMLContent* aContent);
|
|
|
|
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
|
|
|
|
|
|
|
// Script processing related routines
|
|
|
|
nsresult ResumeParsing();
|
1999-05-18 02:08:04 +00:00
|
|
|
PRBool PreEvaluateScript();
|
|
|
|
void PostEvaluateScript(PRBool aBodyPresent);
|
1998-12-15 06:10:59 +00:00
|
|
|
nsresult EvaluateScript(nsString& aScript,
|
2000-03-07 21:08:46 +00:00
|
|
|
nsIURI *aScriptURI,
|
(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
|
|
|
PRInt32 aLineNo,
|
2000-03-23 04:53:16 +00:00
|
|
|
const char* aVersion);
|
(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
|
|
|
const char* mScriptLanguageVersion;
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void UpdateAllContexts();
|
|
|
|
void NotifyAppend(nsIContent* aContent,
|
|
|
|
PRInt32 aStartIndex);
|
|
|
|
void NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer);
|
2000-02-16 23:43:59 +00:00
|
|
|
PRBool IsMonolithicContainer(nsHTMLTag aTag);
|
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
|
|
|
|
1999-11-11 21:35:34 +00:00
|
|
|
MOZ_TIMER_DECLARE(mWatch) // Measures content model creation time for current document
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-06-23 22:25:28 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
class SinkContext {
|
|
|
|
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.
|
|
|
|
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
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsIHTMLContent* aRoot,
|
|
|
|
PRInt32 aNumFlushed, PRInt32 aInsertionPoint);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult OpenContainer(const nsIParserNode& aNode);
|
|
|
|
nsresult CloseContainer(const nsIParserNode& aNode);
|
|
|
|
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);
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult DemoteContainer(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();
|
|
|
|
nsresult AddText(const nsString& aText);
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult FlushText(PRBool* aDidFlush = nsnull, PRBool aReleaseLast = PR_FALSE);
|
|
|
|
nsresult FlushTextAndRelease(PRBool* aDidFlush = nsnull)
|
|
|
|
{
|
|
|
|
return FlushText(aDidFlush, PR_TRUE);
|
|
|
|
}
|
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
|
|
|
|
1999-10-27 14:03:15 +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;
|
|
|
|
nsIContent* 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;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mNumFlushed;
|
|
|
|
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-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
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,
|
|
|
|
const nsIParserNode& aNode,
|
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
|
|
|
{
|
1999-09-30 22:07:04 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo,aBit)) {
|
|
|
|
char cbuf[40];
|
|
|
|
const char* cp;
|
|
|
|
nsAutoString str;
|
|
|
|
PRInt32 nt = aNode.GetNodeType();
|
|
|
|
if ((nt > PRInt32(eHTMLTag_unknown)) &&
|
|
|
|
(nt < PRInt32(eHTMLTag_text)) && mParser) {
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
dtd->IntTagToStringTag(nsHTMLTag(aNode.GetNodeType()), str);
|
|
|
|
cp = str.ToCString(cbuf, sizeof(cbuf));
|
|
|
|
} else {
|
|
|
|
aNode.GetText().ToCString(cbuf, sizeof(cbuf));
|
|
|
|
cp = cbuf;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
PR_LogPrint("%s: this=%p node='%s' stackPos=%d", aMsg, aThis, cp, aStackPos);
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::ReduceEntities(nsString& aString)
|
|
|
|
{
|
|
|
|
if (mParser) {
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
|
|
|
|
nsresult rv = mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
|
|
|
// Reduce any entities
|
|
|
|
// XXX Note: as coded today, this will only convert well formed
|
|
|
|
// entities. This may not be compatible enough.
|
|
|
|
// XXX there is a table in navigator that translates some numeric entities
|
|
|
|
// should we be doing that? If so then it needs to live in two places (bad)
|
|
|
|
// so we should add a translate numeric entity method from the parser...
|
|
|
|
char cbuf[100];
|
|
|
|
PRInt32 i = 0;
|
|
|
|
while (i < aString.Length()) {
|
|
|
|
// If we have the start of an entity (and it's not at the end of
|
|
|
|
// our string) then translate the entity into it's unicode value.
|
|
|
|
if ((aString.CharAt(i++) == '&') && (i < aString.Length())) {
|
|
|
|
PRInt32 start = i - 1;
|
|
|
|
PRUnichar e = aString.CharAt(i);
|
|
|
|
if (e == '#') {
|
|
|
|
// Convert a numeric character reference
|
1999-07-05 19:45:27 +00:00
|
|
|
i++;
|
1999-09-30 22:07:04 +00:00
|
|
|
char* cp = cbuf;
|
|
|
|
char* limit = cp + sizeof(cbuf) - 1;
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
PRInt32 slen = aString.Length();
|
|
|
|
while ((i < slen) && (cp < limit)) {
|
|
|
|
e = aString.CharAt(i);
|
|
|
|
if (e == ';') {
|
|
|
|
i++;
|
|
|
|
ok = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((e >= '0') && (e <= '9')) {
|
|
|
|
*cp++ = char(e);
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ok || (cp == cbuf)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
if (cp - cbuf > 5) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PRInt32 ch = PRInt32( ::atoi(cbuf) );
|
|
|
|
if (ch > 65535) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove entity from string and replace it with the integer
|
|
|
|
// value.
|
|
|
|
aString.Cut(start, i - start);
|
|
|
|
aString.Insert(PRUnichar(ch), start);
|
|
|
|
i = start + 1;
|
1998-08-31 17:51:32 +00:00
|
|
|
}
|
1999-09-30 22:07:04 +00:00
|
|
|
else if (((e >= 'A') && (e <= 'Z')) ||
|
|
|
|
((e >= 'a') && (e <= 'z'))) {
|
|
|
|
// Convert a named entity
|
1999-07-05 19:45:27 +00:00
|
|
|
i++;
|
1999-09-30 22:07:04 +00:00
|
|
|
char* cp = cbuf;
|
|
|
|
char* limit = cp + sizeof(cbuf) - 1;
|
|
|
|
*cp++ = char(e);
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
PRInt32 slen = aString.Length();
|
|
|
|
while ((i < slen) && (cp < limit)) {
|
|
|
|
e = aString.CharAt(i);
|
|
|
|
if (e == ';') {
|
|
|
|
i++;
|
|
|
|
ok = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (((e >= '0') && (e <= '9')) ||
|
|
|
|
((e >= 'A') && (e <= 'Z')) ||
|
|
|
|
((e >= 'a') && (e <= 'z'))) {
|
|
|
|
*cp++ = char(e);
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ok || (cp == cbuf)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
PRInt32 ch;
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString str; str.AssignWithConversion(cbuf);
|
1999-09-30 22:07:04 +00:00
|
|
|
dtd->ConvertEntityToUnicode(str, &ch);
|
1998-08-31 17:51:32 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
if (ch < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove entity from string and replace it with the integer
|
|
|
|
// value.
|
|
|
|
aString.Cut(start, i - start);
|
|
|
|
aString.Insert(PRUnichar(ch), start);
|
|
|
|
i = start + 1;
|
1998-08-31 17:51:32 +00:00
|
|
|
}
|
1999-09-30 22:07:04 +00:00
|
|
|
else if (e == '{') {
|
|
|
|
// Convert a script entity
|
|
|
|
// XXX write me!
|
1998-08-31 17:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-15 22:31:10 +00:00
|
|
|
}
|
|
|
|
|
1998-11-17 16:29:25 +00:00
|
|
|
// Temporary factory code to create content objects
|
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode,
|
|
|
|
PRInt32 aIndex,
|
1999-12-03 09:24:22 +00:00
|
|
|
nsString& aResult)
|
1998-11-17 16:29:25 +00:00
|
|
|
{
|
|
|
|
// Copy value
|
2000-02-11 12:10:40 +00:00
|
|
|
const nsString& value = aNode.GetValueAt(aIndex);
|
1998-11-17 16:29:25 +00:00
|
|
|
aResult.Truncate();
|
|
|
|
aResult.Append(value);
|
2000-04-21 21:59:53 +00:00
|
|
|
aResult.Trim("\b\r\t\n",PR_TRUE,PR_TRUE,PR_TRUE);
|
1998-11-17 16:29:25 +00:00
|
|
|
|
|
|
|
// Strip quotes if present
|
|
|
|
PRUnichar first = aResult.First();
|
1999-02-04 16:28:16 +00:00
|
|
|
if ((first == '\"') || (first == '\'')) {
|
1998-11-17 16:29:25 +00:00
|
|
|
if (aResult.Last() == first) {
|
|
|
|
aResult.Cut(0, 1);
|
|
|
|
PRInt32 pos = aResult.Length() - 1;
|
|
|
|
if (pos >= 0) {
|
|
|
|
aResult.Cut(pos, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Mismatched quotes - leave them in
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReduceEntities(aResult);
|
|
|
|
}
|
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aContent,
|
|
|
|
PRBool aNotify)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add tag attributes to the content attributes
|
|
|
|
nsAutoString k, v;
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
// Get upper-cased key
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
k.Truncate();
|
|
|
|
k.Append(key);
|
1999-02-12 06:19:07 +00:00
|
|
|
k.ToLowerCase();
|
1998-09-22 02:09:26 +00:00
|
|
|
|
|
|
|
nsIAtom* keyAtom = NS_NewAtom(k);
|
|
|
|
nsHTMLValue value;
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1998-09-22 02:09:26 +00:00
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE ==
|
1998-12-20 01:21:23 +00:00
|
|
|
aContent->GetHTMLAttribute(keyAtom, value)) {
|
1998-09-22 02:09:26 +00:00
|
|
|
// Get value and remove mandatory quotes
|
1999-12-03 09:24:22 +00:00
|
|
|
GetAttributeValueAt(aNode, i, v);
|
1998-06-26 16:12:51 +00:00
|
|
|
|
1998-09-22 02:09:26 +00:00
|
|
|
// Add attribute to content
|
1999-04-25 22:18:49 +00:00
|
|
|
aContent->SetAttribute(kNameSpaceID_HTML, keyAtom, v,aNotify);
|
1998-09-22 02:09:26 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(keyAtom);
|
1998-06-26 16:12:51 +00:00
|
|
|
}
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-06 19:55:57 +00:00
|
|
|
static
|
1998-09-23 17:16:51 +00:00
|
|
|
void SetForm(nsIHTMLContent* aContent, nsIDOMHTMLFormElement* aForm)
|
|
|
|
{
|
|
|
|
nsIFormControl* formControl = nsnull;
|
|
|
|
nsresult result = aContent->QueryInterface(kIFormControlIID, (void**)&formControl);
|
|
|
|
if ((NS_OK == result) && formControl) {
|
|
|
|
formControl->SetForm(aForm);
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-03 22:23:09 +00:00
|
|
|
// XXX compare switch statement against nsHTMLTags.h's list
|
1998-08-28 16:20:16 +00:00
|
|
|
static nsresult
|
1998-09-01 01:37:17 +00:00
|
|
|
MakeContentObject(nsHTMLTag aNodeType,
|
1999-08-31 11:17:26 +00:00
|
|
|
nsIAtom* aAtom,
|
|
|
|
nsIDOMHTMLFormElement* aForm,
|
|
|
|
nsIWebShell* aWebShell,
|
|
|
|
nsIHTMLContent** aResult,
|
|
|
|
const nsString* aContent = nsnull)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch (aNodeType) {
|
1998-09-03 22:23:09 +00:00
|
|
|
default:
|
|
|
|
rv = NS_NewHTMLSpanElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
|
1998-08-29 03:17:02 +00:00
|
|
|
case eHTMLTag_a:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLAnchorElement(aResult, aAtom);
|
1998-08-29 03:17:02 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_applet:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLAppletElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_area:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLAreaElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_base:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLBaseElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_basefont:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLBaseFontElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1999-04-13 22:22:51 +00:00
|
|
|
case eHTMLTag_blockquote:
|
|
|
|
rv = NS_NewHTMLQuoteElement(aResult, aAtom);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_body:
|
1998-09-03 22:23:09 +00:00
|
|
|
rv = NS_NewHTMLBodyElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_br:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLBRElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1998-10-13 21:31:26 +00:00
|
|
|
case eHTMLTag_button:
|
|
|
|
rv = NS_NewHTMLButtonElement(aResult, aAtom);
|
|
|
|
SetForm(*aResult, aForm);
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_caption:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableCaptionElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_col:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableColElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_colgroup:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableColGroupElement(aResult, aAtom);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_dir:
|
|
|
|
rv = NS_NewHTMLDirectoryElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_div:
|
1999-11-22 06:16:25 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
|
|
|
case eHTMLTag_noscript:
|
1999-03-11 05:26:53 +00:00
|
|
|
case eHTMLTag_parsererror:
|
|
|
|
case eHTMLTag_sourcetext:
|
1998-09-03 22:23:09 +00:00
|
|
|
rv = NS_NewHTMLDivElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_dl:
|
|
|
|
rv = NS_NewHTMLDListElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_embed:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLEmbedElement(aResult, aAtom);
|
|
|
|
break;
|
1998-10-08 04:38:41 +00:00
|
|
|
case eHTMLTag_fieldset:
|
|
|
|
rv = NS_NewHTMLFieldSetElement(aResult, aAtom);
|
|
|
|
SetForm(*aResult, aForm);
|
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_font:
|
|
|
|
rv = NS_NewHTMLFontElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-02 23:53:49 +00:00
|
|
|
case eHTMLTag_form:
|
1998-09-23 17:16:51 +00:00
|
|
|
// the form was already created
|
|
|
|
if (aForm) {
|
|
|
|
rv = aForm->QueryInterface(kIHTMLContentIID, (void**)aResult);
|
|
|
|
}
|
1998-11-16 06:16:17 +00:00
|
|
|
else {
|
|
|
|
rv = NS_NewHTMLFormElement(aResult, aAtom);
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_frame:
|
1998-09-09 23:30:30 +00:00
|
|
|
rv = NS_NewHTMLFrameElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_frameset:
|
1998-09-09 23:30:30 +00:00
|
|
|
rv = NS_NewHTMLFrameSetElement(aResult, aAtom);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_h1:
|
|
|
|
case eHTMLTag_h2:
|
|
|
|
case eHTMLTag_h3:
|
|
|
|
case eHTMLTag_h4:
|
|
|
|
case eHTMLTag_h5:
|
|
|
|
case eHTMLTag_h6:
|
|
|
|
rv = NS_NewHTMLHeadingElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1998-09-02 23:53:49 +00:00
|
|
|
case eHTMLTag_head:
|
|
|
|
rv = NS_NewHTMLHeadElement(aResult, aAtom);
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_hr:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLHRElement(aResult, aAtom);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1999-06-28 23:41:01 +00:00
|
|
|
case eHTMLTag_html:
|
|
|
|
rv = NS_NewHTMLHtmlElement(aResult, aAtom);
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_iframe:
|
1998-09-09 23:30:30 +00:00
|
|
|
rv = NS_NewHTMLIFrameElement(aResult, aAtom);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_img:
|
|
|
|
rv = NS_NewHTMLImageElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_input:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLInputElement(aResult, aAtom);
|
1998-09-23 17:16:51 +00:00
|
|
|
SetForm(*aResult, aForm);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_isindex:
|
|
|
|
rv = NS_NewHTMLIsIndexElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_label:
|
|
|
|
rv = NS_NewHTMLLabelElement(aResult, aAtom);
|
1998-10-22 23:00:37 +00:00
|
|
|
SetForm(*aResult, aForm);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_legend:
|
|
|
|
rv = NS_NewHTMLLegendElement(aResult, aAtom);
|
2000-02-11 01:18:41 +00:00
|
|
|
SetForm(*aResult, aForm);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_li:
|
|
|
|
rv = NS_NewHTMLLIElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-01 01:37:17 +00:00
|
|
|
case eHTMLTag_link:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLLinkElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_map:
|
|
|
|
rv = NS_NewHTMLMapElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_menu:
|
|
|
|
rv = NS_NewHTMLMenuElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-01 01:37:17 +00:00
|
|
|
case eHTMLTag_meta:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLMetaElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_object:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLObjectElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_ol:
|
|
|
|
rv = NS_NewHTMLOListElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_optgroup:
|
|
|
|
rv = NS_NewHTMLOptGroupElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-01 01:37:17 +00:00
|
|
|
case eHTMLTag_option:
|
1998-09-23 17:16:51 +00:00
|
|
|
rv = NS_NewHTMLOptionElement(aResult, aAtom);
|
1998-09-03 22:23:09 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_p:
|
|
|
|
rv = NS_NewHTMLParagraphElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_pre:
|
|
|
|
rv = NS_NewHTMLPreElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_param:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLParamElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_q:
|
|
|
|
rv = NS_NewHTMLQuoteElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-01 01:37:17 +00:00
|
|
|
case eHTMLTag_script:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLScriptElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_select:
|
1998-09-23 17:16:51 +00:00
|
|
|
rv = NS_NewHTMLSelectElement(aResult, aAtom);
|
|
|
|
SetForm(*aResult, aForm);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1998-09-01 01:37:17 +00:00
|
|
|
case eHTMLTag_spacer:
|
1998-09-04 00:52:49 +00:00
|
|
|
rv = NS_NewHTMLSpacerElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_style:
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLStyleElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_table:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_tbody:
|
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tfoot:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableSectionElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_td:
|
|
|
|
case eHTMLTag_th:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableCellElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_textarea:
|
|
|
|
rv = NS_NewHTMLTextAreaElement(aResult, aAtom);
|
1998-09-23 17:16:51 +00:00
|
|
|
// XXX why is textarea not a container. If it were, this code would not be necessary
|
|
|
|
// If the text area has some content, set it
|
|
|
|
if (aContent && (aContent->Length() > 0)) {
|
|
|
|
nsIDOMHTMLTextAreaElement* taElem;
|
|
|
|
rv = (*aResult)->QueryInterface(kIDOMHTMLTextAreaElementIID, (void **)&taElem);
|
|
|
|
if ((NS_OK == rv) && taElem) {
|
|
|
|
taElem->SetDefaultValue(*aContent);
|
|
|
|
NS_RELEASE(taElem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetForm(*aResult, aForm);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_title:
|
|
|
|
rv = NS_NewHTMLTitleElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_tr:
|
1998-09-15 17:58:24 +00:00
|
|
|
rv = NS_NewHTMLTableRowElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_ul:
|
|
|
|
rv = NS_NewHTMLUListElement(aResult, aAtom);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_wbr:
|
1998-09-04 01:03:20 +00:00
|
|
|
rv = NS_NewHTMLWBRElement(aResult, aAtom);
|
1998-09-01 01:37:17 +00:00
|
|
|
break;
|
2000-04-05 01:46:48 +00:00
|
|
|
case eHTMLTag_layer:
|
|
|
|
case eHTMLTag_ilayer:
|
|
|
|
case eHTMLTag_nolayer:
|
|
|
|
case eHTMLTag_unknown:
|
|
|
|
case eHTMLTag_userdefined:
|
|
|
|
rv = NS_NewHTMLUnknownElement(aResult, aAtom);
|
|
|
|
break;
|
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;
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
#if 0
|
|
|
|
// XXX is this logic needed by nsDOMHTMLOptionElement?
|
|
|
|
void
|
|
|
|
GetOptionText(const nsIParserNode& aNode, nsString& aText)
|
|
|
|
{
|
|
|
|
aText.SetLength(0);
|
|
|
|
switch (aNode.GetTokenType()) {
|
|
|
|
case eToken_text:
|
|
|
|
case eToken_whitespace:
|
|
|
|
case eToken_newline:
|
|
|
|
aText.Append(aNode.GetText());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eToken_entity:
|
|
|
|
{
|
|
|
|
nsAutoString tmp2("");
|
|
|
|
PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp2);
|
|
|
|
if (unicode < 0) {
|
|
|
|
aText.Append(aNode.GetText());
|
|
|
|
} else {
|
|
|
|
aText.Append(tmp2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsAutoString x;
|
|
|
|
char* y = aText.ToNewCString();
|
|
|
|
printf("foo");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-09-01 01:37:17 +00:00
|
|
|
/**
|
|
|
|
* Factory subroutine to create all of the html content objects.
|
|
|
|
*/
|
1999-09-30 22:07:04 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
|
|
|
|
nsHTMLTag aNodeType,
|
|
|
|
nsIDOMHTMLFormElement* aForm,
|
|
|
|
nsIWebShell* aWebShell,
|
|
|
|
nsIHTMLContent** aResult)
|
1998-09-01 01:37:17 +00:00
|
|
|
{
|
1999-09-30 22:07:04 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1998-09-01 01:37:17 +00:00
|
|
|
// Find/create atom for the tag name
|
|
|
|
nsAutoString tmp;
|
|
|
|
if (eHTMLTag_userdefined == aNodeType) {
|
|
|
|
tmp.Append(aNode.GetText());
|
1999-02-12 06:19:07 +00:00
|
|
|
tmp.ToLowerCase();
|
1998-09-01 01:37:17 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-09-30 22:07:04 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
rv = mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString str;
|
|
|
|
dtd->IntTagToStringTag(aNodeType, str);
|
|
|
|
tmp.Append(str);
|
|
|
|
}
|
1998-09-01 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
if (nsnull == atom) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-04-28 00:21:13 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
// Make the content object
|
|
|
|
// XXX why is textarea not a container?
|
|
|
|
nsAutoString content;
|
|
|
|
if (eHTMLTag_textarea == aNodeType) {
|
2000-04-15 20:15:37 +00:00
|
|
|
content.Assign(aNode.GetSkippedContent());
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
|
|
|
rv = MakeContentObject(aNodeType, atom, aForm, aWebShell,
|
|
|
|
aResult, &content);
|
2000-03-21 03:25:16 +00:00
|
|
|
|
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
(*aResult)->SetContentID(id);
|
1999-09-30 22:07:04 +00:00
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
|
1998-09-01 01:37:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
|
|
|
|
|
1998-09-01 01:37:17 +00:00
|
|
|
nsresult
|
|
|
|
NS_CreateHTMLElement(nsIHTMLContent** aResult, const nsString& aTag)
|
|
|
|
{
|
1999-09-30 22:07:04 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-09-01 01:37:17 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
NS_WITH_SERVICE(nsIParserService,
|
|
|
|
parserService,
|
|
|
|
kParserServiceCID,
|
|
|
|
&rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Find tag in tag table
|
|
|
|
PRInt32 id;
|
|
|
|
rv = parserService->HTMLStringTagToId(aTag, &id);
|
|
|
|
if (eHTMLTag_userdefined == nsHTMLTag(id)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create atom for tag and then create content object
|
|
|
|
nsAutoString tag;
|
|
|
|
rv = parserService->HTMLIdToStringTag(id, tag);
|
|
|
|
nsIAtom* atom = NS_NewAtom(tag.GetUnicode());
|
|
|
|
rv = MakeContentObject(nsHTMLTag(id), atom, nsnull, nsnull, aResult);
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2000-01-06 23:36:45 +00:00
|
|
|
nsresult
|
|
|
|
NS_CreateHTMLElement(nsIHTMLContent** aResult, PRInt32 aID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (eHTMLTag_userdefined == nsHTMLTag(aID)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIParserService,
|
|
|
|
parserService,
|
|
|
|
kParserServiceCID,
|
|
|
|
&rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Create atom for tag and then create content object
|
|
|
|
nsAutoString tag;
|
|
|
|
rv = parserService->HTMLIdToStringTag(aID, tag);
|
|
|
|
nsIAtom* atom = NS_NewAtom(tag.GetUnicode());
|
|
|
|
rv = MakeContentObject(nsHTMLTag(aID), atom, nsnull, nsnull, aResult);
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-05-06 19:26:43 +00:00
|
|
|
|
2000-01-19 03:10:06 +00:00
|
|
|
class nsHTMLElementFactory : public nsIElementFactory {
|
1999-05-06 19:26:43 +00:00
|
|
|
public:
|
|
|
|
nsHTMLElementFactory();
|
|
|
|
virtual ~nsHTMLElementFactory();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CreateInstanceByTag(const nsString& aTag,
|
2000-01-19 03:10:06 +00:00
|
|
|
nsIContent** aResult);
|
1999-05-06 19:26:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2000-01-19 03:10:06 +00:00
|
|
|
NS_NewHTMLElementFactory(nsIElementFactory** aInstancePtrResult)
|
1999-05-06 19:26:43 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aInstancePtrResult, "null OUT ptr");
|
|
|
|
if (!aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsHTMLElementFactory* it = new nsHTMLElementFactory();
|
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-02-02 22:24:56 +00:00
|
|
|
return it->QueryInterface(NS_GET_IID(nsIElementFactory),
|
1999-05-06 19:26:43 +00:00
|
|
|
(void**)aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::~nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-19 03:10:06 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLElementFactory, nsIElementFactory);
|
1999-05-06 19:26:43 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLElementFactory::CreateInstanceByTag(const nsString& aTag,
|
2000-01-19 03:10:06 +00:00
|
|
|
nsIContent** aResult)
|
1999-05-06 19:26:43 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-19 03:10:06 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent;
|
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(htmlContent), aTag);
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(htmlContent);
|
|
|
|
*aResult = content;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-05-06 19:26:43 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(SinkContext);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext::SinkContext(HTMLContentSink* aSink)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(SinkContext);
|
1998-08-28 16:20:16 +00:00
|
|
|
mSink = aSink;
|
|
|
|
mPreAppend = PR_FALSE;
|
1999-10-26 14:55:51 +00:00
|
|
|
mNotifyLevel = 0;
|
1998-08-31 18:40:39 +00:00
|
|
|
mStack = nsnull;
|
1998-08-28 16:20:16 +00:00
|
|
|
mStackSize = 0;
|
|
|
|
mStackPos = 0;
|
|
|
|
mText = nsnull;
|
|
|
|
mTextLength = 0;
|
|
|
|
mTextSize = 0;
|
1999-10-26 14:55:51 +00:00
|
|
|
mLastTextNode = nsnull;
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize = 0;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SinkContext::~SinkContext()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(SinkContext);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull != mStack) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (nsnull != mText) {
|
|
|
|
delete [] mText;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
NS_IF_RELEASE(mLastTextNode);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-10-26 14:55:51 +00:00
|
|
|
SinkContext::Begin(nsHTMLTag aNodeType,
|
|
|
|
nsIHTMLContent* aRoot,
|
|
|
|
PRInt32 aNumFlushed,
|
|
|
|
PRInt32 aInsertionPoint)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
if (1 > mStackSize) {
|
|
|
|
nsresult rv = GrowStack();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (aTag == mStack[mStackPos-1].mType) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
PRBool
|
|
|
|
SinkContext::IsAncestorContainer(nsHTMLTag aTag)
|
|
|
|
{
|
|
|
|
PRInt32 stackPos = mStackPos-1;
|
|
|
|
|
|
|
|
while (stackPos >= 0) {
|
|
|
|
if (aTag == mStack[stackPos].mType) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLContent*
|
|
|
|
SinkContext::GetCurrentContainer()
|
|
|
|
{
|
|
|
|
nsIHTMLContent* content = mStack[mStackPos-1].mContent;
|
|
|
|
NS_ADDREF(content);
|
|
|
|
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
|
|
|
PRInt32 childCount;
|
|
|
|
|
|
|
|
// If there was a notification done for this content, update the
|
|
|
|
// parent's notification count.
|
|
|
|
if (aDidNotify && (0 < mStackPos)) {
|
|
|
|
nsIContent* parent = mStack[mStackPos-1].mContent;
|
|
|
|
parent->ChildCount(childCount);
|
|
|
|
mStack[mStackPos-1].mNumFlushed = childCount;
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
if ((2 == mStackPos) &&
|
1998-08-28 16:20:16 +00:00
|
|
|
(mSink->mBody == mStack[1].mContent)) {
|
|
|
|
// 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
|
|
|
|
// an insertion happen, we need to do an immediate
|
|
|
|
// notification for that insertion.
|
1999-10-29 19:07:24 +00:00
|
|
|
if (!aDidNotify && (0 < mStackPos) &&
|
1999-10-26 14:55:51 +00:00
|
|
|
(mStack[mStackPos-1].mInsertionPoint != -1)) {
|
|
|
|
nsIContent* parent = mStack[mStackPos-1].mContent;
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Tracing code
|
|
|
|
char cbuf[40];
|
|
|
|
const char* cp;
|
|
|
|
nsAutoString str;
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mSink->mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
dtd->IntTagToStringTag(nsHTMLTag(mStack[mStackPos-1].mType), str);
|
|
|
|
cp = str.ToCString(cbuf, sizeof(cbuf));
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::DidAddContent: Insertion notification for parent=%s at position=%d and stackPos=%d",
|
|
|
|
cp, mStack[mStackPos-1].mInsertionPoint-1, mStackPos-1));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mSink->NotifyInsert(parent,
|
|
|
|
aContent,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint-1);
|
|
|
|
parent->ChildCount(childCount);
|
|
|
|
mStack[mStackPos-1].mNumFlushed = childCount;
|
|
|
|
}
|
1999-12-04 01:27:46 +00:00
|
|
|
else if (!aDidNotify && mSink->IsTimeToNotify()) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"SinkContext::OpenContainer", aNode, 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();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
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;
|
1999-09-30 22:07:04 +00:00
|
|
|
rv = mSink->CreateContentObject(aNode, nodeType,
|
|
|
|
mSink->mCurrentForm,
|
|
|
|
mSink->mFrameset ? mSink->mWebShell : nsnull,
|
|
|
|
&content);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1999-11-19 15:41:30 +00:00
|
|
|
nsresult srv;
|
|
|
|
nsCOMPtr<nsISelectElement> select = do_QueryInterface(content, &srv);
|
|
|
|
if (NS_SUCCEEDED(srv)) {
|
|
|
|
srv = select->DoneAddingContent(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
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;
|
1998-10-26 23:26:01 +00:00
|
|
|
content->SetDocument(mSink->mDocument, PR_FALSE);
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
|
|
|
mSink->mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
|
|
|
|
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-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;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIHTMLContent* parent = mStack[mStackPos-1].mContent;
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[mStackPos].mFlags |= APPENDED;
|
|
|
|
}
|
|
|
|
mStackPos++;
|
1998-07-20 18:52:40 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mSink->IsMonolithicContainer(nodeType)) {
|
|
|
|
mSink->mInMonolithicContainer++;
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
case eHTMLTag_nolayer:
|
|
|
|
case eHTMLTag_noscript:
|
|
|
|
mSink->mInsideNoXXXTag++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_a:
|
|
|
|
mSink->ProcessATag(aNode, content);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_table:
|
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tbody:
|
|
|
|
case eHTMLTag_tfoot:
|
|
|
|
case eHTMLTag_tr:
|
|
|
|
case eHTMLTag_td:
|
|
|
|
case eHTMLTag_th:
|
|
|
|
// XXX if navigator_quirks_mode (only body in html supports background)
|
|
|
|
mSink->AddBaseTagInfo(content);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_map:
|
|
|
|
mSink->ProcessMAPTag(aNode, content);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES++;
|
|
|
|
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
|
|
|
|
SinkContext::CloseContainer(const nsIParserNode& aNode)
|
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();
|
|
|
|
|
1998-07-20 18:52:40 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"SinkContext::CloseContainer", aNode, mStackPos-1, mSink);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
--mStackPos;
|
|
|
|
nsHTMLTag nodeType = mStack[mStackPos].mType;
|
|
|
|
nsIHTMLContent* content = mStack[mStackPos].mContent;
|
|
|
|
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
|
|
|
|
if (0 == (mStack[mStackPos].mFlags & APPENDED)) {
|
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;
|
|
|
|
}
|
1998-08-28 16:20:16 +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.
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
result = parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
result = parent->AppendChildTo(content, 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) {
|
|
|
|
PRInt32 childCount;
|
|
|
|
|
|
|
|
// Check to see if new content has been added after our last
|
|
|
|
// notification
|
|
|
|
content->ChildCount(childCount);
|
|
|
|
if (mStack[mStackPos].mNumFlushed < childCount) {
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Tracing code
|
|
|
|
char cbuf[40];
|
|
|
|
const char* cp;
|
|
|
|
nsAutoString str;
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mSink->mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
dtd->IntTagToStringTag(nsHTMLTag(nodeType), str);
|
|
|
|
cp = str.ToCString(cbuf, sizeof(cbuf));
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::CloseContainer: reflow on notifyImmediate tag=%s newIndex=%d stackPos=%d", cp, mStack[mStackPos].mNumFlushed, mStackPos));
|
|
|
|
#endif
|
|
|
|
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that notification has now happened at this level
|
|
|
|
mNotifyLevel = mStackPos-1;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
DidAddContent(content, PR_FALSE);
|
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
|
|
|
|
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
1999-09-11 14:55:33 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
|
|
|
case eHTMLTag_nolayer:
|
|
|
|
case eHTMLTag_noscript:
|
|
|
|
mSink->mInsideNoXXXTag--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_form:
|
|
|
|
{
|
|
|
|
nsHTMLTag parserNodeType = nsHTMLTag(aNode.GetNodeType());
|
1999-07-22 23:28:16 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
// 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.
|
|
|
|
if (parserNodeType != nodeType) {
|
|
|
|
result = CloseContainer(aNode);
|
|
|
|
}
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
1999-09-16 23:30:51 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES--;
|
|
|
|
break;
|
1999-09-16 23:30:51 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_select:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectElement> select = do_QueryInterface(content, &result);
|
1999-11-11 22:15:02 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = select->DoneAddingContent(PR_TRUE);
|
|
|
|
}
|
1999-11-11 22:15:02 +00:00
|
|
|
}
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
1999-11-11 22:15:02 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
default:
|
|
|
|
break;
|
1999-11-11 22:15:02 +00:00
|
|
|
|
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
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mPreAppend &&
|
1999-04-03 19:00:23 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo,SINK_ALWAYS_REFLOW)) {
|
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetDocumentInChildrenOf(nsIContent* aContent,
|
|
|
|
nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
PRInt32 i, n;
|
|
|
|
aContent->ChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIContent* child;
|
|
|
|
aContent->ChildAt(i, child);
|
|
|
|
if (nsnull != child) {
|
|
|
|
child->SetDocument(aDocument, PR_TRUE);
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// This method is called when a container is determined to be
|
|
|
|
// non well-formed in the source content. Currently this can only
|
|
|
|
// happen for forms, since the parser doesn't do fixup of forms.
|
|
|
|
// The method makes the container a leaf and moves all the container's
|
|
|
|
// children up a level to the container's parent.
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult
|
1999-10-26 14:55:51 +00:00
|
|
|
SinkContext::DemoteContainer(const nsIParserNode& aNode)
|
1999-07-22 23:28:16 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
// Search for the nearest container on the stack of the
|
|
|
|
// specified type
|
|
|
|
PRInt32 stackPos = mStackPos-1;
|
|
|
|
while ((stackPos > 0) && (nodeType != mStack[stackPos].mType)) {
|
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we find such a container...
|
1999-07-22 23:28:16 +00:00
|
|
|
if (stackPos > 0) {
|
|
|
|
nsIHTMLContent* container = mStack[stackPos].mContent;
|
1999-12-08 03:47:05 +00:00
|
|
|
PRBool sync = PR_FALSE;
|
1999-07-22 23:28:16 +00:00
|
|
|
|
|
|
|
// See if it has a parent on the stack. It should for all the
|
|
|
|
// cases for which this is called, but put in a check anyway
|
|
|
|
if (stackPos > 1) {
|
|
|
|
nsIHTMLContent* parent = mStack[stackPos-1].mContent;
|
1999-12-08 03:47:05 +00:00
|
|
|
PRInt32 parentCount;
|
|
|
|
|
|
|
|
// If we've already flushed the demoted container, flush
|
|
|
|
// what we have and do everything synchronously. If not,
|
|
|
|
// the children that will be promoted will just be dealt
|
|
|
|
// with later.
|
|
|
|
parent->ChildCount(parentCount);
|
|
|
|
if (mStack[stackPos-1].mNumFlushed == parentCount) {
|
2000-01-28 23:43:12 +00:00
|
|
|
FlushTags(PR_TRUE);
|
1999-12-08 03:47:05 +00:00
|
|
|
sync = PR_TRUE;
|
|
|
|
}
|
|
|
|
// Otherwise just append the container to the parent without
|
|
|
|
// notification
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(container, PR_FALSE);
|
|
|
|
}
|
1999-07-22 23:28:16 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
// Move all of the demoted containers children to its parent
|
|
|
|
PRInt32 i, count;
|
|
|
|
container->ChildCount(count);
|
|
|
|
|
|
|
|
for (i = 0; i < count && NS_SUCCEEDED(result); i++) {
|
|
|
|
nsIContent* child;
|
|
|
|
|
|
|
|
// Since we're removing as we go along, always get the
|
|
|
|
// first child
|
|
|
|
result = container->ChildAt(0, child);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
// Remove it from its old parent (the demoted container)
|
|
|
|
|
|
|
|
// If the child is a form control, cache the form that contains it.
|
|
|
|
// After the form control is removed from it's container, restore
|
|
|
|
// it's form.
|
1999-09-01 21:57:01 +00:00
|
|
|
nsIFormControl* childFormControl = nsnull;
|
|
|
|
result = child->QueryInterface(kIFormControlIID, (void**)&childFormControl);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-10-26 14:55:51 +00:00
|
|
|
// It is a form control, so get it's form and cache it.
|
1999-09-01 21:57:01 +00:00
|
|
|
nsIDOMHTMLFormElement* formElem = nsnull;
|
|
|
|
childFormControl->GetForm(&formElem);
|
1999-10-26 14:55:51 +00:00
|
|
|
// Removing the child will set it's form control to nsnull.
|
1999-12-08 03:47:05 +00:00
|
|
|
result = container->RemoveChildAt(0, sync);
|
1999-10-26 14:55:51 +00:00
|
|
|
// Restore the child's form control using the cache'd pointer.
|
1999-09-01 21:57:01 +00:00
|
|
|
childFormControl->SetForm(formElem);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1999-09-01 21:57:01 +00:00
|
|
|
NS_RELEASE(childFormControl);
|
|
|
|
NS_IF_RELEASE(formElem);
|
|
|
|
} else {
|
1999-12-08 03:47:05 +00:00
|
|
|
result = container->RemoveChildAt(0, sync);
|
1999-09-01 21:57:01 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
SetDocumentInChildrenOf(child, mSink->mDocument);
|
|
|
|
// Note that we're doing synchronous notifications here
|
|
|
|
// since we already did notifications for all content
|
|
|
|
// that's come through with the FlushTags() call so far.
|
1999-12-08 03:47:05 +00:00
|
|
|
result = parent->AppendChildTo(child, sync);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the demoted element from the context stack.
|
|
|
|
while (stackPos < mStackPos-1) {
|
|
|
|
mStack[stackPos].mType = mStack[stackPos+1].mType;
|
|
|
|
mStack[stackPos].mContent = mStack[stackPos+1].mContent;
|
|
|
|
mStack[stackPos].mFlags = mStack[stackPos+1].mFlags;
|
|
|
|
stackPos++;
|
|
|
|
}
|
|
|
|
mStackPos--;
|
|
|
|
}
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(container);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1999-12-08 03:47:05 +00:00
|
|
|
if (sync) {
|
|
|
|
// Update child counts for everything on the stack, since
|
|
|
|
// we've moved around content in the hierarchy
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
|
|
|
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"SinkContext::AddLeaf", aNode, 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());
|
|
|
|
nsIHTMLContent* content;
|
1999-09-30 22:07:04 +00:00
|
|
|
rv = mSink->CreateContentObject(aNode, nodeType,
|
|
|
|
mSink->mCurrentForm, mSink->mWebShell,
|
|
|
|
&content);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
2000-03-21 03:25:16 +00:00
|
|
|
}
|
1998-09-03 01:23:12 +00:00
|
|
|
|
|
|
|
// Set the content's document
|
1998-10-26 23:26:01 +00:00
|
|
|
content->SetDocument(mSink->mDocument, PR_FALSE);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
switch (nodeType) {
|
1999-03-25 06:40:06 +00:00
|
|
|
case eHTMLTag_img: // elements with 'SRC='
|
1998-11-24 02:01:45 +00:00
|
|
|
case eHTMLTag_frame:
|
|
|
|
case eHTMLTag_input:
|
1999-01-22 22:14:58 +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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add new leaf to its parent
|
1999-01-09 00:14:53 +00:00
|
|
|
AddLeaf(content);
|
1998-08-29 03:17:02 +00:00
|
|
|
NS_RELEASE(content);
|
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());
|
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
else {
|
1999-07-05 19:45:27 +00:00
|
|
|
// Map carriage returns to newlines
|
|
|
|
if (tmp.CharAt(0) == '\r') {
|
2000-04-15 20:15:37 +00:00
|
|
|
tmp.AssignWithConversion("\n");
|
1999-07-05 19:45:27 +00:00
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
rv = AddText(tmp);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
case eToken_skippedcontent:
|
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;
|
|
|
|
}
|
1999-01-09 00:14:53 +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.
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(aContent,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
parent->AppendChildTo(aContent, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
DidAddContent(aContent, PR_FALSE);
|
1999-01-09 00:14:53 +00:00
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mPreAppend &&
|
1999-04-03 19:00:23 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo,SINK_ALWAYS_REFLOW)) {
|
|
|
|
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,
|
|
|
|
"SinkContext::AddLeaf", aNode, mStackPos, mSink);
|
|
|
|
|
1999-01-22 22:48:00 +00:00
|
|
|
nsIContent *comment;
|
|
|
|
nsIDOMComment *domComment;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
|
|
|
|
1999-01-22 22:48:00 +00:00
|
|
|
result = NS_NewCommentNode(&comment);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
result = comment->QueryInterface(kIDOMCommentIID,
|
|
|
|
(void **)&domComment);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
domComment->AppendData(aNode.GetText());
|
|
|
|
NS_RELEASE(domComment);
|
|
|
|
|
|
|
|
comment->SetDocument(mSink->mDocument, PR_FALSE);
|
|
|
|
|
|
|
|
nsIHTMLContent* parent;
|
|
|
|
if ((nsnull == mSink->mBody) && (nsnull != mSink->mHead)) {
|
|
|
|
parent = mSink->mHead;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent = mStack[mStackPos - 1].mContent;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the parent has an insertion point, insert rather than
|
|
|
|
// append.
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(comment,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
parent->AppendChildTo(comment, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1999-01-22 22:48:00 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
DidAddContent(comment, PR_FALSE);
|
1999-04-03 19:00:23 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mPreAppend &&
|
1999-04-03 19:00:23 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo,SINK_ALWAYS_REFLOW)) {
|
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-22 22:48:00 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::End()
|
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
for (PRInt32 i = 0; i < mStackPos; i++) {
|
|
|
|
NS_RELEASE(mStack[i].mContent);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (0 == newSize) {
|
|
|
|
newSize = 32;
|
|
|
|
}
|
|
|
|
Node* stack = new Node[newSize];
|
|
|
|
if (nsnull == stack) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (0 != mStackPos) {
|
|
|
|
memcpy(stack, mStack, sizeof(Node) * mStackPos);
|
|
|
|
delete [] mStack;
|
|
|
|
}
|
|
|
|
mStack = stack;
|
|
|
|
mStackSize = newSize;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
// XXX If we get a giant string grow the buffer instead of chopping it up???
|
|
|
|
nsresult
|
|
|
|
SinkContext::AddText(const nsString& aText)
|
|
|
|
{
|
|
|
|
PRInt32 addLen = aText.Length();
|
|
|
|
if (0 == addLen) {
|
|
|
|
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
|
|
|
|
if (0 == mTextSize) {
|
|
|
|
mText = new PRUnichar[4096];
|
|
|
|
if (nsnull == mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = 4096;
|
|
|
|
}
|
|
|
|
// else if (mTextLength + addLen > mTextSize) {
|
|
|
|
// }
|
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;
|
|
|
|
while (0 != addLen) {
|
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
|
|
|
if (amount > addLen) {
|
|
|
|
amount = addLen;
|
|
|
|
}
|
|
|
|
if (0 == amount) {
|
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();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(&mText[mTextLength], aText.GetUnicode() + offset,
|
|
|
|
sizeof(PRUnichar) * amount);
|
|
|
|
mTextLength += amount;
|
|
|
|
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
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 childCount;
|
|
|
|
nsIHTMLContent* content;
|
|
|
|
|
|
|
|
// Start from the top of the stack (growing upwards) and append
|
|
|
|
// all content that hasn't been previously appended to the tree
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 stackPos = mStackPos-1;
|
|
|
|
while ((stackPos > 0) && (0 == (mStack[stackPos].mFlags & APPENDED))) {
|
1999-10-26 14:55:51 +00:00
|
|
|
content = mStack[stackPos].mContent;
|
1998-11-28 23:51:06 +00:00
|
|
|
nsIHTMLContent* parent = mStack[stackPos-1].mContent;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the parent has an insertion point, insert rather than
|
|
|
|
// append.
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(content, PR_FALSE);
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
mStack[stackPos].mFlags |= APPENDED;
|
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;
|
|
|
|
content->ChildCount(childCount);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) {
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Tracing code
|
|
|
|
char cbuf[40];
|
|
|
|
const char* cp;
|
|
|
|
nsAutoString str;
|
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
mSink->mParser->GetDTD(getter_AddRefs(dtd));
|
|
|
|
dtd->IntTagToStringTag(nsHTMLTag(mStack[stackPos].mType), str);
|
|
|
|
cp = str.ToCString(cbuf, sizeof(cbuf));
|
|
|
|
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::FlushTags: tag=%s from newindex=%d at stackPos=%d",
|
|
|
|
cp, 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) &&
|
|
|
|
(mStackPos > (stackPos+1))) {
|
|
|
|
nsIContent* child = mStack[stackPos+1].mContent;
|
|
|
|
mSink->NotifyInsert(content,
|
|
|
|
child,
|
|
|
|
mStack[stackPos].mInsertionPoint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSink->NotifyAppend(content, mStack[stackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
flushed = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
stackPos++;
|
|
|
|
}
|
|
|
|
mNotifyLevel = mStackPos-1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SinkContext::UpdateChildCounts()
|
|
|
|
{
|
|
|
|
PRInt32 childCount;
|
|
|
|
nsIHTMLContent* content;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
while (stackPos > 0) {
|
|
|
|
if (mStack[stackPos].mFlags & APPENDED) {
|
|
|
|
content = mStack[stackPos].mContent;
|
|
|
|
content->ChildCount(childCount);
|
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
}
|
|
|
|
stackPos--;
|
|
|
|
}
|
2000-03-10 02:00:42 +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;
|
|
|
|
if (0 != mTextLength) {
|
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;
|
|
|
|
NS_RELEASE(mLastTextNode);
|
|
|
|
FlushText(aDidFlush, aReleaseLast);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMCharacterData> cdata = do_QueryInterface(mLastTextNode, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CBufDescriptor bd(mText, PR_TRUE, mTextSize+1, mTextLength);
|
|
|
|
bd.mIsConst = PR_TRUE;
|
|
|
|
nsAutoString str(bd);
|
|
|
|
|
|
|
|
rv = cdata->AppendData(str);
|
|
|
|
|
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
|
|
|
didFlush = PR_TRUE;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIContent* content;
|
|
|
|
rv = NS_NewTextNode(&content);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Set the content's document
|
|
|
|
content->SetDocument(mSink->mDocument, PR_FALSE);
|
|
|
|
|
|
|
|
// Set the text in the text node
|
|
|
|
nsITextContent* text = nsnull;
|
|
|
|
content->QueryInterface(kITextContentIID, (void**) &text);
|
|
|
|
text->SetText(mText, mTextLength, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
2000-01-31 23:39:19 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Add text to its parent
|
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;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1998-09-06 00:20:59 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mLastTextNode = content;
|
1998-06-11 16:46:33 +00:00
|
|
|
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize += mTextLength;
|
1999-12-10 22:47:39 +00:00
|
|
|
mTextLength = 0;
|
|
|
|
didFlush = PR_TRUE;
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
DidAddContent(content, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
if (nsnull != aDidFlush) {
|
|
|
|
*aDidFlush = didFlush;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
if (aReleaseLast && mLastTextNode) {
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize = 0;
|
1999-10-26 14:55:51 +00:00
|
|
|
NS_RELEASE(mLastTextNode);
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mPreAppend && didFlush &&
|
1999-04-03 19:00:23 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo,SINK_ALWAYS_REFLOW)) {
|
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
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,
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIWebShell* aWebShell)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-09-12 19:33:48 +00:00
|
|
|
HTMLContentSink* it;
|
|
|
|
NS_NEWXPCOM(it, HTMLContentSink);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURL, aWebShell);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
delete it;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aResult);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
// Note: operator new zeros our memory
|
1999-12-07 07:25:56 +00:00
|
|
|
HTMLContentSink::HTMLContentSink() {
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_INIT_REFCNT();
|
1998-08-28 16:20:16 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull == gSinkLogModuleInfo) {
|
|
|
|
gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink");
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-21 03:25:16 +00:00
|
|
|
mNotAtRef = PR_TRUE;
|
1999-10-26 14:55:51 +00:00
|
|
|
mInScript = 0;
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification = 0;
|
2000-02-16 23:43:59 +00:00
|
|
|
mInMonolithicContainer = 0;
|
1999-12-07 07:25:56 +00:00
|
|
|
mInsideNoXXXTag = 0;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
|
|
|
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-08-28 16:20:16 +00:00
|
|
|
NS_IF_RELEASE(mWebShell);
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IF_RELEASE(mCurrentForm);
|
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
|
|
|
NS_IF_RELEASE(mRefContent);
|
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();
|
1999-11-19 04:02:23 +00:00
|
|
|
|
|
|
|
if(mCurrentContext==mHeadContext) {
|
|
|
|
// 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);
|
1999-11-19 04:02:23 +00:00
|
|
|
if(sc) {
|
|
|
|
sc->End();
|
|
|
|
if (sc == mCurrentContext) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (nsnull != mCurrentContext) {
|
|
|
|
delete mCurrentContext;
|
|
|
|
}
|
|
|
|
if (nsnull != mHeadContext) {
|
|
|
|
delete mHeadContext;
|
|
|
|
}
|
|
|
|
if (nsnull != mTitle) {
|
|
|
|
delete mTitle;
|
|
|
|
}
|
|
|
|
if (nsnull != mRef) {
|
|
|
|
delete mRef;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
NS_IMPL_ISUPPORTS6(HTMLContentSink,
|
1999-11-30 04:50:42 +00:00
|
|
|
nsIHTMLContentSink,
|
|
|
|
nsIContentSink,
|
2000-02-02 23:04:47 +00:00
|
|
|
nsIStreamLoaderObserver,
|
1999-12-04 01:27:46 +00:00
|
|
|
nsITimerCallback,
|
2000-01-28 23:43:12 +00:00
|
|
|
nsICSSLoaderObserver,
|
|
|
|
nsIDocumentObserver)
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::Init(nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIWebShell* aContainer)
|
1999-09-21 06:24:58 +00:00
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Reset and start: nsHTMLContentSink::Init(), this=%p\n", this));
|
|
|
|
MOZ_TIMER_RESET(mWatch);
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_PRECONDITION(nsnull != aDoc, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aURL, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aContainer, "null ptr");
|
|
|
|
if ((nsnull == aDoc) || (nsnull == aURL) || (nsnull == aContainer)) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-31 17:51:32 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mDocument = aDoc;
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_ADDREF(aDoc);
|
2000-01-28 23:43:12 +00:00
|
|
|
aDoc->AddObserver(this);
|
1999-01-15 02:02:48 +00:00
|
|
|
aDoc->QueryInterface(kIHTMLDocumentIID, (void**)&mHTMLDocument);
|
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);
|
1998-08-28 16:20:16 +00:00
|
|
|
mWebShell = aContainer;
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_ADDREF(aContainer);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-12-08 03:47:05 +00:00
|
|
|
mNotifyOnTimer = PR_TRUE;
|
1999-12-04 01:27:46 +00:00
|
|
|
prefs->GetBoolPref("content.notify.ontimer", &mNotifyOnTimer);
|
|
|
|
|
|
|
|
mBackoffCount = 3;
|
|
|
|
prefs->GetIntPref("content.notify.backoffcount", &mBackoffCount);
|
|
|
|
|
|
|
|
mNotificationInterval = 1000000;
|
|
|
|
prefs->GetIntPref("content.notify.interval", &mNotificationInterval);
|
|
|
|
|
2000-01-31 23:39:19 +00:00
|
|
|
mMaxTextRun = 8192;
|
|
|
|
prefs->GetIntPref("content.maxtextrun", &mMaxTextRun);
|
|
|
|
|
1999-05-18 23:05:43 +00:00
|
|
|
nsIHTMLContentContainer* htmlContainer = nsnull;
|
|
|
|
if (NS_SUCCEEDED(aDoc->QueryInterface(kIHTMLContentContainerIID, (void**)&htmlContainer))) {
|
|
|
|
htmlContainer->GetCSSLoader(mCSSLoader);
|
|
|
|
NS_RELEASE(htmlContainer);
|
|
|
|
}
|
|
|
|
|
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...
|
|
|
|
mDocument->GetHeaderData(nsHTMLAtoms::headerDefaultStyle, mPreferredStyle);
|
|
|
|
|
1998-07-30 16:06:22 +00:00
|
|
|
// Make root part
|
1999-12-04 01:27:46 +00:00
|
|
|
rv = NS_NewHTMLHtmlElement(&mRoot, nsHTMLAtoms::html);
|
1998-07-30 16:06:22 +00:00
|
|
|
if (NS_OK != 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;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
1998-10-26 23:26:01 +00:00
|
|
|
mRoot->SetDocument(mDocument, PR_FALSE);
|
1998-09-08 22:38:17 +00:00
|
|
|
mDocument->SetRootContent(mRoot);
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make head part
|
1999-02-12 06:19:07 +00:00
|
|
|
nsIAtom* atom = NS_NewAtom("head");
|
1998-07-30 16:06:22 +00:00
|
|
|
if (nsnull == atom) {
|
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 NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-09-02 23:53:49 +00:00
|
|
|
rv = NS_NewHTMLHeadElement(&mHead, atom);
|
1998-07-30 16:06:22 +00:00
|
|
|
NS_RELEASE(atom);
|
|
|
|
if (NS_OK != 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;
|
|
|
|
}
|
1998-08-21 21:38:26 +00:00
|
|
|
mRoot->AppendChildTo(mHead, PR_FALSE);
|
1998-07-30 16:06:22 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = new SinkContext(this);
|
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);
|
|
|
|
|
1999-06-23 19:55:21 +00:00
|
|
|
char* spec;
|
1998-12-16 05:40:20 +00:00
|
|
|
(void)aURL->GetSpec(&spec);
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::Init: this=%p url='%s'",
|
1998-12-16 05:40:20 +00:00
|
|
|
this, spec));
|
1999-06-23 19:55:21 +00:00
|
|
|
nsCRT::free(spec);
|
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);
|
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)
|
|
|
|
{
|
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHODIMP
|
1998-06-30 23:51:53 +00:00
|
|
|
HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
|
|
|
{
|
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
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::DidBuildModel(), this=%p\n", this));
|
|
|
|
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,
|
|
|
|
("HTMLContentSink::DidBuildModel: canceling notification timeout"));
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
mNotificationTimer = 0;
|
|
|
|
}
|
|
|
|
|
1998-08-10 17:39:48 +00:00
|
|
|
if (nsnull == mTitle) {
|
2000-04-15 20:15:37 +00:00
|
|
|
mHTMLDocument->SetTitle(nsAutoString());
|
1998-08-10 17:39:48 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 07:38:27 +00:00
|
|
|
// XXX this is silly; who cares? RickG cares. It's part of the regression test. So don't bug me.
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
1999-02-12 20:13:47 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell(dont_AddRef(mDocument->GetShellAt(i)));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
nsresult rv = shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && vm) {
|
1998-06-27 22:57:52 +00:00
|
|
|
vm->SetQuality(nsContentQuality(aQualityLevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
// Reflow the last batch of content
|
1998-09-10 20:37:19 +00:00
|
|
|
if (nsnull != 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);
|
1998-09-10 20:37:19 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
ScrollToRef();
|
|
|
|
|
|
|
|
mDocument->EndLoad();
|
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);
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
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);
|
|
|
|
#ifdef MOZ_DEBUG
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
PRInt64 diff, interval;
|
|
|
|
PRInt32 delay;
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
LL_I2L(interval, mNotificationInterval);
|
|
|
|
LL_SUB(diff, now, mLastNotificationTime);
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
LL_SUB(diff, diff, interval);
|
|
|
|
LL_L2I(delay, diff);
|
|
|
|
delay /= PR_USEC_PER_MSEC;
|
2000-03-31 01:57:54 +00:00
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
mBackoffCount--;
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::Notify: reflow on a timer: %d milliseconds late, backoff count: %d", delay, mBackoffCount));
|
|
|
|
#endif
|
|
|
|
if (mCurrentContext) {
|
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
2000-04-05 04:02:38 +00:00
|
|
|
mNotificationTimer = 0;
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Notify()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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;
|
|
|
|
|
1998-07-27 18:04:38 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::WillInterrupt: this=%p", this));
|
1999-11-12 02:07:54 +00:00
|
|
|
#ifdef SINK_NO_INCREMENTAL
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
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;
|
|
|
|
|
|
|
|
LL_I2L(interval, mNotificationInterval);
|
|
|
|
LL_SUB(diff, now, mLastNotificationTime);
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
("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);
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
// Else set up a timer for the expected interval
|
|
|
|
else {
|
|
|
|
delay = mNotificationInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert to milliseconds
|
|
|
|
delay /= PR_USEC_PER_MSEC;
|
|
|
|
|
|
|
|
// Cancel a timer if we had one out there
|
|
|
|
if (mNotificationTimer) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::WillInterrupt: canceling notification timeout"));
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
result = NS_NewTimer(getter_AddRefs(mNotificationTimer));
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::WillInterrupt: setting up timer with delay %d", delay));
|
|
|
|
|
|
|
|
result = mNotificationTimer->Init(this, delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("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
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1999-11-12 02:07:54 +00:00
|
|
|
#endif
|
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
|
|
|
{
|
1998-07-27 18:04:38 +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,
|
|
|
|
("HTMLContentSink::WillResume: canceling notification timeout"));
|
|
|
|
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);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-15 20:18:34 +00:00
|
|
|
HTMLContentSink::BeginContext(PRInt32 aPosition)
|
1998-04-13 20:24:54 +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);
|
|
|
|
if (nsnull == sc) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-04-15 20:18:34 +00:00
|
|
|
|
1999-12-08 23:05:14 +00:00
|
|
|
NS_ASSERTION(mCurrentContext != nsnull," Non-existing context");
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mCurrentContext == nsnull) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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;
|
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.
|
|
|
|
if (aPosition < (mCurrentContext->mStackPos-1)) {
|
|
|
|
content->ChildCount(insertionPoint);
|
|
|
|
insertionPoint--;
|
|
|
|
}
|
|
|
|
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;
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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);
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_PRECONDITION(mCurrentContext != nsnull && 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
|
|
|
|
1999-04-15 20:18:34 +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;
|
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
for(PRInt32 i=0; i<mCurrentContext->mStackPos; i++)
|
|
|
|
NS_IF_RELEASE(mCurrentContext->mStack[i].mContent);
|
|
|
|
delete [] mCurrentContext->mStack;
|
|
|
|
mCurrentContext->mStack = nsnull;
|
|
|
|
mCurrentContext->mStackPos = 0;
|
|
|
|
mCurrentContext->mStackSize = 0;
|
|
|
|
if(mCurrentContext->mText != nsnull)
|
|
|
|
delete [] mCurrentContext->mText;
|
|
|
|
mCurrentContext->mText = nsnull;
|
|
|
|
mCurrentContext->mTextLength = 0;
|
|
|
|
mCurrentContext->mTextSize = 0;
|
|
|
|
NS_IF_RELEASE(mCurrentContext->mSink);
|
|
|
|
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);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::EndContext()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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-08-28 16:20:16 +00:00
|
|
|
NS_ASSERTION(mCurrentContext == mHeadContext, "SetTitle not in head");
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull == mTitle) {
|
|
|
|
mTitle = new nsString(aValue);
|
|
|
|
}
|
|
|
|
else {
|
1999-06-28 19:56:10 +00:00
|
|
|
// If the title was already set then don't try to overwrite it
|
|
|
|
// when a new title is encountered - For backwards compatiblity
|
|
|
|
//*mTitle = aValue;
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::SetTitle()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-06-28 19:56:10 +00:00
|
|
|
return NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-11-17 16:29:25 +00:00
|
|
|
ReduceEntities(*mTitle);
|
1998-08-28 16:20:16 +00:00
|
|
|
mTitle->CompressWhitespace(PR_TRUE, PR_TRUE);
|
1999-01-15 02:02:48 +00:00
|
|
|
mHTMLDocument->SetTitle(*mTitle);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1999-02-12 06:19:07 +00:00
|
|
|
nsIAtom* atom = NS_NewAtom("title");
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIHTMLContent* it = nsnull;
|
1998-09-03 22:23:09 +00:00
|
|
|
nsresult rv = NS_NewHTMLTitleElement(&it, atom);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK == rv) {
|
1999-02-17 23:56:55 +00:00
|
|
|
nsIContent* text;
|
|
|
|
rv = NS_NewTextNode(&text);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIDOMText* tc;
|
|
|
|
rv = text->QueryInterface(kIDOMTextIID, (void**)&tc);
|
|
|
|
if (NS_OK == rv) {
|
2000-02-02 22:47:24 +00:00
|
|
|
tc->SetData(*mTitle);
|
1999-02-17 23:56:55 +00:00
|
|
|
NS_RELEASE(tc);
|
|
|
|
}
|
|
|
|
it->AppendChildTo(text, PR_FALSE);
|
|
|
|
text->SetDocument(mDocument, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
1998-09-03 22:23:09 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
mHead->AppendChildTo(it, PR_FALSE);
|
|
|
|
NS_RELEASE(it);
|
1998-07-22 23:42:47 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(atom);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::SetTitle()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::OpenHTML(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-09-15 00:39:41 +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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenHTML", aNode, 0, this);
|
2000-03-30 01:07:02 +00:00
|
|
|
if(mRoot) {
|
|
|
|
// Add attributes to the node...if found.
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
if(ac>0) AddAttributes(aNode,mRoot,PR_TRUE);
|
|
|
|
}
|
1999-09-14 19:24:42 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::CloseHTML(const nsIParserNode& aNode)
|
|
|
|
{
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseHTML", aNode, 0, this);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull != mHeadContext) {
|
1999-12-10 03:36:50 +00:00
|
|
|
if(mCurrentContext==mHeadContext) {
|
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
|
|
|
// 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
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
mHeadContext->End();
|
|
|
|
delete mHeadContext;
|
|
|
|
mHeadContext = nsnull;
|
|
|
|
}
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseHTML()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenHead", aNode, 0, this);
|
1999-03-20 01:51:00 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull == mHeadContext) {
|
|
|
|
mHeadContext = new SinkContext(this);
|
|
|
|
if (nsnull == mHeadContext) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mHeadContext->SetPreAppend(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
rv = mHeadContext->Begin(eHTMLTag_head, mHead, 0, -1);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
mCurrentContext = mHeadContext;
|
1999-03-20 01:51:00 +00:00
|
|
|
|
|
|
|
if (nsnull != mHead) {
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = AddAttributes(aNode, mHead);
|
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);
|
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
|
|
|
|
HTMLContentSink::CloseHead(const nsIParserNode& aNode)
|
|
|
|
{
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseHead", aNode,
|
|
|
|
0, this);
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 n = mContextStack.Count() - 1;
|
|
|
|
mCurrentContext = (SinkContext*) mContextStack.ElementAt(n);
|
|
|
|
mContextStack.RemoveElementAt(n);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseHead()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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);
|
1999-04-05 20:53:54 +00:00
|
|
|
//NS_PRECONDITION(nsnull == mBody, "parser called OpenBody twice");
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenBody", aNode,
|
|
|
|
mCurrentContext->mStackPos, this);
|
1999-04-25 22:18:49 +00:00
|
|
|
// Add attributes, if any, to the current BODY node
|
1999-04-05 20:53:54 +00:00
|
|
|
if(mBody != nsnull){
|
1999-12-03 09:24:22 +00:00
|
|
|
AddAttributes(aNode,mBody,PR_TRUE);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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);
|
1999-03-25 06:40:06 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext->SetPreAppend(PR_FALSE);
|
|
|
|
if (NS_OK != rv) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mBody = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
|
|
|
NS_ADDREF(mBody);
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
StartLayout();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::CloseBody(const nsIParserNode& aNode)
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseBody", aNode,
|
|
|
|
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);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseBody()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
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"));
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext->CloseContainer(aNode);
|
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);
|
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);
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLContent* content = nsnull;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1999-07-22 23:28:16 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenForm", aNode,
|
|
|
|
mCurrentContext->mStackPos, this);
|
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.
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IF_RELEASE(mCurrentForm);
|
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-04-15 20:15:37 +00:00
|
|
|
nsAutoString tmp; tmp.AssignWithConversion("form");
|
1999-07-22 23:28:16 +00:00
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
result = NS_NewHTMLFormElement(&content, atom);
|
|
|
|
if (NS_SUCCEEDED(result) && content) {
|
|
|
|
content->QueryInterface(kIDOMHTMLFormElementIID, (void**)&mCurrentForm);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
|
|
|
|
result = AddLeaf(aNode);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-22 23:28:16 +00:00
|
|
|
else {
|
|
|
|
// Otherwise the form can be a content parent.
|
|
|
|
result = mCurrentContext->OpenContainer(aNode);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
|
|
|
|
content = mCurrentContext->GetCurrentContainer();
|
|
|
|
if (nsnull != content) {
|
|
|
|
result = content->QueryInterface(kIDOMHTMLFormElementIID,
|
|
|
|
(void**)&mCurrentForm);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// add the form to the document
|
1999-01-15 02:02:48 +00:00
|
|
|
if (mCurrentForm) {
|
|
|
|
mHTMLDocument->AddForm(mCurrentForm);
|
1998-10-22 23:00:37 +00:00
|
|
|
}
|
1999-10-11 23:42:56 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenForm()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::CloseForm(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseForm()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseForm", aNode,
|
|
|
|
mCurrentContext->mStackPos-1, this);
|
1999-07-22 23:28:16 +00:00
|
|
|
|
|
|
|
if (nsnull != mCurrentForm) {
|
|
|
|
// Check if this is a well-formed form
|
|
|
|
if (mCurrentContext->IsCurrentContainer(eHTMLTag_form)) {
|
|
|
|
result = mCurrentContext->CloseContainer(aNode);
|
|
|
|
}
|
|
|
|
else if (mCurrentContext->IsAncestorContainer(eHTMLTag_form)) {
|
1999-10-26 14:55:51 +00:00
|
|
|
result = mCurrentContext->DemoteContainer(aNode);
|
1999-07-22 23:28:16 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(mCurrentForm);
|
|
|
|
}
|
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseForm()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenFrameset", aNode,
|
|
|
|
mCurrentContext->mStackPos, this);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
if ((NS_OK == rv) && (nsnull == mFrameset)) {
|
|
|
|
mFrameset = mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
|
|
|
NS_ADDREF(mFrameset);
|
|
|
|
}
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenFrameset()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::CloseFrameset(const nsIParserNode& aNode)
|
|
|
|
{
|
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,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseFrameset", aNode,
|
|
|
|
mCurrentContext->mStackPos-1, this);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
SinkContext* sc = mCurrentContext;
|
|
|
|
nsIHTMLContent* fs = sc->mStack[sc->mStackPos-1].mContent;
|
|
|
|
PRBool done = fs == mFrameset;
|
|
|
|
nsresult rv = sc->CloseContainer(aNode);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseFrameset()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (done) {
|
|
|
|
StartLayout();
|
1998-04-13 20:24:54 +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);
|
1999-09-14 19:24:42 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-01 16:57:35 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::OpenMap", aNode,
|
|
|
|
mCurrentContext->mStackPos, this);
|
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);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenMap()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::CloseMap(const nsIParserNode& aNode)
|
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);
|
1999-09-14 19:24:42 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
1999-10-26 14:55:51 +00:00
|
|
|
"HTMLContentSink::CloseMap", aNode,
|
|
|
|
mCurrentContext->mStackPos-1, this);
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
1999-03-01 16:57:35 +00:00
|
|
|
|
1999-09-14 19:24:42 +00:00
|
|
|
rv = mCurrentContext->CloseContainer(aNode);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseMap()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
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);
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX work around parser bug
|
|
|
|
if (eHTMLTag_frameset == aNode.GetNodeType()) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return OpenFrameset(aNode);
|
|
|
|
}
|
1999-09-14 14:38:52 +00:00
|
|
|
rv = mCurrentContext->OpenContainer(aNode);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::CloseContainer(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
// XXX work around parser bug
|
|
|
|
if (eHTMLTag_frameset == aNode.GetNodeType()) {
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1998-08-28 16:20:16 +00:00
|
|
|
return CloseFrameset(aNode);
|
|
|
|
}
|
1999-09-14 14:38:52 +00:00
|
|
|
rv = mCurrentContext->CloseContainer(aNode);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
HTMLContentSink::AddLeaf(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddLeaf()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
1999-09-14 14:38:52 +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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
case eHTMLTag_script:
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
1999-09-14 14:38:52 +00:00
|
|
|
rv = ProcessSCRIPTTag(aNode);
|
1998-07-12 00:18:26 +00:00
|
|
|
break;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
default:
|
|
|
|
rv = mCurrentContext->AddLeaf(aNode);
|
|
|
|
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);
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
1998-07-12 00:18:26 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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);
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
rv = mCurrentContext->AddComment(aNode);
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddComment()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
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
|
|
|
|
*/
|
|
|
|
nsresult HTMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode) {
|
1999-10-11 23:42:56 +00:00
|
|
|
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);
|
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
|
1999-07-28 06:56:05 +00:00
|
|
|
HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode)
|
1999-07-26 05:40:25 +00:00
|
|
|
{
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
|
|
|
MOZ_TIMER_START(mWatch);
|
2000-03-28 23:25:26 +00:00
|
|
|
|
|
|
|
mHTMLDocument->SetDTDMode((nsDTDMode)aMode);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mHTMLDocument));
|
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
const nsString& docTypeStr = aNode.GetText();
|
|
|
|
|
|
|
|
PRInt32 publicStart = docTypeStr.Find("public", PR_TRUE);
|
|
|
|
nsAutoString name, publicId;
|
|
|
|
|
|
|
|
if (publicStart >= 0) {
|
|
|
|
/*
|
|
|
|
* We found 'PUBLIC' in the doctype, put everything before that in
|
|
|
|
* the name, and then cut out "DOCTYPE" from the name.
|
|
|
|
*/
|
|
|
|
docTypeStr.Mid(name, 0, publicStart);
|
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
if (name.EqualsWithConversion("DOCTYPE", PR_TRUE, 7))
|
2000-03-28 23:25:26 +00:00
|
|
|
name.Cut(0, 7);
|
|
|
|
|
|
|
|
name.CompressWhitespace();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if name contains whitespace chars, if it does we simply
|
|
|
|
* ignore averything that follows the whitespace.
|
|
|
|
*/
|
|
|
|
PRInt32 nameEnd = name.FindCharInSet(" \n\r\t");
|
|
|
|
if (nameEnd > 0) {
|
|
|
|
name.Truncate(nameEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
docTypeStr.Mid(publicId, publicStart + 6,
|
|
|
|
docTypeStr.Length() - publicStart);
|
|
|
|
publicId.CompressWhitespace();
|
|
|
|
|
|
|
|
PRUnichar ch = publicId.First();
|
|
|
|
|
|
|
|
if (ch == '"' || ch == '\'') {
|
|
|
|
publicId.Cut(0, 1);
|
|
|
|
|
|
|
|
PRInt32 end = publicId.FindChar(ch);
|
|
|
|
|
|
|
|
if (end < 0) {
|
|
|
|
/*
|
|
|
|
* We didn't find an end quote, then we just make sure we cut of the
|
|
|
|
* '>' on the end of the doctype declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
end = publicId.FindChar('>');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we didn't find an closing quote nor a '>' we leave publicId as
|
|
|
|
* it is.
|
|
|
|
*/
|
|
|
|
if (end >= 0) {
|
|
|
|
publicId.Truncate(end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No 'PUBLIC' found, we assume we got a '<!DOCTYPE HTML "...">'
|
|
|
|
*/
|
2000-04-15 20:15:37 +00:00
|
|
|
name.Assign(docTypeStr);
|
2000-03-28 23:25:26 +00:00
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
if (name.EqualsWithConversion("DOCTYPE", PR_TRUE, 7))
|
2000-03-28 23:25:26 +00:00
|
|
|
name.Cut(0, 7);
|
|
|
|
|
|
|
|
name.CompressWhitespace();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the name contains whitespace chars, if it does we simply
|
|
|
|
* replace it with "HTML".
|
|
|
|
*/
|
|
|
|
PRInt32 nameEnd = name.FindCharInSet(" \n\r\t");
|
|
|
|
|
|
|
|
if (nameEnd > 0) {
|
|
|
|
/*
|
|
|
|
* We found whitespace after the '<!DOCTYPE HTML' string, we put the
|
|
|
|
* following text, up to the '>' and put it in the public id, and then
|
|
|
|
* we remove quotes.
|
|
|
|
*/
|
|
|
|
name.Mid(publicId, nameEnd, name.Length() - nameEnd);
|
|
|
|
publicId.Trim(">", PR_FALSE, PR_TRUE); // Remove trailing '>'
|
|
|
|
publicId.CompressWhitespace();
|
|
|
|
publicId.Trim("\"'");
|
|
|
|
|
|
|
|
name.Truncate(nameEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (publicId.Length() || name.Length()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name.Length()) {
|
2000-04-15 20:15:37 +00:00
|
|
|
name.AssignWithConversion("HTML");
|
2000-03-28 23:25:26 +00:00
|
|
|
}
|
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
rv = domImpl->CreateDocumentType(name, publicId, nsAutoString(),
|
2000-03-28 23:25:26 +00:00
|
|
|
getter_AddRefs(docType));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> tmpNode;
|
|
|
|
|
|
|
|
if (oldDocType) {
|
|
|
|
/*
|
|
|
|
* If we already have a doctype we replace the old one.
|
|
|
|
*/
|
|
|
|
rv = doc->ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIDOMNode> firstChild;
|
|
|
|
|
|
|
|
doc->GetFirstChild(getter_AddRefs(firstChild));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the above fails it must be because we don't have any child
|
|
|
|
* nodes, then firstChild will be 0 and InsertBefore() will append
|
|
|
|
*/
|
|
|
|
|
|
|
|
rv = doc->InsertBefore(docType, firstChild, getter_AddRefs(tmpNode));
|
|
|
|
}
|
|
|
|
}
|
1999-09-15 17:57:16 +00:00
|
|
|
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1999-07-26 05:40:25 +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;
|
|
|
|
}
|
|
|
|
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;
|
1998-12-20 23:29:47 +00:00
|
|
|
if (mWebShell) {
|
2000-02-29 06:51:48 +00:00
|
|
|
nsCOMPtr<nsIScrollable> scrollableContainer = do_QueryInterface(mWebShell, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && scrollableContainer) {
|
|
|
|
if (mFrameset) {
|
|
|
|
scrollableContainer->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
scrollableContainer->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X, NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
} else {
|
|
|
|
scrollableContainer->ResetScrollbarPreferences();
|
|
|
|
}
|
|
|
|
}
|
1998-12-20 23:29:47 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
1999-02-12 20:13:47 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell(dont_AddRef(mDocument->GetShellAt(i)));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
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
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-31 19:18:39 +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.
|
1999-08-27 21:52:19 +00:00
|
|
|
char* ref = nsnull; // init in case mDocumentURI is not a url
|
1999-06-23 19:55:21 +00:00
|
|
|
nsIURL* url;
|
2000-02-29 06:51:48 +00:00
|
|
|
rv = mDocumentURI->QueryInterface(NS_GET_IID(nsIURL), (void**)&url);
|
1999-06-23 19:55:21 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = url->GetRef(&ref);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
}
|
1998-12-16 05:40:20 +00:00
|
|
|
if (rv == NS_OK) {
|
2000-04-15 20:15:37 +00:00
|
|
|
mRef = new nsString;
|
|
|
|
mRef->AssignWithConversion(ref);
|
1999-06-23 19:55:21 +00:00
|
|
|
nsCRT::free(ref);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1999-03-31 19:18:39 +00:00
|
|
|
if ((nsnull != ref) || 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++) {
|
1999-02-12 20:13:47 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell(dont_AddRef(mDocument->GetShellAt(i)));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIView* rootView = nsnull;
|
|
|
|
vm->GetRootView(rootView);
|
|
|
|
if (nsnull != rootView) {
|
|
|
|
nsIScrollableView* sview = nsnull;
|
|
|
|
rootView->QueryInterface(kIScrollableViewIID, (void**) &sview);
|
|
|
|
if (nsnull != sview) {
|
1999-03-31 19:18:39 +00:00
|
|
|
if (mFrameset)
|
1998-08-30 19:16:11 +00:00
|
|
|
mOriginalScrollPreference = nsScrollPreference_kNeverScroll;
|
|
|
|
else
|
|
|
|
sview->GetScrollPreference(mOriginalScrollPreference);
|
1998-08-28 16:20:16 +00:00
|
|
|
sview->SetScrollPreference(nsScrollPreference_kNeverScroll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::ScrollToRef()
|
1998-04-22 22:12:24 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mNotAtRef && (nsnull != mRef) && (nsnull != mRefContent)) {
|
1999-02-18 23:55:10 +00:00
|
|
|
// See if the ref content has been reflowed by finding its frame
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
1999-02-18 23:55:10 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell( dont_AddRef(mDocument->GetShellAt(i)) );
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
1998-12-29 04:45:18 +00:00
|
|
|
nsIFrame* frame;
|
1999-02-12 17:45:58 +00:00
|
|
|
shell->GetPrimaryFrameFor(mRefContent, &frame);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull != frame) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
1999-02-16 04:41:15 +00:00
|
|
|
nsIScrollableView* sview = nsnull;
|
|
|
|
vm->GetRootScrollableView(&sview);
|
|
|
|
|
|
|
|
if (sview) {
|
|
|
|
// Determine the x,y scroll offsets for the given
|
|
|
|
// frame. The offsets are relative to the
|
|
|
|
// ScrollableView's upper left corner so we need frame
|
|
|
|
// coordinates that are relative to that.
|
|
|
|
nsPoint offset;
|
|
|
|
nsIView* view;
|
1999-10-26 04:44:41 +00:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
frame->GetOffsetFromView(presContext, offset, &view);
|
1999-02-16 04:41:15 +00:00
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = offset.y;
|
|
|
|
sview->SetScrollPreference(mOriginalScrollPreference);
|
|
|
|
// XXX If view != scrolledView, then there is a scrolled frame,
|
|
|
|
// e.g., a DIV with 'overflow' of 'scroll', somewhere in the middle,
|
|
|
|
// or maybe an absolutely positioned element that has a view. We
|
|
|
|
// need to handle these cases...
|
|
|
|
sview->ScrollTo(x, y, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
|
|
|
|
// Note that we did this so that we don't bother doing it again
|
|
|
|
mNotAtRef = PR_FALSE;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-24 18:20:27 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::AddBaseTagInfo(nsIHTMLContent* aContent)
|
|
|
|
{
|
|
|
|
if (mBaseHREF.Length() > 0) {
|
1998-12-20 01:21:23 +00:00
|
|
|
aContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::_baseHref, mBaseHREF, PR_FALSE);
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
|
|
|
if (mBaseTarget.Length() > 0) {
|
1998-12-20 01:21:23 +00:00
|
|
|
aContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::_baseTarget, mBaseTarget, PR_FALSE);
|
1998-07-24 18:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessATag(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aContent)
|
|
|
|
{
|
|
|
|
AddBaseTagInfo(aContent);
|
|
|
|
if ((nsnull != mRef) && (nsnull == mRefContent)) {
|
|
|
|
nsHTMLValue value;
|
1998-12-20 01:21:23 +00:00
|
|
|
aContent->GetHTMLAttribute(nsHTMLAtoms::name, value);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
nsAutoString tmp;
|
|
|
|
value.GetStringValue(tmp);
|
|
|
|
if (mRef->EqualsIgnoreCase(tmp)) {
|
|
|
|
// Winner. We just found the content that is the named anchor
|
|
|
|
mRefContent = aContent;
|
|
|
|
NS_ADDREF(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-01-09 00:14:53 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != mCurrentMap) {
|
1999-01-09 00:14:53 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
|
|
|
nsIHTMLContent* area;
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = CreateContentObject(aNode, nodeType, nsnull, nsnull, &area);
|
1999-01-09 00:14:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2000-03-21 03:25:16 +00:00
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
|
|
|
// Set the content's document and attributes
|
1999-12-03 09:24:22 +00:00
|
|
|
area->SetDocument(mDocument, PR_FALSE);
|
|
|
|
rv = AddAttributes(aNode, area);
|
1999-01-09 00:14:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(area);
|
|
|
|
return rv;
|
1999-08-31 11:17:26 +00:00
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
|
|
|
// Add AREA object to the current map
|
|
|
|
mCurrentMap->AppendChildTo(area, PR_FALSE);
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_RELEASE(area);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::ProcessBaseHref(const nsString& aBaseHref)
|
|
|
|
{
|
|
|
|
if (nsnull == mBody) { // still in real HEAD
|
|
|
|
mHTMLDocument->SetBaseURL(aBaseHref);
|
|
|
|
NS_RELEASE(mDocumentBaseURL);
|
|
|
|
mDocument->GetBaseURL(mDocumentBaseURL);
|
|
|
|
}
|
|
|
|
else { // NAV compatibility quirk
|
|
|
|
mBaseHREF = aBaseHref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
|
|
|
|
{
|
|
|
|
if (vm) {
|
2000-03-11 00:34:54 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
nsresult rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (NS_SUCCEEDED(rv) && (contentViewer)) {
|
1999-05-13 20:27:47 +00:00
|
|
|
PRBool enabled;
|
|
|
|
contentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
2000-02-09 15:48:01 +00:00
|
|
|
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::ProcessBaseTarget(const nsString& aBaseTarget)
|
|
|
|
{
|
|
|
|
if (nsnull == mBody) { // still in real HEAD
|
|
|
|
mHTMLDocument->SetBaseTarget(aBaseTarget);
|
|
|
|
}
|
|
|
|
else { // NAV compatibility quirk
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(mCurrentContext!=nsnull) {
|
|
|
|
parent=mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parent!=nsnull) {
|
|
|
|
// Create content object
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString tag; tag.AssignWithConversion("BASE");
|
2000-02-11 22:07:12 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> element;
|
|
|
|
result = NS_CreateHTMLElement(getter_AddRefs(element), tag);
|
1999-06-16 00:44:50 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2000-03-21 03:25:16 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
1999-06-16 00:44:50 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
|
|
|
result = AddAttributes(aNode, element);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
parent->AppendChildTo(element, PR_FALSE);
|
|
|
|
if(!mInsideNoXXXTag) {
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == element->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, value)) {
|
|
|
|
ProcessBaseHref(value);
|
|
|
|
}
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == element->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::target, value)) {
|
|
|
|
ProcessBaseTarget(value);
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 00:44:50 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +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('>');
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessLink(nsIHTMLContent* aElement, const nsString& aLinkData)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
nsAutoString stringList(aLinkData); // copy to work buffer
|
|
|
|
|
|
|
|
stringList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
1999-04-21 23:43:11 +00:00
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)stringList.GetUnicode();
|
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
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
2000-03-12 09:14:14 +00:00
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
1999-01-23 07:05:49 +00:00
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
last = end - 1;
|
|
|
|
|
1999-01-30 06:24:09 +00:00
|
|
|
while ((kNullCh != *end) && (kSemiCh != *end) && (kCommaCh != *end)) { // look for semicolon or comma
|
1999-01-23 07:05:49 +00:00
|
|
|
if ((kApostrophe == *end) || (kQuote == *end) ||
|
|
|
|
(kLessThanCh == *end)) { // quoted string
|
|
|
|
PRUnichar quote = *end;
|
|
|
|
if (kLessThanCh == quote) {
|
|
|
|
quote = kGreaterThanCh;
|
|
|
|
}
|
|
|
|
PRUnichar* closeQuote = (end + 1);
|
|
|
|
while ((kNullCh != *closeQuote) && (quote != *closeQuote)) {
|
|
|
|
closeQuote++; // seek closing quote
|
|
|
|
}
|
|
|
|
if (quote == *closeQuote) { // found closer
|
|
|
|
end = closeQuote; // skip to close quote
|
|
|
|
last = end - 1;
|
1999-01-30 06:24:09 +00:00
|
|
|
if ((kSemiCh != *(end + 1)) && (kNullCh != *(end + 1)) && (kCommaCh != *(end + 1))) {
|
1999-01-23 07:05:49 +00:00
|
|
|
*(++end) = kNullCh; // end string here
|
1999-01-30 06:24:09 +00:00
|
|
|
while ((kNullCh != *(end + 1)) && (kSemiCh != *(end + 1)) &&
|
|
|
|
(kCommaCh != *(end + 1))) { // keep going until semi or comma
|
1999-01-23 07:05:49 +00:00
|
|
|
end++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end++;
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
|
1999-01-30 06:24:09 +00:00
|
|
|
endCh = *end;
|
1999-01-23 07:05:49 +00:00
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
if (start < end) {
|
|
|
|
if ((kLessThanCh == *start) && (kGreaterThanCh == *last)) {
|
|
|
|
*last = kNullCh;
|
1999-01-30 06:24:09 +00:00
|
|
|
if (0 == href.Length()) { // first one wins
|
|
|
|
href = (start + 1);
|
|
|
|
href.StripWhitespace();
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRUnichar* equals = start;
|
|
|
|
while ((kNullCh != *equals) && (kEqualsCh != *equals)) {
|
|
|
|
equals++;
|
|
|
|
}
|
|
|
|
if (kNullCh != *equals) {
|
|
|
|
*equals = kNullCh;
|
|
|
|
nsAutoString attr = start;
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
if (((kApostrophe == *value) || (kQuote == *value)) &&
|
|
|
|
(*value == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.EqualsIgnoreCase("rel")) {
|
1999-01-30 06:24:09 +00:00
|
|
|
if (0 == rel.Length()) {
|
|
|
|
rel = value;
|
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("title")) {
|
1999-01-30 06:24:09 +00:00
|
|
|
if (0 == title.Length()) {
|
|
|
|
title = value;
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("type")) {
|
1999-01-30 06:24:09 +00:00
|
|
|
if (0 == type.Length()) {
|
|
|
|
type = value;
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("media")) {
|
1999-01-30 06:24:09 +00:00
|
|
|
if (0 == media.Length()) {
|
|
|
|
media = value;
|
1999-05-26 23:49:33 +00:00
|
|
|
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
1999-01-30 06:24:09 +00:00
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-30 06:24:09 +00:00
|
|
|
if (kCommaCh == endCh) { // hit a comma, process what we've got so far
|
|
|
|
if (0 < href.Length()) {
|
1999-05-26 23:49:33 +00:00
|
|
|
result = ProcessStyleLink(aElement, href, rel, title, type, media);
|
|
|
|
if (NS_ERROR_HTMLPARSER_BLOCK == result) {
|
1999-01-30 06:24:09 +00:00
|
|
|
didBlock = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
href.Truncate();
|
|
|
|
rel.Truncate();
|
|
|
|
title.Truncate();
|
|
|
|
type.Truncate();
|
|
|
|
media.Truncate();
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 < href.Length()) {
|
1999-05-26 23:49:33 +00:00
|
|
|
result = ProcessStyleLink(aElement, href, rel, title, type, media);
|
|
|
|
if (NS_SUCCEEDED(result) && didBlock) {
|
1999-01-23 07:05:49 +00:00
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
static void ParseLinkTypes(const nsString& aTypes, nsStringArray& aResult)
|
|
|
|
{
|
|
|
|
nsAutoString stringList(aTypes); // copy to work buffer
|
|
|
|
nsAutoString subStr;
|
|
|
|
|
|
|
|
stringList.ToLowerCase();
|
|
|
|
stringList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)stringList.GetUnicode();
|
|
|
|
PRUnichar* end = start;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
2000-03-12 09:14:14 +00:00
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
1999-05-26 23:49:33 +00:00
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
|
2000-03-12 09:14:14 +00:00
|
|
|
while ((kNullCh != *end) && (! nsCRT::IsAsciiSpace(*end))) { // look for space
|
1999-05-26 23:49:33 +00:00
|
|
|
end++;
|
|
|
|
}
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
subStr = start;
|
|
|
|
|
|
|
|
if (0 < subStr.Length()) {
|
|
|
|
aResult.AppendString(subStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SplitMimeType(const nsString& aValue, nsString& aType, nsString& aParams)
|
|
|
|
{
|
|
|
|
aType.Truncate();
|
|
|
|
aParams.Truncate();
|
1999-07-26 00:37:24 +00:00
|
|
|
PRInt32 semiIndex = aValue.FindChar(PRUnichar(';'));
|
1999-05-26 23:49:33 +00:00
|
|
|
if (-1 != semiIndex) {
|
|
|
|
aValue.Left(aType, semiIndex);
|
|
|
|
aValue.Right(aParams, (aValue.Length() - semiIndex) - 1);
|
(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
|
|
|
aParams.StripWhitespace();
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aType = aValue;
|
|
|
|
}
|
(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
|
|
|
aType.StripWhitespace();
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aDidNotify)
|
|
|
|
{
|
|
|
|
// If there was a notification done for this style sheet, we know
|
|
|
|
// that frames have been created for all content seen so far
|
|
|
|
// (processing of a new style sheet causes recreation of the frame
|
|
|
|
// model). As a result, all contexts should update their notion of
|
|
|
|
// how much frame creation has happened.
|
|
|
|
if (aDidNotify) {
|
|
|
|
UpdateAllContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessStyleLink(nsIHTMLContent* aElement,
|
|
|
|
const nsString& aHref, const nsString& aRel,
|
|
|
|
const nsString& aTitle, const nsString& aType,
|
1999-05-26 23:49:33 +00:00
|
|
|
const nsString& aMedia)
|
1999-01-23 07:05:49 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
nsStringArray linkTypes;
|
|
|
|
ParseLinkTypes(aRel, linkTypes);
|
2000-04-05 04:02:38 +00:00
|
|
|
PRBool isAlternate = PR_FALSE;
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
if (-1 != linkTypes.IndexOf(NS_ConvertASCIItoUCS2("stylesheet"))) { // is it a stylesheet link?
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
if (-1 != linkTypes.IndexOf(NS_ConvertASCIItoUCS2("alternate"))) { // if alternate, does it have title?
|
1999-05-26 23:49:33 +00:00
|
|
|
if (0 == aTitle.Length()) { // alternates must have title
|
|
|
|
return NS_OK; //return without error, for now
|
2000-04-05 04:02:38 +00:00
|
|
|
} else {
|
|
|
|
isAlternate = PR_TRUE;
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
SplitMimeType(aType, mimeType, params);
|
|
|
|
|
2000-01-08 10:09:00 +00:00
|
|
|
nsDTDMode mode;
|
|
|
|
mHTMLDocument->GetDTDMode(mode);
|
|
|
|
|
|
|
|
PRBool isStyleSheet = PR_FALSE; // see bug 18817
|
|
|
|
if (eDTDMode_NoQuirks == mode) {
|
|
|
|
if (mimeType.EqualsIgnoreCase("text/css")) {
|
|
|
|
isStyleSheet = PR_TRUE; // strict mode + good mime type
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (0 == mimeType.Length()) {
|
|
|
|
nsString extension;
|
|
|
|
aHref.Right(extension, 4);
|
2000-04-15 20:15:37 +00:00
|
|
|
if (extension.EqualsWithConversion(".css")) {
|
2000-01-08 10:09:00 +00:00
|
|
|
isStyleSheet = PR_TRUE; // strict mode + no mime type + '.css' extension
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (0 == mimeType.Length() || mimeType.EqualsIgnoreCase("text/css")) {
|
|
|
|
isStyleSheet = PR_TRUE; // quirks mode + good mime type or no mime type at all
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isStyleSheet) {
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* url = nsnull;
|
1999-06-23 19:55:21 +00:00
|
|
|
{
|
|
|
|
result = NS_NewURI(&url, aHref, mDocumentBaseURL);
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
if (NS_OK != result) {
|
1999-01-30 06:24:09 +00:00
|
|
|
return NS_OK; // The URL is bad, move along, don't propogate the error (for now)
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
if (-1 == linkTypes.IndexOf(NS_ConvertASCIItoUCS2("alternate"))) {
|
1999-05-18 23:05:43 +00:00
|
|
|
if (0 < aTitle.Length()) { // possibly preferred sheet
|
1999-01-23 07:05:49 +00:00
|
|
|
if (0 == mPreferredStyle.Length()) {
|
|
|
|
mPreferredStyle = aTitle;
|
1999-05-18 23:05:43 +00:00
|
|
|
mCSSLoader->SetPreferredSheet(aTitle);
|
1999-01-23 07:05:49 +00:00
|
|
|
mDocument->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, aTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
PRBool blockParser = kBlockByDefault;
|
|
|
|
if (isAlternate) {
|
|
|
|
blockParser = PR_FALSE;
|
2000-03-31 01:57:54 +00:00
|
|
|
}
|
|
|
|
|
2000-04-05 04:02:38 +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
|
|
|
|
if (-1 != linkTypes.IndexOf("important")) {
|
|
|
|
blockParser = PR_TRUE;
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
2000-04-05 04:02:38 +00:00
|
|
|
*/
|
1999-05-26 23:49:33 +00:00
|
|
|
|
1999-05-18 23:05:43 +00:00
|
|
|
PRBool doneLoading;
|
1999-06-15 06:22:46 +00:00
|
|
|
result = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, kNameSpaceID_HTML,
|
1999-05-18 23:05:43 +00:00
|
|
|
mStyleSheetCount++,
|
1999-06-15 06:22:46 +00:00
|
|
|
((blockParser) ? mParser : nsnull),
|
1999-12-04 01:27:46 +00:00
|
|
|
doneLoading,
|
|
|
|
this);
|
1999-01-23 07:05:49 +00:00
|
|
|
NS_RELEASE(url);
|
2000-04-05 04:02:38 +00:00
|
|
|
if (NS_SUCCEEDED(result) && blockParser && (! doneLoading)) {
|
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(mCurrentContext!=nsnull) {
|
|
|
|
parent=mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
1998-06-26 15:08:55 +00:00
|
|
|
}
|
2000-02-11 22:07:12 +00:00
|
|
|
|
|
|
|
if(parent!=nsnull) {
|
|
|
|
// Create content object
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString tag; tag.AssignWithConversion("LINK");
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
result = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2000-03-21 03:25:16 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
2000-02-11 22:07:12 +00:00
|
|
|
|
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
|
|
|
result = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
parent->AppendChildTo(element, PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
1998-11-26 01:29:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
2000-02-11 22:07:12 +00:00
|
|
|
|
|
|
|
// XXX need prefs. check here.
|
|
|
|
if(!mInsideNoXXXTag) {
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 count = aNode.GetAttributeCount();
|
|
|
|
|
|
|
|
nsAutoString href;
|
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("href")) {
|
|
|
|
GetAttributeValueAt(aNode, i, href);
|
|
|
|
href.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("rel")) {
|
|
|
|
GetAttributeValueAt(aNode, i, rel);
|
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("title")) {
|
|
|
|
GetAttributeValueAt(aNode, i, title);
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("type")) {
|
|
|
|
GetAttributeValueAt(aNode, i, type);
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("media")) {
|
|
|
|
GetAttributeValueAt(aNode, i, media);
|
|
|
|
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = ProcessStyleLink(element, href, rel, title, type, media);
|
|
|
|
}
|
|
|
|
NS_RELEASE(element);
|
1998-11-26 01:29:10 +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)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
|
|
|
|
|
|
|
nsIDOMHTMLMapElement* domMap;
|
|
|
|
rv = aContent->QueryInterface(kIDOMHTMLMapElementIID, (void**)&domMap);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip out whitespace in the name for navigator compatability
|
1999-07-07 01:26:25 +00:00
|
|
|
// XXX NAV QUIRK -- XXX this should be done in the content node, not the sink
|
1999-03-01 16:57:35 +00:00
|
|
|
nsHTMLValue name;
|
|
|
|
aContent->GetHTMLAttribute(nsHTMLAtoms::name, name);
|
|
|
|
if (eHTMLUnit_String == name.GetUnit()) {
|
|
|
|
nsAutoString tmp;
|
|
|
|
name.GetStringValue(tmp);
|
|
|
|
tmp.StripWhitespace();
|
|
|
|
name.SetStringValue(tmp);
|
|
|
|
aContent->SetHTMLAttribute(nsHTMLAtoms::name, name, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2000-01-11 07:21:24 +00:00
|
|
|
// This is for nav4 compatibility. (Bug 18478)
|
|
|
|
// The base tag should only appear in the head,
|
|
|
|
// but nav4 allows the base tag in the body as well.
|
|
|
|
AddBaseTagInfo(aContent);
|
|
|
|
|
1999-03-01 16:57:35 +00:00
|
|
|
// Don't need to add the map to the document here anymore.
|
|
|
|
// The map adds itself
|
|
|
|
mCurrentMap = aContent;
|
|
|
|
NS_ADDREF(aContent);
|
1999-10-26 14:55:51 +00:00
|
|
|
NS_IF_RELEASE(domMap);
|
1999-03-01 16:57:35 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-01-23 07:05:49 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* parent = nsnull;
|
|
|
|
|
|
|
|
if(mCurrentContext!=nsnull) {
|
|
|
|
parent=mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
if (nsnull != parent) {
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create content object
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString tmp; tmp.AssignWithConversion("meta");
|
1998-08-28 16:20:16 +00:00
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
if (nsnull == atom) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsIHTMLContent* it;
|
1999-01-23 07:05:49 +00:00
|
|
|
rv = NS_NewHTMLMetaElement(&it, atom);
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Add in the attributes and add the meta content object to the
|
|
|
|
// head container.
|
1999-02-27 07:13:48 +00:00
|
|
|
it->SetDocument(mDocument, PR_FALSE);
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = AddAttributes(aNode, it);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(it);
|
|
|
|
return rv;
|
|
|
|
}
|
2000-02-11 22:07:12 +00:00
|
|
|
parent->AppendChildTo(it, PR_FALSE);
|
|
|
|
|
|
|
|
// XXX It's just not sufficient to check if the parent is head. Also check for
|
|
|
|
// the preference.
|
|
|
|
if(!mInsideNoXXXTag) {
|
|
|
|
|
|
|
|
// set any HTTP-EQUIV data into document's header data as well as url
|
|
|
|
nsAutoString header;
|
|
|
|
it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::httpEquiv, header);
|
|
|
|
if (header.Length() > 0) {
|
|
|
|
nsAutoString result;
|
|
|
|
it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::content, result);
|
|
|
|
if (result.Length() > 0) {
|
|
|
|
// XXX necko isn't going to process headers coming in from the parser
|
|
|
|
//NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)");
|
1999-08-03 21:48:40 +00:00
|
|
|
|
2000-03-11 02:57:39 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// see if we have a refresh "header".
|
2000-04-15 20:15:37 +00:00
|
|
|
if (!header.CompareWithConversion("refresh", PR_TRUE)) {
|
2000-02-11 22:07:12 +00:00
|
|
|
// Refresh headers are parsed with the following format in mind
|
|
|
|
// <META HTTP-EQUIV=REFRESH CONTENT="5; URL=http://uri">
|
|
|
|
// By the time we are here, the following is true:
|
|
|
|
// header = "REFRESH"
|
2000-03-04 00:32:30 +00:00
|
|
|
// result = "5; URL=http://uri" // note the URL attribute is
|
|
|
|
// optional, if it is absent, the currently loaded url is used.
|
|
|
|
//
|
|
|
|
// We need to handle the following strings.
|
|
|
|
// - X is a set of digits
|
|
|
|
// - URI is either a relative or absolute URI
|
|
|
|
// - FOO is any text
|
|
|
|
//
|
|
|
|
// ""
|
|
|
|
// empty string. use the currently loaded URI
|
|
|
|
// and refresh immediately.
|
|
|
|
// "X"
|
|
|
|
// Refresh the currently loaded URI in X milliseconds.
|
|
|
|
// "X; URI"
|
|
|
|
// Refresh using URI as the destination in X milliseconds.
|
|
|
|
// "X; URI; Blah"
|
|
|
|
// Refresh using URI as the destination in X milliseconds,
|
|
|
|
// ignoring "Blah"
|
|
|
|
// "URI"
|
|
|
|
// Refresh immediately using URI as the destination.
|
|
|
|
// "URI; Blah"
|
|
|
|
// Refresh immediately using URI as the destination,
|
|
|
|
// ignoring "Blah"
|
|
|
|
//
|
|
|
|
// Note that we need to remove any tokens wrapping the URI.
|
|
|
|
// These tokens currently include spaces, double and single
|
|
|
|
// quotes.
|
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// first get our baseURI
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2000-03-11 02:57:39 +00:00
|
|
|
rv = docShell->GetCurrentURI(getter_AddRefs(baseURI));
|
2000-02-11 22:07:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-03-04 00:32:30 +00:00
|
|
|
PRInt32 millis = -1;
|
|
|
|
PRUnichar *uriAttrib = nsnull;
|
|
|
|
|
2000-03-12 01:11:41 +00:00
|
|
|
PRInt32 semiColon = result.FindCharInSet(";,");
|
2000-03-04 00:32:30 +00:00
|
|
|
nsAutoString token;
|
|
|
|
if (semiColon > -1)
|
|
|
|
result.Left(token, semiColon);
|
|
|
|
else
|
|
|
|
token = result;
|
|
|
|
|
|
|
|
PRBool done = PR_FALSE;
|
|
|
|
while (!done && !token.IsEmpty()) {
|
|
|
|
token.CompressWhitespace();
|
2000-03-12 11:06:57 +00:00
|
|
|
if (millis == -1 && nsCRT::IsAsciiDigit(token.First())) {
|
2000-03-04 00:32:30 +00:00
|
|
|
PRInt32 i = 0;
|
|
|
|
PRUnichar value = nsnull;
|
|
|
|
while ((value = token[i++])) {
|
2000-03-12 11:06:57 +00:00
|
|
|
if (!nsCRT::IsAsciiDigit(value)) {
|
2000-03-04 00:32:30 +00:00
|
|
|
i = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > -1) {
|
|
|
|
PRInt32 err;
|
|
|
|
millis = token.ToInteger(&err) * 1000;
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
2000-03-04 00:32:30 +00:00
|
|
|
if (done) {
|
|
|
|
PRInt32 loc = token.FindChar('=');
|
|
|
|
if (loc > -1)
|
|
|
|
token.Cut(0, loc+1);
|
|
|
|
token.Trim(" \"'");
|
|
|
|
uriAttrib = token.ToNewUnicode();
|
|
|
|
} else {
|
|
|
|
// Increment to the next token.
|
|
|
|
if (semiColon > -1) {
|
|
|
|
semiColon++;
|
2000-03-12 01:11:41 +00:00
|
|
|
PRInt32 semiColon2 = result.FindCharInSet(";,", semiColon);
|
2000-03-04 00:32:30 +00:00
|
|
|
if (semiColon2 == -1) semiColon2 = result.Length();
|
|
|
|
result.Mid(token, semiColon, semiColon2 - semiColon);
|
|
|
|
semiColon = semiColon2;
|
|
|
|
} else {
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end while
|
2000-02-11 22:07:12 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2000-03-04 00:32:30 +00:00
|
|
|
if (!uriAttrib) {
|
|
|
|
uri = baseURI;
|
2000-02-11 22:07:12 +00:00
|
|
|
} else {
|
2000-03-04 00:32:30 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), uriAttrib, baseURI);
|
|
|
|
nsAllocator::Free(uriAttrib);
|
2000-02-11 22:07:12 +00:00
|
|
|
}
|
|
|
|
|
2000-03-04 00:32:30 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_WITH_SERVICE(nsIScriptSecurityManager,
|
|
|
|
securityManager,
|
|
|
|
NS_SCRIPTSECURITYMANAGER_PROGID,
|
|
|
|
&rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = securityManager->CheckLoadURI(baseURI,
|
|
|
|
uri,
|
|
|
|
PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIRefreshURI> reefer =
|
|
|
|
do_QueryInterface(mWebShell);
|
|
|
|
if (reefer) {
|
|
|
|
if (millis == -1) millis = 0;
|
|
|
|
rv = reefer->RefreshURI(uri, millis,
|
|
|
|
PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 22:07:12 +00:00
|
|
|
} // END refresh
|
2000-04-15 20:15:37 +00:00
|
|
|
else if (!header.CompareWithConversion("set-cookie", PR_TRUE)) {
|
2000-02-11 22:07:12 +00:00
|
|
|
nsCOMPtr<nsICookieService> cookieServ = do_GetService(NS_COOKIESERVICE_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2000-03-11 02:57:39 +00:00
|
|
|
rv = docShell->GetCurrentURI(getter_AddRefs(baseURI));
|
2000-02-11 22:07:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = cookieServ->SetCookieString(baseURI, result);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} // END set-cookie
|
|
|
|
|
|
|
|
header.ToLowerCase();
|
|
|
|
nsIAtom* fieldAtom = NS_NewAtom(header);
|
|
|
|
mDocument->SetHeaderData(fieldAtom, result);
|
|
|
|
|
|
|
|
if (fieldAtom == nsHTMLAtoms::headerDefaultStyle) {
|
|
|
|
mPreferredStyle = result;
|
|
|
|
mCSSLoader->SetPreferredSheet(mPreferredStyle);
|
|
|
|
}
|
|
|
|
else if (fieldAtom == nsHTMLAtoms::link) {
|
|
|
|
rv = ProcessLink(it, result);
|
|
|
|
}
|
|
|
|
else if (fieldAtom == nsHTMLAtoms::headerContentBase) {
|
|
|
|
ProcessBaseHref(result);
|
|
|
|
}
|
|
|
|
else if (fieldAtom == nsHTMLAtoms::headerWindowTarget) {
|
|
|
|
ProcessBaseTarget(result);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(fieldAtom);
|
|
|
|
}//if (result.Length() > 0)
|
|
|
|
}//if (header.Length() > 0)
|
|
|
|
}//if(!mInsideNoXXXTag)
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(it);
|
2000-02-11 22:07:12 +00:00
|
|
|
}//if (NS_OK == rv)
|
|
|
|
}//if (nsnull != parent)
|
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
|
|
|
}
|
|
|
|
|
1998-10-30 03:36:35 +00:00
|
|
|
// Returns PR_TRUE if the language name is a version of JavaScript and
|
|
|
|
// PR_FALSE otherwise
|
|
|
|
static PRBool
|
(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
|
|
|
IsJavaScriptLanguage(const nsString& aName, const char* *aVersion)
|
1998-10-30 03:36:35 +00:00
|
|
|
{
|
(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
|
|
|
JSVersion version = JSVERSION_UNKNOWN;
|
|
|
|
|
|
|
|
if (aName.EqualsIgnoreCase("JavaScript") ||
|
|
|
|
aName.EqualsIgnoreCase("LiveScript") ||
|
|
|
|
aName.EqualsIgnoreCase("Mocha")) {
|
|
|
|
version = JSVERSION_DEFAULT;
|
|
|
|
}
|
|
|
|
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
|
|
|
|
version = JSVERSION_1_1;
|
|
|
|
}
|
|
|
|
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
|
|
|
|
version = JSVERSION_1_2;
|
|
|
|
}
|
|
|
|
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
|
|
|
|
version = JSVERSION_1_3;
|
|
|
|
}
|
|
|
|
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
|
|
|
|
version = JSVERSION_1_4;
|
|
|
|
}
|
|
|
|
else if (aName.EqualsIgnoreCase("JavaScript1.5")) {
|
|
|
|
version = JSVERSION_1_5;
|
|
|
|
}
|
|
|
|
if (version == JSVERSION_UNKNOWN)
|
1998-10-30 03:36:35 +00:00
|
|
|
return PR_FALSE;
|
(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
|
|
|
*aVersion = JS_VersionToString(version);
|
|
|
|
return PR_TRUE;
|
1998-10-30 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
HTMLContentSink::ForceReflow()
|
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyAppend(nsIContent* aContainer, PRInt32 aStartIndex)
|
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification++;
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Save and stop: nsHTMLContentSink::NotifyAppend()\n"));
|
|
|
|
MOZ_TIMER_SAVE(mWatch)
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-10-26 14:55:51 +00:00
|
|
|
mDocument->ContentAppended(aContainer, aStartIndex);
|
1999-12-04 01:27:46 +00:00
|
|
|
mLastNotificationTime = PR_Now();
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Restore: nsHTMLContentSink::NotifyAppend()\n"));
|
|
|
|
MOZ_TIMER_RESTORE(mWatch);
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification--;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification++;
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Save and stop: nsHTMLContentSink::NotifyInsert()\n"));
|
|
|
|
MOZ_TIMER_SAVE(mWatch)
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-10-26 14:55:51 +00:00
|
|
|
mDocument->ContentInserted(aContent, aChildContent, aIndexInContainer);
|
1999-12-04 01:27:46 +00:00
|
|
|
mLastNotificationTime = PR_Now();
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Restore: nsHTMLContentSink::NotifyInsert()\n"));
|
|
|
|
MOZ_TIMER_RESTORE(mWatch);
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification--;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
PRBool
|
|
|
|
HTMLContentSink::IsMonolithicContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2000-02-28 21:38:30 +00:00
|
|
|
if (eHTMLTag_tr == aTag || eHTMLTag_select == aTag) {
|
2000-02-16 23:43:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-04 01:27:46 +00:00
|
|
|
PRBool
|
|
|
|
HTMLContentSink::IsTimeToNotify()
|
|
|
|
{
|
2000-02-16 23:43:59 +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;
|
|
|
|
|
|
|
|
LL_I2L(interval, mNotificationInterval);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::BeginUpdate(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
// If we're in a script and we didn't do the notification,
|
|
|
|
// something else in the script processing caused the
|
|
|
|
// notification to occur. Since this could result in frame
|
|
|
|
// creation, make sure we've flushed everything before we
|
|
|
|
// continue
|
|
|
|
if (mInScript && !mInNotification && mCurrentContext) {
|
|
|
|
result = mCurrentContext->FlushTags(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::EndUpdate(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
|
|
|
|
// If we're in a script and we didn't do the notification,
|
|
|
|
// something else in the script processing caused the
|
|
|
|
// notification to occur. Update our notion of how much
|
|
|
|
// has been flushed to include any new content.
|
|
|
|
if (mInScript && !mInNotification) {
|
|
|
|
UpdateAllContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ResumeParsing()
|
|
|
|
{
|
1999-07-27 23:33:16 +00:00
|
|
|
nsresult result=NS_OK;
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mParser) {
|
1999-07-27 23:33:16 +00:00
|
|
|
result=mParser->EnableParser(PR_TRUE);
|
1998-12-15 06:10:59 +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,
|
|
|
|
("HTMLContentSink::PreEvaluateScript: flushing tags before evaluating script"));
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->FlushTags(PR_FALSE);
|
|
|
|
mCurrentContext->SetPreAppend(PR_TRUE);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
mInScript++;
|
1999-05-18 02:08:04 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
|
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
|
|
|
|
HTMLContentSink::PostEvaluateScript(PRBool aBodyPresent)
|
1999-04-13 22:22:51 +00:00
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
mInScript--;
|
2000-01-28 23:43:12 +00:00
|
|
|
mCurrentContext->SetPreAppend(PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
HTMLContentSink::IsInScript()
|
|
|
|
{
|
|
|
|
return (mInScript > 0);
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::EvaluateScript(nsString& aScript,
|
2000-03-07 21:08:46 +00:00
|
|
|
nsIURI *aScriptURI,
|
(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
|
|
|
PRInt32 aLineNo,
|
2000-03-23 04:53:16 +00:00
|
|
|
const char* aVersion)
|
1998-12-15 06:10:59 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (aScript.Length() > 0) {
|
1999-12-03 09:24:22 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE);
|
1999-10-06 21:13:37 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> context;
|
|
|
|
NS_ENSURE_SUCCESS(globalObject->GetContext(getter_AddRefs(context)),
|
|
|
|
NS_ERROR_FAILURE);
|
1999-09-16 00:10:54 +00:00
|
|
|
|
2000-03-23 04:53:16 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
mDocument->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
NS_ASSERTION(principal, "principal required for document");
|
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
nsAutoString ret;
|
|
|
|
char* url = nsnull;
|
|
|
|
|
2000-03-07 21:08:46 +00:00
|
|
|
if (aScriptURI) {
|
|
|
|
(void)aScriptURI->GetSpec(&url);
|
1999-12-03 09:24:22 +00:00
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
PRBool isUndefined;
|
2000-03-23 04:53:16 +00:00
|
|
|
context->EvaluateString(aScript, nsnull, principal, url,
|
1999-12-03 09:24:22 +00:00
|
|
|
aLineNo, aVersion, ret, &isUndefined);
|
|
|
|
|
2000-03-07 21:08:46 +00:00
|
|
|
if (url) {
|
1999-12-03 09:24:22 +00:00
|
|
|
nsCRT::free(url);
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
NS_IMETHODIMP
|
2000-02-02 23:04:47 +00:00
|
|
|
HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus,
|
|
|
|
PRUint32 stringLen,
|
|
|
|
const char* string)
|
1998-12-15 06:10:59 +00:00
|
|
|
{
|
1999-11-02 06:49:44 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-03-25 01:21:21 +00:00
|
|
|
|
|
|
|
if (stringLen) {
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2000-03-28 23:25:26 +00:00
|
|
|
PRUnichar *unicodeString = nsnull;
|
2000-04-05 03:18:41 +00:00
|
|
|
PRInt32 unicodeLength = 0;
|
2000-03-25 01:21:21 +00:00
|
|
|
nsAutoString characterSet;
|
|
|
|
nsICharsetConverterManager *charsetConv = nsnull;
|
|
|
|
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
|
2000-04-14 02:47:28 +00:00
|
|
|
nsIAtom* contentTypeKey = NS_NewAtom("content-type");
|
|
|
|
nsXPIDLCString contenttypeheader;
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = aLoader->GetChannel(getter_AddRefs(channel));
|
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
httpChannel = do_QueryInterface(channel);
|
|
|
|
if (httpChannel) {
|
|
|
|
rv = httpChannel->GetResponseHeader(contentTypeKey, getter_Copies(contenttypeheader));
|
|
|
|
NS_RELEASE(contentTypeKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString contentType; contentType.AssignWithConversion( NS_STATIC_CAST(const char*, contenttypeheader) );
|
2000-04-14 02:47:28 +00:00
|
|
|
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
|
|
|
|
|
|
|
|
if(kNotFound != start)
|
|
|
|
{
|
|
|
|
start += 8; // 8 = "charset=".length
|
|
|
|
PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
|
|
|
|
if(kNotFound == end ) end = contentType.Length();
|
|
|
|
|
|
|
|
contentType.Mid(characterSet, start, end - start);
|
|
|
|
NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &rv);
|
|
|
|
if(NS_SUCCEEDED(rv) && (nsnull != calias) )
|
|
|
|
{
|
|
|
|
nsAutoString preferred;
|
|
|
|
rv = calias->GetPreferred(characterSet, preferred);
|
|
|
|
if(NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
characterSet = preferred;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (characterSet.Length() == 0)) {
|
|
|
|
//charset from script charset tag
|
2000-04-15 20:15:37 +00:00
|
|
|
characterSet.Assign(mScriptCharset);
|
2000-04-14 02:47:28 +00:00
|
|
|
}
|
2000-03-25 01:21:21 +00:00
|
|
|
|
2000-04-14 02:47:28 +00:00
|
|
|
if (NS_FAILED(rv) || (characterSet.Length() == 0) ) {
|
|
|
|
// charset from document default
|
|
|
|
rv = mDocument->GetDocumentCharacterSet(characterSet);
|
|
|
|
}
|
2000-03-25 01:21:21 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not get document charset!");
|
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(kCharsetConverterManagerCID,
|
|
|
|
NS_GET_IID(nsICharsetConverterManager),
|
|
|
|
(nsISupports**)&charsetConv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && (charsetConv))
|
2000-03-21 04:12:56 +00:00
|
|
|
{
|
2000-03-25 01:21:21 +00:00
|
|
|
rv = charsetConv->GetUnicodeDecoder(&characterSet,
|
|
|
|
getter_AddRefs(unicodeDecoder));
|
|
|
|
NS_RELEASE(charsetConv);
|
2000-03-21 04:12:56 +00:00
|
|
|
}
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2000-03-25 01:21:21 +00:00
|
|
|
// converts from the charset to unicode
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = unicodeDecoder->GetMaxLength(string, stringLen, &unicodeLength);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mUnicodeXferBuf.SetCapacity(unicodeLength);
|
|
|
|
unicodeString = (PRUnichar *) mUnicodeXferBuf.GetUnicode();
|
|
|
|
rv = unicodeDecoder->Convert(string, (PRInt32 *) &stringLen, unicodeString, &unicodeLength);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mUnicodeXferBuf.SetLength(unicodeLength);
|
|
|
|
} else {
|
2000-04-05 03:18:41 +00:00
|
|
|
mUnicodeXferBuf.SetLength(0);
|
2000-03-25 01:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-14 02:47:28 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not convert external JavaScript to Unicode!");
|
2000-03-25 01:21:21 +00:00
|
|
|
|
2000-04-05 03:18:41 +00:00
|
|
|
if ((NS_OK == aStatus) && (NS_SUCCEEDED(rv))) {
|
|
|
|
|
|
|
|
nsAutoString jsUnicodeBuffer(CBufDescriptor(unicodeString, PR_TRUE, unicodeLength+1, unicodeLength));
|
2000-03-25 01:21:21 +00:00
|
|
|
PRBool bodyPresent = PreEvaluateScript();
|
|
|
|
|
|
|
|
//-- Merge the principal of the script file with that of the document
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
aLoader->GetOwner(getter_AddRefs(owner));
|
|
|
|
if (owner)
|
|
|
|
{
|
2000-04-23 21:25:39 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> prin = do_QueryInterface(owner, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = mDocument->AddPrincipal(prin);
|
2000-03-25 01:21:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = EvaluateScript(jsUnicodeBuffer, mScriptURI, 1, mScriptLanguageVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2000-03-25 01:21:21 +00:00
|
|
|
PostEvaluateScript(bodyPresent);
|
|
|
|
|
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
rv = ResumeParsing();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-12-15 06:10:59 +00:00
|
|
|
|
|
|
|
// We added a reference when the loader was created. This
|
|
|
|
// release should destroy it.
|
|
|
|
NS_RELEASE(aLoader);
|
2000-03-25 01:21:21 +00:00
|
|
|
//invalidate Xfer buffer content
|
|
|
|
mUnicodeXferBuf.SetLength(0);
|
1999-11-02 06:49:44 +00:00
|
|
|
|
|
|
|
return rv;
|
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;
|
(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
|
|
|
PRBool isJavaScript = PR_TRUE;
|
|
|
|
const char* jsVersionString = nsnull;
|
1998-06-25 22:26:52 +00:00
|
|
|
PRInt32 i, ac = aNode.GetAttributeCount();
|
|
|
|
|
1998-10-30 03:36:35 +00:00
|
|
|
// Look for SRC attribute and look for a LANGUAGE attribute
|
1998-10-01 22:23:48 +00:00
|
|
|
nsAutoString src;
|
1998-06-25 22:26:52 +00:00
|
|
|
for (i = 0; i < ac; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("src")) {
|
1999-12-03 09:24:22 +00:00
|
|
|
GetAttributeValueAt(aNode, i, src);
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
1998-10-30 03:36:35 +00:00
|
|
|
else if (key.EqualsIgnoreCase("type")) {
|
|
|
|
nsAutoString type;
|
1998-06-25 22:26:52 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
GetAttributeValueAt(aNode, i, type);
|
1999-05-26 23:49:33 +00:00
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
SplitMimeType(type, mimeType, params);
|
|
|
|
|
(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
|
|
|
isJavaScript = mimeType.EqualsIgnoreCase("application/x-javascript") ||
|
|
|
|
mimeType.EqualsIgnoreCase("text/javascript");
|
|
|
|
if (isJavaScript) {
|
|
|
|
JSVersion jsVersion = JSVERSION_DEFAULT;
|
|
|
|
if (params.Find("version=", PR_TRUE) == 0) {
|
|
|
|
if (params.Length() != 11 || params[8] != '1' || params[9] != '.')
|
|
|
|
jsVersion = JSVERSION_UNKNOWN;
|
|
|
|
else switch (params[10]) {
|
|
|
|
case '0': jsVersion = JSVERSION_1_0; break;
|
|
|
|
case '1': jsVersion = JSVERSION_1_1; break;
|
|
|
|
case '2': jsVersion = JSVERSION_1_2; break;
|
|
|
|
case '3': jsVersion = JSVERSION_1_3; break;
|
|
|
|
case '4': jsVersion = JSVERSION_1_4; break;
|
|
|
|
case '5': jsVersion = JSVERSION_1_5; break;
|
|
|
|
default: jsVersion = JSVERSION_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jsVersionString = JS_VersionToString(jsVersion);
|
|
|
|
}
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
1998-10-30 03:36:35 +00:00
|
|
|
else if (key.EqualsIgnoreCase("language")) {
|
|
|
|
nsAutoString lang;
|
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
GetAttributeValueAt(aNode, i, lang);
|
(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
|
|
|
isJavaScript = IsJavaScriptLanguage(lang, &jsVersionString);
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
2000-04-14 02:47:28 +00:00
|
|
|
else if (key.EqualsIgnoreCase("charset")) {
|
|
|
|
//charset from script charset tag
|
|
|
|
nsAutoString charset;
|
|
|
|
|
|
|
|
GetAttributeValueAt(aNode, i, charset);
|
|
|
|
NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &rv);
|
|
|
|
if(NS_SUCCEEDED(rv) && (nsnull != calias) )
|
|
|
|
{
|
|
|
|
rv = calias->GetPreferred(charset, mScriptCharset);
|
|
|
|
} else {
|
|
|
|
mScriptCharset = charset;
|
|
|
|
}
|
|
|
|
}
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
1999-07-02 20:59:39 +00:00
|
|
|
nsIHTMLContent* parent = mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString tag; tag.AssignWithConversion("SCRIPT");
|
1999-07-02 20:59:39 +00:00
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
rv = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-03-21 03:25:16 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1999-07-02 20:59:39 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = AddAttributes(aNode, element);
|
1999-07-02 20:59:39 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mCurrentContext->mStack[mCurrentContext->mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(element,
|
|
|
|
mCurrentContext->mStack[mCurrentContext->mStackPos-1].mInsertionPoint++,
|
2000-01-28 23:43:12 +00:00
|
|
|
PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-01-28 23:43:12 +00:00
|
|
|
parent->AppendChildTo(element, PR_FALSE);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1999-07-02 20:59:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a text node holding the content
|
|
|
|
// First, get the text content of the script tag
|
|
|
|
nsAutoString script;
|
2000-04-15 20:15:37 +00:00
|
|
|
script.Assign(aNode.GetSkippedContent());
|
1999-07-02 20:59:39 +00:00
|
|
|
|
|
|
|
if (script.Length() > 0) {
|
|
|
|
nsIContent* text;
|
|
|
|
rv = NS_NewTextNode(&text);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIDOMText* tc;
|
|
|
|
rv = text->QueryInterface(kIDOMTextIID, (void**)&tc);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
tc->SetData(script);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
}
|
2000-01-28 23:43:12 +00:00
|
|
|
element->AppendChildTo(text, PR_FALSE);
|
1999-07-02 20:59:39 +00:00
|
|
|
text->SetDocument(mDocument, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
}
|
|
|
|
}
|
1999-10-05 00:05:38 +00:00
|
|
|
NS_RELEASE(element);
|
1999-07-02 20:59:39 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
// Don't include script loading and evaluation in the stopwatch
|
|
|
|
// that is measuring content creation time
|
1999-11-10 03:41:09 +00:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::ProcessSCRIPTTag()\n"));
|
|
|
|
MOZ_TIMER_STOP(mWatch);
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1999-09-16 23:30:51 +00:00
|
|
|
// Don't process scripts that aren't JavaScript and don't process
|
2000-02-11 01:18:41 +00:00
|
|
|
// scripts that are inside iframes, noframe, or noscript tags.
|
|
|
|
if (isJavaScript && !mNumOpenIFRAMES && !mInsideNoXXXTag) {
|
(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
|
|
|
mScriptLanguageVersion = jsVersionString;
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
// If there is a SRC attribute...
|
|
|
|
if (src.Length() > 0) {
|
1998-12-18 01:36:41 +00:00
|
|
|
// Use the SRC attribute value to load the URL
|
1999-06-23 19:55:21 +00:00
|
|
|
{
|
2000-03-07 21:08:46 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(mScriptURI), src, mDocumentBaseURL);
|
1998-10-30 03:36:35 +00:00
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1998-10-30 03:36:35 +00:00
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-11-16 05:07:31 +00:00
|
|
|
// Check that this page is allowed to load this URI.
|
|
|
|
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
|
|
|
|
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-03-07 21:08:46 +00:00
|
|
|
rv = securityManager->CheckLoadURI(mDocumentBaseURL, mScriptURI, PR_FALSE);
|
1999-11-16 05:07:31 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-11-02 23:44:27 +00:00
|
|
|
|
1999-09-18 06:20:49 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2000-02-02 23:04:47 +00:00
|
|
|
nsIStreamLoader* loader;
|
1999-09-18 06:20:49 +00:00
|
|
|
|
|
|
|
mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
2000-03-10 06:25:13 +00:00
|
|
|
rv = NS_NewStreamLoader(&loader, mScriptURI, this, nsnull, loadGroup,
|
|
|
|
nsnull, nsIChannel::FORCE_RELOAD);
|
1998-12-18 01:36:41 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
1998-10-30 03:36:35 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-05-18 02:08:04 +00:00
|
|
|
PRBool bodyPresent = PreEvaluateScript();
|
1999-04-13 22:22:51 +00:00
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
PRUint32 lineNo = (PRUint32)aNode.GetSourceLineNumber();
|
2000-03-07 21:08:46 +00:00
|
|
|
nsIURI *docURI = mDocument->GetDocumentURL();
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2000-03-23 04:53:16 +00:00
|
|
|
EvaluateScript(script, docURI, lineNo, jsVersionString);
|
2000-03-21 04:12:56 +00:00
|
|
|
NS_IF_RELEASE(docURI);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1999-05-18 02:08:04 +00:00
|
|
|
PostEvaluateScript(bodyPresent);
|
1999-04-13 22:22:51 +00:00
|
|
|
|
|
|
|
// If the parse was disabled as a result of this evaluate script
|
|
|
|
// (for example, if the script document.wrote a SCRIPT SRC= tag,
|
|
|
|
// we remind the parser to block.
|
|
|
|
if ((nsnull != mParser) && (PR_FALSE == mParser->IsParserEnabled())) {
|
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
1998-06-25 22:26:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +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;
|
|
|
|
|
|
|
|
if(mCurrentContext!=nsnull) {
|
|
|
|
parent=mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
if(parent!=nsnull) {
|
|
|
|
// Create content object
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString tag; tag.AssignWithConversion("STYLE");
|
2000-02-11 22:07:12 +00:00
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
rv = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-03-21 03:25:16 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
element->SetContentID(id);
|
1999-08-31 11:17:26 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
|
|
|
rv = AddAttributes(aNode, element);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
parent->AppendChildTo(element, PR_FALSE);
|
1998-11-26 01:29:10 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
if(!mInsideNoXXXTag && NS_SUCCEEDED(rv)) {
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
PRInt32 i, count = aNode.GetAttributeCount();
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
nsAutoString src;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
1999-05-26 23:49:33 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("src")) {
|
|
|
|
GetAttributeValueAt(aNode, i, src);
|
|
|
|
src.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("title")) {
|
|
|
|
GetAttributeValueAt(aNode, i, title);
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("type")) {
|
|
|
|
GetAttributeValueAt(aNode, i, type);
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("media")) {
|
|
|
|
GetAttributeValueAt(aNode, i, media);
|
|
|
|
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
}
|
1999-05-26 23:49:33 +00:00
|
|
|
}
|
|
|
|
|
1999-01-06 00:19:46 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
SplitMimeType(type, mimeType, params);
|
|
|
|
|
2000-04-05 04:02:38 +00:00
|
|
|
PRBool blockParser = kBlockByDefault;
|
2000-02-11 22:07:12 +00:00
|
|
|
|
|
|
|
if ((0 == mimeType.Length()) || mimeType.EqualsIgnoreCase("text/css")) {
|
1999-07-01 21:39:14 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
if (0 < title.Length()) { // possibly preferred sheet
|
|
|
|
if (0 == mPreferredStyle.Length()) {
|
|
|
|
mPreferredStyle = title;
|
|
|
|
mCSSLoader->SetPreferredSheet(title);
|
|
|
|
mDocument->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, title);
|
|
|
|
}
|
1999-07-01 21:39:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// The skipped content contains the inline style data
|
|
|
|
const nsString& content = aNode.GetSkippedContent();
|
|
|
|
PRBool doneLoading = PR_FALSE;
|
|
|
|
|
|
|
|
nsIUnicharInputStream* uin = nsnull;
|
|
|
|
if (0 == src.Length()) {
|
|
|
|
|
|
|
|
// Create a text node holding the content
|
|
|
|
nsIContent* text;
|
|
|
|
rv = NS_NewTextNode(&text);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsIDOMText* tc;
|
|
|
|
rv = text->QueryInterface(kIDOMTextIID, (void**)&tc);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
tc->SetData(content);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
}
|
|
|
|
element->AppendChildTo(text, PR_FALSE);
|
|
|
|
text->SetDocument(mDocument, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// Create a string to hold the data and wrap it up in a unicode
|
|
|
|
// input stream.
|
|
|
|
rv = NS_NewStringUnicharInputStream(&uin, new nsString(content));
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
// Now that we have a url and a unicode input stream, parse the
|
|
|
|
// style sheet.
|
|
|
|
rv = mCSSLoader->LoadInlineStyle(element, uin, title, media, kNameSpaceID_HTML,
|
|
|
|
mStyleSheetCount++,
|
|
|
|
((blockParser) ? mParser : nsnull),
|
|
|
|
doneLoading, this);
|
|
|
|
NS_RELEASE(uin);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// src with immediate style data doesn't add up
|
|
|
|
// XXX what does nav do?
|
|
|
|
// Use the SRC attribute value to load the URL
|
|
|
|
nsIURI* url = nsnull;
|
|
|
|
{
|
|
|
|
rv = NS_NewURI(&url, src, mDocumentBaseURL);
|
|
|
|
}
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2000-02-11 22:07:12 +00:00
|
|
|
rv = mCSSLoader->LoadStyleLink(element, url, title, media, kNameSpaceID_HTML,
|
|
|
|
mStyleSheetCount++,
|
|
|
|
((blockParser) ? mParser : nsnull),
|
|
|
|
doneLoading, this);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && blockParser && (! doneLoading)) {
|
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}//if ((0 == mimeType.Length()) || mimeType.EqualsIgnoreCase("text/css"))
|
|
|
|
}//if(!mInsideNoXXXTag && NS_SUCCEEDED(rv))
|
|
|
|
NS_RELEASE(element);
|
|
|
|
}//if(parent!=nsnull)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-03-06 02:01:11 +00:00
|
|
|
HTMLContentSink::NotifyError(const nsParserError* aError)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
// Errors in HTML? Who would have thought!
|
2000-02-15 22:03:05 +00:00
|
|
|
// Why are you telling us, parser. Deal with it yourself.
|
1998-11-11 22:06:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-15 05:11:43 +00:00
|
|
|
|
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
|
|
|
|
// (since we aren't reentrant) and if we're in a script (since
|
|
|
|
// we only care to flush if this is done via script).
|
|
|
|
if (mCurrentContext && !mInNotification && mInScript) {
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::DoFragment(PRBool aFlag)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|