2015-05-03 22:32:37 +03: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 15:12:37 +04: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 09:50:08 +04:00
|
|
|
|
2013-09-06 10:41:42 +04:00
|
|
|
#include "nsHTMLDocument.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2013-09-06 10:41:42 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2019-08-15 08:30:56 +03:00
|
|
|
#include "mozilla/StaticPrefs_intl.h"
|
2019-04-03 15:51:38 +03:00
|
|
|
#include "nsCommandManager.h"
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-12 12:15:56 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2017-08-17 08:29:03 +03:00
|
|
|
#include "nsString.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
Bug 1489308 part 5. Align the work we do on document.open with the spec. r=mccr8,smaug
The main behavior changes are:
1) We no longer create a new Window when doing document.open(). We use the
same Window but remove all the event listeners on it and on the existing DOM
tree before removing the document's existing kids.
2) We no longer create a new session history entry. The existing one always
gets replaced instead.
3) We now support document.open on documents that are not in a Window.
The reasons for the various test changes are as follows:
The change to browser_modifiedclick_inherit_principal.js is because we no
longer set the docshell to a wyciwyg URL when document.open() happens and the
test was depending on that to terminate.
browser_wyciwyg_urlbarCopying.js is being removed because it's trying to test
wyciwyg URIs, which no longer exist.
The changes in docshell/test/navigation are because document.open() no longer
affects session history. One of the tests was testing the interactions there
and is being removed; another is being repurposed to just test that
document.open() does not affect history.length.
The change to test_x-frame-options.html is because document.open() now removes
event listeners on the window, which it didn't use to do (and in the specific
case in this test reused the existing inner too, so the listener was still
around in practice). The new behavior matches other browsers.
The removal of test_bug172261.html is because document.open() no longer affects
session history, so you can't go back across it or forward to the "opened"
state, so the situation that test is trying to test no longer exists.
The changes to test_bug255820.html are because reloading a document after
document.open() will now just load the URL of the document that was the entry
document for the open() call, not reload the written content. So there's not
much point testing reload behavior, and in this test it was just reloading the
toplevel test file inside the frames.
The change to test_bug346659.html is because now we no longer create a new
Window on document.open().
The change to test_bug1232829.html is because document.open() (implicit in this
test) no longer adds history entries, so the back() was just leaving the test
page instead of going back across the document.open(). The test is a
crashtest in practice, so might still be testing something useful about how
document.open() interacts with animations.
The change to test_bug715739.html is because the URL of the document after
document.open() is now the URL of the entry document, not a wyciwyg URL, so
reload() has different behavior than it used to.
The change to test_bug329869.html is because now when we go back we're
reloading the original document we had, not doing a wyciwyg load, and the
security info now doesn't include the untrusted script.
The changes to the wpt expectations are removing a bunch of expected failures
now that we pass those tests and disabling some tests that are fundamentally
racy and hence fail randomly. The latter all have github issues filed for the
test problem.
The change to testing/web-platform/tests/common/object-association.js is fixing
tests that were not matching the spec (and were failing in other browsers).
The change to parser-uses-registry-of-owner-document.html is fixing tests that
were not matching the spec (and were failing in other browsers).
The change to document-write.tentative.html is because the test was buggy: it
was using the same iframe element for all its tests and racing loads from some
tests against API calls from other tests, etc. It's a wonder it ever managed
to pass, independent of these patches (and in fact it doesn't pass according to
wpt.fyi data, even in Firefox).
The changes in html/browsers/history/the-history-interface are because
document.open() no longer adds history entries. The test was failing in all
other browsers for the same reason.
The changes in html/browsers/history/the-location-interface are because
reloading a document.open()-created thing now loads the URL of the page that
was the entry document for the open() call. The test was failing in all other
browsers.
The change to reload_document_open_write.html is because we now reload the url
of the document that entered the script that called open() when we reload, not
the written content. Other browsers were failing this test too; Gecko with
the old document.open implementation was the only one that passed.
The change to http-refresh.py is to fix a test bug: it was not returning a
Content-Type header, so we were putting up helper app dialogs, etc.
The change to test_ext_contentscript.js is because we no create a new global
for document.open() calls. Kris Maglione OKed this part.
Differential Revision: https://phabricator.services.mozilla.com/D17323
--HG--
extra : moz-landing-system : lando
2019-02-28 02:24:48 +03:00
|
|
|
#include "nsGlobalWindowInner.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIHTMLContentSink.h"
|
2003-04-19 04:28:09 +04:00
|
|
|
#include "nsIXMLContentSink.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsHTMLParts.h"
|
2004-04-13 01:56:09 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2005-08-12 08:11:00 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
1998-07-01 15:16:09 +04:00
|
|
|
#include "nsIStreamListener.h"
|
2002-10-30 07:57:15 +03:00
|
|
|
#include "nsIURI.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIContentViewer.h"
|
2013-11-15 11:12:43 +04:00
|
|
|
#include "nsDocShell.h"
|
2007-07-04 01:41:32 +04:00
|
|
|
#include "nsDocShellLoadTypes.h"
|
2002-04-19 02:49:39 +04:00
|
|
|
#include "nsIScriptContext.h"
|
1998-07-23 03:32:19 +04:00
|
|
|
#include "nsContentList.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2012-06-15 10:31:27 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
2005-12-29 00:52:39 +03:00
|
|
|
#include "nsAttrName.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
|
2003-10-30 05:59:31 +03:00
|
|
|
#include "nsNetCID.h"
|
1998-07-31 02:42:27 +04:00
|
|
|
#include "nsParserCIID.h"
|
2019-03-09 04:00:23 +03:00
|
|
|
#include "mozilla/parser/PrototypeDocumentParser.h"
|
|
|
|
#include "mozilla/dom/PrototypeDocumentContentSink.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-07-07 08:52:27 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2006-04-26 05:57:22 +04:00
|
|
|
#include "nsFrameSelection.h"
|
1999-07-14 19:33:48 +04:00
|
|
|
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsContentUtils.h"
|
2004-04-13 07:21:50 +04:00
|
|
|
#include "nsJSUtils.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "DocumentInlines.h"
|
2001-04-27 06:26:32 +04:00
|
|
|
#include "nsICachingChannel.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2006-01-24 04:25:14 +03:00
|
|
|
#include "nsIScriptElement.h"
|
2006-04-12 19:43:32 +04:00
|
|
|
#include "nsArrayUtils.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 20:46:42 +04:00
|
|
|
|
2003-03-26 10:41:30 +03:00
|
|
|
// AHMED 12-2
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2000-05-13 12:11:29 +04:00
|
|
|
|
2013-11-04 15:24:33 +04:00
|
|
|
#include "mozilla/dom/FallbackEncoding.h"
|
2017-06-16 15:11:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
Bug 1489308 part 5. Align the work we do on document.open with the spec. r=mccr8,smaug
The main behavior changes are:
1) We no longer create a new Window when doing document.open(). We use the
same Window but remove all the event listeners on it and on the existing DOM
tree before removing the document's existing kids.
2) We no longer create a new session history entry. The existing one always
gets replaced instead.
3) We now support document.open on documents that are not in a Window.
The reasons for the various test changes are as follows:
The change to browser_modifiedclick_inherit_principal.js is because we no
longer set the docshell to a wyciwyg URL when document.open() happens and the
test was depending on that to terminate.
browser_wyciwyg_urlbarCopying.js is being removed because it's trying to test
wyciwyg URIs, which no longer exist.
The changes in docshell/test/navigation are because document.open() no longer
affects session history. One of the tests was testing the interactions there
and is being removed; another is being repurposed to just test that
document.open() does not affect history.length.
The change to test_x-frame-options.html is because document.open() now removes
event listeners on the window, which it didn't use to do (and in the specific
case in this test reused the existing inner too, so the listener was still
around in practice). The new behavior matches other browsers.
The removal of test_bug172261.html is because document.open() no longer affects
session history, so you can't go back across it or forward to the "opened"
state, so the situation that test is trying to test no longer exists.
The changes to test_bug255820.html are because reloading a document after
document.open() will now just load the URL of the document that was the entry
document for the open() call, not reload the written content. So there's not
much point testing reload behavior, and in this test it was just reloading the
toplevel test file inside the frames.
The change to test_bug346659.html is because now we no longer create a new
Window on document.open().
The change to test_bug1232829.html is because document.open() (implicit in this
test) no longer adds history entries, so the back() was just leaving the test
page instead of going back across the document.open(). The test is a
crashtest in practice, so might still be testing something useful about how
document.open() interacts with animations.
The change to test_bug715739.html is because the URL of the document after
document.open() is now the URL of the entry document, not a wyciwyg URL, so
reload() has different behavior than it used to.
The change to test_bug329869.html is because now when we go back we're
reloading the original document we had, not doing a wyciwyg load, and the
security info now doesn't include the untrusted script.
The changes to the wpt expectations are removing a bunch of expected failures
now that we pass those tests and disabling some tests that are fundamentally
racy and hence fail randomly. The latter all have github issues filed for the
test problem.
The change to testing/web-platform/tests/common/object-association.js is fixing
tests that were not matching the spec (and were failing in other browsers).
The change to parser-uses-registry-of-owner-document.html is fixing tests that
were not matching the spec (and were failing in other browsers).
The change to document-write.tentative.html is because the test was buggy: it
was using the same iframe element for all its tests and racing loads from some
tests against API calls from other tests, etc. It's a wonder it ever managed
to pass, independent of these patches (and in fact it doesn't pass according to
wpt.fyi data, even in Firefox).
The changes in html/browsers/history/the-history-interface are because
document.open() no longer adds history entries. The test was failing in all
other browsers for the same reason.
The changes in html/browsers/history/the-location-interface are because
reloading a document.open()-created thing now loads the URL of the page that
was the entry document for the open() call. The test was failing in all other
browsers.
The change to reload_document_open_write.html is because we now reload the url
of the document that entered the script that called open() when we reload, not
the written content. Other browsers were failing this test too; Gecko with
the old document.open implementation was the only one that passed.
The change to http-refresh.py is to fix a test bug: it was not returning a
Content-Type header, so we were putting up helper app dialogs, etc.
The change to test_ext_contentscript.js is because we no create a new global
for document.open() calls. Kris Maglione OKed this part.
Differential Revision: https://phabricator.services.mozilla.com/D17323
--HG--
extra : moz-landing-system : lando
2019-02-28 02:24:48 +03:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2019-01-08 13:15:55 +03:00
|
|
|
#include "mozilla/IdentifierMapEntry.h"
|
2014-07-10 10:56:37 +04:00
|
|
|
#include "mozilla/LoadInfo.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2007-06-28 06:48:16 +04:00
|
|
|
#include "nsRange.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2009-03-03 15:14:13 +03:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
#include "nsHtml5Module.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-05-28 11:03:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-11-01 19:27:36 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2012-01-30 21:03:52 +04:00
|
|
|
#include "nsIRequest.h"
|
2012-03-24 15:34:42 +04:00
|
|
|
#include "nsHtml5TreeOpExecutor.h"
|
2019-05-27 23:57:00 +03:00
|
|
|
#include "nsHtml5Parser.h"
|
2012-08-20 22:34:32 +04:00
|
|
|
#include "nsSandboxFlags.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.h"
|
2012-12-12 06:45:36 +04:00
|
|
|
#include "mozilla/dom/HTMLDocumentBinding.h"
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "mozilla/dom/nsCSPContext.h"
|
2018-03-27 07:35:23 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
Bug 1489308 part 5. Align the work we do on document.open with the spec. r=mccr8,smaug
The main behavior changes are:
1) We no longer create a new Window when doing document.open(). We use the
same Window but remove all the event listeners on it and on the existing DOM
tree before removing the document's existing kids.
2) We no longer create a new session history entry. The existing one always
gets replaced instead.
3) We now support document.open on documents that are not in a Window.
The reasons for the various test changes are as follows:
The change to browser_modifiedclick_inherit_principal.js is because we no
longer set the docshell to a wyciwyg URL when document.open() happens and the
test was depending on that to terminate.
browser_wyciwyg_urlbarCopying.js is being removed because it's trying to test
wyciwyg URIs, which no longer exist.
The changes in docshell/test/navigation are because document.open() no longer
affects session history. One of the tests was testing the interactions there
and is being removed; another is being repurposed to just test that
document.open() does not affect history.length.
The change to test_x-frame-options.html is because document.open() now removes
event listeners on the window, which it didn't use to do (and in the specific
case in this test reused the existing inner too, so the listener was still
around in practice). The new behavior matches other browsers.
The removal of test_bug172261.html is because document.open() no longer affects
session history, so you can't go back across it or forward to the "opened"
state, so the situation that test is trying to test no longer exists.
The changes to test_bug255820.html are because reloading a document after
document.open() will now just load the URL of the document that was the entry
document for the open() call, not reload the written content. So there's not
much point testing reload behavior, and in this test it was just reloading the
toplevel test file inside the frames.
The change to test_bug346659.html is because now we no longer create a new
Window on document.open().
The change to test_bug1232829.html is because document.open() (implicit in this
test) no longer adds history entries, so the back() was just leaving the test
page instead of going back across the document.open(). The test is a
crashtest in practice, so might still be testing something useful about how
document.open() interacts with animations.
The change to test_bug715739.html is because the URL of the document after
document.open() is now the URL of the entry document, not a wyciwyg URL, so
reload() has different behavior than it used to.
The change to test_bug329869.html is because now when we go back we're
reloading the original document we had, not doing a wyciwyg load, and the
security info now doesn't include the untrusted script.
The changes to the wpt expectations are removing a bunch of expected failures
now that we pass those tests and disabling some tests that are fundamentally
racy and hence fail randomly. The latter all have github issues filed for the
test problem.
The change to testing/web-platform/tests/common/object-association.js is fixing
tests that were not matching the spec (and were failing in other browsers).
The change to parser-uses-registry-of-owner-document.html is fixing tests that
were not matching the spec (and were failing in other browsers).
The change to document-write.tentative.html is because the test was buggy: it
was using the same iframe element for all its tests and racing loads from some
tests against API calls from other tests, etc. It's a wonder it ever managed
to pass, independent of these patches (and in fact it doesn't pass according to
wpt.fyi data, even in Firefox).
The changes in html/browsers/history/the-history-interface are because
document.open() no longer adds history entries. The test was failing in all
other browsers for the same reason.
The changes in html/browsers/history/the-location-interface are because
reloading a document.open()-created thing now loads the URL of the page that
was the entry document for the open() call. The test was failing in all other
browsers.
The change to reload_document_open_write.html is because we now reload the url
of the document that entered the script that called open() when we reload, not
the written content. Other browsers were failing this test too; Gecko with
the old document.open implementation was the only one that passed.
The change to http-refresh.py is to fix a test bug: it was not returning a
Content-Type header, so we were putting up helper app dialogs, etc.
The change to test_ext_contentscript.js is because we no create a new global
for document.open() calls. Kris Maglione OKed this part.
Differential Revision: https://phabricator.services.mozilla.com/D17323
--HG--
extra : moz-landing-system : lando
2019-02-28 02:24:48 +03:00
|
|
|
#include "mozilla/dom/ShadowIncludingTreeIterator.h"
|
2013-01-18 18:27:03 +04:00
|
|
|
#include "nsCharsetSource.h"
|
2015-04-21 09:27:10 +03:00
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-11-15 08:18:33 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2002-11-07 18:38:35 +03:00
|
|
|
|
1999-11-12 05:06:54 +03:00
|
|
|
#include "prtime.h"
|
1999-07-14 21:13:05 +04:00
|
|
|
|
1999-12-14 00:00:47 +03:00
|
|
|
//#define DEBUG_charset
|
|
|
|
|
2001-03-11 00:02:12 +03:00
|
|
|
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
|
|
|
|
1999-01-19 19:58:45 +03:00
|
|
|
// ==================================================================
|
|
|
|
// =
|
|
|
|
// ==================================================================
|
2010-10-29 20:30:15 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
static bool IsAsciiCompatible(const Encoding* aEncoding) {
|
|
|
|
return aEncoding->IsAsciiCompatible() || aEncoding == ISO_2022_JP_ENCODING;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult NS_NewHTMLDocument(Document** aInstancePtrResult, bool aLoadedAsData) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHTMLDocument> doc = new nsHTMLDocument();
|
2002-01-25 09:37:35 +03:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-07-27 13:12:38 +04:00
|
|
|
*aInstancePtrResult = nullptr;
|
|
|
|
return rv;
|
2002-01-25 09:37:35 +03:00
|
|
|
}
|
|
|
|
|
2012-11-21 20:18:57 +04:00
|
|
|
doc->SetLoadedAsData(aLoadedAsData);
|
2013-07-27 13:12:38 +04:00
|
|
|
doc.forget(aInstancePtrResult);
|
2002-01-25 09:37:35 +03:00
|
|
|
|
2013-07-27 13:12:38 +04:00
|
|
|
return NS_OK;
|
2002-01-25 09:37:35 +03:00
|
|
|
}
|
|
|
|
|
2013-05-06 17:42:00 +04:00
|
|
|
nsHTMLDocument::nsHTMLDocument()
|
2019-01-02 16:05:23 +03:00
|
|
|
: Document("text/html"),
|
2017-09-14 21:56:58 +03:00
|
|
|
mContentListHolder(nullptr),
|
2017-01-24 19:10:39 +03:00
|
|
|
mNumForms(0),
|
|
|
|
mLoadFlags(0),
|
|
|
|
mWarnedWidthHeight(false),
|
2019-02-23 19:06:52 +03:00
|
|
|
mIsPlainText(false) {
|
2014-05-24 23:28:48 +04:00
|
|
|
mType = eHTML;
|
2015-10-14 18:07:06 +03:00
|
|
|
mDefaultElementType = kNameSpaceID_XHTML;
|
2006-12-05 18:46:18 +03:00
|
|
|
mCompatMode = eCompatibility_NavQuirks;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-06-12 10:55:00 +04:00
|
|
|
nsHTMLDocument::~nsHTMLDocument() {}
|
2013-09-06 10:41:42 +04: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 17:13:33 +03:00
|
|
|
JSObject* nsHTMLDocument::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-11-29 02:24:53 +03:00
|
|
|
return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto);
|
2012-12-12 06:45:36 +04:00
|
|
|
}
|
2008-02-21 23:39:20 +03:00
|
|
|
|
2002-01-25 09:37:35 +03:00
|
|
|
nsresult nsHTMLDocument::Init() {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult rv = Document::Init();
|
2002-01-25 09:37:35 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
// Now reset the compatibility mode of the CSSLoader
|
|
|
|
// to match our compat mode.
|
2006-01-06 05:53:10 +03:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
|
|
|
|
2002-01-25 09:37:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-26 10:41:30 +03:00
|
|
|
void nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::Reset(aChannel, aLoadGroup);
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
if (aChannel) {
|
2003-03-26 10:41:30 +03:00
|
|
|
aChannel->GetLoadFlags(&mLoadFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-22 21:27:54 +03:00
|
|
|
void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
|
2019-04-12 08:31:32 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIPrincipal* aStoragePrincipal) {
|
2003-03-26 10:41:30 +03:00
|
|
|
mLoadFlags = nsIRequest::LOAD_NORMAL;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2019-04-12 08:31:32 +03:00
|
|
|
Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aStoragePrincipal);
|
2001-11-16 05:03:19 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mImages = nullptr;
|
|
|
|
mApplets = nullptr;
|
|
|
|
mEmbeds = nullptr;
|
|
|
|
mLinks = nullptr;
|
|
|
|
mAnchors = nullptr;
|
|
|
|
mScripts = nullptr;
|
1999-01-06 03:32:41 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mForms = nullptr;
|
1998-05-14 03:43:44 +04:00
|
|
|
|
2003-05-31 00:04:50 +04: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-27 00:39:56 +04:00
|
|
|
SetContentTypeInternal(nsDependentCString("text/html"));
|
1999-01-06 03:32:41 +03:00
|
|
|
}
|
|
|
|
|
2014-07-10 01:27:49 +04:00
|
|
|
void nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
2017-06-18 14:37:50 +03:00
|
|
|
int32_t& aCharsetSource,
|
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2014-07-10 01:27:49 +04:00
|
|
|
if (aCv) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t requestCharsetSource;
|
2014-07-10 01:27:49 +04:00
|
|
|
nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2001-12-26 06:17:59 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
2017-06-25 16:46:08 +03:00
|
|
|
auto requestCharset = aCv->GetHintCharset();
|
2014-07-10 01:27:49 +04:00
|
|
|
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
if (requestCharsetSource <= aCharsetSource) return;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2017-06-25 16:46:08 +03:00
|
|
|
if (requestCharset && IsAsciiCompatible(requestCharset)) {
|
|
|
|
aCharsetSource = requestCharsetSource;
|
|
|
|
aEncoding = WrapNotNull(requestCharset);
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:27:49 +04:00
|
|
|
void nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
2012-01-24 13:52:05 +04:00
|
|
|
nsIDocShell* aDocShell,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2003-03-26 10:41:30 +03:00
|
|
|
if (kCharsetFromUserForced <= aCharsetSource) return;
|
2013-01-18 18:27:03 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
// mCharacterSet not updated yet for channel, so check aEncoding, too.
|
|
|
|
if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aEncoding)) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2017-06-25 16:46:08 +03:00
|
|
|
const Encoding* forceCharsetFromDocShell = nullptr;
|
2014-07-10 01:27:49 +04:00
|
|
|
if (aCv) {
|
2013-01-18 18:27:03 +04:00
|
|
|
// XXX mailnews-only
|
2017-06-25 16:46:08 +03:00
|
|
|
forceCharsetFromDocShell = aCv->GetForceCharset();
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2017-06-17 05:54:40 +03:00
|
|
|
if (forceCharsetFromDocShell && IsAsciiCompatible(forceCharsetFromDocShell)) {
|
2017-06-25 16:46:08 +03:00
|
|
|
aEncoding = WrapNotNull(forceCharsetFromDocShell);
|
2003-03-26 10:41:30 +03:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDocShell) {
|
|
|
|
// This is the Character Encoding menu code path in Firefox
|
2017-06-18 14:37:50 +03:00
|
|
|
auto encoding = nsDocShell::Cast(aDocShell)->GetForcedCharset();
|
2013-05-25 18:09:30 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
if (encoding) {
|
|
|
|
if (!IsAsciiCompatible(encoding)) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(encoding);
|
2003-03-26 10:41:30 +03:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-05-25 18:09:30 +04:00
|
|
|
aDocShell->SetForcedCharset(NS_LITERAL_CSTRING(""));
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 10:55:19 +04:00
|
|
|
void nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2001-12-26 06:17:59 +03:00
|
|
|
nsresult rv;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
|
|
|
if (kCharsetFromCache <= aCharsetSource) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2010-06-24 10:55:19 +04:00
|
|
|
nsCString cachedCharset;
|
|
|
|
rv = aCachingChannel->GetCacheTokenCachedCharset(cachedCharset);
|
2017-06-15 10:52:31 +03:00
|
|
|
if (NS_FAILED(rv) || cachedCharset.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The canonical names changed, so the cache may have an old name.
|
2017-08-28 12:57:17 +03:00
|
|
|
const Encoding* encoding = Encoding::ForLabelNoReplacement(cachedCharset);
|
2017-06-17 05:54:40 +03:00
|
|
|
if (!encoding) {
|
|
|
|
return;
|
2017-06-15 10:52:31 +03:00
|
|
|
}
|
2017-06-17 05:54:40 +03:00
|
|
|
// Check IsAsciiCompatible() even in the cache case, because the value
|
2012-10-16 11:42:54 +04: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.
|
2017-06-17 05:54:40 +03:00
|
|
|
if (!encoding->IsAsciiCompatible() && encoding != ISO_2022_JP_ENCODING) {
|
|
|
|
return;
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(encoding);
|
2017-06-17 05:54:40 +03:00
|
|
|
aCharsetSource = kCharsetFromCache;
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:52:05 +04:00
|
|
|
void nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2012-10-16 11:42:54 +04:00
|
|
|
if (!aDocShell) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-18 18:27:03 +04:00
|
|
|
if (aCharsetSource >= kCharsetFromParentForced) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 11:42:54 +04:00
|
|
|
int32_t parentSource;
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* parentCharset;
|
2013-10-16 05:46:10 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> parentPrincipal;
|
|
|
|
aDocShell->GetParentCharset(parentCharset, &parentSource,
|
|
|
|
getter_AddRefs(parentPrincipal));
|
2017-06-18 14:37:50 +03:00
|
|
|
if (!parentCharset) {
|
2012-10-16 11:42:54 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-18 18:27:03 +04:00
|
|
|
if (kCharsetFromParentForced == parentSource ||
|
2019-12-12 20:50:19 +03:00
|
|
|
kCharsetFromUserForced == parentSource ||
|
|
|
|
kCharsetFromUserForcedAutoDetection == parentSource) {
|
2013-01-18 18:27:03 +04:00
|
|
|
if (WillIgnoreCharsetOverride() ||
|
2017-06-18 14:37:50 +03:00
|
|
|
!IsAsciiCompatible(aEncoding) || // if channel said UTF-16
|
2017-06-17 05:54:40 +03:00
|
|
|
!IsAsciiCompatible(parentCharset)) {
|
2012-10-16 11:42:54 +04:00
|
|
|
return;
|
2007-01-13 06:28:00 +03:00
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(parentCharset);
|
2013-01-18 18:27:03 +04:00
|
|
|
aCharsetSource = kCharsetFromParentForced;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-13 06:28:00 +03:00
|
|
|
|
2013-01-18 18:27:03 +04:00
|
|
|
if (aCharsetSource >= kCharsetFromParentFrame) {
|
2012-10-16 11:42:54 +04:00
|
|
|
return;
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
2012-10-16 11:42:54 +04:00
|
|
|
|
2013-01-18 18:27:03 +04:00
|
|
|
if (kCharsetFromCache <= parentSource) {
|
|
|
|
// Make sure that's OK
|
2013-10-16 05:46:10 +04:00
|
|
|
if (!NodePrincipal()->Equals(parentPrincipal) ||
|
2017-06-17 05:54:40 +03:00
|
|
|
!IsAsciiCompatible(parentCharset)) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(parentCharset);
|
2013-01-18 18:27:03 +04:00
|
|
|
aCharsetSource = kCharsetFromParentFrame;
|
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
void nsHTMLDocument::TryTLD(int32_t& aCharsetSource,
|
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2014-02-06 13:08:01 +04:00
|
|
|
if (aCharsetSource >= kCharsetFromTopLevelDomain) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-15 08:30:56 +03:00
|
|
|
if (!StaticPrefs::intl_charset_fallback_tld()) {
|
2014-02-06 13:08:01 +04:00
|
|
|
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;
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = FallbackEncoding::FromTopLevelDomain(tld);
|
2014-02-06 13:08:01 +04:00
|
|
|
}
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
void nsHTMLDocument::TryFallback(int32_t& aCharsetSource,
|
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2013-11-04 15:24:33 +04:00
|
|
|
if (kCharsetFromFallback <= aCharsetSource) return;
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2013-11-04 15:24:33 +04:00
|
|
|
aCharsetSource = kCharsetFromFallback;
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = FallbackEncoding::FromLocale();
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
|
2019-04-05 18:44:56 +03:00
|
|
|
// Using a prototype document is only allowed with chrome privilege.
|
2019-04-16 21:27:52 +03:00
|
|
|
bool ShouldUsePrototypeDocument(nsIChannel* aChannel, Document* aDoc) {
|
|
|
|
if (!aChannel || !aDoc ||
|
2019-03-09 04:00:23 +03:00
|
|
|
!StaticPrefs::dom_prototype_document_cache_enabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-19 22:24:58 +03:00
|
|
|
return nsContentUtils::IsChromeDoc(aDoc);
|
2019-03-09 04:00:23 +03:00
|
|
|
}
|
|
|
|
|
2003-03-22 06:20:23 +03:00
|
|
|
nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset, nsIContentSink* aSink) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if (!aCommand) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Command is mandatory");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
if (aSink) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Got a sink override. Should not happen for HTML doc.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-05-24 23:28:48 +04:00
|
|
|
if (mType != eHTML) {
|
|
|
|
MOZ_ASSERT(mType == eXHTML);
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2011-11-01 19:27:36 +04:00
|
|
|
aChannel->GetContentType(contentType);
|
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
bool view =
|
|
|
|
!strcmp(aCommand, "view") || !strcmp(aCommand, "external-resource");
|
|
|
|
bool viewSource = !strcmp(aCommand, "view-source");
|
|
|
|
bool asData = !strcmp(aCommand, kLoadAsData);
|
2017-06-12 17:36:02 +03:00
|
|
|
if (!(view || viewSource || asData)) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Bad parser command");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool html = contentType.EqualsLiteral(TEXT_HTML);
|
2016-09-28 17:48:17 +03:00
|
|
|
bool xhtml = !html && (contentType.EqualsLiteral(APPLICATION_XHTML_XML) ||
|
2019-12-24 02:02:05 +03:00
|
|
|
contentType.EqualsLiteral(APPLICATION_WAPXHTML_XML));
|
2019-02-23 19:06:52 +03:00
|
|
|
mIsPlainText =
|
2013-03-20 00:30:53 +04:00
|
|
|
!html && !xhtml && nsContentUtils::IsPlainTextType(contentType);
|
2019-02-23 19:06:52 +03:00
|
|
|
if (!(html || xhtml || mIsPlainText || viewSource)) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Channel with bad content type.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2011-11-01 19:27:36 +04:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:29:30 +03:00
|
|
|
bool forceUtf8 =
|
2019-02-23 19:06:52 +03:00
|
|
|
mIsPlainText && nsContentUtils::IsUtf8OnlyPlainTextType(contentType);
|
2016-06-09 14:29:30 +03:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
bool loadAsHtml5 = true;
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
if (!viewSource && xhtml) {
|
|
|
|
// We're parsing XHTML as XML, remember that.
|
2014-05-24 23:28:48 +04:00
|
|
|
mType = eXHTML;
|
2019-04-03 10:02:00 +03:00
|
|
|
SetCompatibilityMode(eCompatibility_FullStandards);
|
2012-03-31 18:10:34 +04:00
|
|
|
loadAsHtml5 = false;
|
2003-04-19 04:28:09 +04:00
|
|
|
}
|
2016-08-26 09:02:32 +03:00
|
|
|
|
2010-02-02 10:39:26 +03:00
|
|
|
// TODO: Proper about:blank treatment is bug 543435
|
2012-03-31 18:10:34 +04:00
|
|
|
if (loadAsHtml5 && view) {
|
2010-02-02 10:39:26 +03: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.
|
2019-08-02 11:54:18 +03:00
|
|
|
if (uri && uri->SchemeIs("about")) {
|
2016-08-26 09:02:32 +03:00
|
|
|
if (uri->GetSpecOrDefault().EqualsLiteral("about:blank")) {
|
|
|
|
loadAsHtml5 = false;
|
2010-02-02 10:39:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-26 09:02:32 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult rv = Document::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset);
|
2003-03-22 06:20:23 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-02-28 04:09:48 +03:00
|
|
|
// Store the security info for future use.
|
2004-07-28 04:26:58 +04:00
|
|
|
aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
2003-03-22 06:20:23 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
|
2019-03-09 04:00:23 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2003-03-22 06:20:23 +03:00
|
|
|
|
2019-03-09 04:00:23 +03:00
|
|
|
bool loadWithPrototype = false;
|
2019-05-14 22:46:25 +03:00
|
|
|
RefPtr<nsHtml5Parser> html5Parser;
|
2012-03-31 18:10:34 +04:00
|
|
|
if (loadAsHtml5) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser = nsHtml5Module::NewHtml5Parser();
|
|
|
|
mParser = html5Parser;
|
2019-02-23 19:06:52 +03:00
|
|
|
if (mIsPlainText) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if (viewSource) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("view-source-plain");
|
2011-11-01 19:27:36 +04:00
|
|
|
} else {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("plain-text");
|
2011-11-01 19:27:36 +04:00
|
|
|
}
|
2012-03-31 18:10:34 +04:00
|
|
|
} else if (viewSource && !html) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("view-source-xml");
|
2009-06-29 02:44:22 +04:00
|
|
|
} else {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated(aCommand);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2019-04-16 21:27:52 +03:00
|
|
|
} else if (xhtml && ShouldUsePrototypeDocument(aChannel, this)) {
|
2019-03-09 04:00:23 +03:00
|
|
|
loadWithPrototype = true;
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
mParser = new mozilla::parser::PrototypeDocumentParser(originalURI, this);
|
2012-03-31 18:10:34 +04:00
|
|
|
} else {
|
|
|
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-12-09 10:18:38 +03:00
|
|
|
}
|
1999-04-26 21:56:37 +04:00
|
|
|
|
2007-01-13 06:28:00 +03:00
|
|
|
// Look for the parent document. Note that at this point we don't have our
|
|
|
|
// content viewer set up yet, and therefore do not have a useful
|
|
|
|
// mParentDocument.
|
|
|
|
|
|
|
|
// in this block of code, if we get an error result, we return it
|
|
|
|
// but if we get a null pointer, that's perfectly legal for parent
|
|
|
|
// and parentContentViewer
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
2013-02-13 02:02:51 +04:00
|
|
|
if (docShell) {
|
2019-07-26 19:48:31 +03:00
|
|
|
docShell->GetInProcessSameTypeParent(getter_AddRefs(parentAsItem));
|
2008-09-28 23:14:28 +04:00
|
|
|
}
|
2007-01-13 06:28:00 +03: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 10:18:38 +03:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2008-09-28 23:14:28 +04:00
|
|
|
if (docShell) {
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
}
|
2014-07-10 01:27:49 +04:00
|
|
|
if (!cv) {
|
|
|
|
cv = parentContentViewer.forget();
|
1999-12-09 10:18:38 +03:00
|
|
|
}
|
2001-05-15 07:42:33 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString urlSpec;
|
2004-01-10 02:54:21 +03:00
|
|
|
uri->GetSpec(urlSpec);
|
2006-04-25 10:57:31 +04:00
|
|
|
#ifdef DEBUG_charset
|
|
|
|
printf("Determining charset for %s\n", urlSpec.get());
|
|
|
|
#endif
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2007-05-09 06:47:58 +04:00
|
|
|
// These are the charset source and charset for our document
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t charsetSource;
|
2017-06-18 14:37:50 +03:00
|
|
|
auto encoding = UTF_8_ENCODING;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2014-12-17 22:14:04 +03:00
|
|
|
// For error reporting and referrer policy setting
|
2012-07-30 18:20:58 +04:00
|
|
|
nsHtml5TreeOpExecutor* executor = nullptr;
|
2012-03-24 15:34:42 +04:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
executor = static_cast<nsHtml5TreeOpExecutor*>(mParser->GetContentSink());
|
|
|
|
}
|
|
|
|
|
2016-06-09 14:29:30 +03:00
|
|
|
if (forceUtf8) {
|
|
|
|
charsetSource = kCharsetFromUtf8OnlyMime;
|
|
|
|
} else if (!IsHTMLDocument() || !docShell) { // no docshell for text/html XHR
|
2015-03-03 14:08:59 +03:00
|
|
|
charsetSource =
|
|
|
|
IsHTMLDocument() ? kCharsetFromFallback : kCharsetFromDocTypeDefault;
|
2017-06-18 14:37:50 +03:00
|
|
|
TryChannelCharset(aChannel, charsetSource, encoding, executor);
|
2004-04-14 02:28:16 +04:00
|
|
|
} else {
|
2013-02-13 02:02:51 +04:00
|
|
|
NS_ASSERTION(docShell, "Unexpected null value");
|
2008-09-28 23:14:28 +04:00
|
|
|
|
2004-04-14 02:28:16 +04:00
|
|
|
charsetSource = kCharsetUninitialized;
|
|
|
|
|
2013-01-18 18:27:03 +04: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.
|
|
|
|
|
2019-02-28 04:09:48 +03:00
|
|
|
// 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, encoding, executor);
|
2013-01-18 18:27:03 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
TryUserForcedCharset(cv, docShell, charsetSource, encoding);
|
2013-01-18 18:27:03 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
TryHintCharset(cv, charsetSource, encoding); // XXX mailnews-only
|
|
|
|
TryParentCharset(docShell, charsetSource, encoding);
|
2013-01-18 18:27:03 +04:00
|
|
|
|
|
|
|
if (cachingChan && !urlSpec.IsEmpty()) {
|
2017-06-18 14:37:50 +03:00
|
|
|
TryCacheCharset(cachingChan, charsetSource, encoding);
|
2000-08-05 04:07:03 +04:00
|
|
|
}
|
2002-08-27 00:13:31 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
TryTLD(charsetSource, encoding);
|
|
|
|
TryFallback(charsetSource, encoding);
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
1999-12-09 10:18:38 +03:00
|
|
|
|
2001-12-26 06:17:59 +03:00
|
|
|
SetDocumentCharacterSetSource(charsetSource);
|
2017-06-18 14:37:50 +03:00
|
|
|
SetDocumentCharacterSet(encoding);
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2010-06-24 10:55:19 +04:00
|
|
|
if (cachingChan) {
|
2017-06-18 14:37:50 +03:00
|
|
|
nsAutoCString charset;
|
|
|
|
encoding->Name(charset);
|
2010-06-24 10:55:19 +04:00
|
|
|
rv = cachingChan->SetCacheTokenCachedCharset(charset);
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "cannot SetMetaDataElement");
|
2011-11-16 11:38:51 +04:00
|
|
|
rv = NS_OK; // don't propagate error
|
2000-08-22 03:16:43 +04:00
|
|
|
}
|
|
|
|
|
1999-12-09 10:18:38 +03:00
|
|
|
// Set the parser as the stream listener for the document loader...
|
2012-03-31 18:10:34 +04:00
|
|
|
rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = mParser->GetStreamListener();
|
|
|
|
listener.forget(aDocListener);
|
1998-07-02 12:14:22 +04:00
|
|
|
|
1999-12-14 00:00:47 +03:00
|
|
|
#ifdef DEBUG_charset
|
2012-03-31 18:10:34 +04:00
|
|
|
printf(" charset = %s source %d\n", charset.get(), charsetSource);
|
1999-12-14 00:00:47 +03:00
|
|
|
#endif
|
2019-02-28 04:09:48 +03:00
|
|
|
mParser->SetDocumentCharset(encoding, charsetSource);
|
2012-03-31 18:10:34 +04:00
|
|
|
mParser->SetCommand(aCommand);
|
2001-11-02 04:53:13 +03:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!IsHTMLDocument()) {
|
2012-03-31 18:10:34 +04:00
|
|
|
MOZ_ASSERT(!loadAsHtml5);
|
2019-03-09 04:00:23 +03:00
|
|
|
if (loadWithPrototype) {
|
|
|
|
nsCOMPtr<nsIContentSink> sink;
|
|
|
|
NS_NewPrototypeDocumentContentSink(getter_AddRefs(sink), this, uri,
|
|
|
|
docShell, aChannel);
|
|
|
|
mParser->SetContentSink(sink);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIXMLContentSink> xmlsink;
|
|
|
|
NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri, docShell,
|
|
|
|
aChannel);
|
|
|
|
mParser->SetContentSink(xmlsink);
|
|
|
|
}
|
2012-03-31 18:10:34 +04:00
|
|
|
} else {
|
|
|
|
if (loadAsHtml5) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->Initialize(this, uri, docShell, aChannel);
|
2009-06-29 02:44:22 +04:00
|
|
|
} else {
|
2012-03-31 18:10:34 +04:00
|
|
|
// about:blank *only*
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> htmlsink;
|
|
|
|
NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri, docShell,
|
|
|
|
aChannel);
|
|
|
|
mParser->SetContentSink(htmlsink);
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-01 23:53:19 +04:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
// parser the content of the URI
|
2012-07-30 18:20:58 +04:00
|
|
|
mParser->Parse(uri, nullptr, (void*)this);
|
2012-03-31 18:10:34 +04:00
|
|
|
|
1998-06-01 23:53:19 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2019-02-24 19:32:08 +03:00
|
|
|
bool nsHTMLDocument::UseWidthDeviceWidthFallbackViewport() const {
|
|
|
|
if (mIsPlainText) {
|
|
|
|
// Plain text documents are simple enough that font inflation doesn't offer
|
|
|
|
// any appreciable advantage over defaulting to "width=device-width" and
|
|
|
|
// subsequently turning on word-wrapping.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Document::UseWidthDeviceWidthFallbackViewport();
|
|
|
|
}
|
|
|
|
|
2019-03-04 09:11:41 +03:00
|
|
|
Element* nsHTMLDocument::GetUnfocusedKeyEventTarget() {
|
2017-07-13 23:53:26 +03:00
|
|
|
if (nsGenericHTMLElement* body = GetBody()) {
|
|
|
|
return body;
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
return Document::GetUnfocusedKeyEventTarget();
|
2017-07-13 23:53:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:37:34 +03:00
|
|
|
bool nsHTMLDocument::IsRegistrableDomainSuffixOfOrEqualTo(
|
|
|
|
const nsAString& aHostSuffixString, const nsACString& aOrigHost) {
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#is-a-registrable-domain-suffix-of-or-is-equal-to
|
|
|
|
if (aHostSuffixString.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> origURI = CreateInheritingURIForHost(aOrigHost);
|
|
|
|
if (!origURI) {
|
|
|
|
// Error: failed to parse input domain
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newURI =
|
|
|
|
RegistrableDomainSuffixOfInternal(aHostSuffixString, origURI);
|
|
|
|
if (!newURI) {
|
|
|
|
// Error: illegal domain
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-07-17 02:38:51 +04:00
|
|
|
void nsHTMLDocument::AddedForm() { ++mNumForms; }
|
|
|
|
|
|
|
|
void nsHTMLDocument::RemovedForm() { --mNumForms; }
|
|
|
|
|
2004-02-04 02:23:10 +03:00
|
|
|
int32_t nsHTMLDocument::GetNumFormsSynchronous() { return mNumForms; }
|
2002-07-17 02:38:51 +04:00
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
bool nsHTMLDocument::ResolveName(JSContext* aCx, const nsAString& aName,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aError) {
|
2019-01-08 13:15:55 +03:00
|
|
|
IdentifierMapEntry* entry = mIdentifierMap.GetEntry(aName);
|
2011-04-23 11:29:12 +04:00
|
|
|
if (!entry) {
|
2016-12-09 20:02:50 +03:00
|
|
|
return false;
|
2004-05-08 00:02:40 +04:00
|
|
|
}
|
|
|
|
|
2008-06-23 03:12:40 +04:00
|
|
|
nsBaseContentList* list = entry->GetNameContentList();
|
2013-03-18 13:47:32 +04:00
|
|
|
uint32_t length = list ? list->Length() : 0;
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
nsIContent* node;
|
2003-07-15 06:07:55 +04:00
|
|
|
if (length > 0) {
|
2016-12-09 20:02:50 +03:00
|
|
|
if (length > 1) {
|
|
|
|
// The list contains more than one element, return the whole list.
|
|
|
|
if (!ToJSValue(aCx, list, aRetval)) {
|
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
2003-07-15 06:07:55 +04:00
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
// Only one element in the list, return the element instead of returning
|
|
|
|
// the list.
|
|
|
|
node = list->Item(0);
|
|
|
|
} else {
|
|
|
|
// No named items were found, see if there's one registerd by id for aName.
|
|
|
|
Element* e = entry->GetIdElement();
|
2018-09-07 17:47:51 +03:00
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
if (!e || !nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) {
|
|
|
|
return false;
|
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
node = e;
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
if (!ToJSValue(aCx, node, aRetval)) {
|
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
return false;
|
2013-03-27 21:15:37 +04:00
|
|
|
}
|
|
|
|
|
2016-12-09 20:02:50 +03:00
|
|
|
return true;
|
2013-03-27 21:15:37 +04:00
|
|
|
}
|
|
|
|
|
2016-05-10 05:25:40 +03:00
|
|
|
void nsHTMLDocument::GetSupportedNames(nsTArray<nsString>& aNames) {
|
2015-07-16 05:22:46 +03:00
|
|
|
for (auto iter = mIdentifierMap.Iter(); !iter.Done(); iter.Next()) {
|
2019-01-08 13:15:55 +03:00
|
|
|
IdentifierMapEntry* entry = iter.Get();
|
2015-07-16 21:56:47 +03:00
|
|
|
if (entry->HasNameElement() ||
|
|
|
|
entry->HasIdElementExposedAsHTMLDocumentProperty()) {
|
2017-04-13 22:12:20 +03:00
|
|
|
aNames.AppendElement(entry->GetKeyAsString());
|
2015-07-16 05:22:46 +03:00
|
|
|
}
|
|
|
|
}
|
2013-03-27 21:15:37 +04:00
|
|
|
}
|
|
|
|
|
1998-08-28 19:55:31 +04:00
|
|
|
//----------------------------
|
1998-09-04 19:41:20 +04:00
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
// forms related stuff
|
|
|
|
|
2017-08-27 06:28:15 +03:00
|
|
|
bool nsHTMLDocument::MatchFormControls(Element* aElement, int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAtom, void* aData) {
|
2017-02-14 00:06:45 +03:00
|
|
|
return aElement->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
|
2006-06-08 08:28:20 +04:00
|
|
|
}
|
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult nsHTMLDocument::Clone(dom::NodeInfo* aNodeInfo,
|
|
|
|
nsINode** aResult) const {
|
2008-09-18 15:15:47 +04:00
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHTMLDocument> clone = new nsHTMLDocument();
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
2008-09-18 15:15:47 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// State from nsHTMLDocument
|
|
|
|
clone->mLoadFlags = mLoadFlags;
|
|
|
|
|
2018-09-27 17:59:55 +03:00
|
|
|
clone.forget(aResult);
|
|
|
|
return NS_OK;
|
2008-09-18 15:15:47 +04:00
|
|
|
}
|
2008-10-29 23:12:24 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
void nsHTMLDocument::DocAddSizeOfExcludingThis(
|
2017-08-10 07:13:22 +03:00
|
|
|
nsWindowSizes& aWindowSizes) const {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::DocAddSizeOfExcludingThis(aWindowSizes);
|
2012-02-02 01:58:01 +04:00
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mLinks
|
|
|
|
// - mAnchors
|
|
|
|
}
|
2013-01-18 18:27:03 +04:00
|
|
|
|
|
|
|
bool nsHTMLDocument::WillIgnoreCharsetOverride() {
|
2017-11-23 10:03:41 +03:00
|
|
|
if (mEncodingMenuDisabled) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-24 23:28:48 +04:00
|
|
|
if (mType != eHTML) {
|
|
|
|
MOZ_ASSERT(mType == eXHTML);
|
2013-01-18 18:27:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-09 14:29:30 +03:00
|
|
|
if (mCharacterSetSource >= kCharsetFromByteOrderMark) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
if (!mCharacterSet->IsAsciiCompatible() &&
|
|
|
|
mCharacterSet != ISO_2022_JP_ENCODING) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
nsIURI* uri = GetOriginalURI();
|
|
|
|
if (uri) {
|
2019-08-02 11:54:18 +03:00
|
|
|
if (uri->SchemeIs("about")) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool isResource;
|
|
|
|
nsresult rv = NS_URIChainHasFlags(
|
|
|
|
uri, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isResource);
|
|
|
|
if (NS_FAILED(rv) || isResource) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-14 21:56:58 +03:00
|
|
|
|
|
|
|
void nsHTMLDocument::GetFormsAndFormControls(nsContentList** aFormList,
|
|
|
|
nsContentList** aFormControlList) {
|
|
|
|
RefPtr<ContentListHolder> holder = mContentListHolder;
|
|
|
|
if (!holder) {
|
|
|
|
// Flush our content model so it'll be up to date
|
|
|
|
// If this becomes unnecessary and the following line is removed,
|
|
|
|
// please also remove the corresponding flush operation from
|
|
|
|
// nsHtml5TreeBuilderCppSupplement.h. (Look for "See bug 497861." there.)
|
|
|
|
// XXXsmaug nsHtml5TreeBuilderCppSupplement doesn't seem to have such flush
|
|
|
|
// anymore.
|
|
|
|
FlushPendingNotifications(FlushType::Content);
|
|
|
|
|
|
|
|
RefPtr<nsContentList> htmlForms = GetExistingForms();
|
|
|
|
if (!htmlForms) {
|
|
|
|
// If the document doesn't have an existing forms content list, create a
|
2018-03-13 04:44:56 +03:00
|
|
|
// new one which will be released soon by ContentListHolder. The idea is
|
|
|
|
// that we don't have that list hanging around for a long time and slowing
|
|
|
|
// down future DOM mutations.
|
|
|
|
//
|
2019-01-02 16:05:23 +03:00
|
|
|
// Please keep this in sync with Document::Forms().
|
2017-09-14 21:56:58 +03:00
|
|
|
htmlForms = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::form,
|
|
|
|
nsGkAtoms::form,
|
|
|
|
/* aDeep = */ true,
|
|
|
|
/* aLiveList = */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsContentList> htmlFormControls = new nsContentList(
|
|
|
|
this, nsHTMLDocument::MatchFormControls, nullptr, nullptr,
|
|
|
|
/* aDeep = */ true,
|
|
|
|
/* aMatchAtom = */ nullptr,
|
|
|
|
/* aMatchNameSpaceId = */ kNameSpaceID_None,
|
|
|
|
/* aFuncMayDependOnAttr = */ true,
|
|
|
|
/* aLiveList = */ true);
|
|
|
|
|
|
|
|
holder = new ContentListHolder(this, htmlForms, htmlFormControls);
|
|
|
|
RefPtr<ContentListHolder> runnable = holder;
|
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
Dispatch(TaskCategory::GarbageCollection, runnable.forget()))) {
|
|
|
|
mContentListHolder = holder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aFormList = holder->mFormList);
|
|
|
|
NS_ADDREF(*aFormControlList = holder->mFormControlList);
|
2017-10-30 18:45:09 +03:00
|
|
|
}
|