1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.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"
|
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"
|
1999-06-27 16:12:20 +00:00
|
|
|
#include "nsIUnicharStreamLoader.h"
|
1999-06-23 19:55:21 +00:00
|
|
|
#include "nsNeckoUtil.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-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"
|
1999-05-06 19:26:43 +00:00
|
|
|
#include "nsIHTMLElementFactory.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"
|
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"
|
|
|
|
|
1998-07-18 21:47:56 +00:00
|
|
|
#include "nsIWebShell.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsIDocument.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"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsIScriptContextOwner.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-01-19 16:58:45 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIParserService.h"
|
|
|
|
#include "nsParserCIID.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-09-14 14:38:52 +00:00
|
|
|
#include "stopwatch.h"
|
1999-11-02 23:44:27 +00:00
|
|
|
#include "nsDOMError.h"
|
1999-09-14 14:38:52 +00:00
|
|
|
|
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);
|
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
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
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,
|
|
|
|
public nsIUnicharStreamLoaderObserver
|
|
|
|
{
|
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
|
1999-11-02 06:49:44 +00:00
|
|
|
NS_DECL_NSIUNICHARSTREAMLOADEROBSERVER
|
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);
|
|
|
|
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-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,
|
|
|
|
nsString& aResult,
|
|
|
|
nsIScriptContextOwner* aScriptContextOwner);
|
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aContent,
|
|
|
|
nsIScriptContextOwner* aScriptContextOwner,
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
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;
|
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;
|
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
|
|
|
|
1998-07-22 23:42:47 +00:00
|
|
|
nsString* mRef;
|
|
|
|
nsScrollPreference mOriginalScrollPreference;
|
|
|
|
PRBool mNotAtRef;
|
|
|
|
nsIHTMLContent* mRefContent;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsString mBaseHREF;
|
|
|
|
nsString mBaseTarget;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
nsString mPreferredStyle;
|
|
|
|
PRInt32 mStyleSheetCount;
|
1999-05-18 23:05:43 +00:00
|
|
|
nsICSSLoader* mCSSLoader;
|
1999-08-31 11:17:26 +00:00
|
|
|
PRUint32 mContentIDCounter;
|
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,
|
(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,
|
|
|
|
const char* aVersion);
|
|
|
|
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);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void ForceReflow();
|
1999-04-03 19:00:23 +00:00
|
|
|
#endif
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1999-10-19 22:27:20 +00:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-09-14 14:38:52 +00:00
|
|
|
Stopwatch mWatch; // Measures content model creation time for current document
|
|
|
|
#endif
|
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);
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
nsresult FlushTags();
|
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;
|
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;
|
|
|
|
nsAutoString str(cbuf);
|
|
|
|
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,
|
|
|
|
nsString& aResult,
|
|
|
|
nsIScriptContextOwner* aScriptContextOwner)
|
1998-11-17 16:29:25 +00:00
|
|
|
{
|
|
|
|
// Copy value
|
|
|
|
const nsString& value = aNode.GetValueAt(aIndex);
|
|
|
|
aResult.Truncate();
|
|
|
|
aResult.Append(value);
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
nsIScriptContextOwner* aScriptContextOwner,
|
|
|
|
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
|
|
|
|
GetAttributeValueAt(aNode, i, v, aScriptContextOwner);
|
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-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;
|
1998-10-23 04:20:08 +00:00
|
|
|
case eHTMLTag_layer:
|
|
|
|
rv = NS_NewHTMLLayerElement(aResult, aAtom);
|
|
|
|
break;
|
1999-03-30 15:20:14 +00:00
|
|
|
case eHTMLTag_ilayer:
|
|
|
|
rv = NS_NewHTMLLayerElement(aResult, aAtom);
|
|
|
|
break;
|
1998-09-03 22:23:09 +00:00
|
|
|
case eHTMLTag_legend:
|
|
|
|
rv = NS_NewHTMLLegendElement(aResult, aAtom);
|
|
|
|
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;
|
|
|
|
}
|
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) {
|
|
|
|
content = aNode.GetSkippedContent();
|
|
|
|
}
|
|
|
|
rv = MakeContentObject(aNodeType, atom, aForm, aWebShell,
|
|
|
|
aResult, &content);
|
|
|
|
|
|
|
|
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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-05-06 19:26:43 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID);
|
|
|
|
|
|
|
|
class nsHTMLElementFactory : public nsIHTMLElementFactory {
|
|
|
|
public:
|
|
|
|
nsHTMLElementFactory();
|
|
|
|
virtual ~nsHTMLElementFactory();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CreateInstanceByTag(const nsString& aTag,
|
|
|
|
nsIHTMLContent** aResult);
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLElementFactory(nsIHTMLElementFactory** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return it->QueryInterface(kIHTMLElementFactoryIID,
|
|
|
|
(void**)aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLElementFactory::~nsHTMLElementFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLElementFactory, kIHTMLElementFactoryIID);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLElementFactory::CreateInstanceByTag(const nsString& aTag,
|
|
|
|
nsIHTMLContent** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = NS_CreateHTMLElement(aResult, aTag);
|
|
|
|
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;
|
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-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
|
|
|
content->SetContentID(mSink->mContentIDCounter++);
|
|
|
|
|
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
|
|
|
|
1998-09-03 01:23:12 +00:00
|
|
|
nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner();
|
1999-09-30 22:07:04 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content, sco);
|
1998-09-03 01:23:12 +00:00
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mPreAppend) {
|
|
|
|
NS_ASSERTION(mStackPos > 0, "container w/o parent");
|
|
|
|
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++,
|
|
|
|
mSink->IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(content, mSink->IsInScript());
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
|
|
|
case eHTMLTag_a:
|
|
|
|
mSink->ProcessATag(aNode, content);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_table:
|
1999-03-25 06:40:06 +00:00
|
|
|
case eHTMLTag_layer:
|
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tbody:
|
|
|
|
case eHTMLTag_tfoot:
|
1999-03-20 15:42:21 +00:00
|
|
|
case eHTMLTag_tr:
|
|
|
|
case eHTMLTag_td:
|
|
|
|
case eHTMLTag_th:
|
|
|
|
// XXX if navigator_quirks_mode (only body in html supports background)
|
|
|
|
mSink->AddBaseTagInfo(content);
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1999-03-01 16:57:35 +00:00
|
|
|
case eHTMLTag_map:
|
|
|
|
mSink->ProcessMAPTag(aNode, content);
|
|
|
|
break;
|
1999-09-16 23:30:51 +00:00
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES++;
|
|
|
|
break;
|
1999-02-12 17:45:58 +00:00
|
|
|
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)) {
|
|
|
|
NS_ASSERTION(mStackPos > 0, "container w/o parent");
|
|
|
|
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++,
|
|
|
|
mSink->IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = parent->AppendChildTo(content, mSink->IsInScript());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
1999-10-27 14:03:15 +00:00
|
|
|
DidAddContent(content, mSink->IsInScript());
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1999-09-13 22:30:36 +00:00
|
|
|
NS_IF_RELEASE(content);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
1999-09-11 14:55:33 +00:00
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
case eHTMLTag_form:
|
|
|
|
{
|
|
|
|
nsHTMLTag parserNodeType = nsHTMLTag(aNode.GetNodeType());
|
|
|
|
|
|
|
|
// 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
|
1999-10-26 14:55:51 +00:00
|
|
|
// of invalid form nesting. When the end FORM tag comes through,
|
|
|
|
// we'll ignore it.
|
1999-07-22 23:28:16 +00:00
|
|
|
if (parserNodeType != nodeType) {
|
|
|
|
result = CloseContainer(aNode);
|
|
|
|
}
|
|
|
|
}
|
1999-09-21 00:18:49 +00:00
|
|
|
break;
|
1999-09-16 23:30:51 +00:00
|
|
|
|
|
|
|
case eHTMLTag_iframe:
|
|
|
|
mSink->mNumOpenIFRAMES--;
|
|
|
|
break;
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-07-20 18:52:40 +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-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;
|
|
|
|
|
|
|
|
// 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-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
// Flush all tags and do notifications - it's easier to deal
|
|
|
|
// with later notifications.
|
|
|
|
FlushTags();
|
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.
|
|
|
|
result = container->RemoveChildAt(0, PR_TRUE);
|
|
|
|
// 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-10-26 14:55:51 +00:00
|
|
|
result = container->RemoveChildAt(0, PR_TRUE);
|
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.
|
|
|
|
result = parent->AppendChildTo(child, PR_TRUE);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
content->SetContentID(mSink->mContentIDCounter++);
|
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
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
nsIScriptContextOwner* sco = mSink->mDocument->GetScriptContextOwner();
|
1999-09-30 22:07:04 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content, sco);
|
1998-08-31 17:51:32 +00:00
|
|
|
NS_IF_RELEASE(sco);
|
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') {
|
|
|
|
tmp = "\n";
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mStackPos > 0, "leaf w/o container");
|
|
|
|
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++,
|
|
|
|
mSink->IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(aContent, mSink->IsInScript());
|
|
|
|
}
|
1999-01-09 00:14:53 +00:00
|
|
|
|
1999-10-27 14:03:15 +00:00
|
|
|
DidAddContent(aContent, mSink->IsInScript());
|
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++,
|
|
|
|
mSink->IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(comment, mSink->IsInScript());
|
|
|
|
}
|
1999-01-22 22:48:00 +00:00
|
|
|
|
1999-10-27 14:03:15 +00:00
|
|
|
DidAddContent(comment, mSink->IsInScript());
|
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()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mStackPos == 1, "insufficient close container calls");
|
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
|
|
|
|
SinkContext::FlushTags()
|
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
1999-09-16 23:30:51 +00:00
|
|
|
if (eHTMLTag_iframe == mStack[mStackPos].mType) {
|
|
|
|
mSink->mNumOpenIFRAMES--;
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
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));
|
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
|
|
|
|
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--;
|
|
|
|
}
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
1998-09-06 00:20:59 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Add text to its parent
|
|
|
|
NS_ASSERTION(mStackPos > 0, "leaf w/o container");
|
|
|
|
nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
if (mStack[mStackPos-1].mInsertionPoint != -1) {
|
|
|
|
parent->InsertChildAt(content,
|
|
|
|
mStack[mStackPos-1].mInsertionPoint++,
|
|
|
|
mSink->IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(content, mSink->IsInScript());
|
|
|
|
}
|
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
|
|
|
|
1999-10-27 14:03:15 +00:00
|
|
|
DidAddContent(content, mSink->IsInScript());
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
mTextLength = 0;
|
|
|
|
didFlush = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (nsnull != aDidFlush) {
|
|
|
|
*aDidFlush = didFlush;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
if (aReleaseLast && mLastTextNode) {
|
|
|
|
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
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::HTMLContentSink()
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull == gSinkLogModuleInfo) {
|
|
|
|
gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink");
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-19 17:26:06 +00:00
|
|
|
mNotAtRef = PR_TRUE;
|
1999-08-31 11:17:26 +00:00
|
|
|
mContentIDCounter = NS_CONTENT_ID_COUNTER_BASE;
|
1999-10-26 14:55:51 +00:00
|
|
|
mInScript = 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
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IF_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-10-26 14:55:51 +00:00
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
|
|
|
for (PRInt32 i = 0; i < numContexts; i++) {
|
|
|
|
SinkContext* sc = (SinkContext*)mContextStack.ElementAt(i);
|
1998-08-28 16:20:16 +00:00
|
|
|
sc->End();
|
|
|
|
if (sc == mCurrentContext) {
|
|
|
|
mCurrentContext = nsnull;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
delete sc;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mCurrentContext == mHeadContext) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(HTMLContentSink, nsIHTMLContentSink, nsIUnicharStreamLoaderObserver)
|
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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Reset and start: nsHTMLContentSink::Init(), this=%p\n", this));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_RESET_AND_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::Init()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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);
|
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-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
|
1998-09-08 22:38:17 +00:00
|
|
|
nsresult rv = NS_NewHTMLHtmlElement(&mRoot, nsHTMLAtoms::html);
|
1998-07-30 16:06:22 +00:00
|
|
|
if (NS_OK != rv) {
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::Init()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::Init()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::Init()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::Init()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::DidBuildModel(), this=%p\n", this));
|
1999-09-20 06:48:33 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_TRACE(("Content creation time (this=%p): ", this));
|
1999-09-14 19:24:42 +00:00
|
|
|
mWatch.Print();
|
1999-09-24 08:57:36 +00:00
|
|
|
RAPTOR_STOPWATCH_TRACE(("\n"));
|
1999-09-14 19:24:42 +00:00
|
|
|
#endif
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1998-08-10 17:39:48 +00:00
|
|
|
if (nsnull == mTitle) {
|
1999-01-15 02:02:48 +00:00
|
|
|
mHTMLDocument->SetTitle("");
|
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"));
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTags();
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
1998-07-27 18:04:38 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::WillInterrupt: this=%p", this));
|
1999-10-26 14:55:51 +00:00
|
|
|
return mCurrentContext->FlushTags();
|
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));
|
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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::BeginContext()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-04-15 20:18:34 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mCurrentContext != nsnull," Non-existing context");
|
|
|
|
|
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.
|
|
|
|
mCurrentContext->FlushTags();
|
|
|
|
|
|
|
|
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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::BeginContext()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::EndContext()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::EndContext()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::SetTitle()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::SetTitle()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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) {
|
|
|
|
tc->SetData(aValue);
|
|
|
|
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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::SetTitle()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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
|
|
|
|
|
|
|
NS_START_STOPWATCH(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);
|
1999-09-14 19:24:42 +00:00
|
|
|
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::CloseHTML(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseHTML()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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) {
|
|
|
|
mHeadContext->End();
|
|
|
|
delete mHeadContext;
|
|
|
|
mHeadContext = nsnull;
|
|
|
|
}
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseHTML()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenHead(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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) {
|
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
|
|
|
rv = AddAttributes(aNode, mHead, sco);
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
}
|
|
|
|
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseHead()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenBody(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-04-25 22:18:49 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
|
|
|
AddAttributes(aNode,mBody,sco,PR_TRUE);
|
1999-09-14 19:24:42 +00:00
|
|
|
NS_IF_RELEASE(sco);
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mBody = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
|
|
|
NS_ADDREF(mBody);
|
|
|
|
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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"));
|
|
|
|
mCurrentContext->FlushTags();
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext->CloseContainer(aNode);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseBody()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenForm()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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)) {
|
|
|
|
nsAutoString tmp("form");
|
|
|
|
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
|
|
|
|
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenForm()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseForm()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseForm()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenFrameset()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenFrameset()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseFrameset()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseFrameset()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenMap()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenMap()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseMap()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseMap()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::OpenContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::OpenContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::CloseContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::CloseContainer()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::AddLeaf()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::AddLeaf()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::AddComment()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(mWatch)
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
rv = mCurrentContext->AddComment(aNode);
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::AddComment()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(mWatch)
|
1999-09-14 14:38:52 +00:00
|
|
|
// Implementation of AddProcessingInstruction() should start here
|
|
|
|
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Start: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_START_STOPWATCH(mWatch)
|
1999-09-15 17:57:16 +00:00
|
|
|
|
|
|
|
rv=mHTMLDocument->AddDocTypeDecl(aNode.GetText(),(nsDTDMode)aMode);
|
|
|
|
|
1999-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::AddDocTypeDecl()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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-03-31 19:18:39 +00:00
|
|
|
// If it's a frameset document then disable scrolling. If it is not a <frame>
|
1999-01-19 23:16:02 +00:00
|
|
|
// document, then let the style dictate. We need to do this before the initial reflow...
|
1998-12-20 23:29:47 +00:00
|
|
|
if (mWebShell) {
|
1999-09-08 23:51:02 +00:00
|
|
|
// initially show the scrollbars. We need to do this because another
|
|
|
|
// document like a XUL document, could have have hidden the scrollbars. -EDV
|
|
|
|
mWebShell->SetScrolling(-1, PR_FALSE);
|
1999-03-31 19:18:39 +00:00
|
|
|
if (mFrameset) {
|
1999-04-09 21:09:00 +00:00
|
|
|
mWebShell->SetScrolling(NS_STYLE_OVERFLOW_HIDDEN, PR_FALSE);
|
1999-03-31 19:18:39 +00:00
|
|
|
}
|
|
|
|
else if (mBody) {
|
1999-01-19 23:16:02 +00:00
|
|
|
PRBool isFrameDoc = PR_FALSE;
|
|
|
|
mWebShell->GetIsFrame(isFrameDoc);
|
1999-03-31 19:18:39 +00:00
|
|
|
// a <frame> webshell will have its scrolling set by the parent nsFramesetFrame.
|
|
|
|
// a <body> webshell is reset here just for safety.
|
1999-01-19 23:16:02 +00:00
|
|
|
if (!isFrameDoc) {
|
1999-04-09 21:09:00 +00:00
|
|
|
mWebShell->SetScrolling(-1, PR_FALSE);
|
1999-01-19 23:16:02 +00:00
|
|
|
}
|
1999-01-19 17:26:06 +00:00
|
|
|
}
|
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;
|
1999-08-27 21:52:19 +00:00
|
|
|
nsresult rv = mDocumentURI->QueryInterface(nsIURL::GetIID(), (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) {
|
1998-08-28 16:20:16 +00:00
|
|
|
mRef = new nsString(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;
|
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
area->SetContentID(mContentIDCounter++);
|
1999-01-09 00:14:53 +00:00
|
|
|
|
|
|
|
// Set the content's document and attributes
|
1999-08-31 11:17:26 +00:00
|
|
|
area->SetDocument(mDocument, PR_FALSE);
|
1998-08-31 17:51:32 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
1999-01-09 00:14:53 +00:00
|
|
|
rv = AddAttributes(aNode, area, sco);
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
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) {
|
|
|
|
nsIContentViewer* contentViewer = nsnull;
|
|
|
|
nsresult rv = mWebShell->GetContentViewer(&contentViewer);
|
|
|
|
if (NS_SUCCEEDED(rv) && (contentViewer != nsnull)) {
|
|
|
|
PRBool enabled;
|
|
|
|
contentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
|
|
|
vm->EnableRefresh();
|
|
|
|
}
|
|
|
|
NS_RELEASE(contentViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
1998-08-31 17:51:32 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
1999-06-16 00:44:50 +00:00
|
|
|
|
|
|
|
// Create content object
|
|
|
|
nsAutoString tag("BASE");
|
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
result = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-08-31 11:17:26 +00:00
|
|
|
element->SetContentID(mContentIDCounter++);
|
|
|
|
|
1999-06-16 00:44:50 +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, sco);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
mHead->AppendChildTo(element, PR_FALSE);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-16 00:44:50 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
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) {
|
|
|
|
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
|
|
|
|
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;
|
|
|
|
while (nsString::IsSpace(*value)) {
|
|
|
|
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) {
|
|
|
|
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (! nsString::IsSpace(*end))) { // look for space
|
|
|
|
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-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);
|
|
|
|
|
|
|
|
if (-1 != linkTypes.IndexOf("stylesheet")) { // is it a stylesheet link?
|
|
|
|
|
|
|
|
if (-1 != linkTypes.IndexOf("alternate")) { // if alternate, does it have title?
|
|
|
|
if (0 == aTitle.Length()) { // alternates must have title
|
|
|
|
return NS_OK; //return without error, for now
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
SplitMimeType(aType, mimeType, params);
|
|
|
|
|
|
|
|
if ((0 == mimeType.Length()) || mimeType.EqualsIgnoreCase("text/css")) {
|
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
|
|
|
}
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
if (-1 == linkTypes.IndexOf("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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
PRBool blockParser = PR_FALSE;
|
|
|
|
if (-1 != linkTypes.IndexOf("important")) {
|
|
|
|
blockParser = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
doneLoading);
|
1999-01-23 07:05:49 +00:00
|
|
|
NS_RELEASE(url);
|
1999-05-26 23:49:33 +00:00
|
|
|
if (NS_SUCCEEDED(result) && blockParser && (! doneLoading)) {
|
1999-01-23 07:05:49 +00:00
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
1999-07-05 19:45:27 +00:00
|
|
|
PRInt32 i;
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 count = aNode.GetAttributeCount();
|
1998-08-13 20:09:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsAutoString href;
|
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
1998-11-26 01:29:10 +00:00
|
|
|
nsAutoString media;
|
1998-08-13 20:09:10 +00:00
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
1999-07-05 19:45:27 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (key.EqualsIgnoreCase("href")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, href, sco);
|
1998-08-28 16:20:16 +00:00
|
|
|
href.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("rel")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, rel, sco);
|
1998-08-28 16:20:16 +00:00
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("title")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, title, sco);
|
1998-08-28 16:20:16 +00:00
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("type")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, type, sco);
|
1998-08-28 16:20:16 +00:00
|
|
|
type.StripWhitespace();
|
1998-06-26 15:08:55 +00:00
|
|
|
}
|
1998-11-26 01:29:10 +00:00
|
|
|
else if (key.EqualsIgnoreCase("media")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, media, sco);
|
1999-05-26 23:49:33 +00:00
|
|
|
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
1998-11-26 01:29:10 +00:00
|
|
|
}
|
1998-06-26 15:08:55 +00:00
|
|
|
}
|
1998-08-13 20:09:10 +00:00
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
// Create content object
|
|
|
|
nsAutoString tag("LINK");
|
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
result = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-08-31 11:17:26 +00:00
|
|
|
element->SetContentID(mContentIDCounter++);
|
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
1999-08-31 11:17:26 +00:00
|
|
|
// head container.
|
1999-02-27 07:13:48 +00:00
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
1998-11-26 01:29:10 +00:00
|
|
|
result = AddAttributes(aNode, element, sco);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
mHead->AppendChildTo(element, PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
result = ProcessStyleLink(element, href, rel, title, type, media);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
NS_RELEASE(element);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (nsnull != mHead) {
|
|
|
|
// Create content object
|
1999-02-12 06:19:07 +00:00
|
|
|
nsAutoString tmp("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.
|
1998-08-31 17:51:32 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
1999-02-27 07:13:48 +00:00
|
|
|
it->SetDocument(mDocument, PR_FALSE);
|
1998-08-31 17:51:32 +00:00
|
|
|
rv = AddAttributes(aNode, it, sco);
|
|
|
|
NS_IF_RELEASE(sco);
|
1998-08-28 16:20:16 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(it);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mHead->AppendChildTo(it, PR_FALSE);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
// 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) {
|
1999-08-03 21:48:40 +00:00
|
|
|
// 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-04 21:19:22 +00:00
|
|
|
// see if we have a refresh "header".
|
1999-08-04 01:27:22 +00:00
|
|
|
if (!header.Compare("refresh", PR_TRUE)) {
|
1999-08-04 21:19:22 +00:00
|
|
|
// Refresh haders 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"
|
|
|
|
// result = "5; URL=http://uri" // note the URL attribute is optional, if it
|
|
|
|
// is absent, the currently loaded url is used.
|
|
|
|
const PRUnichar *uriCStr = nsnull;
|
|
|
|
nsAutoString uriAttribStr;
|
|
|
|
|
|
|
|
// first get our baseURI
|
|
|
|
rv = mWebShell->GetURL(&uriCStr);
|
1999-08-04 01:27:22 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-04 21:19:22 +00:00
|
|
|
|
|
|
|
nsIURI *baseURI = nsnull;
|
|
|
|
rv = NS_NewURI(&baseURI, uriCStr, nsnull);
|
1999-08-04 01:27:22 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-04 21:19:22 +00:00
|
|
|
// next get any uri provided as an attribute in the tag.
|
1999-08-13 23:50:29 +00:00
|
|
|
PRInt32 loc = result.Find("url", PR_TRUE);
|
|
|
|
PRInt32 urlLoc = loc;
|
|
|
|
if (loc > -1) {
|
1999-08-04 21:19:22 +00:00
|
|
|
// there is a url attribute, let's use it.
|
1999-08-13 23:50:29 +00:00
|
|
|
loc += 3;
|
1999-08-04 21:19:22 +00:00
|
|
|
// go past the '=' sign
|
1999-08-13 23:50:29 +00:00
|
|
|
loc = result.Find("=", PR_TRUE, loc);
|
|
|
|
if (loc > -1) {
|
|
|
|
loc++; // leading/trailign spaces get trimmed in url creating code.
|
|
|
|
result.Mid(uriAttribStr, loc, result.Length() - loc);
|
1999-08-04 21:19:22 +00:00
|
|
|
uriCStr = uriAttribStr.GetUnicode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-04 01:27:22 +00:00
|
|
|
nsIURI *uri = nsnull;
|
1999-08-04 21:19:22 +00:00
|
|
|
rv = NS_NewURI(&uri, uriCStr, baseURI);
|
|
|
|
NS_RELEASE(baseURI);
|
1999-08-04 01:27:22 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-04 21:19:22 +00:00
|
|
|
// the units of the numeric value contained in the result are seconds.
|
|
|
|
// we need them in milliseconds before handing off to the refresh interface.
|
1999-08-13 23:50:29 +00:00
|
|
|
|
|
|
|
PRInt32 millis;
|
|
|
|
if (urlLoc > 1) {
|
|
|
|
nsString2 seconds;
|
|
|
|
result.Left(seconds, urlLoc-2);
|
|
|
|
millis = seconds.ToInteger(&loc) * 1000;
|
|
|
|
} else {
|
|
|
|
millis = result.ToInteger(&loc) * 1000;
|
|
|
|
}
|
1999-08-04 21:19:22 +00:00
|
|
|
|
|
|
|
nsIRefreshURI *reefer = nsnull;
|
|
|
|
rv = mWebShell->QueryInterface(nsCOMTypeInfo<nsIRefreshURI>::GetIID(), (void**)&reefer);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(uri);
|
|
|
|
return rv;
|
|
|
|
};
|
|
|
|
|
1999-08-04 01:27:22 +00:00
|
|
|
rv = reefer->RefreshURI(uri, millis, PR_FALSE);
|
1999-08-04 21:19:22 +00:00
|
|
|
NS_RELEASE(uri);
|
|
|
|
NS_RELEASE(reefer);
|
1999-08-04 01:27:22 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-01-23 07:05:49 +00:00
|
|
|
|
1999-02-12 06:19:07 +00:00
|
|
|
header.ToLowerCase();
|
1999-01-23 07:05:49 +00:00
|
|
|
nsIAtom* fieldAtom = NS_NewAtom(header);
|
|
|
|
mDocument->SetHeaderData(fieldAtom, result);
|
|
|
|
|
|
|
|
if (fieldAtom == nsHTMLAtoms::headerDefaultStyle) {
|
|
|
|
mPreferredStyle = result;
|
1999-05-18 23:05:43 +00:00
|
|
|
mCSSLoader->SetPreferredSheet(mPreferredStyle);
|
1999-01-23 07:05:49 +00:00
|
|
|
}
|
|
|
|
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);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
1998-08-27 00:48:53 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_RELEASE(it);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1999-01-23 07:05:49 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
mCurrentContext->FlushTags();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyAppend(nsIContent* aContainer, PRInt32 aStartIndex)
|
|
|
|
{
|
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Save and stop: nsHTMLContentSink::NotifyAppend()\n"));
|
|
|
|
NS_SAVE_STOPWATCH_STATE(mWatch)
|
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
|
|
|
mDocument->ContentAppended(aContainer, aStartIndex);
|
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Restore: nsHTMLContentSink::NotifyAppend()\n"));
|
|
|
|
NS_RESTORE_STOPWATCH_STATE(mWatch)
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Save and stop: nsHTMLContentSink::NotifyInsert()\n"));
|
|
|
|
NS_SAVE_STOPWATCH_STATE(mWatch)
|
|
|
|
NS_STOP_STOPWATCH(mWatch)
|
|
|
|
mDocument->ContentInserted(aContent, aChildContent, aIndexInContainer);
|
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Restore: nsHTMLContentSink::NotifyInsert()\n"));
|
|
|
|
NS_RESTORE_STOPWATCH_STATE(mWatch)
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::UpdateAllContexts()
|
|
|
|
{
|
|
|
|
PRInt32 numContexts = mContextStack.Count();
|
|
|
|
for (PRInt32 i = 0; i < numContexts; i++) {
|
|
|
|
SinkContext* sc = (SinkContext*)mContextStack.ElementAt(i);
|
|
|
|
|
|
|
|
sc->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ResumeParsing()
|
|
|
|
{
|
1999-07-27 23:33:16 +00:00
|
|
|
nsresult result=NS_OK;
|
1998-12-15 06:10:59 +00:00
|
|
|
if (nsnull != 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"));
|
1999-05-18 02:08:04 +00:00
|
|
|
mCurrentContext->FlushTags();
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
mInScript++;
|
1999-05-18 02:08:04 +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--;
|
|
|
|
|
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
(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,
|
|
|
|
const char* aVersion)
|
1998-12-15 06:10:59 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (aScript.Length() > 0) {
|
|
|
|
nsIScriptContextOwner *owner;
|
|
|
|
nsIScriptContext *context;
|
|
|
|
owner = mDocument->GetScriptContextOwner();
|
|
|
|
if (nsnull != owner) {
|
|
|
|
|
|
|
|
rv = owner->GetScriptContext(&context);
|
|
|
|
if (rv != NS_OK) {
|
|
|
|
NS_RELEASE(owner);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-10-06 21:13:37 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
principal = getter_AddRefs(mDocument->GetDocumentPrincipal());
|
|
|
|
NS_ASSERTION(principal, "principal expected for document");
|
1998-12-15 06:10:59 +00:00
|
|
|
|
|
|
|
nsAutoString ret;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* docURL = mDocument->GetDocumentURL();
|
1999-09-16 00:10:54 +00:00
|
|
|
char* url = nsnull;
|
|
|
|
|
1998-12-15 06:10:59 +00:00
|
|
|
if (docURL) {
|
1998-12-16 05:40:20 +00:00
|
|
|
(void)docURL->GetSpec(&url);
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool isUndefined;
|
1999-10-06 21:13:37 +00:00
|
|
|
context->EvaluateString(aScript, nsnull, principal, url,
|
(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
|
|
|
aLineNo, aVersion, ret, &isUndefined);
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-09-16 00:10:54 +00:00
|
|
|
if (docURL) {
|
|
|
|
NS_RELEASE(docURL);
|
|
|
|
nsCRT::free(url);
|
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
|
|
|
NS_RELEASE(context);
|
|
|
|
NS_RELEASE(owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OnUnicharStreamComplete(nsIUnicharStreamLoader* aLoader,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* string)
|
1998-12-15 06:10:59 +00:00
|
|
|
{
|
1999-11-02 06:49:44 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsString aData(string);
|
1998-12-15 06:10:59 +00:00
|
|
|
|
|
|
|
if (NS_OK == aStatus) {
|
1999-11-02 06:49:44 +00:00
|
|
|
PRBool bodyPresent = PreEvaluateScript();
|
1999-04-13 22:22:51 +00:00
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
rv = EvaluateScript(aData, 0, mScriptLanguageVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-04-13 22:22:51 +00:00
|
|
|
|
1999-11-02 06:49:44 +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);
|
1999-11-02 06:49:44 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-12-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 23:44:27 +00:00
|
|
|
/*
|
|
|
|
** The enum "SchemeOrder" defines an ordering of URI schemes used to
|
|
|
|
** determine whether a page can load a script. Schemes are listed in
|
|
|
|
** order of declining power: chrome can access everything, resource
|
|
|
|
** can access everything but chrome, and so forth.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum SchemeOrder { CHROME_SCHEME, RESOURCE_SCHEME, FILE_SCHEME, OTHER_SCHEME };
|
|
|
|
|
|
|
|
static SchemeOrder
|
|
|
|
GetSchemeOrder(nsIURI *uri)
|
|
|
|
{
|
|
|
|
SchemeOrder result = OTHER_SCHEME;
|
|
|
|
if (uri) {
|
|
|
|
char *scheme;
|
|
|
|
uri->GetScheme(&scheme);
|
|
|
|
if (scheme) {
|
|
|
|
if (PL_strcmp(scheme, "chrome") == 0)
|
|
|
|
result = CHROME_SCHEME;
|
|
|
|
else if (PL_strcmp(scheme, "resource") == 0)
|
|
|
|
result = RESOURCE_SCHEME;
|
|
|
|
else if (PL_strcmp(scheme, "file") == 0)
|
|
|
|
result = FILE_SCHEME;
|
|
|
|
nsCRT::free(scheme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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")) {
|
1998-12-15 06:10:59 +00:00
|
|
|
GetAttributeValueAt(aNode, i, src, nsnull);
|
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
|
|
|
|
1998-10-30 03:36:35 +00:00
|
|
|
GetAttributeValueAt(aNode, i, type, nsnull);
|
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;
|
|
|
|
|
|
|
|
GetAttributeValueAt(aNode, i, lang, nsnull);
|
(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-02 20:59:39 +00:00
|
|
|
// Create content object
|
|
|
|
NS_ASSERTION(mCurrentContext->mStackPos > 0, "leaf w/o container");
|
|
|
|
nsIHTMLContent* parent = mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;
|
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
|
|
|
nsAutoString tag("SCRIPT");
|
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
rv = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-08-31 11:17:26 +00:00
|
|
|
element->SetContentID(mContentIDCounter++);
|
|
|
|
|
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);
|
|
|
|
rv = AddAttributes(aNode, element, sco);
|
|
|
|
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++,
|
|
|
|
IsInScript());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent->AppendChildTo(element, IsInScript());
|
|
|
|
}
|
1999-07-02 20:59:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
|
|
|
|
// Create a text node holding the content
|
|
|
|
// First, get the text content of the script tag
|
|
|
|
nsAutoString script;
|
|
|
|
script = aNode.GetSkippedContent();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
element->AppendChildTo(text, IsInScript());
|
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-10-11 23:42:56 +00:00
|
|
|
RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsHTMLContentSink::ProcessSCRIPTTag()\n"));
|
1999-09-15 00:39:41 +00:00
|
|
|
NS_STOP_STOPWATCH(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
|
|
|
|
// scripts that are inside iframes
|
|
|
|
if (isJavaScript && !mNumOpenIFRAMES) {
|
(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 03:29:44 +00:00
|
|
|
nsIURI* url = nsnull;
|
1999-06-23 19:55:21 +00:00
|
|
|
{
|
|
|
|
rv = NS_NewURI(&url, 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-02 23:44:27 +00:00
|
|
|
// Check access to file:, chrome:, and resource:.
|
|
|
|
SchemeOrder order = GetSchemeOrder(url);
|
|
|
|
SchemeOrder baseOrder = GetSchemeOrder(mDocumentBaseURL);
|
|
|
|
if (baseOrder > order) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
|
1999-09-18 06:20:49 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
1998-12-18 01:36:41 +00:00
|
|
|
nsIUnicharStreamLoader* loader;
|
1999-09-18 06:20:49 +00:00
|
|
|
|
|
|
|
mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
1999-11-02 06:49:44 +00:00
|
|
|
rv = NS_NewUnicharStreamLoader(&loader, url, loadGroup, this);
|
1998-10-30 03:36:35 +00:00
|
|
|
NS_RELEASE(url);
|
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();
|
1998-11-28 23:51:06 +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
|
|
|
EvaluateScript(script, lineNo, jsVersionString);
|
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;
|
1999-07-05 19:45:27 +00:00
|
|
|
PRInt32 i, count = aNode.GetAttributeCount();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
nsAutoString src;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
1998-08-10 23:02:39 +00:00
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
nsIScriptContextOwner* sco = mDocument->GetScriptContextOwner();
|
1999-07-05 19:45:27 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
1998-04-13 20:24:54 +00:00
|
|
|
if (key.EqualsIgnoreCase("src")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, src, sco);
|
1998-11-26 01:29:10 +00:00
|
|
|
src.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("title")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, title, sco);
|
1998-11-26 01:29:10 +00:00
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("type")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, type, sco);
|
1998-11-26 01:29:10 +00:00
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("media")) {
|
1999-07-05 19:45:27 +00:00
|
|
|
GetAttributeValueAt(aNode, i, media, sco);
|
1999-05-26 23:49:33 +00:00
|
|
|
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
// Create content object
|
|
|
|
nsAutoString tag("STYLE");
|
|
|
|
nsIHTMLContent* element = nsnull;
|
|
|
|
rv = NS_CreateHTMLElement(&element, tag);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-08-31 11:17:26 +00:00
|
|
|
element->SetContentID(mContentIDCounter++);
|
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
// Add in the attributes and add the style content object to the
|
|
|
|
// head container.
|
1999-02-27 07:13:48 +00:00
|
|
|
element->SetDocument(mDocument, PR_FALSE);
|
1998-11-26 01:29:10 +00:00
|
|
|
rv = AddAttributes(aNode, element, sco);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mHead->AppendChildTo(element, PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(sco);
|
|
|
|
|
1999-05-26 23:49:33 +00:00
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
SplitMimeType(type, mimeType, params);
|
|
|
|
|
|
|
|
PRBool blockParser = PR_FALSE; // hardwired off for now
|
|
|
|
|
|
|
|
if ((0 == mimeType.Length()) || mimeType.EqualsIgnoreCase("text/css")) {
|
|
|
|
|
|
|
|
if (0 < title.Length()) { // possibly preferred sheet
|
|
|
|
if (0 == mPreferredStyle.Length()) {
|
|
|
|
mPreferredStyle = title;
|
|
|
|
mCSSLoader->SetPreferredSheet(title);
|
|
|
|
mDocument->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:29:10 +00:00
|
|
|
// The skipped content contains the inline style data
|
1999-01-06 00:19:46 +00:00
|
|
|
const nsString& content = aNode.GetSkippedContent();
|
1999-05-18 23:05:43 +00:00
|
|
|
PRBool doneLoading = PR_FALSE;
|
1999-01-06 00:19:46 +00:00
|
|
|
|
|
|
|
nsIUnicharInputStream* uin = nsnull;
|
|
|
|
if (0 == src.Length()) {
|
1999-07-01 21:39:14 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
element->AppendChildTo(text, IsInScript());
|
1999-07-01 21:39:14 +00:00
|
|
|
text->SetDocument(mDocument, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
}
|
|
|
|
|
1999-01-06 00:19:46 +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;
|
1999-01-15 02:02:48 +00:00
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-01-06 00:19:46 +00:00
|
|
|
// Now that we have a url and a unicode input stream, parse the
|
|
|
|
// style sheet.
|
1999-06-15 06:22:46 +00:00
|
|
|
rv = mCSSLoader->LoadInlineStyle(element, uin, title, media, kNameSpaceID_HTML,
|
1999-05-26 23:49:33 +00:00
|
|
|
mStyleSheetCount++,
|
|
|
|
((blockParser) ? mParser : nsnull),
|
1999-05-18 23:05:43 +00:00
|
|
|
doneLoading);
|
1999-01-06 00:19:46 +00:00
|
|
|
NS_RELEASE(uin);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
// If we're done loading the inline style, 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 (doneLoading) {
|
|
|
|
UpdateAllContexts();
|
|
|
|
}
|
1999-01-15 02:02:48 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-01-06 00:19:46 +00:00
|
|
|
// src with immediate style data doesn't add up
|
|
|
|
// XXX what does nav do?
|
|
|
|
// Use the SRC attribute value to load the URL
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* url = nsnull;
|
1999-06-23 19:55:21 +00:00
|
|
|
{
|
|
|
|
rv = NS_NewURI(&url, src, mDocumentBaseURL);
|
1999-01-15 02:02:48 +00:00
|
|
|
}
|
1999-01-06 00:19:46 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1999-01-15 02:02:48 +00:00
|
|
|
}
|
1998-12-15 06:10:59 +00:00
|
|
|
|
1999-06-15 06:22:46 +00:00
|
|
|
rv = mCSSLoader->LoadStyleLink(element, url, title, media, kNameSpaceID_HTML,
|
1999-05-18 23:05:43 +00:00
|
|
|
mStyleSheetCount++,
|
1999-05-26 23:49:33 +00:00
|
|
|
((blockParser) ? mParser : nsnull),
|
|
|
|
doneLoading);
|
1999-01-06 00:19:46 +00:00
|
|
|
NS_RELEASE(url);
|
1999-05-18 23:05:43 +00:00
|
|
|
}
|
1999-05-26 23:49:33 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && blockParser && (! doneLoading)) {
|
1999-05-18 23:05:43 +00:00
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
1999-01-15 02:02:48 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-03 16:46:56 +00:00
|
|
|
NS_RELEASE(element);
|
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!
|
|
|
|
// Why are you telling us, parser. Deal with it yourself.
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-15 05:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::DoFragment(PRBool aFlag)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|