2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-06-07 19:21:05 +00:00
|
|
|
/* vim: set sw=2 ts=2 et tw=80: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
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>
|
2002-11-11 20:19:37 +00:00
|
|
|
* Kathleen Brade <brade@netscape.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-24 07:38:00 +00:00
|
|
|
#include "nsICharsetAlias.h"
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-08-09 19:10:24 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsPrintfCString.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"
|
2003-04-19 00:28:09 +00:00
|
|
|
#include "nsIXMLContentSink.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsHTMLParts.h"
|
2004-04-12 21:56:09 +00:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2003-03-26 07:41:30 +00:00
|
|
|
#include "nsIPresShell.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.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"
|
2003-03-26 07:41:30 +00:00
|
|
|
#include "nsIDOMComment.h"
|
2000-03-22 22:16:14 +00:00
|
|
|
#include "nsIDOMDOMImplementation.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2005-08-12 04:11:00 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2004-04-01 19:44:17 +00:00
|
|
|
#include "nsDOMString.h"
|
1998-07-01 11:16:09 +00:00
|
|
|
#include "nsIStreamListener.h"
|
2002-10-30 04:57:15 +00:00
|
|
|
#include "nsIURI.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.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"
|
2000-03-11 00:35:36 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2007-07-03 21:41:32 +00:00
|
|
|
#include "nsDocShellLoadTypes.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"
|
2002-04-18 22:49:39 +00:00
|
|
|
#include "nsIScriptContext.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"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsIPrincipal.h"
|
1999-10-02 03:41:37 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2005-12-28 21:52:39 +00:00
|
|
|
#include "nsAttrName.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2003-10-30 02:59:31 +00:00
|
|
|
#include "nsNetCID.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"
|
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"
|
2006-04-26 01:57:22 +00:00
|
|
|
#include "nsFrameSelection.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"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2004-04-13 03:21:50 +00:00
|
|
|
#include "nsJSUtils.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
|
2003-05-29 22:11:23 +00:00
|
|
|
#include "nsICharsetResolver.h"
|
2001-04-27 02:26:32 +00:00
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsICacheEntryDescriptor.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 "nsIJSContextStack.h"
|
2001-05-25 08:49:03 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
2002-01-31 19:36:45 +00:00
|
|
|
#include "nsIWyciwygChannel.h"
|
2006-01-24 01:25:14 +00:00
|
|
|
#include "nsIScriptElement.h"
|
2006-04-10 17:04:54 +00:00
|
|
|
#include "nsIScriptError.h"
|
2006-04-12 15:43:32 +00:00
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsArrayUtils.h"
|
2007-04-25 20:48:28 +00:00
|
|
|
#include "nsIEffectiveTLDService.h"
|
2007-06-28 02:48:16 +00:00
|
|
|
#include "nsIEventStateManager.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-03-29 02:11:48 +00:00
|
|
|
#include "nsIPrompt.h"
|
2003-03-26 07:41:30 +00:00
|
|
|
//AHMED 12-2
|
2002-02-19 20:41:32 +00:00
|
|
|
#include "nsBidiUtils.h"
|
2000-05-13 08:11:29 +00:00
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
#include "nsIEditingSession.h"
|
2006-08-18 02:38:40 +00:00
|
|
|
#include "nsIEditor.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2007-06-28 02:48:16 +00:00
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorDocShell.h"
|
|
|
|
#include "nsIEditorStyleSheets.h"
|
|
|
|
#include "nsIInlineSpellChecker.h"
|
|
|
|
#include "nsRange.h"
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2007-02-11 00:30:20 +00:00
|
|
|
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
|
|
|
|
|
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;
|
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
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
// Entries in an nsSmallVoidArray must not have the low bit set, so
|
|
|
|
// can't use "1" for ID_NOT_IN_DOCUMENT. "2" should be a perfectly
|
|
|
|
// reasonable value, though -- no real nsIContent* will be equal to 2.
|
|
|
|
#define ID_NOT_IN_DOCUMENT ((nsIContent *)2)
|
2004-05-07 20:02:40 +00:00
|
|
|
#define NAME_NOT_VALID ((nsBaseContentList*)1)
|
2000-09-09 05:46:14 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
// Returns the name atom of aContent, if the content is a named item
|
|
|
|
// and has a name atom.
|
|
|
|
static nsIAtom* IsNamedItem(nsIContent* aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2001-03-10 21:02:12 +00:00
|
|
|
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
|
|
|
|
2003-05-28 22:12:16 +00:00
|
|
|
PRUint32 nsHTMLDocument::gWyciwygSessionCnt = 0;
|
1998-10-06 01:39:33 +00:00
|
|
|
|
2008-01-14 09:26:22 +00:00
|
|
|
// this function will return false if the command is not recognized
|
|
|
|
// inCommandID will be converted as necessary for internal operations
|
|
|
|
// inParam will be converted as necessary for internal operations
|
|
|
|
// outParam will be Empty if no parameter is needed or if returning a boolean
|
|
|
|
// outIsBoolean will determine whether to send param as a boolean or string
|
|
|
|
// outBooleanParam will not be set unless outIsBoolean
|
|
|
|
static PRBool ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
const nsAString & inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
|
|
|
PRBool& isBoolean,
|
|
|
|
PRBool& boolValue);
|
|
|
|
|
|
|
|
static PRBool ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
nsACString& outCommandID);
|
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)
|
|
|
|
{
|
2004-04-29 23:34:19 +00:00
|
|
|
const nsAdoptingString& detector_name =
|
|
|
|
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (detector_name.Length() > 0) {
|
|
|
|
PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,
|
|
|
|
DETECTOR_CONTRACTID_MAX);
|
|
|
|
PL_strncat(g_detector_contractid,
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertUTF16toUTF8(detector_name).get(),
|
2003-03-26 07:41:30 +00:00
|
|
|
DETECTOR_CONTRACTID_MAX);
|
|
|
|
gPlugDetector = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
g_detector_contractid[0]=0;
|
|
|
|
gPlugDetector = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1999-09-23 02:10:15 +00:00
|
|
|
}
|
2000-08-16 23:16:21 +00:00
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
// ==================================================================
|
|
|
|
// =
|
|
|
|
// ==================================================================
|
2003-03-05 15:08:41 +00:00
|
|
|
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);
|
|
|
|
|
2005-04-28 17:16:19 +00:00
|
|
|
NS_ADDREF(doc);
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-04-28 17:16:19 +00:00
|
|
|
NS_RELEASE(doc);
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = doc;
|
|
|
|
|
2005-04-28 17:16:19 +00:00
|
|
|
return rv;
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class IdAndNameMapEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
2005-11-16 02:55:29 +00:00
|
|
|
IdAndNameMapEntry(nsIAtom* aKey) :
|
|
|
|
mKey(aKey), mNameContentList(nsnull), mIdContentList()
|
2002-01-25 06:37:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~IdAndNameMapEntry()
|
|
|
|
{
|
2005-11-09 21:52:06 +00:00
|
|
|
if (mNameContentList && mNameContentList != NAME_NOT_VALID) {
|
|
|
|
NS_RELEASE(mNameContentList);
|
2004-05-07 20:02:40 +00:00
|
|
|
}
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
nsIContent* GetIdContent() {
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsIContent*>(mIdContentList.SafeElementAt(0));
|
2005-11-09 21:52:06 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 22:05:03 +00:00
|
|
|
PRBool AddIdContent(nsIContent* aContent);
|
2005-11-09 21:52:06 +00:00
|
|
|
|
|
|
|
PRBool RemoveIdContent(nsIContent* aContent) {
|
|
|
|
// XXXbz should this ever Compact() I guess when all the content is gone
|
|
|
|
// we'll just get cleaned up in the natural order of things...
|
|
|
|
return mIdContentList.RemoveElement(aContent) &&
|
|
|
|
mIdContentList.Count() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlagIDNotInDocument() {
|
|
|
|
NS_ASSERTION(mIdContentList.Count() == 0,
|
|
|
|
"Flagging ID not in document when we have content?");
|
|
|
|
// Note that if this fails that's OK; this is just an optimization
|
|
|
|
mIdContentList.AppendElement(ID_NOT_IN_DOCUMENT);
|
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsCOMPtr<nsIAtom> mKey;
|
2005-11-09 21:52:06 +00:00
|
|
|
nsBaseContentList *mNameContentList;
|
2007-07-26 00:36:19 +00:00
|
|
|
nsRefPtr<nsContentList> mDocAllList;
|
2005-11-09 21:52:06 +00:00
|
|
|
private:
|
|
|
|
nsSmallVoidArray mIdContentList;
|
2002-01-25 06:37:35 +00:00
|
|
|
};
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
PRBool
|
2005-11-14 22:05:03 +00:00
|
|
|
IdAndNameMapEntry::AddIdContent(nsIContent* aContent)
|
2005-11-09 21:52:06 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "Must have content");
|
|
|
|
NS_PRECONDITION(mIdContentList.IndexOf(nsnull) == -1,
|
|
|
|
"Why is null in our list?");
|
|
|
|
NS_PRECONDITION(aContent != ID_NOT_IN_DOCUMENT,
|
|
|
|
"Bogus content pointer");
|
|
|
|
|
|
|
|
if (GetIdContent() == ID_NOT_IN_DOCUMENT) {
|
|
|
|
NS_ASSERTION(mIdContentList.Count() == 1, "Bogus count");
|
|
|
|
return mIdContentList.ReplaceElementAt(aContent, 0);
|
|
|
|
}
|
|
|
|
|
2007-11-22 02:28:47 +00:00
|
|
|
// Common case
|
|
|
|
if (mIdContentList.Count() == 0) {
|
|
|
|
return mIdContentList.AppendElement(aContent);
|
2005-11-09 21:52:06 +00:00
|
|
|
}
|
2007-11-22 02:28:47 +00:00
|
|
|
|
|
|
|
// We seem to have multiple content nodes for the same id, or we're doing our
|
|
|
|
// top-down registration when the id table is going live. Search for the
|
|
|
|
// right place to insert the content.
|
|
|
|
PRInt32 start = 0;
|
|
|
|
PRInt32 end = mIdContentList.Count();
|
|
|
|
do {
|
|
|
|
NS_ASSERTION(start < end, "Bogus start/end");
|
2005-11-09 21:52:06 +00:00
|
|
|
|
2007-11-22 02:28:47 +00:00
|
|
|
PRInt32 cur = (start + end) / 2;
|
|
|
|
NS_ASSERTION(cur >= start && cur < end, "What happened here?");
|
|
|
|
|
|
|
|
nsIContent* curContent = static_cast<nsIContent*>(mIdContentList[cur]);
|
|
|
|
if (curContent == aContent) {
|
|
|
|
// Already in the list, so already in the right spot. Get out of here.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsContentUtils::PositionIsBefore(aContent, curContent)) {
|
|
|
|
end = cur;
|
|
|
|
} else {
|
|
|
|
start = cur + 1;
|
|
|
|
}
|
|
|
|
} while (start != end);
|
|
|
|
|
|
|
|
return mIdContentList.InsertElementAt(aContent, start);
|
2005-11-09 21:52:06 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashNumber)
|
|
|
|
IdAndNameHashHashKey(PLDHashTable *table, const void *key)
|
|
|
|
{
|
2005-11-16 02:55:29 +00:00
|
|
|
// Our key is an nsIAtom*, so just shift it and use that as the hash.
|
|
|
|
return NS_PTR_TO_INT32(key) >> 2;
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
|
|
|
IdAndNameHashMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const IdAndNameMapEntry *e =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<const IdAndNameMapEntry *>(entry);
|
|
|
|
const nsIAtom *atom = static_cast<const nsIAtom *>(key);
|
2002-01-25 06:37:35 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
return atom == e->mKey;
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
IdAndNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
IdAndNameMapEntry *e = static_cast<IdAndNameMapEntry *>(entry);
|
2002-01-25 06:37:35 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// An entry is being cleared, let the entry do its own cleanup.
|
2002-01-25 06:37:35 +00:00
|
|
|
e->~IdAndNameMapEntry();
|
|
|
|
}
|
|
|
|
|
2003-08-05 20:09:21 +00:00
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsIAtom *atom = const_cast<nsIAtom *>
|
|
|
|
(static_cast<const nsIAtom*>(key));
|
2002-01-25 06:37:35 +00:00
|
|
|
|
|
|
|
// Inititlize the entry with placement new
|
2005-11-16 02:55:29 +00:00
|
|
|
new (entry) IdAndNameMapEntry(atom);
|
2003-08-05 20:09:21 +00:00
|
|
|
return PR_TRUE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsHTMLDocument::nsHTMLDocument()
|
2006-04-21 01:24:44 +00:00
|
|
|
: nsDocument("text/html"),
|
2006-01-06 02:53:10 +00:00
|
|
|
mDefaultNamespaceID(kNameSpaceID_None)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-28 15:55:31 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// NOTE! nsDocument::operator new() zeroes out all members, so don't
|
|
|
|
// bother initializing members to 0.
|
2001-05-18 01:10:54 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
mDefaultElementType = kNameSpaceID_XHTML;
|
2006-12-05 15:46:18 +00:00
|
|
|
mCompatMode = eCompatibility_NavQuirks;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLDocument::~nsHTMLDocument()
|
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
if (mIdAndNameHashTable.ops) {
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHashTableFinish(&mIdAndNameHashTable);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLDocument)
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
IdAndNameMapEntryTraverse(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(arg);
|
|
|
|
IdAndNameMapEntry *entry = static_cast<IdAndNameMapEntry*>(hdr);
|
2007-03-08 11:17:16 +00:00
|
|
|
|
2007-03-09 13:14:06 +00:00
|
|
|
if (entry->mNameContentList != NAME_NOT_VALID)
|
2007-03-08 11:17:16 +00:00
|
|
|
cb->NoteXPCOMChild(entry->mNameContentList);
|
|
|
|
|
2007-07-26 00:55:13 +00:00
|
|
|
cb->NoteXPCOMChild(static_cast<nsIDOMNodeList*>(entry->mDocAllList));
|
2007-07-26 00:36:19 +00:00
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
|
|
|
|
if (tmp->mIdAndNameHashTable.ops) {
|
|
|
|
PL_DHashTableEnumerate(&tmp->mIdAndNameHashTable,
|
|
|
|
IdAndNameMapEntryTraverse,
|
|
|
|
&cb);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mImageMaps)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mImages)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplets)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls,
|
|
|
|
nsIDOMNodeList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
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
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = nsDocument::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-01-06 02:53:10 +00:00
|
|
|
// Now reset the case-sensitivity of the CSSLoader, since we default
|
|
|
|
// to being HTML, not XHTML. Also, reset the compatibility mode to
|
|
|
|
// match our compat mode.
|
|
|
|
CSSLoader()->SetCaseSensitive(IsXHTML());
|
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
static PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
IdAndNameHashHashKey,
|
|
|
|
IdAndNameHashMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
IdAndNameHashClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
IdAndNameHashInitEntry
|
|
|
|
};
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool ok = PL_DHashTableInit(&mIdAndNameHashTable, &hash_table_ops, nsnull,
|
|
|
|
sizeof(IdAndNameMapEntry), 16);
|
|
|
|
if (!ok) {
|
|
|
|
mIdAndNameHashTable.ops = nsnull;
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-01-25 06:37:35 +00:00
|
|
|
|
|
|
|
PrePopulateHashTables();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-16 02:03:19 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2003-03-26 07:41:30 +00:00
|
|
|
nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
2003-10-22 06:09:48 +00:00
|
|
|
nsDocument::Reset(aChannel, aLoadGroup);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
if (aChannel) {
|
2003-03-26 07:41:30 +00:00
|
|
|
aChannel->GetLoadFlags(&mLoadFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2006-11-22 18:27:54 +00:00
|
|
|
nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2001-11-16 02:03:19 +00:00
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
mLoadFlags = nsIRequest::LOAD_NORMAL;
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2006-11-22 18:27:54 +00:00
|
|
|
nsDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
|
2001-11-16 02:03:19 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
InvalidateHashTables();
|
|
|
|
PrePopulateHashTables();
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
mImages = nsnull;
|
|
|
|
mApplets = nsnull;
|
|
|
|
mEmbeds = nsnull;
|
|
|
|
mLinks = nsnull;
|
|
|
|
mAnchors = nsnull;
|
1999-01-06 00:32:41 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
mImageMaps.Clear();
|
|
|
|
mForms = nsnull;
|
1998-05-13 23:43:44 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_ASSERTION(!mWyciwygChannel,
|
|
|
|
"nsHTMLDocument::Reset() - Wyciwyg Channel still exists!");
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
mWyciwygChannel = nsnull;
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2003-05-30 20:04:50 +00:00
|
|
|
// Make the content type default to "text/html", we are a HTML
|
|
|
|
// document, after all. Once we start getting data, this may be
|
|
|
|
// changed.
|
|
|
|
mContentType = "text/html";
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
|
|
|
|
2004-05-05 00:30:57 +00:00
|
|
|
nsStyleSet::sheetType
|
|
|
|
nsHTMLDocument::GetAttrSheetType()
|
|
|
|
{
|
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::GetAttrSheetType();
|
|
|
|
}
|
|
|
|
|
2004-07-15 20:30:30 +00:00
|
|
|
return nsStyleSet::eHTMLPresHintSheet;
|
2004-05-05 00:30:57 +00:00
|
|
|
}
|
2001-11-16 02:03:19 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLDocument::CreateShell(nsPresContext* aContext,
|
1999-07-07 01:27:08 +00:00
|
|
|
nsIViewManager* aViewManager,
|
2004-01-07 22:30:53 +00:00
|
|
|
nsStyleSet* aStyleSet,
|
1999-07-07 01:27:08 +00:00
|
|
|
nsIPresShell** aInstancePtrResult)
|
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
return doCreateShell(aContext, aViewManager, aStyleSet, mCompatMode,
|
|
|
|
aInstancePtrResult);
|
1999-07-07 01:27:08 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +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.
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
2001-12-26 03:17:59 +00:00
|
|
|
nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
|
2003-06-17 16:40:34 +00:00
|
|
|
PRInt32& aCharsetSource, nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
|
|
|
if (aMarkupDV) {
|
2003-03-26 07:41:30 +00:00
|
|
|
PRInt32 requestCharsetSource;
|
|
|
|
nsresult rv = aMarkupDV->GetHintCharacterSetSource(&requestCharsetSource);
|
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString requestCharset;
|
|
|
|
rv = aMarkupDV->GetHintCharacterSet(requestCharset);
|
2001-12-26 03:17:59 +00:00
|
|
|
aMarkupDV->SetHintCharacterSetSource((PRInt32)(kCharsetUninitialized));
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if(requestCharsetSource <= aCharsetSource)
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
if(NS_SUCCEEDED(rv)) {
|
|
|
|
aCharsetSource = requestCharsetSource;
|
|
|
|
aCharset = requestCharset;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
2001-12-26 03:17:59 +00:00
|
|
|
nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
|
|
|
|
nsIDocumentCharsetInfo* aDocInfo,
|
2003-03-26 07:41:30 +00:00
|
|
|
PRInt32& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2002-02-05 05:47:22 +00:00
|
|
|
nsresult rv = NS_OK;
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if(kCharsetFromUserForced <= aCharsetSource)
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString forceCharsetFromDocShell;
|
2003-03-26 07:41:30 +00:00
|
|
|
if (aMarkupDV) {
|
2003-06-17 16:40:34 +00:00
|
|
|
rv = aMarkupDV->GetForceCharacterSet(forceCharsetFromDocShell);
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2003-06-17 16:40:34 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && !forceCharsetFromDocShell.IsEmpty()) {
|
2003-04-02 11:18:00 +00:00
|
|
|
aCharset = forceCharsetFromDocShell;
|
2001-12-26 03:17:59 +00:00
|
|
|
//TODO: we should define appropriate constant for force charset
|
2003-03-26 07:41:30 +00:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2001-12-26 03:17:59 +00:00
|
|
|
} else if (aDocInfo) {
|
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
aDocInfo->GetForcedCharset(getter_AddRefs(csAtom));
|
2002-12-11 14:24:49 +00:00
|
|
|
if (csAtom) {
|
2003-06-17 16:40:34 +00:00
|
|
|
csAtom->ToUTF8String(aCharset);
|
2003-03-26 07:41:30 +00:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2001-12-26 03:17:59 +00:00
|
|
|
aDocInfo->SetForcedCharset(nsnull);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
|
|
|
|
PRInt32& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (kCharsetFromCache <= aCharsetSource) {
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
|
|
|
nsXPIDLCString cachedCharset;
|
|
|
|
rv = aCacheDescriptor->GetMetaDataElement("charset",
|
|
|
|
getter_Copies(cachedCharset));
|
2002-11-17 05:16:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !cachedCharset.IsEmpty())
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2003-06-17 16:40:34 +00:00
|
|
|
aCharset = cachedCharset;
|
2001-12-26 03:17:59 +00:00
|
|
|
aCharsetSource = kCharsetFromCache;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
2003-05-29 22:11:23 +00:00
|
|
|
nsHTMLDocument::TryBookmarkCharset(nsIDocShell* aDocShell,
|
|
|
|
nsIChannel* aChannel,
|
2003-03-26 07:41:30 +00:00
|
|
|
PRInt32& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
if (kCharsetFromBookmarks <= aCharsetSource) {
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2005-03-05 03:35:54 +00:00
|
|
|
if (!aChannel) {
|
2003-03-26 07:41:30 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2005-03-05 03:35:54 +00:00
|
|
|
nsCOMPtr<nsICharsetResolver> bookmarksResolver =
|
|
|
|
do_GetService("@mozilla.org/embeddor.implemented/bookmark-charset-resolver;1");
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2005-03-05 03:35:54 +00:00
|
|
|
if (!bookmarksResolver) {
|
2003-03-26 07:41:30 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-03-05 03:35:54 +00:00
|
|
|
PRBool wantCharset; // ignored for now
|
|
|
|
nsCAutoString charset;
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(aDocShell));
|
2006-05-15 17:17:04 +00:00
|
|
|
nsCOMPtr<nsISupports> closure;
|
2005-03-05 03:35:54 +00:00
|
|
|
nsresult rv = bookmarksResolver->RequestCharset(webNav,
|
|
|
|
aChannel,
|
|
|
|
&wantCharset,
|
2006-05-15 17:17:04 +00:00
|
|
|
getter_AddRefs(closure),
|
2005-03-05 03:35:54 +00:00
|
|
|
charset);
|
2006-05-15 17:40:51 +00:00
|
|
|
// FIXME: Bug 337790
|
|
|
|
NS_ASSERTION(!wantCharset, "resolved charset notification not implemented!");
|
|
|
|
|
2005-03-05 03:35:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) {
|
|
|
|
aCharset = charset;
|
|
|
|
aCharsetSource = kCharsetFromBookmarks;
|
|
|
|
return PR_TRUE;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-13 03:28:00 +00:00
|
|
|
static PRBool
|
|
|
|
CheckSameOrigin(nsINode* aNode1, nsINode* aNode2)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNode1, "Null node?");
|
|
|
|
NS_PRECONDITION(aNode2, "Null node?");
|
|
|
|
|
2007-07-10 04:22:55 +00:00
|
|
|
PRBool equal;
|
2007-01-13 03:28:00 +00:00
|
|
|
return
|
2007-07-10 04:22:55 +00:00
|
|
|
NS_SUCCEEDED(aNode1->NodePrincipal()->
|
|
|
|
Equals(aNode2->NodePrincipal(), &equal)) &&
|
|
|
|
equal;
|
2007-01-13 03:28:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
2001-12-26 03:17:59 +00:00
|
|
|
nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
|
2007-01-13 03:28:00 +00:00
|
|
|
nsIDocument* aParentDocument,
|
2003-03-26 07:41:30 +00:00
|
|
|
PRInt32& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
|
|
|
if (aDocInfo) {
|
|
|
|
PRInt32 source;
|
|
|
|
nsCOMPtr<nsIAtom> csAtom;
|
|
|
|
PRInt32 parentSource;
|
|
|
|
aDocInfo->GetParentCharsetSource(&parentSource);
|
|
|
|
if (kCharsetFromParentForced <= parentSource)
|
|
|
|
source = kCharsetFromParentForced;
|
2007-01-13 03:28:00 +00:00
|
|
|
else if (kCharsetFromHintPrevDoc == parentSource) {
|
|
|
|
// Make sure that's OK
|
|
|
|
if (!aParentDocument || !CheckSameOrigin(this, aParentDocument)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-09-20 09:24:54 +00:00
|
|
|
// if parent is posted doc, set this prevent autodections
|
2007-01-13 03:28:00 +00:00
|
|
|
// I'm not sure this makes much sense... but whatever.
|
2002-09-20 09:24:54 +00:00
|
|
|
source = kCharsetFromHintPrevDoc;
|
2007-01-13 03:28:00 +00:00
|
|
|
}
|
|
|
|
else if (kCharsetFromCache <= parentSource) {
|
|
|
|
// Make sure that's OK
|
|
|
|
if (!aParentDocument || !CheckSameOrigin(this, aParentDocument)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
source = kCharsetFromParentFrame;
|
2007-01-13 03:28:00 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
else
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (source < aCharsetSource)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
aDocInfo->GetParentCharset(getter_AddRefs(csAtom));
|
|
|
|
if (csAtom) {
|
2003-06-17 16:40:34 +00:00
|
|
|
csAtom->ToUTF8String(aCharset);
|
2003-03-26 07:41:30 +00:00
|
|
|
aCharsetSource = source;
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
|
|
|
if (kCharsetFromWeakDocTypeDefault <= aCharsetSource)
|
|
|
|
return PR_TRUE;
|
2003-04-02 11:18:00 +00:00
|
|
|
// fallback value in case docshell return error
|
2004-06-17 00:13:25 +00:00
|
|
|
aCharset.AssignLiteral("ISO-8859-1");
|
2004-04-29 23:34:19 +00:00
|
|
|
|
|
|
|
const nsAdoptingString& defCharset =
|
|
|
|
nsContentUtils::GetLocalizedStringPref("intl.charset.default");
|
|
|
|
|
|
|
|
if (!defCharset.IsEmpty()) {
|
|
|
|
LossyCopyUTF16toASCII(defCharset, aCharset);
|
|
|
|
aCharsetSource = kCharsetFromWeakDocTypeDefault;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
PRBool
|
2002-06-12 04:18:31 +00:00
|
|
|
nsHTMLDocument::TryDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
|
2003-06-17 16:40:34 +00:00
|
|
|
PRInt32& aCharsetSource,
|
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
if(kCharsetFromUserDefault <= aCharsetSource)
|
2001-12-26 03:17:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString defaultCharsetFromDocShell;
|
2001-12-26 03:17:59 +00:00
|
|
|
if (aMarkupDV) {
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv =
|
2003-06-17 16:40:34 +00:00
|
|
|
aMarkupDV->GetDefaultCharacterSet(defaultCharsetFromDocShell);
|
2001-12-26 03:17:59 +00:00
|
|
|
if(NS_SUCCEEDED(rv)) {
|
2003-04-02 11:18:00 +00:00
|
|
|
aCharset = defaultCharsetFromDocShell;
|
2003-06-17 16:40:34 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
aCharsetSource = kCharsetFromUserDefault;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
void
|
2003-06-17 16:40:34 +00:00
|
|
|
nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsACString& aCharset,
|
2001-12-26 03:17:59 +00:00
|
|
|
const char* aCommand)
|
|
|
|
{
|
|
|
|
nsCOMPtr <nsIParserFilter> cdetflt;
|
|
|
|
|
|
|
|
nsresult rv_detect;
|
2004-04-29 23:34:19 +00:00
|
|
|
if(!gInitDetector) {
|
|
|
|
const nsAdoptingString& detector_name =
|
|
|
|
nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
|
|
|
|
|
|
|
|
if(!detector_name.IsEmpty()) {
|
|
|
|
PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,
|
|
|
|
DETECTOR_CONTRACTID_MAX);
|
|
|
|
PL_strncat(g_detector_contractid,
|
|
|
|
NS_ConvertUTF16toUTF8(detector_name).get(),
|
|
|
|
DETECTOR_CONTRACTID_MAX);
|
|
|
|
gPlugDetector = PR_TRUE;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
2004-04-29 23:34:19 +00:00
|
|
|
|
|
|
|
nsContentUtils::RegisterPrefCallback("intl.charset.detector",
|
|
|
|
MyPrefChangedCallback,
|
|
|
|
nsnull);
|
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
gInitDetector = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gPlugDetector) {
|
2003-03-26 07:41:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICharsetDetectionAdaptor> adp = do_QueryInterface(cdetflt);
|
|
|
|
if (adp) {
|
|
|
|
nsCOMPtr<nsIWebShellServices> wss = do_QueryInterface(aDocShell);
|
|
|
|
if (wss) {
|
|
|
|
rv_detect = adp->Init(wss, cdet, this, mParser,
|
2003-06-17 16:40:34 +00:00
|
|
|
PromiseFlatCString(aCharset).get(), aCommand);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (mParser)
|
2003-04-08 21:23:34 +00:00
|
|
|
mParser->SetParserFilter(cdetflt);
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-03-26 07:41:30 +00:00
|
|
|
// IF we cannot create the detector, don't bother to
|
2001-12-26 03:17:59 +00:00
|
|
|
// create one next time.
|
|
|
|
gPlugDetector = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-09 02:47:58 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
|
|
|
|
{
|
|
|
|
nsDocument::SetDocumentCharacterSet(aCharSetID);
|
|
|
|
// Make sure to stash this charset on our channel as needed if it's a wyciwyg
|
|
|
|
// channel.
|
|
|
|
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel = do_QueryInterface(mChannel);
|
|
|
|
if (wyciwygChannel) {
|
|
|
|
wyciwygChannel->SetCharsetAndSource(GetDocumentCharacterSetSource(),
|
|
|
|
aCharSetID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-03-22 03:20:23 +00:00
|
|
|
nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
PRBool aReset,
|
|
|
|
nsIContentSink* aSink)
|
|
|
|
{
|
2003-04-19 00:28:09 +00:00
|
|
|
nsCAutoString contentType;
|
|
|
|
aChannel->GetContentType(contentType);
|
|
|
|
|
|
|
|
if (contentType.Equals("application/xhtml+xml") &&
|
|
|
|
(!aCommand || nsCRT::strcmp(aCommand, "view-source") != 0)) {
|
|
|
|
// We're parsing XHTML as XML, remember that.
|
|
|
|
|
|
|
|
mDefaultNamespaceID = kNameSpaceID_XHTML;
|
|
|
|
mCompatMode = eCompatibility_FullStandards;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(mDefaultNamespaceID == kNameSpaceID_None,
|
|
|
|
"Hey, someone forgot to reset mDefaultNamespaceID!!!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-19 01:27:11 +00:00
|
|
|
CSSLoader()->SetCaseSensitive(IsXHTML());
|
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
|
|
|
|
2003-04-19 00:28:09 +00:00
|
|
|
PRBool needsParser = PR_TRUE;
|
2003-03-22 03:20:23 +00:00
|
|
|
if (aCommand)
|
|
|
|
{
|
|
|
|
if (!nsCRT::strcmp(aCommand, "view delayedContentLoad")) {
|
|
|
|
needsParser = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICacheEntryDescriptor> cacheDescriptor;
|
|
|
|
nsresult rv = nsDocument::StartDocumentLoad(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer,
|
|
|
|
aDocListener, aReset);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-07-28 00:26:58 +00:00
|
|
|
// Store the security info for future use with wyciwyg channels.
|
|
|
|
aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
2003-03-22 03:20:23 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
|
|
|
|
if (cachingChan) {
|
|
|
|
nsCOMPtr<nsISupports> cacheToken;
|
|
|
|
cachingChan->GetCacheToken(getter_AddRefs(cacheToken));
|
|
|
|
if (cacheToken)
|
|
|
|
cacheDescriptor = do_QueryInterface(cacheToken);
|
|
|
|
}
|
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
if (needsParser) {
|
2003-03-26 07:41:30 +00:00
|
|
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
1999-04-26 17:56:37 +00:00
|
|
|
|
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;
|
2003-03-26 07:41:30 +00:00
|
|
|
docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
|
2005-11-08 22:45:49 +00:00
|
|
|
PRInt32 textType = GET_BIDI_OPTION_TEXTTYPE(GetBidiOptions());
|
|
|
|
|
2007-01-13 03:28:00 +00:00
|
|
|
// Look for the parent document. Note that at this point we don't have our
|
|
|
|
// content viewer set up yet, and therefore do not have a useful
|
|
|
|
// mParentDocument.
|
|
|
|
|
|
|
|
// in this block of code, if we get an error result, we return it
|
|
|
|
// but if we get a null pointer, that's perfectly legal for parent
|
|
|
|
// and parentContentViewer
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
|
|
|
nsCOMPtr<nsIDocument> parentDocument;
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
|
|
|
if (parent) {
|
|
|
|
rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer =
|
|
|
|
do_QueryInterface(parentContentViewer);
|
|
|
|
if (docViewer) {
|
|
|
|
docViewer->GetDocument(getter_AddRefs(parentDocument));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2006-04-25 06:57:31 +00:00
|
|
|
PRBool muCVIsParent = PR_FALSE;
|
1999-12-09 07:18:38 +00:00
|
|
|
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) {
|
2003-03-26 07:41:30 +00:00
|
|
|
muCV = do_QueryInterface(cv);
|
1999-12-13 22:45:06 +00:00
|
|
|
} else {
|
2007-01-13 03:28:00 +00:00
|
|
|
muCV = do_QueryInterface(parentContentViewer);
|
|
|
|
if (muCV) {
|
|
|
|
muCVIsParent = PR_TRUE;
|
1999-12-13 22:45:06 +00:00
|
|
|
}
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-05-15 03:42:33 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString scheme;
|
2004-01-09 23:54:21 +00:00
|
|
|
uri->GetScheme(scheme);
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString urlSpec;
|
2004-01-09 23:54:21 +00:00
|
|
|
uri->GetSpec(urlSpec);
|
2006-04-25 06:57:31 +00:00
|
|
|
#ifdef DEBUG_charset
|
|
|
|
printf("Determining charset for %s\n", urlSpec.get());
|
|
|
|
#endif
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2007-05-09 02:47:58 +00:00
|
|
|
// These are the charset source and charset for our document
|
2004-04-13 22:28:16 +00:00
|
|
|
PRInt32 charsetSource;
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString charset;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-05-09 02:47:58 +00:00
|
|
|
// These are the charset source and charset for the parser. This can differ
|
|
|
|
// from that for the document if the channel is a wyciwyg channel.
|
|
|
|
PRInt32 parserCharsetSource;
|
|
|
|
nsCAutoString parserCharset;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel;
|
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
charsetSource = kCharsetFromDocTypeDefault;
|
2004-06-17 00:13:25 +00:00
|
|
|
charset.AssignLiteral("UTF-8");
|
2004-05-02 19:48:54 +00:00
|
|
|
TryChannelCharset(aChannel, charsetSource, charset);
|
2007-05-09 02:47:58 +00:00
|
|
|
parserCharsetSource = charsetSource;
|
|
|
|
parserCharset = charset;
|
2004-04-13 22:28:16 +00:00
|
|
|
} else {
|
|
|
|
charsetSource = kCharsetUninitialized;
|
2007-05-09 02:47:58 +00:00
|
|
|
wyciwygChannel = do_QueryInterface(aChannel);
|
2004-04-13 22:28:16 +00:00
|
|
|
|
|
|
|
// 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);
|
2007-01-13 03:28:00 +00:00
|
|
|
TryParentCharset(dcInfo, parentDocument, charsetSource, charset);
|
2007-05-09 02:47:58 +00:00
|
|
|
|
|
|
|
// Don't actually get the charset from the channel if this is a
|
|
|
|
// wyciwyg channel; it'll always be UTF-16
|
|
|
|
if (!wyciwygChannel &&
|
|
|
|
TryChannelCharset(aChannel, charsetSource, charset)) {
|
2004-04-13 22:28:16 +00:00
|
|
|
// Use the channel's charset (e.g., charset from HTTP
|
|
|
|
// "Content-Type" header).
|
|
|
|
}
|
2004-05-22 22:15:22 +00:00
|
|
|
else if (!scheme.EqualsLiteral("about") && // don't try to access bookmarks for about:blank
|
2004-04-13 22:28:16 +00:00
|
|
|
TryBookmarkCharset(docShell, aChannel, charsetSource, charset)) {
|
|
|
|
// Use the bookmark's charset.
|
|
|
|
}
|
|
|
|
else if (cacheDescriptor && !urlSpec.IsEmpty() &&
|
|
|
|
TryCacheCharset(cacheDescriptor, charsetSource, charset)) {
|
|
|
|
// Use the cache's charset.
|
|
|
|
}
|
|
|
|
else if (TryDefaultCharset(muCV, charsetSource, charset)) {
|
|
|
|
// Use the default charset.
|
|
|
|
// previous document charset might be inherited as default charset.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Use the weak doc type default charset
|
|
|
|
UseWeakDocTypeDefault(charsetSource, charset);
|
|
|
|
}
|
2000-08-05 00:07:03 +00:00
|
|
|
}
|
2002-08-26 20:13:31 +00:00
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
PRBool isPostPage = PR_FALSE;
|
|
|
|
// check if current doc is from POST command
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
|
|
|
|
if (httpChannel) {
|
|
|
|
nsCAutoString methodStr;
|
|
|
|
rv = httpChannel->GetRequestMethod(methodStr);
|
|
|
|
isPostPage = (NS_SUCCEEDED(rv) &&
|
2004-05-22 22:15:22 +00:00
|
|
|
methodStr.EqualsLiteral("POST"));
|
2004-04-13 22:28:16 +00:00
|
|
|
}
|
2002-08-26 20:13:31 +00:00
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
if (isPostPage && muCV && kCharsetFromHintPrevDoc > charsetSource) {
|
|
|
|
nsCAutoString requestCharset;
|
|
|
|
muCV->GetPrevDocCharacterSet(requestCharset);
|
|
|
|
if (!requestCharset.IsEmpty()) {
|
|
|
|
charsetSource = kCharsetFromHintPrevDoc;
|
|
|
|
charset = requestCharset;
|
|
|
|
}
|
2002-06-12 04:18:31 +00:00
|
|
|
}
|
2002-08-26 20:13:31 +00:00
|
|
|
|
2007-05-09 02:47:58 +00:00
|
|
|
if (wyciwygChannel) {
|
|
|
|
// We know for sure that the parser needs to be using UTF16.
|
|
|
|
parserCharset = "UTF-16";
|
|
|
|
parserCharsetSource = charsetSource < kCharsetFromChannel ?
|
|
|
|
kCharsetFromChannel : charsetSource;
|
|
|
|
|
|
|
|
nsCAutoString cachedCharset;
|
|
|
|
PRInt32 cachedSource;
|
|
|
|
rv = wyciwygChannel->GetCharsetAndSource(&cachedSource, cachedCharset);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (cachedSource > charsetSource) {
|
|
|
|
charsetSource = cachedSource;
|
|
|
|
charset = cachedCharset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Don't propagate this error.
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
parserCharset = charset;
|
|
|
|
parserCharsetSource = charsetSource;
|
|
|
|
}
|
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
if(kCharsetFromAutoDetection > charsetSource && !isPostPage) {
|
|
|
|
StartAutodetection(docShell, charset, aCommand);
|
|
|
|
}
|
1998-07-10 05:35:23 +00:00
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
// ahmed
|
|
|
|
// Check if 864 but in Implicit mode !
|
2007-05-09 02:47:58 +00:00
|
|
|
// XXXbz why is this happening after StartAutodetection ?
|
2005-11-08 22:45:49 +00:00
|
|
|
if ((textType == IBMBIDI_TEXTTYPE_LOGICAL) &&
|
2004-06-17 00:13:25 +00:00
|
|
|
(charset.LowerCaseEqualsLiteral("ibm864"))) {
|
|
|
|
charset.AssignLiteral("IBM864i");
|
2004-04-13 22:28:16 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
1999-12-09 07:18:38 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
SetDocumentCharacterSetSource(charsetSource);
|
2007-05-09 02:47:58 +00:00
|
|
|
SetDocumentCharacterSet(charset);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2002-08-26 20:13:31 +00:00
|
|
|
// set doc charset to muCV for next document.
|
2006-04-25 06:57:31 +00:00
|
|
|
// Don't propagate this back up to the parent document if we have one.
|
|
|
|
if (muCV && !muCVIsParent)
|
2003-06-17 16:40:34 +00:00
|
|
|
muCV->SetPrevDocCharacterSet(charset);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-04-27 02:26:32 +00:00
|
|
|
if(cacheDescriptor) {
|
2007-05-09 02:47:58 +00:00
|
|
|
NS_ASSERTION(charset == parserCharset,
|
|
|
|
"How did those end up different here? wyciwyg channels are "
|
|
|
|
"not nsICachingChannel");
|
2001-04-27 02:26:32 +00:00
|
|
|
rv = cacheDescriptor->SetMetaDataElement("charset",
|
2003-06-17 16:40:34 +00:00
|
|
|
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) {
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(mParser, aDocListener);
|
2000-12-26 01:01:41 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-02 08:14:22 +00:00
|
|
|
|
1999-12-13 21:00:47 +00:00
|
|
|
#ifdef DEBUG_charset
|
2006-04-25 06:57:31 +00:00
|
|
|
printf(" charset = %s source %d\n",
|
|
|
|
charset.get(), charsetSource);
|
1999-12-13 21:00:47 +00:00
|
|
|
#endif
|
2007-05-09 02:47:58 +00:00
|
|
|
mParser->SetDocumentCharset(parserCharset, parserCharsetSource);
|
1999-12-09 07:18:38 +00:00
|
|
|
mParser->SetCommand(aCommand);
|
2001-11-02 01:53:13 +00:00
|
|
|
|
2003-04-02 11:18:00 +00:00
|
|
|
// create the content sink
|
2003-04-19 00:28:09 +00:00
|
|
|
nsCOMPtr<nsIContentSink> sink;
|
|
|
|
|
2001-11-02 01:53:13 +00:00
|
|
|
if (aSink)
|
2003-04-19 00:28:09 +00:00
|
|
|
sink = aSink;
|
2001-11-02 01:53:13 +00:00
|
|
|
else {
|
2003-04-19 00:28:09 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
nsCOMPtr<nsIXMLContentSink> xmlsink;
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri,
|
2003-12-25 10:30:48 +00:00
|
|
|
docShell, aChannel);
|
2003-04-19 00:28:09 +00:00
|
|
|
|
|
|
|
sink = xmlsink;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> htmlsink;
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri,
|
2003-04-19 00:28:09 +00:00
|
|
|
docShell, aChannel);
|
|
|
|
|
|
|
|
sink = htmlsink;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2003-04-19 00:28:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_ASSERTION(sink,
|
|
|
|
"null sink with successful result from factory method");
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
mParser->SetContentSink(sink);
|
2004-01-09 23:54:21 +00:00
|
|
|
// parser the content of the URI
|
2006-01-30 23:45:19 +00:00
|
|
|
mParser->Parse(uri, nsnull, (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
|
|
|
}
|
|
|
|
|
2006-06-19 23:51:32 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::StopDocumentLoad()
|
|
|
|
{
|
|
|
|
// If we're writing (i.e., there's been a document.open call), then
|
|
|
|
// nsDocument::StopDocumentLoad will do the wrong thing and simply terminate
|
|
|
|
// our parser.
|
|
|
|
if (mWriteState != eNotWriting) {
|
|
|
|
Close();
|
|
|
|
} else {
|
|
|
|
nsDocument::StopDocumentLoad();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-18 22:49:39 +00:00
|
|
|
// static
|
2002-04-19 02:33:00 +00:00
|
|
|
void
|
2002-04-18 22:49:39 +00:00
|
|
|
nsHTMLDocument::DocumentWriteTerminationFunc(nsISupports *aRef)
|
|
|
|
{
|
2006-04-08 01:45:27 +00:00
|
|
|
nsCOMPtr<nsIArray> arr = do_QueryInterface(aRef);
|
|
|
|
NS_ASSERTION(arr, "Must have array!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryElementAt(arr, 0);
|
|
|
|
NS_ASSERTION(doc, "Must have document!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIParser> parser = do_QueryElementAt(arr, 1);
|
|
|
|
NS_ASSERTION(parser, "Must have parser!");
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsHTMLDocument *htmldoc = static_cast<nsHTMLDocument*>(doc.get());
|
2006-04-08 01:45:27 +00:00
|
|
|
|
|
|
|
// Check whether htmldoc still has the same parser. If not, it's
|
|
|
|
// not for us to mess with it.
|
|
|
|
if (htmldoc->mParser != parser) {
|
|
|
|
return;
|
|
|
|
}
|
2002-04-18 22:49:39 +00:00
|
|
|
|
|
|
|
// If the document is in the middle of a document.write() call, this
|
|
|
|
// most likely means that script on a page document.write()'d out a
|
|
|
|
// script tag that did location="..." and we're right now finishing
|
|
|
|
// up executing the script that was written with
|
|
|
|
// document.write(). Since there's still script on the stack (the
|
|
|
|
// script that called document.write()) we don't want to release the
|
|
|
|
// parser now, that would cause the next document.write() call to
|
|
|
|
// cancel the load that was initiated by the location="..." in the
|
|
|
|
// script that was written out by document.write().
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
if (!htmldoc->mWriteLevel && htmldoc->mWriteState != eDocumentOpened) {
|
2006-04-08 01:45:27 +00:00
|
|
|
// Release the document's parser so that the call to EndLoad()
|
2002-04-18 22:49:39 +00:00
|
|
|
// doesn't just return early and set the termination function again.
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
htmldoc->mParser = nsnull;
|
2002-04-18 22:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
htmldoc->EndLoad();
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
1998-07-23 22:06:05 +00:00
|
|
|
nsHTMLDocument::EndLoad()
|
|
|
|
{
|
2006-01-24 01:25:14 +00:00
|
|
|
if (mParser && mWriteState != eDocumentClosed) {
|
2002-04-18 22:49:39 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
|
|
|
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
|
|
|
|
|
|
|
if (stack) {
|
|
|
|
JSContext *cx = nsnull;
|
|
|
|
stack->Peek(&cx);
|
|
|
|
|
|
|
|
if (cx) {
|
2004-04-13 03:21:50 +00:00
|
|
|
nsIScriptContext *scx = nsJSUtils::GetDynamicScriptContext(cx);
|
2002-04-18 22:49:39 +00:00
|
|
|
|
|
|
|
if (scx) {
|
|
|
|
// The load of the document was terminated while we're
|
|
|
|
// called from within JS and we have a parser (i.e. we're in
|
|
|
|
// the middle of doing document.write()). In stead of
|
|
|
|
// releasing the parser and ending the document load
|
|
|
|
// directly, we'll make that happen once the script is done
|
|
|
|
// executing. This way subsequent document.write() calls
|
|
|
|
// won't end up creating a new parser and interrupting other
|
|
|
|
// loads that were started while the script was
|
|
|
|
// running. I.e. this makes the following case work as
|
|
|
|
// expected:
|
|
|
|
//
|
|
|
|
// document.write("foo");
|
|
|
|
// location.href = "http://www.mozilla.org";
|
|
|
|
// document.write("bar");
|
2006-04-08 01:45:27 +00:00
|
|
|
|
2006-04-12 15:43:32 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> arr =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
2005-06-09 15:42:19 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-08 07:08:04 +00:00
|
|
|
rv = arr->AppendElement(static_cast<nsIDocument*>(this),
|
2006-04-08 01:45:27 +00:00
|
|
|
PR_FALSE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = arr->AppendElement(mParser, PR_FALSE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = scx->SetTerminationFunction(DocumentWriteTerminationFunc,
|
|
|
|
arr);
|
|
|
|
// If we fail to set the termination function, just go ahead
|
|
|
|
// and EndLoad now. The slight bugginess involved is better
|
|
|
|
// than leaking.
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-09 15:42:19 +00:00
|
|
|
}
|
2002-04-18 22:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
// Reset this now, since we're really done "loading" this document.written
|
|
|
|
// document.
|
|
|
|
NS_ASSERTION(mWriteState == eNotWriting || mWriteState == ePendingClose ||
|
|
|
|
mWriteState == eDocumentClosed, "EndLoad called early");
|
|
|
|
mWriteState = eNotWriting;
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
PRBool turnOnEditing =
|
|
|
|
mParser && (HasFlag(NODE_IS_EDITABLE) || mContentEditableCount > 0);
|
2006-01-24 01:25:14 +00:00
|
|
|
// Note: nsDocument::EndLoad nulls out mParser.
|
2003-10-22 06:09:48 +00:00
|
|
|
nsDocument::EndLoad();
|
2007-06-28 02:48:16 +00:00
|
|
|
if (turnOnEditing) {
|
|
|
|
EditingStateChanged();
|
|
|
|
}
|
1998-07-23 22:06:05 +00:00
|
|
|
}
|
1998-07-01 11:16:09 +00:00
|
|
|
|
2000-12-26 01:01:41 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetTitle(const nsAString& 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
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
nsresult
|
1999-01-09 00:15:19 +00:00
|
|
|
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.
|
2003-03-26 07:41:30 +00:00
|
|
|
// XXX Otherwise scripts that add/remove maps with duplicate names
|
2001-04-18 00:14:34 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
if (mImageMaps.AppendObject(aMap)) {
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
void
|
1999-03-01 16:57:35 +00:00
|
|
|
nsHTMLDocument::RemoveImageMap(nsIDOMHTMLMapElement* aMap)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
2003-03-26 07:41:30 +00:00
|
|
|
mImageMaps.RemoveObject(aMap);
|
1999-03-01 16:57:35 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
nsIDOMHTMLMapElement *
|
|
|
|
nsHTMLDocument::GetImageMap(const nsAString& aMapName)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
nsAutoString name;
|
2003-03-26 07:41:30 +00:00
|
|
|
PRUint32 i, n = mImageMaps.Count();
|
2005-07-25 23:37:56 +00:00
|
|
|
nsIDOMHTMLMapElement *firstMatch = nsnull;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (i = 0; i < n; ++i) {
|
2004-02-03 23:23:10 +00:00
|
|
|
nsIDOMHTMLMapElement *map = mImageMaps[i];
|
2003-05-29 00:53:03 +00:00
|
|
|
NS_ASSERTION(map, "Null map in map list!");
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2003-05-29 00:53:03 +00:00
|
|
|
PRBool match;
|
|
|
|
nsresult rv;
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2003-05-29 00:53:03 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
rv = map->GetId(name);
|
|
|
|
|
|
|
|
match = name.Equals(aMapName);
|
|
|
|
} else {
|
|
|
|
rv = map->GetName(name);
|
|
|
|
|
|
|
|
match = name.Equals(aMapName, nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
if (match && NS_SUCCEEDED(rv)) {
|
2005-07-25 23:37:56 +00:00
|
|
|
// Quirk: if the first matching map is empty, remember it, but keep
|
|
|
|
// searching for a non-empty one, only use it if none was found (bug 264624).
|
|
|
|
if (mCompatMode == eCompatibility_NavQuirks) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
|
|
|
|
rv = map->GetAreas(getter_AddRefs(mapAreas));
|
|
|
|
if (NS_SUCCEEDED(rv) && mapAreas) {
|
|
|
|
PRUint32 length = 0;
|
|
|
|
mapAreas->GetLength(&length);
|
|
|
|
if (length == 0) {
|
|
|
|
if (!firstMatch) {
|
|
|
|
firstMatch = map;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-03 23:23:10 +00:00
|
|
|
return map;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:37:56 +00:00
|
|
|
return firstMatch;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
void
|
2002-06-25 21:16:17 +00:00
|
|
|
nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
|
1998-09-02 02:06:39 +00:00
|
|
|
{
|
2003-04-19 00:28:09 +00:00
|
|
|
NS_ASSERTION(!IsXHTML() || aMode == eCompatibility_FullStandards,
|
|
|
|
"Bad compat mode for XHTML document!");
|
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
mCompatMode = aMode;
|
2005-04-19 01:27:11 +00:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
2007-05-01 22:24:20 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
|
2002-05-18 00:02:50 +00:00
|
|
|
if (shell) {
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *pc = shell->GetPresContext();
|
2001-12-21 01:10:07 +00:00
|
|
|
if (pc) {
|
2006-12-05 15:46:18 +00:00
|
|
|
pc->CompatibilityModeChanged();
|
2001-12-21 01:10:07 +00:00
|
|
|
}
|
1999-09-15 17:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2006-07-02 07:23:10 +00:00
|
|
|
nsHTMLDocument::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_ASSERTION(aDocument == this, "unexpected doc");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 count = aContainer->GetChildCount();
|
|
|
|
for (PRUint32 i = aNewIndexInContainer; i < count; ++i) {
|
|
|
|
RegisterNamedItems(aContainer->GetChildAt(i));
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2006-07-02 07:23:10 +00:00
|
|
|
nsHTMLDocument::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aContent,
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_ASSERTION(aDocument == this, "unexpected doc");
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
RegisterNamedItems(aContent);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2006-07-02 07:23:10 +00:00
|
|
|
nsHTMLDocument::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
1998-11-28 23:51:06 +00:00
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_ASSERTION(aDocument == this, "unexpected doc");
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(aChild, "Null content!");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
UnregisterNamedItems(aChild);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2001-03-22 08:51:52 +00:00
|
|
|
nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute)
|
|
|
|
{
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
2003-10-21 16:16:42 +00:00
|
|
|
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!IsXHTML() && aAttribute == nsGkAtoms::name &&
|
2003-04-19 00:28:09 +00:00
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* name = IsNamedItem(aContent);
|
|
|
|
if (name) {
|
|
|
|
nsresult rv = RemoveFromNameTable(name, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2003-10-22 06:09:48 +00:00
|
|
|
return;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-26 14:16:19 +00:00
|
|
|
} else if (aAttribute == aContent->GetIDAttributeName() &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult rv = RemoveFromIdTable(aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2003-10-22 06:09:48 +00:00
|
|
|
return;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsDocument::AttributeWillChange(aContent, aNameSpaceID, aAttribute);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
2006-07-02 07:23:10 +00:00
|
|
|
nsHTMLDocument::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent, PRInt32 aNameSpaceID,
|
2007-07-12 20:05:45 +00:00
|
|
|
nsIAtom* aAttribute, PRInt32 aModType,
|
|
|
|
PRUint32 aStateMask)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_ASSERTION(aDocument == this, "unexpected doc");
|
|
|
|
|
2001-08-07 06:09:17 +00:00
|
|
|
NS_ABORT_IF_FALSE(aContent, "Null content!");
|
2003-10-21 16:16:42 +00:00
|
|
|
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
|
2001-08-07 06:09:17 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!IsXHTML() && aAttribute == nsGkAtoms::name &&
|
2003-04-19 00:28:09 +00:00
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* name = IsNamedItem(aContent);
|
|
|
|
if (name) {
|
2006-07-02 07:23:10 +00:00
|
|
|
UpdateNameTableEntry(name, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
2007-07-26 14:16:19 +00:00
|
|
|
} else if (aAttribute == aContent->GetIDAttributeName() &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* id = aContent->GetID();
|
|
|
|
if (id) {
|
2006-07-02 07:23:10 +00:00
|
|
|
UpdateIdTableEntry(id, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRBool
|
2003-04-19 00:28:09 +00:00
|
|
|
nsHTMLDocument::IsCaseSensitive()
|
|
|
|
{
|
|
|
|
return IsXHTML();
|
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
//
|
|
|
|
// nsIDOMDocument interface implementation
|
|
|
|
//
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateElement(const nsAString& aTagName,
|
1998-07-14 18:44:44 +00:00
|
|
|
nsIDOMElement** aReturn)
|
1998-05-04 17:54:45 +00:00
|
|
|
{
|
2004-02-11 02:22:43 +00:00
|
|
|
*aReturn = nsnull;
|
2004-06-02 16:21:22 +00:00
|
|
|
nsresult rv;
|
2004-02-11 02:22:43 +00:00
|
|
|
|
2005-06-08 16:42:04 +00:00
|
|
|
nsAutoString tagName(aTagName);
|
|
|
|
|
|
|
|
// if we are in quirks, allow surrounding '<' '>' for IE compat
|
|
|
|
if (mCompatMode == eCompatibility_NavQuirks &&
|
|
|
|
tagName.Length() > 2 &&
|
|
|
|
tagName.First() == '<' &&
|
|
|
|
tagName.Last() == '>') {
|
|
|
|
tagName = Substring(tagName, 1, tagName.Length() - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nsContentUtils::CheckQName(tagName, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-02-11 02:22:43 +00:00
|
|
|
|
|
|
|
if (!IsXHTML()) {
|
2005-06-08 16:42:04 +00:00
|
|
|
ToLowerCase(tagName);
|
2004-02-11 02:22:43 +00:00
|
|
|
}
|
|
|
|
|
2005-06-08 16:42:04 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(tagName);
|
2004-02-11 02:22:43 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
2004-07-22 14:54:49 +00:00
|
|
|
rv = CreateElem(name, nsnull, GetDefaultNamespaceID(), PR_TRUE,
|
|
|
|
getter_AddRefs(content));
|
2004-02-11 02:22:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(content, aReturn);
|
2004-02-10 10:58:13 +00:00
|
|
|
}
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2004-02-10 10:58:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateElementNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
|
|
|
nsIDOMElement** aReturn)
|
|
|
|
{
|
|
|
|
return nsDocument::CreateElementNS(aNamespaceURI, aQualifiedName, aReturn);
|
1998-05-04 17:54:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateProcessingInstruction(const nsAString& aTarget,
|
|
|
|
const nsAString& aData,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMProcessingInstruction** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2004-03-02 22:39:46 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::CreateProcessingInstruction(aTarget, aData, aReturn);
|
|
|
|
}
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
// There are no PIs for HTML
|
|
|
|
*aReturn = nsnull;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-09-08 23:18:27 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateCDATASection(const nsAString& aData,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMCDATASection** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2004-03-02 22:39:46 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::CreateCDATASection(aData, aReturn);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::CreateEntityReference(const nsAString& aName,
|
1998-10-20 17:07:23 +00:00
|
|
|
nsIDOMEntityReference** aReturn)
|
|
|
|
{
|
2004-03-02 22:39:46 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::CreateEntityReference(aName, aReturn);
|
|
|
|
}
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-20 17:07:23 +00:00
|
|
|
nsHTMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
return nsDocument::GetDoctype(aDocumentType);
|
1998-10-20 17:07:23 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-01-19 16:58:45 +00:00
|
|
|
nsHTMLDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetImplementation(aImplementation);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-01-19 16:58:45 +00:00
|
|
|
nsHTMLDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::GetDocumentElement(aDocumentElement);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-01-19 16:58:45 +00:00
|
|
|
nsHTMLDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateDocumentFragment(aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateComment(aData, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::CreateAttribute(const nsAString& aName, nsIDOMAttr** aReturn)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateAttribute(aName, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
|
|
|
return nsDocument::CreateTextNode(aData, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname,
|
|
|
|
nsIDOMNodeList** aReturn)
|
|
|
|
{
|
2000-05-17 03:47:06 +00:00
|
|
|
nsAutoString tmp(aTagname);
|
2004-10-28 02:34:21 +00:00
|
|
|
if (!IsXHTML()) {
|
|
|
|
ToLowerCase(tmp); // HTML elements are lower case internally.
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
return nsDocument::GetElementsByTagName(tmp, aReturn);
|
1999-01-19 16:58:45 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetBaseURI(nsAString &aURI)
|
2001-03-30 02:15:21 +00:00
|
|
|
{
|
|
|
|
aURI.Truncate();
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI *uri = mDocumentBaseURI; // WEAK
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (!uri) {
|
2004-01-09 23:54:21 +00:00
|
|
|
uri = mDocumentURI;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-06-21 00:26:28 +00:00
|
|
|
CopyUTF8toUTF16(spec, aURI);
|
2001-03-30 02:15:21 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-19 16:58:45 +00:00
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
// nsIDOM3Document interface implementation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetXmlEncoding(nsAString& aXmlEncoding)
|
|
|
|
{
|
2003-11-18 22:07:53 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::GetXmlEncoding(aXmlEncoding);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
SetDOMStringToNull(aXmlEncoding);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetXmlStandalone(PRBool *aXmlStandalone)
|
|
|
|
{
|
2003-11-18 22:07:53 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::GetXmlStandalone(aXmlStandalone);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
*aXmlStandalone = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetXmlStandalone(PRBool aXmlStandalone)
|
|
|
|
{
|
2003-11-18 22:07:53 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::SetXmlStandalone(aXmlStandalone);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetXmlVersion(nsAString& aXmlVersion)
|
|
|
|
{
|
2003-11-18 22:07:53 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::GetXmlVersion(aXmlVersion);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
SetDOMStringToNull(aXmlVersion);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetXmlVersion(const nsAString& aXmlVersion)
|
|
|
|
{
|
2003-11-18 22:07:53 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
return nsDocument::SetXmlVersion(aXmlVersion);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
//
|
|
|
|
// nsIDOMHTMLDocument interface implementation
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetTitle(nsAString& 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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetReferrer(nsAString& aReferrer)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2004-01-27 04:41:12 +00:00
|
|
|
return nsDocument::GetReferrer(aReferrer);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::GetDomainURI(nsIURI **aURI)
|
1999-10-02 03:41:37 +00:00
|
|
|
{
|
2006-04-27 18:21:11 +00:00
|
|
|
nsIPrincipal *principal = NodePrincipal();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
principal->GetDomain(aURI);
|
|
|
|
if (!*aURI) {
|
|
|
|
principal->GetURI(aURI);
|
|
|
|
}
|
1999-10-02 03:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetDomain(nsAString& aDomain)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-10-02 03:41:37 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2003-03-26 07:41:30 +00:00
|
|
|
GetDomainURI(getter_AddRefs(uri));
|
|
|
|
|
|
|
|
if (!uri) {
|
1999-10-02 03:41:37 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
1999-10-02 03:41:37 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString hostName;
|
2003-06-21 00:26:28 +00:00
|
|
|
|
2004-01-28 23:44:08 +00:00
|
|
|
if (NS_SUCCEEDED(uri->GetHost(hostName))) {
|
|
|
|
CopyUTF8toUTF16(hostName, aDomain);
|
|
|
|
} else {
|
|
|
|
// If we can't get the host from the URI (e.g. about:, javascript:,
|
|
|
|
// etc), just return an null string.
|
|
|
|
SetDOMStringToNull(aDomain);
|
|
|
|
}
|
1999-10-02 03:41:37 +00:00
|
|
|
|
1998-12-07 06:10:12 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetDomain(const nsAString& aDomain)
|
1999-10-02 03:41:37 +00:00
|
|
|
{
|
2003-05-09 23:56:04 +00:00
|
|
|
if (aDomain.IsEmpty())
|
|
|
|
return NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
// Create new URI
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2003-03-26 07:41:30 +00:00
|
|
|
GetDomainURI(getter_AddRefs(uri));
|
|
|
|
|
|
|
|
if (!uri) {
|
1999-10-02 03:41:37 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2007-12-31 03:43:42 +00:00
|
|
|
nsCAutoString newURIString;
|
|
|
|
if (NS_FAILED(uri->GetScheme(newURIString)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCAutoString path;
|
|
|
|
if (NS_FAILED(uri->GetPath(path)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
newURIString.AppendLiteral("://");
|
|
|
|
AppendUTF16toUTF8(aDomain, newURIString);
|
|
|
|
newURIString.Append(path);
|
1999-10-02 03:41:37 +00:00
|
|
|
|
2007-12-31 03:43:42 +00:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(newURI), newURIString)))
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-30 23:35:42 +00:00
|
|
|
|
2007-11-12 07:58:16 +00:00
|
|
|
// Check new domain - must be a superdomain of the current host
|
|
|
|
// For example, a page from foo.bar.com may set domain to bar.com,
|
|
|
|
// but not to ar.com, baz.com, or fi.foo.bar.com.
|
|
|
|
nsCAutoString current, domain;
|
|
|
|
if (NS_FAILED(uri->GetHost(current)))
|
|
|
|
current.Truncate();
|
|
|
|
if (NS_FAILED(newURI->GetHost(domain)))
|
|
|
|
domain.Truncate();
|
|
|
|
|
|
|
|
PRBool ok = current.Equals(domain);
|
|
|
|
if (current.Length() > domain.Length() &&
|
|
|
|
StringEndsWith(current, domain) &&
|
|
|
|
current.CharAt(current.Length() - domain.Length() - 1) == '.') {
|
|
|
|
// Using only a TLD is forbidden (bug 368700)
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
if (!tldService)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
// try to get the base domain; if this works, we're ok.
|
|
|
|
// if we're dealing with an IP address, getting the base domain
|
|
|
|
// will fail, as required.
|
|
|
|
nsCAutoString baseDomain;
|
|
|
|
ok = NS_SUCCEEDED(tldService->GetBaseDomain(newURI, 0, baseDomain));
|
|
|
|
}
|
|
|
|
if (!ok) {
|
|
|
|
// Error: illegal domain
|
|
|
|
return NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN;
|
|
|
|
}
|
|
|
|
|
2006-10-10 01:07:45 +00:00
|
|
|
return NodePrincipal()->SetDomain(newURI);
|
1999-10-02 03:41:37 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetURL(nsAString& aURL)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2003-06-21 00:26:28 +00:00
|
|
|
nsCAutoString str;
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
if (mDocumentURI) {
|
|
|
|
mDocumentURI->GetSpec(str);
|
1998-11-24 21:07:43 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2003-06-21 00:26:28 +00:00
|
|
|
CopyUTF8toUTF16(str, aURL);
|
|
|
|
|
1998-11-24 21:07:43 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
|
|
|
|
{
|
2001-02-23 02:01:30 +00:00
|
|
|
*aBody = nsnull;
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* body = GetBodyContent();
|
2001-02-23 02:01:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
if (body) {
|
2001-02-23 02:01:30 +00:00
|
|
|
// There is a body element, return that as the body.
|
2007-12-12 02:26:09 +00:00
|
|
|
return CallQueryInterface(body, aBody);
|
|
|
|
}
|
2001-02-23 02:01:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
// The document is most likely a frameset document so look for the
|
|
|
|
// outer most frameset element
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
2001-02-23 02:01:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (IsXHTML()) {
|
|
|
|
rv = GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"),
|
|
|
|
NS_LITERAL_STRING("frameset"),
|
2004-04-30 17:44:53 +00:00
|
|
|
getter_AddRefs(nodeList));
|
2007-12-12 02:26:09 +00:00
|
|
|
} else {
|
|
|
|
rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
|
|
|
|
getter_AddRefs(nodeList));
|
2006-03-23 08:21:21 +00:00
|
|
|
}
|
2007-12-12 02:26:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nodeList->Item(0, getter_AddRefs(node));
|
2006-03-23 08:21:21 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
return node ? CallQueryInterface(node, aBody) : NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
|
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIContent> newBody = do_QueryInterface(aBody);
|
|
|
|
nsIContent* root = GetRootContent();
|
2000-12-14 22:37:22 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
// The body element must be either a body tag or a frameset tag. And we must
|
|
|
|
// have a html root tag, otherwise GetBody will not return the newly set
|
|
|
|
// body.
|
|
|
|
if (!newBody || !(newBody->Tag() == nsGkAtoms::body ||
|
|
|
|
newBody->Tag() == nsGkAtoms::frameset) ||
|
|
|
|
!root || !root->IsNodeOfType(nsINode::eHTML) ||
|
|
|
|
root->Tag() != nsGkAtoms::html) {
|
2000-12-14 22:37:22 +00:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
1999-02-04 02:16:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> rootElem = do_QueryInterface(root);
|
2004-04-12 23:30:01 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
2000-12-14 22:37:22 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
// Use DOM methods so that we pass through the appropriate security checks.
|
|
|
|
nsCOMPtr<nsIDOMNode> currentBody = do_QueryInterface(GetBodyContent());
|
|
|
|
if (currentBody) {
|
|
|
|
return rootElem->ReplaceChild(aBody, currentBody, getter_AddRefs(tmp));
|
2000-12-14 22:37:22 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
return rootElem->AppendChild(aBody, getter_AddRefs(tmp));
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
|
|
|
|
{
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mImages) {
|
2006-12-26 17:47:52 +00:00
|
|
|
mImages = new nsContentList(this, nsGkAtoms::img, mDefaultNamespaceID);
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mImages) {
|
1998-07-22 23:32:19 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
*aImages = mImages;
|
2002-05-20 22:47:02 +00:00
|
|
|
NS_ADDREF(*aImages);
|
1998-07-22 23:32:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
|
|
|
|
{
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mApplets) {
|
2006-12-26 17:47:52 +00:00
|
|
|
mApplets = new nsContentList(this, nsGkAtoms::applet,
|
2003-04-19 00:28:09 +00:00
|
|
|
mDefaultNamespaceID);
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mApplets) {
|
1998-07-22 23:32:19 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
*aApplets = mApplets;
|
2002-05-20 22:47:02 +00:00
|
|
|
NS_ADDREF(*aApplets);
|
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
|
2004-04-15 01:51:32 +00:00
|
|
|
nsHTMLDocument::MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2006-07-18 00:18:19 +00:00
|
|
|
nsIDocument* doc = aContent->GetCurrentDoc();
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
NS_ASSERTION(aContent->IsInDoc(),
|
|
|
|
"This method should never be called on content nodes that "
|
|
|
|
"are not in a document!");
|
2005-01-23 18:21:34 +00:00
|
|
|
#ifdef DEBUG
|
2006-07-18 00:18:19 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmldoc =
|
|
|
|
do_QueryInterface(aContent->GetCurrentDoc());
|
|
|
|
NS_ASSERTION(htmldoc,
|
|
|
|
"Huh, how did this happen? This should only be used with "
|
|
|
|
"HTML documents!");
|
|
|
|
}
|
2005-01-23 18:21:34 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-18 00:18:19 +00:00
|
|
|
nsINodeInfo *ni = aContent->NodeInfo();
|
|
|
|
PRInt32 namespaceID = doc->GetDefaultNamespaceID();
|
2002-05-20 22:47:02 +00:00
|
|
|
|
2006-07-18 00:18:19 +00:00
|
|
|
nsIAtom *localName = ni->NameAtom();
|
|
|
|
if (ni->NamespaceID() == namespaceID &&
|
2006-12-26 17:47:52 +00:00
|
|
|
(localName == nsGkAtoms::a || localName == nsGkAtoms::area)) {
|
|
|
|
return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
|
2006-07-18 00:18:19 +00:00
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
return PR_FALSE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks)
|
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!mLinks) {
|
2007-02-01 15:14:00 +00:00
|
|
|
mLinks = new nsContentList(this, MatchLinks, nsnull, nsnull);
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!mLinks) {
|
1998-07-22 23:32:19 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
*aLinks = mLinks;
|
|
|
|
NS_ADDREF(*aLinks);
|
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
|
2004-04-15 01:51:32 +00:00
|
|
|
nsHTMLDocument::MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_ASSERTION(aContent->IsInDoc(),
|
|
|
|
"This method should never be called on content nodes that "
|
|
|
|
"are not in a document!");
|
2005-01-23 18:21:34 +00:00
|
|
|
#ifdef DEBUG
|
2005-09-24 18:43:15 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmldoc =
|
|
|
|
do_QueryInterface(aContent->GetCurrentDoc());
|
|
|
|
NS_ASSERTION(htmldoc,
|
|
|
|
"Huh, how did this happen? This should only be used with "
|
|
|
|
"HTML documents!");
|
|
|
|
}
|
2005-01-23 18:21:34 +00:00
|
|
|
#endif
|
2002-05-20 22:47:02 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
PRInt32 namespaceID = aContent->GetCurrentDoc()->GetDefaultNamespaceID();
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aContent->NodeInfo()->Equals(nsGkAtoms::a, namespaceID)) {
|
|
|
|
return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::name);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
return PR_FALSE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetAnchors(nsIDOMHTMLCollection** aAnchors)
|
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mAnchors) {
|
2007-02-01 15:14:00 +00:00
|
|
|
mAnchors = new nsContentList(this, MatchAnchors, nsnull, nsnull);
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!mAnchors) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
*aAnchors = 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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetCookie(nsAString& aCookie)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2002-04-12 10:11:00 +00:00
|
|
|
aCookie.Truncate(); // clear current cookie in case service fails;
|
|
|
|
// no cookie isn't an error condition.
|
|
|
|
|
2007-07-27 02:49:18 +00:00
|
|
|
if (mDisableCookieAccess) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-04 22:44:51 +00:00
|
|
|
// not having a cookie service isn't an error
|
2006-06-18 21:18:22 +00:00
|
|
|
nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2003-03-26 07:41:30 +00:00
|
|
|
if (service) {
|
|
|
|
// Get a URI from the document principal. We use the original
|
|
|
|
// codebase in case the codebase was changed by SetDomain
|
2003-10-21 22:11:49 +00:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2006-04-27 18:21:11 +00:00
|
|
|
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
2003-10-21 22:11:49 +00:00
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Document's principal is not a codebase (may be system), so
|
|
|
|
// can't set cookies
|
2002-07-02 17:58:24 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
return NS_OK;
|
2002-07-02 17:58:24 +00:00
|
|
|
}
|
|
|
|
|
2001-06-26 00:11:04 +00:00
|
|
|
nsXPIDLCString cookie;
|
2003-11-04 22:44:51 +00:00
|
|
|
service->GetCookieString(codebaseURI, mChannel, getter_Copies(cookie));
|
|
|
|
CopyASCIItoUTF16(cookie, aCookie);
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
2003-11-04 22:44:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetCookie(const nsAString& aCookie)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2007-07-27 02:49:18 +00:00
|
|
|
if (mDisableCookieAccess) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-04 22:44:51 +00:00
|
|
|
// not having a cookie service isn't an error
|
2006-06-18 21:18:22 +00:00
|
|
|
nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2004-01-09 23:54:21 +00:00
|
|
|
if (service && mDocumentURI) {
|
2001-03-29 02:11:48 +00:00
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = GetWindow();
|
2003-10-22 06:09:48 +00:00
|
|
|
if (window) {
|
|
|
|
window->GetPrompter(getter_AddRefs(prompt));
|
2001-03-29 02:11:48 +00:00
|
|
|
}
|
2002-07-02 17:58:24 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2006-04-27 18:21:11 +00:00
|
|
|
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
2003-10-21 22:11:49 +00:00
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Document's principal is not a codebase (may be system), so
|
|
|
|
// can't set cookies
|
2002-07-02 17:58:24 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
return NS_OK;
|
2002-07-02 17:58:24 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 22:44:51 +00:00
|
|
|
NS_LossyConvertUTF16toASCII cookie(aCookie);
|
|
|
|
service->SetCookieString(codebaseURI, prompt, cookie.get(), mChannel);
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
2003-11-04 22:44:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
|
1999-05-28 00:18:48 +00:00
|
|
|
// XXX TBI: accepting arguments to the open method.
|
|
|
|
nsresult
|
2005-03-02 23:17:28 +00:00
|
|
|
nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2006-05-03 21:19:26 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
// No calling document.open() on XHTML
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
2006-08-01 21:48:03 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2007-01-05 22:02:22 +00:00
|
|
|
// If we already have a parser we ignore the document.open call.
|
|
|
|
if (mParser) {
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-03 06:35:47 +00:00
|
|
|
NS_ASSERTION(nsContentUtils::CanCallerAccess(static_cast<nsIDOMHTMLDocument*>(this)),
|
|
|
|
"XOW should have caught this!");
|
2006-08-01 21:48:03 +00:00
|
|
|
|
2006-04-21 01:24:44 +00:00
|
|
|
if (!aContentType.EqualsLiteral("text/html") &&
|
|
|
|
!aContentType.EqualsLiteral("text/plain")) {
|
|
|
|
NS_WARNING("Unsupported type; fix the caller");
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
2007-06-14 18:18:05 +00:00
|
|
|
// check whether we're in the middle of unload. If so, ignore this call.
|
|
|
|
nsCOMPtr<nsIDocShell> shell = do_QueryReferent(mDocumentContainer);
|
|
|
|
if (shell) {
|
|
|
|
PRBool inUnload;
|
|
|
|
shell->GetIsInUnload(&inUnload);
|
|
|
|
if (inUnload) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-03 22:47:06 +00:00
|
|
|
// Note: We want to use GetDocumentFromContext here because this document
|
|
|
|
// should inherit the security information of the document that's opening us,
|
|
|
|
// (since if it's secure, then it's presumeably trusted).
|
2005-03-02 23:17:28 +00:00
|
|
|
nsCOMPtr<nsIDocument> callerDoc =
|
2005-11-03 22:47:06 +00:00
|
|
|
do_QueryInterface(nsContentUtils::GetDocumentFromContext());
|
2004-07-28 00:26:58 +00:00
|
|
|
|
|
|
|
// Grab a reference to the calling documents security info (if any)
|
2005-03-02 23:17:28 +00:00
|
|
|
// and principal as it may be lost in the call to Reset().
|
2004-07-28 00:26:58 +00:00
|
|
|
nsCOMPtr<nsISupports> securityInfo;
|
2005-03-02 23:17:28 +00:00
|
|
|
if (callerDoc) {
|
|
|
|
securityInfo = callerDoc->GetSecurityInfo();
|
|
|
|
}
|
|
|
|
|
2005-09-02 18:02:51 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> callerPrincipal;
|
2008-01-25 21:49:11 +00:00
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
|
|
|
|
secMan->GetSubjectPrincipal(getter_AddRefs(callerPrincipal));
|
|
|
|
|
|
|
|
if (!callerPrincipal) {
|
|
|
|
// If we're called from C++ we can't do a document.open w/o
|
|
|
|
// changing the principal of the document to something like
|
|
|
|
// about:blank (as that's the only sane thing to do when we don't
|
|
|
|
// know the origin of this call), and since we can't change the
|
|
|
|
// principals of a document for security reasons we'll have to
|
|
|
|
// refuse to go ahead with this call.
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're called from script. Make sure the script is from the same
|
|
|
|
// origin, not just that the caller can access the document. This is
|
|
|
|
// needed to keep document principals from ever changing, which is
|
|
|
|
// needed because of the way we use our XOW code, and is a sane
|
|
|
|
// thing to do anyways.
|
|
|
|
|
|
|
|
PRBool equals = PR_FALSE;
|
|
|
|
if (NS_FAILED(callerPrincipal->Equals(NodePrincipal(), &equals)) ||
|
|
|
|
!equals) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2005-09-02 18:02:51 +00:00
|
|
|
|
2005-03-02 23:17:28 +00:00
|
|
|
// The URI for the document after this call. Get it from the calling
|
|
|
|
// principal (if available), or set it to "about:blank" if no
|
|
|
|
// principal is reachable.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2008-01-25 21:49:11 +00:00
|
|
|
callerPrincipal->GetURI(getter_AddRefs(uri));
|
2004-07-28 00:26:58 +00:00
|
|
|
|
2005-08-08 03:15:56 +00:00
|
|
|
if (!uri) {
|
2005-03-02 23:17:28 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(uri),
|
|
|
|
NS_LITERAL_CSTRING("about:blank"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-07-28 00:26:58 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 20:00:24 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docshell = do_QueryReferent(mDocumentContainer);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
// Stop current loads targeted at the window this document is in.
|
2003-09-19 20:00:24 +00:00
|
|
|
if (mScriptGlobalObject && docshell) {
|
2004-02-11 06:09:51 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
|
|
|
if (cv) {
|
|
|
|
PRBool okToUnload;
|
|
|
|
rv = cv->PermitUnload(&okToUnload);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !okToUnload) {
|
|
|
|
// We don't want to unload, so stop here, but don't throw an
|
|
|
|
// exception.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-19 20:00:24 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(docshell));
|
|
|
|
webnav->Stop(nsIWebNavigation::STOP_NETWORK);
|
2000-06-08 22:51:06 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2005-03-02 23:17:28 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, group);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-08-12 22:19:55 +00:00
|
|
|
|
2006-02-02 20:02:34 +00:00
|
|
|
// Set the caller principal, if any, on the channel so that we'll
|
|
|
|
// make sure to use it when we reset.
|
|
|
|
rv = channel->SetOwner(callerPrincipal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-12-01 19:35:27 +00:00
|
|
|
// Before we reset the doc notify the globalwindow of the change,
|
|
|
|
// but only if we still have a window (i.e. our window object the
|
|
|
|
// current inner window in our outer window).
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2006-04-26 19:53:27 +00:00
|
|
|
// Hold onto ourselves on the offchance that we're down to one ref
|
|
|
|
nsCOMPtr<nsIDOMDocument> kungFuDeathGrip =
|
|
|
|
do_QueryInterface((nsIHTMLDocument*)this);
|
|
|
|
|
2005-12-01 19:35:27 +00:00
|
|
|
nsPIDOMWindow *window = GetInnerWindow();
|
|
|
|
if (window) {
|
2006-08-01 21:48:03 +00:00
|
|
|
// Remember the old scope in case the call to SetNewDocument changes it.
|
2006-04-26 19:53:27 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> oldScope(do_QueryReferent(mScopeObject));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-12-01 19:35:27 +00:00
|
|
|
rv = window->SetNewDocument(this, nsnull, PR_FALSE);
|
2006-04-26 19:53:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2006-08-15 17:31:16 +00:00
|
|
|
// Now make sure we're not flagged as the initial document anymore, now
|
|
|
|
// that we've had stuff done to us. From now on, if anyone tries to
|
|
|
|
// document.open() us, they get a new inner window.
|
|
|
|
SetIsInitialDocument(PR_FALSE);
|
|
|
|
|
2006-04-26 19:53:27 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> newScope(do_QueryReferent(mScopeObject));
|
|
|
|
if (oldScope && newScope != oldScope) {
|
2006-04-26 20:21:31 +00:00
|
|
|
nsContentUtils::ReparentContentWrappersInScope(oldScope, newScope);
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
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
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIContent> root = GetRootContent();
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
if (root) {
|
2007-12-12 02:26:09 +00:00
|
|
|
PRInt32 rootIndex = mChildren.IndexOfChild(root);
|
2005-09-30 20:06:33 +00:00
|
|
|
NS_ASSERTION(rootIndex >= 0, "Root must be in list!");
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 count = root->GetChildCount();
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
// Remove all the children from the root.
|
2003-09-27 04:18:26 +00:00
|
|
|
while (count-- > 0) {
|
2001-04-12 09:50:55 +00:00
|
|
|
root->RemoveChildAt(count, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
count = root->GetAttrCount();
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
// Remove all attributes from the root element
|
2003-09-27 04:18:26 +00:00
|
|
|
while (count-- > 0) {
|
2005-12-28 21:52:39 +00:00
|
|
|
const nsAttrName* name = root->GetAttrNameAt(count);
|
|
|
|
root->UnsetAttr(name->NamespaceID(), name->LocalName(), PR_FALSE);
|
2001-04-12 09:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the root from the childlist
|
2005-09-30 20:06:33 +00:00
|
|
|
mChildren.RemoveChildAt(rootIndex);
|
2007-12-12 02:26:09 +00:00
|
|
|
mCachedRootContent = nsnull;
|
2001-04-12 09:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
Reset(channel, group);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2001-04-12 09:50:55 +00:00
|
|
|
if (root) {
|
|
|
|
// Tear down the frames for the root element.
|
2007-10-19 16:01:09 +00:00
|
|
|
MOZ_AUTO_DOC_UPDATE(this, UPDATE_CONTENT_MODEL, PR_TRUE);
|
2006-07-02 07:23:10 +00:00
|
|
|
nsNodeUtils::ContentRemoved(this, root, 0);
|
2001-04-12 09:50:55 +00:00
|
|
|
|
|
|
|
// Put the root element back into the document, we don't notify
|
|
|
|
// the document about this insertion since the sink will do that
|
2006-02-02 20:02:34 +00:00
|
|
|
// for us 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)
|
2001-04-12 09:50:55 +00:00
|
|
|
|
2005-09-30 20:06:33 +00:00
|
|
|
mChildren.AppendChild(root);
|
2001-04-12 09:50:55 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
if (IsEditingOn()) {
|
2005-04-06 02:22:45 +00:00
|
|
|
// Reset() blows away all event listeners in the document, and our
|
|
|
|
// editor relies heavily on those. Midas is turned on, to make it
|
|
|
|
// work, re-initialize it to give it a chance to add its event
|
|
|
|
// listeners again.
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
TurnEditingOff();
|
|
|
|
EditingStateChanged();
|
2005-04-06 02:22:45 +00:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:51:46 +00:00
|
|
|
// Zap the old title -- otherwise it would hang around until document.close()
|
|
|
|
// (which might never come) if the new document doesn't explicitly set one.
|
2005-12-29 20:38:06 +00:00
|
|
|
// Void the title to make sure that we actually respect any titles set by the
|
|
|
|
// new document.
|
2005-09-30 18:51:46 +00:00
|
|
|
SetTitle(EmptyString());
|
2005-12-29 20:38:06 +00:00
|
|
|
mDocumentTitle.SetIsVoid(PR_TRUE);
|
2005-09-30 18:51:46 +00:00
|
|
|
|
2004-07-28 00:26:58 +00:00
|
|
|
// Store the security info of the caller now that we're done
|
|
|
|
// resetting the document.
|
|
|
|
mSecurityInfo = securityInfo;
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
|
|
|
|
2004-05-21 21:32:11 +00:00
|
|
|
// This will be propagated to the parser when someone actually calls write()
|
|
|
|
mContentType = aContentType;
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
mWriteState = eDocumentOpened;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-03-22 08:51:52 +00:00
|
|
|
nsCOMPtr<nsIHTMLContentSink> sink;
|
|
|
|
|
2005-03-02 23:17:28 +00:00
|
|
|
rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, uri, docshell,
|
|
|
|
channel);
|
2003-09-19 20:00:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-09-19 20:00:24 +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();
|
2004-04-28 01:40:39 +00:00
|
|
|
|
|
|
|
// Now check whether we were opened with a "replace" argument. If
|
|
|
|
// so, we need to tell the docshell to not create a new history
|
2007-07-03 21:41:32 +00:00
|
|
|
// entry for this load. Otherwise, make sure that we're doing a normal load,
|
|
|
|
// not whatever type of load was previously done on this docshell.
|
|
|
|
docshell->SetLoadType(aReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL);
|
|
|
|
|
2001-05-25 08:49:03 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv);
|
|
|
|
if (docViewer) {
|
2007-07-08 07:08:04 +00:00
|
|
|
docViewer->LoadStart(static_cast<nsIHTMLDocument *>(this));
|
2001-05-25 08:49:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
// Add a wyciwyg channel request into the document load group
|
2004-05-09 21:37:32 +00:00
|
|
|
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::OpenCommon(): wyciwyg "
|
|
|
|
"channel already exists!");
|
2005-04-06 02:22:45 +00:00
|
|
|
|
|
|
|
// In case the editor is listening and will see the new channel
|
|
|
|
// being added, make sure mWriteLevel is non-zero so that the editor
|
|
|
|
// knows that document.open/write/close() is being called on this
|
|
|
|
// document.
|
|
|
|
++mWriteLevel;
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
CreateAndAddWyciwygChannel();
|
2003-09-19 20:00:24 +00:00
|
|
|
|
2005-04-06 02:22:45 +00:00
|
|
|
--mWriteLevel;
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
return rv;
|
1999-05-28 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-05-28 00:18:48 +00:00
|
|
|
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;
|
2004-05-21 21:32:11 +00:00
|
|
|
return Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, getter_AddRefs(doc));
|
1999-05-28 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2004-05-21 21:32:11 +00:00
|
|
|
nsHTMLDocument::Open(const nsACString& aContentType, PRBool aReplace,
|
|
|
|
nsIDOMDocument** aReturn)
|
1999-05-28 00:18:48 +00:00
|
|
|
{
|
2005-03-02 23:17:28 +00:00
|
|
|
nsresult rv = OpenCommon(aContentType, aReplace);
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-01 20:54:38 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
return CallQueryInterface(this, aReturn);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::Close()
|
|
|
|
{
|
2006-05-03 21:19:26 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
// No calling document.close() on XHTML!
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-02-03 19:38:16 +00:00
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
if (mParser && mWriteState == eDocumentOpened) {
|
2006-06-19 23:51:32 +00:00
|
|
|
mPendingScripts.RemoveElement(GenerateParserKey());
|
|
|
|
|
|
|
|
mWriteState = mPendingScripts.Count() == 0
|
|
|
|
? eDocumentClosed
|
|
|
|
: ePendingClose;
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
++mWriteLevel;
|
2006-06-21 00:39:24 +00:00
|
|
|
rv = mParser->Parse(EmptyString(), mParser->GetRootContextKey(),
|
|
|
|
mContentType, PR_TRUE);
|
2003-09-27 04:18:26 +00:00
|
|
|
--mWriteLevel;
|
2006-01-24 01:25:14 +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!
|
2005-09-06 02:14:36 +00:00
|
|
|
// XXXbz as far as I can tell this may not be needed anymore; all
|
|
|
|
// the testcases in bug 57636 pass without this line... Leaving
|
|
|
|
// it be for now, though. In any case, there's no reason to do
|
|
|
|
// this if we have no presshell, since in that case none of the
|
|
|
|
// above about reusing frames applies.
|
2007-05-22 21:45:03 +00:00
|
|
|
if (GetPrimaryShell()) {
|
2005-09-06 02:14:36 +00:00
|
|
|
FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
2001-05-25 08:49:03 +00:00
|
|
|
|
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.
|
2004-05-09 21:37:32 +00:00
|
|
|
NS_ASSERTION(mWyciwygChannel, "nsHTMLDocument::Close(): Trying to remove "
|
|
|
|
"non-existent wyciwyg channel!");
|
2002-01-31 19:36:45 +00:00
|
|
|
RemoveWyciwygChannel();
|
2004-05-09 21:37:32 +00:00
|
|
|
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::Close(): "
|
|
|
|
"nsIWyciwygChannel 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
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::WriteCommon(const nsAString& aText,
|
1999-01-06 00:32:41 +00:00
|
|
|
PRBool aNewlineTerminate)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2007-02-11 00:30:20 +00:00
|
|
|
mTooDeepWriteRecursion =
|
|
|
|
(mWriteLevel > NS_MAX_DOCUMENT_WRITE_DEPTH || mTooDeepWriteRecursion);
|
|
|
|
NS_ENSURE_STATE(!mTooDeepWriteRecursion);
|
|
|
|
|
2006-05-03 21:19:26 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
// No calling document.write*() on XHTML!
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
void *key = GenerateParserKey();
|
|
|
|
if (mWriteState == eDocumentClosed ||
|
|
|
|
(mWriteState == ePendingClose &&
|
|
|
|
mPendingScripts.IndexOf(key) == kNotFound)) {
|
|
|
|
mWriteState = eDocumentClosed;
|
|
|
|
mParser->Terminate();
|
|
|
|
NS_ASSERTION(!mParser, "mParser should have been null'd out");
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
if (!mParser) {
|
|
|
|
rv = Open();
|
2004-02-11 06:09:51 +00:00
|
|
|
|
|
|
|
// If Open() fails, or if it didn't create a parser (as it won't
|
|
|
|
// if the user chose to not discard the current document through
|
|
|
|
// onbeforeunload), don't write anything.
|
|
|
|
if (NS_FAILED(rv) || !mParser) {
|
2001-05-13 00:27:58 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
static NS_NAMED_LITERAL_STRING(new_line, "\n");
|
|
|
|
|
|
|
|
// Save the data in cache
|
|
|
|
if (mWyciwygChannel) {
|
2005-06-01 16:10:58 +00:00
|
|
|
if (!aText.IsEmpty()) {
|
|
|
|
mWyciwygChannel->WriteToCacheEntry(aText);
|
|
|
|
}
|
2004-05-11 22:37:31 +00:00
|
|
|
|
|
|
|
if (aNewlineTerminate) {
|
|
|
|
mWyciwygChannel->WriteToCacheEntry(new_line);
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2002-01-31 19:36:45 +00:00
|
|
|
|
2004-05-11 22:37:31 +00:00
|
|
|
++mWriteLevel;
|
|
|
|
|
|
|
|
// This could be done with less code, but for performance reasons it
|
|
|
|
// makes sense to have the code for two separate Parse() calls here
|
|
|
|
// since the concatenation of strings costs more than we like. And
|
|
|
|
// why pay that price when we don't need to?
|
|
|
|
if (aNewlineTerminate) {
|
|
|
|
rv = mParser->Parse(aText + new_line,
|
2006-01-30 23:45:19 +00:00
|
|
|
key, mContentType,
|
2006-01-24 01:25:14 +00:00
|
|
|
(mWriteState == eNotWriting || (mWriteLevel > 1)));
|
2004-05-11 22:37:31 +00:00
|
|
|
} else {
|
|
|
|
rv = mParser->Parse(aText,
|
2006-01-30 23:45:19 +00:00
|
|
|
key, mContentType,
|
2006-01-24 01:25:14 +00:00
|
|
|
(mWriteState == eNotWriting || (mWriteLevel > 1)));
|
2004-05-11 22:37:31 +00:00
|
|
|
}
|
2002-01-31 19:36:45 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
--mWriteLevel;
|
2001-05-13 00:27:58 +00:00
|
|
|
|
2007-02-11 00:30:20 +00:00
|
|
|
mTooDeepWriteRecursion = (mWriteLevel != 0 && mTooDeepWriteRecursion);
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::Write(const nsAString& aText)
|
2001-05-13 00:27:58 +00:00
|
|
|
{
|
|
|
|
return WriteCommon(aText, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::Writeln(const nsAString& aText)
|
2001-05-13 00:27:58 +00:00
|
|
|
{
|
|
|
|
return WriteCommon(aText, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::ScriptWriteCommon(PRBool aNewlineTerminate)
|
|
|
|
{
|
2008-01-15 15:50:57 +00:00
|
|
|
nsAXPCNativeCallContext *ncc = nsnull;
|
1999-05-28 00:18:48 +00:00
|
|
|
|
2004-09-01 16:50:12 +00:00
|
|
|
nsresult rv = nsContentUtils::XPConnect()->
|
2008-01-15 15:50:57 +00:00
|
|
|
GetCurrentNativeCallContext(&ncc);
|
2004-09-01 16:50:12 +00:00
|
|
|
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 (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) {
|
2006-06-12 22:39:55 +00:00
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
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
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsDependentString str(reinterpret_cast<const PRUnichar *>
|
|
|
|
(::JS_GetStringChars(jsstr)),
|
2001-05-13 00:27:58 +00:00
|
|
|
::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
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (i = 0; i < argc; ++i) {
|
2006-06-12 22:39:55 +00:00
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
|
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);
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
string_buffer.Append(reinterpret_cast<const PRUnichar *>
|
|
|
|
(::JS_GetStringChars(str)),
|
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
|
|
|
::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...
|
2004-05-22 20:02:43 +00:00
|
|
|
return WriteCommon(EmptyString(), 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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetElementById(const nsAString& aElementId,
|
2001-03-22 08:51:52 +00:00
|
|
|
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
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsCOMPtr<nsIAtom> idAtom(do_GetAtom(aElementId));
|
|
|
|
NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2005-02-28 22:24:17 +00:00
|
|
|
// We don't have to flush before we do the initial hashtable lookup, since if
|
|
|
|
// the id is already in the hashtable it couldn't have been removed without
|
|
|
|
// us being notified (all removals notify immediately, as far as I can tell).
|
|
|
|
// So do the lookup first.
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, idAtom,
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
1998-08-07 23:08:00 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
nsIContent *e = entry->GetIdContent();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
if (!e || e == ID_NOT_IN_DOCUMENT) {
|
2005-02-28 22:24:17 +00:00
|
|
|
// Now we have to flush. It could be that we have a cached "not in
|
2005-11-09 21:52:06 +00:00
|
|
|
// document" or know nothing about this ID yet but more content has been
|
|
|
|
// added to the document since. Note that we have to flush notifications,
|
|
|
|
// so that the entry will get updated properly.
|
2005-02-28 22:24:17 +00:00
|
|
|
|
|
|
|
// Make sure to stash away the current generation so we can check whether
|
|
|
|
// the table changes when we flush.
|
|
|
|
PRUint32 generation = mIdAndNameHashTable.generation;
|
|
|
|
|
|
|
|
FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
|
|
|
|
if (generation != mIdAndNameHashTable.generation) {
|
|
|
|
// Table changed, so the entry pointer is no longer valid; look up the
|
|
|
|
// entry again, adding if necessary (the adding may be necessary in case
|
|
|
|
// the flush actually deleted entries).
|
|
|
|
entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, idAtom,
|
2005-02-28 22:24:17 +00:00
|
|
|
PL_DHASH_ADD));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
2005-08-25 05:17:06 +00:00
|
|
|
|
2005-08-27 05:16:06 +00:00
|
|
|
// We could now have a new entry, or the entry could have been
|
|
|
|
// updated, so update e to point to the current entry's
|
2005-08-25 05:17:06 +00:00
|
|
|
// mIdContent.
|
2005-11-09 21:52:06 +00:00
|
|
|
e = entry->GetIdContent();
|
2005-02-28 22:24:17 +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;
|
2005-08-25 05:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!e) {
|
2005-09-07 17:04:34 +00:00
|
|
|
// If IdTableIsLive(), no need to look for the element in the document,
|
|
|
|
// since we're fully maintaining our table's state as the DOM mutates.
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* root = GetRootContent();
|
2005-09-07 17:04:34 +00:00
|
|
|
if (!IdTableIsLive()) {
|
|
|
|
if (IdTableShouldBecomeLive()) {
|
|
|
|
// Just make sure our table is up to date and call this method again
|
|
|
|
// to look up in the hashtable.
|
2007-12-12 02:26:09 +00:00
|
|
|
if (root) {
|
|
|
|
RegisterNamedItems(root);
|
2005-09-07 17:04:34 +00:00
|
|
|
}
|
|
|
|
return GetElementById(aElementId, aReturn);
|
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
if (root && CheckGetElementByIdArg(aElementId)) {
|
|
|
|
e = nsContentUtils::MatchElementId(root, idAtom);
|
2005-09-07 17:04:34 +00:00
|
|
|
}
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!e) {
|
2005-11-09 21:52:06 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// No reason to call MatchElementId if !IdTableIsLive, since
|
|
|
|
// we'd have done just that already
|
2007-12-12 02:26:09 +00:00
|
|
|
if (IdTableIsLive() && root && !aElementId.IsEmpty()) {
|
2005-11-09 21:52:06 +00:00
|
|
|
nsIContent* eDebug =
|
2007-12-12 02:26:09 +00:00
|
|
|
nsContentUtils::MatchElementId(root, idAtom);
|
2005-11-09 21:52:06 +00:00
|
|
|
NS_ASSERTION(!eDebug,
|
|
|
|
"We got null for |e| but MatchElementId found something?");
|
|
|
|
}
|
|
|
|
#endif
|
2001-03-22 08:51:52 +00:00
|
|
|
// There is no element with the given id in the document, cache
|
|
|
|
// the fact that it's not in the document
|
2005-11-09 21:52:06 +00:00
|
|
|
entry->FlagIDNotInDocument();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found an element with a matching id, store that in the hash
|
2005-11-14 22:05:03 +00:00
|
|
|
if (NS_UNLIKELY(!entry->AddIdContent(e))) {
|
2005-11-09 21:52:06 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
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
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMAttr** aReturn)
|
|
|
|
{
|
2003-04-19 00:28:09 +00:00
|
|
|
return nsDocument::CreateAttributeNS(aNamespaceURI, aQualifiedName, aReturn);
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
|
|
|
{
|
2000-05-17 03:47:06 +00:00
|
|
|
nsAutoString tmp(aLocalName);
|
2003-04-19 00:28:09 +00:00
|
|
|
|
|
|
|
if (!IsXHTML()) {
|
|
|
|
ToLowerCase(tmp); // HTML elements are lower case internally.
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDocument::GetElementsByTagNameNS(aNamespaceURI, tmp, aReturn);
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
1999-02-04 23:23:07 +00:00
|
|
|
PRBool
|
2004-04-15 01:51:32 +00:00
|
|
|
nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
1999-02-04 23:23:07 +00:00
|
|
|
{
|
2004-04-15 01:51:32 +00:00
|
|
|
NS_PRECONDITION(aContent, "Must have content node to work with!");
|
2007-07-08 07:08:04 +00:00
|
|
|
nsString* elementName = static_cast<nsString*>(aData);
|
2007-02-01 15:14:00 +00:00
|
|
|
return aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
*elementName, eCaseMatters);
|
1999-02-04 23:23:07 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetElementsByName(const nsAString& aElementName,
|
1999-02-04 23:23:07 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2007-02-01 15:14:00 +00:00
|
|
|
void* elementNameData = new nsString(aElementName);
|
|
|
|
NS_ENSURE_TRUE(elementNameData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsContentList* elements =
|
|
|
|
new nsContentList(this,
|
|
|
|
MatchNameAttribute,
|
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
elementNameData);
|
2001-03-22 08:51:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::ScriptLoading(nsIScriptElement *aScript)
|
|
|
|
{
|
|
|
|
if (mWriteState == eNotWriting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingScripts.AppendElement(aScript);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::ScriptExecuted(nsIScriptElement *aScript)
|
|
|
|
{
|
|
|
|
if (mWriteState == eNotWriting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingScripts.RemoveElement(aScript);
|
|
|
|
if (mPendingScripts.Count() == 0 && mWriteState == ePendingClose) {
|
|
|
|
// The last pending script just finished, terminate our parser now.
|
|
|
|
mWriteState = eDocumentClosed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
void
|
2002-07-16 22:38:51 +00:00
|
|
|
nsHTMLDocument::AddedForm()
|
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
++mNumForms;
|
2002-07-16 22:38:51 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
void
|
2002-07-16 22:38:51 +00:00
|
|
|
nsHTMLDocument::RemovedForm()
|
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
--mNumForms;
|
2002-07-16 22:38:51 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
PRInt32
|
|
|
|
nsHTMLDocument::GetNumFormsSynchronous()
|
2002-07-16 22:38:51 +00:00
|
|
|
{
|
2004-02-03 23:23:10 +00:00
|
|
|
return mNumForms;
|
2002-07-16 22:38:51 +00:00
|
|
|
}
|
|
|
|
|
2000-08-16 01:04:52 +00:00
|
|
|
nsresult
|
2007-05-23 03:52:53 +00:00
|
|
|
nsHTMLDocument::GetBodySize(PRInt32* aWidth,
|
|
|
|
PRInt32* aHeight)
|
2000-08-16 01:04:52 +00:00
|
|
|
{
|
|
|
|
*aWidth = *aHeight = 0;
|
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
FlushPendingNotifications(Flush_Layout);
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2007-05-23 03:52:53 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
|
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return NS_OK;
|
|
|
|
|
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.
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* body = GetBodyContent();
|
|
|
|
if (!body) {
|
2006-03-23 08:21:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-16 01:04:52 +00:00
|
|
|
// Now grab its frame
|
2007-05-23 03:52:53 +00:00
|
|
|
nsIFrame* frame = shell->GetPrimaryFrameFor(body);
|
|
|
|
if (!frame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsSize size = frame->GetSize();
|
2000-08-16 01:04:52 +00:00
|
|
|
|
2007-05-23 03:52:53 +00:00
|
|
|
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
|
|
|
|
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height);
|
2000-08-16 01:04:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-16 01:04:52 +00:00
|
|
|
nsHTMLDocument::GetWidth(PRInt32* aWidth)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
|
2007-05-23 03:52:53 +00:00
|
|
|
PRInt32 height;
|
|
|
|
return GetBodySize(aWidth, &height);
|
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);
|
|
|
|
|
2007-05-23 03:52:53 +00:00
|
|
|
PRInt32 width;
|
|
|
|
return GetBodySize(&width, 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
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetAlinkColor(nsAString& aAlinkColor)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
1999-07-07 04:52:27 +00:00
|
|
|
aAlinkColor.Truncate();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (body) {
|
|
|
|
body->GetALink(aAlinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
1999-07-07 04:52:27 +00:00
|
|
|
nscolor color;
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv = mAttrStyleSheet->GetActiveLinkColor(color);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_RGBToHex(color, aAlinkColor);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetAlinkColor(const nsAString& aAlinkColor)
|
1998-08-04 00:05:22 +00:00
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
1999-02-04 02:58:02 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetALink(aAlinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue value;
|
2003-01-21 21:24:16 +00:00
|
|
|
if (value.ParseColor(aAlinkColor, this)) {
|
2004-02-11 00:09:59 +00:00
|
|
|
nscolor color;
|
|
|
|
value.GetColorValue(color);
|
|
|
|
mAttrStyleSheet->SetActiveLinkColor(color);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetLinkColor(nsAString& aLinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-07-07 04:52:27 +00:00
|
|
|
aLinkColor.Truncate();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (body) {
|
|
|
|
body->GetLink(aLinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
1999-07-07 04:52:27 +00:00
|
|
|
nscolor color;
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv = mAttrStyleSheet->GetLinkColor(color);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_RGBToHex(color, aLinkColor);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetLinkColor(const nsAString& aLinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
1999-02-04 02:58:02 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetLink(aLinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue value;
|
2003-01-21 21:24:16 +00:00
|
|
|
if (value.ParseColor(aLinkColor, this)) {
|
2004-02-11 00:09:59 +00:00
|
|
|
nscolor color;
|
|
|
|
value.GetColorValue(color);
|
|
|
|
mAttrStyleSheet->SetLinkColor(color);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetVlinkColor(nsAString& aVlinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-07-07 04:52:27 +00:00
|
|
|
aVlinkColor.Truncate();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (body) {
|
|
|
|
body->GetVLink(aVlinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
1999-07-07 04:52:27 +00:00
|
|
|
nscolor color;
|
2003-03-26 07:41:30 +00:00
|
|
|
nsresult rv = mAttrStyleSheet->GetVisitedLinkColor(color);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_RGBToHex(color, aVlinkColor);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetVlinkColor(const nsAString& aVlinkColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
1999-02-04 02:58:02 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetVLink(aVlinkColor);
|
|
|
|
} else if (mAttrStyleSheet) {
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue value;
|
2003-01-21 21:24:16 +00:00
|
|
|
if (value.ParseColor(aVlinkColor, this)) {
|
2004-02-11 00:09:59 +00:00
|
|
|
nscolor color;
|
|
|
|
value.GetColorValue(color);
|
|
|
|
mAttrStyleSheet->SetVisitedLinkColor(color);
|
1999-07-07 04:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetBgColor(nsAString& aBgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-07-07 04:52:27 +00:00
|
|
|
aBgColor.Truncate();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (body) {
|
|
|
|
body->GetBgColor(aBgColor);
|
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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetBgColor(const nsAString& aBgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
1999-02-04 02:58:02 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetBgColor(aBgColor);
|
1999-02-04 02:58:02 +00:00
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
// XXXldb And otherwise?
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-07-07 04:52:27 +00:00
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetFgColor(nsAString& aFgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
1999-07-07 04:52:27 +00:00
|
|
|
aFgColor.Truncate();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (body) {
|
|
|
|
body->GetText(aFgColor);
|
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
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::SetFgColor(const nsAString& aFgColor)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLBodyElement> body = do_QueryInterface(GetBodyContent());
|
1999-02-04 02:58:02 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetText(aFgColor);
|
1999-02-04 02:58:02 +00:00
|
|
|
}
|
2002-01-07 23:46:07 +00:00
|
|
|
// XXXldb And otherwise?
|
2003-03-26 07:41:30 +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
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-07 23:08:00 +00:00
|
|
|
nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
|
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mEmbeds) {
|
2006-12-26 17:47:52 +00:00
|
|
|
mEmbeds = new nsContentList(this, nsGkAtoms::embed, mDefaultNamespaceID);
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!mEmbeds) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-09-25 00:51:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
*aEmbeds = mEmbeds;
|
|
|
|
NS_ADDREF(*aEmbeds);
|
1998-09-25 00:51:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetSelection(nsAString& 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"));
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-01-23 07:45:08 +00:00
|
|
|
if (consoleService) {
|
|
|
|
consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get());
|
|
|
|
}
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2001-01-23 07:45:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-04-10 17:04:54 +00:00
|
|
|
static void
|
|
|
|
ReportUseOfDeprecatedMethod(nsHTMLDocument* aDoc, const char* aWarning)
|
|
|
|
{
|
|
|
|
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
aWarning,
|
|
|
|
nsnull, 0,
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsIDocument*>(aDoc)->
|
2006-04-10 17:04:54 +00:00
|
|
|
GetDocumentURI(),
|
|
|
|
EmptyString(), 0, 0,
|
|
|
|
nsIScriptError::warningFlag,
|
2006-04-11 17:05:25 +00:00
|
|
|
"DOM Events");
|
2006-04-10 17:04:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-21 14:18:52 +00:00
|
|
|
nsHTMLDocument::CaptureEvents(PRInt32 aEventFlags)
|
|
|
|
{
|
2006-04-10 17:04:54 +00:00
|
|
|
ReportUseOfDeprecatedMethod(this, "UseOfCaptureEventsWarning");
|
|
|
|
return NS_OK;
|
1999-09-21 14:18:52 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-21 14:18:52 +00:00
|
|
|
nsHTMLDocument::ReleaseEvents(PRInt32 aEventFlags)
|
|
|
|
{
|
2006-04-10 17:04:54 +00:00
|
|
|
ReportUseOfDeprecatedMethod(this, "UseOfReleaseEventsWarning");
|
|
|
|
return NS_OK;
|
1999-09-21 14:18:52 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-21 14:18:52 +00:00
|
|
|
nsHTMLDocument::RouteEvent(nsIDOMEvent* aEvt)
|
|
|
|
{
|
2006-04-10 17:04:54 +00:00
|
|
|
ReportUseOfDeprecatedMethod(this, "UseOfRouteEventWarning");
|
1999-09-21 14:18:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-10 07:36:19 +00:00
|
|
|
// readonly attribute DOMString compatMode;
|
2002-06-25 21:16:17 +00:00
|
|
|
// Returns "BackCompat" if we are in quirks mode, "CSS1Compat" if we are
|
|
|
|
// in almost standards or full standards mode. See bug 105640. This was
|
|
|
|
// implemented to match MSIE's compatMode property
|
2001-11-10 07:36:19 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::GetCompatMode(nsAString& aCompatMode)
|
2001-11-10 07:36:19 +00:00
|
|
|
{
|
2002-06-25 21:16:17 +00:00
|
|
|
NS_ASSERTION(mCompatMode == eCompatibility_NavQuirks ||
|
|
|
|
mCompatMode == eCompatibility_AlmostStandards ||
|
|
|
|
mCompatMode == eCompatibility_FullStandards,
|
|
|
|
"mCompatMode is neither quirks nor strict for this document");
|
2001-11-10 07:36:19 +00:00
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
if (mCompatMode == eCompatibility_NavQuirks) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aCompatMode.AssignLiteral("BackCompat");
|
2001-11-10 07:36:19 +00:00
|
|
|
} else {
|
2004-06-17 00:13:25 +00:00
|
|
|
aCompatMode.AssignLiteral("CSS1Compat");
|
2001-11-10 07:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-21 12:15:34 +00:00
|
|
|
// Mapped to document.embeds for NS4 compatibility
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins)
|
|
|
|
{
|
|
|
|
*aPlugins = nsnull;
|
|
|
|
|
|
|
|
return GetEmbeds(aPlugins);
|
|
|
|
}
|
|
|
|
|
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
|
2005-11-16 02:55:29 +00:00
|
|
|
ReserveNameInHash(const char* aName, PLDHashTable *aHash)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2005-11-16 02:55:29 +00:00
|
|
|
nsCOMPtr<nsIAtom> atom(do_GetAtom(aName));
|
|
|
|
NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(aHash, atom, PL_DHASH_ADD));
|
2002-01-25 06:37:35 +00:00
|
|
|
|
2004-05-07 20:02:40 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
entry->mNameContentList = NAME_NOT_VALID;
|
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;
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("write", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("writeln", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("open", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("close", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("forms", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("elements", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("characterSet", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("nodeType", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("parentNode", &mIdAndNameHashTable);
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
rv = ReserveNameInHash("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
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
static nsIAtom*
|
|
|
|
IsNamedItem(nsIContent* aContent)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
|
|
|
// Only the content types reflected in Level 0 with a NAME
|
2003-03-26 07:41:30 +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).
|
2005-11-16 02:55:29 +00:00
|
|
|
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
|
|
|
|
if (!elm) {
|
|
|
|
return nsnull;
|
1999-05-17 21:17:48 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* tag = elm->Tag();
|
2006-12-26 17:47:52 +00:00
|
|
|
if (tag != nsGkAtoms::img &&
|
|
|
|
tag != nsGkAtoms::form &&
|
|
|
|
tag != nsGkAtoms::applet &&
|
|
|
|
tag != nsGkAtoms::embed &&
|
|
|
|
tag != nsGkAtoms::object) {
|
2005-11-16 02:55:29 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
|
2005-11-16 02:55:29 +00:00
|
|
|
if (val && val->Type() == nsAttrValue::eAtom) {
|
|
|
|
return val->GetAtomValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
nsresult
|
2005-11-16 02:55:29 +00:00
|
|
|
nsHTMLDocument::UpdateNameTableEntry(nsIAtom* aName,
|
2002-01-25 06:37:35 +00:00
|
|
|
nsIContent *aContent)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2005-09-04 18:16:58 +00:00
|
|
|
NS_ASSERTION(!IsXHTML(),
|
|
|
|
"nsHTMLDocument::UpdateNameTableEntry Don't call me on an XHTML document!!!");
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, aName,
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
2003-08-05 20:09:21 +00:00
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
|
2002-01-25 06:37:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
nsBaseContentList *list = entry->mNameContentList;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2004-05-07 20:02:40 +00:00
|
|
|
if (!list || list == NAME_NOT_VALID) {
|
2001-03-22 08:51:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
// NOTE: this indexof is absolutely needed, since we don't flush
|
|
|
|
// content notifications when we do document.foo resolution. So
|
|
|
|
// aContent may be in our list already and just now getting notified
|
|
|
|
// for!
|
2003-09-27 04:18:26 +00:00
|
|
|
if (list->IndexOf(aContent, PR_FALSE) < 0) {
|
2001-03-22 08:51:52 +00:00
|
|
|
list->AppendElement(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2005-11-16 02:55:29 +00:00
|
|
|
nsHTMLDocument::UpdateIdTableEntry(nsIAtom* aId, nsIContent *aContent)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2005-09-07 17:04:34 +00:00
|
|
|
PRBool liveTable = IdTableIsLive();
|
|
|
|
PLDHashOperator op = liveTable ? PL_DHASH_ADD : PL_DHASH_LOOKUP;
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, aId,
|
2005-09-07 17:04:34 +00:00
|
|
|
op));
|
2002-01-25 06:37:35 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry) &&
|
2005-11-14 22:05:03 +00:00
|
|
|
NS_UNLIKELY(!entry->AddIdContent(aContent))) {
|
2005-11-09 21:52:06 +00:00
|
|
|
// failed to update...
|
2005-09-08 18:39:12 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2005-11-16 02:55:29 +00:00
|
|
|
nsHTMLDocument::RemoveFromNameTable(nsIAtom* aName, nsIContent *aContent)
|
2002-01-25 06:37:35 +00:00
|
|
|
{
|
2005-09-04 18:16:58 +00:00
|
|
|
NS_ASSERTION(!IsXHTML(),
|
|
|
|
"nsHTMLDocument::RemoveFromNameTable Don't call me on an XHTML document!!!");
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, aName,
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHASH_LOOKUP));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mNameContentList &&
|
|
|
|
entry->mNameContentList != NAME_NOT_VALID) {
|
|
|
|
entry->mNameContentList->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
|
|
|
{
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* id = aContent->GetID();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (!id) {
|
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
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
IdAndNameMapEntry *entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, id,
|
2002-01-25 06:37:35 +00:00
|
|
|
PL_DHASH_LOOKUP));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
|
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
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
if (entry->RemoveIdContent(aContent)) {
|
|
|
|
PL_DHashTableRawRemove(&mIdAndNameHashTable, entry);
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::UnregisterNamedItems(nsIContent *aContent)
|
|
|
|
{
|
2006-05-05 06:52:21 +00:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
|
2001-03-22 08:51:52 +00:00
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (!IsXHTML()) {
|
|
|
|
nsIAtom* name = IsNamedItem(aContent);
|
|
|
|
if (name) {
|
|
|
|
rv = RemoveFromNameTable(name, aContent);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = RemoveFromIdTable(aContent);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, count = aContent->GetChildCount();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
UnregisterNamedItems(aContent->GetChildAt(i));
|
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
|
|
|
{
|
2006-05-05 06:52:21 +00:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
|
2001-03-22 08:51:52 +00:00
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (!IsXHTML()) {
|
|
|
|
nsIAtom* name = IsNamedItem(aContent);
|
|
|
|
if (name) {
|
|
|
|
UpdateNameTableEntry(name, aContent);
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsIAtom* id = aContent->GetID();
|
|
|
|
if (id) {
|
|
|
|
nsresult rv = UpdateIdTableEntry(id, aContent);
|
2003-10-21 16:16:42 +00:00
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, count = aContent->GetChildCount();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
RegisterNamedItems(aContent->GetChildAt(i));
|
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
|
2005-11-16 02:55:29 +00:00
|
|
|
FindNamedItems(nsIAtom* aName, nsIContent *aContent,
|
2003-04-19 00:28:09 +00:00
|
|
|
IdAndNameMapEntry& aEntry, PRBool aIsXHTML)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2005-11-09 21:52:06 +00:00
|
|
|
NS_ASSERTION(aEntry.mNameContentList,
|
2002-01-25 06:37:35 +00:00
|
|
|
"Entry w/o content list passed to FindNamedItems()!");
|
2005-11-09 21:52:06 +00:00
|
|
|
NS_ASSERTION(aEntry.mNameContentList != NAME_NOT_VALID,
|
2004-05-07 20:02:40 +00:00
|
|
|
"Entry that should never have a list passed to FindNamedItems()!");
|
1998-11-28 23:51:06 +00:00
|
|
|
|
2006-05-05 06:52:21 +00:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
|
2001-03-22 08:51:52 +00:00
|
|
|
// Text nodes are not named items nor can they have children.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (!aIsXHTML && aName == IsNamedItem(aContent)) {
|
2005-11-09 21:52:06 +00:00
|
|
|
aEntry.mNameContentList->AppendElement(aContent);
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
if (!aEntry.GetIdContent() &&
|
|
|
|
// Maybe this node has the right id?
|
|
|
|
aName == aContent->GetID()) {
|
|
|
|
aEntry.AddIdContent(aContent);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, count = aContent->GetChildCount();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
FindNamedItems(aName, aContent->GetChildAt(i), aEntry, aIsXHTML);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-03 23:23:10 +00:00
|
|
|
nsresult
|
2002-03-23 23:13:20 +00:00
|
|
|
nsHTMLDocument::ResolveName(const nsAString& aName,
|
2001-03-22 08:51:52 +00:00
|
|
|
nsIDOMHTMLFormElement *aForm,
|
|
|
|
nsISupports **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
2003-04-19 00:28:09 +00:00
|
|
|
if (IsXHTML()) {
|
|
|
|
// We don't dynamically resolve names on XHTML documents.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-16 02:55:29 +00:00
|
|
|
nsCOMPtr<nsIAtom> name(do_GetAtom(aName));
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
// 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 =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, name,
|
2007-12-21 13:44:58 +00:00
|
|
|
PL_DHASH_ADD));
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
if (entry->mNameContentList == NAME_NOT_VALID) {
|
2004-05-07 20:02:40 +00:00
|
|
|
// There won't be any named items by this name -- it's reserved
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we know we _might_ have items. Before looking at
|
2005-11-09 21:52:06 +00:00
|
|
|
// entry->mNameContentList, make sure to flush out content (see
|
2004-05-07 20:02:40 +00:00
|
|
|
// bug 69826).
|
|
|
|
// This is a perf killer while the document is loading!
|
2004-05-08 06:07:04 +00:00
|
|
|
|
|
|
|
// Make sure to stash away the current generation so we can check whether the
|
|
|
|
// table changes when we flush.
|
|
|
|
PRUint32 generation = mIdAndNameHashTable.generation;
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
// If we already have an entry->mNameContentList, we need to flush out
|
2005-02-28 22:24:17 +00:00
|
|
|
// notifications too, so that it will get updated properly.
|
2005-11-09 21:52:06 +00:00
|
|
|
FlushPendingNotifications(entry->mNameContentList ?
|
2007-12-21 13:44:58 +00:00
|
|
|
Flush_ContentAndNotify : Flush_Content);
|
2004-05-07 20:02:40 +00:00
|
|
|
|
2004-05-08 06:07:04 +00:00
|
|
|
if (generation != mIdAndNameHashTable.generation) {
|
|
|
|
// Table changed, so the entry pointer is no longer valid; look up the
|
|
|
|
// entry again, adding if necessary (the adding may be necessary in case
|
|
|
|
// the flush actually deleted entries).
|
|
|
|
entry =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, name,
|
2007-12-21 13:44:58 +00:00
|
|
|
PL_DHASH_ADD));
|
2004-05-08 06:07:04 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
nsBaseContentList *list = entry->mNameContentList;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
#ifdef DEBUG_jst
|
|
|
|
{
|
|
|
|
printf ("nsHTMLDocument name cache miss for name '%s'\n",
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
list = new nsBaseContentList();
|
|
|
|
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
entry->mNameContentList = list;
|
|
|
|
NS_ADDREF(entry->mNameContentList);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
if (root && !aName.IsEmpty()) {
|
2003-04-19 00:28:09 +00:00
|
|
|
// We'll never get here if !IsXHTML(), so we can just pass
|
|
|
|
// PR_FALSE to FindNamedItems().
|
2007-12-12 02:26:09 +00:00
|
|
|
FindNamedItems(name, root, *entry, PR_FALSE);
|
2001-07-17 13:53:15 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
list->GetLength(&length);
|
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
if (length > 0) {
|
2002-01-25 06:37:35 +00:00
|
|
|
if (length == 1) {
|
2003-07-15 02:07:55 +00:00
|
|
|
// Only one element in the list, return the element instead of
|
2002-01-25 06:37:35 +00:00
|
|
|
// 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
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
nsCOMPtr<nsIContent> ourContent(do_QueryInterface(node));
|
|
|
|
if (aForm && ourContent &&
|
|
|
|
!nsContentUtils::BelongsInForm(aForm, ourContent)) {
|
|
|
|
// This is not the content you are looking for
|
|
|
|
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
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
// The list contains more than one element, return the whole
|
|
|
|
// list, unless...
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
if (aForm) {
|
|
|
|
// ... we're called from a form, in that case we create a
|
2005-11-09 21:52:06 +00:00
|
|
|
// nsFormNameContentList which will filter out the elements in the
|
2003-07-15 02:07:55 +00:00
|
|
|
// list that don't belong to aForm
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +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
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
PRUint32 len;
|
|
|
|
fc_list->GetLength(&len);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
if (len < 2) {
|
|
|
|
// After the nsFormContentList is done filtering there's either
|
|
|
|
// nothing 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
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
fc_list->Item(0, getter_AddRefs(node));
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
NS_IF_ADDREF(*aResult = node);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
delete fc_list;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
return NS_OK;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
list = fc_list;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
2003-07-15 02:07:55 +00:00
|
|
|
|
|
|
|
return CallQueryInterface(list, 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
|
2005-11-09 21:52:06 +00:00
|
|
|
// the id aName, it'll be entry's IdContent.
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2005-11-09 21:52:06 +00:00
|
|
|
nsIContent *e = entry->GetIdContent();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2006-05-05 06:52:21 +00:00
|
|
|
if (e && e != ID_NOT_IN_DOCUMENT && e->IsNodeOfType(nsINode::eHTML)) {
|
2003-11-19 01:20:56 +00:00
|
|
|
nsIAtom *tag = e->Tag();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if ((tag == nsGkAtoms::embed ||
|
|
|
|
tag == nsGkAtoms::img ||
|
|
|
|
tag == nsGkAtoms::object ||
|
|
|
|
tag == nsGkAtoms::applet) &&
|
2004-01-06 17:14:58 +00:00
|
|
|
(!aForm || nsContentUtils::BelongsInForm(aForm, e))) {
|
2003-07-15 02:07:55 +00:00
|
|
|
NS_ADDREF(*aResult = e);
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent*
|
1998-11-12 22:25:51 +00:00
|
|
|
nsHTMLDocument::GetBodyContent()
|
|
|
|
{
|
2007-12-12 02:26:09 +00:00
|
|
|
// Loop backwards because any non-elements, such as doctypes and PIs
|
|
|
|
// are likely to appear before the root element.
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = mChildren.ChildCount(); i > 0; --i) {
|
|
|
|
nsIContent* html = mChildren.ChildAt(i - 1);
|
|
|
|
if (html->Tag() == nsGkAtoms::html &&
|
|
|
|
html->IsNodeOfType(nsINode::eHTML)) {
|
|
|
|
|
|
|
|
// Look for body inside html
|
|
|
|
for (i = html->GetChildCount(); i > 0; --i) {
|
|
|
|
nsIContent* body = html->GetChildAt(i - 1);
|
|
|
|
if (body->Tag() == nsGkAtoms::body &&
|
|
|
|
body->IsNodeOfType(nsINode::eHTML)) {
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
2006-03-23 08:21:21 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
break;
|
1998-11-12 22:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-14 22:37:22 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
return nsnull;
|
1999-02-04 23:23:07 +00:00
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// forms related stuff
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-23 17:16:51 +00:00
|
|
|
nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms)
|
|
|
|
{
|
2005-02-02 23:16:02 +00:00
|
|
|
nsContentList *forms = nsHTMLDocument::GetForms();
|
|
|
|
if (!forms)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-09-23 17:16:51 +00:00
|
|
|
|
2005-02-02 23:16:02 +00:00
|
|
|
NS_ADDREF(*aForms = forms);
|
1998-09-23 17:16:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-02 23:16:02 +00:00
|
|
|
nsContentList*
|
|
|
|
nsHTMLDocument::GetForms()
|
|
|
|
{
|
|
|
|
if (!mForms)
|
2006-12-26 17:47:52 +00:00
|
|
|
mForms = new nsContentList(this, nsGkAtoms::form, mDefaultNamespaceID);
|
2005-02-02 23:16:02 +00:00
|
|
|
|
|
|
|
return mForms;
|
|
|
|
}
|
|
|
|
|
2006-06-08 04:28:20 +00:00
|
|
|
static PRBool MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
2006-06-08 04:28:20 +00:00
|
|
|
{
|
|
|
|
return aContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentList*
|
|
|
|
nsHTMLDocument::GetFormControls()
|
|
|
|
{
|
|
|
|
if (!mFormControls) {
|
2007-02-01 15:14:00 +00:00
|
|
|
mFormControls = new nsContentList(this, MatchFormControls, nsnull, nsnull);
|
2006-06-08 04:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mFormControls;
|
|
|
|
}
|
2001-05-25 08:49:03 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-01-31 19:36:45 +00:00
|
|
|
nsHTMLDocument::CreateAndAddWyciwygChannel(void)
|
2003-03-26 07:41:30 +00:00
|
|
|
{
|
2001-05-25 08:49:03 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString url, originalSpec;
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
mDocumentURI->GetSpec(originalSpec);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
// Generate the wyciwyg url
|
2002-03-06 07:48:55 +00:00
|
|
|
url = NS_LITERAL_CSTRING("wyciwyg://")
|
2003-05-28 22:12:16 +00:00
|
|
|
+ nsPrintfCString("%d", gWyciwygSessionCnt++)
|
2002-03-06 07:48:55 +00:00
|
|
|
+ NS_LITERAL_CSTRING("/")
|
|
|
|
+ originalSpec;
|
2002-01-31 19:36:45 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> wcwgURI;
|
|
|
|
NS_NewURI(getter_AddRefs(wcwgURI), url);
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// Create the nsIWyciwygChannel to store out-of-band
|
|
|
|
// document.write() script to cache
|
2002-01-31 19:36:45 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
// Create a wyciwyg Channel
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel), wcwgURI);
|
2004-07-28 00:26:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mWyciwygChannel = do_QueryInterface(channel);
|
|
|
|
|
|
|
|
mWyciwygChannel->SetSecurityInfo(mSecurityInfo);
|
|
|
|
|
2007-05-09 02:47:58 +00:00
|
|
|
// Note: we want to treat this like a "previous document" hint so that,
|
|
|
|
// e.g. a <meta> tag in the document.write content can override it.
|
2007-08-11 18:37:16 +00:00
|
|
|
SetDocumentCharacterSetSource(kCharsetFromHintPrevDoc);
|
2007-05-09 02:47:58 +00:00
|
|
|
mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc,
|
|
|
|
GetDocumentCharacterSet());
|
|
|
|
|
2007-01-26 04:37:16 +00:00
|
|
|
// Use our new principal
|
|
|
|
channel->SetOwner(NodePrincipal());
|
|
|
|
|
2004-07-28 00:26:58 +00:00
|
|
|
// Inherit load flags from the original document's channel
|
|
|
|
channel->SetLoadFlags(mLoadFlags);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
|
2001-05-25 08:49:03 +00:00
|
|
|
|
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);
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
channel->GetLoadFlags(&loadFlags);
|
|
|
|
loadFlags |= nsIChannel::LOAD_DOCUMENT_URI;
|
|
|
|
channel->SetLoadFlags(loadFlags);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
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);
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to add request to load group.");
|
2001-05-25 08:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-31 19:36:45 +00:00
|
|
|
nsHTMLDocument::RemoveWyciwygChannel(void)
|
2001-05-25 08:49:03 +00:00
|
|
|
{
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
|
2001-05-25 08:49:03 +00:00
|
|
|
|
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) {
|
2003-01-18 02:15:14 +00:00
|
|
|
mWyciwygChannel->CloseCacheEntry(NS_OK);
|
2006-06-26 16:50:09 +00:00
|
|
|
loadGroup->RemoveRequest(mWyciwygChannel, nsnull, NS_OK);
|
2001-05-25 08:49:03 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
mWyciwygChannel = nsnull;
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2006-06-26 16:50:09 +00:00
|
|
|
return NS_OK;
|
2001-05-25 08:49:03 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2005-06-07 19:21:05 +00:00
|
|
|
void *
|
|
|
|
nsHTMLDocument::GenerateParserKey(void)
|
|
|
|
{
|
2005-09-22 23:01:33 +00:00
|
|
|
if (!mScriptLoader) {
|
|
|
|
// If we don't have a script loader, then the parser probably isn't parsing
|
|
|
|
// anything anyway, so just return null.
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2005-06-07 19:21:05 +00:00
|
|
|
// The script loader provides us with the currently executing script element,
|
|
|
|
// which is guaranteed to be unique per script.
|
2006-11-04 05:45:02 +00:00
|
|
|
return mScriptLoader->GetCurrentScript();
|
2005-06-07 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
/* attribute DOMString designMode; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetDesignMode(nsAString & aDesignMode)
|
|
|
|
{
|
2007-06-28 02:48:16 +00:00
|
|
|
if (HasFlag(NODE_IS_EDITABLE)) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aDesignMode.AssignLiteral("on");
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 00:13:25 +00:00
|
|
|
aDesignMode.AssignLiteral("off");
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-26 10:30:44 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::EndUpdate(nsUpdateType aUpdateType)
|
|
|
|
{
|
|
|
|
nsDocument::EndUpdate(aUpdateType);
|
|
|
|
|
2007-10-29 18:22:48 +00:00
|
|
|
if (mUpdateNestLevel == 0 && mContentEditableCount > 0 != IsEditingOn()) {
|
2007-10-26 10:30:44 +00:00
|
|
|
EditingStateChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::ChangeContentEditableCount(nsIContent *aElement,
|
|
|
|
PRInt32 aChange)
|
2007-06-27 22:29:45 +00:00
|
|
|
{
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ASSERTION(mContentEditableCount + aChange >= 0,
|
|
|
|
"Trying to decrement too much.");
|
|
|
|
|
|
|
|
mContentEditableCount += aChange;
|
|
|
|
|
2007-10-26 10:30:44 +00:00
|
|
|
if (mParser ||
|
2007-10-29 18:22:48 +00:00
|
|
|
(mUpdateNestLevel > 0 && mContentEditableCount > 0 != IsEditingOn())) {
|
2007-06-28 02:48:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditingState oldState = mEditingState;
|
|
|
|
|
|
|
|
nsresult rv = EditingStateChanged();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (oldState == mEditingState && mEditingState == eContentEditable) {
|
|
|
|
// We just changed the contentEditable state of a node, we need to reset
|
|
|
|
// the spellchecking state of that node.
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
|
|
|
|
if (node) {
|
|
|
|
nsPIDOMWindow *window = GetWindow();
|
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIDocShell *docshell = window->GetDocShell();
|
|
|
|
if (!docshell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell =
|
|
|
|
do_QueryInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2007-07-18 09:44:22 +00:00
|
|
|
editorDocShell->GetEditor(getter_AddRefs(editor));
|
|
|
|
if (editor) {
|
2007-07-18 09:46:41 +00:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
rv = NS_NewRange(getter_AddRefs(range));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-07-18 09:46:41 +00:00
|
|
|
rv = range->SelectNode(node);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-07-18 09:46:41 +00:00
|
|
|
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
|
|
|
|
rv = editor->GetInlineSpellChecker(PR_FALSE,
|
|
|
|
getter_AddRefs(spellChecker));
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-18 09:46:41 +00:00
|
|
|
|
|
|
|
if (spellChecker) {
|
|
|
|
rv = spellChecker->SpellCheckRange(range);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-26 00:36:19 +00:00
|
|
|
static PRBool
|
|
|
|
DocAllResultMatch(nsIContent* aContent, PRInt32 aNamespaceID, nsIAtom* aAtom,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
if (aContent->GetID() == aAtom) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
|
|
|
|
if (!elm || aContent->GetNameSpaceID() != kNameSpaceID_None) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* tag = elm->Tag();
|
|
|
|
if (tag != nsGkAtoms::img &&
|
|
|
|
tag != nsGkAtoms::form &&
|
|
|
|
tag != nsGkAtoms::applet &&
|
|
|
|
tag != nsGkAtoms::embed &&
|
|
|
|
tag != nsGkAtoms::object &&
|
|
|
|
tag != nsGkAtoms::input) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
|
|
|
|
return val && val->Type() == nsAttrValue::eAtom &&
|
|
|
|
val->GetAtomValue() == aAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::GetDocumentAllResult(const nsAString& aID, nsISupports** aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
PLDHashOperator op = IdTableIsLive() ? PL_DHASH_LOOKUP : PL_DHASH_ADD;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> id = do_GetAtom(aID);
|
|
|
|
IdAndNameMapEntry *entry =
|
|
|
|
static_cast<IdAndNameMapEntry *>
|
|
|
|
(PL_DHashTableOperate(&mIdAndNameHashTable, id, op));
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// If we did a lookup and it failed, there are no items with this id
|
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
|
|
|
|
NS_ASSERTION(IdTableIsLive(), "should have gotten a busy entry");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
if (!root) {
|
2007-07-26 00:36:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry->mDocAllList) {
|
2007-12-12 02:26:09 +00:00
|
|
|
entry->mDocAllList = new nsContentList(root, DocAllResultMatch,
|
2007-07-26 00:36:19 +00:00
|
|
|
nsnull, nsnull, PR_TRUE, id);
|
|
|
|
NS_ENSURE_TRUE(entry->mDocAllList, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there are more than 1 entries. Do this by getting the second one
|
|
|
|
// rather than the length since getting the length always requires walking
|
|
|
|
// the entire document.
|
|
|
|
|
|
|
|
nsIContent* cont = entry->mDocAllList->Item(1, PR_TRUE);
|
|
|
|
if (cont) {
|
|
|
|
NS_ADDREF(*aResult = static_cast<nsIDOMNodeList*>(entry->mDocAllList));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's only 0 or 1 items. Return the first one or null.
|
|
|
|
NS_IF_ADDREF(*aResult = entry->mDocAllList->Item(0, PR_TRUE));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
static void
|
|
|
|
NotifyEditableStateChange(nsINode *aNode, nsIDocument *aDocument,
|
|
|
|
PRBool aEditable)
|
|
|
|
{
|
|
|
|
PRUint32 i, n = aNode->GetChildCount();
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
nsIContent *child = aNode->GetChildAt(i);
|
|
|
|
if (child->HasFlag(NODE_IS_EDITABLE) != aEditable) {
|
|
|
|
aDocument->ContentStatesChanged(child, nsnull,
|
|
|
|
NS_EVENT_STATE_MOZ_READONLY |
|
|
|
|
NS_EVENT_STATE_MOZ_READWRITE);
|
|
|
|
}
|
|
|
|
NotifyEditableStateChange(child, aDocument, aEditable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::TurnEditingOff()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mEditingState != eOff, "Editing is already off.");
|
|
|
|
|
2007-06-27 22:29:45 +00:00
|
|
|
nsPIDOMWindow *window = GetWindow();
|
|
|
|
if (!window)
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-06-27 22:29:45 +00:00
|
|
|
nsIDocShell *docshell = window->GetDocShell();
|
|
|
|
if (!docshell)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-06-02 03:11:35 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell =
|
|
|
|
do_QueryInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 22:29:45 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// turn editing off
|
2007-11-12 14:47:03 +00:00
|
|
|
rv = editSession->TearDownEditorOnWindow(window);
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-18 09:44:22 +00:00
|
|
|
nsCOMPtr<nsIEditor> editor;
|
|
|
|
editorDocShell->GetEditor(getter_AddRefs(editor));
|
|
|
|
nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor);
|
|
|
|
if (editorss) {
|
2007-10-31 18:51:49 +00:00
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css"));
|
2007-07-18 09:44:22 +00:00
|
|
|
if (mEditingState == eDesignMode)
|
2007-10-31 18:51:49 +00:00
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
2007-07-18 09:44:22 +00:00
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
mEditingState = eOff;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-02 00:51:08 +00:00
|
|
|
static PRBool HasPresShell(nsPIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
nsIDocShell *docShell = aWindow->GetDocShell();
|
|
|
|
if (!docShell)
|
|
|
|
return PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
docShell->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
return presShell != nsnull;
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::EditingStateChanged()
|
|
|
|
{
|
|
|
|
if (mEditingState == eSettingUp) {
|
|
|
|
// XXX We shouldn't recurse.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool designMode = HasFlag(NODE_IS_EDITABLE);
|
|
|
|
EditingState newState = designMode ? eDesignMode :
|
|
|
|
(mContentEditableCount > 0 ? eContentEditable : eOff);
|
|
|
|
if (mEditingState == newState) {
|
|
|
|
// No changes in editing mode.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newState == eOff) {
|
|
|
|
// Editing is being turned off.
|
|
|
|
return TurnEditingOff();
|
2007-06-27 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
// get editing session
|
|
|
|
nsPIDOMWindow *window = GetWindow();
|
|
|
|
if (!window)
|
2007-06-27 23:21:05 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsIDocShell *docshell = window->GetDocShell();
|
|
|
|
if (!docshell)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
if (!HasPresShell(window)) {
|
2007-11-02 00:51:08 +00:00
|
|
|
// We should not make the window editable or setup its editor.
|
|
|
|
// It's probably style=display:none.
|
|
|
|
return NS_OK;
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
PRBool makeWindowEditable = mEditingState == eOff;
|
|
|
|
if (makeWindowEditable) {
|
|
|
|
// Editing is being turned on (through designMode or contentEditable)
|
|
|
|
// Turn on editor.
|
|
|
|
// XXX This can cause flushing which can change the editing state, so make
|
|
|
|
// sure to avoid recursing.
|
|
|
|
EditingState oldState = mEditingState;
|
|
|
|
mEditingState = eSettingUp;
|
2007-11-02 00:51:08 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
|
|
|
|
PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-11-02 00:51:08 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
mEditingState = oldState;
|
|
|
|
}
|
2007-11-02 00:51:08 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
// XXX Need to call TearDownEditorOnWindow for all failures.
|
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell =
|
|
|
|
do_QueryInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2007-07-18 09:44:22 +00:00
|
|
|
editorDocShell->GetEditor(getter_AddRefs(editor));
|
|
|
|
if (!editor)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-10-31 18:51:49 +00:00
|
|
|
editorss->AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
// Should we update the editable state of all the nodes in the document? We
|
|
|
|
// need to do this when the designMode value changes, as that overrides
|
|
|
|
// specific states on the elements.
|
|
|
|
PRBool updateState;
|
|
|
|
|
|
|
|
PRBool spellRecheckAll = PR_FALSE;
|
|
|
|
if (designMode) {
|
|
|
|
// designMode is being turned on (overrides contentEditable).
|
2007-10-31 18:51:49 +00:00
|
|
|
editorss->AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-11-12 14:47:03 +00:00
|
|
|
// Disable scripting and plugins.
|
|
|
|
rv = editSession->DisableJSAndPlugins(window);
|
2007-07-03 11:54:41 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
updateState = PR_TRUE;
|
|
|
|
spellRecheckAll = mEditingState == eContentEditable;
|
|
|
|
}
|
|
|
|
else if (mEditingState == eDesignMode) {
|
|
|
|
// designMode is being turned off (contentEditable is still on).
|
2007-10-31 18:51:49 +00:00
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-11-12 14:47:03 +00:00
|
|
|
rv = editSession->RestoreJSAndPlugins(window);
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
updateState = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// contentEditable is being turned on (and designMode is off).
|
|
|
|
updateState = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEditingState = newState;
|
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
if (makeWindowEditable) {
|
|
|
|
// Set the editor to not insert br's on return when in p
|
|
|
|
// elements by default.
|
|
|
|
// XXX Do we only want to do this for designMode?
|
|
|
|
PRBool unused;
|
|
|
|
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
|
|
|
|
NS_LITERAL_STRING("false"), &unused);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Editor setup failed. Editing is not on after all.
|
|
|
|
// XXX Should we reset the editable flag on nodes?
|
2007-11-12 14:47:03 +00:00
|
|
|
editSession->TearDownEditorOnWindow(window);
|
2007-11-05 21:19:52 +00:00
|
|
|
mEditingState = eOff;
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-11-05 21:19:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState) {
|
|
|
|
mozAutoDocUpdate upd(this, UPDATE_CONTENT_STATE, PR_TRUE);
|
|
|
|
NotifyEditableStateChange(this, this, !designMode);
|
|
|
|
}
|
2007-06-27 22:29:45 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
// Resync the editor's spellcheck state.
|
|
|
|
if (spellRecheckAll) {
|
|
|
|
nsCOMPtr<nsISelectionController> selcon;
|
|
|
|
nsresult rv = editor->GetSelectionController(getter_AddRefs(selcon));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> spellCheckSelection;
|
|
|
|
rv = selcon->GetSelection(nsISelectionController::SELECTION_SPELLCHECK,
|
|
|
|
getter_AddRefs(spellCheckSelection));
|
2007-06-27 23:21:05 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-06-28 02:48:16 +00:00
|
|
|
spellCheckSelection->RemoveAllRanges();
|
2007-06-27 23:21:05 +00:00
|
|
|
}
|
2007-06-27 22:29:45 +00:00
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
editor->SyncRealTimeSpell();
|
2007-06-27 22:29:45 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!nsContentUtils::IsCallerTrustedForWrite()) {
|
|
|
|
nsCOMPtr<nsIPrincipal> subject;
|
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (subject) {
|
2007-07-10 04:22:55 +00:00
|
|
|
PRBool subsumes;
|
|
|
|
rv = subject->Subsumes(NodePrincipal(), &subsumes);
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-10 04:22:55 +00:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(subsumes, NS_ERROR_DOM_PROP_ACCESS_DENIED);
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool editableMode = HasFlag(NODE_IS_EDITABLE);
|
|
|
|
if (aDesignMode.LowerCaseEqualsASCII(editableMode ? "off" : "on")) {
|
|
|
|
SetEditableFlag(!editableMode);
|
|
|
|
|
|
|
|
return EditingStateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr)
|
|
|
|
{
|
|
|
|
// initialize return value
|
|
|
|
NS_ENSURE_ARG_POINTER(aCmdMgr);
|
|
|
|
|
|
|
|
// check if we have it cached
|
|
|
|
if (mMidasCommandManager) {
|
|
|
|
NS_ADDREF(*aCmdMgr = mMidasCommandManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCmdMgr = nsnull;
|
2005-11-28 23:56:44 +00:00
|
|
|
|
|
|
|
nsPIDOMWindow *window = GetWindow();
|
|
|
|
if (!window)
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsIDocShell *docshell = window->GetDocShell();
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!docshell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-03-18 14:47:17 +00:00
|
|
|
mMidasCommandManager = do_GetInterface(docshell);
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!mMidasCommandManager)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(*aCmdMgr = mMidasCommandManager);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct MidasCommand {
|
|
|
|
const char* incomingCommandString;
|
|
|
|
const char* internalCommandString;
|
|
|
|
const char* internalParamString;
|
2003-01-22 01:04:51 +00:00
|
|
|
PRPackedBool useNewParam;
|
|
|
|
PRPackedBool convertToBoolean;
|
2002-11-07 15:38:35 +00:00
|
|
|
};
|
|
|
|
|
2003-01-25 21:49:53 +00:00
|
|
|
static const struct MidasCommand gMidasCommandTable[] = {
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "bold", "cmd_bold", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "italic", "cmd_italic", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "underline", "cmd_underline", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "strikethrough", "cmd_strikethrough", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "subscript", "cmd_subscript", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "superscript", "cmd_superscript", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "cut", "cmd_cut", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "copy", "cmd_copy", "", PR_TRUE, PR_FALSE },
|
2003-03-04 13:56:36 +00:00
|
|
|
{ "paste", "cmd_paste", "", PR_TRUE, PR_FALSE },
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "delete", "cmd_delete", "", PR_TRUE, PR_FALSE },
|
2003-02-19 13:55:29 +00:00
|
|
|
{ "selectall", "cmd_selectAll", "", PR_TRUE, PR_FALSE },
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "undo", "cmd_undo", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "redo", "cmd_redo", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "indent", "cmd_indent", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "outdent", "cmd_outdent", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "backcolor", "cmd_backgroundColor", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "forecolor", "cmd_fontColor", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "hilitecolor", "cmd_highlight", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "fontname", "cmd_fontFace", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "fontsize", "cmd_fontSize", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "increasefontsize", "cmd_increaseFont", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "decreasefontsize", "cmd_decreaseFont", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "inserthorizontalrule", "cmd_insertHR", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "createlink", "cmd_insertLinkNoUI", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "insertimage", "cmd_insertImageNoUI", "", PR_FALSE, PR_FALSE },
|
2003-05-30 15:02:12 +00:00
|
|
|
{ "inserthtml", "cmd_insertHTML", "", PR_FALSE, PR_FALSE },
|
2003-06-10 21:12:29 +00:00
|
|
|
{ "gethtml", "cmd_getContents", "", PR_FALSE, PR_FALSE },
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "justifyleft", "cmd_align", "left", PR_TRUE, PR_FALSE },
|
|
|
|
{ "justifyright", "cmd_align", "right", PR_TRUE, PR_FALSE },
|
|
|
|
{ "justifycenter", "cmd_align", "center", PR_TRUE, PR_FALSE },
|
|
|
|
{ "justifyfull", "cmd_align", "justify", PR_TRUE, PR_FALSE },
|
|
|
|
{ "removeformat", "cmd_removeStyles", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "unlink", "cmd_removeLinks", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "insertorderedlist", "cmd_ol", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "insertunorderedlist", "cmd_ul", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "insertparagraph", "cmd_paragraphState", "p", PR_TRUE, PR_FALSE },
|
|
|
|
{ "formatblock", "cmd_paragraphState", "", PR_FALSE, PR_FALSE },
|
|
|
|
{ "heading", "cmd_paragraphState", "", PR_FALSE, PR_FALSE },
|
2005-08-25 11:51:04 +00:00
|
|
|
{ "styleWithCSS", "cmd_setDocumentUseCSS", "", PR_FALSE, PR_TRUE },
|
|
|
|
{ "contentReadOnly", "cmd_setDocumentReadOnly", "", PR_FALSE, PR_TRUE },
|
2005-06-02 03:11:35 +00:00
|
|
|
{ "insertBrOnReturn", "cmd_insertBrOnReturn", "", PR_FALSE, PR_TRUE },
|
2005-06-24 17:18:27 +00:00
|
|
|
{ "enableObjectResizing", "cmd_enableObjectResizing", "", PR_FALSE, PR_TRUE },
|
|
|
|
{ "enableInlineTableEditing", "cmd_enableInlineTableEditing", "", PR_FALSE, PR_TRUE },
|
2002-11-07 15:38:35 +00:00
|
|
|
#if 0
|
2002-11-20 01:22:17 +00:00
|
|
|
// no editor support to remove alignments right now
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "justifynone", "cmd_align", "", PR_TRUE, PR_FALSE },
|
2002-11-11 20:19:37 +00:00
|
|
|
|
|
|
|
// the following will need special review before being turned on
|
2003-01-22 01:04:51 +00:00
|
|
|
{ "saveas", "cmd_saveAs", "", PR_TRUE, PR_FALSE },
|
|
|
|
{ "print", "cmd_print", "", PR_TRUE, PR_FALSE },
|
2002-11-07 15:38:35 +00:00
|
|
|
#endif
|
2003-01-22 01:04:51 +00:00
|
|
|
{ NULL, NULL, NULL, PR_FALSE, PR_FALSE }
|
2002-11-07 15:38:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MidasCommandCount ((sizeof(gMidasCommandTable) / sizeof(struct MidasCommand)) - 1)
|
|
|
|
|
2007-11-28 23:38:20 +00:00
|
|
|
static const char* const gBlocks[] = {
|
|
|
|
"ADDRESS",
|
|
|
|
"BLOCKQUOTE",
|
|
|
|
"DD",
|
|
|
|
"DIV",
|
|
|
|
"DL",
|
|
|
|
"DT",
|
|
|
|
"H1",
|
|
|
|
"H2",
|
|
|
|
"H3",
|
|
|
|
"H4",
|
|
|
|
"H5",
|
|
|
|
"H6",
|
|
|
|
"P",
|
|
|
|
"PRE"
|
2002-12-20 06:44:32 +00:00
|
|
|
};
|
|
|
|
|
2008-01-14 09:26:22 +00:00
|
|
|
static PRBool
|
|
|
|
ConvertToMidasInternalCommandInner(const nsAString & inCommandID,
|
|
|
|
const nsAString & inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
|
|
|
PRBool& outIsBoolean,
|
|
|
|
PRBool& outBooleanValue,
|
|
|
|
PRBool aIgnoreParams)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2005-08-25 11:51:04 +00:00
|
|
|
NS_ConvertUTF16toUTF8 convertedCommandID(inCommandID);
|
|
|
|
|
|
|
|
// Hack to support old boolean commands that were backwards (see bug 301490).
|
|
|
|
PRBool invertBool = PR_FALSE;
|
|
|
|
if (convertedCommandID.LowerCaseEqualsLiteral("usecss")) {
|
|
|
|
convertedCommandID.Assign("styleWithCSS");
|
|
|
|
invertBool = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (convertedCommandID.LowerCaseEqualsLiteral("readonly")) {
|
|
|
|
convertedCommandID.Assign("contentReadOnly");
|
|
|
|
invertBool = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-22 01:04:51 +00:00
|
|
|
PRUint32 i;
|
|
|
|
PRBool found = PR_FALSE;
|
2002-11-07 15:38:35 +00:00
|
|
|
for (i = 0; i < MidasCommandCount; ++i) {
|
|
|
|
if (convertedCommandID.Equals(gMidasCommandTable[i].incomingCommandString,
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
2003-01-22 01:04:51 +00:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
// set outCommandID (what we use internally)
|
|
|
|
outCommandID.Assign(gMidasCommandTable[i].internalCommandString);
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2003-01-22 01:04:51 +00:00
|
|
|
// set outParam & outIsBoolean based on flags from the table
|
|
|
|
outIsBoolean = gMidasCommandTable[i].convertToBoolean;
|
|
|
|
|
2008-01-14 09:26:22 +00:00
|
|
|
if (!aIgnoreParams) {
|
|
|
|
if (gMidasCommandTable[i].useNewParam) {
|
|
|
|
outParam.Assign(gMidasCommandTable[i].internalParamString);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-01-14 09:26:22 +00:00
|
|
|
// handle checking of param passed in
|
|
|
|
if (outIsBoolean) {
|
|
|
|
// if this is a boolean value and it's not explicitly false
|
|
|
|
// (e.g. no value) we default to "true". For old backwards commands
|
|
|
|
// we invert the check (see bug 301490).
|
|
|
|
if (invertBool) {
|
|
|
|
outBooleanValue = inParam.LowerCaseEqualsLiteral("false");
|
2007-11-28 23:38:20 +00:00
|
|
|
}
|
2008-01-14 09:26:22 +00:00
|
|
|
else {
|
|
|
|
outBooleanValue = !inParam.LowerCaseEqualsLiteral("false");
|
2002-12-20 06:44:32 +00:00
|
|
|
}
|
2008-01-14 09:26:22 +00:00
|
|
|
outParam.Truncate();
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-01-14 09:26:22 +00:00
|
|
|
// check to see if we need to convert the parameter
|
|
|
|
if (outCommandID.EqualsLiteral("cmd_paragraphState")) {
|
|
|
|
const PRUnichar *start = inParam.BeginReading();
|
|
|
|
const PRUnichar *end = inParam.EndReading();
|
|
|
|
if (start != end && *start == '<' && *(end - 1) == '>') {
|
|
|
|
++start;
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 convertedParam(Substring(start, end));
|
|
|
|
PRUint32 j;
|
|
|
|
for (j = 0; j < NS_ARRAY_LENGTH(gBlocks); ++j) {
|
|
|
|
if (convertedParam.Equals(gBlocks[j],
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
|
|
|
outParam.Assign(gBlocks[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return j != NS_ARRAY_LENGTH(gBlocks);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CopyUTF16toUTF8(inParam, outParam);
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-22 01:04:51 +00:00
|
|
|
} // end else for useNewParam (do convert existing param)
|
|
|
|
else {
|
|
|
|
// reset results if the command is not found in our table
|
|
|
|
outCommandID.SetLength(0);
|
|
|
|
outParam.SetLength(0);
|
|
|
|
outIsBoolean = PR_FALSE;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
return found;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 09:26:22 +00:00
|
|
|
static PRBool
|
|
|
|
ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
const nsAString & inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
|
|
|
PRBool& outIsBoolean,
|
|
|
|
PRBool& outBooleanValue)
|
|
|
|
{
|
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, inParam, outCommandID,
|
|
|
|
outParam, outIsBoolean,
|
|
|
|
outBooleanValue, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
nsACString& outCommandID)
|
|
|
|
{
|
|
|
|
nsCAutoString dummyCString;
|
|
|
|
nsAutoString dummyString;
|
|
|
|
PRBool dummyBool;
|
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, dummyString,
|
|
|
|
outCommandID, dummyCString,
|
|
|
|
dummyBool, dummyBool, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2003-03-04 13:56:36 +00:00
|
|
|
jsval
|
|
|
|
nsHTMLDocument::sCutCopyInternal_id = JSVAL_VOID;
|
|
|
|
jsval
|
|
|
|
nsHTMLDocument::sPasteInternal_id = JSVAL_VOID;
|
|
|
|
|
|
|
|
/* Helper function to check security of clipboard commands. If aPaste is */
|
|
|
|
/* true, we check paste, else we check cutcopy */
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::DoClipboardSecurityCheck(PRBool aPaste)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
|
|
|
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
|
|
|
|
|
|
|
if (stack) {
|
|
|
|
JSContext *cx = nsnull;
|
|
|
|
stack->Peek(&cx);
|
2008-01-08 18:41:08 +00:00
|
|
|
if (!cx) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoRequest ar(cx);
|
2003-03-04 13:56:36 +00:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(classNameStr, "Clipboard");
|
|
|
|
|
2005-10-14 09:07:29 +00:00
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
2003-10-30 03:01:25 +00:00
|
|
|
|
2003-03-04 13:56:36 +00:00
|
|
|
if (aPaste) {
|
|
|
|
if (nsHTMLDocument::sPasteInternal_id == JSVAL_VOID) {
|
|
|
|
nsHTMLDocument::sPasteInternal_id =
|
|
|
|
STRING_TO_JSVAL(::JS_InternString(cx, "paste"));
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
rv = secMan->CheckPropertyAccess(cx, nsnull, classNameStr.get(),
|
2003-03-04 13:56:36 +00:00
|
|
|
nsHTMLDocument::sPasteInternal_id,
|
|
|
|
nsIXPCSecurityManager::ACCESS_GET_PROPERTY);
|
|
|
|
} else {
|
|
|
|
if (nsHTMLDocument::sCutCopyInternal_id == JSVAL_VOID) {
|
|
|
|
nsHTMLDocument::sCutCopyInternal_id =
|
|
|
|
STRING_TO_JSVAL(::JS_InternString(cx, "cutcopy"));
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
rv = secMan->CheckPropertyAccess(cx, nsnull, classNameStr.get(),
|
2003-03-04 13:56:36 +00:00
|
|
|
nsHTMLDocument::sCutCopyInternal_id,
|
|
|
|
nsIXPCSecurityManager::ACCESS_GET_PROPERTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
/* TODO: don't let this call do anything if the page is not done loading */
|
2003-03-26 07:41:30 +00:00
|
|
|
/* boolean execCommand(in DOMString commandID, in boolean doShowUI,
|
2002-11-07 15:38:35 +00:00
|
|
|
in DOMString value); */
|
|
|
|
NS_IMETHODIMP
|
2003-03-26 07:41:30 +00:00
|
|
|
nsHTMLDocument::ExecCommand(const nsAString & commandID,
|
|
|
|
PRBool doShowUI,
|
|
|
|
const nsAString & value,
|
2002-11-07 15:38:35 +00:00
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
// for optional parameters see dom/src/base/nsHistory.cpp: HistoryImpl::Go()
|
|
|
|
// this might add some ugly JS dependencies?
|
|
|
|
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// if they are requesting UI from us, let's fail since we have no UI
|
|
|
|
if (doShowUI)
|
2007-06-28 02:48:16 +00:00
|
|
|
return NS_OK;
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2003-03-18 22:18:10 +00:00
|
|
|
nsresult rv = NS_OK;
|
2003-03-04 13:56:36 +00:00
|
|
|
|
2004-06-17 00:13:25 +00:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("gethtml"))
|
2003-06-10 21:12:29 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-17 00:13:25 +00:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
(commandID.LowerCaseEqualsLiteral("copy"))) {
|
2003-03-04 13:56:36 +00:00
|
|
|
rv = DoClipboardSecurityCheck(PR_FALSE);
|
2004-06-17 00:13:25 +00:00
|
|
|
} else if (commandID.LowerCaseEqualsLiteral("paste")) {
|
2003-03-04 13:56:36 +00:00
|
|
|
rv = DoClipboardSecurityCheck(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 15:23:03 +00:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!cmdMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cmdToDispatch, paramStr;
|
2003-01-22 01:04:51 +00:00
|
|
|
PRBool isBool, boolVal;
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, value,
|
2003-01-22 01:04:51 +00:00
|
|
|
cmdToDispatch, paramStr, isBool, boolVal))
|
2007-06-28 02:48:16 +00:00
|
|
|
return NS_OK;
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2003-01-22 01:04:51 +00:00
|
|
|
if (!isBool && paramStr.IsEmpty()) {
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), nsnull, window);
|
2002-11-07 15:38:35 +00:00
|
|
|
} else {
|
|
|
|
// we have a command that requires a parameter, create params
|
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
|
|
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
|
|
|
if (!cmdParams)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-01-22 01:04:51 +00:00
|
|
|
|
|
|
|
if (isBool)
|
|
|
|
rv = cmdParams->SetBooleanValue("state_attribute", boolVal);
|
2003-05-30 15:02:12 +00:00
|
|
|
else if (cmdToDispatch.Equals("cmd_fontFace"))
|
|
|
|
rv = cmdParams->SetStringValue("state_attribute", value);
|
|
|
|
else if (cmdToDispatch.Equals("cmd_insertHTML"))
|
|
|
|
rv = cmdParams->SetStringValue("state_data", value);
|
2003-01-22 01:04:51 +00:00
|
|
|
else
|
|
|
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
2002-11-07 15:38:35 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: don't let this call do anything if the page is not done loading */
|
|
|
|
/* boolean execCommandShowHelp(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::ExecCommandShowHelp(const nsAString & commandID,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean queryCommandEnabled(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandEnabled(const nsAString & commandID,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-11-13 15:23:03 +00:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
|
|
|
if (!cmdMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2002-11-13 15:23:03 +00:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cmdToDispatch, paramStr;
|
2008-01-14 09:26:22 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch))
|
2002-11-13 15:23:03 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, _retval);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean queryCommandIndeterm (in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-03-19 14:17:51 +00:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
|
|
|
if (!cmdMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2004-03-19 14:17:51 +00:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cmdToDispatch, paramToCheck;
|
|
|
|
PRBool dummy;
|
|
|
|
if (!ConvertToMidasInternalCommand(commandID, commandID,
|
|
|
|
cmdToDispatch, paramToCheck, dummy, dummy))
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
|
|
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// if command does not have a state_mixed value, this call fails, so we fail too,
|
|
|
|
// which is what is expected
|
|
|
|
rv = cmdParams->GetBooleanValue("state_mixed", _retval);
|
|
|
|
return rv;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean queryCommandState(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandState(const nsAString & commandID, PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 15:23:03 +00:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!cmdMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cmdToDispatch, paramToCheck;
|
2003-01-22 01:04:51 +00:00
|
|
|
PRBool dummy, dummy2;
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, commandID,
|
2003-01-22 01:04:51 +00:00
|
|
|
cmdToDispatch, paramToCheck, dummy, dummy2))
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2002-11-13 15:23:03 +00:00
|
|
|
nsresult rv;
|
2002-11-07 15:38:35 +00:00
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
|
|
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
|
|
|
if (!cmdParams)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
2002-11-07 15:38:35 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// handle alignment as a special case (possibly other commands too?)
|
2003-03-26 07:41:30 +00:00
|
|
|
// Alignment is special because the external api is individual
|
|
|
|
// commands but internally we use cmd_align with different
|
|
|
|
// parameters. When getting the state of this command, we need to
|
|
|
|
// return the boolean for this particular alignment rather than the
|
|
|
|
// string of 'which alignment is this?'
|
2002-11-07 15:38:35 +00:00
|
|
|
if (cmdToDispatch.Equals("cmd_align")) {
|
|
|
|
char * actualAlignmentType = nsnull;
|
|
|
|
rv = cmdParams->GetCStringValue("state_attribute", &actualAlignmentType);
|
|
|
|
if (NS_SUCCEEDED(rv) && actualAlignmentType && actualAlignmentType[0]) {
|
|
|
|
*_retval = paramToCheck.Equals(actualAlignmentType);
|
|
|
|
}
|
|
|
|
if (actualAlignmentType)
|
|
|
|
nsMemory::Free(actualAlignmentType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = cmdParams->GetBooleanValue("state_all", _retval);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean queryCommandSupported(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandSupported(const nsAString & commandID,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString queryCommandText(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandText(const nsAString & commandID,
|
|
|
|
nsAString & _retval)
|
|
|
|
{
|
|
|
|
_retval.SetLength(0);
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString queryCommandValue(in DOMString commandID); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandValue(const nsAString & commandID,
|
|
|
|
nsAString &_retval)
|
|
|
|
{
|
|
|
|
_retval.SetLength(0);
|
|
|
|
|
|
|
|
// if editing is not on, bail
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!IsEditingOn())
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 15:23:03 +00:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!cmdMgr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDOMWindow *window = GetWindow();
|
2002-11-07 15:38:35 +00:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCAutoString cmdToDispatch, paramStr;
|
2008-01-14 09:26:22 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch))
|
2002-11-07 15:38:35 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
// create params
|
2002-11-13 15:23:03 +00:00
|
|
|
nsresult rv;
|
2002-11-07 15:38:35 +00:00
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
|
|
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
|
|
|
if (!cmdParams)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-10 21:12:29 +00:00
|
|
|
|
|
|
|
// this is a special command since we are calling "DoCommand rather than
|
|
|
|
// GetCommandState like the other commands
|
|
|
|
if (cmdToDispatch.Equals("cmd_getContents"))
|
|
|
|
{
|
|
|
|
rv = cmdParams->SetBooleanValue("selection_only", PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = cmdParams->SetCStringValue("format", "text/html");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return cmdParams->GetStringValue("result", _retval);
|
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
2002-11-07 15:38:35 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2004-01-26 09:48:50 +00:00
|
|
|
nsXPIDLCString cStringResult;
|
|
|
|
rv = cmdParams->GetCStringValue("state_attribute",
|
|
|
|
getter_Copies(cStringResult));
|
|
|
|
CopyUTF8toUTF16(cStringResult, _retval);
|
2002-11-07 15:38:35 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2004-06-25 12:26:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
|
|
|
|
PRInt32 aNamespaceID, PRBool aDocumentDefaultType,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aDocumentDefaultType || IsXHTML() ||
|
|
|
|
aNamespaceID == kNameSpaceID_None,
|
|
|
|
"HTML elements in an HTML document should have "
|
|
|
|
"kNamespaceID_None as their namespace ID.");
|
|
|
|
|
2004-08-19 12:45:47 +00:00
|
|
|
if (IsXHTML() &&
|
|
|
|
(aDocumentDefaultType || aNamespaceID == kNameSpaceID_XHTML)) {
|
|
|
|
nsCAutoString name, lcName;
|
|
|
|
aName->ToUTF8String(name);
|
|
|
|
ToLowerCase(name, lcName);
|
|
|
|
NS_ASSERTION(lcName.Equals(name),
|
|
|
|
"aName should be lowercase, fix caller.");
|
|
|
|
}
|
|
|
|
|
2004-07-05 10:16:39 +00:00
|
|
|
return nsDocument::CreateElem(aName, aPrefix, aNamespaceID,
|
|
|
|
aDocumentDefaultType, aResult);
|
2004-06-25 12:26:02 +00:00
|
|
|
}
|
|
|
|
#endif
|