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"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2013-09-06 10:41:42 +04:00
|
|
|
#include "mozilla/dom/HTMLAllCollection.h"
|
2019-04-03 15:51:38 +03:00
|
|
|
#include "nsCommandManager.h"
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-12 12:15:56 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2017-08-17 08:29:03 +03:00
|
|
|
#include "nsString.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "nsIContentSecurityPolicy.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"
|
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"
|
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"
|
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"
|
2019-05-27 23:57:00 +03: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"
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "mozilla/dom/nsCSPContext.h"
|
2018-03-27 07:35:23 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
Bug 1489308 part 5. Align the work we do on document.open with the spec. r=mccr8,smaug
The main behavior changes are:
1) We no longer create a new Window when doing document.open(). We use the
same Window but remove all the event listeners on it and on the existing DOM
tree before removing the document's existing kids.
2) We no longer create a new session history entry. The existing one always
gets replaced instead.
3) We now support document.open on documents that are not in a Window.
The reasons for the various test changes are as follows:
The change to browser_modifiedclick_inherit_principal.js is because we no
longer set the docshell to a wyciwyg URL when document.open() happens and the
test was depending on that to terminate.
browser_wyciwyg_urlbarCopying.js is being removed because it's trying to test
wyciwyg URIs, which no longer exist.
The changes in docshell/test/navigation are because document.open() no longer
affects session history. One of the tests was testing the interactions there
and is being removed; another is being repurposed to just test that
document.open() does not affect history.length.
The change to test_x-frame-options.html is because document.open() now removes
event listeners on the window, which it didn't use to do (and in the specific
case in this test reused the existing inner too, so the listener was still
around in practice). The new behavior matches other browsers.
The removal of test_bug172261.html is because document.open() no longer affects
session history, so you can't go back across it or forward to the "opened"
state, so the situation that test is trying to test no longer exists.
The changes to test_bug255820.html are because reloading a document after
document.open() will now just load the URL of the document that was the entry
document for the open() call, not reload the written content. So there's not
much point testing reload behavior, and in this test it was just reloading the
toplevel test file inside the frames.
The change to test_bug346659.html is because now we no longer create a new
Window on document.open().
The change to test_bug1232829.html is because document.open() (implicit in this
test) no longer adds history entries, so the back() was just leaving the test
page instead of going back across the document.open(). The test is a
crashtest in practice, so might still be testing something useful about how
document.open() interacts with animations.
The change to test_bug715739.html is because the URL of the document after
document.open() is now the URL of the entry document, not a wyciwyg URL, so
reload() has different behavior than it used to.
The change to test_bug329869.html is because now when we go back we're
reloading the original document we had, not doing a wyciwyg load, and the
security info now doesn't include the untrusted script.
The changes to the wpt expectations are removing a bunch of expected failures
now that we pass those tests and disabling some tests that are fundamentally
racy and hence fail randomly. The latter all have github issues filed for the
test problem.
The change to testing/web-platform/tests/common/object-association.js is fixing
tests that were not matching the spec (and were failing in other browsers).
The change to parser-uses-registry-of-owner-document.html is fixing tests that
were not matching the spec (and were failing in other browsers).
The change to document-write.tentative.html is because the test was buggy: it
was using the same iframe element for all its tests and racing loads from some
tests against API calls from other tests, etc. It's a wonder it ever managed
to pass, independent of these patches (and in fact it doesn't pass according to
wpt.fyi data, even in Firefox).
The changes in html/browsers/history/the-history-interface are because
document.open() no longer adds history entries. The test was failing in all
other browsers for the same reason.
The changes in html/browsers/history/the-location-interface are because
reloading a document.open()-created thing now loads the URL of the page that
was the entry document for the open() call. The test was failing in all other
browsers.
The change to reload_document_open_write.html is because we now reload the url
of the document that entered the script that called open() when we reload, not
the written content. Other browsers were failing this test too; Gecko with
the old document.open implementation was the only one that passed.
The change to http-refresh.py is to fix a test bug: it was not returning a
Content-Type header, so we were putting up helper app dialogs, etc.
The change to test_ext_contentscript.js is because we no create a new global
for document.open() calls. Kris Maglione OKed this part.
Differential Revision: https://phabricator.services.mozilla.com/D17323
--HG--
extra : moz-landing-system : lando
2019-02-28 02:24:48 +03:00
|
|
|
#include "mozilla/dom/ShadowIncludingTreeIterator.h"
|
2013-01-18 18:27:03 +04:00
|
|
|
#include "nsCharsetSource.h"
|
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
|
|
|
|
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),
|
|
|
|
mLoadFlags(0),
|
|
|
|
mWarnedWidthHeight(false),
|
|
|
|
mContentEditableCount(0),
|
|
|
|
mEditingState(EditingState::eOff),
|
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,
|
2019-04-12 08:31:32 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIPrincipal* aStoragePrincipal) {
|
2003-03-26 10:41:30 +03:00
|
|
|
mLoadFlags = nsIRequest::LOAD_NORMAL;
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2019-04-12 08:31:32 +03:00
|
|
|
Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aStoragePrincipal);
|
2001-11-16 05:03:19 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mImages = nullptr;
|
|
|
|
mApplets = nullptr;
|
|
|
|
mEmbeds = nullptr;
|
|
|
|
mLinks = nullptr;
|
|
|
|
mAnchors = nullptr;
|
|
|
|
mScripts = nullptr;
|
1999-01-06 03:32:41 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mForms = nullptr;
|
1998-05-14 03:43:44 +04:00
|
|
|
|
2003-05-31 00:04:50 +04:00
|
|
|
// Make the content type default to "text/html", we are a HTML
|
|
|
|
// document, after all. Once we start getting data, this may be
|
|
|
|
// changed.
|
2010-06-27 00:39:56 +04:00
|
|
|
SetContentTypeInternal(nsDependentCString("text/html"));
|
1999-01-06 03:32:41 +03:00
|
|
|
}
|
|
|
|
|
2014-07-10 01:27:49 +04:00
|
|
|
void nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
2017-06-18 14:37:50 +03:00
|
|
|
int32_t& aCharsetSource,
|
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2014-07-10 01:27:49 +04:00
|
|
|
if (aCv) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t requestCharsetSource;
|
2014-07-10 01:27:49 +04:00
|
|
|
nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2001-12-26 06:17:59 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
2017-06-25 16:46:08 +03:00
|
|
|
auto requestCharset = aCv->GetHintCharset();
|
2014-07-10 01:27:49 +04:00
|
|
|
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
if (requestCharsetSource <= aCharsetSource) return;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2017-06-25 16:46:08 +03:00
|
|
|
if (requestCharset && IsAsciiCompatible(requestCharset)) {
|
|
|
|
aCharsetSource = requestCharsetSource;
|
|
|
|
aEncoding = WrapNotNull(requestCharset);
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:27:49 +04:00
|
|
|
void nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
2012-01-24 13:52:05 +04:00
|
|
|
nsIDocShell* aDocShell,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2003-03-26 10:41:30 +03:00
|
|
|
if (kCharsetFromUserForced <= aCharsetSource) return;
|
2013-01-18 18:27:03 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
// mCharacterSet not updated yet for channel, so check aEncoding, too.
|
|
|
|
if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aEncoding)) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2017-06-25 16:46:08 +03:00
|
|
|
const Encoding* forceCharsetFromDocShell = nullptr;
|
2014-07-10 01:27:49 +04:00
|
|
|
if (aCv) {
|
2013-01-18 18:27:03 +04:00
|
|
|
// XXX mailnews-only
|
2017-06-25 16:46:08 +03:00
|
|
|
forceCharsetFromDocShell = aCv->GetForceCharset();
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2017-06-17 05:54:40 +03:00
|
|
|
if (forceCharsetFromDocShell && IsAsciiCompatible(forceCharsetFromDocShell)) {
|
2017-06-25 16:46:08 +03:00
|
|
|
aEncoding = WrapNotNull(forceCharsetFromDocShell);
|
2003-03-26 10:41:30 +03:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDocShell) {
|
|
|
|
// This is the Character Encoding menu code path in Firefox
|
2017-06-18 14:37:50 +03:00
|
|
|
auto encoding = nsDocShell::Cast(aDocShell)->GetForcedCharset();
|
2013-05-25 18:09:30 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
if (encoding) {
|
|
|
|
if (!IsAsciiCompatible(encoding)) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(encoding);
|
2003-03-26 10:41:30 +03:00
|
|
|
aCharsetSource = kCharsetFromUserForced;
|
2013-05-25 18:09:30 +04:00
|
|
|
aDocShell->SetForcedCharset(NS_LITERAL_CSTRING(""));
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 10:55:19 +04:00
|
|
|
void nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2001-12-26 06:17:59 +03:00
|
|
|
nsresult rv;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
|
|
|
if (kCharsetFromCache <= aCharsetSource) {
|
2013-01-18 18:27:03 +04:00
|
|
|
return;
|
2003-03-26 10:41:30 +03:00
|
|
|
}
|
2001-12-26 06:17:59 +03:00
|
|
|
|
2010-06-24 10:55:19 +04:00
|
|
|
nsCString cachedCharset;
|
|
|
|
rv = aCachingChannel->GetCacheTokenCachedCharset(cachedCharset);
|
2017-06-15 10:52:31 +03:00
|
|
|
if (NS_FAILED(rv) || cachedCharset.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The canonical names changed, so the cache may have an old name.
|
2017-08-28 12:57:17 +03:00
|
|
|
const Encoding* encoding = Encoding::ForLabelNoReplacement(cachedCharset);
|
2017-06-17 05:54:40 +03:00
|
|
|
if (!encoding) {
|
|
|
|
return;
|
2017-06-15 10:52:31 +03:00
|
|
|
}
|
2017-06-17 05:54:40 +03:00
|
|
|
// Check IsAsciiCompatible() even in the cache case, because the value
|
2012-10-16 11:42:54 +04:00
|
|
|
// might be stale and in the case of a stale charset that is not a rough
|
|
|
|
// ASCII superset, the parser has no way to recover.
|
2017-06-17 05:54:40 +03:00
|
|
|
if (!encoding->IsAsciiCompatible() && encoding != ISO_2022_JP_ENCODING) {
|
|
|
|
return;
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
aEncoding = WrapNotNull(encoding);
|
2017-06-17 05:54:40 +03:00
|
|
|
aCharsetSource = kCharsetFromCache;
|
2001-12-26 06:17:59 +03:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:52:05 +04:00
|
|
|
void nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCharsetSource,
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*>& aEncoding) {
|
2012-10-16 11:42:54 +04:00
|
|
|
if (!aDocShell) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-18 18:27:03 +04:00
|
|
|
if (aCharsetSource >= kCharsetFromParentForced) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 11:42:54 +04:00
|
|
|
int32_t parentSource;
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* parentCharset;
|
2013-10-16 05:46:10 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> parentPrincipal;
|
|
|
|
aDocShell->GetParentCharset(parentCharset, &parentSource,
|
|
|
|
getter_AddRefs(parentPrincipal));
|
2017-06-18 14:37:50 +03:00
|
|
|
if (!parentCharset) {
|
2012-10-16 11:42:54 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-18 18:27:03 +04:00
|
|
|
if (kCharsetFromParentForced == parentSource ||
|
|
|
|
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-04-05 18:44:56 +03:00
|
|
|
// Using a prototype document is only allowed with chrome privilege.
|
2019-04-16 21:27:52 +03:00
|
|
|
bool ShouldUsePrototypeDocument(nsIChannel* aChannel, Document* aDoc) {
|
|
|
|
if (!aChannel || !aDoc ||
|
2019-03-09 04:00:23 +03:00
|
|
|
!StaticPrefs::dom_prototype_document_cache_enabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-16 21:27:52 +03:00
|
|
|
if (!nsContentUtils::IsChromeDoc(aDoc)) {
|
2019-03-09 04:00:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(originalURI));
|
2019-04-05 18:44:56 +03:00
|
|
|
return IsChromeURI(originalURI);
|
2019-03-09 04:00:23 +03:00
|
|
|
}
|
|
|
|
|
2003-03-22 06:20:23 +03:00
|
|
|
nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
bool aReset, nsIContentSink* aSink) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if (!aCommand) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Command is mandatory");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
if (aSink) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Got a sink override. Should not happen for HTML doc.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-05-24 23:28:48 +04:00
|
|
|
if (mType != eHTML) {
|
|
|
|
MOZ_ASSERT(mType == eXHTML);
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentType;
|
2011-11-01 19:27:36 +04:00
|
|
|
aChannel->GetContentType(contentType);
|
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
bool view =
|
|
|
|
!strcmp(aCommand, "view") || !strcmp(aCommand, "external-resource");
|
|
|
|
bool viewSource = !strcmp(aCommand, "view-source");
|
|
|
|
bool asData = !strcmp(aCommand, kLoadAsData);
|
2017-06-12 17:36:02 +03:00
|
|
|
if (!(view || viewSource || asData)) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Bad parser command");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool html = contentType.EqualsLiteral(TEXT_HTML);
|
2016-09-28 17:48:17 +03:00
|
|
|
bool xhtml = !html && (contentType.EqualsLiteral(APPLICATION_XHTML_XML) ||
|
|
|
|
contentType.EqualsLiteral(APPLICATION_WAPXHTML_XML));
|
2019-02-23 19:06:52 +03:00
|
|
|
mIsPlainText =
|
2013-03-20 00:30:53 +04:00
|
|
|
!html && !xhtml && nsContentUtils::IsPlainTextType(contentType);
|
2019-02-23 19:06:52 +03:00
|
|
|
if (!(html || xhtml || mIsPlainText || viewSource)) {
|
2012-04-10 11:02:31 +04:00
|
|
|
MOZ_ASSERT(false, "Channel with bad content type.");
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2011-11-01 19:27:36 +04:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:29:30 +03:00
|
|
|
bool forceUtf8 =
|
2019-02-23 19:06:52 +03:00
|
|
|
mIsPlainText && nsContentUtils::IsUtf8OnlyPlainTextType(contentType);
|
2016-06-09 14:29:30 +03:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
bool loadAsHtml5 = true;
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
if (!viewSource && xhtml) {
|
|
|
|
// We're parsing XHTML as XML, remember that.
|
2014-05-24 23:28:48 +04:00
|
|
|
mType = eXHTML;
|
2019-04-03 10:02:00 +03:00
|
|
|
SetCompatibilityMode(eCompatibility_FullStandards);
|
2012-03-31 18:10:34 +04:00
|
|
|
loadAsHtml5 = false;
|
2003-04-19 04:28:09 +04:00
|
|
|
}
|
2016-08-26 09:02:32 +03:00
|
|
|
|
2010-02-02 10:39:26 +03:00
|
|
|
// TODO: Proper about:blank treatment is bug 543435
|
2012-03-31 18:10:34 +04:00
|
|
|
if (loadAsHtml5 && view) {
|
2010-02-02 10:39:26 +03:00
|
|
|
// mDocumentURI hasn't been set, yet, so get the URI from the channel
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(uri));
|
|
|
|
// Adapted from nsDocShell:
|
|
|
|
// GetSpec can be expensive for some URIs, so check the scheme first.
|
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
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult rv = Document::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
|
|
|
|
aContainer, aDocListener, aReset);
|
2003-03-22 06:20:23 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-02-28 04:09:48 +03:00
|
|
|
// Store the security info for future use.
|
2004-07-28 04:26:58 +04:00
|
|
|
aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
2003-03-22 06:20:23 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
|
2019-03-09 04:00:23 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2003-03-22 06:20:23 +03:00
|
|
|
|
2019-03-09 04:00:23 +03:00
|
|
|
bool loadWithPrototype = false;
|
2019-05-14 22:46:25 +03:00
|
|
|
RefPtr<nsHtml5Parser> html5Parser;
|
2012-03-31 18:10:34 +04:00
|
|
|
if (loadAsHtml5) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser = nsHtml5Module::NewHtml5Parser();
|
|
|
|
mParser = html5Parser;
|
2019-02-23 19:06:52 +03:00
|
|
|
if (mIsPlainText) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if (viewSource) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("view-source-plain");
|
2011-11-01 19:27:36 +04:00
|
|
|
} else {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("plain-text");
|
2011-11-01 19:27:36 +04:00
|
|
|
}
|
2012-03-31 18:10:34 +04:00
|
|
|
} else if (viewSource && !html) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated("view-source-xml");
|
2009-06-29 02:44:22 +04:00
|
|
|
} else {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->MarkAsNotScriptCreated(aCommand);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2019-04-16 21:27:52 +03:00
|
|
|
} else if (xhtml && ShouldUsePrototypeDocument(aChannel, this)) {
|
2019-03-09 04:00:23 +03:00
|
|
|
loadWithPrototype = true;
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
mParser = new mozilla::parser::PrototypeDocumentParser(originalURI, this);
|
2012-03-31 18:10:34 +04:00
|
|
|
} else {
|
|
|
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-12-09 10:18:38 +03:00
|
|
|
}
|
1999-04-26 21:56:37 +04:00
|
|
|
|
2007-01-13 06:28:00 +03:00
|
|
|
// Look for the parent document. Note that at this point we don't have our
|
|
|
|
// content viewer set up yet, and therefore do not have a useful
|
|
|
|
// mParentDocument.
|
|
|
|
|
|
|
|
// in this block of code, if we get an error result, we return it
|
|
|
|
// but if we get a null pointer, that's perfectly legal for parent
|
|
|
|
// and parentContentViewer
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
2013-02-13 02:02:51 +04:00
|
|
|
if (docShell) {
|
|
|
|
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) {
|
2019-05-14 22:46:25 +03:00
|
|
|
html5Parser->Initialize(this, uri, docShell, aChannel);
|
2009-06-29 02:44:22 +04:00
|
|
|
} else {
|
2012-03-31 18:10:34 +04:00
|
|
|
// about:blank *only*
|
|
|
|
nsCOMPtr<nsIHTMLContentSink> htmlsink;
|
|
|
|
NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri, docShell,
|
|
|
|
aChannel);
|
|
|
|
mParser->SetContentSink(htmlsink);
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-01 23:53:19 +04:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
// parser the content of the URI
|
2012-07-30 18:20:58 +04:00
|
|
|
mParser->Parse(uri, nullptr, (void*)this);
|
2012-03-31 18:10:34 +04:00
|
|
|
|
1998-06-01 23:53:19 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-02-24 19:32:08 +03:00
|
|
|
bool nsHTMLDocument::UseWidthDeviceWidthFallbackViewport() const {
|
|
|
|
if (mIsPlainText) {
|
|
|
|
// Plain text documents are simple enough that font inflation doesn't offer
|
|
|
|
// any appreciable advantage over defaulting to "width=device-width" and
|
|
|
|
// subsequently turning on word-wrapping.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Document::UseWidthDeviceWidthFallbackViewport();
|
|
|
|
}
|
|
|
|
|
2019-03-04 09:11:41 +03:00
|
|
|
Element* nsHTMLDocument::GetUnfocusedKeyEventTarget() {
|
2017-07-13 23:53:26 +03:00
|
|
|
if (nsGenericHTMLElement* body = GetBody()) {
|
|
|
|
return body;
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
return Document::GetUnfocusedKeyEventTarget();
|
2017-07-13 23:53:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:37:34 +03:00
|
|
|
bool nsHTMLDocument::IsRegistrableDomainSuffixOfOrEqualTo(
|
|
|
|
const nsAString& aHostSuffixString, const nsACString& aOrigHost) {
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#is-a-registrable-domain-suffix-of-or-is-equal-to
|
|
|
|
if (aHostSuffixString.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> origURI = CreateInheritingURIForHost(aOrigHost);
|
|
|
|
if (!origURI) {
|
|
|
|
// Error: failed to parse input domain
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> newURI =
|
|
|
|
RegistrableDomainSuffixOfInternal(aHostSuffixString, origURI);
|
|
|
|
if (!newURI) {
|
|
|
|
// Error: illegal domain
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-07-17 02:38:51 +04:00
|
|
|
void nsHTMLDocument::AddedForm() { ++mNumForms; }
|
|
|
|
|
|
|
|
void nsHTMLDocument::RemovedForm() { --mNumForms; }
|
|
|
|
|
2004-02-04 02:23:10 +03:00
|
|
|
int32_t nsHTMLDocument::GetNumFormsSynchronous() { return mNumForms; }
|
2002-07-17 02:38:51 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
mEditingState = eTearingDown;
|
2019-04-19 17:34:36 +03:00
|
|
|
RemoveContentEditableStyleSheets();
|
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);
|
|
|
|
|
2019-03-29 18:12:47 +03:00
|
|
|
RefPtr<PresShell> presShell = GetPresShell();
|
2010-10-29 20:30:15 +04:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
2019-04-19 17:34:36 +03:00
|
|
|
MOZ_ASSERT(mStyleSetFilled);
|
|
|
|
|
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.
|
2019-04-19 17:34:36 +03:00
|
|
|
AddContentEditableStyleSheetsToStyleSet(designMode);
|
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.
|
2019-04-19 17:34:36 +03:00
|
|
|
updateState = designMode || oldState == eDesignMode;
|
2008-09-18 06:32:44 +04:00
|
|
|
if (designMode) {
|
|
|
|
// designMode is being turned on (overrides contentEditable).
|
2009-02-12 07:15:59 +03:00
|
|
|
spellRecheckAll = oldState == eContentEditable;
|
2008-09-18 06:32:44 +04:00
|
|
|
}
|
2010-10-29 20:30:15 +04:00
|
|
|
|
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) {
|
2019-03-29 18:12:47 +03:00
|
|
|
PresShell* presShell = GetPresShell();
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-03 15:51:38 +03:00
|
|
|
nsCommandManager* nsHTMLDocument::GetMidasCommandManager() {
|
2002-11-07 18:38:35 +03:00
|
|
|
// check if we have it cached
|
|
|
|
if (mMidasCommandManager) {
|
2019-04-03 15:51:38 +03:00
|
|
|
return mMidasCommandManager;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = GetWindow();
|
2019-04-03 15:51:38 +03:00
|
|
|
if (!window) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
2019-04-03 15:51:38 +03:00
|
|
|
if (!docshell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-11-07 18:38:35 +03:00
|
|
|
|
2016-04-12 11:09:41 +03:00
|
|
|
mMidasCommandManager = docshell->GetCommandManager();
|
2019-04-03 15:51:38 +03:00
|
|
|
return mMidasCommandManager;
|
2002-11-07 18:38:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-04-03 15:51:38 +03:00
|
|
|
RefPtr<nsCommandManager> commandManager = GetMidasCommandManager();
|
|
|
|
if (!commandManager) {
|
2012-12-26 06:00:47 +04:00
|
|
|
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)
|
2019-04-03 15:51:38 +03:00
|
|
|
if (!commandManager->IsCommandEnabled(cmdToDispatch, window)) {
|
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()) {
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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;
|
|
|
|
}
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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
|
2019-04-03 15:51:38 +03:00
|
|
|
RefPtr<nsCommandManager> commandManager = GetMidasCommandManager();
|
|
|
|
if (!commandManager) {
|
2012-12-26 06:00:47 +04:00
|
|
|
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
|
|
|
|
2019-04-03 15:51:38 +03:00
|
|
|
return commandManager->IsCommandEnabled(cmdToDispatch, window);
|
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
|
2019-04-03 15:51:38 +03:00
|
|
|
RefPtr<nsCommandManager> commandManager = GetMidasCommandManager();
|
|
|
|
if (!commandManager) {
|
2012-12-26 06:00:47 +04:00
|
|
|
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();
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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
|
2019-04-03 15:51:38 +03:00
|
|
|
RefPtr<nsCommandManager> commandManager = GetMidasCommandManager();
|
|
|
|
if (!commandManager) {
|
2012-12-26 06:00:47 +04:00
|
|
|
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();
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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;
|
|
|
|
}
|
2019-05-02 00:06:58 +03:00
|
|
|
if (!StaticPrefs::dom_allow_cut_copy()) {
|
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
|
2019-04-03 15:51:38 +03:00
|
|
|
RefPtr<nsCommandManager> commandManager = GetMidasCommandManager();
|
|
|
|
if (!commandManager) {
|
2012-12-26 06:00:47 +04:00
|
|
|
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;
|
|
|
|
}
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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
|
|
|
|
2019-04-03 15:51:38 +03:00
|
|
|
rv = commandManager->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(); }
|