2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-24 07:38:00 +00:00
|
|
|
#include "nsICharsetAlias.h"
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-03-12 22:41:28 +00:00
|
|
|
#include "nsIFileChannel.h"
|
1999-08-09 19:10:24 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsHTMLDocument.h"
|
1999-07-14 15:33:48 +00:00
|
|
|
#include "nsIParserFilter.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContentSink.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIHTMLStyleSheet.h"
|
1998-05-13 23:43:44 +00:00
|
|
|
#include "nsIHTMLCSSStyleSheet.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
2001-03-22 08:51:52 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-11-11 11:55:32 +00:00
|
|
|
#include "nsIPresShell.h"
|
1998-06-23 00:52:21 +00:00
|
|
|
#include "nsIPresContext.h"
|
1998-05-04 17:54:45 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-09-04 15:41:20 +00:00
|
|
|
#include "nsIDOMNode.h" // for Find
|
1999-01-19 23:07:33 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
1998-05-04 17:54:45 +00:00
|
|
|
#include "nsIDOMElement.h"
|
1998-05-04 20:34:37 +00:00
|
|
|
#include "nsIDOMText.h"
|
1999-02-16 07:38:27 +00:00
|
|
|
#include "nsIDOMComment.h"
|
2000-03-22 22:16:14 +00:00
|
|
|
#include "nsIDOMDOMImplementation.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2000-09-01 01:54:35 +00:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
1998-07-01 11:16:09 +00:00
|
|
|
#include "nsIStreamListener.h"
|
1998-06-17 23:13:28 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIContentViewerContainer.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
1998-07-18 21:47:56 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-03-11 00:35:36 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2000-06-08 22:51:06 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
1999-11-27 03:11:10 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-07-14 15:33:48 +00:00
|
|
|
#include "nsIWebShellServices.h"
|
1998-07-17 06:30:00 +00:00
|
|
|
#include "nsIDocumentLoader.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsIXPConnect.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
#include "nsContentList.h"
|
1999-09-08 23:18:27 +00:00
|
|
|
#include "nsDOMError.h"
|
1999-10-02 03:41:37 +00:00
|
|
|
#include "nsICodebasePrincipal.h"
|
2000-03-31 00:31:18 +00:00
|
|
|
#include "nsIAggregatePrincipal.h"
|
1999-10-02 03:41:37 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2001-01-27 16:58:15 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
|
|
|
|
#include "nsIIOService.h"
|
1999-08-19 22:23:20 +00:00
|
|
|
#include "nsICookieService.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
|
1998-09-17 00:55:35 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2000-04-28 14:05:45 +00:00
|
|
|
#include "nsIConsoleService.h"
|
1998-08-04 00:05:22 +00:00
|
|
|
#include "nsIFormManager.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1998-07-30 22:42:27 +00:00
|
|
|
#include "nsParserCIID.h"
|
1998-11-12 22:25:51 +00:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
1999-01-09 00:15:19 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
1999-02-04 02:58:02 +00:00
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-07-07 04:52:27 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsGenericDOMNodeList.h"
|
1999-05-18 23:06:31 +00:00
|
|
|
#include "nsICSSLoader.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIFile.h"
|
1999-09-21 14:18:52 +00:00
|
|
|
#include "nsIEventListenerManager.h"
|
1999-11-14 00:34:15 +00:00
|
|
|
#include "nsISelectElement.h"
|
2000-04-28 14:05:45 +00:00
|
|
|
#include "nsIFrameSelection.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelectionPrivate.h"//for toStringwithformat code
|
1999-07-14 15:33:48 +00:00
|
|
|
|
|
|
|
#include "nsICharsetDetector.h"
|
|
|
|
#include "nsICharsetDetectionAdaptor.h"
|
|
|
|
#include "nsCharsetDetectionAdaptorCID.h"
|
1999-08-24 07:38:00 +00:00
|
|
|
#include "nsICharsetAlias.h"
|
1999-07-14 15:33:48 +00:00
|
|
|
#include "nsIPref.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-05-17 06:56:34 +00:00
|
|
|
#include "nsIDocumentCharsetInfo.h"
|
2000-05-13 08:11:29 +00:00
|
|
|
#include "nsIDocumentEncoder.h" //for outputting selection
|
2000-06-01 01:13:45 +00:00
|
|
|
#include "nsIBookmarksService.h"
|
2001-04-27 02:26:32 +00:00
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsICacheEntryDescriptor.h"
|
2000-06-07 01:14:08 +00:00
|
|
|
#include "nsIXMLContent.h" //for createelementNS
|
2000-06-09 04:19:09 +00:00
|
|
|
#include "nsHTMLParts.h" //for createelementNS
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsContentUtils.h"
|
2001-05-25 08:49:03 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
2002-01-31 19:36:45 +00:00
|
|
|
#include "nsIWyciwygChannel.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentCID.h"
|
2001-03-29 02:11:48 +00:00
|
|
|
#include "nsIPrompt.h"
|
2001-04-12 23:35:24 +00:00
|
|
|
//AHMED 12-2
|
|
|
|
#ifdef IBMBIDI
|
2002-02-19 20:41:32 +00:00
|
|
|
#include "nsBidiUtils.h"
|
2001-04-12 23:35:24 +00:00
|
|
|
#endif
|
2000-05-13 08:11:29 +00:00
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
#define DETECTOR_CONTRACTID_MAX 127
|
|
|
|
static char g_detector_contractid[DETECTOR_CONTRACTID_MAX + 1];
|
1999-07-14 15:33:48 +00:00
|
|
|
static PRBool gInitDetector = PR_FALSE;
|
|
|
|
static PRBool gPlugDetector = PR_FALSE;
|
2000-06-16 21:22:00 +00:00
|
|
|
//static PRBool gBookmarkCharset = PR_TRUE;
|
1999-09-22 08:49:28 +00:00
|
|
|
|
1999-07-14 17:13:05 +00:00
|
|
|
#include "prmem.h"
|
1999-11-12 02:06:54 +00:00
|
|
|
#include "prtime.h"
|
1999-07-14 17:13:05 +00:00
|
|
|
|
2001-02-06 05:46:46 +00:00
|
|
|
// Find/Search Includes
|
1998-08-28 15:55:31 +00:00
|
|
|
const PRInt32 kForward = 0;
|
|
|
|
const PRInt32 kBackward = 1;
|
|
|
|
|
1999-12-13 21:00:47 +00:00
|
|
|
//#define DEBUG_charset
|
|
|
|
|
1998-08-28 15:55:31 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
#define ID_NOT_IN_DOCUMENT ((nsIContent *)1)
|
2000-09-09 05:46:14 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2000-06-01 01:13:45 +00:00
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
static PRBool
|
|
|
|
IsNamedItem(nsIContent* aContent, nsIAtom *aTag, nsAWritableString& aName);
|
|
|
|
|
2001-03-10 21:02:12 +00:00
|
|
|
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID);
|
|
|
|
|
2000-06-01 01:13:45 +00:00
|
|
|
nsIRDFService* nsHTMLDocument::gRDF;
|
|
|
|
nsrefcnt nsHTMLDocument::gRefCntRDFService = 0;
|
1998-10-06 01:39:33 +00:00
|
|
|
|
2000-05-02 23:07:11 +00:00
|
|
|
static int PR_CALLBACK
|
1999-09-23 02:10:15 +00:00
|
|
|
MyPrefChangedCallback(const char*aPrefName, void* instance_data)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIPref> prefs =
|
|
|
|
do_GetService("@mozilla.org/preferences;1", &rv);
|
2000-08-18 00:47:03 +00:00
|
|
|
PRUnichar* detector_name = nsnull;
|
1999-09-23 02:10:15 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && NS_SUCCEEDED(
|
2000-08-18 00:47:03 +00:00
|
|
|
rv = prefs->GetLocalizedUnicharPref("intl.charset.detector",
|
1999-09-23 02:10:15 +00:00
|
|
|
&detector_name)))
|
|
|
|
{
|
|
|
|
if(nsCRT::strlen(detector_name) > 0) {
|
2000-09-13 23:57:52 +00:00
|
|
|
PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,DETECTOR_CONTRACTID_MAX);
|
2001-03-08 08:05:05 +00:00
|
|
|
PL_strncat(g_detector_contractid, NS_ConvertUCS2toUTF8(detector_name).get(),DETECTOR_CONTRACTID_MAX);
|
1999-09-23 02:10:15 +00:00
|
|
|
gPlugDetector = PR_TRUE;
|
|
|
|
} else {
|
2000-09-13 23:57:52 +00:00
|
|
|
g_detector_contractid[0]=0;
|
1999-09-23 02:10:15 +00:00
|
|
|
gPlugDetector = PR_FALSE;
|
|
|
|
}
|
|
|
|
PR_FREEIF(detector_name);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-08-16 23:16:21 +00:00
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
// ==================================================================
|
|
|
|
// =
|
|
|
|
// ==================================================================
|
2001-10-19 20:59:33 +00:00
|
|
|
NS_EXPORT nsresult
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
nsHTMLDocument* doc = new nsHTMLDocument();
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete doc;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = doc;
|
|
|
|
NS_ADDREF(*aInstancePtrResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
class IdAndNameMapEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IdAndNameMapEntry(const nsAString& aString) :
|
|
|
|
mKey(aString), mIdContent(nsnull), mContentList(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~IdAndNameMapEntry()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mContentList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString mKey;
|
|
|
|
nsIContent *mIdContent;
|
|
|
|
nsBaseContentList *mContentList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(const void *)
|
|
|
|
IdAndNameHashGetKey(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
|
|
|
IdAndNameMapEntry *e = NS_STATIC_CAST(IdAndNameMapEntry *, entry);
|
|
|
|
|
|
|
|
return NS_STATIC_CAST(const nsAString *, &e->mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashNumber)
|
|
|
|
IdAndNameHashHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
|
|
|
const nsAString *str = NS_STATIC_CAST(const nsAString *, key);
|
|
|
|
|
|
|
|
return HashString(*str);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
|
|
|
IdAndNameHashMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const IdAndNameMapEntry *e =
|
|
|
|
NS_STATIC_CAST(const IdAndNameMapEntry *, entry);
|
|
|
|
const nsAString *str = NS_STATIC_CAST(const nsAString *, key);
|
|
|
|
|
|
|
|
return str->Equals(e->mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
IdAndNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
|
|
|
IdAndNameMapEntry *e = NS_STATIC_CAST(IdAndNameMapEntry *, entry);
|
|
|
|
|
|
|
|
// An entry is being cleared, let the entry its own cleanup.
|
|
|
|
e->~IdAndNameMapEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
IdAndNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const nsAString *keyStr = NS_STATIC_CAST(const nsAString *, key);
|
|
|
|
|
|
|
|
// Inititlize the entry with placement new
|
2002-02-05 05:47:22 +00:00
|
|
|
new (entry) IdAndNameMapEntry(*keyStr);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLDocument::nsHTMLDocument()
|
1998-07-17 23:00:54 +00:00
|
|
|
: nsMarkupDocument(),
|
1998-09-02 02:06:39 +00:00
|
|
|
mAttrStyleSheet(nsnull),
|
1999-01-15 02:01:36 +00:00
|
|
|
mStyleAttrStyleSheet(nsnull),
|
|
|
|
mBaseURL(nsnull),
|
1999-08-09 19:10:24 +00:00
|
|
|
mBaseTarget(nsnull),
|
1999-09-17 06:56:39 +00:00
|
|
|
mLastModified(nsnull),
|
1999-09-26 10:07:16 +00:00
|
|
|
mReferrer(nsnull),
|
|
|
|
mIsWriting(0)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-07-22 23:32:19 +00:00
|
|
|
mImages = nsnull;
|
|
|
|
mApplets = nsnull;
|
|
|
|
mEmbeds = nsnull;
|
|
|
|
mLinks = nsnull;
|
|
|
|
mAnchors = nsnull;
|
1999-05-17 21:17:48 +00:00
|
|
|
mLayers = nsnull;
|
1998-07-23 22:06:05 +00:00
|
|
|
mParser = nsnull;
|
2000-05-04 05:54:04 +00:00
|
|
|
mDTDMode = eDTDMode_quirks;
|
1999-05-18 23:06:31 +00:00
|
|
|
mCSSLoader = nsnull;
|
1998-08-28 15:55:31 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
mForms = nsnull;
|
1999-02-03 19:38:16 +00:00
|
|
|
mIsWriting = 0;
|
|
|
|
mWriteLevel = 0;
|
2002-01-31 19:36:45 +00:00
|
|
|
mWyciwygSessionCnt = 0;
|
2001-05-18 01:10:54 +00:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
mTexttype = IBMBIDI_TEXTTYPE_LOGICAL;
|
|
|
|
#endif
|
2000-06-01 01:13:45 +00:00
|
|
|
|
|
|
|
if (gRefCntRDFService++ == 0)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = nsServiceManager::GetService(kRDFServiceCID,
|
|
|
|
NS_GET_IID(nsIRDFService),
|
|
|
|
(nsISupports**) &gRDF);
|
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
//nsCOMPtr<nsIRDFService> gRDF(do_GetService(kRDFServiceCID,
|
|
|
|
//&rv));
|
2000-06-01 01:13:45 +00:00
|
|
|
}
|
2000-10-24 04:35:25 +00:00
|
|
|
mDomainWasSet = PR_FALSE; // Bug 13871: Frameset spoofing
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLDocument::~nsHTMLDocument()
|
|
|
|
{
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IF_RELEASE(mImages);
|
|
|
|
NS_IF_RELEASE(mApplets);
|
|
|
|
NS_IF_RELEASE(mEmbeds);
|
|
|
|
NS_IF_RELEASE(mLinks);
|
|
|
|
NS_IF_RELEASE(mAnchors);
|
1999-05-17 21:17:48 +00:00
|
|
|
NS_IF_RELEASE(mLayers);
|
1998-11-26 01:34:53 +00:00
|
|
|
if (nsnull != mAttrStyleSheet) {
|
|
|
|
mAttrStyleSheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(mAttrStyleSheet);
|
|
|
|
}
|
|
|
|
if (nsnull != mStyleAttrStyleSheet) {
|
|
|
|
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(mStyleAttrStyleSheet);
|
|
|
|
}
|
1999-01-15 02:01:36 +00:00
|
|
|
NS_IF_RELEASE(mBaseURL);
|
|
|
|
if (nsnull != mBaseTarget) {
|
|
|
|
delete mBaseTarget;
|
|
|
|
mBaseTarget = nsnull;
|
|
|
|
}
|
1999-08-09 19:10:24 +00:00
|
|
|
if (nsnull != mLastModified) {
|
2001-02-23 02:03:02 +00:00
|
|
|
delete mLastModified;
|
1999-08-09 19:10:24 +00:00
|
|
|
mLastModified = nsnull;
|
|
|
|
}
|
1999-09-17 06:56:39 +00:00
|
|
|
if (nsnull != mReferrer) {
|
2001-02-23 02:03:02 +00:00
|
|
|
delete mReferrer;
|
1999-09-17 06:56:39 +00:00
|
|
|
mReferrer = nsnull;
|
|
|
|
}
|
1998-07-23 22:06:05 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
2002-02-12 21:17:53 +00:00
|
|
|
mImageMaps->Clear();
|
1999-01-18 03:43:43 +00:00
|
|
|
NS_IF_RELEASE(mForms);
|
1999-05-26 23:50:26 +00:00
|
|
|
if (mCSSLoader) {
|
|
|
|
mCSSLoader->DropDocumentReference(); // release weak ref
|
|
|
|
}
|
1999-01-18 03:43:43 +00:00
|
|
|
|
2000-06-01 01:13:45 +00:00
|
|
|
if (--gRefCntRDFService == 0)
|
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
nsServiceManager::ReleaseService("@mozilla.org/rdf/rdf-service;1", gRDF);
|
2000-06-01 01:13:45 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (mIdAndNameHashIsLive) {
|
|
|
|
PL_DHashTableFinish(&mIdAndNameHashTable);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-06-20 22:49:10 +00:00
|
|
|
// QueryInterface implementation for nsHTMLDocument
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsHTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDocument)
|
|
|
|
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = nsDocument::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mImageMaps));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
static PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
IdAndNameHashGetKey,
|
|
|
|
IdAndNameHashHashKey,
|
|
|
|
IdAndNameHashMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
IdAndNameHashClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
IdAndNameHashInitEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
mIdAndNameHashIsLive = PL_DHashTableInit(&mIdAndNameHashTable,
|
|
|
|
&hash_table_ops, nsnull,
|
|
|
|
sizeof(IdAndNameMapEntry), 16);
|
|
|
|
NS_ENSURE_TRUE(mIdAndNameHashIsLive, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PrePopulateHashTables();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-20 08:46:33 +00:00
|
|
|
nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-07-20 08:46:33 +00:00
|
|
|
nsresult result = nsDocument::Reset(aChannel, aLoadGroup);
|
1999-07-16 11:14:36 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
2001-03-12 06:38:39 +00:00
|
|
|
|
|
|
|
if (aChannel) {
|
|
|
|
result = aChannel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
1998-05-13 23:43:44 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2001-11-16 02:03:19 +00:00
|
|
|
return BaseResetToURI(aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
|
|
|
|
{
|
|
|
|
nsresult result = nsDocument::ResetToURI(aURI, aLoadGroup);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = BaseResetToURI(aURI);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::BaseResetToURI(nsIURI *aURL)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
InvalidateHashTables();
|
|
|
|
PrePopulateHashTables();
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
NS_IF_RELEASE(mImages);
|
|
|
|
NS_IF_RELEASE(mApplets);
|
|
|
|
NS_IF_RELEASE(mEmbeds);
|
|
|
|
NS_IF_RELEASE(mLinks);
|
|
|
|
NS_IF_RELEASE(mAnchors);
|
1999-05-17 21:17:48 +00:00
|
|
|
NS_IF_RELEASE(mLayers);
|
1999-01-06 00:32:41 +00:00
|
|
|
|
2001-10-31 23:52:52 +00:00
|
|
|
mBodyContent = nsnull;
|
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
mImageMaps->Clear();
|
1999-01-18 03:43:43 +00:00
|
|
|
NS_IF_RELEASE(mForms);
|
1998-05-13 23:43:44 +00:00
|
|
|
|
2001-03-12 06:38:39 +00:00
|
|
|
if (aURL) {
|
|
|
|
if (!mAttrStyleSheet) {
|
|
|
|
//result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
|
|
|
result = nsComponentManager::CreateInstance(kHTMLStyleSheetCID, nsnull,
|
|
|
|
NS_GET_IID(nsIHTMLStyleSheet),
|
|
|
|
(void**)&mAttrStyleSheet);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = mAttrStyleSheet->Init(aURL,this);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_RELEASE(mAttrStyleSheet);
|
|
|
|
}
|
2001-02-19 12:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-03 19:38:16 +00:00
|
|
|
else {
|
2001-03-12 06:38:39 +00:00
|
|
|
result = mAttrStyleSheet->Reset(aURL);
|
1999-02-03 19:38:16 +00:00
|
|
|
}
|
2001-03-12 06:38:39 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
|
|
|
|
|
|
|
if (!mStyleAttrStyleSheet) {
|
|
|
|
result = NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = mStyleAttrStyleSheet->Reset(aURL);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
|
|
|
}
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
NS_ASSERTION(mWyciwygChannel == nsnull, "nsHTMLDocument::Reset() - Wyciwyg Channel still exists!");
|
|
|
|
mWyciwygChannel = nsnull;
|
2001-05-25 08:49:03 +00:00
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-11-16 02:03:19 +00:00
|
|
|
|
1999-07-07 01:27:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateShell(nsIPresContext* aContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet,
|
|
|
|
nsIPresShell** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
nsresult result = nsMarkupDocument::CreateShell(aContext,
|
|
|
|
aViewManager,
|
|
|
|
aStyleSet,
|
|
|
|
aInstancePtrResult);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2000-05-04 05:54:04 +00:00
|
|
|
aContext->SetCompatibilityMode(((eDTDMode_strict== mDTDMode) ?
|
1999-07-07 01:27:08 +00:00
|
|
|
eCompatibility_Standard :
|
|
|
|
eCompatibility_NavQuirks));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
// The following Try*Charset will return PR_FALSE only if the charset source
|
|
|
|
// should be considered (ie. aCharsetSource < thisCharsetSource) but we failed
|
|
|
|
// to get the charset from this source.
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
PRInt32 requestCharsetSource;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (aMarkupDV) {
|
|
|
|
rv = aMarkupDV->GetHintCharacterSetSource(&requestCharsetSource);
|
|
|
|
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
|
|
|
PRUnichar* requestCharset;
|
|
|
|
rv = aMarkupDV->GetHintCharacterSet(&requestCharset);
|
|
|
|
aMarkupDV->SetHintCharacterSetSource((PRInt32)(kCharsetUninitialized));
|
|
|
|
if(requestCharsetSource <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
aCharsetSource = requestCharsetSource;
|
|
|
|
aCharset = requestCharset;
|
|
|
|
Recycle(requestCharset);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
|
|
|
|
nsIDocumentCharsetInfo* aDocInfo,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
2002-02-05 05:47:22 +00:00
|
|
|
nsresult rv = NS_OK;
|
2001-12-26 03:17:59 +00:00
|
|
|
|
|
|
|
if(kCharsetFromUserForced <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
PRUnichar* forceCharsetFromWebShell = nsnull;
|
|
|
|
if (aMarkupDV)
|
|
|
|
rv = aMarkupDV->GetForceCharacterSet(&forceCharsetFromWebShell);
|
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && forceCharsetFromWebShell)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
|
|
|
aCharset = forceCharsetFromWebShell;
|
|
|
|
Recycle(forceCharsetFromWebShell);
|
|
|
|
//TODO: we should define appropriate constant for force charset
|
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
|
|
|
} else if (aDocInfo) {
|
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
aDocInfo->GetForcedCharset(getter_AddRefs(csAtom));
|
|
|
|
if (csAtom.get() != nsnull) {
|
|
|
|
csAtom->ToString(aCharset);
|
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
|
|
|
aDocInfo->SetForcedCharset(nsnull);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (kCharsetFromCache <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsXPIDLCString cachedCharset;
|
|
|
|
rv = aCacheDescriptor->GetMetaDataElement("charset",
|
|
|
|
getter_Copies(cachedCharset));
|
|
|
|
if (NS_SUCCEEDED(rv) && PL_strlen(cachedCharset) > 0)
|
|
|
|
{
|
|
|
|
aCharset.Assign(NS_ConvertASCIItoUCS2(cachedCharset));
|
|
|
|
aCharsetSource = kCharsetFromCache;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryBookmarkCharset(nsXPIDLCString* aUrlSpec,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (kCharsetFromBookmarks <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFDataSource> datasource;
|
|
|
|
if (gRDF && NS_SUCCEEDED(rv = gRDF->GetDataSource("rdf:bookmarks", getter_AddRefs(datasource)))) {
|
|
|
|
nsCOMPtr<nsIBookmarksService> bookmarks = do_QueryInterface(datasource);
|
|
|
|
if (bookmarks) {
|
|
|
|
if (aUrlSpec) {
|
|
|
|
nsXPIDLString pBookmarkedCharset;
|
|
|
|
rv = bookmarks->GetLastCharset(*aUrlSpec, getter_Copies(pBookmarkedCharset));
|
|
|
|
if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE)) {
|
|
|
|
aCharset = pBookmarkedCharset;
|
|
|
|
aCharsetSource = kCharsetFromBookmarks;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
if (aDocInfo) {
|
|
|
|
PRInt32 source;
|
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
PRInt32 parentSource;
|
|
|
|
aDocInfo->GetParentCharsetSource(&parentSource);
|
|
|
|
if (kCharsetFromParentForced <= parentSource)
|
|
|
|
source = kCharsetFromParentForced;
|
|
|
|
else if (kCharsetFromCache <= parentSource)
|
|
|
|
source = kCharsetFromParentFrame;
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (source < aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
aDocInfo->GetParentCharset(getter_AddRefs(csAtom));
|
|
|
|
if (csAtom) {
|
|
|
|
csAtom->ToString(aCharset);
|
|
|
|
aCharsetSource = source;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryWeakDocTypeDefault(PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
if (kCharsetFromWeakDocTypeDefault <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
aCharset.Assign(NS_LITERAL_STRING("ISO-8859-1")); // fallback value in case webShell return error
|
|
|
|
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
|
|
|
|
if (prefs) {
|
|
|
|
nsXPIDLString defCharset;
|
|
|
|
nsresult rv = prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset));
|
2002-02-01 21:36:00 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !defCharset.IsEmpty()) {
|
2001-12-26 03:17:59 +00:00
|
|
|
aCharset.Assign(defCharset);
|
2002-02-01 21:36:00 +00:00
|
|
|
aCharsetSource = kCharsetFromWeakDocTypeDefault;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryHttpHeaderCharset(nsIHttpChannel *aHttpChannel,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
if(kCharsetFromHTTPHeader <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (aHttpChannel) {
|
|
|
|
nsXPIDLCString charsetheader;
|
|
|
|
nsresult rv = aHttpChannel->GetCharset(getter_Copies(charsetheader));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsICharsetAlias> calias(do_CreateInstance(kCharsetAliasCID, &rv));
|
|
|
|
if(calias) {
|
|
|
|
nsAutoString preferred;
|
|
|
|
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
aCharset = preferred;
|
|
|
|
aCharsetSource = kCharsetFromHTTPHeader;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryUserDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
|
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
|
|
|
if(kCharsetFromUserDefault <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
PRUnichar* defaultCharsetFromWebShell = NULL;
|
|
|
|
if (aMarkupDV) {
|
|
|
|
nsresult rv = aMarkupDV->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
|
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
aCharset = defaultCharsetFromWebShell;
|
|
|
|
Recycle(defaultCharsetFromWebShell);
|
|
|
|
aCharsetSource = kCharsetFromUserDefault;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell,
|
|
|
|
nsAString& aCharset,
|
|
|
|
const char* aCommand)
|
|
|
|
{
|
|
|
|
nsCOMPtr <nsIParserFilter> cdetflt;
|
|
|
|
|
|
|
|
nsresult rv_detect;
|
|
|
|
if(! gInitDetector) {
|
|
|
|
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID));
|
|
|
|
if(pref) {
|
|
|
|
PRUnichar* detector_name = nsnull;
|
|
|
|
rv_detect = pref->GetLocalizedUnicharPref("intl.charset.detector", &detector_name);
|
|
|
|
if(NS_SUCCEEDED(rv_detect)) {
|
|
|
|
PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,DETECTOR_CONTRACTID_MAX);
|
|
|
|
PL_strncat(g_detector_contractid, NS_ConvertUCS2toUTF8(detector_name).get(),DETECTOR_CONTRACTID_MAX);
|
|
|
|
gPlugDetector = PR_TRUE;
|
|
|
|
PR_FREEIF(detector_name);
|
|
|
|
}
|
|
|
|
pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
|
|
|
|
}
|
|
|
|
gInitDetector = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gPlugDetector) {
|
|
|
|
nsCOMPtr <nsICharsetDetector> cdet = do_CreateInstance(g_detector_contractid, &rv_detect);
|
|
|
|
if(NS_SUCCEEDED(rv_detect)) {
|
|
|
|
cdetflt = do_CreateInstance(NS_CHARSET_DETECTION_ADAPTOR_CONTRACTID, &rv_detect);
|
|
|
|
if(NS_SUCCEEDED(rv_detect)) {
|
|
|
|
nsCOMPtr<nsICharsetDetectionAdaptor> adp = do_QueryInterface(cdetflt, &rv_detect);
|
|
|
|
if(cdetflt && NS_SUCCEEDED( rv_detect )) {
|
|
|
|
nsCOMPtr<nsIWebShellServices> wss = do_QueryInterface(aDocShell, &rv_detect);
|
|
|
|
if( NS_SUCCEEDED( rv_detect )) {
|
|
|
|
rv_detect = adp->Init(wss, cdet, this, mParser, PromiseFlatString(aCharset).get(), aCommand);
|
|
|
|
|
|
|
|
// The current implementation for SetParserFilter needs to
|
|
|
|
// be changed to be more XPCOM friendly. See bug #40149
|
|
|
|
if (mParser)
|
|
|
|
nsCOMPtr<nsIParserFilter> oldFilter = getter_AddRefs(mParser->SetParserFilter(cdetflt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// IF we cannot create the detector, don't bother to
|
|
|
|
// create one next time.
|
|
|
|
gPlugDetector = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-16 11:14:36 +00:00
|
|
|
nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 22:17:54 +00:00
|
|
|
nsISupports* aContainer,
|
2000-05-01 06:58:53 +00:00
|
|
|
nsIStreamListener **aDocListener,
|
2001-11-02 01:53:13 +00:00
|
|
|
PRBool aReset,
|
|
|
|
nsIContentSink* aSink)
|
1999-01-06 00:32:41 +00:00
|
|
|
{
|
1999-12-09 07:18:38 +00:00
|
|
|
PRBool needsParser=PR_TRUE;
|
|
|
|
if (aCommand)
|
|
|
|
{
|
2001-12-16 13:18:45 +00:00
|
|
|
if (!nsCRT::strcmp(aCommand, "view delayedContentLoad")) {
|
1999-12-09 07:18:38 +00:00
|
|
|
needsParser = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-27 02:26:32 +00:00
|
|
|
nsCOMPtr<nsICacheEntryDescriptor> cacheDescriptor;
|
1999-07-16 11:14:36 +00:00
|
|
|
nsresult rv = nsDocument::StartDocumentLoad(aCommand,
|
1999-07-20 08:46:33 +00:00
|
|
|
aChannel, aLoadGroup,
|
2000-05-01 06:58:53 +00:00
|
|
|
aContainer,
|
|
|
|
aDocListener, aReset);
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-06 00:32:41 +00:00
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-12 02:06:54 +00:00
|
|
|
nsAutoString lastModified;
|
2001-05-11 21:05:08 +00:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
2000-08-21 23:16:43 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (httpChannel) {
|
1999-09-17 06:56:39 +00:00
|
|
|
nsXPIDLCString lastModHeader;
|
2001-05-11 21:05:08 +00:00
|
|
|
rv = httpChannel->GetResponseHeader("last-modified",
|
1999-09-17 06:56:39 +00:00
|
|
|
getter_Copies(lastModHeader));
|
1999-08-09 19:10:24 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-03-22 08:51:52 +00:00
|
|
|
lastModified.AssignWithConversion(NS_STATIC_CAST(const char*,
|
|
|
|
lastModHeader));
|
1999-08-09 19:10:24 +00:00
|
|
|
SetLastModified(lastModified);
|
|
|
|
}
|
1999-08-24 07:38:00 +00:00
|
|
|
|
1999-09-17 06:56:39 +00:00
|
|
|
nsXPIDLCString referrerHeader;
|
|
|
|
// The misspelled key 'referer' is as per the HTTP spec
|
2001-05-11 21:05:08 +00:00
|
|
|
rv = httpChannel->GetRequestHeader("referer",
|
2001-03-22 08:51:52 +00:00
|
|
|
getter_Copies(referrerHeader));
|
1999-09-17 06:56:39 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-07-25 05:26:37 +00:00
|
|
|
nsAutoString referrer;
|
|
|
|
referrer.AssignWithConversion(referrerHeader);
|
|
|
|
|
1999-09-17 06:56:39 +00:00
|
|
|
SetReferrer(referrer);
|
|
|
|
}
|
|
|
|
|
2001-04-27 02:26:32 +00:00
|
|
|
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(httpChannel);
|
|
|
|
if (cachingChan) {
|
|
|
|
nsCOMPtr<nsISupports> cacheToken;
|
|
|
|
cachingChan->GetCacheToken(getter_AddRefs(cacheToken));
|
|
|
|
if (cacheToken)
|
|
|
|
cacheDescriptor = do_QueryInterface(cacheToken);
|
2000-08-21 23:16:43 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
// Don't propagate the result code beyond here, since it
|
1999-08-09 19:10:24 +00:00
|
|
|
// could just be that the response header wasn't found.
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1999-07-16 11:14:36 +00:00
|
|
|
|
1999-11-12 02:06:54 +00:00
|
|
|
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(aChannel);
|
|
|
|
if (fileChannel) {
|
2000-05-25 14:03:57 +00:00
|
|
|
PRTime modDate, usecs;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = fileChannel->GetFile(getter_AddRefs(file));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// if we failed to get a last modification date, then we don't
|
|
|
|
// want to necessarily fail to create a document for this
|
|
|
|
// file. Just don't set the last modified date on it...
|
2001-11-26 08:05:05 +00:00
|
|
|
rv = file->GetLastModifiedTime(&modDate);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRExplodedTime prtime;
|
|
|
|
char buf[100];
|
|
|
|
PRInt64 intermediateValue;
|
|
|
|
|
|
|
|
LL_I2L(intermediateValue, PR_USEC_PER_MSEC);
|
|
|
|
LL_MUL(usecs, modDate, intermediateValue);
|
|
|
|
PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime);
|
|
|
|
|
|
|
|
// Use '%#c' for windows, because '%c' is backward-compatible and
|
|
|
|
// non-y2k with msvc; '%#c' requests that a full year be used in the
|
|
|
|
// result string. Other OSes just use "%c".
|
|
|
|
PR_FormatTime(buf, sizeof buf,
|
|
|
|
#if defined(XP_PC) && !defined(XP_OS2)
|
2001-02-21 20:38:08 +00:00
|
|
|
"%#c",
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#else
|
2001-02-21 20:38:08 +00:00
|
|
|
"%c",
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#endif
|
2001-02-21 20:38:08 +00:00
|
|
|
&prtime);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
lastModified.AssignWithConversion(buf);
|
|
|
|
SetLastModified(lastModified);
|
2001-02-21 20:38:08 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
1999-11-12 02:06:54 +00:00
|
|
|
}
|
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
if (needsParser) {
|
2001-02-19 12:55:42 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kCParserCID, nsnull,
|
2001-01-04 20:44:42 +00:00
|
|
|
NS_GET_IID(nsIParser),
|
1999-12-09 07:18:38 +00:00
|
|
|
(void **)&mParser);
|
|
|
|
if (NS_FAILED(rv)) { return rv; }
|
|
|
|
}
|
1999-04-26 17:56:37 +00:00
|
|
|
|
1999-12-09 07:18:38 +00:00
|
|
|
nsCOMPtr<nsIHTMLContentSink> sink;
|
1998-07-10 05:35:23 +00:00
|
|
|
#ifdef rickgdebug
|
1999-12-09 07:18:38 +00:00
|
|
|
nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99
|
|
|
|
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink),&outString,0);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_ASSERTION(sink, "null sink in debug code variant.");
|
1998-07-10 05:35:23 +00:00
|
|
|
#else
|
1999-12-09 07:18:38 +00:00
|
|
|
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
|
2000-03-11 00:35:36 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
1999-12-09 07:18:38 +00:00
|
|
|
|
2000-05-17 06:56:34 +00:00
|
|
|
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo;
|
|
|
|
docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
|
2001-04-12 23:35:24 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
docShell->GetPresContext(getter_AddRefs(cx));
|
|
|
|
if(cx){
|
|
|
|
PRUint32 mBidiOption;
|
|
|
|
cx->GetBidi(&mBidiOption);
|
|
|
|
mTexttype = GET_BIDI_OPTION_TEXTTYPE(mBidiOption);
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
2000-01-18 02:40:45 +00:00
|
|
|
//
|
|
|
|
// The following logic is mirrored in nsWebShell::Embed!
|
|
|
|
//
|
1999-12-09 07:18:38 +00:00
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2000-03-11 00:35:36 +00:00
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
1999-12-09 07:18:38 +00:00
|
|
|
if (cv) {
|
|
|
|
muCV = do_QueryInterface(cv);
|
1999-12-13 22:45:06 +00:00
|
|
|
} else {
|
|
|
|
// in this block of code, if we get an error result, we return it
|
|
|
|
// but if we get a null pointer, that's perfectly legal for parent and parentContentViewer
|
2000-03-11 00:35:36 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
1999-12-13 22:45:06 +00:00
|
|
|
if (parent) {
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
|
|
|
rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
|
|
|
if (NS_FAILED(rv)) { return rv; }
|
|
|
|
if (parentContentViewer) {
|
|
|
|
muCV = do_QueryInterface(parentContentViewer);
|
|
|
|
}
|
|
|
|
}
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-05-15 03:42:33 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
nsXPIDLCString scheme;
|
|
|
|
aURL->GetScheme(getter_Copies(scheme));
|
|
|
|
|
|
|
|
nsXPIDLCString urlSpec;
|
|
|
|
aURL->GetSpec(getter_Copies(urlSpec));
|
|
|
|
|
|
|
|
PRInt32 charsetSource = kCharsetUninitialized;
|
|
|
|
nsAutoString charset;
|
|
|
|
|
|
|
|
// The following charset resolving calls has implied knowledge about
|
|
|
|
// charset source priority order. Each try will return true if the
|
|
|
|
// source is higher or equal to the source as its name describes. Some
|
|
|
|
// try call might change charset source to multiple values, like
|
|
|
|
// TryHintCharset and TryParentCharset. It should be always safe to try more
|
|
|
|
// sources.
|
|
|
|
if (! TryUserForcedCharset(muCV, dcInfo, charsetSource, charset)) {
|
|
|
|
TryHintCharset(muCV, charsetSource, charset);
|
|
|
|
TryParentCharset(dcInfo, charsetSource, charset);
|
|
|
|
if (TryHttpHeaderCharset(httpChannel, charsetSource, charset)) {
|
|
|
|
// Use the header's charset.
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
else if (scheme && nsCRT::strcasecmp("about", scheme) && // don't try to access bookmarks for about:blank
|
|
|
|
TryBookmarkCharset(&urlSpec, charsetSource, charset)) {
|
|
|
|
// Use the bookmark's charset.
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
else if (cacheDescriptor && urlSpec &&
|
|
|
|
TryCacheCharset(cacheDescriptor, charsetSource, charset)) {
|
|
|
|
// Use the cache's charset.
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
else if (TryWeakDocTypeDefault(charsetSource, charset)) {
|
|
|
|
// Use the weak doc type default charset
|
2001-06-29 22:56:58 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
else {
|
|
|
|
// Use the user's default charset.
|
|
|
|
TryUserDefaultCharset(muCV, charsetSource, charset);
|
2000-08-05 00:07:03 +00:00
|
|
|
}
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
|
|
|
if(kCharsetFromAutoDetection > charsetSource)
|
|
|
|
StartAutodetection(docShell, charset, aCommand);
|
1998-07-10 05:35:23 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-12 23:35:24 +00:00
|
|
|
//ahmed
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
// Check if 864 but in Implicit mode !
|
|
|
|
if( (mTexttype == IBMBIDI_TEXTTYPE_LOGICAL)&&(charset.EqualsIgnoreCase("ibm864")) )
|
2001-12-16 11:58:03 +00:00
|
|
|
charset.Assign(NS_LITERAL_STRING("IBM864i"));
|
2001-04-12 23:35:24 +00:00
|
|
|
#endif // IBMBIDI
|
1999-12-09 07:18:38 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
SetDocumentCharacterSet(charset);
|
|
|
|
SetDocumentCharacterSetSource(charsetSource);
|
1999-04-27 21:49:25 +00:00
|
|
|
|
2001-04-27 02:26:32 +00:00
|
|
|
if(cacheDescriptor) {
|
|
|
|
rv = cacheDescriptor->SetMetaDataElement("charset",
|
2001-03-08 08:05:05 +00:00
|
|
|
NS_ConvertUCS2toUTF8(charset).get());
|
2001-04-27 02:26:32 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"cannot SetMetaDataElement");
|
2000-08-21 23:16:43 +00:00
|
|
|
}
|
|
|
|
|
1999-12-09 07:18:38 +00:00
|
|
|
// Set the parser as the stream listener for the document loader...
|
2000-12-26 01:01:41 +00:00
|
|
|
if (mParser) {
|
|
|
|
rv = mParser->QueryInterface(NS_GET_IID(nsIStreamListener),
|
|
|
|
(void**)aDocListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-02 08:14:22 +00:00
|
|
|
|
1999-12-09 07:18:38 +00:00
|
|
|
//The following lines were added by Rick.
|
|
|
|
//These perform "dynamic" DTD registration, allowing
|
|
|
|
//the caller total control over process, and decoupling
|
|
|
|
//parser from any given grammar.
|
1998-07-02 08:14:22 +00:00
|
|
|
|
2000-09-08 04:52:57 +00:00
|
|
|
// nsCOMPtr<nsIDTD> theDTD;
|
|
|
|
// NS_NewNavHTMLDTD(getter_AddRefs(theDTD));
|
1999-01-26 01:25:37 +00:00
|
|
|
// mParser->RegisterDTD(theDTD);
|
1999-07-14 15:33:48 +00:00
|
|
|
|
1999-12-13 21:00:47 +00:00
|
|
|
#ifdef DEBUG_charset
|
2001-09-29 08:28:41 +00:00
|
|
|
char* cCharset = ToNewCString(charset);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("set to parser charset = %s source %d\n",
|
1999-12-13 21:00:47 +00:00
|
|
|
cCharset, charsetSource);
|
|
|
|
Recycle(cCharset);
|
|
|
|
#endif
|
1999-12-09 07:18:38 +00:00
|
|
|
mParser->SetDocumentCharset( charset, charsetSource);
|
|
|
|
mParser->SetCommand(aCommand);
|
|
|
|
// create the content sink
|
2000-03-11 00:35:36 +00:00
|
|
|
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
|
2001-11-02 01:53:13 +00:00
|
|
|
|
|
|
|
if (aSink)
|
|
|
|
sink = do_QueryInterface(aSink);
|
|
|
|
else {
|
|
|
|
rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aURL, webShell,aChannel);
|
|
|
|
if (NS_FAILED(rv)) { return rv; }
|
|
|
|
NS_ASSERTION(sink, "null sink with successful result from factory method");
|
|
|
|
}
|
|
|
|
|
1999-12-09 07:18:38 +00:00
|
|
|
mParser->SetContentSink(sink);
|
|
|
|
// parser the content of the URL
|
|
|
|
mParser->Parse(aURL, nsnull, PR_FALSE, (void *)this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-01 19:53:19 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 13:27:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::StopDocumentLoad()
|
|
|
|
{
|
|
|
|
if (mParser) {
|
|
|
|
mParser->Terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-23 22:06:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::EndLoad()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mParser);
|
|
|
|
return nsDocument::EndLoad();
|
|
|
|
}
|
1998-07-01 11:16:09 +00:00
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetTitle(const nsAReadableString& aTitle)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return nsDocument::SetTitle(aTitle);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 00:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::AddImageMap(nsIDOMHTMLMapElement* aMap)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2001-04-18 00:14:34 +00:00
|
|
|
// XXX We should order the maps based on their order in the document.
|
|
|
|
// XXX Otherwise scripts that add/remove maps with duplicate names
|
|
|
|
// XXX will cause problems
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
|
|
|
if (nsnull == aMap) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-02-12 21:17:53 +00:00
|
|
|
if (mImageMaps->AppendElement(aMap)) {
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-03-01 16:57:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::RemoveImageMap(nsIDOMHTMLMapElement* aMap)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
|
|
|
if (nsnull == aMap) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-02-12 21:17:53 +00:00
|
|
|
mImageMaps->RemoveElement(aMap);
|
1999-03-01 16:57:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-09 00:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetImageMap(const nsString& aMapName,
|
|
|
|
nsIDOMHTMLMapElement** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString name;
|
2001-05-26 06:43:20 +00:00
|
|
|
PRUint32 i, n;
|
2002-02-12 21:17:53 +00:00
|
|
|
mImageMaps->Count(&n);
|
1998-04-13 20:24:54 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2001-05-26 06:43:20 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> map;
|
2002-02-12 21:17:53 +00:00
|
|
|
mImageMaps->QueryElementAt(i, NS_GET_IID(nsIDOMHTMLMapElement), getter_AddRefs(map));
|
2001-05-26 06:43:20 +00:00
|
|
|
if (map && NS_SUCCEEDED(map->GetName(name))) {
|
1998-04-13 20:24:54 +00:00
|
|
|
if (name.EqualsIgnoreCase(aMapName)) {
|
|
|
|
*aResult = map;
|
2001-05-26 06:43:20 +00:00
|
|
|
NS_ADDREF(*aResult);
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-15 22:26:30 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult)
|
1998-07-25 01:26:12 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mAttrStyleSheet;
|
|
|
|
if (nsnull == mAttrStyleSheet) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
1998-09-12 02:43:19 +00:00
|
|
|
else {
|
|
|
|
NS_ADDREF(mAttrStyleSheet);
|
|
|
|
}
|
1998-07-25 01:26:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
|
1998-12-02 00:35:41 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mStyleAttrStyleSheet;
|
|
|
|
if (nsnull == mStyleAttrStyleSheet) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mStyleAttrStyleSheet);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook for sheet ordering
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-01-23 07:07:09 +00:00
|
|
|
if (aSheet == mAttrStyleSheet) { // always first
|
|
|
|
mStyleSheets.InsertElementAt(aSheet, 0);
|
|
|
|
}
|
|
|
|
else if (aSheet == mStyleAttrStyleSheet) { // always last
|
|
|
|
mStyleSheets.AppendElement(aSheet);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-21 01:10:07 +00:00
|
|
|
if (mStyleSheets.Count() != 0 &&
|
|
|
|
mStyleAttrStyleSheet == mStyleSheets.ElementAt(mStyleSheets.Count() - 1)) {
|
1999-01-23 07:07:09 +00:00
|
|
|
// keep attr sheet last
|
|
|
|
mStyleSheets.InsertElementAt(aSheet, mStyleSheets.Count() - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mStyleSheets.AppendElement(aSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:06:31 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
|
1999-01-23 07:07:09 +00:00
|
|
|
{
|
|
|
|
mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-15 02:01:36 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
nsHTMLDocument::GetBaseURL(nsIURI*& aURL) const
|
1999-01-15 02:01:36 +00:00
|
|
|
{
|
2001-04-30 23:35:09 +00:00
|
|
|
if (mDocumentBaseURL) {
|
|
|
|
aURL = mDocumentBaseURL.get();
|
|
|
|
NS_ADDREF(aURL);
|
1999-01-15 02:01:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-06-20 03:27:48 +00:00
|
|
|
GetDocumentURL(&aURL);
|
1999-01-15 02:01:36 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-02 22:31:02 +00:00
|
|
|
nsHTMLDocument::GetBaseTarget(nsAWritableString& aTarget)
|
1999-01-15 02:01:36 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mBaseTarget) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aTarget.Assign(*mBaseTarget);
|
1999-01-15 02:01:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aTarget.Truncate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-12-26 01:01:41 +00:00
|
|
|
nsHTMLDocument::SetBaseTarget(const nsAReadableString& aTarget)
|
1999-01-15 02:01:36 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aTarget.IsEmpty()) {
|
1999-01-15 02:01:36 +00:00
|
|
|
if (nsnull != mBaseTarget) {
|
|
|
|
*mBaseTarget = aTarget;
|
|
|
|
}
|
|
|
|
else {
|
2000-08-23 17:27:06 +00:00
|
|
|
mBaseTarget = new nsString(aTarget);
|
1999-01-15 02:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != mBaseTarget) {
|
|
|
|
delete mBaseTarget;
|
|
|
|
mBaseTarget = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-09 19:10:24 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetLastModified(const nsAReadableString& aLastModified)
|
1999-08-09 19:10:24 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aLastModified.IsEmpty()) {
|
1999-08-09 19:10:24 +00:00
|
|
|
if (nsnull != mLastModified) {
|
|
|
|
*mLastModified = aLastModified;
|
|
|
|
}
|
|
|
|
else {
|
2000-08-23 17:27:06 +00:00
|
|
|
mLastModified = new nsString(aLastModified);
|
1999-08-09 19:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsnull != mLastModified) {
|
2001-02-23 02:03:02 +00:00
|
|
|
delete mLastModified;
|
1999-08-09 19:10:24 +00:00
|
|
|
mLastModified = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 06:56:39 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetReferrer(const nsAReadableString& aReferrer)
|
1999-09-17 06:56:39 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aReferrer.IsEmpty()) {
|
1999-09-17 06:56:39 +00:00
|
|
|
if (nsnull != mReferrer) {
|
|
|
|
*mReferrer = aReferrer;
|
|
|
|
}
|
|
|
|
else {
|
2000-08-23 17:27:06 +00:00
|
|
|
mReferrer = new nsString(aReferrer);
|
1999-09-17 06:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsnull != mReferrer) {
|
2001-02-23 02:03:02 +00:00
|
|
|
delete mReferrer;
|
1999-09-17 06:56:39 +00:00
|
|
|
mReferrer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:06:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (! mCSSLoader) {
|
2001-05-19 02:59:15 +00:00
|
|
|
result = NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader));
|
1999-05-18 23:06:31 +00:00
|
|
|
}
|
1999-07-07 01:27:08 +00:00
|
|
|
if (mCSSLoader) {
|
|
|
|
mCSSLoader->SetCaseSensitive(PR_FALSE);
|
2000-05-04 05:54:04 +00:00
|
|
|
mCSSLoader->SetQuirkMode(PRBool(eDTDMode_strict!= mDTDMode));
|
1999-07-07 01:27:08 +00:00
|
|
|
}
|
1999-05-18 23:06:31 +00:00
|
|
|
aLoader = mCSSLoader;
|
|
|
|
NS_IF_ADDREF(aLoader);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-01-15 02:01:36 +00:00
|
|
|
|
1998-09-02 02:06:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetDTDMode(nsDTDMode& aMode)
|
|
|
|
{
|
|
|
|
aMode = mDTDMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetDTDMode(nsDTDMode aMode)
|
|
|
|
{
|
|
|
|
mDTDMode = aMode;
|
1999-07-07 01:27:08 +00:00
|
|
|
if (mCSSLoader) {
|
2000-05-04 05:54:04 +00:00
|
|
|
mCSSLoader->SetQuirkMode(PRBool(eDTDMode_strict!= mDTDMode));
|
1999-07-07 01:27:08 +00:00
|
|
|
}
|
2001-12-21 01:10:07 +00:00
|
|
|
nsIPresShell* shell = (nsIPresShell*) mPresShells.SafeElementAt(0);
|
1999-09-15 17:57:16 +00:00
|
|
|
if (nsnull != shell) {
|
|
|
|
nsCOMPtr<nsIPresContext> pc;
|
|
|
|
shell->GetPresContext(getter_AddRefs(pc));
|
2001-12-21 01:10:07 +00:00
|
|
|
if (pc) {
|
|
|
|
pc->SetCompatibilityMode(((eDTDMode_strict== mDTDMode) ?
|
|
|
|
eCompatibility_Standard :
|
|
|
|
eCompatibility_NavQuirks));
|
|
|
|
}
|
1999-09-15 17:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ContentAppended(nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContainer, "Null container!");
|
|
|
|
|
2001-04-05 03:14:57 +00:00
|
|
|
// Register new content. That is the content numbered from
|
|
|
|
// aNewIndexInContainer and upwards.
|
2001-04-05 03:38:20 +00:00
|
|
|
PRInt32 count=0;
|
2001-04-05 03:14:57 +00:00
|
|
|
aContainer->ChildCount(count);
|
2001-04-05 03:38:20 +00:00
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
nsCOMPtr<nsIContent> newChild;
|
2001-04-05 03:14:57 +00:00
|
|
|
for (i = aNewIndexInContainer; i < count; ++i) {
|
|
|
|
aContainer->ChildAt(i, *getter_AddRefs(newChild));
|
2001-04-05 03:38:20 +00:00
|
|
|
if (newChild)
|
|
|
|
RegisterNamedItems(newChild);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsDocument::ContentAppended(aContainer, aNewIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::ContentInserted(nsIContent* aContainer, nsIContent* aContent,
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult rv = RegisterNamedItems(aContent);
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
return nsDocument::ContentInserted(aContainer, aContent, aIndexInContainer);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::ContentReplaced(nsIContent* aContainer, nsIContent* aOldChild,
|
1998-11-28 23:51:06 +00:00
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2001-08-10 01:22:07 +00:00
|
|
|
NS_ABORT_IF_FALSE(aOldChild && aNewChild, "Null new or old child!");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult rv = UnregisterNamedItems(aOldChild);
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = RegisterNamedItems(aNewChild);
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsDocument::ContentReplaced(aContainer, aOldChild,
|
|
|
|
aNewChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::ContentRemoved(nsIContent* aContainer, nsIContent* aContent,
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2001-08-11 00:37:27 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult rv = UnregisterNamedItems(aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDocument::ContentRemoved(aContainer, aContent, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute)
|
|
|
|
{
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
// XXX: Check namespaces!!!
|
|
|
|
|
|
|
|
if (aAttribute == nsHTMLAtoms::name) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (IsNamedItem(aContent, tag, value)) {
|
|
|
|
nsresult rv = RemoveFromNameTable(value, aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (aAttribute == nsHTMLAtoms::id) {
|
|
|
|
nsresult rv = RemoveFromIdTable(aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDocument::AttributeWillChange(aContent, aNameSpaceID, aAttribute);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
|
2001-08-25 02:01:08 +00:00
|
|
|
nsIAtom* aAttribute, PRInt32 aModType, PRInt32 aHint)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
// XXX: Check namespaces!
|
|
|
|
|
|
|
|
if (aAttribute == nsHTMLAtoms::name) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (IsNamedItem(aContent, tag, value)) {
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = UpdateNameTableEntry(value, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (aAttribute == nsHTMLAtoms::id) {
|
|
|
|
nsAutoString value;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
aContent->GetAttr(aNameSpaceID, nsHTMLAtoms::id, value);
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = AddToIdTable(value, aContent);
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2001-08-25 02:01:08 +00:00
|
|
|
return nsDocument::AttributeChanged(aContent, aNameSpaceID, aAttribute, aModType,
|
2001-03-22 08:51:52 +00:00
|
|
|
aHint);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2000-01-24 06:43:15 +00:00
|
|
|
NS_IMETHODIMP
|
2001-10-30 09:58:07 +00:00
|
|
|
nsHTMLDocument::FlushPendingNotifications(PRBool aFlushReflows,
|
|
|
|
PRBool aUpdateViews)
|
2000-01-24 06:43:15 +00:00
|
|
|
{
|
2000-10-17 05:07:39 +00:00
|
|
|
// Determine if it is safe to flush the sink
|
|
|
|
// by determining if it safe to flush all the presshells.
|
|
|
|
PRBool isSafeToFlush = PR_TRUE;
|
2001-05-30 11:26:21 +00:00
|
|
|
if (aFlushReflows) {
|
|
|
|
PRInt32 i = 0, n = mPresShells.Count();
|
|
|
|
while ((i < n) && (isSafeToFlush)) {
|
|
|
|
nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
|
|
|
|
if (shell) {
|
|
|
|
shell->IsSafeToFlush(isSafeToFlush);
|
|
|
|
}
|
|
|
|
++i;
|
2000-10-17 05:07:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((isSafeToFlush) && (mParser)) {
|
2000-01-24 06:43:15 +00:00
|
|
|
nsCOMPtr<nsIContentSink> sink;
|
|
|
|
|
|
|
|
// XXX Ack! Parser doesn't addref sink before passing it back
|
|
|
|
sink = mParser->GetContentSink();
|
|
|
|
if (sink) {
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = sink->FlushPendingNotifications();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return nsDocument::FlushPendingNotifications(aFlushReflows, aUpdateViews);
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
|
2000-06-09 04:19:09 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateElementNS(const nsAReadableString& aNamespaceURI,
|
|
|
|
const nsAReadableString& aQualifiedName,
|
|
|
|
nsIDOMElement** aReturn)
|
2000-06-09 04:19:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
rv = mNodeInfoManager->GetNodeInfo(aQualifiedName, aNamespaceURI,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
nodeInfo->GetNamespaceID(namespaceID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (namespaceID == kNameSpaceID_HTML) {
|
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent;
|
|
|
|
|
2001-05-12 07:12:33 +00:00
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo, PR_FALSE);
|
2000-06-09 04:19:09 +00:00
|
|
|
content = do_QueryInterface(htmlContent);
|
|
|
|
}
|
2001-11-28 06:13:11 +00:00
|
|
|
else {
|
2001-11-17 06:18:04 +00:00
|
|
|
rv = NS_NewXMLElement(getter_AddRefs(content), nodeInfo);
|
2001-11-28 06:13:11 +00:00
|
|
|
}
|
2000-06-09 04:19:09 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
content->SetContentID(mNextContentID++);
|
|
|
|
|
2000-09-09 05:46:14 +00:00
|
|
|
return content->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aReturn);
|
2000-06-09 04:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
//
|
|
|
|
// nsIDOMDocument interface implementation
|
|
|
|
//
|
1998-07-14 18:44:44 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateElement(const nsAReadableString& aTagName,
|
1998-07-14 18:44:44 +00:00
|
|
|
nsIDOMElement** aReturn)
|
1998-05-04 17:54:45 +00:00
|
|
|
{
|
2000-05-10 13:13:39 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
2002-01-24 02:03:19 +00:00
|
|
|
NS_ENSURE_TRUE(!aTagName.IsEmpty(), NS_ERROR_DOM_INVALID_CHARACTER_ERR);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nsAutoString tmp(aTagName);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(tmp);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2000-09-20 05:12:44 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(tmp, nsnull, kNameSpaceID_None,
|
2000-05-10 13:13:39 +00:00
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> content;
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = NS_CreateHTMLElement(getter_AddRefs(content), nodeInfo,
|
|
|
|
PR_FALSE);
|
1999-10-08 20:41:19 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-03-21 03:25:16 +00:00
|
|
|
content->SetContentID(mNextContentID++);
|
2000-09-09 05:46:14 +00:00
|
|
|
rv = content->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aReturn);
|
1998-05-04 17:54:45 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateProcessingInstruction(const nsAReadableString& aTarget,
|
|
|
|
const nsAReadableString& aData,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMProcessingInstruction** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1998-10-20 17:07:23 +00:00
|
|
|
// There are no PIs for HTML
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
1999-09-08 23:18:27 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateCDATASection(const nsAReadableString& aData,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMCDATASection** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1998-10-20 17:07:23 +00:00
|
|
|
// There are no CDATASections in HTML
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
1999-09-08 23:18:27 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
1998-10-20 17:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateEntityReference(const nsAReadableString& aName,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMEntityReference** aReturn)
|
|
|
|
{
|
|
|
|
// There are no EntityReferences in HTML
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
1999-09-08 23:18:27 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-10-20 17:07:23 +00:00
|
|
|
nsHTMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2000-03-22 22:16:14 +00:00
|
|
|
return nsDocument::GetDoctype(aDocumentType);
|
1998-10-20 17:07:23 +00:00
|
|
|
}
|
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
|
|
|
|
{
|
|
|
|
return nsDocument::GetImplementation(aImplementation);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
|
|
|
|
{
|
|
|
|
return nsDocument::GetDocumentElement(aDocumentElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
|
|
|
|
{
|
|
|
|
return nsDocument::CreateDocumentFragment(aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateComment(const nsAReadableString& aData, nsIDOMComment** aReturn)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateComment(aData, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateAttribute(const nsAReadableString& aName, nsIDOMAttr** aReturn)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateAttribute(aName, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateTextNode(const nsAReadableString& aData, nsIDOMText** aReturn)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateTextNode(aData, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetElementsByTagName(const nsAReadableString& aTagname, nsIDOMNodeList** aReturn)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
2000-05-17 03:47:06 +00:00
|
|
|
nsAutoString tmp(aTagname);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(tmp); // HTML elements are lower case internally.
|
2000-05-17 03:47:06 +00:00
|
|
|
return nsDocument::GetElementsByTagName(tmp, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIDOMNode interface implementation
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::GetChildNodes(aChildNodes);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetFirstChild(nsIDOMNode** aFirstChild)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::GetFirstChild(aFirstChild);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetLastChild(nsIDOMNode** aLastChild)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::GetLastChild(aLastChild);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::InsertBefore(nsIDOMNode* aNewChild,
|
|
|
|
nsIDOMNode* aRefChild,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::InsertBefore(aNewChild, aRefChild, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ReplaceChild(nsIDOMNode* aNewChild,
|
|
|
|
nsIDOMNode* aOldChild,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::ReplaceChild(aNewChild, aOldChild, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::RemoveChild(aOldChild, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::AppendChild(aNewChild, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::HasChildNodes(PRBool* aReturn)
|
|
|
|
{
|
1999-03-31 20:49:25 +00:00
|
|
|
return nsDocument::HasChildNodes(aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 05:19:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::HasAttributes(PRBool* aReturn)
|
|
|
|
{
|
|
|
|
return nsDocument::HasAttributes(aReturn);
|
|
|
|
}
|
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetNodeName(nsAWritableString& aNodeName)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetNodeName(aNodeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetNodeValue(nsAWritableString& aNodeValue)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetNodeValue(aNodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetNodeValue(const nsAReadableString& aNodeValue)
|
1999-01-19 16:58:45 +00:00
|
|
|
{
|
|
|
|
return nsDocument::SetNodeValue(aNodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetNodeType(PRUint16* aNodeType)
|
|
|
|
{
|
|
|
|
return nsDocument::GetNodeType(aNodeType);
|
|
|
|
}
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetNamespaceURI(nsAWritableString& aNamespaceURI)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetNamespaceURI(aNamespaceURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetPrefix(nsAWritableString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetPrefix(aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetPrefix(const nsAReadableString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
return nsDocument::SetPrefix(aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetLocalName(nsAWritableString& aLocalName)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetLocalName(aLocalName);
|
|
|
|
}
|
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetParentNode(nsIDOMNode** aParentNode)
|
|
|
|
{
|
|
|
|
return nsDocument::GetParentNode(aParentNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
|
|
|
|
{
|
|
|
|
return nsDocument::GetPreviousSibling(aPreviousSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetNextSibling(nsIDOMNode** aNextSibling)
|
|
|
|
{
|
|
|
|
return nsDocument::GetNextSibling(aNextSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
|
|
|
|
{
|
|
|
|
return nsDocument::GetAttributes(aAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
|
|
|
{
|
|
|
|
return nsDocument::GetOwnerDocument(aOwnerDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
return nsDocument::CloneNode(aDeep, aReturn);
|
|
|
|
}
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Normalize()
|
|
|
|
{
|
|
|
|
return nsDocument::Normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-09-14 05:19:00 +00:00
|
|
|
nsHTMLDocument::IsSupported(const nsAReadableString& aFeature,
|
|
|
|
const nsAReadableString& aVersion,
|
|
|
|
PRBool* aReturn)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
2000-09-14 05:19:00 +00:00
|
|
|
return nsDocument::IsSupported(aFeature, aVersion, aReturn);
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetBaseURI(nsAWritableString &aURI)
|
|
|
|
{
|
|
|
|
aURI.Truncate();
|
|
|
|
nsCOMPtr<nsIURI> uri(do_QueryInterface(mBaseURL ? mBaseURL : mDocumentURL));
|
|
|
|
if (uri) {
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
uri->GetSpec(getter_Copies(spec));
|
|
|
|
if (spec) {
|
2001-05-19 11:27:30 +00:00
|
|
|
CopyASCIItoUCS2(nsDependentCString(spec), aURI);
|
2001-03-30 02:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-19 16:58:45 +00:00
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI,
|
|
|
|
nsAWritableString& aPrefix)
|
|
|
|
{
|
|
|
|
aPrefix.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix,
|
|
|
|
nsAWritableString& aNamespaceURI)
|
|
|
|
{
|
|
|
|
aNamespaceURI.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
//
|
|
|
|
// nsIDOMHTMLDocument interface implementation
|
|
|
|
//
|
1998-12-07 06:10:12 +00:00
|
|
|
// see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html.html#ID-1006298752
|
|
|
|
// for full specification.
|
|
|
|
//
|
1998-10-20 17:07:23 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetTitle(nsAWritableString& aTitle)
|
1998-10-20 17:07:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return nsDocument::GetTitle(aTitle);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetReferrer(nsAWritableString& aReferrer)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-09-17 06:56:39 +00:00
|
|
|
if (nsnull != mReferrer) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aReferrer.Assign(*mReferrer);
|
1998-12-07 06:10:12 +00:00
|
|
|
}
|
1999-09-17 06:56:39 +00:00
|
|
|
else {
|
|
|
|
aReferrer.Truncate();
|
|
|
|
}
|
|
|
|
|
1998-12-07 06:10:12 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetDomainURI(nsIURI **uri)
|
|
|
|
{
|
2000-01-26 15:33:57 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
if (NS_FAILED(GetPrincipal(getter_AddRefs(principal))))
|
1999-10-02 03:41:37 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
|
|
|
|
if (!codebase)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return codebase->GetURI(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetDomain(nsAWritableString& aDomain)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-10-02 03:41:37 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (NS_FAILED(GetDomainURI(getter_AddRefs(uri))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
char *hostName;
|
|
|
|
if (NS_FAILED(uri->GetHost(&hostName)))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-23 17:27:06 +00:00
|
|
|
aDomain.Assign(NS_ConvertASCIItoUCS2(hostName));
|
1999-10-02 03:41:37 +00:00
|
|
|
nsCRT::free(hostName);
|
|
|
|
|
1998-12-07 06:10:12 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetDomain(const nsAReadableString& aDomain)
|
1999-10-02 03:41:37 +00:00
|
|
|
{
|
|
|
|
// Check new domain
|
2000-03-31 00:31:18 +00:00
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
nsAutoString current;
|
|
|
|
if (NS_FAILED(GetDomain(current)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
if (current.Equals(aDomain)) {
|
|
|
|
ok = PR_TRUE;
|
|
|
|
} else if (aDomain.Length() < current.Length()) {
|
|
|
|
nsAutoString suffix;
|
|
|
|
current.Right(suffix, aDomain.Length());
|
|
|
|
PRUnichar c = current.CharAt(current.Length() - aDomain.Length() - 1);
|
2000-09-02 07:21:57 +00:00
|
|
|
if (suffix.EqualsIgnoreCase(nsString(aDomain)) &&
|
2000-08-23 17:27:06 +00:00
|
|
|
(c == '.' || c == '/'))
|
1999-10-02 03:41:37 +00:00
|
|
|
ok = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (!ok) {
|
|
|
|
// Error: illegal domain
|
|
|
|
return NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN;
|
|
|
|
}
|
2000-03-31 00:31:18 +00:00
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
// Create new URI
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (NS_FAILED(GetDomainURI(getter_AddRefs(uri))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsXPIDLCString scheme;
|
|
|
|
if (NS_FAILED(uri->GetScheme(getter_Copies(scheme))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsXPIDLCString path;
|
|
|
|
if (NS_FAILED(uri->GetPath(getter_Copies(path))))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-04-15 20:15:37 +00:00
|
|
|
nsAutoString newURIString; newURIString.AssignWithConversion( NS_STATIC_CAST(const char*, scheme) );
|
2001-12-16 11:58:03 +00:00
|
|
|
newURIString.Append(NS_LITERAL_STRING("://"));
|
1999-10-02 03:41:37 +00:00
|
|
|
newURIString += aDomain;
|
2000-04-15 20:15:37 +00:00
|
|
|
newURIString.AppendWithConversion(path);
|
1999-10-02 03:41:37 +00:00
|
|
|
nsIURI *newURI;
|
|
|
|
if (NS_FAILED(NS_NewURI(&newURI, newURIString)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-11-16 05:07:31 +00:00
|
|
|
// Get codebase principal
|
1999-10-02 03:41:37 +00:00
|
|
|
nsresult rv;
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
1999-10-02 03:41:37 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-31 00:31:18 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> newCodebase;
|
|
|
|
rv = securityManager->GetCodebasePrincipal(newURI, getter_AddRefs(newCodebase));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIAggregatePrincipal> agg = do_QueryInterface(mPrincipal, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Principal not an aggregate.");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-19 10:25:49 +00:00
|
|
|
|
|
|
|
rv = agg->SetCodebase(newCodebase);
|
|
|
|
|
|
|
|
// Bug 13871: Frameset spoofing - note that document.domain was set
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2000-10-24 04:35:25 +00:00
|
|
|
mDomainWasSet = PR_TRUE;
|
2000-10-19 10:25:49 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-10-24 04:35:25 +00:00
|
|
|
nsHTMLDocument::WasDomainSet(PRBool* aDomainWasSet)
|
2000-10-19 10:25:49 +00:00
|
|
|
{
|
2000-10-24 04:35:25 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDomainWasSet);
|
|
|
|
*aDomainWasSet = mDomainWasSet;
|
2000-10-19 10:25:49 +00:00
|
|
|
return NS_OK;
|
1999-10-02 03:41:37 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetURL(nsAWritableString& aURL)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1998-11-24 21:07:43 +00:00
|
|
|
if (nsnull != mDocumentURL) {
|
1999-06-25 01:53:22 +00:00
|
|
|
char* str;
|
|
|
|
mDocumentURL->GetSpec(&str);
|
2000-08-23 17:27:06 +00:00
|
|
|
aURL.Assign(NS_ConvertASCIItoUCS2(str));
|
1999-06-25 01:53:22 +00:00
|
|
|
nsCRT::free(str);
|
1998-11-24 21:07:43 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
|
|
|
|
{
|
2001-02-23 02:01:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aBody);
|
|
|
|
*aBody = nsnull;
|
|
|
|
|
|
|
|
nsISupports* element = nsnull;
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
|
|
|
|
if (mBodyContent || (GetBodyContent() && mBodyContent)) {
|
|
|
|
// There is a body element, return that as the body.
|
|
|
|
element = mBodyContent;
|
|
|
|
} else {
|
|
|
|
// The document is most likely a frameset document so look for the
|
|
|
|
// outer most frameset element
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
|
|
|
|
nsresult rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
|
|
|
|
getter_AddRefs(nodeList));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (nodeList) {
|
|
|
|
rv = nodeList->Item(0, getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
element = node;
|
|
|
|
}
|
1998-11-12 22:25:51 +00:00
|
|
|
}
|
2001-02-23 02:01:30 +00:00
|
|
|
|
|
|
|
return element ? CallQueryInterface(element, aBody) : NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
|
|
|
|
{
|
2000-12-14 22:37:22 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> bodyElement(do_QueryInterface(aBody));
|
|
|
|
|
|
|
|
// The body element must be of type nsIDOMHTMLBodyElement.
|
|
|
|
if (!bodyElement) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
1999-02-04 02:16:11 +00:00
|
|
|
}
|
|
|
|
|
2000-12-14 22:37:22 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> root;
|
|
|
|
GetDocumentElement(getter_AddRefs(root));
|
|
|
|
|
|
|
|
if (!root) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString bodyStr;
|
2001-12-16 11:58:03 +00:00
|
|
|
bodyStr.Assign(NS_LITERAL_STRING("BODY"));
|
2000-12-14 22:37:22 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
root->GetFirstChild(getter_AddRefs(child));
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(child));
|
|
|
|
|
|
|
|
if (domElement) {
|
|
|
|
nsAutoString tagName;
|
1999-02-04 02:16:11 +00:00
|
|
|
|
|
|
|
domElement->GetTagName(tagName);
|
2000-12-14 22:37:22 +00:00
|
|
|
|
1999-02-04 02:16:11 +00:00
|
|
|
if (bodyStr.EqualsIgnoreCase(tagName)) {
|
2000-12-14 22:37:22 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> ret;
|
|
|
|
|
|
|
|
nsresult rv = root->ReplaceChild(aBody, child, getter_AddRefs(ret));
|
|
|
|
|
2001-10-31 23:52:52 +00:00
|
|
|
mBodyContent = nsnull;
|
1999-02-04 02:16:11 +00:00
|
|
|
|
2000-12-14 22:37:22 +00:00
|
|
|
return rv;
|
1999-02-04 02:16:11 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-14 22:37:22 +00:00
|
|
|
|
|
|
|
nsIDOMNode *tmpNode = child;
|
|
|
|
tmpNode->GetNextSibling(getter_AddRefs(child));
|
1999-02-04 02:16:11 +00:00
|
|
|
}
|
2000-12-14 22:37:22 +00:00
|
|
|
|
1999-02-04 02:16:11 +00:00
|
|
|
return PR_FALSE;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
|
|
|
|
{
|
|
|
|
if (nsnull == mImages) {
|
2000-05-17 20:35:19 +00:00
|
|
|
mImages = new nsContentList(this, nsHTMLAtoms::img, kNameSpaceID_Unknown);
|
1998-07-22 23:32:19 +00:00
|
|
|
if (nsnull == mImages) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mImages);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aImages = (nsIDOMHTMLCollection *)mImages;
|
|
|
|
NS_ADDREF(mImages);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
|
|
|
|
{
|
|
|
|
if (nsnull == mApplets) {
|
2000-05-17 20:35:19 +00:00
|
|
|
mApplets = new nsContentList(this, nsHTMLAtoms::applet, kNameSpaceID_Unknown);
|
1998-07-22 23:32:19 +00:00
|
|
|
if (nsnull == mApplets) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mApplets);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-09-25 00:51:45 +00:00
|
|
|
*aApplets = (nsIDOMHTMLCollection *)mApplets;
|
|
|
|
NS_ADDREF(mApplets);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
PRBool
|
1999-05-04 20:53:44 +00:00
|
|
|
nsHTMLDocument::MatchLinks(nsIContent *aContent, nsString* aData)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom *name;
|
|
|
|
aContent->GetTag(name);
|
1998-07-22 23:32:19 +00:00
|
|
|
nsAutoString attr;
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if ((nsnull != name) &&
|
1999-01-15 19:18:30 +00:00
|
|
|
((nsHTMLAtoms::area == name) || (nsHTMLAtoms::a == name)) &&
|
2001-08-17 08:14:14 +00:00
|
|
|
(NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::href, attr))) {
|
1998-07-22 23:32:19 +00:00
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(name);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks)
|
|
|
|
{
|
|
|
|
if (nsnull == mLinks) {
|
2001-03-22 08:51:52 +00:00
|
|
|
mLinks = new nsContentList(this, MatchLinks, nsString());
|
1998-07-22 23:32:19 +00:00
|
|
|
if (nsnull == mLinks) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mLinks);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLinks = (nsIDOMHTMLCollection *)mLinks;
|
|
|
|
NS_ADDREF(mLinks);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
PRBool
|
1999-05-04 20:53:44 +00:00
|
|
|
nsHTMLDocument::MatchAnchors(nsIContent *aContent, nsString* aData)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom *name;
|
|
|
|
aContent->GetTag(name);
|
1998-07-22 23:32:19 +00:00
|
|
|
nsAutoString attr;
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if ((nsnull != name) &&
|
1999-01-15 19:18:30 +00:00
|
|
|
(nsHTMLAtoms::a == name) &&
|
2001-08-17 08:14:14 +00:00
|
|
|
(NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::name, attr))) {
|
1998-07-22 23:32:19 +00:00
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(name);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetAnchors(nsIDOMHTMLCollection** aAnchors)
|
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mAnchors) {
|
|
|
|
mAnchors = new nsContentList(this, MatchAnchors, nsString());
|
|
|
|
NS_ENSURE_TRUE(mAnchors, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_ADDREF(mAnchors);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aAnchors = (nsIDOMHTMLCollection *)mAnchors;
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ADDREF(*aAnchors);
|
1998-07-22 23:32:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetCookie(nsAWritableString& aCookie)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-08-19 22:23:20 +00:00
|
|
|
nsresult result = NS_OK;
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAutoString str;
|
2001-06-26 00:11:04 +00:00
|
|
|
|
|
|
|
aCookie.Truncate(); // clear current cookie in case service fails; no cookie isn't an error condition.
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookieService> service = do_GetService(kCookieServiceCID, &result);
|
|
|
|
if (NS_SUCCEEDED(result) && service && mDocumentURL) {
|
|
|
|
nsXPIDLCString cookie;
|
|
|
|
result = service->GetCookieString(mDocumentURL, getter_Copies(cookie));
|
|
|
|
if (NS_SUCCEEDED(result) && cookie)
|
|
|
|
CopyASCIItoUCS2(nsDependentCString(cookie), aCookie);
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetCookie(const nsAReadableString& aCookie)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-08-19 22:23:20 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-06-26 00:11:04 +00:00
|
|
|
nsCOMPtr<nsICookieService> service = do_GetService(kCookieServiceCID, &result);
|
|
|
|
if (NS_SUCCEEDED(result) && service && mDocumentURL) {
|
2001-03-29 02:11:48 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
this->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
if (globalObj) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
|
|
|
if (window) {
|
|
|
|
window->GetPrompter(getter_AddRefs(prompt));
|
|
|
|
}
|
|
|
|
}
|
2001-06-26 00:11:04 +00:00
|
|
|
result = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
char* cookie = ToNewCString(aCookie);
|
|
|
|
if (cookie) {
|
2001-11-16 15:05:53 +00:00
|
|
|
result = service->SetCookieString(mDocumentURL, prompt, cookie, 0);
|
2001-06-26 00:11:04 +00:00
|
|
|
nsCRT::free(cookie);
|
|
|
|
}
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-08-11 00:37:27 +00:00
|
|
|
// static
|
1999-05-18 23:44:55 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::GetSourceDocumentURL(JSContext* cx,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI** sourceURL)
|
1999-05-18 23:44:55 +00:00
|
|
|
{
|
|
|
|
// XXX Tom said this reminded him of the "Six Degrees of
|
|
|
|
// Kevin Bacon" game. We try to get from here to there using
|
|
|
|
// whatever connections possible. The problem is that this
|
|
|
|
// could break if any of the connections along the way change.
|
|
|
|
// I wish there were a better way.
|
1999-08-18 08:48:33 +00:00
|
|
|
*sourceURL = nsnull;
|
|
|
|
|
2001-08-11 00:37:27 +00:00
|
|
|
if (!cx) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
// We need to use the dynamically scoped global and assume that the
|
|
|
|
// current JSContext is a DOM context with a nsIScriptGlobalObject so
|
|
|
|
// that we can get the url of the caller.
|
|
|
|
// XXX This will fail on non-DOM contexts :(
|
1999-05-18 23:44:55 +00:00
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
2001-02-19 12:55:42 +00:00
|
|
|
nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global));
|
1999-05-18 23:44:55 +00:00
|
|
|
|
2001-08-11 00:37:27 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(global));
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
return NS_OK; // Can't get the source URI if we can't get the window.
|
1999-05-18 23:44:55 +00:00
|
|
|
}
|
2001-08-11 00:37:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> dom_doc;
|
|
|
|
window->GetDocument(getter_AddRefs(dom_doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
|
|
|
|
|
|
|
|
if (!doc) {
|
|
|
|
return NS_OK; // No document in the window
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->GetDocumentURL(sourceURL);
|
|
|
|
|
|
|
|
return sourceURL ? NS_OK : NS_ERROR_FAILURE;
|
1999-05-18 23:44:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-28 00:18:48 +00:00
|
|
|
|
|
|
|
// XXX TBI: accepting arguments to the open method.
|
|
|
|
nsresult
|
1999-06-23 03:29:44 +00:00
|
|
|
nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2001-05-25 08:49:03 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docshell;
|
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
// If we already have a parser we ignore the document.open call.
|
|
|
|
if (mParser)
|
|
|
|
return NS_OK;
|
2000-06-08 22:51:06 +00:00
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
// Stop current loads targeted at the window this document is in.
|
2000-06-08 22:51:06 +00:00
|
|
|
if (mScriptGlobalObject) {
|
|
|
|
mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell));
|
|
|
|
|
|
|
|
if (docshell) {
|
2001-08-14 04:46:20 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(docshell));
|
|
|
|
webnav->Stop(nsIWebNavigation::STOP_NETWORK);
|
2000-06-08 22:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
// The open occurred after the document finished loading.
|
|
|
|
// So we reset the document and create a new one.
|
2000-09-19 05:11:59 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
1999-09-21 06:44:56 +00:00
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
result = NS_OpenURI(getter_AddRefs(channel), aSourceURL, nsnull, group);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
if (NS_FAILED(result)) return result;
|
2000-08-12 22:19:55 +00:00
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
//Before we reset the doc notify the globalwindow of the change.
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
if (mScriptGlobalObject) {
|
|
|
|
//Hold onto ourselves on the offchance that we're down to one ref
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> kungFuDeathGrip =
|
|
|
|
do_QueryInterface((nsIHTMLDocument*)this);
|
|
|
|
|
2001-10-02 00:54:44 +00:00
|
|
|
result = mScriptGlobalObject->SetNewDocument(kungFuDeathGrip, PR_FALSE);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-09-19 05:11:59 +00:00
|
|
|
}
|
|
|
|
|
2001-04-12 09:50:55 +00:00
|
|
|
// XXX This is a nasty workaround for a scrollbar code bug
|
|
|
|
// (http://bugzilla.mozilla.org/show_bug.cgi?id=55334).
|
|
|
|
|
|
|
|
// Hold on to our root element
|
|
|
|
nsCOMPtr<nsIContent> root(mRootContent);
|
|
|
|
|
|
|
|
if (root) {
|
|
|
|
PRInt32 count;
|
|
|
|
root->ChildCount(count);
|
|
|
|
|
|
|
|
// Remove all the children from the root.
|
|
|
|
while (--count >= 0) {
|
|
|
|
root->RemoveChildAt(count, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
mRootContent->GetAttrCount(count);
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
// Remove all attributes from the root element
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsCOMPtr<nsIAtom> name, prefix;
|
|
|
|
PRInt32 nsid;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
root->GetAttrNameAt(count, nsid, *getter_AddRefs(name),
|
|
|
|
*getter_AddRefs(prefix));
|
2001-04-12 09:50:55 +00:00
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
root->UnsetAttr(nsid, name, PR_FALSE);
|
2001-04-12 09:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the root from the childlist
|
|
|
|
if (mChildren) {
|
|
|
|
mChildren->RemoveElement(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
mRootContent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call Reset(), this will now do the full reset, except removing
|
|
|
|
// the root from the document, doing that confuses the scrollbar
|
|
|
|
// code in mozilla since the document in the root element and all
|
|
|
|
// the anonymous content (i.e. scrollbar elements) is set to
|
|
|
|
// null.
|
|
|
|
|
2000-09-19 05:11:59 +00:00
|
|
|
result = Reset(channel, group);
|
2001-03-22 08:51:52 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2001-04-12 09:50:55 +00:00
|
|
|
if (root) {
|
|
|
|
// Tear down the frames for the root element.
|
|
|
|
ContentRemoved(nsnull, root, 0);
|
|
|
|
|
|
|
|
// Put the root element back into the document, we don't notify
|
|
|
|
// the document about this insertion since the sink will do that
|
|
|
|
// for us, the sink will call InitialReflow() and that'll create
|
|
|
|
// frames for the root element and the scrollbars work as expected
|
|
|
|
// (since the document in the root element was never set to null)
|
|
|
|
|
|
|
|
mChildren->AppendElement(root);
|
|
|
|
mRootContent = root;
|
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
result = nsComponentManager::CreateInstance(kCParserCID, nsnull,
|
|
|
|
NS_GET_IID(nsIParser),
|
|
|
|
(void **)&mParser);
|
|
|
|
mIsWriting = 1;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> sink;
|
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
|
|
|
|
// Get the webshell of our primary presentation shell
|
2001-12-21 01:10:07 +00:00
|
|
|
nsIPresShell* shell = (nsIPresShell*) mPresShells.SafeElementAt(0);
|
2001-03-22 08:51:52 +00:00
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
|
|
|
|
if (container) {
|
|
|
|
webShell = do_QueryInterface(container);
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aSourceURL,
|
|
|
|
webShell, channel);
|
|
|
|
|
|
|
|
if (NS_OK == result) {
|
|
|
|
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
|
|
|
|
nsCOMPtr<nsIDTD> theDTD(do_CreateInstance(kNavDTDCID, &result));
|
|
|
|
if(NS_SUCCEEDED(result)) {
|
|
|
|
mParser->RegisterDTD(theDTD);
|
2000-09-19 05:11:59 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
mParser->SetContentSink(sink);
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-28 00:18:48 +00:00
|
|
|
|
2001-08-11 00:37:27 +00:00
|
|
|
// Prepare the docshell and the document viewer for the impending
|
|
|
|
// out of band document.write()
|
2001-05-25 08:49:03 +00:00
|
|
|
if (docshell) {
|
|
|
|
docshell->PrepareForNewContentModel();
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv);
|
|
|
|
if (docViewer) {
|
|
|
|
docViewer->LoadStart(NS_STATIC_CAST(nsIHTMLDocument *, this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
// Add a wyciwyg channel request into the document load group
|
|
|
|
NS_ASSERTION(mWyciwygChannel == nsnull, "nsHTMLDocument::OpenCommon(): wyciwyg channel already exists!");
|
|
|
|
CreateAndAddWyciwygChannel();
|
1999-05-28 00:18:48 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Open()
|
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
return Open(getter_AddRefs(doc));
|
1999-05-28 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsHTMLDocument::Open(nsIDOMDocument** aReturn)
|
1999-05-28 00:18:48 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2001-08-11 00:37:27 +00:00
|
|
|
nsCOMPtr<nsIURI> sourceURL;
|
1999-05-28 00:18:48 +00:00
|
|
|
|
|
|
|
// XXX The URL of the newly created document will match
|
|
|
|
// that of the source document. Is this right?
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
// XXX: This service should be cached.
|
|
|
|
nsCOMPtr<nsIJSContextStack>
|
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
if (NS_FAILED(stack->Peek(&cx)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-08-11 00:37:27 +00:00
|
|
|
result = GetSourceDocumentURL(cx, getter_AddRefs(sourceURL));
|
1999-05-28 00:18:48 +00:00
|
|
|
// Recover if we had a problem obtaining the source URL
|
2001-08-11 00:37:27 +00:00
|
|
|
if (!sourceURL) {
|
|
|
|
result = NS_NewURI(getter_AddRefs(sourceURL), "about:blank");
|
1999-05-28 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = OpenCommon(sourceURL);
|
|
|
|
}
|
|
|
|
|
2001-01-01 20:54:38 +00:00
|
|
|
QueryInterface(NS_GET_IID(nsIDOMDocument), (void **)aReturn);
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
return result;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-02-03 19:38:16 +00:00
|
|
|
#define NS_GENERATE_PARSER_KEY() (void*)((mIsWriting << 31) | (mWriteLevel & 0x7fffffff))
|
|
|
|
|
1999-12-14 23:34:17 +00:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsHTMLDocument::Clear()
|
1999-12-14 23:34:17 +00:00
|
|
|
{
|
2001-01-23 02:20:33 +00:00
|
|
|
// This method has been deprecated
|
|
|
|
return NS_OK;
|
1999-12-14 23:34:17 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Close()
|
|
|
|
{
|
1999-02-03 19:38:16 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (mParser && mIsWriting) {
|
1999-02-03 19:38:16 +00:00
|
|
|
mWriteLevel++;
|
2002-01-25 06:37:35 +00:00
|
|
|
result = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
|
|
|
|
NS_GENERATE_PARSER_KEY(),
|
2001-11-14 01:33:42 +00:00
|
|
|
NS_LITERAL_STRING("text/html"), PR_FALSE,
|
2001-03-22 08:51:52 +00:00
|
|
|
PR_TRUE);
|
1999-02-03 19:38:16 +00:00
|
|
|
mWriteLevel--;
|
|
|
|
mIsWriting = 0;
|
2000-05-22 22:16:56 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
// XXX Make sure that all the document.written content is
|
|
|
|
// reflowed. We should remove this call once we change
|
|
|
|
// nsHTMLDocument::OpenCommon() so that it completely destroys the
|
|
|
|
// earlier document's content and frame hierarchy. Right now, it
|
|
|
|
// re-uses the earlier document's root content object and
|
|
|
|
// corresponding frame objects. These re-used frame objects think
|
|
|
|
// that they have already been reflowed, so they drop initial
|
|
|
|
// reflows. For certain cases of document.written content, like a
|
|
|
|
// frameset document, the dropping of the initial reflow means
|
|
|
|
// that we end up in document.close() without appended any reflow
|
|
|
|
// commands to the reflow queue and, consequently, without adding
|
|
|
|
// the dummy layout request to the load group. Since the dummy
|
|
|
|
// layout request is not added to the load group, the onload
|
|
|
|
// handler of the frameset fires before the frames get reflowed
|
|
|
|
// and loaded. That is the long explanation for why we need this
|
|
|
|
// one line of code here!
|
2001-05-25 08:49:03 +00:00
|
|
|
FlushPendingNotifications();
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
// Remove the wyciwyg channel request from the document load group
|
2001-05-25 08:49:03 +00:00
|
|
|
// that we added in OpenCommon(). If all other requests between
|
|
|
|
// document.open() and document.close() have completed, then this
|
|
|
|
// method should cause the firing of an onload event.
|
2002-01-31 19:36:45 +00:00
|
|
|
NS_ASSERTION(mWyciwygChannel, "nsHTMLDocument::Close(): Trying to remove non-existent wyciwyg channel!");
|
|
|
|
RemoveWyciwygChannel();
|
|
|
|
NS_ASSERTION(mWyciwygChannel == nsnull, "nsHTMLDocument::Close(): nsIWyciwyg Channel could not be removed!");
|
1999-02-03 19:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::WriteCommon(const nsAReadableString& aText,
|
1999-01-06 00:32:41 +00:00
|
|
|
PRBool aNewlineTerminate)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2001-05-13 00:27:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mParser) {
|
|
|
|
rv = Open();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-16 01:31:49 +00:00
|
|
|
mWriteLevel++;
|
2001-05-13 00:27:58 +00:00
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
static NS_NAMED_LITERAL_STRING(new_line, "\n");
|
|
|
|
static NS_NAMED_LITERAL_STRING(empty, "");
|
|
|
|
const nsAString *term = aNewlineTerminate ? &new_line : ∅
|
|
|
|
|
|
|
|
const nsAString& text = aText + *term;
|
|
|
|
|
|
|
|
// Save the data in cache
|
|
|
|
if (mWyciwygChannel) {
|
|
|
|
mWyciwygChannel->WriteToCache(NS_ConvertUCS2toUTF8(text).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mParser->Parse(text ,
|
2001-10-16 04:07:30 +00:00
|
|
|
NS_GENERATE_PARSER_KEY(),
|
|
|
|
NS_LITERAL_STRING("text/html"), PR_FALSE,
|
|
|
|
(!mIsWriting || (mWriteLevel > 1)));
|
2002-01-31 19:36:45 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
mWriteLevel--;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Write(const nsAReadableString& aText)
|
|
|
|
{
|
|
|
|
return WriteCommon(aText, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Writeln(const nsAReadableString& aText)
|
|
|
|
{
|
|
|
|
return WriteCommon(aText, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::ScriptWriteCommon(PRBool aNewlineTerminate)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
|
1998-07-23 22:06:05 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsIXPCNativeCallContext> ncc;
|
1999-05-28 00:18:48 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (xpc) {
|
|
|
|
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(ncc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-05-28 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsXPIDLCString spec;
|
1999-05-28 00:18:48 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (mDocumentURL) {
|
|
|
|
rv = mDocumentURL->GetSpec(getter_Copies(spec));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
1999-05-28 00:18:48 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (!mDocumentURL || nsCRT::strcasecmp(spec, "about:blank") == 0) {
|
2000-03-24 22:15:37 +00:00
|
|
|
// The current document's URL and principal are empty or "about:blank".
|
|
|
|
// By writing to this document, the script acquires responsibility for the
|
|
|
|
// document for security purposes. Thus a document.write of a script tag
|
|
|
|
// ends up producing a script with the same principals as the script
|
|
|
|
// that performed the write.
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-03-24 22:15:37 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> subject;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-03-24 22:15:37 +00:00
|
|
|
if (subject) {
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(subject);
|
|
|
|
if (codebase) {
|
|
|
|
nsCOMPtr<nsIURI> subjectURI;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
rv = codebase->GetURI(getter_AddRefs(subjectURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-24 22:15:37 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
mDocumentURL = subjectURI;
|
|
|
|
NS_ADDREF(mDocumentURL);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mPrincipal);
|
|
|
|
mPrincipal = subject;
|
|
|
|
NS_ADDREF(mPrincipal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (ncc) {
|
2001-05-21 23:29:14 +00:00
|
|
|
// We're called from JS, concatenate the extra arguments into
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
// string_buffer
|
|
|
|
PRUint32 i, argc;
|
2001-01-01 20:54:38 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
ncc->GetArgc(&argc);
|
2001-01-01 20:54:38 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
JSContext *cx = nsnull;
|
|
|
|
rv = ncc->GetJSContext(&cx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
jsval *argv = nsnull;
|
|
|
|
ncc->GetArgvPtr(&argv);
|
|
|
|
NS_ENSURE_TRUE(argv, NS_ERROR_UNEXPECTED);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
JSString *jsstr = JS_ValueToString(cx, argv[0]);
|
|
|
|
NS_ENSURE_TRUE(jsstr, NS_ERROR_OUT_OF_MEMORY);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-05-19 11:27:30 +00:00
|
|
|
nsDependentString str(NS_REINTERPRET_CAST(const PRUnichar *,
|
2001-05-13 00:27:58 +00:00
|
|
|
::JS_GetStringChars(jsstr)),
|
|
|
|
::JS_GetStringLength(jsstr));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
return WriteCommon(str, aNewlineTerminate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
nsAutoString string_buffer;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
JSString *str = JS_ValueToString(cx, argv[i]);
|
|
|
|
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
string_buffer.Append(NS_REINTERPRET_CAST(const PRUnichar *,
|
|
|
|
::JS_GetStringChars(str)),
|
|
|
|
::JS_GetStringLength(str));
|
1998-07-23 22:06:05 +00:00
|
|
|
}
|
1999-01-06 00:32:41 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
return WriteCommon(string_buffer, aNewlineTerminate);
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
}
|
1999-01-06 00:32:41 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
// No arguments...
|
|
|
|
return WriteCommon(nsString(), aNewlineTerminate);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-13 00:27:58 +00:00
|
|
|
nsHTMLDocument::Write()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2001-05-13 00:27:58 +00:00
|
|
|
return ScriptWriteCommon(PR_FALSE);
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
1998-07-23 22:06:05 +00:00
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Writeln()
|
1999-01-06 00:32:41 +00:00
|
|
|
{
|
2001-05-13 00:27:58 +00:00
|
|
|
return ScriptWriteCommon(PR_TRUE);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
nsIContent *
|
2000-10-04 14:11:19 +00:00
|
|
|
nsHTMLDocument::MatchId(nsIContent *aContent, const nsAReadableString& aId)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
nsresult rv = aContent->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::id,
|
|
|
|
value);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE && aId.Equals(value)) {
|
1998-08-07 23:08:00 +00:00
|
|
|
return aContent;
|
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsIContent *result = nsnull;
|
1998-08-07 23:08:00 +00:00
|
|
|
PRInt32 i, count;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-08-29 20:20:38 +00:00
|
|
|
aContent->ChildCount(count);
|
1998-08-07 23:08:00 +00:00
|
|
|
for (i = 0; i < count && result == nsnull; i++) {
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIContent *child;
|
|
|
|
aContent->ChildAt(i, child);
|
2000-10-04 14:11:19 +00:00
|
|
|
result = MatchId(child, aId);
|
1998-08-07 23:08:00 +00:00
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::GetElementById(const nsAReadableString& aElementId,
|
|
|
|
nsIDOMElement** aReturn)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2000-07-28 21:48:08 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
*aReturn = nsnull;
|
1998-08-07 23:08:00 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aElementId,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
1998-08-07 23:08:00 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsIContent *e = entry->mIdContent;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (e == ID_NOT_IN_DOCUMENT) {
|
|
|
|
// We've looked for this id before and we didn't find it, so it
|
|
|
|
// won't be in the document now either (since the
|
|
|
|
// mIdAndNameHashTable is live for entries in the table)
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
} else if (!e) {
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_WARN_IF_FALSE(!aElementId.IsEmpty(),
|
|
|
|
"getElementById(\"\") called, fix caller?");
|
|
|
|
|
|
|
|
if (mRootContent && !aElementId.IsEmpty()) {
|
|
|
|
e = MatchId(mRootContent, aElementId);
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!e) {
|
|
|
|
// There is no element with the given id in the document, cache
|
|
|
|
// the fact that it's not in the document
|
2002-01-25 06:37:35 +00:00
|
|
|
entry->mIdContent = ID_NOT_IN_DOCUMENT;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found an element with a matching id, store that in the hash
|
2002-01-25 06:37:35 +00:00
|
|
|
entry->mIdContent = e;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
2000-07-28 21:48:08 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
return CallQueryInterface(e, aReturn);
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 17:46:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ImportNode(nsIDOMNode* aImportedNode,
|
|
|
|
PRBool aDeep,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2000-06-21 23:56:52 +00:00
|
|
|
return nsDocument::ImportNode(aImportedNode, aDeep, aReturn);
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::CreateAttributeNS(const nsAReadableString& aNamespaceURI,
|
|
|
|
const nsAReadableString& aQualifiedName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMAttr** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI,
|
|
|
|
const nsAReadableString& aLocalName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
|
|
|
{
|
2000-05-17 03:47:06 +00:00
|
|
|
nsAutoString tmp(aLocalName);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(tmp); // HTML elements are lower case internally.
|
2000-05-17 03:47:06 +00:00
|
|
|
return nsDocument::GetElementsByTagNameNS(aNamespaceURI, tmp,
|
2000-05-16 00:55:05 +00:00
|
|
|
aReturn);
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
PRBool
|
1999-05-04 20:53:44 +00:00
|
|
|
nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, nsString* aData)
|
1999-02-04 23:23:07 +00:00
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
nsresult rv = aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name,
|
|
|
|
name);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && aData && name.Equals(*aData)) {
|
1999-02-04 23:23:07 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetElementsByName(const nsAReadableString& aElementName,
|
1999-02-04 23:23:07 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
nsContentList* elements = new nsContentList(this, MatchNameAttribute,
|
|
|
|
aElementName);
|
|
|
|
NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);
|
2000-08-23 17:27:06 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
*aReturn = elements;
|
|
|
|
NS_ADDREF(*aReturn);
|
1999-02-04 23:23:07 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2001-05-30 11:26:21 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::MatchFormControls(nsIContent* aContent, nsString* aData)
|
|
|
|
{
|
|
|
|
return aContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetFormControlElements(nsIDOMNodeList** aReturn)
|
|
|
|
{
|
|
|
|
nsContentList* elements = nsnull;
|
|
|
|
elements = new nsContentList(this, MatchFormControls, nsString());
|
|
|
|
NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aReturn = elements;
|
|
|
|
NS_ADDREF(*aReturn);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-16 01:04:52 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::GetPixelDimensions(nsIPresShell* aShell,
|
|
|
|
PRInt32* aWidth,
|
|
|
|
PRInt32* aHeight)
|
|
|
|
{
|
|
|
|
*aWidth = *aHeight = 0;
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult result = FlushPendingNotifications();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2000-08-16 01:04:52 +00:00
|
|
|
|
|
|
|
// Find the <body> element: this is what we'll want to use for the
|
|
|
|
// document's width and height values.
|
2001-10-31 23:52:52 +00:00
|
|
|
if (!mBodyContent && PR_FALSE == GetBodyContent()) {
|
2000-08-16 01:04:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> body = do_QueryInterface(mBodyContent);
|
|
|
|
|
|
|
|
// Now grab its frame
|
|
|
|
nsIFrame* frame;
|
|
|
|
result = aShell->GetPrimaryFrameFor(body, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame) {
|
|
|
|
nsSize size;
|
|
|
|
nsIView* view;
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
|
|
|
|
aShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
result = frame->GetView(presContext, &view);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
// If we have a view check if it's scrollable. If not,
|
|
|
|
// just use the view size itself
|
|
|
|
if (view) {
|
2001-03-22 08:51:52 +00:00
|
|
|
nsIScrollableView* scrollableView = nsnull;
|
|
|
|
|
|
|
|
view->QueryInterface(NS_GET_IID(nsIScrollableView),
|
|
|
|
(void**)&scrollableView);
|
|
|
|
|
|
|
|
if (scrollableView) {
|
2000-08-16 01:04:52 +00:00
|
|
|
scrollableView->GetScrolledView(view);
|
|
|
|
}
|
|
|
|
|
2001-12-01 14:31:45 +00:00
|
|
|
nsRect r;
|
|
|
|
result = view->GetBounds(r);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
size.height = r.height;
|
|
|
|
size.width = r.width;
|
|
|
|
}
|
2000-08-16 01:04:52 +00:00
|
|
|
}
|
|
|
|
// If we don't have a view, use the frame size
|
|
|
|
else {
|
|
|
|
result = frame->GetSize(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from twips to pixels
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
|
|
|
|
result = aShell->GetPresContext(getter_AddRefs(context));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
float scale;
|
|
|
|
context->GetTwipsToPixels(&scale);
|
|
|
|
|
|
|
|
*aWidth = NSTwipsToIntPixels(size.width, scale);
|
|
|
|
*aHeight = NSTwipsToIntPixels(size.height, scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetWidth(PRInt32* aWidth)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
2002-02-05 05:47:22 +00:00
|
|
|
*aWidth = 0;
|
2001-10-31 23:52:52 +00:00
|
|
|
|
2000-08-16 01:04:52 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
|
|
|
|
// We make the assumption that the first presentation shell
|
|
|
|
// is the one for which we need information.
|
2001-06-20 03:27:48 +00:00
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2002-02-05 05:47:22 +00:00
|
|
|
if (!shell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
PRInt32 dummy;
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
// GetPixelDimensions() does the flushing for us, no need to flush
|
|
|
|
// here too
|
|
|
|
return GetPixelDimensions(shell, aWidth, &dummy);
|
2000-08-16 01:04:52 +00:00
|
|
|
}
|
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-16 01:04:52 +00:00
|
|
|
nsHTMLDocument::GetHeight(PRInt32* aHeight)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
2002-02-05 05:47:22 +00:00
|
|
|
*aHeight = 0;
|
2001-10-31 23:52:52 +00:00
|
|
|
|
2000-08-16 01:04:52 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
|
|
|
|
// We make the assumption that the first presentation shell
|
|
|
|
// is the one for which we need information.
|
2001-06-20 03:27:48 +00:00
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2002-02-05 05:47:22 +00:00
|
|
|
if (!shell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
PRInt32 dummy;
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2002-02-05 05:47:22 +00:00
|
|
|
// GetPixelDimensions() does the flushing for us, no need to flush
|
|
|
|
// here too
|
|
|
|
return GetPixelDimensions(shell, &dummy, aHeight);
|
2000-08-16 01:04:52 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetAlinkColor(nsAWritableString& aAlinkColor)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
aAlinkColor.Truncate();
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
result = body->GetALink(aAlinkColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nscolor color;
|
|
|
|
result = mAttrStyleSheet->GetActiveLinkColor(color);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsHTMLValue value(color);
|
|
|
|
nsGenericHTMLElement::ColorToString(value, aAlinkColor);
|
|
|
|
}
|
|
|
|
}
|
1999-02-04 02:58:02 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetAlinkColor(const nsAReadableString& aAlinkColor)
|
1998-08-04 00:05:22 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
result = body->SetALink(aAlinkColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nsHTMLValue value;
|
|
|
|
|
1999-07-18 00:22:29 +00:00
|
|
|
if (nsGenericHTMLElement::ParseColor(aAlinkColor, this, value)) {
|
1999-07-07 04:52:27 +00:00
|
|
|
mAttrStyleSheet->SetActiveLinkColor(value.GetColorValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetLinkColor(nsAWritableString& aLinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
aLinkColor.Truncate();
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
result = body->GetLink(aLinkColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nscolor color;
|
|
|
|
result = mAttrStyleSheet->GetLinkColor(color);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsHTMLValue value(color);
|
|
|
|
nsGenericHTMLElement::ColorToString(value, aLinkColor);
|
|
|
|
}
|
|
|
|
}
|
1999-02-04 02:58:02 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetLinkColor(const nsAReadableString& aLinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
result = body->SetLink(aLinkColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nsHTMLValue value;
|
1999-07-18 00:22:29 +00:00
|
|
|
if (nsGenericHTMLElement::ParseColor(aLinkColor, this, value)) {
|
1999-07-07 04:52:27 +00:00
|
|
|
mAttrStyleSheet->SetLinkColor(value.GetColorValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetVlinkColor(nsAWritableString& aVlinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
aVlinkColor.Truncate();
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
1999-07-08 19:55:47 +00:00
|
|
|
result = body->GetVLink(aVlinkColor);
|
1999-02-04 02:58:02 +00:00
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nscolor color;
|
|
|
|
result = mAttrStyleSheet->GetVisitedLinkColor(color);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsHTMLValue value(color);
|
|
|
|
nsGenericHTMLElement::ColorToString(value, aVlinkColor);
|
|
|
|
}
|
|
|
|
}
|
1999-02-04 02:58:02 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetVlinkColor(const nsAReadableString& aVlinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
1999-02-04 02:58:02 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
result = body->SetVLink(aVlinkColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
1999-07-07 04:52:27 +00:00
|
|
|
else if (nsnull != mAttrStyleSheet) {
|
|
|
|
nsHTMLValue value;
|
1999-07-18 00:22:29 +00:00
|
|
|
if (nsGenericHTMLElement::ParseColor(aVlinkColor, this, value)) {
|
1999-07-07 04:52:27 +00:00
|
|
|
mAttrStyleSheet->SetVisitedLinkColor(value.GetColorValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetBgColor(nsAWritableString& aBgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
aBgColor.Truncate();
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
2002-01-07 23:46:07 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-02-04 02:58:02 +00:00
|
|
|
result = body->GetBgColor(aBgColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetBgColor(const nsAReadableString& aBgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
2002-01-07 23:46:07 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-02-04 02:58:02 +00:00
|
|
|
result = body->SetBgColor(aBgColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
// XXXldb And otherwise?
|
1999-07-07 04:52:27 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetFgColor(nsAWritableString& aFgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
aFgColor.Truncate();
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
2002-01-07 23:46:07 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-02-04 02:58:02 +00:00
|
|
|
result = body->GetText(aFgColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::SetFgColor(const nsAReadableString& aFgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-02-04 02:58:02 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLBodyElement* body;
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
result = GetBodyElement(&body);
|
2002-01-07 23:46:07 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-02-04 02:58:02 +00:00
|
|
|
result = body->SetText(aFgColor);
|
|
|
|
NS_RELEASE(body);
|
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
// XXXldb And otherwise?
|
1999-07-07 04:52:27 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetLastModified(nsAWritableString& aLastModified)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-08-09 19:10:24 +00:00
|
|
|
if (nsnull != mLastModified) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aLastModified.Assign(*mLastModified);
|
1999-08-09 19:10:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-08-23 17:27:06 +00:00
|
|
|
aLastModified.Assign(NS_LITERAL_STRING("January 1, 1970 GMT"));
|
1999-08-09 19:10:24 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 23:39:25 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
|
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mEmbeds) {
|
|
|
|
mEmbeds = new nsContentList(this, nsHTMLAtoms::embed,
|
|
|
|
kNameSpaceID_Unknown);
|
|
|
|
NS_ENSURE_TRUE(mEmbeds, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
1998-09-25 00:51:45 +00:00
|
|
|
NS_ADDREF(mEmbeds);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aEmbeds = (nsIDOMHTMLCollection *)mEmbeds;
|
|
|
|
NS_ADDREF(mEmbeds);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsHTMLDocument::GetSelection(nsAWritableString& aReturn)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-06-28 23:39:25 +00:00
|
|
|
aReturn.Truncate();
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
nsCOMPtr<nsIConsoleService> consoleService
|
|
|
|
(do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
|
|
|
|
if (consoleService) {
|
|
|
|
consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get());
|
|
|
|
}
|
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
nsIPresShell* shell = (nsIPresShell*)mPresShells.SafeElementAt(0);
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
if (!shell) {
|
2000-04-28 14:05:45 +00:00
|
|
|
return NS_OK;
|
2001-01-23 07:45:08 +00:00
|
|
|
}
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
|
|
|
NS_ENSURE_TRUE(cx, NS_OK);
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
nsCOMPtr<nsISupports> container;
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
cx->GetContainer(getter_AddRefs(container));
|
|
|
|
NS_ENSURE_TRUE(container, NS_OK);
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window(do_GetInterface(container));
|
|
|
|
NS_ENSURE_TRUE(window, NS_OK);
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
|
|
|
|
nsresult rv = window->GetSelection(getter_AddRefs(selection));
|
|
|
|
NS_ENSURE_TRUE(selection && NS_SUCCEEDED(rv), rv);
|
|
|
|
|
|
|
|
nsXPIDLString str;
|
|
|
|
|
|
|
|
rv = selection->ToString(getter_Copies(str));
|
|
|
|
|
|
|
|
aReturn.Assign(str);
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2000-09-14 11:45:01 +00:00
|
|
|
return rv;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 14:18:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CaptureEvents(PRInt32 aEventFlags)
|
|
|
|
{
|
|
|
|
nsIEventListenerManager *manager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&manager)) {
|
2000-02-16 06:59:07 +00:00
|
|
|
manager->CaptureEvent(aEventFlags);
|
1999-09-21 14:18:52 +00:00
|
|
|
NS_RELEASE(manager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-16 06:59:07 +00:00
|
|
|
|
1999-09-21 14:18:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ReleaseEvents(PRInt32 aEventFlags)
|
|
|
|
{
|
2000-02-16 06:59:07 +00:00
|
|
|
nsIEventListenerManager *manager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&manager)) {
|
|
|
|
manager->ReleaseEvent(aEventFlags);
|
|
|
|
NS_RELEASE(manager);
|
1999-09-21 14:18:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-16 06:59:07 +00:00
|
|
|
|
1999-09-21 14:18:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::RouteEvent(nsIDOMEvent* aEvt)
|
|
|
|
{
|
|
|
|
//XXX Not the best solution -joki
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-10 07:36:19 +00:00
|
|
|
// readonly attribute DOMString compatMode;
|
|
|
|
// Returns "BackCompat" if we are in quirks mode,
|
|
|
|
// "CSS1Compat" if we are in strict mode. See bug 105640.
|
|
|
|
// This was implemented to match MSIE's compatMode property
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetCompatMode(nsAWritableString& aCompatMode)
|
|
|
|
{
|
|
|
|
aCompatMode.Truncate();
|
|
|
|
NS_ASSERTION((mDTDMode == eDTDMode_quirks) || (mDTDMode == eDTDMode_strict),
|
|
|
|
"mDTDMode is neither quirks nor strict for this document");
|
|
|
|
|
|
|
|
if (mDTDMode == eDTDMode_quirks) {
|
|
|
|
aCompatMode.Assign(NS_LITERAL_STRING("BackCompat"));
|
|
|
|
} else {
|
|
|
|
aCompatMode.Assign(NS_LITERAL_STRING("CSS1Compat"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
IdAndNameMapEntryRemoveCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
|
|
|
{
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
void
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::InvalidateHashTables()
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHashTableEnumerate(&mIdAndNameHashTable, IdAndNameMapEntryRemoveCallback,
|
|
|
|
nsnull);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
2002-01-25 06:37:35 +00:00
|
|
|
AddEmptyListToHash(const nsAString& aName, PLDHashTable *aHash)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
|
|
|
nsBaseContentList *list = new nsBaseContentList();
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
NS_ADDREF(list);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(aHash, &aName, PL_DHASH_ADD));
|
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
NS_RELEASE(list);
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
entry->mContentList = list;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pre-fill the name hash with names that are likely to be resolved in
|
|
|
|
// this document to avoid walking the tree looking for elements with
|
|
|
|
// these names.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::PrePopulateHashTables()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("write"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("writeln"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("open"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("close"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("forms"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("elements"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("characterSet"),
|
|
|
|
&mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("nodeType"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("parentNode"),
|
|
|
|
&mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
rv = AddEmptyListToHash(NS_LITERAL_STRING("cookie"), &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return rv;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
static PRBool
|
2001-03-22 08:51:52 +00:00
|
|
|
IsNamedItem(nsIContent* aContent, nsIAtom *aTag, nsAWritableString& aName)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
|
|
|
// Only the content types reflected in Level 0 with a NAME
|
1999-05-17 21:17:48 +00:00
|
|
|
// attribute are registered. Images, layers and forms always get
|
1998-08-07 23:08:00 +00:00
|
|
|
// reflected up to the document. Applets and embeds only go
|
|
|
|
// to the closest container (which could be a form).
|
2002-01-25 06:37:35 +00:00
|
|
|
if (aTag == nsHTMLAtoms::img ||
|
|
|
|
aTag == nsHTMLAtoms::form ||
|
|
|
|
aTag == nsHTMLAtoms::applet ||
|
|
|
|
aTag == nsHTMLAtoms::embed ||
|
|
|
|
aTag == nsHTMLAtoms::object) {
|
2001-08-17 08:14:14 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, aName);
|
1998-08-07 23:08:00 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!aName.IsEmpty()) {
|
1999-05-17 21:17:48 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult
|
2002-01-25 06:37:35 +00:00
|
|
|
nsHTMLDocument::UpdateNameTableEntry(const nsAString& aName,
|
|
|
|
nsIContent *aContent)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aName,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (!PL_DHASH_ENTRY_IS_LIVE(entry)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsBaseContentList *list = entry->mContentList;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
list->IndexOf(aContent, i);
|
|
|
|
|
|
|
|
if (i < 0) {
|
|
|
|
list->AppendElement(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-25 06:37:35 +00:00
|
|
|
nsHTMLDocument::AddToIdTable(const nsAString& aId, nsIContent *aContent)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aId,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
const nsIContent *e = entry->mIdContent;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (!e || e == ID_NOT_IN_DOCUMENT) {
|
|
|
|
entry->mIdContent = aContent;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-25 06:37:35 +00:00
|
|
|
nsHTMLDocument::UpdateIdTableEntry(const nsAString& aId, nsIContent *aContent)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aId,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_LIVE(entry)) {
|
|
|
|
entry->mIdContent = aContent;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::RemoveFromNameTable(const nsAString& aName,
|
|
|
|
nsIContent *aContent)
|
|
|
|
{
|
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aName,
|
|
|
|
PL_DHASH_LOOKUP));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (PL_DHASH_ENTRY_IS_LIVE(entry) && entry->mContentList) {
|
|
|
|
entry->mContentList->RemoveElement(aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::RemoveFromIdTable(nsIContent *aContent)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
if (!aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::id)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (value.IsEmpty()) {
|
|
|
|
return NS_OK;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable,
|
|
|
|
NS_STATIC_CAST(const nsAString *,
|
|
|
|
&value),
|
|
|
|
PL_DHASH_LOOKUP));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (!PL_DHASH_ENTRY_IS_LIVE(entry) || entry->mIdContent != aContent) {
|
2001-03-22 08:51:52 +00:00
|
|
|
return NS_OK;
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHashTableRawRemove(&mIdAndNameHashTable, entry);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::UnregisterNamedItems(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (tag == nsLayoutAtoms::textTagName) {
|
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (IsNamedItem(aContent, tag, value)) {
|
|
|
|
rv = RemoveFromNameTable(value, aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = RemoveFromIdTable(aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 i, count;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
aContent->ChildCount(count);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
nsIContent *child;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
aContent->ChildAt(i, child);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
UnregisterNamedItems(child);
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
NS_RELEASE(child);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::RegisterNamedItems(nsIContent *aContent)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (tag == nsLayoutAtoms::textTagName) {
|
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (IsNamedItem(aContent, tag, value)) {
|
2002-01-25 06:37:35 +00:00
|
|
|
UpdateNameTableEntry(value, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!value.IsEmpty()) {
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = UpdateIdTableEntry(value, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
PRInt32 i, count;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-08-29 20:20:38 +00:00
|
|
|
aContent->ChildCount(count);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIContent *child;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-08-29 20:20:38 +00:00
|
|
|
aContent->ChildAt(i, child);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
RegisterNamedItems(child);
|
|
|
|
|
1998-08-07 23:08:00 +00:00
|
|
|
NS_RELEASE(child);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
static void
|
|
|
|
FindNamedItems(const nsAReadableString& aName, nsIContent *aContent,
|
|
|
|
IdAndNameMapEntry& aEntry)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_ASSERTION(aEntry.mContentList,
|
|
|
|
"Entry w/o content list passed to FindNamedItems()!");
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2001-03-22 08:51:52 +00:00
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
|
|
|
if (tag == nsLayoutAtoms::textTagName) {
|
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
if (IsNamedItem(aContent, tag, value) && value.Equals(aName)) {
|
2002-01-25 06:37:35 +00:00
|
|
|
aEntry.mContentList->AppendElement(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aEntry.mIdContent) {
|
2001-08-17 08:14:14 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (value.Equals(aName)) {
|
2002-01-25 06:37:35 +00:00
|
|
|
aEntry.mIdContent = aContent;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i, count;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
aContent->ChildCount(count);
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
aContent->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
FindNamedItems(aName, child, aEntry);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ResolveName(const nsAReadableString& aName,
|
|
|
|
nsIDOMHTMLFormElement *aForm,
|
|
|
|
nsISupports **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
// Bug 69826 - Make sure to flush the content model if the document
|
|
|
|
// is still loading.
|
|
|
|
|
|
|
|
// This is a perf killer while the document is loading!
|
|
|
|
FlushPendingNotifications(PR_FALSE);
|
|
|
|
|
|
|
|
// We have built a table and cache the named items. The table will
|
|
|
|
// be updated as content is added and removed.
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
|
|
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aName,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsBaseContentList *list = entry->mContentList;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
#ifdef DEBUG_jst
|
|
|
|
{
|
|
|
|
printf ("nsHTMLDocument name cache miss for name '%s'\n",
|
|
|
|
NS_ConvertUCS2toUTF8(aName).get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
list = new nsBaseContentList();
|
|
|
|
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
entry->mContentList = list;
|
|
|
|
NS_ADDREF(entry->mContentList);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if(mRootContent && !aName.IsEmpty()) {
|
|
|
|
FindNamedItems(aName, mRootContent, *entry);
|
2001-07-17 13:53:15 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
list->GetLength(&length);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (length) {
|
|
|
|
if (length == 1) {
|
|
|
|
// Onle one element in the list, return the list in stead of
|
|
|
|
// returning the list
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
list->Item(0, getter_AddRefs(node));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (aForm && node) {
|
|
|
|
// document.forms["foo"].bar should not map to <form
|
|
|
|
// name="bar"> so we check here to see if we found a form and
|
|
|
|
// if we did we ignore what we found in the document. This
|
|
|
|
// doesn't deal with the case where more than one element in
|
|
|
|
// found in the document (i.e. there are two named items in
|
|
|
|
// the document that have the name we're looking for), that
|
|
|
|
// case is dealt with in nsFormContentList
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> f(do_QueryInterface(node));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (f) {
|
|
|
|
node = nsnull;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
*aResult = node;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (length > 1) {
|
|
|
|
// The list contains more than one element, return the whole
|
|
|
|
// list, unless...
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (aForm) {
|
|
|
|
// ... we're called from a form, in that case we create a
|
|
|
|
// nsFormContentList which will filter out the elements in the
|
|
|
|
// list that don't belong to aForm
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsFormContentList *fc_list = new nsFormContentList(aForm, *list);
|
|
|
|
NS_ENSURE_TRUE(fc_list, NS_ERROR_OUT_OF_MEMORY);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
PRUint32 len;
|
|
|
|
fc_list->GetLength(&len);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (len < 2) {
|
|
|
|
// After t nsFormContentList is done filtering there's zero
|
|
|
|
// or one element in the list, return that element, or null
|
|
|
|
// if there's no element in the list.
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
fc_list->Item(0, getter_AddRefs(node));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
*aResult = node;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
delete fc_list;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
list = fc_list;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return list->QueryInterface(NS_GET_IID(nsISupports), (void **)aResult);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
// No named items were found, see if there's one registerd by id for
|
|
|
|
// aName. If we get this far, FindNamedItems() will have been called
|
|
|
|
// for aName, so we're guaranteed that if there is an element with
|
|
|
|
// the id aName, it'll be in entry->mIdContent.
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsIContent *e = entry->mIdContent;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (e && e != ID_NOT_IN_DOCUMENT) {
|
2001-03-22 08:51:52 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
e->GetTag(*getter_AddRefs(tag));
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
if (tag == nsHTMLAtoms::embed ||
|
|
|
|
tag == nsHTMLAtoms::img ||
|
|
|
|
tag == nsHTMLAtoms::object ||
|
|
|
|
tag == nsHTMLAtoms::applet) {
|
2001-03-22 08:51:52 +00:00
|
|
|
*aResult = e;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 15:55:31 +00:00
|
|
|
//----------------------------
|
1998-09-04 15:41:20 +00:00
|
|
|
|
1998-11-12 22:25:51 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::GetBodyContent()
|
|
|
|
{
|
2000-12-14 22:37:22 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> root;
|
|
|
|
|
|
|
|
GetDocumentElement(getter_AddRefs(root));
|
|
|
|
|
|
|
|
if (!root) {
|
1998-11-12 22:25:51 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-09-04 15:41:20 +00:00
|
|
|
|
2001-12-16 11:58:03 +00:00
|
|
|
nsAutoString bodyStr(NS_LITERAL_STRING("BODY"));
|
2000-12-14 22:37:22 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
root->GetFirstChild(getter_AddRefs(child));
|
1998-11-12 22:25:51 +00:00
|
|
|
|
2000-12-14 22:37:22 +00:00
|
|
|
while (child) {
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(child));
|
|
|
|
|
|
|
|
if (domElement) {
|
|
|
|
nsAutoString tagName;
|
1998-11-12 22:25:51 +00:00
|
|
|
domElement->GetTagName(tagName);
|
2000-12-14 22:37:22 +00:00
|
|
|
|
1998-11-12 22:25:51 +00:00
|
|
|
if (bodyStr.EqualsIgnoreCase(tagName)) {
|
|
|
|
mBodyContent = child;
|
2001-11-01 00:58:28 +00:00
|
|
|
|
1998-11-12 22:25:51 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 22:37:22 +00:00
|
|
|
nsIDOMNode *tmpNode = child;
|
|
|
|
tmpNode->GetNextSibling(getter_AddRefs(child));
|
1998-11-12 22:25:51 +00:00
|
|
|
}
|
2000-12-14 22:37:22 +00:00
|
|
|
|
1998-11-12 22:25:51 +00:00
|
|
|
return PR_FALSE;
|
1998-08-28 15:55:31 +00:00
|
|
|
}
|
|
|
|
|
2001-08-02 14:34:55 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-04 23:23:07 +00:00
|
|
|
nsHTMLDocument::GetBodyElement(nsIDOMHTMLBodyElement** aBody)
|
|
|
|
{
|
2001-10-31 23:52:52 +00:00
|
|
|
if (!mBodyContent && PR_FALSE == GetBodyContent()) {
|
1999-02-04 23:23:07 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-09-09 05:46:14 +00:00
|
|
|
return mBodyContent->QueryInterface(NS_GET_IID(nsIDOMHTMLBodyElement),
|
1999-02-04 23:23:07 +00:00
|
|
|
(void**)aBody);
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// forms related stuff
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms)
|
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mForms) {
|
2000-05-17 20:35:19 +00:00
|
|
|
mForms = new nsContentList(this, nsHTMLAtoms::form, kNameSpaceID_Unknown);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_TRUE(mForms, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
1998-10-21 09:26:33 +00:00
|
|
|
NS_ADDREF(mForms);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aForms = (nsIDOMHTMLCollection *)mForms;
|
|
|
|
NS_ADDREF(mForms);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-25 08:49:03 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-01-31 19:36:45 +00:00
|
|
|
nsHTMLDocument::CreateAndAddWyciwygChannel(void)
|
2001-05-25 08:49:03 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-01-31 19:36:45 +00:00
|
|
|
nsAutoString url;
|
|
|
|
nsXPIDLCString originalSpec, urlPart;
|
|
|
|
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
mDocumentURL->GetSpec(getter_Copies(originalSpec));
|
|
|
|
nsCOMPtr<nsIIOService> ioService(do_GetService("@mozilla.org/network/io-service;1", &rv));
|
|
|
|
if (ioService) {
|
|
|
|
ioService->ExtractUrlPart(originalSpec.get(), nsIIOService::url_Path, 0, 0, getter_Copies(urlPart));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the wyciwyg url
|
|
|
|
url.AssignWithConversion( "wyciwyg://" );
|
|
|
|
url.AppendInt(mWyciwygSessionCnt++, 10);
|
|
|
|
url.AppendWithConversion("/");
|
|
|
|
url.AppendWithConversion(urlPart);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> wcwgURI;
|
|
|
|
NS_NewURI(getter_AddRefs(wcwgURI), url);
|
|
|
|
|
|
|
|
// Create the nsIWyciwygChannel to store
|
|
|
|
// out-of-band document.write() script to cache
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
// Create a wyciwyg Channel
|
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel), wcwgURI);
|
|
|
|
if (NS_SUCCEEDED(rv) && channel) {
|
|
|
|
mWyciwygChannel = do_QueryInterface(channel);
|
|
|
|
mWyciwygChannel->CreateCacheEntry(NS_ConvertUCS2toUTF8(url).get());
|
|
|
|
}
|
2001-05-25 08:49:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
|
|
|
|
rv = GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
// Use the Parent document's loadgroup to trigger load notifications
|
|
|
|
if (loadGroup && channel) {
|
2001-05-25 08:49:03 +00:00
|
|
|
rv = channel->SetLoadGroup(loadGroup);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
channel->GetLoadFlags(&loadFlags);
|
|
|
|
loadFlags |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
channel->SetLoadFlags(loadFlags);
|
2002-01-31 19:36:45 +00:00
|
|
|
|
|
|
|
channel->SetOriginalURI(wcwgURI);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
rv = loadGroup->AddRequest(mWyciwygChannel, nsnull);
|
2001-05-25 08:49:03 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-31 19:36:45 +00:00
|
|
|
nsHTMLDocument::RemoveWyciwygChannel(void)
|
2001-05-25 08:49:03 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
rv = GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-11-16 02:03:19 +00:00
|
|
|
// note there can be a write request without a load group if
|
|
|
|
// this is a synchronously constructed about:blank document
|
2002-01-31 19:36:45 +00:00
|
|
|
if (loadGroup && mWyciwygChannel) {
|
|
|
|
mWyciwygChannel->CloseCacheEntry();
|
|
|
|
rv = loadGroup->RemoveRequest(mWyciwygChannel, nsnull, NS_OK);
|
2001-05-25 08:49:03 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2002-01-31 19:36:45 +00:00
|
|
|
mWyciwygChannel = nsnull;
|
2001-05-25 08:49:03 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|