2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2013-09-06 06:41:42 +00:00
|
|
|
#include "nsHTMLDocument.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2014-09-21 16:36:25 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
2013-09-06 06:41:42 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/dom/HTMLAllCollection.h"
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-12 08:15:56 +00:00
|
|
|
#include "nsGlobalWindow.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 "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"
|
2005-08-12 04:11:00 +00:00
|
|
|
#include "nsPIDOMWindow.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"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIPrivateBrowsingChannel.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIContentViewerContainer.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2013-11-15 07:12:43 +00:00
|
|
|
#include "nsDocShell.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"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2012-06-15 06:31:27 +00:00
|
|
|
#include "nsJSPrincipals.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-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"
|
2010-05-02 08:02:21 +00:00
|
|
|
#include "nsIDOMHTMLHeadElement.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-07-07 04:52:27 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2010-06-28 22:49:35 +00:00
|
|
|
#include "mozilla/css/Loader.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIFile.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
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2004-04-13 03:21:50 +00:00
|
|
|
#include "nsJSUtils.h"
|
2013-01-12 21:53:01 +00:00
|
|
|
#include "nsIDocumentInlines.h"
|
2000-05-13 08:11:29 +00:00
|
|
|
#include "nsIDocumentEncoder.h" //for outputting selection
|
2001-04-27 02:26:32 +00:00
|
|
|
#include "nsICachingChannel.h"
|
2011-10-15 07:33:26 +00:00
|
|
|
#include "nsIContentViewer.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"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2003-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
|
|
|
|
2013-03-04 18:09:11 +00:00
|
|
|
#include "mozilla/dom/EncodingUtils.h"
|
2013-11-04 11:24:33 +00:00
|
|
|
#include "mozilla/dom/FallbackEncoding.h"
|
2014-07-10 06:56:37 +00:00
|
|
|
#include "mozilla/LoadInfo.h"
|
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"
|
2010-12-06 19:27:14 +00:00
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsIHTMLEditor.h"
|
2007-06-28 02:48:16 +00:00
|
|
|
#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"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-05-28 07:03:00 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-11-01 15:27:36 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2012-01-30 17:03:52 +00:00
|
|
|
#include "nsIRequest.h"
|
2012-03-24 11:34:42 +00:00
|
|
|
#include "nsHtml5TreeOpExecutor.h"
|
2012-03-27 06:27:45 +00:00
|
|
|
#include "nsHtml5Parser.h"
|
2012-08-20 18:34:32 +00:00
|
|
|
#include "nsSandboxFlags.h"
|
2012-12-12 02:45:36 +00:00
|
|
|
#include "nsIImageDocument.h"
|
2013-01-12 21:53:01 +00:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.h"
|
2012-12-12 02:45:36 +00:00
|
|
|
#include "mozilla/dom/HTMLDocumentBinding.h"
|
2013-01-18 14:27:03 +00:00
|
|
|
#include "nsCharsetSource.h"
|
2013-03-19 20:30:53 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2013-03-27 17:15:37 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2015-04-21 06:27:10 +00:00
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
2015-06-16 01:34:48 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2016-02-24 07:01:12 +00:00
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
|
|
|
#include "mozilla/StyleSheetHandleInlines.h"
|
2010-04-30 13:12:05 +00:00
|
|
|
|
2011-05-28 07:03:00 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2007-02-11 00:30:20 +00:00
|
|
|
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
|
|
|
|
|
1999-11-12 02:06:54 +00:00
|
|
|
#include "prtime.h"
|
1999-07-14 17:13:05 +00:00
|
|
|
|
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);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t 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
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
2008-01-14 09:26:22 +00:00
|
|
|
const nsAString & inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& isBoolean,
|
|
|
|
bool& boolValue);
|
2008-01-14 09:26:22 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
2008-01-14 09:26:22 +00:00
|
|
|
nsACString& outCommandID);
|
2000-08-16 23:16:21 +00:00
|
|
|
|
1999-01-19 16:58:45 +00:00
|
|
|
// ==================================================================
|
|
|
|
// =
|
|
|
|
// ==================================================================
|
2010-10-29 16:30:15 +00:00
|
|
|
|
2003-03-05 15:08:41 +00:00
|
|
|
nsresult
|
2012-11-21 16:18:57 +00:00
|
|
|
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsHTMLDocument> doc = new nsHTMLDocument();
|
2002-01-25 06:37:35 +00:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-07-27 09:12:38 +00:00
|
|
|
*aInstancePtrResult = nullptr;
|
|
|
|
return rv;
|
2002-01-25 06:37:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 16:18:57 +00:00
|
|
|
doc->SetLoadedAsData(aLoadedAsData);
|
2013-07-27 09:12:38 +00:00
|
|
|
doc.forget(aInstancePtrResult);
|
2002-01-25 06:37:35 +00:00
|
|
|
|
2013-07-27 09:12:38 +00:00
|
|
|
return NS_OK;
|
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.
|
|
|
|
|
2013-05-06 13:42:00 +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
|
|
|
|
2014-05-24 19:28:48 +00:00
|
|
|
mType = eHTML;
|
2015-10-14 15:07:06 +00:00
|
|
|
mDefaultElementType = kNameSpaceID_XHTML;
|
2006-12-05 15:46:18 +00:00
|
|
|
mCompatMode = eCompatibility_NavQuirks;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 06:55:00 +00:00
|
|
|
nsHTMLDocument::~nsHTMLDocument()
|
|
|
|
{
|
2013-09-06 06:41:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsDocument,
|
|
|
|
mAll,
|
|
|
|
mImages,
|
|
|
|
mApplets,
|
|
|
|
mEmbeds,
|
|
|
|
mLinks,
|
|
|
|
mAnchors,
|
|
|
|
mScripts,
|
|
|
|
mForms,
|
|
|
|
mFormControls,
|
|
|
|
mWyciwygChannel,
|
|
|
|
mMidasCommandManager)
|
2009-10-21 09:41:18 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2008-02-21 20:39:20 +00:00
|
|
|
// QueryInterface implementation for nsHTMLDocument
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(nsHTMLDocument, nsIHTMLDocument,
|
|
|
|
nsIDOMHTMLDocument)
|
2013-05-21 19:59:27 +00:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsDocument)
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2012-12-12 02:45:36 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-12 02:45:36 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return HTMLDocumentBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-12 02:45:36 +00:00
|
|
|
}
|
2008-02-21 20:39:20 +00:00
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mImages = nullptr;
|
|
|
|
mApplets = nullptr;
|
|
|
|
mEmbeds = nullptr;
|
|
|
|
mLinks = nullptr;
|
|
|
|
mAnchors = nullptr;
|
|
|
|
mScripts = nullptr;
|
1999-01-06 00:32:41 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mForms = nullptr;
|
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!");
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mWyciwygChannel = nullptr;
|
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.
|
2010-06-26 20:39:56 +00:00
|
|
|
SetContentTypeInternal(nsDependentCString("text/html"));
|
1999-01-06 00:32:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 10:26:37 +00:00
|
|
|
already_AddRefed<nsIPresShell>
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLDocument::CreateShell(nsPresContext* aContext,
|
2013-01-05 03:12:24 +00:00
|
|
|
nsViewManager* aViewManager,
|
2016-02-24 07:01:11 +00:00
|
|
|
StyleSetHandle aStyleSet)
|
1999-07-07 01:27:08 +00:00
|
|
|
{
|
2016-01-06 00:08:17 +00:00
|
|
|
return doCreateShell(aContext, aViewManager, aStyleSet);
|
1999-07-07 01:27:08 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 07:42:54 +00:00
|
|
|
void
|
2014-07-09 21:27:49 +00:00
|
|
|
nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& aCharsetSource, nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2014-07-09 21:27:49 +00:00
|
|
|
if (aCv) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t requestCharsetSource;
|
2014-07-09 21:27:49 +00:00
|
|
|
nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString requestCharset;
|
2014-07-09 21:27:49 +00:00
|
|
|
rv = aCv->GetHintCharacterSet(requestCharset);
|
|
|
|
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if(requestCharsetSource <= aCharsetSource)
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2013-03-04 18:09:11 +00:00
|
|
|
if(NS_SUCCEEDED(rv) && EncodingUtils::IsAsciiCompatible(requestCharset)) {
|
2001-12-26 03:17:59 +00:00
|
|
|
aCharsetSource = requestCharsetSource;
|
|
|
|
aCharset = requestCharset;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
void
|
2014-07-09 21:27:49 +00:00
|
|
|
nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
2012-01-24 09:52:05 +00:00
|
|
|
nsIDocShell* aDocShell,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& 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)
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// mCharacterSet not updated yet for channel, so check aCharset, too.
|
2013-03-04 18:09:11 +00:00
|
|
|
if (WillIgnoreCharsetOverride() || !EncodingUtils::IsAsciiCompatible(aCharset)) {
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString forceCharsetFromDocShell;
|
2014-07-09 21:27:49 +00:00
|
|
|
if (aCv) {
|
2013-01-18 14:27:03 +00:00
|
|
|
// XXX mailnews-only
|
2014-07-09 21:27:49 +00:00
|
|
|
rv = aCv->GetForceCharacterSet(forceCharsetFromDocShell);
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
if(NS_SUCCEEDED(rv) &&
|
|
|
|
!forceCharsetFromDocShell.IsEmpty() &&
|
2013-03-04 18:09:11 +00:00
|
|
|
EncodingUtils::IsAsciiCompatible(forceCharsetFromDocShell)) {
|
2003-04-02 11:18:00 +00:00
|
|
|
aCharset = forceCharsetFromDocShell;
|
2003-03-26 07:41:30 +00:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDocShell) {
|
|
|
|
// This is the Character Encoding menu code path in Firefox
|
2013-05-25 14:09:30 +00:00
|
|
|
nsAutoCString charset;
|
|
|
|
rv = aDocShell->GetForcedCharset(charset);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) {
|
2013-03-04 18:09:11 +00:00
|
|
|
if (!EncodingUtils::IsAsciiCompatible(charset)) {
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
aCharset = charset;
|
2003-03-26 07:41:30 +00:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-05-25 14:09:30 +00:00
|
|
|
aDocShell->SetForcedCharset(NS_LITERAL_CSTRING(""));
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
void
|
2010-06-24 06:55:19 +00:00
|
|
|
nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& 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) {
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
|
2010-06-24 06:55:19 +00:00
|
|
|
nsCString cachedCharset;
|
|
|
|
rv = aCachingChannel->GetCacheTokenCachedCharset(cachedCharset);
|
2013-03-04 18:09:11 +00:00
|
|
|
// Check EncodingUtils::IsAsciiCompatible() even in the cache case, because the value
|
2012-10-16 07:42:54 +00:00
|
|
|
// might be stale and in the case of a stale charset that is not a rough
|
|
|
|
// ASCII superset, the parser has no way to recover.
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
!cachedCharset.IsEmpty() &&
|
2013-03-04 18:09:11 +00:00
|
|
|
EncodingUtils::IsAsciiCompatible(cachedCharset))
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 07:42:54 +00:00
|
|
|
void
|
2012-01-24 09:52:05 +00:00
|
|
|
nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t& aCharsetSource,
|
2003-06-17 16:40:34 +00:00
|
|
|
nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2012-10-16 07:42:54 +00:00
|
|
|
if (!aDocShell) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-18 14:27:03 +00:00
|
|
|
if (aCharsetSource >= kCharsetFromParentForced) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 07:42:54 +00:00
|
|
|
int32_t parentSource;
|
|
|
|
nsAutoCString parentCharset;
|
2013-10-16 01:46:10 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> parentPrincipal;
|
|
|
|
aDocShell->GetParentCharset(parentCharset,
|
|
|
|
&parentSource,
|
|
|
|
getter_AddRefs(parentPrincipal));
|
2013-05-25 14:09:30 +00:00
|
|
|
if (parentCharset.IsEmpty()) {
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-18 14:27:03 +00:00
|
|
|
if (kCharsetFromParentForced == parentSource ||
|
|
|
|
kCharsetFromUserForced == parentSource) {
|
|
|
|
if (WillIgnoreCharsetOverride() ||
|
2013-03-04 18:09:11 +00:00
|
|
|
!EncodingUtils::IsAsciiCompatible(aCharset) || // if channel said UTF-16
|
|
|
|
!EncodingUtils::IsAsciiCompatible(parentCharset)) {
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2007-01-13 03:28:00 +00:00
|
|
|
}
|
2013-01-18 14:27:03 +00:00
|
|
|
aCharset.Assign(parentCharset);
|
|
|
|
aCharsetSource = kCharsetFromParentForced;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-13 03:28:00 +00:00
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
if (aCharsetSource >= kCharsetFromParentFrame) {
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
2012-10-16 07:42:54 +00:00
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
if (kCharsetFromCache <= parentSource) {
|
|
|
|
// Make sure that's OK
|
2013-10-16 01:46:10 +00:00
|
|
|
if (!NodePrincipal()->Equals(parentPrincipal) ||
|
2013-03-04 18:09:11 +00:00
|
|
|
!EncodingUtils::IsAsciiCompatible(parentCharset)) {
|
2013-01-18 14:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCharset.Assign(parentCharset);
|
|
|
|
aCharsetSource = kCharsetFromParentFrame;
|
|
|
|
}
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
|
2014-02-06 09:08:01 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::TryTLD(int32_t& aCharsetSource, nsACString& aCharset)
|
|
|
|
{
|
|
|
|
if (aCharsetSource >= kCharsetFromTopLevelDomain) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!FallbackEncoding::sGuessFallbackFromTopLevelDomain) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mDocumentURI) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAutoCString host;
|
|
|
|
mDocumentURI->GetAsciiHost(host);
|
|
|
|
if (host.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// First let's see if the host is DNS-absolute and ends with a dot and
|
|
|
|
// get rid of that one.
|
|
|
|
if (host.Last() == '.') {
|
|
|
|
host.SetLength(host.Length() - 1);
|
|
|
|
if (host.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we still have a dot, the host is weird, so let's continue only
|
|
|
|
// if we have something other than a dot now.
|
|
|
|
if (host.Last() == '.') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int32_t index = host.RFindChar('.');
|
|
|
|
if (index == kNotFound) {
|
|
|
|
// We have an intranet host, Gecko-internal URL or an IPv6 address.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Since the string didn't end with a dot and we found a dot,
|
|
|
|
// there is at least one character between the dot and the end of
|
|
|
|
// the string, so taking the substring below is safe.
|
|
|
|
nsAutoCString tld;
|
|
|
|
ToLowerCase(Substring(host, index + 1, host.Length() - (index + 1)), tld);
|
|
|
|
// Reject generic TLDs and country TLDs that need more research
|
|
|
|
if (!FallbackEncoding::IsParticipatingTopLevelDomain(tld)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check if we have an IPv4 address
|
|
|
|
bool seenNonDigit = false;
|
|
|
|
for (size_t i = 0; i < tld.Length(); ++i) {
|
|
|
|
char c = tld.CharAt(i);
|
|
|
|
if (c < '0' || c > '9') {
|
|
|
|
seenNonDigit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!seenNonDigit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aCharsetSource = kCharsetFromTopLevelDomain;
|
|
|
|
FallbackEncoding::FromTopLevelDomain(tld, aCharset);
|
|
|
|
}
|
|
|
|
|
2012-10-16 07:42:54 +00:00
|
|
|
void
|
2013-11-04 11:24:33 +00:00
|
|
|
nsHTMLDocument::TryFallback(int32_t& aCharsetSource, nsACString& aCharset)
|
2001-12-26 03:17:59 +00:00
|
|
|
{
|
2013-11-04 11:24:33 +00:00
|
|
|
if (kCharsetFromFallback <= aCharsetSource)
|
2012-10-16 07:42:54 +00:00
|
|
|
return;
|
2004-04-29 23:34:19 +00:00
|
|
|
|
2013-11-04 11:24:33 +00:00
|
|
|
aCharsetSource = kCharsetFromFallback;
|
|
|
|
FallbackEncoding::FromLocale(aCharset);
|
2001-12-26 03:17:59 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aReset,
|
2003-03-22 03:20:23 +00:00
|
|
|
nsIContentSink* aSink)
|
|
|
|
{
|
2012-03-31 14:10:34 +00:00
|
|
|
if (!aCommand) {
|
2012-04-10 07:02:31 +00:00
|
|
|
MOZ_ASSERT(false, "Command is mandatory");
|
2012-03-31 14:10:34 +00:00
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
if (aSink) {
|
2012-04-10 07:02:31 +00:00
|
|
|
MOZ_ASSERT(false, "Got a sink override. Should not happen for HTML doc.");
|
2012-03-31 14:10:34 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-05-24 19:28:48 +00:00
|
|
|
if (mType != eHTML) {
|
|
|
|
MOZ_ASSERT(mType == eXHTML);
|
2012-04-10 07:02:31 +00:00
|
|
|
MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start.");
|
2012-03-31 14:10:34 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString contentType;
|
2011-11-01 15:27:36 +00:00
|
|
|
aChannel->GetContentType(contentType);
|
|
|
|
|
2012-03-31 14:10:34 +00:00
|
|
|
bool view = !strcmp(aCommand, "view") ||
|
|
|
|
!strcmp(aCommand, "external-resource");
|
|
|
|
bool viewSource = !strcmp(aCommand, "view-source");
|
|
|
|
bool asData = !strcmp(aCommand, kLoadAsData);
|
2014-05-21 17:08:12 +00:00
|
|
|
bool import = !strcmp(aCommand, "import");
|
|
|
|
if (!(view || viewSource || asData || import)) {
|
2012-04-10 07:02:31 +00:00
|
|
|
MOZ_ASSERT(false, "Bad parser command");
|
2012-03-31 14:10:34 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool html = contentType.EqualsLiteral(TEXT_HTML);
|
2012-04-03 07:25:38 +00:00
|
|
|
bool xhtml = !html && contentType.EqualsLiteral(APPLICATION_XHTML_XML);
|
2013-03-19 20:30:53 +00:00
|
|
|
bool plainText = !html && !xhtml && nsContentUtils::IsPlainTextType(contentType);
|
2012-03-31 14:10:34 +00:00
|
|
|
if (!(html || xhtml || plainText || viewSource)) {
|
2012-04-10 07:02:31 +00:00
|
|
|
MOZ_ASSERT(false, "Channel with bad content type.");
|
2012-03-31 14:10:34 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2011-11-01 15:27:36 +00:00
|
|
|
}
|
|
|
|
|
2012-03-31 14:10:34 +00:00
|
|
|
bool loadAsHtml5 = true;
|
2011-11-01 11:33:11 +00:00
|
|
|
|
2012-03-31 14:10:34 +00:00
|
|
|
if (!viewSource && xhtml) {
|
|
|
|
// We're parsing XHTML as XML, remember that.
|
2014-05-24 19:28:48 +00:00
|
|
|
mType = eXHTML;
|
2012-03-31 14:10:34 +00:00
|
|
|
mCompatMode = eCompatibility_FullStandards;
|
|
|
|
loadAsHtml5 = 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
|
2012-03-31 14:10:34 +00:00
|
|
|
if (loadAsHtml5 && view) {
|
2010-02-02 07:39:26 +00:00
|
|
|
// 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.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isAbout = false;
|
2010-02-02 07:39:26 +00:00
|
|
|
if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString str;
|
2010-02-02 07:39:26 +00:00
|
|
|
uri->GetSpec(str);
|
|
|
|
if (str.EqualsLiteral("about:blank")) {
|
2011-10-17 14:59:28 +00:00
|
|
|
loadAsHtml5 = false;
|
2010-02-02 07:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-19 01:27:11 +00:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
|
|
|
|
2003-03-22 03:20:23 +00:00
|
|
|
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);
|
|
|
|
|
2012-03-31 14:10:34 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
|
|
|
if (plainText) {
|
|
|
|
if (viewSource) {
|
|
|
|
mParser->MarkAsNotScriptCreated("view-source-plain");
|
2011-11-01 15:27:36 +00:00
|
|
|
} else {
|
2012-03-31 14:10:34 +00:00
|
|
|
mParser->MarkAsNotScriptCreated("plain-text");
|
2011-11-01 15:27:36 +00:00
|
|
|
}
|
2012-03-31 14:10:34 +00:00
|
|
|
} else if (viewSource && !html) {
|
|
|
|
mParser->MarkAsNotScriptCreated("view-source-xml");
|
2009-06-28 22:44:22 +00:00
|
|
|
} else {
|
2012-03-31 14:10:34 +00:00
|
|
|
mParser->MarkAsNotScriptCreated(aCommand);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2012-03-31 14:10:34 +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
|
|
|
|
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));
|
2007-01-13 03:28:00 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
2013-02-12 22:02:51 +00:00
|
|
|
if (docShell) {
|
|
|
|
docShell->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
2008-09-28 19:14:28 +00:00
|
|
|
}
|
2007-01-13 03:28:00 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
|
|
|
if (parent) {
|
|
|
|
rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
2014-07-09 21:27:49 +00:00
|
|
|
if (!cv) {
|
|
|
|
cv = parentContentViewer.forget();
|
1999-12-09 07:18:38 +00:00
|
|
|
}
|
2001-05-15 03:42:33 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString 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
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t charsetSource;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString 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.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t parserCharsetSource;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString parserCharset;
|
2007-05-09 02:47:58 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel;
|
|
|
|
|
2014-12-17 19:14:04 +00:00
|
|
|
// For error reporting and referrer policy setting
|
2012-07-30 14:20:58 +00:00
|
|
|
nsHtml5TreeOpExecutor* executor = nullptr;
|
2012-03-24 11:34:42 +00:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
executor = static_cast<nsHtml5TreeOpExecutor*> (mParser->GetContentSink());
|
2014-12-17 19:14:04 +00:00
|
|
|
if (mReferrerPolicySet) {
|
|
|
|
// CSP may have set the referrer policy, so a speculative parser should
|
|
|
|
// start with the new referrer policy.
|
|
|
|
executor->SetSpeculationReferrerPolicy(static_cast<ReferrerPolicy>(mReferrerPolicy));
|
|
|
|
}
|
2012-03-24 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!IsHTMLDocument() || !docShell) { // no docshell for text/html XHR
|
|
|
|
charsetSource = IsHTMLDocument() ? kCharsetFromFallback
|
|
|
|
: kCharsetFromDocTypeDefault;
|
2004-06-17 00:13:25 +00:00
|
|
|
charset.AssignLiteral("UTF-8");
|
2012-03-24 11:34:42 +00:00
|
|
|
TryChannelCharset(aChannel, charsetSource, charset, executor);
|
2007-05-09 02:47:58 +00:00
|
|
|
parserCharsetSource = charsetSource;
|
|
|
|
parserCharset = charset;
|
2004-04-13 22:28:16 +00:00
|
|
|
} else {
|
2013-02-12 22:02:51 +00:00
|
|
|
NS_ASSERTION(docShell, "Unexpected null value");
|
2008-09-28 19:14:28 +00:00
|
|
|
|
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
|
|
|
|
2013-01-18 14:27:03 +00:00
|
|
|
// The following will try to get the character encoding from various
|
|
|
|
// sources. Each Try* function will return early if the source is already
|
|
|
|
// at least as large as any of the sources it might look at. Some of
|
|
|
|
// these functions (like TryHintCharset and TryParentCharset) can set
|
|
|
|
// charsetSource to various values depending on where the charset they
|
|
|
|
// end up finding originally comes from.
|
|
|
|
|
|
|
|
// Don't actually get the charset from the channel if this is a
|
|
|
|
// wyciwyg channel; it'll always be UTF-16
|
|
|
|
if (!wyciwygChannel) {
|
|
|
|
// Otherwise, try the channel's charset (e.g., charset from HTTP
|
|
|
|
// "Content-Type" header) first. This way, we get to reject overrides in
|
|
|
|
// TryParentCharset and TryUserForcedCharset if the channel said UTF-16.
|
|
|
|
// This is to avoid socially engineered XSS by adding user-supplied
|
|
|
|
// content to a UTF-16 site such that the byte have a dangerous
|
|
|
|
// interpretation as ASCII and the user can be lured to using the
|
|
|
|
// charset menu.
|
|
|
|
TryChannelCharset(aChannel, charsetSource, charset, executor);
|
|
|
|
}
|
|
|
|
|
2014-07-09 21:27:49 +00:00
|
|
|
TryUserForcedCharset(cv, docShell, charsetSource, charset);
|
2013-01-18 14:27:03 +00:00
|
|
|
|
2014-07-09 21:27:49 +00:00
|
|
|
TryHintCharset(cv, charsetSource, charset); // XXX mailnews-only
|
2013-10-16 01:46:10 +00:00
|
|
|
TryParentCharset(docShell, charsetSource, charset);
|
2013-01-18 14:27:03 +00:00
|
|
|
|
|
|
|
if (cachingChan && !urlSpec.IsEmpty()) {
|
|
|
|
TryCacheCharset(cachingChan, charsetSource, charset);
|
2000-08-05 00:07:03 +00:00
|
|
|
}
|
2002-08-26 20:13:31 +00:00
|
|
|
|
2014-02-06 09:08:01 +00:00
|
|
|
TryTLD(charsetSource, charset);
|
2013-11-04 11:24:33 +00:00
|
|
|
TryFallback(charsetSource, charset);
|
2013-01-18 14:27:03 +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;
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cachedCharset;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t cachedSource;
|
2007-05-09 02:47:58 +00:00
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
|
2010-06-24 06:55:19 +00:00
|
|
|
if (cachingChan) {
|
2007-05-09 02:47:58 +00:00
|
|
|
NS_ASSERTION(charset == parserCharset,
|
|
|
|
"How did those end up different here? wyciwyg channels are "
|
|
|
|
"not nsICachingChannel");
|
2010-06-24 06:55:19 +00:00
|
|
|
rv = cachingChan->SetCacheTokenCachedCharset(charset);
|
2011-06-05 16:20:53 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "cannot SetMetaDataElement");
|
2011-11-16 07:38:51 +00:00
|
|
|
rv = NS_OK; // don't propagate error
|
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...
|
2012-03-31 14:10:34 +00:00
|
|
|
rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = mParser->GetStreamListener();
|
|
|
|
listener.forget(aDocListener);
|
1998-07-02 08:14:22 +00:00
|
|
|
|
1999-12-13 21:00:47 +00:00
|
|
|
#ifdef DEBUG_charset
|
2012-03-31 14:10:34 +00:00
|
|
|
printf(" charset = %s source %d\n",
|
|
|
|
charset.get(), charsetSource);
|
1999-12-13 21:00:47 +00:00
|
|
|
#endif
|
2012-03-31 14:10:34 +00:00
|
|
|
mParser->SetDocumentCharset(parserCharset, parserCharsetSource);
|
|
|
|
mParser->SetCommand(aCommand);
|
2001-11-02 01:53:13 +00:00
|
|
|
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!IsHTMLDocument()) {
|
2012-03-31 14:10:34 +00:00
|
|
|
MOZ_ASSERT(!loadAsHtml5);
|
|
|
|
nsCOMPtr<nsIXMLContentSink> xmlsink;
|
|
|
|
NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri,
|
|
|
|
docShell, aChannel);
|
|
|
|
mParser->SetContentSink(xmlsink);
|
|
|
|
} else {
|
|
|
|
if (loadAsHtml5) {
|
|
|
|
nsHtml5Module::Initialize(mParser, this, uri, docShell, aChannel);
|
2009-06-28 22:44:22 +00:00
|
|
|
} else {
|
2012-03-31 14:10:34 +00:00
|
|
|
// about:blank *only*
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> htmlsink;
|
|
|
|
NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri,
|
|
|
|
docShell, aChannel);
|
|
|
|
mParser->SetContentSink(htmlsink);
|
2001-11-02 01:53:13 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-01 19:53:19 +00:00
|
|
|
|
2013-03-19 20:30:53 +00:00
|
|
|
if (plainText && !nsContentUtils::IsChildOfSameType(this) &&
|
|
|
|
Preferences::GetBool("plain_text.wrap_long_lines")) {
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && bundleService, "The bundle service could not be loaded");
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
rv = bundleService->CreateBundle("chrome://global/locale/browser.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && bundle, "chrome://global/locale/browser.properties could not be loaded");
|
|
|
|
nsXPIDLString title;
|
|
|
|
if (bundle) {
|
2013-12-13 01:50:01 +00:00
|
|
|
bundle->GetStringFromName(MOZ_UTF16("plainText.wordWrap"), getter_Copies(title));
|
2013-03-19 20:30:53 +00:00
|
|
|
}
|
|
|
|
SetSelectedStyleSheetSet(title);
|
|
|
|
}
|
|
|
|
|
2012-03-31 14:10:34 +00:00
|
|
|
// parser the content of the URI
|
2012-07-30 14:20:58 +00:00
|
|
|
mParser->Parse(uri, nullptr, (void *)this);
|
2012-03-31 14:10:34 +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()
|
|
|
|
{
|
2012-01-20 11:16:26 +00:00
|
|
|
BlockOnload();
|
2010-11-16 07:48:30 +00:00
|
|
|
|
2012-01-20 11:16:26 +00:00
|
|
|
// Remove the wyciwyg channel request from the document load group
|
|
|
|
// that we added in Open() if Open() was called on this doc.
|
|
|
|
RemoveWyciwygChannel();
|
|
|
|
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::StopDocumentLoad(): "
|
|
|
|
"nsIWyciwygChannel could not be removed!");
|
2002-04-18 22:49:39 +00:00
|
|
|
|
2012-01-20 11:16:26 +00:00
|
|
|
nsDocument::StopDocumentLoad();
|
|
|
|
UnblockOnload(false);
|
|
|
|
return;
|
2002-04-18 22:49:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-12 10:29:46 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::BeginLoad()
|
|
|
|
{
|
|
|
|
if (IsEditingOn()) {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
TurnEditingOff();
|
|
|
|
EditingStateChanged();
|
|
|
|
}
|
|
|
|
nsDocument::BeginLoad();
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
void
|
1998-07-23 22:06:05 +00:00
|
|
|
nsHTMLDocument::EndLoad()
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool turnOnEditing =
|
2007-06-28 02:48:16 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(IsHTMLDocument() || 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);
|
2010-06-25 13:59:57 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = GetShell();
|
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-10-20 17:07:23 +00:00
|
|
|
//
|
|
|
|
// nsIDOMHTMLDocument interface implementation
|
|
|
|
//
|
2013-03-17 08:51:39 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLDocument::GetDomainURI()
|
1999-10-02 03:41:37 +00:00
|
|
|
{
|
2013-03-17 08:51:39 +00:00
|
|
|
nsIPrincipal* principal = NodePrincipal();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2013-03-17 08:51:39 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
principal->GetDomain(getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
|
|
|
return uri.forget();
|
2003-10-21 22:11:49 +00:00
|
|
|
}
|
2013-03-17 08:51:39 +00:00
|
|
|
|
|
|
|
principal->GetURI(getter_AddRefs(uri));
|
|
|
|
return uri.forget();
|
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
|
|
|
{
|
2013-03-17 08:51:39 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = GetDomainURI();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (!uri) {
|
2014-11-26 19:25:20 +00:00
|
|
|
SetDOMStringToNull(aDomain);
|
2014-12-12 12:04:00 +00:00
|
|
|
return NS_OK;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
1999-10-02 03:41:37 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString hostName;
|
2016-02-10 12:13:00 +00:00
|
|
|
nsresult rv = nsContentUtils::GetHostOrIPv6WithBrackets(uri, hostName);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-01-28 23:44:08 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-12-12 12:04:00 +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
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
SetDomain(aDomain, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv)
|
|
|
|
{
|
2013-08-22 13:46:27 +00:00
|
|
|
if (mSandboxFlags & SANDBOXED_DOMAIN) {
|
|
|
|
// We're sandboxed; disallow setting domain
|
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
if (aDomain.IsEmpty()) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
1999-10-02 03:41:37 +00:00
|
|
|
// Create new URI
|
2013-03-17 08:51:39 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = GetDomainURI();
|
2003-03-26 07:41:30 +00:00
|
|
|
|
|
|
|
if (!uri) {
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 01:14:00 +00:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
nsresult rv2 = uri->Clone(getter_AddRefs(newURI));
|
|
|
|
if (NS_FAILED(rv2)) {
|
|
|
|
rv.Throw(rv2);
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-24 01:14:00 +00:00
|
|
|
|
|
|
|
rv2 = newURI->SetUserPass(EmptyCString());
|
|
|
|
if (NS_FAILED(rv2)) {
|
|
|
|
rv.Throw(rv2);
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-10-02 03:41:37 +00:00
|
|
|
|
2016-03-24 01:14:00 +00:00
|
|
|
rv2 = newURI->SetHostPort(NS_ConvertUTF16toUTF8(aDomain));
|
|
|
|
if (NS_FAILED(rv2)) {
|
|
|
|
rv.Throw(rv2);
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
|
|
|
}
|
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.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString 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();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ok = current.Equals(domain);
|
2007-11-12 07:58:16 +00:00
|
|
|
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);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!tldService) {
|
|
|
|
rv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
2007-11-12 07:58:16 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString currentBaseDomain;
|
2008-02-07 20:58:56 +00:00
|
|
|
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
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN);
|
|
|
|
return;
|
2007-11-12 07:58:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 01:14:00 +00:00
|
|
|
NS_TryToSetImmutable(newURI);
|
2012-12-26 02:00:47 +00:00
|
|
|
rv = NodePrincipal()->SetDomain(newURI);
|
1999-10-02 03:41:37 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
nsGenericHTMLElement*
|
2011-11-29 16:32:31 +00:00
|
|
|
nsHTMLDocument::GetBody()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2013-07-10 09:54:51 +00:00
|
|
|
Element* html = GetHtmlElement();
|
|
|
|
if (!html) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-05-11 16:27:44 +00:00
|
|
|
|
2013-07-10 09:54:51 +00:00
|
|
|
for (nsIContent* child = html->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::body) ||
|
|
|
|
child->IsHTMLElement(nsGkAtoms::frameset)) {
|
2013-07-10 09:54:51 +00:00
|
|
|
return static_cast<nsGenericHTMLElement*>(child);
|
|
|
|
}
|
2007-12-12 02:26:09 +00:00
|
|
|
}
|
2001-02-23 02:01:30 +00:00
|
|
|
|
2013-07-10 09:54:51 +00:00
|
|
|
return nullptr;
|
2010-04-19 15:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aBody = nullptr;
|
2010-04-19 15:41:38 +00:00
|
|
|
|
2011-11-29 16:32:31 +00:00
|
|
|
nsIContent *body = GetBody();
|
2006-03-23 08:21:21 +00:00
|
|
|
|
2011-11-29 16:32:31 +00:00
|
|
|
return body ? CallQueryInterface(body, 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);
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(!newBody || newBody->IsHTMLElement(),
|
2012-12-26 02:00:47 +00:00
|
|
|
"How could we be an nsIContent but not actually HTML here?");
|
|
|
|
ErrorResult rv;
|
|
|
|
SetBody(static_cast<nsGenericHTMLElement*>(newBody.get()), rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::SetBody(nsGenericHTMLElement* newBody, ErrorResult& rv)
|
|
|
|
{
|
2016-02-19 14:26:07 +00:00
|
|
|
nsCOMPtr<Element> root = GetRootElement();
|
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.
|
2015-03-03 11:09:00 +00:00
|
|
|
if (!newBody ||
|
|
|
|
!newBody->IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset) ||
|
2015-03-03 11:08:59 +00:00
|
|
|
!root || !root->IsHTMLElement() ||
|
2015-03-03 11:09:00 +00:00
|
|
|
!root->IsHTMLElement(nsGkAtoms::html)) {
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
|
|
|
return;
|
1999-02-04 02:16:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 02:26:09 +00:00
|
|
|
// Use DOM methods so that we pass through the appropriate security checks.
|
2013-07-04 15:20:45 +00:00
|
|
|
nsCOMPtr<Element> currentBody = GetBodyElement();
|
2007-12-12 02:26:09 +00:00
|
|
|
if (currentBody) {
|
2012-12-26 02:00:47 +00:00
|
|
|
root->ReplaceChild(*newBody, *currentBody, rv);
|
2013-07-04 15:20:45 +00:00
|
|
|
} else {
|
|
|
|
root->AppendChild(*newBody, rv);
|
2000-12-14 22:37:22 +00:00
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 08:02:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetHead(nsIDOMHTMLHeadElement** aHead)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aHead = nullptr;
|
2010-05-02 08:02:21 +00:00
|
|
|
|
|
|
|
Element* head = GetHeadElement();
|
|
|
|
|
|
|
|
return head ? CallQueryInterface(head, aHead) : NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aImages = Images());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Images()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mImages) {
|
2010-09-01 02:47:00 +00:00
|
|
|
mImages = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::img, nsGkAtoms::img);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mImages;
|
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::GetApplets(nsIDOMHTMLCollection** aApplets)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aApplets = Applets());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Applets()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2002-05-20 22:47:02 +00:00
|
|
|
if (!mApplets) {
|
2010-09-01 02:47:00 +00:00
|
|
|
mApplets = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::applet, nsGkAtoms::applet);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mApplets;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLDocument::MatchLinks(nsIContent *aContent, int32_t aNamespaceID,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2014-10-02 19:07:24 +00:00
|
|
|
nsIDocument* doc = aContent->GetUncomposedDoc();
|
2006-07-18 00:18:19 +00:00
|
|
|
|
|
|
|
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 =
|
2014-10-02 19:07:24 +00:00
|
|
|
do_QueryInterface(aContent->GetUncomposedDoc());
|
2006-07-18 00:18:19 +00:00
|
|
|
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
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo *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
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return 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)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aLinks = Links());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Links()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!mLinks) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mLinks = new nsContentList(this, MatchLinks, nullptr, nullptr);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mLinks;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLDocument::MatchAnchors(nsIContent *aContent, int32_t 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 =
|
2014-10-02 19:07:24 +00:00
|
|
|
do_QueryInterface(aContent->GetUncomposedDoc());
|
2005-09-24 18:43:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return 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)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aAnchors = Anchors());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Anchors()
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mAnchors) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mAnchors = new nsContentList(this, MatchAnchors, nullptr, nullptr);
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mAnchors;
|
2011-09-09 17:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetScripts(nsIDOMHTMLCollection** aScripts)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aScripts = Scripts());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Scripts()
|
2011-09-09 17:18:03 +00:00
|
|
|
{
|
|
|
|
if (!mScripts) {
|
|
|
|
mScripts = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::script, nsGkAtoms::script);
|
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mScripts;
|
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)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
GetCookie(aCookie, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 01:57:29 +00:00
|
|
|
already_AddRefed<nsIChannel>
|
|
|
|
nsHTMLDocument::CreateDummyChannelForCookies(nsIURI* aCodebaseURI)
|
|
|
|
{
|
|
|
|
// The cookie service reads the privacy status of the channel we pass to it in
|
|
|
|
// order to determine which cookie database to query. In some cases we don't
|
|
|
|
// have a proper channel to hand it to the cookie service though. This
|
|
|
|
// function creates a dummy channel that is not used to load anything, for the
|
|
|
|
// sole purpose of handing it to the cookie service. DO NOT USE THIS CHANNEL
|
|
|
|
// FOR ANY OTHER PURPOSE.
|
|
|
|
MOZ_ASSERT(!mChannel);
|
|
|
|
|
2016-03-09 21:55:59 +00:00
|
|
|
// The following channel is never openend, so it does not matter what
|
|
|
|
// securityFlags we pass; let's follow the principle of least privilege.
|
2015-01-22 01:57:29 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_NewChannel(getter_AddRefs(channel), aCodebaseURI, this,
|
2016-03-09 21:55:59 +00:00
|
|
|
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
|
2015-01-22 01:57:29 +00:00
|
|
|
nsIContentPolicy::TYPE_INVALID);
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel =
|
|
|
|
do_QueryInterface(channel);
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
|
|
|
if (!pbChannel || !loadContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
pbChannel->SetPrivate(loadContext->UsePrivateBrowsing());
|
|
|
|
return channel.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::GetCookie(nsAString& aCookie, ErrorResult& rv)
|
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) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
2008-10-01 00:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 18:34:32 +00:00
|
|
|
// If the document's sandboxed origin flag is set, access to read cookies
|
|
|
|
// is prohibited.
|
|
|
|
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2012-08-20 18:34:32 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
2002-07-02 17:58:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 01:57:29 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel(mChannel);
|
|
|
|
if (!channel) {
|
|
|
|
channel = CreateDummyChannelForCookies(codebaseURI);
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 00:11:04 +00:00
|
|
|
nsXPIDLCString cookie;
|
2015-01-22 01:57:29 +00:00
|
|
|
service->GetCookieString(codebaseURI, channel, getter_Copies(cookie));
|
2012-09-05 01:01:57 +00:00
|
|
|
// CopyUTF8toUTF16 doesn't handle error
|
|
|
|
// because it assumes that the input is valid.
|
2013-12-17 10:47:25 +00:00
|
|
|
nsContentUtils::ConvertStringFromEncoding(NS_LITERAL_CSTRING("UTF-8"),
|
|
|
|
cookie, aCookie);
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
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)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
SetCookie(aCookie, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::SetCookie(const nsAString& aCookie, ErrorResult& rv)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2008-10-01 00:49:30 +00:00
|
|
|
if (mDisableCookieAccess) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
2008-10-01 00:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 18:34:32 +00:00
|
|
|
// If the document's sandboxed origin flag is set, access to write cookies
|
|
|
|
// is prohibited.
|
|
|
|
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2012-08-20 18:34:32 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-08-03 18:32:32 +00:00
|
|
|
// The for getting the URI matches nsNavigator::GetCookieEnabled
|
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
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
2002-07-02 17:58:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 01:57:29 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel(mChannel);
|
|
|
|
if (!channel) {
|
|
|
|
channel = CreateDummyChannelForCookies(codebaseURI);
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 01:01:57 +00:00
|
|
|
NS_ConvertUTF16toUTF8 cookie(aCookie);
|
2015-01-22 01:57:29 +00:00
|
|
|
service->SetCookieString(codebaseURI, nullptr, cookie.get(), channel);
|
1999-08-19 22:23:20 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2011-06-04 06:57:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::Open(const nsAString& aContentTypeOrUrl,
|
|
|
|
const nsAString& aReplaceOrName,
|
|
|
|
const nsAString& aFeatures,
|
2012-08-22 15:56:38 +00:00
|
|
|
JSContext* cx, uint8_t aOptionalArgCount,
|
2011-06-04 06:57:23 +00:00
|
|
|
nsISupports** aReturn)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
// When called with 3 or more arguments, document.open() calls window.open().
|
|
|
|
if (aOptionalArgCount > 2) {
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn = Open(cx, aContentTypeOrUrl, aReplaceOrName, aFeatures,
|
2014-03-15 19:00:15 +00:00
|
|
|
false, rv).take();
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
if (aOptionalArgCount > 0) {
|
|
|
|
type = aContentTypeOrUrl;
|
|
|
|
} else {
|
|
|
|
type.AssignLiteral("text/html");
|
|
|
|
}
|
|
|
|
nsString replace;
|
|
|
|
if (aOptionalArgCount > 1) {
|
|
|
|
replace = aReplaceOrName;
|
|
|
|
}
|
|
|
|
ErrorResult rv;
|
2014-03-15 19:00:15 +00:00
|
|
|
*aReturn = Open(cx, type, replace, rv).take();
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
already_AddRefed<nsPIDOMWindowOuter>
|
2012-12-26 02:00:47 +00:00
|
|
|
nsHTMLDocument::Open(JSContext* /* unused */,
|
|
|
|
const nsAString& aURL,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aFeatures,
|
|
|
|
bool aReplace,
|
|
|
|
ErrorResult& rv)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2011-06-04 06:57:23 +00:00
|
|
|
NS_ASSERTION(nsContentUtils::CanCallerAccess(static_cast<nsIDOMHTMLDocument*>(this)),
|
|
|
|
"XOW should have caught this!");
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = GetInnerWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2011-06-04 06:57:23 +00:00
|
|
|
}
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> outer =
|
|
|
|
nsPIDOMWindowOuter::GetFromCurrentInner(window);
|
|
|
|
if (!outer) {
|
2015-07-17 05:10:35 +00:00
|
|
|
rv.Throw(NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-30 17:05:36 +00:00
|
|
|
RefPtr<nsGlobalWindow> win = nsGlobalWindow::Cast(outer);
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> newWindow;
|
2012-12-26 02:00:47 +00:00
|
|
|
// XXXbz We ignore aReplace for now.
|
|
|
|
rv = win->OpenJS(aURL, aName, aFeatures, getter_AddRefs(newWindow));
|
|
|
|
return newWindow.forget();
|
|
|
|
}
|
2011-06-04 06:57:23 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
nsHTMLDocument::Open(JSContext* cx,
|
|
|
|
const nsAString& aType,
|
|
|
|
const nsAString& aReplace,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
2015-09-23 10:12:24 +00:00
|
|
|
// Implements the "When called with two arguments (or fewer)" steps here:
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#opening-the-input-stream
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_ASSERTION(nsContentUtils::CanCallerAccess(static_cast<nsIDOMHTMLDocument*>(this)),
|
|
|
|
"XOW should have caught this!");
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!IsHTMLDocument() || mDisableDocWrite || !IsMasterDocument()) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.open() on XHTML
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString contentType;
|
2011-06-04 06:57:23 +00:00
|
|
|
contentType.AssignLiteral("text/html");
|
2012-12-26 02:00:47 +00:00
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nsContentUtils::ASCIIToLower(aType, type);
|
|
|
|
nsAutoCString actualType, dummy;
|
2015-10-01 18:36:19 +00:00
|
|
|
NS_ParseRequestContentType(NS_ConvertUTF16toUTF8(type), actualType, dummy);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!actualType.EqualsLiteral("text/html") &&
|
|
|
|
!type.EqualsLiteral("replace")) {
|
|
|
|
contentType.AssignLiteral("text/plain");
|
2011-06-04 06:57:23 +00:00
|
|
|
}
|
2006-08-01 21:48:03 +00:00
|
|
|
|
2007-01-05 22:02:22 +00:00
|
|
|
// If we already have a parser we ignore the document.open call.
|
2012-05-18 12:06:28 +00:00
|
|
|
if (mParser || mParserAborted) {
|
|
|
|
// The WHATWG spec says: "If the document has an active parser that isn't
|
|
|
|
// a script-created parser, and the insertion point associated with that
|
|
|
|
// parser's input stream is not undefined (that is, it does point to
|
|
|
|
// somewhere in the input stream), then the method does nothing. Abort
|
|
|
|
// these steps and return the Document object on which the method was
|
|
|
|
// invoked."
|
|
|
|
// Note that aborting a parser leaves the parser "active" with its
|
|
|
|
// insertion point "not undefined". We track this using mParserAborted,
|
|
|
|
// because aborting a parser nulls out mParser.
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2007-01-05 22:02:22 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 08:50:15 +00:00
|
|
|
// No calling document.open() without a script global object
|
|
|
|
if (!mScriptGlobalObject) {
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2011-11-14 08:50:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* outer = GetWindow();
|
2011-11-14 08:50:15 +00:00
|
|
|
if (!outer || (GetInnerWindow() != outer->GetCurrentInnerWindow())) {
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2011-11-14 08:50:15 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 18:18:05 +00:00
|
|
|
// check whether we're in the middle of unload. If so, ignore this call.
|
2013-11-15 07:12:43 +00:00
|
|
|
nsCOMPtr<nsIDocShell> shell(mDocumentContainer);
|
2008-07-09 13:48:02 +00:00
|
|
|
if (!shell) {
|
|
|
|
// We won't be able to create a parser anyway.
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2008-07-09 13:48:02 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool inUnload;
|
2008-07-09 13:48:02 +00:00
|
|
|
shell->GetIsInUnload(&inUnload);
|
|
|
|
if (inUnload) {
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2007-06-14 18:18:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 19:02:06 +00:00
|
|
|
// Note: We want to use GetEntryDocument here because this document
|
2005-11-03 22:47:06 +00:00
|
|
|
// 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).
|
2014-08-19 19:02:06 +00:00
|
|
|
nsCOMPtr<nsIDocument> callerDoc = GetEntryDocument();
|
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.
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return nullptr;
|
2008-01-25 21:49:11 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2012-01-30 17:03:52 +00:00
|
|
|
nsCOMPtr<nsIChannel> callerChannel = callerDoc->GetChannel();
|
2008-12-11 21:00:37 +00:00
|
|
|
|
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.
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool equals = false;
|
2008-01-25 21:49:11 +00:00
|
|
|
if (NS_FAILED(callerPrincipal->Equals(NodePrincipal(), &equals)) ||
|
|
|
|
!equals) {
|
2010-10-15 01:03:45 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIURI> callerDocURI = callerDoc->GetDocumentURI();
|
|
|
|
nsCOMPtr<nsIURI> thisURI = nsIDocument::GetDocumentURI();
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString callerSpec;
|
|
|
|
nsAutoCString thisSpec;
|
2010-10-15 01:03:45 +00:00
|
|
|
if (callerDocURI) {
|
|
|
|
callerDocURI->GetSpec(callerSpec);
|
|
|
|
}
|
|
|
|
if (thisURI) {
|
|
|
|
thisURI->GetSpec(thisSpec);
|
|
|
|
}
|
2011-06-04 06:57:23 +00:00
|
|
|
printf("nsHTMLDocument::Open callerDoc %s this %s\n", callerSpec.get(), thisSpec.get());
|
2010-10-15 01:03:45 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return nullptr;
|
2008-01-25 21:49:11 +00:00
|
|
|
}
|
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) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool okToUnload;
|
2015-09-24 20:32:09 +00:00
|
|
|
if (NS_SUCCEEDED(cv->PermitUnload(&okToUnload)) && !okToUnload) {
|
2004-02-11 06:09:51 +00:00
|
|
|
// We don't want to unload, so stop here, but don't throw an
|
|
|
|
// exception.
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIDocument> ret = this;
|
|
|
|
return ret.forget();
|
2004-02-11 06:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2010-01-18 09:07:08 +00:00
|
|
|
|
|
|
|
// The Stop call may have cancelled the onload blocker request or prevented
|
|
|
|
// it from getting added, so we need to make sure it gets added to the
|
|
|
|
// document again otherwise the document could have a non-zero onload block
|
|
|
|
// count without the onload blocker request being in the loadgroup.
|
|
|
|
EnsureOnloadBlocker();
|
2000-06-08 22:51:06 +00:00
|
|
|
}
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
// The open occurred after the document finished loading.
|
2015-09-23 10:12:24 +00:00
|
|
|
// So we reset the document and then reinitialize it.
|
2000-09-19 05:11:59 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
2014-09-21 16:36:25 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
callerDoc,
|
|
|
|
nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
|
|
|
group);
|
2001-05-25 08:49:03 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2000-08-12 22:19:55 +00:00
|
|
|
|
2012-01-30 17:03:52 +00:00
|
|
|
if (callerChannel) {
|
|
|
|
nsLoadFlags callerLoadFlags;
|
|
|
|
rv = callerChannel->GetLoadFlags(&callerLoadFlags);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-30 17:03:52 +00:00
|
|
|
|
|
|
|
nsLoadFlags loadFlags;
|
|
|
|
rv = channel->GetLoadFlags(&loadFlags);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-30 17:03:52 +00:00
|
|
|
|
|
|
|
loadFlags |= callerLoadFlags & nsIRequest::INHIBIT_PERSISTENT_CACHING;
|
|
|
|
|
|
|
|
rv = channel->SetLoadFlags(loadFlags);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-30 08:04:34 +00:00
|
|
|
|
|
|
|
// If the user has allowed mixed content on the rootDoc, then we should propogate it
|
|
|
|
// down to the new document channel.
|
|
|
|
bool rootHasSecureConnection = false;
|
|
|
|
bool allowMixedContent = false;
|
|
|
|
bool isDocShellRoot = false;
|
|
|
|
nsresult rvalue = shell->GetAllowMixedContentAndConnectionData(&rootHasSecureConnection, &allowMixedContent, &isDocShellRoot);
|
|
|
|
if (NS_SUCCEEDED(rvalue) && allowMixedContent && isDocShellRoot) {
|
|
|
|
shell->SetMixedContentChannel(channel);
|
|
|
|
}
|
2012-01-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
|
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
|
2012-12-26 02:00:47 +00:00
|
|
|
nsCOMPtr<nsIDocument> kungFuDeathGrip = this;
|
2006-04-26 19:53:27 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
if (nsPIDOMWindowInner *window = GetInnerWindow()) {
|
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
|
2011-09-29 06:19:26 +00:00
|
|
|
bool willReparent = mWillReparent;
|
2011-10-17 14:59:28 +00:00
|
|
|
mWillReparent = true;
|
2014-06-26 00:33:24 +00:00
|
|
|
|
|
|
|
nsDocument* templateContentsOwner =
|
|
|
|
static_cast<nsDocument*>(mTemplateContentsOwner.get());
|
|
|
|
|
|
|
|
if (templateContentsOwner) {
|
|
|
|
templateContentsOwner->mWillReparent = true;
|
|
|
|
}
|
2009-07-25 11:27:42 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-05 17:34:46 +00:00
|
|
|
// Per spec, we pass false here so that a new Window is created.
|
|
|
|
rv = window->SetNewDocument(this, nullptr,
|
|
|
|
/* aForceReuseInnerWindow */ false);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2009-07-25 11:27:42 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-26 00:33:24 +00:00
|
|
|
if (templateContentsOwner) {
|
|
|
|
templateContentsOwner->mWillReparent = willReparent;
|
|
|
|
}
|
|
|
|
|
2009-07-25 11:27:42 +00:00
|
|
|
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.
|
2011-10-17 14:59:28 +00:00
|
|
|
SetIsInitialDocument(false);
|
2006-08-15 17:31:16 +00:00
|
|
|
|
2006-04-26 19:53:27 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> newScope(do_QueryReferent(mScopeObject));
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
|
2012-12-12 02:45:36 +00:00
|
|
|
if (oldScope && newScope != oldScope && wrapper) {
|
2014-04-08 22:27:15 +00:00
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
2012-12-12 02:45:36 +00:00
|
|
|
rv = mozilla::dom::ReparentWrapper(cx, wrapper);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-26 00:33:24 +00:00
|
|
|
|
|
|
|
// Also reparent the template contents owner document
|
|
|
|
// because its global is set to the same as this document.
|
|
|
|
if (mTemplateContentsOwner) {
|
|
|
|
JS::Rooted<JSObject*> contentsOwnerWrapper(cx,
|
|
|
|
mTemplateContentsOwner->GetWrapper());
|
|
|
|
if (contentsOwnerWrapper) {
|
|
|
|
rv = mozilla::dom::ReparentWrapper(cx, contentsOwnerWrapper);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
}
|
2000-09-19 05:11:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 21:39:28 +00:00
|
|
|
mDidDocumentOpen = true;
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2012-03-28 05:17:53 +00:00
|
|
|
mParserAborted = false;
|
2012-03-31 14:10:34 +00:00
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
|
|
|
nsHtml5Module::Initialize(mParser, this, uri, shell, channel);
|
2014-12-17 19:14:04 +00:00
|
|
|
if (mReferrerPolicySet) {
|
|
|
|
// CSP may have set the referrer policy, so a speculative parser should
|
|
|
|
// start with the new referrer policy.
|
|
|
|
nsHtml5TreeOpExecutor* executor = nullptr;
|
|
|
|
executor = static_cast<nsHtml5TreeOpExecutor*> (mParser->GetContentSink());
|
|
|
|
if (executor && mReferrerPolicySet) {
|
|
|
|
executor->SetSpeculationReferrerPolicy(static_cast<ReferrerPolicy>(mReferrerPolicy));
|
|
|
|
}
|
|
|
|
}
|
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()
|
2011-06-04 06:57:23 +00:00
|
|
|
SetContentTypeInternal(contentType);
|
2004-05-21 21:32:11 +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.
|
2012-12-26 02:00:47 +00:00
|
|
|
shell->SetLoadType(aReplace.LowerCaseEqualsLiteral("replace") ?
|
|
|
|
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));
|
2011-10-15 07:33:26 +00:00
|
|
|
if (cv) {
|
2014-02-09 08:04:40 +00:00
|
|
|
cv->LoadStart(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
|
2011-06-04 06:57:23 +00:00
|
|
|
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::Open(): wyciwyg "
|
2004-05-09 21:37:32 +00:00
|
|
|
"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;
|
|
|
|
|
2012-04-17 06:41:49 +00:00
|
|
|
SetReadyStateInternal(nsIDocument::READYSTATE_LOADING);
|
|
|
|
|
2012-06-15 06:31:27 +00:00
|
|
|
// After changing everything around, make sure that the principal on the
|
|
|
|
// document's compartment exactly matches NodePrincipal().
|
|
|
|
DebugOnly<JSObject*> wrapper = GetWrapperPreserveColor();
|
|
|
|
MOZ_ASSERT_IF(wrapper,
|
|
|
|
JS_GetCompartmentPrincipals(js::GetObjectCompartment(wrapper)) ==
|
|
|
|
nsJSPrincipals::get(NodePrincipal()));
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
return kungFuDeathGrip.forget();
|
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()
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Close(rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::Close(ErrorResult& rv)
|
1998-07-22 23:32:19 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!IsHTMLDocument()) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.close() on XHTML!
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 11:16:26 +00:00
|
|
|
if (!mParser || !mParser->IsScriptCreated()) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
1999-02-03 19:38:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 11:16:26 +00:00
|
|
|
++mWriteLevel;
|
2012-12-26 02:00:47 +00:00
|
|
|
rv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
|
2012-07-30 14:20:58 +00:00
|
|
|
EmptyString(), nullptr, GetContentTypeInternal(), true);
|
2012-01-20 11:16:26 +00:00
|
|
|
--mWriteLevel;
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
// Even if that Parse() call failed, do the rest of this method
|
|
|
|
|
2012-01-20 11:16:26 +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!
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// XXXhsivonen keeping this around for bug 577508 / 253951 still :-(
|
|
|
|
if (GetShell()) {
|
|
|
|
FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removing the wyciwygChannel here is wrong when document.close() is
|
|
|
|
// called from within the document itself. However, legacy requires the
|
|
|
|
// channel to be removed here. Otherwise, the load event never fires.
|
|
|
|
NS_ASSERTION(mWyciwygChannel, "nsHTMLDocument::Close(): Trying to remove "
|
|
|
|
"nonexistent wyciwyg channel!");
|
|
|
|
RemoveWyciwygChannel();
|
|
|
|
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::Close(): "
|
|
|
|
"nsIWyciwygChannel could not be removed!");
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::WriteCommon(JSContext *cx,
|
|
|
|
const Sequence<nsString>& aText,
|
|
|
|
bool aNewlineTerminate,
|
|
|
|
mozilla::ErrorResult& rv)
|
|
|
|
{
|
|
|
|
// Fast path the common case
|
|
|
|
if (aText.Length() == 1) {
|
|
|
|
rv = WriteCommon(cx, aText[0], aNewlineTerminate);
|
|
|
|
} else {
|
|
|
|
// XXXbz it would be nice if we could pass all the strings to the parser
|
|
|
|
// without having to do all this copying and then ask it to start
|
|
|
|
// parsing....
|
|
|
|
nsString text;
|
|
|
|
for (uint32_t i = 0; i < aText.Length(); ++i) {
|
|
|
|
text.Append(aText[i]);
|
|
|
|
}
|
|
|
|
rv = WriteCommon(cx, text, aNewlineTerminate);
|
|
|
|
}
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
1999-01-06 00:32:41 +00:00
|
|
|
nsresult
|
2011-05-19 20:05:46 +00:00
|
|
|
nsHTMLDocument::WriteCommon(JSContext *cx,
|
|
|
|
const nsAString& aText,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool 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);
|
|
|
|
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!IsHTMLDocument() || mDisableDocWrite || !IsMasterDocument()) {
|
2006-05-03 21:19:26 +00:00
|
|
|
// No calling document.write*() on XHTML!
|
|
|
|
|
2010-04-02 02:09:05 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2006-05-03 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 05:17:53 +00:00
|
|
|
if (mParserAborted) {
|
|
|
|
// Hixie says aborting the parser doesn't undefine the insertion point.
|
|
|
|
// However, since we null out mParser in that case, we track the
|
|
|
|
// theoretically defined insertion point using mParserAborted.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-01-24 01:25:14 +00:00
|
|
|
void *key = GenerateParserKey();
|
2012-01-20 11:16:26 +00:00
|
|
|
if (mParser && !mParser->IsInsertionPointDefined()) {
|
2010-06-19 06:38:41 +00:00
|
|
|
if (mExternalScriptsBeingEvaluated) {
|
|
|
|
// Instead of implying a call to document.open(), ignore the call.
|
2011-12-15 14:47:03 +00:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
2013-08-21 19:28:26 +00:00
|
|
|
NS_LITERAL_CSTRING("DOM Events"), this,
|
2011-12-15 14:47:03 +00:00
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
2010-06-19 06:38:41 +00:00
|
|
|
"DocumentWriteIgnored",
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, 0,
|
2011-12-15 14:47:03 +00:00
|
|
|
mDocumentURI);
|
2010-06-19 06:38:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-01-24 01:25:14 +00:00
|
|
|
mParser->Terminate();
|
|
|
|
NS_ASSERTION(!mParser, "mParser should have been null'd out");
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:27:58 +00:00
|
|
|
if (!mParser) {
|
2010-06-19 06:38:41 +00:00
|
|
|
if (mExternalScriptsBeingEvaluated) {
|
|
|
|
// Instead of implying a call to document.open(), ignore the call.
|
2011-12-15 14:47:03 +00:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
2013-08-21 19:28:26 +00:00
|
|
|
NS_LITERAL_CSTRING("DOM Events"), this,
|
2011-12-15 14:47:03 +00:00
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
2010-06-19 06:38:41 +00:00
|
|
|
"DocumentWriteIgnored",
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, 0,
|
2011-12-15 14:47:03 +00:00
|
|
|
mDocumentURI);
|
2010-06-19 06:38:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-30 11:35:55 +00:00
|
|
|
nsCOMPtr<nsISupports> ignored;
|
|
|
|
rv = Open(NS_LITERAL_STRING("text/html"), EmptyString(), EmptyString(), cx,
|
|
|
|
1, getter_AddRefs(ignored));
|
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;
|
|
|
|
}
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!JS_IsExceptionPending(cx),
|
|
|
|
"Open() succeeded but JS exception is pending");
|
2001-05-13 00:27:58 +00:00
|
|
|
}
|
|
|
|
|
2002-01-31 19:36:45 +00:00
|
|
|
static NS_NAMED_LITERAL_STRING(new_line, "\n");
|
|
|
|
|
2012-01-20 11:16:27 +00:00
|
|
|
// Save the data in cache if the write isn't from within the doc
|
|
|
|
if (mWyciwygChannel && !key) {
|
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) {
|
2012-03-27 06:27:45 +00:00
|
|
|
rv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
|
|
|
|
aText + new_line, key, GetContentTypeInternal(), false);
|
2004-05-11 22:37:31 +00:00
|
|
|
} else {
|
2012-03-27 06:27:45 +00:00
|
|
|
rv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
|
|
|
|
aText, key, GetContentTypeInternal(), false);
|
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
|
2011-05-19 20:05:46 +00:00
|
|
|
nsHTMLDocument::Write(const nsAString& aText, JSContext *cx)
|
2001-05-13 00:27:58 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return WriteCommon(cx, aText, false);
|
2001-05-13 00:27:58 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::Write(JSContext* cx, const Sequence<nsString>& aText,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
|
|
|
WriteCommon(cx, aText, false, rv);
|
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2011-05-19 20:05:46 +00:00
|
|
|
nsHTMLDocument::Writeln(const nsAString& aText, JSContext *cx)
|
2001-05-13 00:27:58 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return WriteCommon(cx, aText, true);
|
2001-05-13 00:27:58 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::Writeln(JSContext* cx, const Sequence<nsString>& aText,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
|
|
|
WriteCommon(cx, aText, true, rv);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, int32_t 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
|
|
|
}
|
|
|
|
|
2010-06-08 19:58:26 +00:00
|
|
|
/* static */
|
|
|
|
void*
|
|
|
|
nsHTMLDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName)
|
|
|
|
{
|
|
|
|
return const_cast<nsString*>(aName);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aReturn = GetElementsByName(aElementName).take();
|
2001-03-22 08:51:52 +00:00
|
|
|
return NS_OK;
|
1998-07-22 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static bool MatchItems(nsIContent* aContent, int32_t aNameSpaceID,
|
2012-06-04 23:49:57 +00:00
|
|
|
nsIAtom* aAtom, void* aData)
|
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!aContent->IsHTMLElement()) {
|
2012-06-04 23:49:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement* elem = static_cast<nsGenericHTMLElement*>(aContent);
|
|
|
|
if (!elem->HasAttr(kNameSpaceID_None, nsGkAtoms::itemscope) ||
|
|
|
|
elem->HasAttr(kNameSpaceID_None, nsGkAtoms::itemprop)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsCOMPtr<nsIAtom> >* tokens = static_cast<nsTArray<nsCOMPtr<nsIAtom> >*>(aData);
|
|
|
|
if (tokens->IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue* attr = elem->GetParsedAttr(nsGkAtoms::itemtype);
|
|
|
|
if (!attr)
|
|
|
|
return false;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < tokens->Length(); i++) {
|
2012-06-04 23:49:57 +00:00
|
|
|
if (!attr->Contains(tokens->ElementAt(i), eCaseMatters)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DestroyTokens(void* aData)
|
|
|
|
{
|
|
|
|
nsTArray<nsCOMPtr<nsIAtom> >* tokens = static_cast<nsTArray<nsCOMPtr<nsIAtom> >*>(aData);
|
|
|
|
delete tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* CreateTokens(nsINode* aRootNode, const nsString* types)
|
|
|
|
{
|
|
|
|
nsTArray<nsCOMPtr<nsIAtom> >* tokens = new nsTArray<nsCOMPtr<nsIAtom> >();
|
|
|
|
nsAString::const_iterator iter, end;
|
|
|
|
types->BeginReading(iter);
|
|
|
|
types->EndReading(end);
|
|
|
|
|
|
|
|
// skip initial whitespace
|
|
|
|
while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the tokens
|
|
|
|
while (iter != end) {
|
|
|
|
nsAString::const_iterator start(iter);
|
|
|
|
|
|
|
|
do {
|
|
|
|
++iter;
|
|
|
|
} while (iter != end && !nsContentUtils::IsHTMLWhitespace(*iter));
|
|
|
|
|
2016-03-28 23:09:43 +00:00
|
|
|
tokens->AppendElement(NS_Atomize(Substring(start, iter)));
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::GetItems(const nsAString& types, nsIDOMNodeList** aReturn)
|
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aReturn = GetItems(types).take();
|
2012-06-04 23:49:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsHTMLDocument::GetItems(const nsAString& aTypeNames)
|
|
|
|
{
|
|
|
|
return NS_GetFuncStringNodeList(this, MatchItems, DestroyTokens, CreateTokens,
|
|
|
|
aTypeNames);
|
|
|
|
}
|
2012-06-04 23:49:57 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2004-02-03 23:23:10 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
{
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
{
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
{
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
{
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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
|
|
|
{
|
2013-01-12 21:53:01 +00:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
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)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
NS_ADDREF(*aEmbeds = Embeds());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Embeds()
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2001-03-22 08:51:52 +00:00
|
|
|
if (!mEmbeds) {
|
2010-09-01 02:47:00 +00:00
|
|
|
mEmbeds = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::embed, nsGkAtoms::embed);
|
1998-09-25 00:51:45 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return mEmbeds;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
2011-07-07 18:17:13 +00:00
|
|
|
nsHTMLDocument::GetSelection(nsISelection** aReturn)
|
2012-12-26 02:00:47 +00:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
2014-04-12 08:15:56 +00:00
|
|
|
NS_IF_ADDREF(*aReturn = GetSelection(rv));
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
2014-04-12 08:15:56 +00:00
|
|
|
Selection*
|
|
|
|
nsHTMLDocument::GetSelection(ErrorResult& aRv)
|
1998-08-07 23:08:00 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetScopeObject());
|
2014-04-12 08:15:56 +00:00
|
|
|
if (!window) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-12 08:15:56 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(window->IsInnerWindow(), "Should have inner window here!");
|
|
|
|
if (!window->IsCurrentInnerWindow()) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2000-04-28 14:05:45 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
return nsGlobalWindow::Cast(window)->GetSelection(aRv);
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 21:44:51 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-09 08:04:39 +00:00
|
|
|
nsHTMLDocument::CaptureEvents()
|
2013-07-31 21:44:51 +00:00
|
|
|
{
|
2013-11-11 21:12:18 +00:00
|
|
|
WarnOnceAbout(nsIDocument::eUseOfCaptureEvents);
|
2013-07-31 21:44:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-09 08:04:39 +00:00
|
|
|
nsHTMLDocument::ReleaseEvents()
|
2013-07-31 21:44:51 +00:00
|
|
|
{
|
2013-11-11 21:12:18 +00:00
|
|
|
WarnOnceAbout(nsIDocument::eUseOfReleaseEvents);
|
2013-07-31 21:44:51 +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)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aPlugins = nullptr;
|
2002-02-21 12:15:34 +00:00
|
|
|
|
|
|
|
return GetEmbeds(aPlugins);
|
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
nsIHTMLCollection*
|
|
|
|
nsHTMLDocument::Plugins()
|
|
|
|
{
|
|
|
|
return Embeds();
|
|
|
|
}
|
|
|
|
|
2013-03-18 09:47:32 +00:00
|
|
|
nsISupports*
|
|
|
|
nsHTMLDocument::ResolveName(const nsAString& aName, nsWrapperCache **aCache)
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
2011-04-23 07:29:12 +00:00
|
|
|
nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(aName);
|
|
|
|
if (!entry) {
|
2013-03-18 09:47:32 +00:00
|
|
|
*aCache = nullptr;
|
|
|
|
return nullptr;
|
2004-05-07 20:02:40 +00:00
|
|
|
}
|
|
|
|
|
2008-06-22 23:12:40 +00:00
|
|
|
nsBaseContentList *list = entry->GetNameContentList();
|
2013-03-18 09:47:32 +00:00
|
|
|
uint32_t length = list ? list->Length() : 0;
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2003-07-15 02:07:55 +00:00
|
|
|
if (length > 0) {
|
2002-01-25 06:37:35 +00:00
|
|
|
if (length == 1) {
|
2013-03-18 09:47:32 +00:00
|
|
|
// Only one element in the list, return the element instead of returning
|
|
|
|
// the list.
|
2012-10-13 12:50:24 +00:00
|
|
|
nsIContent *node = list->Item(0);
|
2013-03-18 09:47:32 +00:00
|
|
|
*aCache = node;
|
|
|
|
return node;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
2003-07-15 02:07:55 +00:00
|
|
|
|
2013-03-18 09:47:32 +00:00
|
|
|
// The list contains more than one element, return the whole list.
|
|
|
|
*aCache = list;
|
|
|
|
return list;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 09:47:32 +00:00
|
|
|
// No named items were found, see if there's one registerd by id for aName.
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *e = entry->GetIdElement();
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2013-03-27 17:15:37 +00:00
|
|
|
if (e && nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) {
|
|
|
|
*aCache = e;
|
|
|
|
return e;
|
2001-03-22 08:51:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 09:47:32 +00:00
|
|
|
*aCache = nullptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2013-03-27 17:15:37 +00:00
|
|
|
nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
|
2014-06-11 20:26:52 +00:00
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
2013-03-27 17:15:37 +00:00
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
|
|
|
nsWrapperCache* cache;
|
|
|
|
nsISupports* supp = ResolveName(aName, &cache);
|
|
|
|
if (!supp) {
|
|
|
|
aFound = false;
|
2014-06-11 20:26:52 +00:00
|
|
|
aRetval.set(nullptr);
|
|
|
|
return;
|
2013-03-27 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 09:12:47 +00:00
|
|
|
JS::Rooted<JS::Value> val(cx);
|
2014-04-10 04:58:43 +00:00
|
|
|
// XXXbz Should we call the (slightly misnamed, really) WrapNativeParent
|
|
|
|
// here?
|
|
|
|
if (!dom::WrapObject(cx, supp, cache, nullptr, &val)) {
|
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-03-27 17:15:37 +00:00
|
|
|
}
|
|
|
|
aFound = true;
|
2014-06-11 20:26:52 +00:00
|
|
|
aRetval.set(&val.toObject());
|
2013-03-27 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 02:58:44 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-27 17:15:37 +00:00
|
|
|
void
|
2014-04-16 02:58:44 +00:00
|
|
|
nsHTMLDocument::GetSupportedNames(unsigned, nsTArray<nsString>& aNames)
|
2013-03-27 17:15:37 +00:00
|
|
|
{
|
2015-07-16 02:22:46 +00:00
|
|
|
for (auto iter = mIdentifierMap.Iter(); !iter.Done(); iter.Next()) {
|
2015-07-16 18:56:47 +00:00
|
|
|
nsIdentifierMapEntry* entry = iter.Get();
|
|
|
|
if (entry->HasNameElement() ||
|
|
|
|
entry->HasIdElementExposedAsHTMLDocumentProperty()) {
|
|
|
|
aNames.AppendElement(entry->GetKey());
|
2015-07-16 02:22:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-27 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 15:55:31 +00:00
|
|
|
//----------------------------
|
1998-09-04 15:41:20 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// forms related stuff
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-23 17:16:51 +00:00
|
|
|
nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms)
|
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_ADDREF(*aForms = nsHTMLDocument::GetForms());
|
1998-09-23 17:16:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-02 23:16:02 +00:00
|
|
|
nsContentList*
|
|
|
|
nsHTMLDocument::GetForms()
|
|
|
|
{
|
2010-09-01 02:47:00 +00:00
|
|
|
if (!mForms) {
|
|
|
|
mForms = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::form, nsGkAtoms::form);
|
|
|
|
}
|
2005-02-02 23:16:02 +00:00
|
|
|
|
|
|
|
return mForms;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static bool MatchFormControls(nsIContent* aContent, int32_t 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) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mFormControls = new nsContentList(this, MatchFormControls, nullptr, nullptr);
|
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;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString 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
|
2014-09-21 16:36:25 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
wcwgURI,
|
|
|
|
NodePrincipal(),
|
|
|
|
nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
|
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());
|
|
|
|
|
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
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = loadGroup->AddRequest(mWyciwygChannel, nullptr);
|
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);
|
2012-07-30 14:20:58 +00:00
|
|
|
loadGroup->RemoveRequest(mWyciwygChannel, nullptr, NS_OK);
|
2001-05-25 08:49:03 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mWyciwygChannel = nullptr;
|
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.
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-09-22 23:01:33 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2012-03-31 14:10:34 +00:00
|
|
|
nsIScriptElement* script = mScriptLoader->GetCurrentParserInsertedScript();
|
|
|
|
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.
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-15 11:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-31 14:10:34 +00:00
|
|
|
return script;
|
2005-06-07 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
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()
|
|
|
|
{
|
2013-03-22 23:08:59 +00:00
|
|
|
if (!mPendingMaybeEditingStateChanged &&
|
|
|
|
mUpdateNestLevel == 0 && (mContentEditableCount > 0) != IsEditingOn()) {
|
2009-01-31 12:53:01 +00:00
|
|
|
if (nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
EditingStateChanged();
|
|
|
|
} else if (!mInDestructor) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &nsHTMLDocument::MaybeEditingStateChanged));
|
2009-01-31 12:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 10:30:44 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::EndUpdate(nsUpdateType aUpdateType)
|
|
|
|
{
|
2013-03-22 23:08:59 +00:00
|
|
|
const bool reset = !mPendingMaybeEditingStateChanged;
|
|
|
|
mPendingMaybeEditingStateChanged = true;
|
2007-10-26 10:30:44 +00:00
|
|
|
nsDocument::EndUpdate(aUpdateType);
|
2013-03-22 23:08:59 +00:00
|
|
|
if (reset) {
|
|
|
|
mPendingMaybeEditingStateChanged = false;
|
|
|
|
}
|
2009-01-31 12:53:01 +00:00
|
|
|
MaybeEditingStateChanged();
|
2007-10-26 10:30:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:07:53 +00:00
|
|
|
|
|
|
|
// Helper class, used below in ChangeContentEditableCount().
|
|
|
|
class DeferredContentEditableCountChangeEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeferredContentEditableCountChangeEvent(nsHTMLDocument *aDoc,
|
|
|
|
nsIContent *aElement)
|
|
|
|
: mDoc(aDoc)
|
|
|
|
, mElement(aElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2011-10-18 10:53:36 +00:00
|
|
|
if (mElement && mElement->OwnerDoc() == mDoc) {
|
2010-07-18 22:07:53 +00:00
|
|
|
mDoc->DeferredContentEditableCountChange(mElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsHTMLDocument> mDoc;
|
2010-07-18 22:07:53 +00:00
|
|
|
nsCOMPtr<nsIContent> mElement;
|
|
|
|
};
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::ChangeContentEditableCount(nsIContent *aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aChange)
|
2007-06-27 22:29:45 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_ASSERTION(int32_t(mContentEditableCount) + aChange >= 0,
|
2007-06-28 02:48:16 +00:00
|
|
|
"Trying to decrement too much.");
|
|
|
|
|
|
|
|
mContentEditableCount += aChange;
|
|
|
|
|
2010-05-12 22:21:24 +00:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new DeferredContentEditableCountChangeEvent(this, aElement));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement)
|
|
|
|
{
|
2007-10-26 10:30:44 +00:00
|
|
|
if (mParser ||
|
2010-02-06 21:33:53 +00:00
|
|
|
(mUpdateNestLevel > 0 && (mContentEditableCount > 0) != IsEditingOn())) {
|
2010-05-12 22:21:24 +00:00
|
|
|
return;
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditingState oldState = mEditingState;
|
|
|
|
|
|
|
|
nsresult rv = EditingStateChanged();
|
2012-09-14 10:00:31 +00:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
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) {
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter *window = GetWindow();
|
2007-06-28 02:48:16 +00:00
|
|
|
if (!window)
|
2010-05-12 22:21:24 +00:00
|
|
|
return;
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
nsIDocShell *docshell = window->GetDocShell();
|
|
|
|
if (!docshell)
|
2010-05-12 22:21:24 +00:00
|
|
|
return;
|
2007-06-28 02:48:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2013-02-13 22:39:30 +00:00
|
|
|
docshell->GetEditor(getter_AddRefs(editor));
|
2007-07-18 09:44:22 +00:00
|
|
|
if (editor) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsRange> range = new nsRange(aElement);
|
2007-07-18 09:46:41 +00:00
|
|
|
rv = range->SelectNode(node);
|
2011-07-14 21:06:37 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// The node might be detached from the document at this point,
|
|
|
|
// which would cause this call to fail. In this case, we can
|
|
|
|
// safely ignore the contenteditable count change.
|
|
|
|
return;
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2007-07-18 09:46:41 +00:00
|
|
|
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = editor->GetInlineSpellChecker(false,
|
2007-07-18 09:46:41 +00:00
|
|
|
getter_AddRefs(spellChecker));
|
2012-09-14 10:00:31 +00:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2007-07-18 09:46:41 +00:00
|
|
|
|
|
|
|
if (spellChecker) {
|
|
|
|
rv = spellChecker->SpellCheckRange(range);
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 08:02:45 +00:00
|
|
|
HTMLAllCollection*
|
|
|
|
nsHTMLDocument::All()
|
2013-06-12 06:55:00 +00:00
|
|
|
{
|
|
|
|
if (!mAll) {
|
2013-09-06 06:41:42 +00:00
|
|
|
mAll = new HTMLAllCollection(this);
|
2013-06-12 06:55:00 +00:00
|
|
|
}
|
2014-02-09 08:02:45 +00:00
|
|
|
return mAll;
|
|
|
|
}
|
2013-06-12 06:55:00 +00:00
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
static void
|
2011-10-20 16:27:48 +00:00
|
|
|
NotifyEditableStateChange(nsINode *aNode, nsIDocument *aDocument)
|
2007-06-28 02:48:16 +00:00
|
|
|
{
|
2011-09-27 07:54:58 +00:00
|
|
|
for (nsIContent* child = aNode->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-10-20 16:27:48 +00:00
|
|
|
if (child->IsElement()) {
|
2011-06-01 01:46:57 +00:00
|
|
|
child->AsElement()->UpdateState(true);
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
2011-10-20 16:27:48 +00:00
|
|
|
NotifyEditableStateChange(child, aDocument);
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-10-29 16:30:15 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetShell();
|
|
|
|
if (!presShell)
|
|
|
|
return;
|
|
|
|
|
2016-02-24 07:01:12 +00:00
|
|
|
nsTArray<StyleSheetHandle::RefPtr> agentSheets;
|
2010-10-29 16:30:15 +00:00
|
|
|
presShell->GetAgentStyleSheets(agentSheets);
|
|
|
|
|
2016-02-24 07:01:12 +00:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
|
|
|
|
|
|
|
|
agentSheets.RemoveElement(cache->ContentEditableSheet());
|
2010-10-29 16:30:15 +00:00
|
|
|
if (oldState == eDesignMode)
|
2016-02-24 07:01:12 +00:00
|
|
|
agentSheets.RemoveElement(cache->DesignModeSheet());
|
2010-10-29 16:30:15 +00:00
|
|
|
|
|
|
|
presShell->SetAgentStyleSheets(agentSheets);
|
|
|
|
|
|
|
|
presShell->ReconstructStyleData();
|
2008-02-20 09:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 02:48:16 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLDocument::TurnEditingOff()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mEditingState != eOff, "Editing is already off.");
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter *window = GetWindow();
|
2007-06-27 22:29:45 +00:00
|
|
|
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
|
|
|
|
2016-03-14 18:00:13 +00:00
|
|
|
nsCOMPtr<nsIEditingSession> editSession;
|
|
|
|
nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession));
|
2007-06-28 02:48:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
static bool HasPresShell(nsPIDOMWindowOuter *aWindow)
|
2007-11-02 00:51:08 +00:00
|
|
|
{
|
|
|
|
nsIDocShell *docShell = aWindow->GetDocShell();
|
|
|
|
if (!docShell)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2012-12-29 01:56:42 +00:00
|
|
|
return docShell->GetPresShell() != nullptr;
|
2007-11-02 00:51:08 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2015-04-21 06:27:10 +00:00
|
|
|
// XXX We shouldn't recurse
|
2007-06-28 02:48:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool designMode = HasFlag(NODE_IS_EDITABLE);
|
2007-06-28 02:48:16 +00:00
|
|
|
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.
|
2011-10-20 16:27:48 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
NotifyEditableStateChange(this, this);
|
2007-06-28 02:48:16 +00:00
|
|
|
return TurnEditingOff();
|
2007-06-27 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 02:44:39 +00:00
|
|
|
// Flush out style changes on our _parent_ document, if any, so that
|
|
|
|
// our check for a presshell won't get stale information.
|
|
|
|
if (mParentDocument) {
|
|
|
|
mParentDocument->FlushPendingNotifications(Flush_Style);
|
|
|
|
}
|
|
|
|
|
2010-10-10 22:46:10 +00:00
|
|
|
// get editing session, make sure this is a strong reference so the
|
|
|
|
// window can't get deleted during the rest of this call.
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindow();
|
2007-06-28 02:48:16 +00:00
|
|
|
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
|
|
|
|
2016-03-14 18:00:13 +00:00
|
|
|
nsCOMPtr<nsIEditingSession> editSession;
|
|
|
|
nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession));
|
2007-06-28 02:48:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 23:21:05 +00:00
|
|
|
|
2010-12-06 19:27:14 +00:00
|
|
|
nsCOMPtr<nsIEditor> existingEditor;
|
|
|
|
editSession->GetEditorForWindow(window, getter_AddRefs(existingEditor));
|
|
|
|
if (existingEditor) {
|
|
|
|
// We might already have an editor if it was set up for mail, let's see
|
|
|
|
// if this is actually the case.
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(existingEditor);
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(htmlEditor, "If we have an editor, it must be an HTML editor");
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags = 0;
|
2010-12-06 19:27:14 +00:00
|
|
|
existingEditor->GetFlags(&flags);
|
|
|
|
if (flags & nsIPlaintextEditor::eEditorMailMask) {
|
|
|
|
// We already have a mail editor, then we should not attempt to create
|
|
|
|
// another one.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool makeWindowEditable = mEditingState == eOff;
|
2011-04-14 12:04:12 +00:00
|
|
|
bool updateState = false;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool spellRecheckAll = false;
|
2015-04-21 06:27:10 +00:00
|
|
|
bool putOffToRemoveScriptBlockerUntilModifyingEditingState = false;
|
2008-09-18 02:32:44 +00:00
|
|
|
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);
|
|
|
|
|
2010-10-29 16:30:15 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
2015-04-21 06:27:10 +00:00
|
|
|
// Before making this window editable, we need to modify UA style sheet
|
|
|
|
// because new style may change whether focused element will be focusable
|
|
|
|
// or not.
|
2016-02-24 07:01:12 +00:00
|
|
|
nsTArray<StyleSheetHandle::RefPtr> agentSheets;
|
2010-10-29 16:30:15 +00:00
|
|
|
rv = presShell->GetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2016-02-24 07:01:12 +00:00
|
|
|
auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
|
|
|
|
|
|
|
|
StyleSheetHandle contentEditableSheet = cache->ContentEditableSheet();
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2015-06-16 01:34:48 +00:00
|
|
|
if (!agentSheets.Contains(contentEditableSheet)) {
|
2015-11-17 06:04:09 +00:00
|
|
|
agentSheets.AppendElement(contentEditableSheet);
|
2015-06-16 01:34:48 +00:00
|
|
|
}
|
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).
|
2016-02-24 07:01:12 +00:00
|
|
|
StyleSheetHandle designModeSheet = cache->DesignModeSheet();
|
2015-06-16 01:34:48 +00:00
|
|
|
if (!agentSheets.Contains(designModeSheet)) {
|
2015-11-17 06:04:09 +00:00
|
|
|
agentSheets.AppendElement(designModeSheet);
|
2015-06-16 01:34:48 +00:00
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2011-04-14 12:04:12 +00:00
|
|
|
updateState = 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).
|
2016-02-24 07:01:12 +00:00
|
|
|
agentSheets.RemoveElement(cache->DesignModeSheet());
|
2011-04-14 12:04:12 +00:00
|
|
|
updateState = true;
|
2008-09-18 02:32:44 +00:00
|
|
|
}
|
2010-10-29 16:30:15 +00:00
|
|
|
|
|
|
|
rv = presShell->SetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
presShell->ReconstructStyleData();
|
2015-04-21 06:27:10 +00:00
|
|
|
|
|
|
|
// Adjust focused element with new style but blur event shouldn't be fired
|
|
|
|
// until mEditingState is modified with newState.
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
if (designMode) {
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2015-04-21 06:27:10 +00:00
|
|
|
nsIContent* focusedContent =
|
|
|
|
nsFocusManager::GetFocusedDescendant(window, false,
|
|
|
|
getter_AddRefs(focusedWindow));
|
|
|
|
if (focusedContent) {
|
|
|
|
nsIFrame* focusedFrame = focusedContent->GetPrimaryFrame();
|
|
|
|
bool clearFocus = focusedFrame ? !focusedFrame->IsFocusable() :
|
|
|
|
!focusedContent->IsFocusable();
|
|
|
|
if (clearFocus) {
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
fm->ClearFocus(window);
|
|
|
|
// If we need to dispatch blur event, we should put off after
|
|
|
|
// modifying mEditingState since blur event handler may change
|
|
|
|
// designMode state again.
|
|
|
|
putOffToRemoveScriptBlockerUntilModifyingEditingState = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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", false, false,
|
|
|
|
true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Need to call TearDownEditorOnWindow for all failures.
|
|
|
|
docshell->GetEditor(getter_AddRefs(editor));
|
|
|
|
if (!editor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// If we're entering the design mode, put the selection at the beginning of
|
|
|
|
// the document for compatibility reasons.
|
|
|
|
if (designMode && oldState == eOff) {
|
|
|
|
editor->BeginningOfDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (putOffToRemoveScriptBlockerUntilModifyingEditingState) {
|
|
|
|
nsContentUtils::AddScriptBlocker();
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mEditingState = newState;
|
2015-04-21 06:27:10 +00:00
|
|
|
if (putOffToRemoveScriptBlockerUntilModifyingEditingState) {
|
|
|
|
nsContentUtils::RemoveScriptBlocker();
|
|
|
|
// If mEditingState is overwritten by another call and already disabled
|
|
|
|
// the editing, we shouldn't keep making window editable.
|
|
|
|
if (mEditingState == eOff) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
|
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?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool unused;
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), false,
|
2007-11-05 21:19:52 +00:00
|
|
|
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) {
|
2011-05-31 21:38:25 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-10-20 16:27:48 +00:00
|
|
|
NotifyEditableStateChange(this, this);
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
SetDesignMode(aDesignMode, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
void
|
|
|
|
nsHTMLDocument::SetDesignMode(const nsAString& aDesignMode, ErrorResult& rv)
|
|
|
|
{
|
2014-09-25 09:04:45 +00:00
|
|
|
if (!nsContentUtils::LegacyIsCallerNativeCode() && !nsContentUtils::SubjectPrincipal()->Subsumes(NodePrincipal())) {
|
2014-05-06 22:43:03 +00:00
|
|
|
rv.Throw(NS_ERROR_DOM_PROP_ACCESS_DENIED);
|
|
|
|
return;
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
bool editableMode = HasFlag(NODE_IS_EDITABLE);
|
2007-06-28 02:48:16 +00:00
|
|
|
if (aDesignMode.LowerCaseEqualsASCII(editableMode ? "off" : "on")) {
|
|
|
|
SetEditableFlag(!editableMode);
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
rv = EditingStateChanged();
|
2007-06-28 02:48:16 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aCmdMgr = nullptr;
|
2005-11-28 23:56:44 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter *window = GetWindow();
|
2005-11-28 23:56:44 +00:00
|
|
|
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;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useNewParam;
|
|
|
|
bool convertToBoolean;
|
2002-11-07 15:38:35 +00:00
|
|
|
};
|
|
|
|
|
2003-01-25 21:49:53 +00:00
|
|
|
static const struct MidasCommand gMidasCommandTable[] = {
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "bold", "cmd_bold", "", true, false },
|
|
|
|
{ "italic", "cmd_italic", "", true, false },
|
|
|
|
{ "underline", "cmd_underline", "", true, false },
|
|
|
|
{ "strikethrough", "cmd_strikethrough", "", true, false },
|
|
|
|
{ "subscript", "cmd_subscript", "", true, false },
|
|
|
|
{ "superscript", "cmd_superscript", "", true, false },
|
|
|
|
{ "cut", "cmd_cut", "", true, false },
|
|
|
|
{ "copy", "cmd_copy", "", true, false },
|
|
|
|
{ "paste", "cmd_paste", "", true, false },
|
2012-06-21 12:05:24 +00:00
|
|
|
{ "delete", "cmd_deleteCharBackward", "", true, false },
|
|
|
|
{ "forwarddelete", "cmd_deleteCharForward", "", true, false },
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "selectall", "cmd_selectAll", "", true, false },
|
|
|
|
{ "undo", "cmd_undo", "", true, false },
|
|
|
|
{ "redo", "cmd_redo", "", true, false },
|
|
|
|
{ "indent", "cmd_indent", "", true, false },
|
|
|
|
{ "outdent", "cmd_outdent", "", true, false },
|
2012-04-17 15:37:40 +00:00
|
|
|
{ "backcolor", "cmd_highlight", "", false, false },
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "forecolor", "cmd_fontColor", "", false, false },
|
|
|
|
{ "hilitecolor", "cmd_highlight", "", false, false },
|
|
|
|
{ "fontname", "cmd_fontFace", "", false, false },
|
|
|
|
{ "fontsize", "cmd_fontSize", "", false, false },
|
|
|
|
{ "increasefontsize", "cmd_increaseFont", "", false, false },
|
|
|
|
{ "decreasefontsize", "cmd_decreaseFont", "", false, false },
|
|
|
|
{ "inserthorizontalrule", "cmd_insertHR", "", true, false },
|
|
|
|
{ "createlink", "cmd_insertLinkNoUI", "", false, false },
|
|
|
|
{ "insertimage", "cmd_insertImageNoUI", "", false, false },
|
|
|
|
{ "inserthtml", "cmd_insertHTML", "", false, false },
|
2012-05-22 09:37:17 +00:00
|
|
|
{ "inserttext", "cmd_insertText", "", false, false },
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "gethtml", "cmd_getContents", "", false, false },
|
|
|
|
{ "justifyleft", "cmd_align", "left", true, false },
|
|
|
|
{ "justifyright", "cmd_align", "right", true, false },
|
|
|
|
{ "justifycenter", "cmd_align", "center", true, false },
|
|
|
|
{ "justifyfull", "cmd_align", "justify", true, false },
|
|
|
|
{ "removeformat", "cmd_removeStyles", "", true, false },
|
|
|
|
{ "unlink", "cmd_removeLinks", "", true, false },
|
|
|
|
{ "insertorderedlist", "cmd_ol", "", true, false },
|
|
|
|
{ "insertunorderedlist", "cmd_ul", "", true, false },
|
2012-06-06 17:34:10 +00:00
|
|
|
{ "insertparagraph", "cmd_paragraphState", "p", true, false },
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "formatblock", "cmd_paragraphState", "", false, false },
|
|
|
|
{ "heading", "cmd_paragraphState", "", false, false },
|
|
|
|
{ "styleWithCSS", "cmd_setDocumentUseCSS", "", false, true },
|
|
|
|
{ "contentReadOnly", "cmd_setDocumentReadOnly", "", false, true },
|
|
|
|
{ "insertBrOnReturn", "cmd_insertBrOnReturn", "", false, true },
|
|
|
|
{ "enableObjectResizing", "cmd_enableObjectResizing", "", false, true },
|
|
|
|
{ "enableInlineTableEditing", "cmd_enableInlineTableEditing", "", false, 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
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "justifynone", "cmd_align", "", true, false },
|
2002-11-11 20:19:37 +00:00
|
|
|
|
|
|
|
// the following will need special review before being turned on
|
2011-10-17 14:59:28 +00:00
|
|
|
{ "saveas", "cmd_saveAs", "", true, false },
|
|
|
|
{ "print", "cmd_print", "", true, false },
|
2002-11-07 15:38:35 +00:00
|
|
|
#endif
|
2013-04-03 01:14:24 +00:00
|
|
|
{ nullptr, nullptr, nullptr, false, 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
|
|
|
};
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2012-04-24 10:57:23 +00:00
|
|
|
ConvertToMidasInternalCommandInner(const nsAString& inCommandID,
|
|
|
|
const nsAString& inParam,
|
2008-01-14 09:26:22 +00:00
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& outIsBoolean,
|
|
|
|
bool& outBooleanValue,
|
|
|
|
bool 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).
|
2011-09-29 06:19:26 +00:00
|
|
|
bool invertBool = false;
|
2005-08-25 11:51:04 +00:00
|
|
|
if (convertedCommandID.LowerCaseEqualsLiteral("usecss")) {
|
2014-05-22 03:48:51 +00:00
|
|
|
convertedCommandID.AssignLiteral("styleWithCSS");
|
2011-10-17 14:59:28 +00:00
|
|
|
invertBool = true;
|
2012-04-24 10:57:23 +00:00
|
|
|
} else if (convertedCommandID.LowerCaseEqualsLiteral("readonly")) {
|
2014-05-22 03:48:51 +00:00
|
|
|
convertedCommandID.AssignLiteral("contentReadOnly");
|
2011-10-17 14:59:28 +00:00
|
|
|
invertBool = true;
|
2005-08-25 11:51:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool found = false;
|
2002-11-07 15:38:35 +00:00
|
|
|
for (i = 0; i < MidasCommandCount; ++i) {
|
|
|
|
if (convertedCommandID.Equals(gMidasCommandTable[i].incomingCommandString,
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
2011-10-17 14:59:28 +00:00
|
|
|
found = true;
|
2003-01-22 01:04:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 10:57:23 +00:00
|
|
|
if (!found) {
|
2003-01-22 01:04:51 +00:00
|
|
|
// reset results if the command is not found in our table
|
|
|
|
outCommandID.SetLength(0);
|
|
|
|
outParam.SetLength(0);
|
2011-10-17 14:59:28 +00:00
|
|
|
outIsBoolean = false;
|
2012-04-24 10:57:23 +00:00
|
|
|
return false;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 10:57:23 +00:00
|
|
|
// set outCommandID (what we use internally)
|
|
|
|
outCommandID.Assign(gMidasCommandTable[i].internalCommandString);
|
|
|
|
|
|
|
|
// set outParam & outIsBoolean based on flags from the table
|
|
|
|
outIsBoolean = gMidasCommandTable[i].convertToBoolean;
|
|
|
|
|
|
|
|
if (aIgnoreParams) {
|
|
|
|
// No further work to do
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gMidasCommandTable[i].useNewParam) {
|
|
|
|
// Just have to copy it, no checking
|
|
|
|
outParam.Assign(gMidasCommandTable[i].internalParamString);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
} else {
|
|
|
|
outBooleanValue = !inParam.LowerCaseEqualsLiteral("false");
|
|
|
|
}
|
|
|
|
outParam.Truncate();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// String parameter -- see if we need to convert it (necessary for
|
2012-04-24 10:57:46 +00:00
|
|
|
// cmd_paragraphState and cmd_fontSize)
|
2012-04-24 10:57:23 +00:00
|
|
|
if (outCommandID.EqualsLiteral("cmd_paragraphState")) {
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* start = inParam.BeginReading();
|
|
|
|
const char16_t* end = inParam.EndReading();
|
2012-04-24 10:57:23 +00:00
|
|
|
if (start != end && *start == '<' && *(end - 1) == '>') {
|
|
|
|
++start;
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 convertedParam(Substring(start, end));
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t j;
|
2012-04-24 10:57:23 +00:00
|
|
|
for (j = 0; j < ArrayLength(gBlocks); ++j) {
|
|
|
|
if (convertedParam.Equals(gBlocks[j],
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
|
|
|
outParam.Assign(gBlocks[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == ArrayLength(gBlocks)) {
|
|
|
|
outParam.Truncate();
|
|
|
|
}
|
2012-04-24 10:57:46 +00:00
|
|
|
} else if (outCommandID.EqualsLiteral("cmd_fontSize")) {
|
|
|
|
// Per editing spec as of April 23, 2012, we need to reject the value if
|
|
|
|
// it's not a valid floating-point number surrounded by optional whitespace.
|
|
|
|
// Otherwise, we parse it as a legacy font size. For now, we just parse as
|
|
|
|
// a legacy font size regardless (matching WebKit) -- bug 747879.
|
|
|
|
outParam.Truncate();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t size = nsContentUtils::ParseLegacyFontSize(inParam);
|
2012-04-24 10:57:46 +00:00
|
|
|
if (size) {
|
|
|
|
outParam.AppendInt(size);
|
|
|
|
}
|
2012-04-24 10:57:23 +00:00
|
|
|
} else {
|
|
|
|
CopyUTF16toUTF8(inParam, outParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2008-01-14 09:26:22 +00:00
|
|
|
ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
const nsAString & inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& outIsBoolean,
|
|
|
|
bool& outBooleanValue)
|
2008-01-14 09:26:22 +00:00
|
|
|
{
|
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, inParam, outCommandID,
|
|
|
|
outParam, outIsBoolean,
|
2011-10-17 14:59:28 +00:00
|
|
|
outBooleanValue, false);
|
2008-01-14 09:26:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2008-01-14 09:26:22 +00:00
|
|
|
ConvertToMidasInternalCommand(const nsAString & inCommandID,
|
|
|
|
nsACString& outCommandID)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString dummyCString;
|
2008-01-14 09:26:22 +00:00
|
|
|
nsAutoString dummyString;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool dummyBool;
|
2008-01-14 09:26:22 +00:00
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, dummyString,
|
|
|
|
outCommandID, dummyCString,
|
2011-10-17 14:59:28 +00:00
|
|
|
dummyBool, dummyBool, true);
|
2008-01-14 09:26:22 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
/* TODO: don't let this call do anything if the page is not done loading */
|
|
|
|
NS_IMETHODIMP
|
2012-05-22 09:37:17 +00:00
|
|
|
nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doShowUI,
|
2012-05-22 09:37:17 +00:00
|
|
|
const nsAString& value,
|
|
|
|
bool* _retval)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
*_retval = ExecCommand(commandID, doShowUI, value, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
|
|
|
bool doShowUI,
|
|
|
|
const nsAString& value,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
2002-11-07 15:38:35 +00:00
|
|
|
// for optional parameters see dom/src/base/nsHistory.cpp: HistoryImpl::Go()
|
|
|
|
// this might add some ugly JS dependencies?
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch, paramStr;
|
2012-04-15 12:57:20 +00:00
|
|
|
bool isBool, boolVal;
|
|
|
|
if (!ConvertToMidasInternalCommand(commandID, value,
|
|
|
|
cmdToDispatch, paramStr,
|
|
|
|
isBool, boolVal)) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-04-15 12:57:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 11:43:00 +00:00
|
|
|
bool isCutCopy = (commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy"));
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// if editing is not on, bail
|
2015-05-25 11:43:00 +00:00
|
|
|
if (!isCutCopy && !IsEditingOnAfterFlush()) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
|
|
|
// if they are requesting UI from us, let's fail since we have no UI
|
2012-05-22 09:37:17 +00:00
|
|
|
if (doShowUI) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-05-22 09:37:17 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2015-05-25 11:43:00 +00:00
|
|
|
// special case for cut & copy
|
|
|
|
// cut & copy are allowed in non editable documents
|
|
|
|
if (isCutCopy) {
|
|
|
|
if (!nsContentUtils::IsCutCopyAllowed()) {
|
2015-11-09 18:28:23 +00:00
|
|
|
// We have rejected the event due to it not being performed in an
|
|
|
|
// input-driven context therefore, we report the error to the console.
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("DOM"), this,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"ExecCommandCutCopyDeniedNotInputDriven");
|
2015-05-25 11:43:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For cut & copy commands, we need the behaviour from nsWindowRoot::GetControllers
|
|
|
|
// which is to look at the focused element, and defer to a focused textbox's controller
|
|
|
|
// The code past taken by other commands in ExecCommand always uses the window directly,
|
|
|
|
// rather than deferring to the textbox, which is desireable for most editor commands,
|
|
|
|
// but not 'cut' and 'copy' (as those should allow copying out of embedded editors).
|
|
|
|
// This behaviour is invoked if we call DoCommand directly on the docShell.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
|
|
|
|
if (docShell) {
|
|
|
|
nsresult res = docShell->DoCommand(cmdToDispatch.get());
|
|
|
|
return NS_SUCCEEDED(res);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-22 09:37:17 +00:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("gethtml")) {
|
2012-12-26 02:00:47 +00:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
2012-05-22 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 11:43:00 +00:00
|
|
|
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
|
2013-12-14 03:15:43 +00:00
|
|
|
if (restricted && !nsContentUtils::IsCallerChrome()) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-03-04 13:56:36 +00:00
|
|
|
|
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));
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-05-22 09:37:17 +00:00
|
|
|
if ((cmdToDispatch.EqualsLiteral("cmd_fontSize") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertImageNoUI") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertLinkNoUI") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_paragraphState")) &&
|
2012-05-22 09:37:17 +00:00
|
|
|
paramStr.IsEmpty()) {
|
2012-05-22 09:37:17 +00:00
|
|
|
// Invalid value, return false
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-04-17 10:18:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 12:05:24 +00:00
|
|
|
// Return false for disabled commands (bug 760052)
|
|
|
|
bool enabled = false;
|
|
|
|
cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, &enabled);
|
|
|
|
if (!enabled) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-06-21 12:05:24 +00:00
|
|
|
}
|
|
|
|
|
2003-01-22 01:04:51 +00:00
|
|
|
if (!isBool && paramStr.IsEmpty()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), nullptr, 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(
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_COMMAND_PARAMS_CONTRACTID);
|
|
|
|
if (!cmdParams) {
|
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return false;
|
|
|
|
}
|
2003-01-22 01:04:51 +00:00
|
|
|
|
2012-05-22 09:37:17 +00:00
|
|
|
if (isBool) {
|
2003-01-22 01:04:51 +00:00
|
|
|
rv = cmdParams->SetBooleanValue("state_attribute", boolVal);
|
2012-05-22 09:37:17 +00:00
|
|
|
} else if (cmdToDispatch.EqualsLiteral("cmd_fontFace")) {
|
2003-05-30 15:02:12 +00:00
|
|
|
rv = cmdParams->SetStringValue("state_attribute", value);
|
2012-05-22 09:37:17 +00:00
|
|
|
} else if (cmdToDispatch.EqualsLiteral("cmd_insertHTML") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertText")) {
|
2003-05-30 15:02:12 +00:00
|
|
|
rv = cmdParams->SetStringValue("state_data", value);
|
2012-05-22 09:37:17 +00:00
|
|
|
} else {
|
2003-01-22 01:04:51 +00:00
|
|
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
2012-05-22 09:37:17 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
return !rv.Failed();
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-22 09:37:17 +00:00
|
|
|
nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
|
|
|
|
bool* _retval)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
*_retval = QueryCommandEnabled(commandID, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID, ErrorResult& rv)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-04-15 12:57:20 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-04-15 12:57:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 08:09:00 +00:00
|
|
|
// cut & copy are always allowed
|
|
|
|
bool isCutCopy = commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy");
|
|
|
|
if (isCutCopy) {
|
|
|
|
return nsContentUtils::IsCutCopyAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report false for restricted commands
|
|
|
|
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
|
|
|
|
if (restricted && !nsContentUtils::IsCallerChrome()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// if editing is not on, bail
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
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));
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-13 15:23:03 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-13 15:23:03 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool retval;
|
|
|
|
rv = cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, &retval);
|
|
|
|
return retval;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *_retval)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
*_retval = QueryCommandIndeterm(commandID, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::QueryCommandIndeterm(const nsAString& commandID, ErrorResult& rv)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-04-15 12:57:20 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-04-15 12:57:20 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// if editing is not on, bail
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
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));
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 14:17:51 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 14:17:51 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
nsresult res;
|
2004-03-19 14:17:51 +00:00
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_COMMAND_PARAMS_CONTRACTID, &res);
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
rv.Throw(res);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 14:17:51 +00:00
|
|
|
|
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 14:17:51 +00:00
|
|
|
|
2012-04-06 07:42:54 +00:00
|
|
|
// If command does not have a state_mixed value, this call fails and sets
|
2012-12-26 02:00:47 +00:00
|
|
|
// retval to false. This is fine -- we want to return false in that case
|
|
|
|
// anyway (bug 738385), so we just don't throw regardless.
|
|
|
|
bool retval = false;
|
|
|
|
cmdParams->GetBooleanValue("state_mixed", &retval);
|
|
|
|
return retval;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLDocument::QueryCommandState(const nsAString & commandID, bool *_retval)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
*_retval = QueryCommandState(commandID, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::QueryCommandState(const nsAString& commandID, ErrorResult& rv)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch, paramToCheck;
|
2012-04-15 12:57:20 +00:00
|
|
|
bool dummy, dummy2;
|
|
|
|
if (!ConvertToMidasInternalCommand(commandID, commandID,
|
|
|
|
cmdToDispatch, paramToCheck,
|
|
|
|
dummy, dummy2)) {
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-04-15 12:57:20 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// if editing is not on, bail
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
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));
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-03-23 19:03:42 +00:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("usecss")) {
|
|
|
|
// Per spec, state is supported for styleWithCSS but not useCSS, so we just
|
|
|
|
// return false always.
|
2012-12-26 02:00:47 +00:00
|
|
|
return false;
|
2012-03-23 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_COMMAND_PARAMS_CONTRACTID);
|
|
|
|
if (!cmdParams) {
|
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
|
|
|
// 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?'
|
2012-05-22 09:37:17 +00:00
|
|
|
if (cmdToDispatch.EqualsLiteral("cmd_align")) {
|
2012-07-30 14:20:58 +00:00
|
|
|
char * actualAlignmentType = nullptr;
|
2002-11-07 15:38:35 +00:00
|
|
|
rv = cmdParams->GetCStringValue("state_attribute", &actualAlignmentType);
|
2012-12-26 02:00:47 +00:00
|
|
|
bool retval = false;
|
|
|
|
if (!rv.Failed() && actualAlignmentType && actualAlignmentType[0]) {
|
|
|
|
retval = paramToCheck.Equals(actualAlignmentType);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
2012-05-22 09:37:17 +00:00
|
|
|
if (actualAlignmentType) {
|
2015-03-27 00:01:12 +00:00
|
|
|
free(actualAlignmentType);
|
2012-05-22 09:37:17 +00:00
|
|
|
}
|
2012-12-26 02:00:47 +00:00
|
|
|
return retval;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2012-04-06 07:42:54 +00:00
|
|
|
// If command does not have a state_all value, this call fails and sets
|
2012-12-26 02:00:47 +00:00
|
|
|
// retval to false. This is fine -- we want to return false in that case
|
|
|
|
// anyway (bug 738385), so we just succeed and return false regardless.
|
|
|
|
bool retval = false;
|
|
|
|
cmdParams->GetBooleanValue("state_all", &retval);
|
|
|
|
return retval;
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandSupported(const nsAString & commandID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *_retval)
|
2002-11-07 15:38:35 +00:00
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
*_retval = QueryCommandSupported(commandID);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-08-17 12:04:14 +00:00
|
|
|
|
2012-12-26 02:00:47 +00:00
|
|
|
bool
|
|
|
|
nsHTMLDocument::QueryCommandSupported(const nsAString& commandID)
|
|
|
|
{
|
2015-06-07 22:21:58 +00:00
|
|
|
// Gecko technically supports all the clipboard commands including
|
|
|
|
// cut/copy/paste, but non-privileged content will be unable to call
|
|
|
|
// paste, and depending on the pref "dom.allow_cut_copy", cut and copy
|
|
|
|
// may also be disallowed to be called from non-privileged content.
|
|
|
|
// For that reason, we report the support status of corresponding
|
|
|
|
// command accordingly.
|
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
|
|
|
if (commandID.LowerCaseEqualsLiteral("paste")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (nsContentUtils::IsCutCopyRestricted()) {
|
|
|
|
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 10:37:00 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 12:04:14 +00:00
|
|
|
// commandID is supported if it can be converted to a Midas command
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-12-26 02:00:47 +00:00
|
|
|
return ConvertToMidasInternalCommand(commandID, cmdToDispatch);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLDocument::QueryCommandValue(const nsAString & commandID,
|
|
|
|
nsAString &_retval)
|
|
|
|
{
|
2012-12-26 02:00:47 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
QueryCommandValue(commandID, _retval, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2012-12-26 02:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLDocument::QueryCommandValue(const nsAString& commandID,
|
|
|
|
nsAString& aValue,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString cmdToDispatch, paramStr;
|
2012-04-15 12:57:20 +00:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
|
|
|
// Return empty string
|
2012-12-26 02:00:47 +00:00
|
|
|
return;
|
2012-04-15 12:57:20 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
// if editing is not on, bail
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return;
|
|
|
|
}
|
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));
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 02:00:47 +00:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
|
|
|
// create params
|
|
|
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
2012-12-26 02:00:47 +00:00
|
|
|
NS_COMMAND_PARAMS_CONTRACTID);
|
|
|
|
if (!cmdParams) {
|
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-10 21:12:29 +00:00
|
|
|
|
2012-05-22 09:37:17 +00:00
|
|
|
// this is a special command since we are calling DoCommand rather than
|
2003-06-10 21:12:29 +00:00
|
|
|
// GetCommandState like the other commands
|
2012-05-22 09:37:17 +00:00
|
|
|
if (cmdToDispatch.EqualsLiteral("cmd_getContents")) {
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = cmdParams->SetBooleanValue("selection_only", true);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2003-06-10 21:12:29 +00:00
|
|
|
rv = cmdParams->SetCStringValue("format", "text/html");
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2003-06-10 21:12:29 +00:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rv = cmdParams->GetStringValue("result", aValue);
|
|
|
|
return;
|
2003-06-10 21:12:29 +00:00
|
|
|
}
|
|
|
|
|
2002-11-07 15:38:35 +00:00
|
|
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2002-11-11 20:19:37 +00:00
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
2012-12-26 02:00:47 +00:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 15:38:35 +00:00
|
|
|
|
2012-04-06 07:42:54 +00:00
|
|
|
// If command does not have a state_attribute value, this call fails, and
|
2012-12-26 02:00:47 +00:00
|
|
|
// aValue will wind up being the empty string. This is fine -- we want to
|
2012-04-06 07:42:54 +00:00
|
|
|
// return "" in that case anyway (bug 738385), so we just return NS_OK
|
|
|
|
// regardless.
|
2004-01-26 09:48:50 +00:00
|
|
|
nsXPIDLCString cStringResult;
|
2012-04-06 07:42:54 +00:00
|
|
|
cmdParams->GetCStringValue("state_attribute",
|
|
|
|
getter_Copies(cStringResult));
|
2012-12-26 02:00:47 +00:00
|
|
|
CopyUTF8toUTF16(cStringResult, aValue);
|
2002-11-07 15:38:35 +00:00
|
|
|
}
|
2004-06-25 12:26:02 +00:00
|
|
|
|
2008-09-18 11:15:47 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
nsHTMLDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2008-09-18 11:15:47 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsHTMLDocument> clone = new nsHTMLDocument();
|
2008-09-18 11:15:47 +00:00
|
|
|
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
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-10-29 20:12:24 +00:00
|
|
|
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();
|
|
|
|
}
|
2012-02-01 21:58:01 +00:00
|
|
|
|
|
|
|
/* virtual */ void
|
2013-09-30 23:20:23 +00:00
|
|
|
nsHTMLDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const
|
2012-02-01 21:58:01 +00:00
|
|
|
{
|
2013-09-30 23:20:23 +00:00
|
|
|
nsDocument::DocAddSizeOfExcludingThis(aWindowSizes);
|
2012-02-01 21:58:01 +00:00
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mImages
|
|
|
|
// - mApplets
|
|
|
|
// - mEmbeds
|
|
|
|
// - mLinks
|
|
|
|
// - mAnchors
|
|
|
|
// - mScripts
|
|
|
|
// - mForms
|
|
|
|
// - mFormControls
|
|
|
|
// - mWyciwygChannel
|
|
|
|
// - mMidasCommandManager
|
|
|
|
}
|
2013-01-18 14:27:03 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLDocument::WillIgnoreCharsetOverride()
|
|
|
|
{
|
2014-05-24 19:28:48 +00:00
|
|
|
if (mType != eHTML) {
|
|
|
|
MOZ_ASSERT(mType == eXHTML);
|
2013-01-18 14:27:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (mCharacterSetSource == kCharsetFromByteOrderMark) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-04 18:09:11 +00:00
|
|
|
if (!EncodingUtils::IsAsciiCompatible(mCharacterSet)) {
|
2013-01-18 14:27:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWyciwygChannel> wyciwyg = do_QueryInterface(mChannel);
|
|
|
|
if (wyciwyg) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
nsIURI* uri = GetOriginalURI();
|
|
|
|
if (uri) {
|
|
|
|
bool schemeIs = false;
|
|
|
|
uri->SchemeIs("about", &schemeIs);
|
|
|
|
if (schemeIs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool isResource;
|
|
|
|
nsresult rv = NS_URIChainHasFlags(uri,
|
|
|
|
nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
|
|
|
&isResource);
|
|
|
|
if (NS_FAILED(rv) || isResource) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|