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"
|
2010-03-02 21:00:53 +00:00
|
|
|
#include "nsCSSLoader.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"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2009-03-03 12:14:13 +00:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2009-06-28 22:44:22 +00:00
|
|
|
#include "nsHtml5Module.h"
|
2009-05-20 02:40:07 +00:00
|
|
|
#include "prprf.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
|
|
|
|
|
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);
|
2008-10-10 15:04:34 +00:00
|
|
|
static int
|
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
|
|
|
}
|
|
|
|
|
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()
|
2008-06-22 23:12:40 +00:00
|
|
|
: nsDocument("text/html")
|
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.
|
2001-05-18 01:10:54 +00:00
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
mIsRegularHTML = PR_TRUE;
|
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
|
|
|
}
|
|
|
|
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLDocument)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
|
2009-07-09 01:10:29 +00:00
|
|
|
NS_ASSERTION(!nsCCUncollectableMarker::InGeneration(cb, tmp->GetMarkedCCGeneration()),
|
2009-03-03 12:14:13 +00:00
|
|
|
"Shouldn't traverse nsHTMLDocument!");
|
2007-03-08 11:17:16 +00:00
|
|
|
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)
|
2009-10-21 09:41:18 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mWyciwygChannel)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mMidasCommandManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFragmentParser)
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2009-10-21 09:41:18 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mImageMaps)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mImages)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mApplets)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mEmbeds)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLinks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAnchors)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mForms)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFormControls)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mWyciwygChannel)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mMidasCommandManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFragmentParser)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_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
|
|
|
|
2008-02-21 20:39:20 +00:00
|
|
|
|
|
|
|
// QueryInterface implementation for nsHTMLDocument
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_DOCUMENT_INTERFACE_TABLE_BEGIN(nsHTMLDocument)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsHTMLDocument, nsIHTMLDocument)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsHTMLDocument, nsIDOMHTMLDocument)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(nsHTMLDocument, nsIDOMNSHTMLDocument)
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_END
|
|
|
|
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
|
2008-02-21 20:39:20 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDocument)
|
|
|
|
|
|
|
|
|
2002-01-25 06:37:35 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::Init()
|
|
|
|
{
|
|
|
|
nsresult rv = nsDocument::Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-29 06:07:45 +00:00
|
|
|
// Now reset the compatibility mode of the CSSLoader
|
|
|
|
// to match our compat mode.
|
2006-01-06 02:53:10 +00:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
PrePopulateIdentifierMap();
|
2002-01-25 06:37:35 +00:00
|
|
|
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
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
PrePopulateIdentifierMap();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
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()
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (IsHTML()) {
|
|
|
|
return nsStyleSet::eHTMLPresHintSheet;
|
2004-05-05 00:30:57 +00:00
|
|
|
}
|
2009-08-25 17:15:55 +00:00
|
|
|
|
|
|
|
return nsDocument::GetAttrSheetType();
|
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);
|
2008-04-01 19:46:25 +00:00
|
|
|
// FIXME: Bug 337970
|
2006-05-15 17:40:51 +00:00
|
|
|
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)
|
|
|
|
{
|
2010-01-12 13:15:10 +00:00
|
|
|
if (mIsRegularHTML &&
|
|
|
|
nsHtml5Module::sEnabled &&
|
|
|
|
aCommand &&
|
|
|
|
!nsCRT::strcmp(aCommand, "view")) {
|
|
|
|
return; // the HTML5 parser uses chardet directly
|
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-07-15 11:30:33 +00:00
|
|
|
PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
|
2009-06-28 22:44:22 +00:00
|
|
|
if (aSink) {
|
|
|
|
loadAsHtml5 = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
mIsRegularHTML = PR_FALSE;
|
2003-04-19 00:28:09 +00:00
|
|
|
mCompatMode = eCompatibility_FullStandards;
|
2009-06-28 22:44:22 +00:00
|
|
|
loadAsHtml5 = PR_FALSE;
|
|
|
|
}
|
2010-02-03 08:53:58 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(mIsRegularHTML,
|
|
|
|
"Hey, someone forgot to reset mIsRegularHTML!!!");
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-28 22:44:22 +00:00
|
|
|
|
2010-02-02 07:39:26 +00:00
|
|
|
if (loadAsHtml5 &&
|
|
|
|
!(contentType.EqualsLiteral("text/html") &&
|
|
|
|
aCommand &&
|
|
|
|
!nsCRT::strcmp(aCommand, "view"))) {
|
2009-06-28 22:44:22 +00:00
|
|
|
loadAsHtml5 = PR_FALSE;
|
2003-04-19 00:28:09 +00:00
|
|
|
}
|
2010-02-02 07:39:26 +00:00
|
|
|
|
|
|
|
// TODO: Proper about:blank treatment is bug 543435
|
|
|
|
if (loadAsHtml5) {
|
|
|
|
// mDocumentURI hasn't been set, yet, so get the URI from the channel
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(uri));
|
|
|
|
// Adapted from nsDocShell:
|
|
|
|
// GetSpec can be expensive for some URIs, so check the scheme first.
|
|
|
|
PRBool isAbout = PR_FALSE;
|
|
|
|
if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
|
|
|
|
nsCAutoString str;
|
|
|
|
uri->GetSpec(str);
|
|
|
|
if (str.EqualsLiteral("about:blank")) {
|
|
|
|
loadAsHtml5 = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-19 01:27:11 +00:00
|
|
|
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) {
|
2009-06-28 22:44:22 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
2009-10-15 11:29:11 +00:00
|
|
|
mParser->MarkAsNotScriptCreated();
|
2009-06-28 22:44:22 +00:00
|
|
|
} else {
|
|
|
|
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
|
|
|
|
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
|
2008-09-28 19:14:28 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
|
|
|
|
|
|
|
// No support yet for docshell-less HTML
|
2009-08-25 17:15:55 +00:00
|
|
|
NS_ENSURE_TRUE(docShell || !IsHTML(), NS_ERROR_FAILURE);
|
2008-09-28 19:14:28 +00:00
|
|
|
|
2007-01-13 03:28:00 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
2008-09-28 19:14:28 +00:00
|
|
|
if (docShellAsItem) {
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
}
|
2007-01-13 03:28:00 +00:00
|
|
|
|
|
|
|
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);
|
2010-01-23 11:41:41 +00:00
|
|
|
if (parentContentViewer) {
|
|
|
|
parentDocument = parentContentViewer->GetDocument();
|
2007-01-13 03:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2008-09-28 19:14:28 +00:00
|
|
|
if (docShell) {
|
|
|
|
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;
|
|
|
|
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2004-04-13 22:28:16 +00:00
|
|
|
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 {
|
2008-09-28 19:14:28 +00:00
|
|
|
NS_ASSERTION(docShell && docShellAsItem, "Unexpected null value");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo;
|
|
|
|
docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
|
|
|
|
|
2004-04-13 22:28:16 +00:00
|
|
|
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) {
|
2009-09-18 09:21:47 +00:00
|
|
|
rv = mParser->GetStreamListener(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;
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
if (aSink) {
|
2009-07-15 11:30:33 +00:00
|
|
|
NS_ASSERTION(!loadAsHtml5, "Panic: We are loading as HTML5 and someone tries to set an external sink!");
|
2003-04-19 00:28:09 +00:00
|
|
|
sink = aSink;
|
2009-06-28 22:44:22 +00:00
|
|
|
} else {
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-04-19 00:28:09 +00:00
|
|
|
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 {
|
2009-06-28 22:44:22 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
nsHtml5Module::Initialize(mParser, this, uri, docShell, aChannel);
|
|
|
|
sink = mParser->GetContentSink();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> htmlsink;
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
rv = NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri,
|
|
|
|
docShell, aChannel);
|
2003-04-19 00:28:09 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
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
|
|
|
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-05-29 00:53:03 +00:00
|
|
|
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
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
NS_ASSERTION(IsHTML() || aMode == eCompatibility_FullStandards,
|
2003-04-19 00:28:09 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-08-25 17:15:55 +00:00
|
|
|
if (IsHTML()) {
|
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;
|
2009-06-09 07:41:19 +00:00
|
|
|
rv = CreateElem(name, nsnull, kNameSpaceID_XHTML, PR_TRUE,
|
2004-07-22 14:54:49 +00:00
|
|
|
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
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2004-03-02 22:39:46 +00:00
|
|
|
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
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2004-03-02 22:39:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2004-03-02 22:39:46 +00:00
|
|
|
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);
|
2009-08-25 17:15:55 +00:00
|
|
|
if (IsHTML()) {
|
2004-10-28 02:34:21 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-11-18 22:07:53 +00:00
|
|
|
return nsDocument::GetXmlEncoding(aXmlEncoding);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
SetDOMStringToNull(aXmlEncoding);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetXmlStandalone(PRBool *aXmlStandalone)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-11-18 22:07:53 +00:00
|
|
|
return nsDocument::GetXmlStandalone(aXmlStandalone);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
*aXmlStandalone = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetXmlStandalone(PRBool aXmlStandalone)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-11-18 22:07:53 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-11-18 22:07:53 +00:00
|
|
|
return nsDocument::GetXmlVersion(aXmlVersion);
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:10:11 +00:00
|
|
|
SetDOMStringToNull(aXmlVersion);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::SetXmlVersion(const nsAString& aXmlVersion)
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2003-11-18 22:07:53 +00:00
|
|
|
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;
|
2008-02-07 20:58:56 +00:00
|
|
|
if (NS_FAILED(uri->GetAsciiHost(current)))
|
2007-11-12 07:58:16 +00:00
|
|
|
current.Truncate();
|
2008-02-07 20:58:56 +00:00
|
|
|
if (NS_FAILED(newURI->GetAsciiHost(domain)))
|
2007-11-12 07:58:16 +00:00
|
|
|
domain.Truncate();
|
|
|
|
|
|
|
|
PRBool ok = current.Equals(domain);
|
|
|
|
if (current.Length() > domain.Length() &&
|
|
|
|
StringEndsWith(current, domain) &&
|
|
|
|
current.CharAt(current.Length() - domain.Length() - 1) == '.') {
|
2008-02-07 20:58:56 +00:00
|
|
|
// We're golden if the new domain is the current page's base domain or a
|
|
|
|
// subdomain of it.
|
2007-11-12 07:58:16 +00:00
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
if (!tldService)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2008-02-07 20:58:56 +00:00
|
|
|
nsCAutoString currentBaseDomain;
|
|
|
|
ok = NS_SUCCEEDED(tldService->GetBaseDomain(uri, 0, currentBaseDomain));
|
|
|
|
NS_ASSERTION(StringEndsWith(domain, currentBaseDomain) ==
|
|
|
|
(domain.Length() >= currentBaseDomain.Length()),
|
|
|
|
"uh-oh! slight optimization wasn't valid somehow!");
|
|
|
|
ok = ok && domain.Length() >= currentBaseDomain.Length();
|
2007-11-12 07:58:16 +00:00
|
|
|
}
|
|
|
|
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;
|
2009-08-25 17:15:55 +00:00
|
|
|
if (IsHTML()) {
|
|
|
|
rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
|
|
|
|
getter_AddRefs(nodeList));
|
|
|
|
} else {
|
2007-12-12 02:26:09 +00:00
|
|
|
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));
|
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) ||
|
2009-08-24 20:02:07 +00:00
|
|
|
!root || !root->IsHTML() ||
|
2007-12-12 02:26:09 +00:00
|
|
|
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) {
|
2009-06-09 07:41:19 +00:00
|
|
|
mImages = new nsContentList(this, nsGkAtoms::img, kNameSpaceID_XHTML);
|
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) {
|
2009-06-09 07:41:19 +00:00
|
|
|
mApplets = new nsContentList(this, nsGkAtoms::applet, kNameSpaceID_XHTML);
|
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();
|
2002-05-20 22:47:02 +00:00
|
|
|
|
2006-07-18 00:18:19 +00:00
|
|
|
nsIAtom *localName = ni->NameAtom();
|
2009-06-09 07:41:19 +00:00
|
|
|
if (ni->NamespaceID() == kNameSpaceID_XHTML &&
|
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
|
|
|
|
2009-06-09 07:41:19 +00:00
|
|
|
if (aContent->NodeInfo()->Equals(nsGkAtoms::a, kNameSpaceID_XHTML)) {
|
2006-12-26 17:47:52 +00:00
|
|
|
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.
|
|
|
|
|
2008-10-01 00:49:30 +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
|
|
|
{
|
2008-10-01 00:49:30 +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
|
|
|
{
|
2009-11-06 04:27:30 +00:00
|
|
|
if (!IsHTML() || mDisableDocWrite) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.open() on XHTML
|
|
|
|
|
2009-09-27 09:20:30 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 11:30:33 +00:00
|
|
|
PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
|
2009-06-28 22:44:22 +00:00
|
|
|
|
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);
|
2008-07-09 13:48:02 +00:00
|
|
|
if (!shell) {
|
|
|
|
// We won't be able to create a parser anyway.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool inUnload;
|
|
|
|
shell->GetIsInUnload(&inUnload);
|
|
|
|
if (inUnload) {
|
|
|
|
return NS_OK;
|
2007-06-14 18:18:05 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2009-01-22 15:13:59 +00:00
|
|
|
// (since if it's secure, then it's presumably trusted).
|
2005-03-02 23:17:28 +00:00
|
|
|
nsCOMPtr<nsIDocument> callerDoc =
|
2005-11-03 22:47:06 +00:00
|
|
|
do_QueryInterface(nsContentUtils::GetDocumentFromContext());
|
2008-12-11 21:00:37 +00:00
|
|
|
if (!callerDoc) {
|
|
|
|
// If we're called from C++ or in some other way without an originating
|
|
|
|
// document 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
|
2008-01-25 21:49:11 +00:00
|
|
|
// refuse to go ahead with this call.
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2008-12-11 21:00:37 +00:00
|
|
|
// Grab a reference to the calling documents security info (if any)
|
|
|
|
// and URIs as they may be lost in the call to Reset().
|
|
|
|
nsCOMPtr<nsISupports> securityInfo = callerDoc->GetSecurityInfo();
|
|
|
|
nsCOMPtr<nsIURI> uri = callerDoc->GetDocumentURI();
|
|
|
|
nsCOMPtr<nsIURI> baseURI = callerDoc->GetBaseURI();
|
|
|
|
nsCOMPtr<nsIPrincipal> callerPrincipal = callerDoc->NodePrincipal();
|
|
|
|
|
2008-01-25 21:49:11 +00:00
|
|
|
// 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
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
// Stop current loads targeted at the window this document is in.
|
2008-07-09 13:48:02 +00:00
|
|
|
if (mScriptGlobalObject) {
|
2004-02-11 06:09:51 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2008-07-09 13:48:02 +00:00
|
|
|
shell->GetContentViewer(getter_AddRefs(cv));
|
2004-02-11 06:09:51 +00:00
|
|
|
|
|
|
|
if (cv) {
|
|
|
|
PRBool okToUnload;
|
2009-10-20 14:19:43 +00:00
|
|
|
rv = cv->PermitUnload(PR_FALSE, &okToUnload);
|
2004-02-11 06:09:51 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !okToUnload) {
|
|
|
|
// We don't want to unload, so stop here, but don't throw an
|
|
|
|
// exception.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 13:48:02 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(shell));
|
2003-09-19 20:00:24 +00:00
|
|
|
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
|
|
|
|
2008-11-18 22:54:36 +00:00
|
|
|
// We can't depend on channels implementing property bags, so do our
|
|
|
|
// base URI manually after reset.
|
|
|
|
|
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
|
|
|
|
2009-07-25 11:27:42 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool willReparent = mWillReparent;
|
|
|
|
mWillReparent = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
|
2010-03-13 00:59:18 +00:00
|
|
|
rv = window->SetNewDocument(this, nsnull);
|
2006-04-26 19:53:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2009-07-25 11:27:42 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mWillReparent = willReparent;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-05-12 02:04:58 +00:00
|
|
|
// Call Reset(), this will now do the full reset
|
2003-10-22 06:09:48 +00:00
|
|
|
Reset(channel, group);
|
2008-11-18 22:54:36 +00:00
|
|
|
if (baseURI) {
|
|
|
|
mDocumentBaseURI = baseURI;
|
|
|
|
}
|
2001-03-22 08:51:52 +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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
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)) {
|
2009-06-28 22:44:22 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
nsHtml5Module::Initialize(mParser, this, uri, shell, channel);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> sink;
|
|
|
|
|
|
|
|
rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, uri, shell,
|
|
|
|
channel);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Don't use a parser without a content sink.
|
|
|
|
mParser = nsnull;
|
|
|
|
mWriteState = eNotWriting;
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
mParser->SetContentSink(sink);
|
2008-07-09 13:48:02 +00:00
|
|
|
}
|
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()
|
2008-07-09 13:48:02 +00:00
|
|
|
shell->PrepareForNewContentModel();
|
2004-04-28 01:40:39 +00:00
|
|
|
|
2008-07-09 13:48:02 +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
|
|
|
|
// 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.
|
|
|
|
shell->SetLoadType(aReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL);
|
2007-07-03 21:41:32 +00:00
|
|
|
|
2008-07-09 13:48:02 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
shell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv);
|
|
|
|
if (docViewer) {
|
|
|
|
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()
|
|
|
|
{
|
2009-08-25 17:15:55 +00:00
|
|
|
if (!IsHTML()) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.close() on XHTML!
|
|
|
|
|
2009-09-27 09:20:30 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
mWriteState = mPendingScripts.IsEmpty() ? eDocumentClosed : ePendingClose;
|
2006-06-19 23:51:32 +00:00
|
|
|
|
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);
|
|
|
|
|
2009-11-06 04:27:30 +00:00
|
|
|
if (!IsHTML() || mDisableDocWrite) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.write*() on XHTML!
|
|
|
|
|
2009-09-27 09:20:30 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
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 &&
|
2009-10-15 11:29:11 +00:00
|
|
|
!mPendingScripts.Contains(key)) ||
|
|
|
|
(mParser && !mParser->IsInsertionPointDefined())) {
|
2006-01-24 01:25:14 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-03-13 08:48:05 +00:00
|
|
|
return nsDocument::GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn);
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetElementById(const nsAString& aElementId,
|
|
|
|
nsIDOMElement** aReturn)
|
|
|
|
{
|
|
|
|
return nsDocument::GetElementById(aElementId, aReturn);
|
|
|
|
}
|
|
|
|
|
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);
|
2009-06-19 20:57:39 +00:00
|
|
|
return
|
|
|
|
aContent->GetNameSpaceID() == kNameSpaceID_XHTML &&
|
|
|
|
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
|
|
|
{
|
2010-02-09 17:09:06 +00:00
|
|
|
nsString* elementNameData = new nsString(aElementName);
|
2007-02-01 15:14:00 +00:00
|
|
|
NS_ENSURE_TRUE(elementNameData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsContentList* elements =
|
2010-02-09 17:09:06 +00:00
|
|
|
NS_GetFuncStringContentList(this,
|
|
|
|
MatchNameAttribute,
|
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
elementNameData,
|
|
|
|
*elementNameData).get();
|
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
|
|
|
|
2010-02-09 17:09:06 +00:00
|
|
|
// Transfer ownership
|
2001-03-22 08:51:52 +00:00
|
|
|
*aReturn = elements;
|
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);
|
2009-03-20 08:15:35 +00:00
|
|
|
if (mPendingScripts.IsEmpty() && mWriteState == ePendingClose) {
|
2006-01-24 01:25:14 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
// 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
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame* frame = body->GetPrimaryFrame();
|
2007-05-23 03:52:53 +00:00
|
|
|
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);
|
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());
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetALink(aAlinkColor);
|
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);
|
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());
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetLink(aLinkColor);
|
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);
|
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());
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetVLink(aVlinkColor);
|
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());
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetBgColor(aBgColor);
|
1999-02-04 02:58:02 +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::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());
|
2003-03-26 07:41:30 +00:00
|
|
|
if (body) {
|
|
|
|
body->SetText(aFgColor);
|
1999-02-04 02:58:02 +00:00
|
|
|
}
|
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) {
|
2009-06-09 07:41:19 +00:00
|
|
|
mEmbeds = new nsContentList(this, nsGkAtoms::embed, kNameSpaceID_XHTML);
|
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());
|
|
|
|
}
|
|
|
|
|
2009-08-15 08:51:37 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetScopeObject());
|
|
|
|
nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(window);
|
|
|
|
NS_ENSURE_TRUE(pwin, NS_OK);
|
|
|
|
NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!");
|
|
|
|
NS_ENSURE_TRUE(pwin->GetOuterWindow() &&
|
|
|
|
pwin->GetOuterWindow()->GetCurrentInnerWindow() == pwin,
|
|
|
|
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
|
|
|
static void
|
2005-11-16 02:55:29 +00:00
|
|
|
FindNamedItems(nsIAtom* aName, nsIContent *aContent,
|
2008-06-22 23:12:40 +00:00
|
|
|
nsIdentifierMapEntry* aEntry)
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2008-06-22 23:12:40 +00:00
|
|
|
NS_ASSERTION(aEntry->HasNameContentList(),
|
2002-01-25 06:37:35 +00:00
|
|
|
"Entry w/o content list passed to FindNamedItems()!");
|
2008-06-22 23:12:40 +00:00
|
|
|
NS_ASSERTION(!aEntry->IsInvalidName(),
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
if (aName == nsContentUtils::IsNamedItem(aContent)) {
|
|
|
|
aEntry->AddNameContent(aContent);
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
if (!aEntry->GetIdContent() &&
|
2005-11-16 02:55:29 +00:00
|
|
|
// Maybe this node has the right id?
|
|
|
|
aName == aContent->GetID()) {
|
2008-06-22 23:12:40 +00:00
|
|
|
aEntry->AddIdContent(aContent);
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 i, count = aContent->GetChildCount();
|
|
|
|
for (i = 0; i < count; ++i) {
|
2008-06-22 23:12:40 +00:00
|
|
|
FindNamedItems(aName, aContent->GetChildAt(i), aEntry);
|
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;
|
|
|
|
|
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.
|
2008-06-22 23:12:40 +00:00
|
|
|
nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(name);
|
2002-01-25 06:37:35 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
if (entry->IsInvalidName()) {
|
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.
|
2008-06-22 23:12:40 +00:00
|
|
|
PRUint32 generation = mIdentifierMap.GetGeneration();
|
2004-05-08 06:07:04 +00:00
|
|
|
|
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.
|
2008-06-22 23:12:40 +00:00
|
|
|
FlushPendingNotifications(entry->HasNameContentList() ?
|
2007-12-21 13:44:58 +00:00
|
|
|
Flush_ContentAndNotify : Flush_Content);
|
2004-05-07 20:02:40 +00:00
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
if (generation != mIdentifierMap.GetGeneration()) {
|
2004-05-08 06:07:04 +00:00
|
|
|
// 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).
|
2008-06-22 23:12:40 +00:00
|
|
|
entry = mIdentifierMap.PutEntry(name);
|
2004-05-08 06:07:04 +00:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
if (!entry->HasNameContentList()) {
|
2001-03-22 08:51:52 +00:00
|
|
|
#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
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
nsresult rv = entry->CreateNameContentList();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
if (root && !aName.IsEmpty()) {
|
2008-06-22 23:12:40 +00:00
|
|
|
FindNamedItems(name, root, entry);
|
2001-07-17 13:53:15 +00:00
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
nsBaseContentList *list = entry->GetNameContentList();
|
|
|
|
|
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
|
2008-10-22 14:31:14 +00:00
|
|
|
// nsFormContentList 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
|
|
|
|
2009-08-24 20:02:07 +00:00
|
|
|
if (e && e->IsHTML()) {
|
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
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
// 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::PrePopulateIdentifierMap()
|
|
|
|
{
|
|
|
|
static const char names[][13] = {
|
|
|
|
"write", "writeln", "open", "close", "forms", "elements",
|
|
|
|
"characterSet", "nodeType", "parentNode", "cookie"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(names); ++i) {
|
|
|
|
nsCOMPtr<nsIAtom> atom(do_GetAtom(names[i]));
|
|
|
|
NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(atom);
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
entry->SetInvalidName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-28 15:55:31 +00:00
|
|
|
//----------------------------
|
1998-09-04 15:41:20 +00:00
|
|
|
|
2008-02-19 18:47:34 +00:00
|
|
|
/* virtual */ nsIContent*
|
|
|
|
nsHTMLDocument::GetBodyContentExternal()
|
|
|
|
{
|
|
|
|
return GetBodyContent();
|
|
|
|
}
|
|
|
|
|
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)
|
2009-06-09 07:41:19 +00:00
|
|
|
mForms = new nsContentList(this, nsGkAtoms::form, kNameSpaceID_XHTML);
|
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.
|
2009-10-15 11:29:11 +00:00
|
|
|
if (nsHtml5Module::sEnabled) {
|
|
|
|
nsIScriptElement* script = mScriptLoader->GetCurrentScript();
|
|
|
|
if (script && mParser && mParser->IsScriptCreated()) {
|
|
|
|
nsCOMPtr<nsIParser> creatorParser = script->GetCreatorParser();
|
|
|
|
if (creatorParser != mParser) {
|
|
|
|
// Make scripts that aren't inserted by the active parser of this document
|
|
|
|
// participate in the context of the script that document.open()ed
|
|
|
|
// this document.
|
|
|
|
return mParser->GetRootContextKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return script;
|
|
|
|
} else {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-31 12:53:01 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::MaybeEditingStateChanged()
|
|
|
|
{
|
2010-02-06 21:33:53 +00:00
|
|
|
if (mUpdateNestLevel == 0 && (mContentEditableCount > 0) != IsEditingOn()) {
|
2009-01-31 12:53:01 +00:00
|
|
|
if (nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
EditingStateChanged();
|
|
|
|
} else if (!mInDestructor) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NS_NEW_RUNNABLE_METHOD(nsHTMLDocument, this, MaybeEditingStateChanged));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 10:30:44 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::EndUpdate(nsUpdateType aUpdateType)
|
|
|
|
{
|
|
|
|
nsDocument::EndUpdate(aUpdateType);
|
|
|
|
|
2009-01-31 12:53:01 +00:00
|
|
|
MaybeEditingStateChanged();
|
2007-10-26 10:30:44 +00:00
|
|
|
}
|
|
|
|
|
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 ||
|
2010-02-06 21:33:53 +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);
|
2009-06-09 07:41:19 +00:00
|
|
|
if (!elm) {
|
2007-07-26 00:36:19 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* tag = elm->Tag();
|
2008-08-25 23:48:37 +00:00
|
|
|
if (tag != nsGkAtoms::a &&
|
2007-07-26 00:36:19 +00:00
|
|
|
tag != nsGkAtoms::applet &&
|
2008-08-25 23:48:37 +00:00
|
|
|
tag != nsGkAtoms::button &&
|
|
|
|
tag != nsGkAtoms::embed &&
|
|
|
|
tag != nsGkAtoms::form &&
|
|
|
|
tag != nsGkAtoms::iframe &&
|
|
|
|
tag != nsGkAtoms::img &&
|
|
|
|
tag != nsGkAtoms::input &&
|
|
|
|
tag != nsGkAtoms::map &&
|
|
|
|
tag != nsGkAtoms::meta &&
|
2007-07-26 00:36:19 +00:00
|
|
|
tag != nsGkAtoms::object &&
|
2008-08-25 23:48:37 +00:00
|
|
|
tag != nsGkAtoms::select &&
|
|
|
|
tag != nsGkAtoms::textarea) {
|
2007-07-26 00:36:19 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> id = do_GetAtom(aID);
|
2009-03-23 14:04:40 +00:00
|
|
|
nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(id);
|
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
2007-07-26 00:36:19 +00:00
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
if (!root) {
|
2007-07-26 00:36:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
nsRefPtr<nsContentList> docAllList = entry->GetDocAllList();
|
|
|
|
if (!docAllList) {
|
|
|
|
docAllList = new nsContentList(root, DocAllResultMatch,
|
|
|
|
nsnull, nsnull, PR_TRUE, id);
|
|
|
|
NS_ENSURE_TRUE(docAllList, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
entry->SetDocAllList(docAllList);
|
2007-07-26 00:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2008-06-04 20:18:58 +00:00
|
|
|
nsIContent* cont = docAllList->Item(1, PR_TRUE);
|
2007-07-26 00:36:19 +00:00
|
|
|
if (cont) {
|
2008-06-04 20:18:58 +00:00
|
|
|
NS_ADDREF(*aResult = static_cast<nsIDOMNodeList*>(docAllList));
|
2007-07-26 00:36:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's only 0 or 1 items. Return the first one or null.
|
2008-06-04 20:18:58 +00:00
|
|
|
NS_IF_ADDREF(*aResult = docAllList->Item(0, PR_TRUE));
|
2007-07-26 00:36:19 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 09:54:52 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor)
|
|
|
|
{
|
|
|
|
if (IsEditingOn()) {
|
2009-02-12 04:15:59 +00:00
|
|
|
EditingState oldState = mEditingState;
|
2008-02-20 09:54:52 +00:00
|
|
|
mEditingState = eTearingDown;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(aEditor);
|
|
|
|
if (editorss) {
|
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css"));
|
2009-02-12 04:15:59 +00:00
|
|
|
if (oldState == eDesignMode)
|
2008-02-20 09:54:52 +00:00
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
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<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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-23 21:36:17 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::SetEditingState(EditingState aState)
|
|
|
|
{
|
|
|
|
mEditingState = aState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::EditingStateChanged()
|
|
|
|
{
|
2008-05-02 11:36:29 +00:00
|
|
|
if (mRemovedFromDocShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-20 09:54:52 +00:00
|
|
|
if (mEditingState == eSettingUp || mEditingState == eTearingDown) {
|
2007-06-28 02:48:16 +00:00
|
|
|
// 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;
|
2008-09-18 02:32:44 +00:00
|
|
|
PRBool updateState;
|
|
|
|
PRBool spellRecheckAll = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2007-11-02 00:51:08 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
{
|
2009-02-12 04:15:59 +00:00
|
|
|
EditingState oldState = mEditingState;
|
2008-09-18 02:32:44 +00:00
|
|
|
nsAutoEditingState push(this, eSettingUp);
|
|
|
|
|
|
|
|
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.
|
|
|
|
rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
|
|
|
|
PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
// XXX Need to call TearDownEditorOnWindow for all failures.
|
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell =
|
|
|
|
do_QueryInterface(docshell, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
editorDocShell->GetEditor(getter_AddRefs(editor));
|
|
|
|
if (!editor)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
editorss->AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +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.
|
|
|
|
if (designMode) {
|
|
|
|
// designMode is being turned on (overrides contentEditable).
|
|
|
|
editorss->AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
// Disable scripting and plugins.
|
|
|
|
rv = editSession->DisableJSAndPlugins(window);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-03 11:54:41 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
updateState = PR_TRUE;
|
2009-02-12 04:15:59 +00:00
|
|
|
spellRecheckAll = oldState == eContentEditable;
|
2008-09-18 02:32:44 +00:00
|
|
|
}
|
2009-02-12 04:15:59 +00:00
|
|
|
else if (oldState == eDesignMode) {
|
2008-09-18 02:32:44 +00:00
|
|
|
// designMode is being turned off (contentEditable is still on).
|
|
|
|
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
rv = editSession->RestoreJSAndPlugins(window);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2008-09-18 02:32:44 +00:00
|
|
|
updateState = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// contentEditable is being turned on (and designMode is off).
|
|
|
|
updateState = PR_FALSE;
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
2008-10-29 20:12:24 +00:00
|
|
|
if (!IsEditingOnAfterFlush())
|
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
|
|
|
|
2008-09-18 11:15:47 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
|
|
|
nsRefPtr<nsHTMLDocument> clone = new nsHTMLDocument();
|
|
|
|
NS_ENSURE_TRUE(clone, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// State from nsHTMLDocument
|
|
|
|
clone->mLoadFlags = mLoadFlags;
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
2008-10-29 20:12:24 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLDocument::IsEditingOnAfterFlush()
|
|
|
|
{
|
|
|
|
nsIDocument* doc = GetParentDocument();
|
|
|
|
if (doc) {
|
|
|
|
// Make sure frames are up to date, since that can affect whether
|
|
|
|
// we're editable.
|
|
|
|
doc->FlushPendingNotifications(Flush_Frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsEditingOn();
|
|
|
|
}
|
2009-02-21 02:51:48 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::RemovedFromDocShell()
|
|
|
|
{
|
|
|
|
mEditingState = eOff;
|
|
|
|
nsDocument::RemovedFromDocShell();
|
|
|
|
}
|