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
|
|
|
|
2014-09-21 20:36:25 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
2013-09-06 10:41:42 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/dom/HTMLAllCollection.h"
|
2018-11-14 17:55:02 +03:00
|
|
|
#include "mozilla/dom/FeaturePolicyUtils.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"
|
|
|
|
#include "nsIDocumentLoader.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"
|
2003-03-26 10:41:30 +03:00
|
|
|
#include "nsIPresShell.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"
|
2018-02-26 22:43:45 +03:00
|
|
|
#include "nsIURIMutator.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIPrivateBrowsingChannel.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"
|
2000-06-09 02:51:06 +04:00
|
|
|
#include "nsIWebNavigation.h"
|
1999-11-27 06:11:10 +03:00
|
|
|
#include "nsIBaseWindow.h"
|
2002-04-19 02:49:39 +04: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 20:46:42 +04:00
|
|
|
#include "nsIXPConnect.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"
|
1999-10-02 07:41:37 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2005-12-29 00:52:39 +03:00
|
|
|
#include "nsAttrName.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
|
2003-10-30 05:59:31 +03:00
|
|
|
#include "nsNetCID.h"
|
1999-08-20 02:23:20 +04:00
|
|
|
#include "nsICookieService.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
|
1998-09-17 04:55:35 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2000-04-28 18:05:45 +04:00
|
|
|
#include "nsIConsoleService.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.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"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsIFile.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"
|
2000-05-13 12:11:29 +04:00
|
|
|
#include "nsIDocumentEncoder.h" //for outputting selection
|
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-10 21:04:54 +04:00
|
|
|
#include "nsIScriptError.h"
|
2006-04-12 19:43:32 +04:00
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsArrayUtils.h"
|
2007-04-26 00:48:28 +04: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 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"
|
2017-08-07 08:43:50 +03:00
|
|
|
#include "mozilla/HTMLEditor.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"
|
2002-11-07 18:38:35 +03:00
|
|
|
#include "nsIEditingSession.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2010-12-06 22:27:14 +03:00
|
|
|
#include "nsIPlaintextEditor.h"
|
2007-06-28 06:48:16 +04:00
|
|
|
#include "nsIEditorStyleSheets.h"
|
|
|
|
#include "nsIInlineSpellChecker.h"
|
|
|
|
#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"
|
2012-03-27 10:27:45 +04:00
|
|
|
#include "nsHtml5Parser.h"
|
2012-08-20 22:34:32 +04:00
|
|
|
#include "nsSandboxFlags.h"
|
2012-12-12 06:45:36 +04:00
|
|
|
#include "nsIImageDocument.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"
|
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"
|
2013-03-20 00:30:53 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2015-04-21 09:27:10 +03:00
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.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 "nsIStructuredCloneContainer.h"
|
2015-06-16 04:34:48 +03:00
|
|
|
#include "nsLayoutStylesheetCache.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"
|
2018-07-10 14:04:21 +03:00
|
|
|
#include "nsCommandParams.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
|
|
|
|
2007-02-11 03:30:20 +03:00
|
|
|
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
|
|
|
|
|
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);
|
|
|
|
|
2008-01-14 12:26:22 +03: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 10:19:26 +04:00
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString& inCommandID,
|
2008-01-14 12:26:22 +03:00
|
|
|
const nsAString& inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam, bool& isBoolean,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& boolValue);
|
2008-01-14 12:26:22 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString& inCommandID,
|
2008-01-14 12:26:22 +03:00
|
|
|
nsACString& outCommandID);
|
2000-08-17 03:16:21 +04:00
|
|
|
|
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),
|
|
|
|
mWriteLevel(0),
|
|
|
|
mLoadFlags(0),
|
|
|
|
mTooDeepWriteRecursion(false),
|
|
|
|
mDisableDocWrite(false),
|
|
|
|
mWarnedWidthHeight(false),
|
|
|
|
mContentEditableCount(0),
|
|
|
|
mEditingState(EditingState::eOff),
|
|
|
|
mDisableCookieAccess(false),
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
mPendingMaybeEditingStateChanged(false),
|
2019-02-23 19:06:52 +03:00
|
|
|
mHasBeenEditable(false),
|
|
|
|
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
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, Document, mAll,
|
2019-02-28 04:09:48 +03:00
|
|
|
mMidasCommandManager)
|
2009-10-21 13:41:18 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, Document,
|
2018-01-26 09:03:25 +03:00
|
|
|
nsIHTMLDocument)
|
2008-02-21 23:39:20 +03: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,
|
|
|
|
nsIPrincipal* aPrincipal) {
|
2003-03-26 10:41:30 +03:00
|
|
|
mLoadFlags = nsIRequest::LOAD_NORMAL;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::ResetToURI(aURI, aLoadGroup, aPrincipal);
|
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 ||
|
|
|
|
kCharsetFromUserForced == parentSource) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
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-03-09 04:00:23 +03:00
|
|
|
// Using a prototype document is currently only allowed with browser.xhtml.
|
|
|
|
bool ShouldUsePrototypeDocument(nsIChannel* aChannel, nsIDocShell* aDocShell) {
|
|
|
|
if (!aChannel || !aDocShell ||
|
|
|
|
!StaticPrefs::dom_prototype_document_cache_enabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aDocShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
return IsChromeURI(originalURI) &&
|
|
|
|
originalURI->GetSpecOrDefault().EqualsLiteral(
|
|
|
|
BROWSER_CHROME_URL_QUOTED);
|
|
|
|
}
|
|
|
|
|
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) ||
|
|
|
|
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;
|
2012-03-31 18:10:34 +04:00
|
|
|
mCompatMode = eCompatibility_FullStandards;
|
|
|
|
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.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAbout = false;
|
2010-02-02 10:39:26 +03:00
|
|
|
if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
|
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
|
|
|
|
2005-04-19 05:27:11 +04:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
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;
|
2012-03-31 18:10:34 +04:00
|
|
|
if (loadAsHtml5) {
|
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
2019-02-23 19:06:52 +03:00
|
|
|
if (mIsPlainText) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if (viewSource) {
|
|
|
|
mParser->MarkAsNotScriptCreated("view-source-plain");
|
2011-11-01 19:27:36 +04:00
|
|
|
} else {
|
2012-03-31 18:10:34 +04:00
|
|
|
mParser->MarkAsNotScriptCreated("plain-text");
|
2011-11-01 19:27:36 +04:00
|
|
|
}
|
2012-03-31 18:10:34 +04:00
|
|
|
} else if (viewSource && !html) {
|
|
|
|
mParser->MarkAsNotScriptCreated("view-source-xml");
|
2009-06-29 02:44:22 +04:00
|
|
|
} else {
|
2012-03-31 18:10:34 +04:00
|
|
|
mParser->MarkAsNotScriptCreated(aCommand);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2019-03-09 04:00:23 +03:00
|
|
|
} else if (ShouldUsePrototypeDocument(aChannel, docShell)) {
|
|
|
|
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) {
|
|
|
|
docShell->GetSameTypeParent(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());
|
2014-12-17 22:14:04 +03: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 15:34:42 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
nsHtml5Module::Initialize(mParser, 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
|
|
|
|
2019-02-23 19:06:52 +03:00
|
|
|
if (mIsPlainText && !nsContentUtils::IsChildOfSameType(this) &&
|
2018-12-21 16:34:27 +03:00
|
|
|
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");
|
|
|
|
nsAutoString title;
|
|
|
|
if (bundle) {
|
|
|
|
bundle->GetStringFromName("plainText.wordWrap", title);
|
|
|
|
}
|
|
|
|
SetSelectedStyleSheetSet(title);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-03-12 13:29:46 +03: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();
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::BeginLoad();
|
2010-03-12 13:29:46 +03:00
|
|
|
}
|
|
|
|
|
1998-07-24 02:06:05 +04:00
|
|
|
void nsHTMLDocument::EndLoad() {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool turnOnEditing =
|
2007-06-28 06:48:16 +04:00
|
|
|
mParser && (HasFlag(NODE_IS_EDITABLE) || mContentEditableCount > 0);
|
2019-01-02 16:05:23 +03:00
|
|
|
// Note: Document::EndLoad nulls out mParser.
|
|
|
|
Document::EndLoad();
|
2007-06-28 06:48:16 +04:00
|
|
|
if (turnOnEditing) {
|
|
|
|
EditingStateChanged();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (!GetWindow()) {
|
|
|
|
// This is a document that's not in a window. For example, this could be an
|
|
|
|
// XMLHttpRequest responseXML document, or a document created via DOMParser
|
|
|
|
// or DOMImplementation. We don't reach this code normally for such
|
|
|
|
// documents (which is not obviously correct), but can reach it via
|
|
|
|
// document.open()/document.close().
|
|
|
|
//
|
|
|
|
// Such documents don't fire load events, but per spec should set their
|
|
|
|
// readyState to "complete" when parsing and all loading of subresources is
|
|
|
|
// done. Parsing is done now, and documents not in a window don't load
|
|
|
|
// subresources, so just go ahead and mark ourselves as complete.
|
|
|
|
SetReadyStateInternal(Document::READYSTATE_COMPLETE,
|
|
|
|
/* updateTimingInformation = */ false);
|
|
|
|
|
|
|
|
// Reset mSkipLoadEventAfterClose just in case.
|
|
|
|
mSkipLoadEventAfterClose = false;
|
|
|
|
}
|
1998-07-24 02:06:05 +04:00
|
|
|
}
|
1998-07-01 15:16:09 +04:00
|
|
|
|
2002-06-26 01:16:17 +04:00
|
|
|
void nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode) {
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(IsHTMLDocument() || aMode == eCompatibility_FullStandards,
|
2003-04-19 04:28:09 +04:00
|
|
|
"Bad compat mode for XHTML document!");
|
|
|
|
|
2018-04-26 17:07:30 +03:00
|
|
|
if (mCompatMode == aMode) {
|
|
|
|
return;
|
|
|
|
}
|
2002-06-26 01:16:17 +04:00
|
|
|
mCompatMode = aMode;
|
2005-04-19 05:27:11 +04:00
|
|
|
CSSLoader()->SetCompatibilityMode(mCompatMode);
|
2018-04-26 17:10:10 +03:00
|
|
|
if (nsPresContext* pc = GetPresContext()) {
|
2018-02-21 01:00:10 +03:00
|
|
|
pc->CompatibilityModeChanged();
|
1999-09-15 21:57:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-17 12:51:39 +04:00
|
|
|
already_AddRefed<nsIURI> nsHTMLDocument::GetDomainURI() {
|
|
|
|
nsIPrincipal* principal = NodePrincipal();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-03-17 12:51:39 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
principal->GetDomain(getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
|
|
|
return uri.forget();
|
2003-10-22 02:11:49 +04:00
|
|
|
}
|
2013-03-17 12:51:39 +04:00
|
|
|
|
|
|
|
principal->GetURI(getter_AddRefs(uri));
|
|
|
|
return uri.forget();
|
1999-10-02 07:41:37 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetDomain(nsAString& aDomain) {
|
2013-03-17 12:51:39 +04:00
|
|
|
nsCOMPtr<nsIURI> uri = GetDomainURI();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
|
|
|
if (!uri) {
|
2018-06-07 22:29:23 +03:00
|
|
|
aDomain.Truncate();
|
2018-01-26 09:00:04 +03:00
|
|
|
return;
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
1999-10-02 07:41:37 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostName;
|
2016-02-10 15:13:00 +03:00
|
|
|
nsresult rv = nsContentUtils::GetHostOrIPv6WithBrackets(uri, hostName);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-01-29 02:44:08 +03:00
|
|
|
CopyUTF8toUTF16(hostName, aDomain);
|
|
|
|
} else {
|
|
|
|
// If we can't get the host from the URI (e.g. about:, javascript:,
|
2018-06-07 22:29:23 +03:00
|
|
|
// etc), just return an empty string.
|
|
|
|
aDomain.Truncate();
|
2004-01-29 02:44:08 +03:00
|
|
|
}
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:37:34 +03:00
|
|
|
already_AddRefed<nsIURI> nsHTMLDocument::CreateInheritingURIForHost(
|
|
|
|
const nsACString& aHostString) {
|
|
|
|
if (aHostString.IsEmpty()) {
|
|
|
|
return nullptr;
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
2003-03-26 10:41:30 +03:00
|
|
|
|
1999-10-02 07:41:37 +04:00
|
|
|
// Create new URI
|
2013-03-17 12:51:39 +04:00
|
|
|
nsCOMPtr<nsIURI> uri = GetDomainURI();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (!uri) {
|
2017-03-07 19:37:34 +03:00
|
|
|
return nullptr;
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
|
|
|
|
2018-02-26 22:43:45 +03:00
|
|
|
nsresult rv;
|
|
|
|
rv = NS_MutateURI(uri)
|
|
|
|
.SetUserPass(EmptyCString())
|
|
|
|
.SetPort(-1) // we want to reset the port number if needed.
|
|
|
|
.SetHostPort(aHostString)
|
|
|
|
.Finalize(uri);
|
2017-03-07 19:37:34 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-26 22:43:45 +03:00
|
|
|
return uri.forget();
|
2017-03-07 19:37:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI> nsHTMLDocument::RegistrableDomainSuffixOfInternal(
|
|
|
|
const nsAString& aNewDomain, nsIURI* aOrigHost) {
|
|
|
|
if (NS_WARN_IF(!aOrigHost)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newURI =
|
|
|
|
CreateInheritingURIForHost(NS_ConvertUTF16toUTF8(aNewDomain));
|
|
|
|
if (!newURI) {
|
|
|
|
// Error: failed to parse input domain
|
|
|
|
return nullptr;
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
2007-12-31 02:35:42 +03:00
|
|
|
|
2007-11-12 10:58:16 +03: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.
|
2017-03-07 19:37:34 +03:00
|
|
|
nsAutoCString current;
|
|
|
|
nsAutoCString domain;
|
|
|
|
if (NS_FAILED(aOrigHost->GetAsciiHost(current))) {
|
2007-11-12 10:58:16 +03:00
|
|
|
current.Truncate();
|
2017-03-07 19:37:34 +03:00
|
|
|
}
|
|
|
|
if (NS_FAILED(newURI->GetAsciiHost(domain))) {
|
2017-03-20 23:19:01 +03:00
|
|
|
domain.Truncate();
|
2017-03-07 19:37:34 +03:00
|
|
|
}
|
2007-11-12 10:58:16 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ok = current.Equals(domain);
|
2007-11-12 10:58:16 +03:00
|
|
|
if (current.Length() > domain.Length() && StringEndsWith(current, domain) &&
|
|
|
|
current.CharAt(current.Length() - domain.Length() - 1) == '.') {
|
2008-02-07 23:58:56 +03:00
|
|
|
// We're golden if the new domain is the current page's base domain or a
|
|
|
|
// subdomain of it.
|
2007-11-12 10:58:16 +03:00
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!tldService) {
|
2017-03-07 19:37:34 +03:00
|
|
|
return nullptr;
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
2007-11-12 10:58:16 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString currentBaseDomain;
|
2017-03-07 19:37:34 +03:00
|
|
|
ok = NS_SUCCEEDED(
|
|
|
|
tldService->GetBaseDomain(aOrigHost, 0, currentBaseDomain));
|
2008-02-07 23:58:56 +03:00
|
|
|
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 10:58:16 +03:00
|
|
|
}
|
2017-03-07 19:37:34 +03:00
|
|
|
|
2007-11-12 10:58:16 +03:00
|
|
|
if (!ok) {
|
2017-03-07 19:37:34 +03:00
|
|
|
// Error: illegal domain
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CreateInheritingURIForHost(domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv) {
|
|
|
|
if (mSandboxFlags & SANDBOXED_DOMAIN) {
|
|
|
|
// We're sandboxed; disallow setting domain
|
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:55:02 +03:00
|
|
|
if (!FeaturePolicyUtils::IsFeatureAllowed(
|
|
|
|
this, NS_LITERAL_STRING("document-domain"))) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-07 19:37:34 +03:00
|
|
|
if (aDomain.IsEmpty()) {
|
2018-06-07 21:45:09 +03:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2017-03-07 19:37:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetDomainURI();
|
|
|
|
if (!uri) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newURI = RegistrableDomainSuffixOfInternal(aDomain, uri);
|
|
|
|
if (!newURI) {
|
2007-11-12 10:58:16 +03:00
|
|
|
// Error: illegal domain
|
2018-06-07 21:45:09 +03:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2007-11-12 10:58:16 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
rv = NodePrincipal()->SetDomain(newURI);
|
1999-10-02 07:41:37 +04:00
|
|
|
}
|
|
|
|
|
2015-01-22 04:57:29 +03: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-10 00:55:59 +03: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 04:57:29 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_NewChannel(getter_AddRefs(channel), aCodebaseURI, this,
|
2016-03-10 00:55:59 +03:00
|
|
|
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
|
2015-01-22 04:57:29 +03: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());
|
2018-06-12 22:39:19 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> docHTTPChannel = do_QueryInterface(GetChannel());
|
|
|
|
if (docHTTPChannel) {
|
|
|
|
bool isTracking = docHTTPChannel->GetIsTrackingResource();
|
|
|
|
if (isTracking) {
|
|
|
|
// If our document channel is from a tracking resource, we must
|
|
|
|
// override our channel's tracking status.
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
|
|
|
|
MOZ_ASSERT(httpChannel,
|
|
|
|
"How come we're coming from an HTTP doc but "
|
|
|
|
"we don't have an HTTP channel here?");
|
|
|
|
if (httpChannel) {
|
Bug 1482950 - Use the correct 3rdparty check in tracking annotations. r=dimi,Ehsan,mayhemer!,ehsan!
The mIsTrackingResource flag on nsIHttpChannel was split into two separate
flags depending on whether or not the resource is third-party. The correct
flag will be set by the channel classifier. Similarly, a new function was
introduced, GetIsThirdPartyTrackingResource(), for those consumers (like TP)
who only care about third-party trackers.
The existing function, GetIsTracking(), will continue to look at both
first-party and third-party trackers (the behavior since first party
tracking was added to annotations in bug 1476324).
The OverrideTrackingResource() function now allows nsHTMLDocument to
override both mIsFirstPartyTrackingResource and
mIsThirdPartyTrackingResource, but since this function is a little dangerous
and only has a single user, I added an assert to make future callers think
twice about using it to opt out of tracking annotations.
Currently, only the default storage restrictions need to look at first-party
trackers so every other consumer has been moved to
mIsThirdPartyTrackingResource or GetIsThirdPartyTrackingResource().
This effectively reverts the third-party checks added in bug 1476715 and
replaces them with the more complicated check that was added in bug 1108017.
It follows the approach that Ehsan initially suggested in bug 1476715. It
also reverts the changes in the expected values of the tracking annotation
test since these were, in hindsight, a warning about this regression.
Depends on D3722
Differential Revision: https://phabricator.services.mozilla.com/D3723
--HG--
extra : moz-landing-system : lando
2018-08-21 02:53:45 +03:00
|
|
|
httpChannel->OverrideTrackingFlagsForDocumentCookieAccessor(
|
|
|
|
docHTTPChannel);
|
2018-06-12 22:39:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-22 04:57:29 +03:00
|
|
|
return channel.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
void nsHTMLDocument::GetCookie(nsAString& aCookie, ErrorResult& rv) {
|
2002-04-12 14:11:00 +04:00
|
|
|
aCookie.Truncate(); // clear current cookie in case service fails;
|
|
|
|
// no cookie isn't an error condition.
|
|
|
|
|
2008-10-01 04:49:30 +04:00
|
|
|
if (mDisableCookieAccess) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2008-10-01 04:49:30 +04:00
|
|
|
}
|
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
// If the document's sandboxed origin flag is set, access to read cookies
|
|
|
|
// is prohibited.
|
|
|
|
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
2012-12-26 06:00:47 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2012-08-20 22:34:32 +04:00
|
|
|
}
|
2017-02-09 17:18:33 +03:00
|
|
|
|
2018-08-16 01:02:48 +03:00
|
|
|
if (nsContentUtils::StorageDisabledByAntiTracking(this, nullptr)) {
|
2018-06-20 20:38:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:22:31 +03:00
|
|
|
// If the document is a cookie-averse Document... return the empty string.
|
|
|
|
if (IsCookieAverse()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-05 01:44:51 +03:00
|
|
|
// not having a cookie service isn't an error
|
2006-06-19 01:18:22 +04:00
|
|
|
nsCOMPtr<nsICookieService> service =
|
|
|
|
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2003-03-26 10:41:30 +03: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-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2006-04-27 22:21:11 +04:00
|
|
|
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Document's principal is not a codebase (may be system), so
|
|
|
|
// can't set cookies
|
2002-07-02 21:58:24 +04:00
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2002-07-02 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
2015-01-22 04:57:29 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel(mChannel);
|
|
|
|
if (!channel) {
|
|
|
|
channel = CreateDummyChannelForCookies(codebaseURI);
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 06:58:35 +03:00
|
|
|
nsCString cookie;
|
2015-01-22 04:57:29 +03:00
|
|
|
service->GetCookieString(codebaseURI, channel, getter_Copies(cookie));
|
2012-09-05 05:01:57 +04:00
|
|
|
// CopyUTF8toUTF16 doesn't handle error
|
|
|
|
// because it assumes that the input is valid.
|
2017-06-16 15:11:03 +03:00
|
|
|
UTF_8_ENCODING->DecodeWithoutBOMHandling(cookie, aCookie);
|
1999-08-20 02:23:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
void nsHTMLDocument::SetCookie(const nsAString& aCookie, ErrorResult& rv) {
|
2008-10-01 04:49:30 +04:00
|
|
|
if (mDisableCookieAccess) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2008-10-01 04:49:30 +04:00
|
|
|
}
|
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
// If the document's sandboxed origin flag is set, access to write cookies
|
|
|
|
// is prohibited.
|
|
|
|
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
2012-12-26 06:00:47 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2012-08-20 22:34:32 +04:00
|
|
|
}
|
|
|
|
|
2018-08-16 01:02:48 +03:00
|
|
|
if (nsContentUtils::StorageDisabledByAntiTracking(this, nullptr)) {
|
2018-07-13 15:37:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:22:31 +03:00
|
|
|
// If the document is a cookie-averse Document... do nothing.
|
|
|
|
if (IsCookieAverse()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-05 01:44:51 +03:00
|
|
|
// not having a cookie service isn't an error
|
2006-06-19 01:18:22 +04:00
|
|
|
nsCOMPtr<nsICookieService> service =
|
|
|
|
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2004-01-10 02:54:21 +03:00
|
|
|
if (service && mDocumentURI) {
|
2011-08-03 22:32:32 +04:00
|
|
|
// The for getting the URI matches nsNavigator::GetCookieEnabled
|
2003-10-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2006-04-27 22:21:11 +04:00
|
|
|
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Document's principal is not a codebase (may be system), so
|
|
|
|
// can't set cookies
|
2002-07-02 21:58:24 +04:00
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2002-07-02 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
2015-01-22 04:57:29 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel(mChannel);
|
|
|
|
if (!channel) {
|
|
|
|
channel = CreateDummyChannelForCookies(codebaseURI);
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 05:01:57 +04:00
|
|
|
NS_ConvertUTF16toUTF8 cookie(aCookie);
|
2015-01-22 04:57:29 +03:00
|
|
|
service->SetCookieString(codebaseURI, nullptr, cookie.get(), channel);
|
1999-08-20 02:23:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2019-01-02 16:26:56 +03:00
|
|
|
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> nsHTMLDocument::Open(
|
2019-02-27 08:12:13 +03:00
|
|
|
const nsAString& aURL, const nsAString& aName, const nsAString& aFeatures,
|
|
|
|
bool aReplace, ErrorResult& rv) {
|
2018-05-30 05:58:49 +03:00
|
|
|
MOZ_ASSERT(nsContentUtils::CanCallerAccess(this),
|
2018-01-26 09:03:25 +03:00
|
|
|
"XOW should have caught this!");
|
2011-06-04 10:57:23 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = GetInnerWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2011-06-04 10:57:23 +04:00
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> outer =
|
|
|
|
nsPIDOMWindowOuter::GetFromCurrentInner(window);
|
|
|
|
if (!outer) {
|
2015-07-17 08:10:35 +03:00
|
|
|
rv.Throw(NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-11-04 01:25:38 +03:00
|
|
|
RefPtr<nsGlobalWindowOuter> win = nsGlobalWindowOuter::Cast(outer);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> newWindow;
|
2012-12-26 06:00:47 +04:00
|
|
|
// XXXbz We ignore aReplace for now.
|
|
|
|
rv = win->OpenJS(aURL, aName, aFeatures, getter_AddRefs(newWindow));
|
2019-01-02 16:26:56 +03:00
|
|
|
if (!newWindow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-01-02 16:27:05 +03:00
|
|
|
return WindowProxyHolder(newWindow->GetBrowsingContext());
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
2011-06-04 10:57:23 +04:00
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
Document* nsHTMLDocument::Open(const Optional<nsAString>& /* unused */,
|
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
|
|
|
const nsAString& /* unused */,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
// Implements
|
|
|
|
// <https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document-open-steps>
|
2015-09-23 13:12:24 +03:00
|
|
|
|
2018-05-30 05:58:49 +03:00
|
|
|
MOZ_ASSERT(nsContentUtils::CanCallerAccess(this),
|
2018-01-26 09:03:25 +03:00
|
|
|
"XOW should have caught this!");
|
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
|
|
|
|
|
|
|
// Step 1 -- throw if we're an XML document.
|
2017-06-12 17:36:02 +03:00
|
|
|
if (!IsHTMLDocument() || mDisableDocWrite) {
|
2017-09-13 20:34:58 +03:00
|
|
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2012-12-26 06:00:47 +04:00
|
|
|
return nullptr;
|
2006-05-04 01:19:26 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 2 -- throw if dynamic markup insertion should throw.
|
2017-10-26 09:08:35 +03:00
|
|
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 3 -- get the entry document, so we can use it for security checks.
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> callerDoc = GetEntryDocument();
|
2008-12-12 00:00:37 +03: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-26 00:49:11 +03:00
|
|
|
// refuse to go ahead with this call.
|
|
|
|
|
2017-09-13 20:34:58 +03:00
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2012-12-26 06:00:47 +04:00
|
|
|
return nullptr;
|
2008-01-26 00:49:11 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 4 -- make sure we're same-origin (not just same origin-domain) with
|
|
|
|
// the entry document.
|
|
|
|
if (!callerDoc->NodePrincipal()->Equals(NodePrincipal())) {
|
2017-09-13 20:34:58 +03:00
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2012-12-26 06:00:47 +04:00
|
|
|
return nullptr;
|
2008-01-26 00:49:11 +03:00
|
|
|
}
|
2005-09-02 22:02:51 +04:00
|
|
|
|
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
|
|
|
// Step 5 -- if we have an active parser, just no-op.
|
|
|
|
// If we already have a parser we ignore the document.open call.
|
|
|
|
if (mParser || mParserAborted) {
|
|
|
|
// The WHATWG spec used to say: "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.
|
|
|
|
//
|
|
|
|
// Actually, the spec says something slightly different now, about having
|
|
|
|
// an "active parser whose script nesting level is greater than 0". It
|
|
|
|
// does not mention insertion points at all. Not sure whether it matters
|
|
|
|
// in practice. It seems like "script nesting level" replaced the
|
|
|
|
// insertion point concept? Anyway,
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1475000 is probably
|
|
|
|
// relevant here.
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 6 -- check for open() during unload. Per spec, this is just a check
|
|
|
|
// of the ignore-opens-during-unload counter, but our unload event code
|
|
|
|
// doesn't affect that counter yet (unlike pagehide and beforeunload, which
|
|
|
|
// do), so we check for unload directly.
|
|
|
|
if (ShouldIgnoreOpens()) {
|
|
|
|
return this;
|
2018-07-04 00:48:53 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
nsCOMPtr<nsIDocShell> shell(mDocumentContainer);
|
|
|
|
if (shell) {
|
|
|
|
bool inUnload;
|
|
|
|
shell->GetIsInUnload(&inUnload);
|
|
|
|
if (inUnload) {
|
|
|
|
return this;
|
2004-02-11 09:09:51 +03:00
|
|
|
}
|
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
|
|
|
}
|
2004-02-11 09:09:51 +03:00
|
|
|
|
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
|
|
|
// At this point we know this is a valid-enough document.open() call
|
|
|
|
// and not a no-op. Increment our use counter.
|
|
|
|
SetDocumentAndPageUseCounter(eUseCounter_custom_DocumentOpen);
|
|
|
|
|
|
|
|
// Step 7 -- stop existing navigation of our browsing context (and all other
|
|
|
|
// loads it's doing) if we're the active document of our browsing context.
|
|
|
|
// Note that we do not want to stop anything if there is no existing
|
|
|
|
// navigation.
|
|
|
|
if (shell && IsCurrentActiveDocument() &&
|
|
|
|
shell->GetIsAttemptingToNavigate()) {
|
2008-07-09 17:48:02 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(shell));
|
2003-09-20 00:00:24 +04:00
|
|
|
webnav->Stop(nsIWebNavigation::STOP_NETWORK);
|
2010-01-18 12:07:08 +03:00
|
|
|
|
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
|
|
|
// 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.
|
2010-01-18 12:07:08 +03:00
|
|
|
EnsureOnloadBlocker();
|
2000-06-09 02:51:06 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 8 -- clear event listeners out of our DOM tree
|
|
|
|
for (nsINode* node : ShadowIncludingTreeIterator(*this)) {
|
|
|
|
if (EventListenerManager* elm = node->GetExistingListenerManager()) {
|
|
|
|
elm->RemoveAllListeners();
|
|
|
|
}
|
2018-06-07 15:01:25 +03:00
|
|
|
}
|
2018-09-07 17:47:51 +03:00
|
|
|
|
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
|
|
|
// Step 9 -- clear event listeners from our window, if we have one.
|
|
|
|
//
|
|
|
|
// Note that we explicitly want the inner window, and only if we're its
|
|
|
|
// document. We want to do this (per spec) even when we're not the "active
|
|
|
|
// document", so we can't go through GetWindow(), because it might forward to
|
|
|
|
// the wrong inner.
|
|
|
|
if (nsPIDOMWindowInner* win = GetInnerWindow()) {
|
|
|
|
if (win->GetExtantDoc() == this) {
|
|
|
|
if (EventListenerManager* elm =
|
|
|
|
nsGlobalWindowInner::Cast(win)->GetExistingListenerManager()) {
|
|
|
|
elm->RemoveAllListeners();
|
2018-06-07 15:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 10 -- remove all our DOM kids without firing any mutation events.
|
|
|
|
DisconnectNodeTree();
|
2012-01-30 21:03:52 +04:00
|
|
|
|
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
|
|
|
// Step 11 -- if we're the current document in our docshell, do the
|
|
|
|
// equivalent of pushState() with the new URL we should have.
|
|
|
|
if (shell && IsCurrentActiveDocument()) {
|
|
|
|
nsCOMPtr<nsIURI> newURI = callerDoc->GetDocumentURI();
|
|
|
|
if (callerDoc != this) {
|
|
|
|
nsCOMPtr<nsIURI> noFragmentURI;
|
|
|
|
nsresult rv = NS_GetURIWithoutRef(newURI, getter_AddRefs(noFragmentURI));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
newURI = noFragmentURI.forget();
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
2012-01-30 21:03:52 +04:00
|
|
|
|
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
|
|
|
// UpdateURLAndHistory might do various member-setting, so make sure we're
|
|
|
|
// holding strong refs to all the refcounted args on the stack. We can
|
|
|
|
// assume that our caller is holding on to "this" already.
|
|
|
|
nsCOMPtr<nsIURI> currentURI = GetDocumentURI();
|
|
|
|
bool equalURIs;
|
|
|
|
nsresult rv = currentURI->Equals(newURI, &equalURIs);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aError.Throw(rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
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
|
|
|
nsCOMPtr<nsIStructuredCloneContainer> stateContainer(mStateObjectContainer);
|
|
|
|
rv = shell->UpdateURLAndHistory(this, newURI, stateContainer, EmptyString(),
|
|
|
|
/* aReplace = */ true, currentURI,
|
|
|
|
equalURIs);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aError.Throw(rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
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
|
|
|
// And use the security info of the caller document as well, since
|
|
|
|
// it's the thing providing our data.
|
|
|
|
mSecurityInfo = callerDoc->GetSecurityInfo();
|
2009-07-25 15:27:42 +04:00
|
|
|
|
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
|
|
|
// This is not mentioned in the spec, but I think that's a spec bug. See
|
|
|
|
// <https://github.com/whatwg/html/issues/4299>. In any case, since our
|
|
|
|
// URL may be changing away from about:blank here, we really want to unset
|
|
|
|
// this flag no matter what, since only about:blank can be an initial
|
|
|
|
// document.
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsInitialDocument(false);
|
2006-08-15 21:31:16 +04:00
|
|
|
|
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
|
|
|
// And let our docloader know that it will need to track our load event.
|
|
|
|
nsDocShell::Cast(shell)->SetDocumentOpenedButNotLoaded();
|
2000-09-19 09:11:59 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Per spec nothing happens with our URI in other cases, though note
|
|
|
|
// <https://github.com/whatwg/html/issues/4286>.
|
2013-08-16 01:39:28 +04:00
|
|
|
|
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
|
|
|
// Note that we don't need to do anything here with base URIs per spec.
|
|
|
|
// That said, this might be assuming that we implement
|
|
|
|
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fallback-base-url
|
|
|
|
// correctly, which we don't right now for the about:blank case.
|
2018-03-29 01:01:46 +03:00
|
|
|
|
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
|
|
|
// Step 12, but note <https://github.com/whatwg/html/issues/4292>.
|
|
|
|
mSkipLoadEventAfterClose = mLoadEventFiring;
|
|
|
|
|
|
|
|
// Preliminary to steps 13-16. Set our ready state to uninitialized before
|
|
|
|
// we do anything else, so we can then proceed to later ready state levels.
|
|
|
|
SetReadyStateInternal(READYSTATE_UNINITIALIZED,
|
|
|
|
/* updateTimingInformation = */ false);
|
2001-03-22 11:51:52 +03:00
|
|
|
|
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
|
|
|
// Step 13 -- set our compat mode to standards.
|
|
|
|
SetCompatibilityMode(eCompatibility_FullStandards);
|
2004-07-28 04:26:58 +04:00
|
|
|
|
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
|
|
|
// Step 14 -- create a new parser associated with document. This also does
|
|
|
|
// step 16 implicitly.
|
2012-03-28 09:17:53 +04:00
|
|
|
mParserAborted = false;
|
2012-03-31 18:10:34 +04:00
|
|
|
mParser = nsHtml5Module::NewHtml5Parser();
|
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
|
|
|
nsHtml5Module::Initialize(mParser, this, GetDocumentURI(), shell, nullptr);
|
2014-12-17 22:14:04 +03: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 10:41:30 +03:00
|
|
|
|
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
|
|
|
// Some internal non-spec bookkeeping.
|
2018-03-29 01:01:46 +03:00
|
|
|
mContentTypeForWriteCalls.AssignLiteral("text/html");
|
2004-05-22 01:32:11 +04:00
|
|
|
|
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
|
|
|
if (shell) {
|
|
|
|
// Prepare the docshell and the document viewer for the impending
|
|
|
|
// out-of-band document.write()
|
|
|
|
shell->PrepareForNewContentModel();
|
2004-04-28 05:40:39 +04:00
|
|
|
|
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
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
shell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
|
|
|
cv->LoadStart(this);
|
|
|
|
}
|
2001-05-25 12:49:03 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Step 15.
|
|
|
|
SetReadyStateInternal(Document::READYSTATE_LOADING,
|
|
|
|
/* updateTimingInformation = */ false);
|
2005-04-06 06:22:45 +04:00
|
|
|
|
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
|
|
|
// Step 16 happened with step 14 above.
|
2012-04-17 10:41:49 +04:00
|
|
|
|
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
|
|
|
// Step 17.
|
|
|
|
return this;
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
void nsHTMLDocument::Close(ErrorResult& rv) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!IsHTMLDocument()) {
|
2006-05-04 01:19:26 +04:00
|
|
|
// No calling document.close() on XHTML!
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
2006-05-04 01:19:26 +04:00
|
|
|
}
|
|
|
|
|
2017-10-26 09:08:35 +03:00
|
|
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:16:26 +04:00
|
|
|
if (!mParser || !mParser->IsScriptCreated()) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
1999-02-03 22:38:16 +03:00
|
|
|
}
|
|
|
|
|
2012-01-20 15:16:26 +04:00
|
|
|
++mWriteLevel;
|
2012-12-26 06:00:47 +04:00
|
|
|
rv = (static_cast<nsHtml5Parser*>(mParser.get()))
|
2018-03-29 01:01:46 +03:00
|
|
|
->Parse(EmptyString(), nullptr, mContentTypeForWriteCalls, true);
|
2012-01-20 15:16:26 +04:00
|
|
|
--mWriteLevel;
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
// Even if that Parse() call failed, do the rest of this method
|
|
|
|
|
2012-01-20 15:16:26 +04: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()) {
|
2017-01-05 10:31:56 +03:00
|
|
|
FlushPendingNotifications(FlushType::Layout);
|
2012-01-20 15:16:26 +04:00
|
|
|
}
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
void nsHTMLDocument::WriteCommon(const Sequence<nsString>& aText,
|
2012-12-26 06:00:47 +04:00
|
|
|
bool aNewlineTerminate,
|
|
|
|
mozilla::ErrorResult& rv) {
|
|
|
|
// Fast path the common case
|
|
|
|
if (aText.Length() == 1) {
|
2019-02-27 08:12:13 +03:00
|
|
|
WriteCommon(aText[0], aNewlineTerminate, rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
} 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]);
|
|
|
|
}
|
2019-02-27 08:12:13 +03:00
|
|
|
WriteCommon(text, aNewlineTerminate, rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
void nsHTMLDocument::WriteCommon(const nsAString& aText, bool aNewlineTerminate,
|
|
|
|
ErrorResult& aRv) {
|
2007-02-11 03:30:20 +03:00
|
|
|
mTooDeepWriteRecursion =
|
|
|
|
(mWriteLevel > NS_MAX_DOCUMENT_WRITE_DEPTH || mTooDeepWriteRecursion);
|
2018-01-26 09:00:41 +03:00
|
|
|
if (NS_WARN_IF(mTooDeepWriteRecursion)) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-11 03:30:20 +03:00
|
|
|
|
2017-06-12 17:36:02 +03:00
|
|
|
if (!IsHTMLDocument() || mDisableDocWrite) {
|
2006-05-04 01:19:26 +04:00
|
|
|
// No calling document.write*() on XHTML!
|
|
|
|
|
2018-01-26 09:00:41 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
2006-05-04 01:19:26 +04:00
|
|
|
}
|
|
|
|
|
2017-10-26 09:08:35 +03:00
|
|
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
2018-01-26 09:00:41 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
2017-10-26 09:08:35 +03:00
|
|
|
}
|
|
|
|
|
2012-03-28 09:17:53 +04: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.
|
2018-01-26 09:00:41 +03:00
|
|
|
return;
|
2012-03-28 09:17:53 +04:00
|
|
|
}
|
|
|
|
|
2017-11-02 21:47:21 +03:00
|
|
|
// Implement Step 4.1 of:
|
|
|
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document-write-steps
|
|
|
|
if (ShouldIgnoreOpens()) {
|
2018-01-26 09:00:41 +03:00
|
|
|
return;
|
2017-11-02 21:47:21 +03:00
|
|
|
}
|
|
|
|
|
2006-01-24 04:25:14 +03:00
|
|
|
void* key = GenerateParserKey();
|
2012-01-20 15:16:26 +04:00
|
|
|
if (mParser && !mParser->IsInsertionPointDefined()) {
|
2017-10-30 18:45:09 +03:00
|
|
|
if (mIgnoreDestructiveWritesCounter) {
|
2010-06-19 10:38:41 +04:00
|
|
|
// Instead of implying a call to document.open(), ignore the call.
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::ReportToConsole(
|
2013-08-21 23:28:26 +04:00
|
|
|
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM Events"), this,
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::eDOM_PROPERTIES, "DocumentWriteIgnored", nullptr, 0,
|
|
|
|
mDocumentURI);
|
2018-01-26 09:00:41 +03:00
|
|
|
return;
|
2010-06-19 10:38:41 +04:00
|
|
|
}
|
2017-11-12 21:12:31 +03:00
|
|
|
// The spec doesn't tell us to ignore opens from here, but we need to
|
|
|
|
// ensure opens are ignored here.
|
|
|
|
IgnoreOpensDuringUnload ignoreOpenGuard(this);
|
2006-01-24 04:25:14 +03:00
|
|
|
mParser->Terminate();
|
2017-11-12 21:12:31 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mParser, "mParser should have been null'd out");
|
2006-01-24 04:25:14 +03:00
|
|
|
}
|
|
|
|
|
2001-05-13 04:27:58 +04:00
|
|
|
if (!mParser) {
|
2017-10-30 18:45:09 +03:00
|
|
|
if (mIgnoreDestructiveWritesCounter) {
|
2010-06-19 10:38:41 +04:00
|
|
|
// Instead of implying a call to document.open(), ignore the call.
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::ReportToConsole(
|
2013-08-21 23:28:26 +04:00
|
|
|
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM Events"), this,
|
2011-12-15 18:47:03 +04:00
|
|
|
nsContentUtils::eDOM_PROPERTIES, "DocumentWriteIgnored", nullptr, 0,
|
|
|
|
mDocumentURI);
|
2018-01-26 09:00:41 +03:00
|
|
|
return;
|
2010-06-19 10:38:41 +04:00
|
|
|
}
|
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
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
Open(Optional<nsAString>(), EmptyString(), aRv);
|
2004-02-11 09:09:51 +03: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.
|
2018-01-26 09:00:41 +03:00
|
|
|
if (aRv.Failed() || !mParser) {
|
|
|
|
return;
|
2001-05-13 04:27:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 22:36:45 +03:00
|
|
|
static NS_NAMED_LITERAL_STRING(new_line, "\n");
|
|
|
|
|
2004-05-12 02:37:31 +04: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) {
|
2018-01-26 09:00:41 +03:00
|
|
|
aRv = (static_cast<nsHtml5Parser*>(mParser.get()))
|
2018-03-29 01:01:46 +03:00
|
|
|
->Parse(aText + new_line, key, mContentTypeForWriteCalls, false);
|
2004-05-12 02:37:31 +04:00
|
|
|
} else {
|
2018-01-26 09:00:41 +03:00
|
|
|
aRv = (static_cast<nsHtml5Parser*>(mParser.get()))
|
2018-03-29 01:01:46 +03:00
|
|
|
->Parse(aText, key, mContentTypeForWriteCalls, false);
|
2004-05-12 02:37:31 +04:00
|
|
|
}
|
2002-01-31 22:36:45 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
--mWriteLevel;
|
2001-05-13 04:27:58 +04:00
|
|
|
|
2007-02-11 03:30:20 +03:00
|
|
|
mTooDeepWriteRecursion = (mWriteLevel != 0 && mTooDeepWriteRecursion);
|
2001-05-13 04:27:58 +04:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
void nsHTMLDocument::Write(const Sequence<nsString>& aText, ErrorResult& rv) {
|
|
|
|
WriteCommon(aText, false, rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:12:13 +03:00
|
|
|
void nsHTMLDocument::Writeln(const Sequence<nsString>& aText, ErrorResult& rv) {
|
|
|
|
WriteCommon(aText, true, rv);
|
2012-12-26 06:00:47 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetAlinkColor(nsAString& aAlinkColor) {
|
1999-07-07 08:52:27 +04:00
|
|
|
aAlinkColor.Truncate();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->GetALink(aAlinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-07-23 03:32:19 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::SetAlinkColor(const nsAString& aAlinkColor) {
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->SetALink(aAlinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetLinkColor(nsAString& aLinkColor) {
|
1999-07-07 08:52:27 +04:00
|
|
|
aLinkColor.Truncate();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->GetLink(aLinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::SetLinkColor(const nsAString& aLinkColor) {
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->SetLink(aLinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetVlinkColor(nsAString& aVlinkColor) {
|
1999-07-07 08:52:27 +04:00
|
|
|
aVlinkColor.Truncate();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->GetVLink(aVlinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::SetVlinkColor(const nsAString& aVlinkColor) {
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->SetVLink(aVlinkColor);
|
1999-07-07 08:52:27 +04:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetBgColor(nsAString& aBgColor) {
|
1999-07-07 08:52:27 +04:00
|
|
|
aBgColor.Truncate();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->GetBgColor(aBgColor);
|
1999-02-04 05:58:02 +03:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::SetBgColor(const nsAString& aBgColor) {
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->SetBgColor(aBgColor);
|
1999-02-04 05:58:02 +03:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::GetFgColor(nsAString& aFgColor) {
|
1999-07-07 08:52:27 +04:00
|
|
|
aFgColor.Truncate();
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->GetText(aFgColor);
|
1999-02-04 05:58:02 +03:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 02:13:20 +03:00
|
|
|
void nsHTMLDocument::SetFgColor(const nsAString& aFgColor) {
|
2013-01-13 01:53:01 +04:00
|
|
|
HTMLBodyElement* body = GetBodyElement();
|
2003-03-26 10:41:30 +03:00
|
|
|
if (body) {
|
|
|
|
body->SetText(aFgColor);
|
1999-02-04 05:58:02 +03:00
|
|
|
}
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-09 12:04:39 +04:00
|
|
|
void nsHTMLDocument::CaptureEvents() {
|
2019-01-02 16:05:23 +03:00
|
|
|
WarnOnceAbout(Document::eUseOfCaptureEvents);
|
2013-08-01 01:44:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-09 12:04:39 +04:00
|
|
|
void nsHTMLDocument::ReleaseEvents() {
|
2019-01-02 16:05:23 +03:00
|
|
|
WarnOnceAbout(Document::eUseOfReleaseEvents);
|
2013-08-01 01:44: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
|
|
|
}
|
|
|
|
|
2005-06-07 23:21:05 +04:00
|
|
|
void* nsHTMLDocument::GenerateParserKey(void) {
|
2005-09-23 03:01:33 +04: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 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-09-23 03:01:33 +04:00
|
|
|
}
|
|
|
|
|
2005-06-07 23:21:05 +04:00
|
|
|
// The script loader provides us with the currently executing script element,
|
|
|
|
// which is guaranteed to be unique per script.
|
2012-03-31 18:10:34 +04: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 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-15 15:29:11 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-31 18:10:34 +04:00
|
|
|
return script;
|
2005-06-07 23:21:05 +04:00
|
|
|
}
|
|
|
|
|
2016-10-03 11:34:14 +03:00
|
|
|
void nsHTMLDocument::GetDesignMode(nsAString& aDesignMode) {
|
2007-06-28 06:48:16 +04:00
|
|
|
if (HasFlag(NODE_IS_EDITABLE)) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aDesignMode.AssignLiteral("on");
|
2002-11-07 18:38:35 +03:00
|
|
|
} else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aDesignMode.AssignLiteral("off");
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-31 15:53:01 +03:00
|
|
|
void nsHTMLDocument::MaybeEditingStateChanged() {
|
2017-03-15 07:22:06 +03:00
|
|
|
if (!mPendingMaybeEditingStateChanged && mMayStartLayout &&
|
2013-03-23 03:08:59 +04:00
|
|
|
mUpdateNestLevel == 0 && (mContentEditableCount > 0) != IsEditingOn()) {
|
2009-01-31 15:53:01 +03:00
|
|
|
if (nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
EditingStateChanged();
|
|
|
|
} else if (!mInDestructor) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
2017-06-12 22:34:10 +03:00
|
|
|
NewRunnableMethod("nsHTMLDocument::MaybeEditingStateChanged", this,
|
|
|
|
&nsHTMLDocument::MaybeEditingStateChanged));
|
2009-01-31 15:53:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 16:56:38 +03:00
|
|
|
void nsHTMLDocument::EndUpdate() {
|
2013-03-23 03:08:59 +04:00
|
|
|
const bool reset = !mPendingMaybeEditingStateChanged;
|
|
|
|
mPendingMaybeEditingStateChanged = true;
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::EndUpdate();
|
2013-03-23 03:08:59 +04:00
|
|
|
if (reset) {
|
|
|
|
mPendingMaybeEditingStateChanged = false;
|
|
|
|
}
|
2009-01-31 15:53:01 +03:00
|
|
|
MaybeEditingStateChanged();
|
2007-10-26 14:30:44 +04:00
|
|
|
}
|
|
|
|
|
2017-03-15 07:22:06 +03:00
|
|
|
void nsHTMLDocument::SetMayStartLayout(bool aMayStartLayout) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::SetMayStartLayout(aMayStartLayout);
|
2017-03-15 07:22:06 +03:00
|
|
|
|
|
|
|
MaybeEditingStateChanged();
|
|
|
|
}
|
|
|
|
|
2010-07-19 02:07:53 +04:00
|
|
|
// Helper class, used below in ChangeContentEditableCount().
|
2016-04-26 03:23:21 +03:00
|
|
|
class DeferredContentEditableCountChangeEvent : public Runnable {
|
2010-07-19 02:07:53 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
DeferredContentEditableCountChangeEvent(nsHTMLDocument* aDoc,
|
|
|
|
nsIContent* aElement)
|
|
|
|
: mozilla::Runnable("DeferredContentEditableCountChangeEvent"),
|
|
|
|
mDoc(aDoc),
|
2010-07-19 02:07:53 +04:00
|
|
|
mElement(aElement) {}
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2011-10-18 14:53:36 +04:00
|
|
|
if (mElement && mElement->OwnerDoc() == mDoc) {
|
2010-07-19 02:07:53 +04:00
|
|
|
mDoc->DeferredContentEditableCountChange(mElement);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHTMLDocument> mDoc;
|
2010-07-19 02:07:53 +04:00
|
|
|
nsCOMPtr<nsIContent> mElement;
|
|
|
|
};
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
nsresult nsHTMLDocument::ChangeContentEditableCount(nsIContent* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aChange) {
|
|
|
|
NS_ASSERTION(int32_t(mContentEditableCount) + aChange >= 0,
|
2007-06-28 06:48:16 +04:00
|
|
|
"Trying to decrement too much.");
|
|
|
|
|
|
|
|
mContentEditableCount += aChange;
|
|
|
|
|
2010-05-13 02:21:24 +04:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new DeferredContentEditableCountChangeEvent(this, aElement));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLDocument::DeferredContentEditableCountChange(nsIContent* aElement) {
|
2007-10-26 14:30:44 +04:00
|
|
|
if (mParser ||
|
2010-02-07 00:33:53 +03:00
|
|
|
(mUpdateNestLevel > 0 && (mContentEditableCount > 0) != IsEditingOn())) {
|
2010-05-13 02:21:24 +04:00
|
|
|
return;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditingState oldState = mEditingState;
|
|
|
|
|
|
|
|
nsresult rv = EditingStateChanged();
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2007-06-28 06:48:16 +04: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.
|
2018-03-27 07:35:21 +03:00
|
|
|
if (aElement) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!window) return;
|
|
|
|
|
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
|
|
|
if (!docshell) return;
|
|
|
|
|
2017-08-07 08:43:50 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = docshell->GetHTMLEditor();
|
|
|
|
if (htmlEditor) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> range = new nsRange(aElement);
|
2018-03-27 07:35:21 +03:00
|
|
|
IgnoredErrorResult res;
|
|
|
|
range->SelectNode(*aElement, res);
|
|
|
|
if (res.Failed()) {
|
2011-07-15 01:06:37 +04:00
|
|
|
// 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 06:48:16 +04:00
|
|
|
|
2007-07-18 13:46:41 +04:00
|
|
|
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
|
2017-08-07 08:43:50 +03:00
|
|
|
rv = htmlEditor->GetInlineSpellChecker(false,
|
|
|
|
getter_AddRefs(spellChecker));
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2007-07-18 13:46:41 +04:00
|
|
|
|
|
|
|
if (spellChecker) {
|
|
|
|
rv = spellChecker->SpellCheckRange(range);
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 12:02:45 +04:00
|
|
|
HTMLAllCollection* nsHTMLDocument::All() {
|
2013-06-12 10:55:00 +04:00
|
|
|
if (!mAll) {
|
2013-09-06 10:41:42 +04:00
|
|
|
mAll = new HTMLAllCollection(this);
|
2013-06-12 10:55:00 +04:00
|
|
|
}
|
2014-02-09 12:02:45 +04:00
|
|
|
return mAll;
|
|
|
|
}
|
2013-06-12 10:55:00 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
static void NotifyEditableStateChange(nsINode* aNode, Document* aDocument) {
|
2011-09-27 11:54:58 +04:00
|
|
|
for (nsIContent* child = aNode->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-10-20 20:27:48 +04:00
|
|
|
if (child->IsElement()) {
|
2011-06-01 05:46:57 +04:00
|
|
|
child->AsElement()->UpdateState(true);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2011-10-20 20:27:48 +04:00
|
|
|
NotifyEditableStateChange(child, aDocument);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:25:52 +03:00
|
|
|
void nsHTMLDocument::TearingDownEditor() {
|
2008-02-20 12:54:52 +03:00
|
|
|
if (IsEditingOn()) {
|
2009-02-12 07:15:59 +03:00
|
|
|
EditingState oldState = mEditingState;
|
2008-02-20 12:54:52 +03:00
|
|
|
mEditingState = eTearingDown;
|
|
|
|
|
2010-10-29 20:30:15 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetShell();
|
|
|
|
if (!presShell) return;
|
|
|
|
|
2018-04-30 20:23:14 +03:00
|
|
|
nsTArray<RefPtr<StyleSheet>> agentSheets;
|
2010-10-29 20:30:15 +04:00
|
|
|
presShell->GetAgentStyleSheets(agentSheets);
|
|
|
|
|
2018-03-28 18:34:34 +03:00
|
|
|
auto cache = nsLayoutStylesheetCache::Singleton();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
|
|
|
agentSheets.RemoveElement(cache->ContentEditableSheet());
|
2010-10-29 20:30:15 +04:00
|
|
|
if (oldState == eDesignMode)
|
2016-02-24 10:01:12 +03:00
|
|
|
agentSheets.RemoveElement(cache->DesignModeSheet());
|
2010-10-29 20:30:15 +04:00
|
|
|
|
|
|
|
presShell->SetAgentStyleSheets(agentSheets);
|
|
|
|
|
2018-05-11 19:37:47 +03:00
|
|
|
presShell->ApplicableStylesChanged();
|
2008-02-20 12:54:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
nsresult nsHTMLDocument::TurnEditingOff() {
|
|
|
|
NS_ASSERTION(mEditingState != eOff, "Editing is already off.");
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2002-11-07 18:38:35 +03:00
|
|
|
if (!window) return NS_ERROR_FAILURE;
|
|
|
|
|
2007-06-28 02:29:45 +04:00
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
|
|
|
if (!docshell) return NS_ERROR_FAILURE;
|
2005-06-02 07:11:35 +04:00
|
|
|
|
2016-03-14 21:00:13 +03:00
|
|
|
nsCOMPtr<nsIEditingSession> editSession;
|
|
|
|
nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession));
|
2007-06-28 06:48:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// turn editing off
|
2007-11-12 17:47:03 +03:00
|
|
|
rv = editSession->TearDownEditorOnWindow(window);
|
2007-06-28 06:48:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEditingState = eOff;
|
|
|
|
|
2018-07-09 10:53:47 +03:00
|
|
|
// Editor resets selection since it is being destroyed. But if focus is
|
|
|
|
// still into editable control, we have to initialize selection again.
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
Element* element = fm->GetFocusedElement();
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(element);
|
|
|
|
if (txtCtrl) {
|
|
|
|
RefPtr<TextEditor> textEditor = txtCtrl->GetTextEditor();
|
|
|
|
if (textEditor) {
|
|
|
|
textEditor->ReinitializeSelection(*element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
static bool HasPresShell(nsPIDOMWindowOuter* aWindow) {
|
2007-11-02 03:51:08 +03:00
|
|
|
nsIDocShell* docShell = aWindow->GetDocShell();
|
|
|
|
if (!docShell) return false;
|
2012-12-29 05:56:42 +04:00
|
|
|
return docShell->GetPresShell() != nullptr;
|
2007-11-02 03:51:08 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 01:36:17 +04:00
|
|
|
nsresult nsHTMLDocument::SetEditingState(EditingState aState) {
|
|
|
|
mEditingState = aState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
nsresult nsHTMLDocument::EditingStateChanged() {
|
2008-05-02 15:36:29 +04:00
|
|
|
if (mRemovedFromDocShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-20 12:54:52 +03:00
|
|
|
if (mEditingState == eSettingUp || mEditingState == eTearingDown) {
|
2015-04-21 09:27:10 +03:00
|
|
|
// XXX We shouldn't recurse
|
2007-06-28 06:48:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool designMode = HasFlag(NODE_IS_EDITABLE);
|
2007-06-28 06:48:16 +04: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 20:27:48 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
NotifyEditableStateChange(this, this);
|
2007-06-28 06:48:16 +04:00
|
|
|
return TurnEditingOff();
|
2007-06-28 02:29:45 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 06:44:39 +04: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) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mParentDocument->FlushPendingNotifications(FlushType::Style);
|
2010-08-13 06:44:39 +04:00
|
|
|
}
|
|
|
|
|
2010-10-11 02:46:10 +04: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 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindow();
|
2007-06-28 03:21:05 +04:00
|
|
|
if (!window) return NS_ERROR_FAILURE;
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
|
|
|
if (!docshell) return NS_ERROR_FAILURE;
|
2007-06-28 03:21:05 +04:00
|
|
|
|
2018-03-26 05:25:56 +03:00
|
|
|
// FlushPendingNotifications might destroy our docshell.
|
|
|
|
bool isBeingDestroyed = false;
|
|
|
|
docshell->IsBeingDestroyed(&isBeingDestroyed);
|
|
|
|
if (isBeingDestroyed) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-03-14 21:00:13 +03:00
|
|
|
nsCOMPtr<nsIEditingSession> editSession;
|
|
|
|
nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession));
|
2007-06-28 06:48:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-28 03:21:05 +04:00
|
|
|
|
2017-08-07 08:43:50 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = editSession->GetHTMLEditorForWindow(window);
|
|
|
|
if (htmlEditor) {
|
2010-12-06 22:27:14 +03:00
|
|
|
// We might already have an editor if it was set up for mail, let's see
|
|
|
|
// if this is actually the case.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = 0;
|
2017-08-07 08:43:50 +03:00
|
|
|
htmlEditor->GetFlags(&flags);
|
2010-12-06 22:27:14 +03:00
|
|
|
if (flags & nsIPlaintextEditor::eEditorMailMask) {
|
|
|
|
// We already have a mail editor, then we should not attempt to create
|
|
|
|
// another one.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-06 00:19:52 +03:00
|
|
|
if (!HasPresShell(window)) {
|
2007-11-02 03:51:08 +03:00
|
|
|
// We should not make the window editable or setup its editor.
|
|
|
|
// It's probably style=display:none.
|
|
|
|
return NS_OK;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2007-06-28 03:21:05 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool makeWindowEditable = mEditingState == eOff;
|
2011-04-14 16:04:12 +04:00
|
|
|
bool updateState = false;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool spellRecheckAll = false;
|
2015-04-21 09:27:10 +03:00
|
|
|
bool putOffToRemoveScriptBlockerUntilModifyingEditingState = false;
|
2017-08-07 08:43:50 +03:00
|
|
|
htmlEditor = nullptr;
|
2007-11-02 03:51:08 +03:00
|
|
|
|
2008-09-18 06:32:44 +04:00
|
|
|
{
|
2009-02-12 07:15:59 +03:00
|
|
|
EditingState oldState = mEditingState;
|
2008-09-18 06:32:44 +04:00
|
|
|
nsAutoEditingState push(this, eSettingUp);
|
|
|
|
|
2010-10-29 20:30:15 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
2015-04-21 09:27:10 +03: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.
|
2018-04-30 20:23:14 +03:00
|
|
|
nsTArray<RefPtr<StyleSheet>> agentSheets;
|
2010-10-29 20:30:15 +04:00
|
|
|
rv = presShell->GetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-03-28 18:34:34 +03:00
|
|
|
auto cache = nsLayoutStylesheetCache::Singleton();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2018-04-30 19:19:44 +03:00
|
|
|
StyleSheet* contentEditableSheet = cache->ContentEditableSheet();
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2015-06-16 04:34:48 +03:00
|
|
|
if (!agentSheets.Contains(contentEditableSheet)) {
|
2015-11-17 09:04:09 +03:00
|
|
|
agentSheets.AppendElement(contentEditableSheet);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2008-09-18 06:32:44 +04: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).
|
2018-04-30 19:19:44 +03:00
|
|
|
StyleSheet* designModeSheet = cache->DesignModeSheet();
|
2015-06-16 04:34:48 +03:00
|
|
|
if (!agentSheets.Contains(designModeSheet)) {
|
2015-11-17 09:04:09 +03:00
|
|
|
agentSheets.AppendElement(designModeSheet);
|
2015-06-16 04:34:48 +03:00
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2011-04-14 16:04:12 +04:00
|
|
|
updateState = true;
|
2009-02-12 07:15:59 +03:00
|
|
|
spellRecheckAll = oldState == eContentEditable;
|
|
|
|
} else if (oldState == eDesignMode) {
|
2008-09-18 06:32:44 +04:00
|
|
|
// designMode is being turned off (contentEditable is still on).
|
2018-04-30 19:19:44 +03:00
|
|
|
agentSheets.RemoveElement(cache->DesignModeSheet());
|
2011-04-14 16:04:12 +04:00
|
|
|
updateState = true;
|
2008-09-18 06:32:44 +04:00
|
|
|
}
|
2010-10-29 20:30:15 +04:00
|
|
|
|
|
|
|
rv = presShell->SetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-05-11 19:37:47 +03:00
|
|
|
presShell->ApplicableStylesChanged();
|
2015-04-21 09:27:10 +03: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 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2017-09-07 16:54:49 +03:00
|
|
|
nsIContent* focusedContent = nsFocusManager::GetFocusedDescendant(
|
|
|
|
window, nsFocusManager::eOnlyCurrentWindow,
|
2015-04-21 09:27:10 +03:00
|
|
|
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.
|
2017-08-07 08:43:50 +03:00
|
|
|
htmlEditor = docshell->GetHTMLEditor();
|
|
|
|
if (!htmlEditor) {
|
2015-04-21 09:27:10 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-08-07 08:43:50 +03:00
|
|
|
}
|
2015-04-21 09:27:10 +03:00
|
|
|
|
|
|
|
// If we're entering the design mode, put the selection at the beginning of
|
|
|
|
// the document for compatibility reasons.
|
|
|
|
if (designMode && oldState == eOff) {
|
2017-08-07 08:43:50 +03:00
|
|
|
htmlEditor->BeginningOfDocument();
|
2015-04-21 09:27:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (putOffToRemoveScriptBlockerUntilModifyingEditingState) {
|
|
|
|
nsContentUtils::AddScriptBlocker();
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mEditingState = newState;
|
2015-04-21 09:27:10 +03: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 06:48:16 +04:00
|
|
|
|
2007-11-06 00:19:52 +03: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?
|
2016-11-15 08:18:33 +03:00
|
|
|
// Note that it doesn't matter what CallerType we pass, because the callee
|
|
|
|
// doesn't use it for this command. Play it safe and pass the more
|
|
|
|
// restricted one.
|
|
|
|
ErrorResult errorResult;
|
2019-03-13 03:43:48 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
|
2016-11-15 08:18:33 +03:00
|
|
|
Unused << ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), false,
|
2017-02-01 23:43:36 +03:00
|
|
|
NS_LITERAL_STRING("false"),
|
|
|
|
// Principal doesn't matter here, because the
|
|
|
|
// insertBrOnReturn command doesn't use it. Still
|
|
|
|
// it's too bad we can't easily grab a nullprincipal
|
|
|
|
// from somewhere without allocating one..
|
2019-03-13 03:43:48 +03:00
|
|
|
*principal, errorResult);
|
2016-11-15 08:18:33 +03:00
|
|
|
|
|
|
|
if (errorResult.Failed()) {
|
2007-11-06 00:19:52 +03:00
|
|
|
// Editor setup failed. Editing is not on after all.
|
|
|
|
// XXX Should we reset the editable flag on nodes?
|
2007-11-12 17:47:03 +03:00
|
|
|
editSession->TearDownEditorOnWindow(window);
|
2007-11-06 00:19:52 +03:00
|
|
|
mEditingState = eOff;
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2016-11-15 08:18:33 +03:00
|
|
|
return errorResult.StealNSResult();
|
2007-11-06 00:19:52 +03:00
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updateState) {
|
2011-06-01 01:38:25 +04:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-10-20 20:27:48 +04:00
|
|
|
NotifyEditableStateChange(this, this);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2007-06-28 02:29:45 +04:00
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
// Resync the editor's spellcheck state.
|
|
|
|
if (spellRecheckAll) {
|
2017-08-07 08:43:50 +03:00
|
|
|
nsCOMPtr<nsISelectionController> selectionController =
|
|
|
|
htmlEditor->GetSelectionController();
|
|
|
|
if (NS_WARN_IF(!selectionController)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2018-03-27 07:35:23 +03:00
|
|
|
RefPtr<Selection> spellCheckSelection = selectionController->GetSelection(
|
|
|
|
nsISelectionController::SELECTION_SPELLCHECK);
|
|
|
|
if (spellCheckSelection) {
|
|
|
|
spellCheckSelection->RemoveAllRanges(IgnoreErrors());
|
2007-06-28 03:21:05 +04:00
|
|
|
}
|
2007-06-28 02:29:45 +04:00
|
|
|
}
|
2017-08-07 08:43:50 +03:00
|
|
|
htmlEditor->SyncRealTimeSpell();
|
2007-06-28 02:29:45 +04:00
|
|
|
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
MaybeDispatchCheckKeyPressEventModelEvent();
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
void nsHTMLDocument::MaybeDispatchCheckKeyPressEventModelEvent() {
|
|
|
|
// Currently, we need to check only when we're becoming editable for
|
|
|
|
// contenteditable.
|
|
|
|
if (mEditingState != eContentEditable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHasBeenEditable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHasBeenEditable = true;
|
|
|
|
|
|
|
|
// Dispatch "CheckKeyPressEventModel" event. That is handled only by
|
|
|
|
// KeyPressEventModelCheckerChild. Then, it calls SetKeyPressEventModel()
|
|
|
|
// with proper keypress event for the active web app.
|
|
|
|
WidgetEvent checkEvent(true, eUnidentifiedEvent);
|
|
|
|
checkEvent.mSpecifiedEventType = nsGkAtoms::onCheckKeyPressEventModel;
|
|
|
|
checkEvent.mFlags.mCancelable = false;
|
|
|
|
checkEvent.mFlags.mBubbles = false;
|
|
|
|
checkEvent.mFlags.mOnlySystemGroupDispatch = true;
|
|
|
|
// Post the event rather than dispatching it synchronously because we need
|
|
|
|
// a call of SetKeyPressEventModel() before first key input. Therefore, we
|
|
|
|
// can avoid paying unnecessary runtime cost for most web apps.
|
|
|
|
(new AsyncEventDispatcher(this, checkEvent))->PostDOMEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLDocument::SetKeyPressEventModel(uint16_t aKeyPressEventModel) {
|
|
|
|
nsIPresShell* presShell = GetShell();
|
|
|
|
if (!presShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
presShell->SetKeyPressEventModel(aKeyPressEventModel);
|
|
|
|
}
|
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void nsHTMLDocument::SetDesignMode(const nsAString& aDesignMode,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& rv) {
|
|
|
|
SetDesignMode(aDesignMode, Some(&aSubjectPrincipal), rv);
|
|
|
|
}
|
|
|
|
|
2016-10-03 11:34:14 +03:00
|
|
|
void nsHTMLDocument::SetDesignMode(
|
|
|
|
const nsAString& aDesignMode, const Maybe<nsIPrincipal*>& aSubjectPrincipal,
|
|
|
|
ErrorResult& rv) {
|
2016-10-11 04:07:48 +03:00
|
|
|
if (aSubjectPrincipal.isSome() &&
|
2016-10-03 11:34:14 +03:00
|
|
|
!aSubjectPrincipal.value()->Subsumes(NodePrincipal())) {
|
2014-05-07 02:43:03 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_PROP_ACCESS_DENIED);
|
|
|
|
return;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool editableMode = HasFlag(NODE_IS_EDITABLE);
|
2007-06-28 06:48:16 +04:00
|
|
|
if (aDesignMode.LowerCaseEqualsASCII(editableMode ? "off" : "on")) {
|
|
|
|
SetEditableFlag(!editableMode);
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
rv = EditingStateChanged();
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2002-11-07 18:38:35 +03: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 18:20:58 +04:00
|
|
|
*aCmdMgr = nullptr;
|
2005-11-29 02:56:44 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2002-11-07 18:38:35 +03:00
|
|
|
if (!window) return NS_ERROR_FAILURE;
|
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
2002-11-07 18:38:35 +03:00
|
|
|
if (!docshell) return NS_ERROR_FAILURE;
|
|
|
|
|
2016-04-12 11:09:41 +03:00
|
|
|
mMidasCommandManager = docshell->GetCommandManager();
|
2002-11-07 18:38:35 +03:00
|
|
|
if (!mMidasCommandManager) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(*aCmdMgr = mMidasCommandManager);
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MidasCommand {
|
|
|
|
const char* incomingCommandString;
|
|
|
|
const char* internalCommandString;
|
|
|
|
const char* internalParamString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useNewParam;
|
|
|
|
bool convertToBoolean;
|
2002-11-07 18:38:35 +03:00
|
|
|
};
|
|
|
|
|
2003-01-26 00:49:53 +03:00
|
|
|
static const struct MidasCommand gMidasCommandTable[] = {
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format off
|
2011-10-17 18:59:28 +04: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 16:05:24 +04:00
|
|
|
{ "delete", "cmd_deleteCharBackward", "", true, false },
|
|
|
|
{ "forwarddelete", "cmd_deleteCharForward", "", true, false },
|
2011-10-17 18:59:28 +04: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 19:37:40 +04:00
|
|
|
{ "backcolor", "cmd_highlight", "", false, false },
|
2011-10-17 18:59:28 +04: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 13:37:17 +04:00
|
|
|
{ "inserttext", "cmd_insertText", "", false, false },
|
2011-10-17 18:59:28 +04: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 },
|
2016-08-21 16:33:07 +03:00
|
|
|
{ "insertparagraph", "cmd_insertParagraph", "", true, false },
|
|
|
|
{ "insertlinebreak", "cmd_insertLineBreak", "", true, false },
|
2011-10-17 18:59:28 +04: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 },
|
2016-08-24 15:53:52 +03:00
|
|
|
{ "defaultParagraphSeparator", "cmd_defaultParagraphSeparator", "", false, false },
|
2011-10-17 18:59:28 +04:00
|
|
|
{ "enableObjectResizing", "cmd_enableObjectResizing", "", false, true },
|
|
|
|
{ "enableInlineTableEditing", "cmd_enableInlineTableEditing", "", false, true },
|
2018-04-04 16:27:49 +03:00
|
|
|
{ "enableAbsolutePositionEditing", "cmd_enableAbsolutePositionEditing", "", false, true },
|
2002-11-07 18:38:35 +03:00
|
|
|
#if 0
|
2002-11-20 04:22:17 +03:00
|
|
|
// no editor support to remove alignments right now
|
2011-10-17 18:59:28 +04:00
|
|
|
{ "justifynone", "cmd_align", "", true, false },
|
2002-11-11 23:19:37 +03:00
|
|
|
|
|
|
|
// the following will need special review before being turned on
|
2011-10-17 18:59:28 +04:00
|
|
|
{ "saveas", "cmd_saveAs", "", true, false },
|
|
|
|
{ "print", "cmd_print", "", true, false },
|
2002-11-07 18:38:35 +03:00
|
|
|
#endif
|
2013-04-03 05:14:24 +04:00
|
|
|
{ nullptr, nullptr, nullptr, false, false }
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format on
|
2002-11-07 18:38:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MidasCommandCount \
|
|
|
|
((sizeof(gMidasCommandTable) / sizeof(struct MidasCommand)) - 1)
|
|
|
|
|
2007-11-29 02:38:20 +03:00
|
|
|
static const char* const gBlocks[] = {
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format off
|
2007-11-29 02:38:20 +03:00
|
|
|
"ADDRESS",
|
|
|
|
"BLOCKQUOTE",
|
|
|
|
"DD",
|
|
|
|
"DIV",
|
|
|
|
"DL",
|
|
|
|
"DT",
|
|
|
|
"H1",
|
|
|
|
"H2",
|
|
|
|
"H3",
|
|
|
|
"H4",
|
|
|
|
"H5",
|
|
|
|
"H6",
|
|
|
|
"P",
|
|
|
|
"PRE"
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format on
|
2002-12-20 09:44:32 +03:00
|
|
|
};
|
|
|
|
|
2012-04-24 14:57:23 +04:00
|
|
|
static bool ConvertToMidasInternalCommandInner(
|
|
|
|
const nsAString& inCommandID, const nsAString& inParam,
|
2008-01-14 12:26:22 +03:00
|
|
|
nsACString& outCommandID, nsACString& outParam, bool& outIsBoolean,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& outBooleanValue, bool aIgnoreParams) {
|
2005-08-25 15:51:04 +04:00
|
|
|
NS_ConvertUTF16toUTF8 convertedCommandID(inCommandID);
|
|
|
|
|
|
|
|
// Hack to support old boolean commands that were backwards (see bug 301490).
|
2011-09-29 10:19:26 +04:00
|
|
|
bool invertBool = false;
|
2005-08-25 15:51:04 +04:00
|
|
|
if (convertedCommandID.LowerCaseEqualsLiteral("usecss")) {
|
2014-05-22 07:48:51 +04:00
|
|
|
convertedCommandID.AssignLiteral("styleWithCSS");
|
2011-10-17 18:59:28 +04:00
|
|
|
invertBool = true;
|
2012-04-24 14:57:23 +04:00
|
|
|
} else if (convertedCommandID.LowerCaseEqualsLiteral("readonly")) {
|
2014-05-22 07:48:51 +04:00
|
|
|
convertedCommandID.AssignLiteral("contentReadOnly");
|
2011-10-17 18:59:28 +04:00
|
|
|
invertBool = true;
|
2005-08-25 15:51:04 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2002-11-07 18:38:35 +03:00
|
|
|
for (i = 0; i < MidasCommandCount; ++i) {
|
|
|
|
if (convertedCommandID.Equals(gMidasCommandTable[i].incomingCommandString,
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
2003-01-22 04:04:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:57:23 +04:00
|
|
|
if (!found) {
|
2003-01-22 04:04:51 +03:00
|
|
|
// reset results if the command is not found in our table
|
|
|
|
outCommandID.SetLength(0);
|
|
|
|
outParam.SetLength(0);
|
2011-10-17 18:59:28 +04:00
|
|
|
outIsBoolean = false;
|
2012-04-24 14:57:23 +04:00
|
|
|
return false;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 14:57:23 +04: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 14:57:46 +04:00
|
|
|
// cmd_paragraphState and cmd_fontSize)
|
2012-04-24 14:57:23 +04:00
|
|
|
if (outCommandID.EqualsLiteral("cmd_paragraphState")) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* start = inParam.BeginReading();
|
|
|
|
const char16_t* end = inParam.EndReading();
|
2012-04-24 14:57:23 +04:00
|
|
|
if (start != end && *start == '<' && *(end - 1) == '>') {
|
|
|
|
++start;
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 convertedParam(Substring(start, end));
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t j;
|
2012-04-24 14:57:23 +04: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 14:57:46 +04: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 19:56:38 +04:00
|
|
|
int32_t size = nsContentUtils::ParseLegacyFontSize(inParam);
|
2012-04-24 14:57:46 +04:00
|
|
|
if (size) {
|
|
|
|
outParam.AppendInt(size);
|
|
|
|
}
|
2012-04-24 14:57:23 +04:00
|
|
|
} else {
|
|
|
|
CopyUTF16toUTF8(inParam, outParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2008-01-14 12:26:22 +03:00
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString& inCommandID,
|
|
|
|
const nsAString& inParam,
|
|
|
|
nsACString& outCommandID,
|
|
|
|
nsACString& outParam,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& outIsBoolean,
|
|
|
|
bool& outBooleanValue) {
|
2008-01-14 12:26:22 +03:00
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, inParam, outCommandID,
|
|
|
|
outParam, outIsBoolean,
|
2011-10-17 18:59:28 +04:00
|
|
|
outBooleanValue, false);
|
2008-01-14 12:26:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool ConvertToMidasInternalCommand(const nsAString& inCommandID,
|
|
|
|
nsACString& outCommandID) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString dummyCString;
|
2008-01-14 12:26:22 +03:00
|
|
|
nsAutoString dummyString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummyBool;
|
2008-01-14 12:26:22 +03:00
|
|
|
return ConvertToMidasInternalCommandInner(inCommandID, dummyString,
|
|
|
|
outCommandID, dummyCString,
|
2011-10-17 18:59:28 +04:00
|
|
|
dummyBool, dummyBool, true);
|
2008-01-14 12:26:22 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
bool nsHTMLDocument::ExecCommand(const nsAString& commandID, bool doShowUI,
|
|
|
|
const nsAString& value,
|
2017-02-01 23:43:36 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2012-12-26 06:00:47 +04:00
|
|
|
ErrorResult& rv) {
|
2002-11-07 18:38:35 +03:00
|
|
|
// for optional parameters see dom/src/base/nsHistory.cpp: HistoryImpl::Go()
|
|
|
|
// this might add some ugly JS dependencies?
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch, paramStr;
|
2012-04-15 16:57:20 +04:00
|
|
|
bool isBool, boolVal;
|
|
|
|
if (!ConvertToMidasInternalCommand(commandID, value, cmdToDispatch, paramStr,
|
|
|
|
isBool, boolVal)) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-04-15 16:57:20 +04:00
|
|
|
}
|
|
|
|
|
2015-05-25 14:43:00 +03:00
|
|
|
bool isCutCopy = (commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy"));
|
2017-09-07 20:41:13 +03:00
|
|
|
bool isPaste = commandID.LowerCaseEqualsLiteral("paste");
|
2015-05-25 14:43:00 +03:00
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// if editing is not on, bail
|
2017-09-07 20:41:13 +03:00
|
|
|
if (!isCutCopy && !isPaste && !IsEditingOnAfterFlush()) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
|
|
|
// if they are requesting UI from us, let's fail since we have no UI
|
2012-05-22 13:37:17 +04:00
|
|
|
if (doShowUI) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-05-22 13:37:17 +04:00
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2015-05-25 14:43:00 +03:00
|
|
|
// special case for cut & copy
|
|
|
|
// cut & copy are allowed in non editable documents
|
|
|
|
if (isCutCopy) {
|
2017-02-01 23:43:36 +03:00
|
|
|
if (!nsContentUtils::IsCutCopyAllowed(&aSubjectPrincipal)) {
|
2015-11-09 21:28:23 +03: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 14:43:00 +03: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());
|
2018-03-26 22:18:05 +03:00
|
|
|
if (res == NS_SUCCESS_DOM_NO_OPERATION) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-25 14:43:00 +03:00
|
|
|
return NS_SUCCEEDED(res);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-22 13:37:17 +04:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("gethtml")) {
|
2012-12-26 06:00:47 +04:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
2012-05-22 13:37:17 +04:00
|
|
|
}
|
|
|
|
|
2017-09-07 20:41:13 +03:00
|
|
|
if (isPaste && !nsContentUtils::PrincipalHasPermission(
|
|
|
|
&aSubjectPrincipal, nsGkAtoms::clipboardRead)) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
2003-03-04 16:56:36 +03:00
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 18:23:03 +03:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2019-03-13 03:43:48 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2012-05-22 13:37:17 +04:00
|
|
|
if ((cmdToDispatch.EqualsLiteral("cmd_fontSize") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertImageNoUI") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertLinkNoUI") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_paragraphState")) &&
|
2012-05-22 13:37:17 +04:00
|
|
|
paramStr.IsEmpty()) {
|
2012-05-22 13:37:17 +04:00
|
|
|
// Invalid value, return false
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-04-17 14:18:08 +04:00
|
|
|
}
|
|
|
|
|
2016-08-24 15:53:52 +03:00
|
|
|
if (cmdToDispatch.EqualsLiteral("cmd_defaultParagraphSeparator") &&
|
|
|
|
!paramStr.LowerCaseEqualsLiteral("div") &&
|
|
|
|
!paramStr.LowerCaseEqualsLiteral("p") &&
|
|
|
|
!paramStr.LowerCaseEqualsLiteral("br")) {
|
|
|
|
// Invalid value
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-21 16:05:24 +04:00
|
|
|
// Return false for disabled commands (bug 760052)
|
|
|
|
bool enabled = false;
|
|
|
|
cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, &enabled);
|
|
|
|
if (!enabled) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-06-21 16:05:24 +04:00
|
|
|
}
|
|
|
|
|
2003-01-22 04:04:51 +03:00
|
|
|
if (!isBool && paramStr.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), nullptr, window);
|
2002-11-07 18:38:35 +03:00
|
|
|
} else {
|
|
|
|
// we have a command that requires a parameter, create params
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
2012-05-22 13:37:17 +04:00
|
|
|
if (isBool) {
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetBool("state_attribute", boolVal);
|
2019-02-25 06:30:50 +03:00
|
|
|
} else if (cmdToDispatch.EqualsLiteral("cmd_fontFace") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertImageNoUI") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertLinkNoUI")) {
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetString("state_attribute", value);
|
2012-05-22 13:37:17 +04:00
|
|
|
} else if (cmdToDispatch.EqualsLiteral("cmd_insertHTML") ||
|
|
|
|
cmdToDispatch.EqualsLiteral("cmd_insertText")) {
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetString("state_data", value);
|
2012-05-22 13:37:17 +04:00
|
|
|
} else {
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetCString("state_attribute", paramStr);
|
2012-05-22 13:37:17 +04:00
|
|
|
}
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), params, window);
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
return !rv.Failed();
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 08:18:33 +03:00
|
|
|
bool nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
|
2017-02-01 23:43:36 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-11-15 08:18:33 +03:00
|
|
|
ErrorResult& rv) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-04-15 16:57:20 +04:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-04-15 16:57:20 +04:00
|
|
|
}
|
|
|
|
|
2015-05-25 11:09:00 +03:00
|
|
|
// cut & copy are always allowed
|
|
|
|
bool isCutCopy = commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy");
|
|
|
|
if (isCutCopy) {
|
2017-02-01 23:43:36 +03:00
|
|
|
return nsContentUtils::IsCutCopyAllowed(&aSubjectPrincipal);
|
2015-05-25 11:09:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Report false for restricted commands
|
|
|
|
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
|
2017-02-01 23:43:36 +03:00
|
|
|
if (restricted && !nsContentUtils::IsSystemPrincipal(&aSubjectPrincipal)) {
|
2015-05-25 11:09:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// if editing is not on, bail
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2002-11-13 18:23:03 +03:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-13 18:23:03 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-13 18:23:03 +03:00
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
bool retval;
|
|
|
|
rv = cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, &retval);
|
|
|
|
return retval;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
bool nsHTMLDocument::QueryCommandIndeterm(const nsAString& commandID,
|
|
|
|
ErrorResult& rv) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-04-15 16:57:20 +04:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-04-15 16:57:20 +04:00
|
|
|
}
|
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// if editing is not on, bail
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2004-03-19 17:17:51 +03:00
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 17:17:51 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 17:17:51 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, params);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-19 17:17:51 +03:00
|
|
|
|
2012-04-06 11:42:54 +04:00
|
|
|
// If command does not have a state_mixed value, this call fails and sets
|
2012-12-26 06:00:47 +04: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.
|
2018-07-10 14:04:21 +03:00
|
|
|
return params->GetBool("state_mixed");
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
bool nsHTMLDocument::QueryCommandState(const nsAString& commandID,
|
|
|
|
ErrorResult& rv) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch, paramToCheck;
|
2012-04-15 16:57:20 +04:00
|
|
|
bool dummy, dummy2;
|
|
|
|
if (!ConvertToMidasInternalCommand(commandID, commandID, cmdToDispatch,
|
|
|
|
paramToCheck, dummy, dummy2)) {
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-04-15 16:57:20 +04:00
|
|
|
}
|
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// if editing is not on, bail
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 18:23:03 +03:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2012-03-23 23:03:42 +04:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("usecss")) {
|
|
|
|
// Per spec, state is supported for styleWithCSS but not useCSS, so we just
|
|
|
|
// return false always.
|
2012-12-26 06:00:47 +04:00
|
|
|
return false;
|
2012-03-23 23:03:42 +04:00
|
|
|
}
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, params);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
|
|
|
// handle alignment as a special case (possibly other commands too?)
|
2003-03-26 10:41:30 +03: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 13:37:17 +04:00
|
|
|
if (cmdToDispatch.EqualsLiteral("cmd_align")) {
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString actualAlignmentType;
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->GetCString("state_attribute", actualAlignmentType);
|
2018-07-10 12:04:46 +03:00
|
|
|
return !rv.Failed() && !actualAlignmentType.IsEmpty() &&
|
|
|
|
paramToCheck == actualAlignmentType;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-04-06 11:42:54 +04:00
|
|
|
// If command does not have a state_all value, this call fails and sets
|
2012-12-26 06:00:47 +04: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.
|
2018-07-10 14:04:21 +03:00
|
|
|
return params->GetBool("state_all");
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 08:18:33 +03:00
|
|
|
bool nsHTMLDocument::QueryCommandSupported(const nsAString& commandID,
|
|
|
|
CallerType aCallerType) {
|
2015-06-08 01:21:58 +03: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.
|
2016-11-15 08:18:33 +03:00
|
|
|
if (aCallerType != CallerType::System) {
|
2015-06-08 01:21:58 +03:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("paste")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (nsContentUtils::IsCutCopyRestricted()) {
|
2017-02-01 23:43:36 +03:00
|
|
|
// XXXbz should we worry about correctly reporting "true" in the
|
|
|
|
// "restricted, but we're an addon with clipboardWrite permissions" case?
|
|
|
|
// See also nsContentUtils::IsCutCopyAllowed.
|
2015-06-08 01:21:58 +03:00
|
|
|
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
|
|
|
commandID.LowerCaseEqualsLiteral("copy")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 13:37:00 +03:00
|
|
|
}
|
|
|
|
|
2011-08-17 16:04:14 +04:00
|
|
|
// commandID is supported if it can be converted to a Midas command
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch;
|
2012-12-26 06:00:47 +04:00
|
|
|
return ConvertToMidasInternalCommand(commandID, cmdToDispatch);
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:00:47 +04:00
|
|
|
void nsHTMLDocument::QueryCommandValue(const nsAString& commandID,
|
|
|
|
nsAString& aValue, ErrorResult& rv) {
|
|
|
|
aValue.Truncate();
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmdToDispatch, paramStr;
|
2012-04-15 16:57:20 +04:00
|
|
|
if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
|
|
|
|
// Return empty string
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2012-04-15 16:57:20 +04:00
|
|
|
}
|
|
|
|
|
2002-11-07 18:38:35 +03:00
|
|
|
// if editing is not on, bail
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!IsEditingOnAfterFlush()) {
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
|
|
|
// get command manager and dispatch command to our window if it's acceptable
|
|
|
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
2002-11-13 18:23:03 +03:00
|
|
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!cmdMgr) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2019-03-13 03:43:48 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindow();
|
2012-12-26 06:00:47 +04:00
|
|
|
if (!window) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2012-05-22 13:37:17 +04:00
|
|
|
// this is a special command since we are calling DoCommand rather than
|
2003-06-11 01:12:29 +04:00
|
|
|
// GetCommandState like the other commands
|
2018-07-10 14:04:21 +03:00
|
|
|
RefPtr<nsCommandParams> params = new nsCommandParams();
|
2012-05-22 13:37:17 +04:00
|
|
|
if (cmdToDispatch.EqualsLiteral("cmd_getContents")) {
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetBool("selection_only", true);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetCString("format", NS_LITERAL_CSTRING("text/html"));
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), params, window);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
params->GetString("result", aValue);
|
2012-12-26 06:00:47 +04:00
|
|
|
return;
|
2003-06-11 01:12:29 +04:00
|
|
|
}
|
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = params->SetCString("state_attribute", paramStr);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, params);
|
2012-12-26 06:00:47 +04:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2012-04-06 11:42:54 +04:00
|
|
|
// If command does not have a state_attribute value, this call fails, and
|
2012-12-26 06:00:47 +04:00
|
|
|
// aValue will wind up being the empty string. This is fine -- we want to
|
2012-04-06 11:42:54 +04:00
|
|
|
// return "" in that case anyway (bug 738385), so we just return NS_OK
|
|
|
|
// regardless.
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString result;
|
2018-07-10 14:04:21 +03:00
|
|
|
params->GetCString("state_attribute", result);
|
2018-07-10 12:04:46 +03:00
|
|
|
CopyUTF8toUTF16(result, aValue);
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
2004-06-25 16:26:02 +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
|
|
|
|
|
|
|
bool nsHTMLDocument::IsEditingOnAfterFlush() {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetParentDocument();
|
2008-10-29 23:12:24 +03:00
|
|
|
if (doc) {
|
|
|
|
// Make sure frames are up to date, since that can affect whether
|
|
|
|
// we're editable.
|
2017-01-05 10:31:56 +03:00
|
|
|
doc->FlushPendingNotifications(FlushType::Frames);
|
2008-10-29 23:12:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return IsEditingOn();
|
|
|
|
}
|
2009-02-21 05:51:48 +03:00
|
|
|
|
|
|
|
void nsHTMLDocument::RemovedFromDocShell() {
|
|
|
|
mEditingState = eOff;
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::RemovedFromDocShell();
|
2009-02-21 05:51:48 +03:00
|
|
|
}
|
2012-02-02 01:58:01 +04: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
|
|
|
|
// - mMidasCommandManager
|
|
|
|
}
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
}
|
2018-07-10 11:09:59 +03:00
|
|
|
|
|
|
|
void nsHTMLDocument::UserInteractionForTesting() { SetUserHasInteracted(); }
|